mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
added eml file format support for restoring
This commit is contained in:
parent
b3b6f827e8
commit
e834c30f6b
1 changed files with 40 additions and 18 deletions
|
@ -151,12 +151,12 @@ static int usage_lf_em4x50_restore(void) {
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
PrintAndLogEx(NORMAL, "Options:");
|
||||||
PrintAndLogEx(NORMAL, " h - this help");
|
PrintAndLogEx(NORMAL, " h - this help");
|
||||||
PrintAndLogEx(NORMAL, " u <UID> - uid, try to restore from lf-4x50-<UID>-dump.bin");
|
PrintAndLogEx(NORMAL, " u <UID> - uid, try to restore from lf-4x50-<UID>-dump.bin");
|
||||||
PrintAndLogEx(NORMAL, " f <filename prefix> - data filename <filename>.<prefix> (optional)");
|
PrintAndLogEx(NORMAL, " f <filename> - data filename <filename.bin/eml> (optional)");
|
||||||
PrintAndLogEx(NORMAL, " p <pwd> - password (hex, lsb) (optional)");
|
PrintAndLogEx(NORMAL, " p <pwd> - password (hex, lsb) (optional)");
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
PrintAndLogEx(NORMAL, "Examples:");
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_restore h"));
|
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_restore h"));
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_restore f em4x50dump"));
|
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_restore f em4x50dump.bin"));
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_restore f em4x50dump p 12345678"));
|
PrintAndLogEx(NORMAL, _YELLOW_(" lf em 4x50_restore f em4x50dump.eml p 12345678"));
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -920,7 +920,8 @@ int CmdEM4x50Restore(const char *Cmd) {
|
||||||
|
|
||||||
//uint8_t data[136] = {0x0};
|
//uint8_t data[136] = {0x0};
|
||||||
size_t bytes_read = 0;
|
size_t bytes_read = 0;
|
||||||
char filename[FILE_PATH_SIZE] = {0x00};
|
char filename[FILE_PATH_SIZE] = {0};
|
||||||
|
char ext[FILE_PATH_SIZE] = {0};
|
||||||
char szTemp[FILE_PATH_SIZE - 20] = {0x00};
|
char szTemp[FILE_PATH_SIZE - 20] = {0x00};
|
||||||
FILE *fdump;
|
FILE *fdump;
|
||||||
|
|
||||||
|
@ -939,7 +940,7 @@ int CmdEM4x50Restore(const char *Cmd) {
|
||||||
case 'u':
|
case 'u':
|
||||||
param_getstr(Cmd, cmdp + 1, szTemp, FILE_PATH_SIZE - 20);
|
param_getstr(Cmd, cmdp + 1, szTemp, FILE_PATH_SIZE - 20);
|
||||||
if (filename[0] == 0x00)
|
if (filename[0] == 0x00)
|
||||||
snprintf(filename, FILE_PATH_SIZE, "lf-4x50-%s-dump.bin", szTemp);
|
snprintf(filename, FILE_PATH_SIZE, "./lf-4x50-%s-dump.bin", szTemp);
|
||||||
cmdp += 2;
|
cmdp += 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -965,20 +966,41 @@ int CmdEM4x50Restore(const char *Cmd) {
|
||||||
if (errors)
|
if (errors)
|
||||||
return usage_lf_em4x50_restore();
|
return usage_lf_em4x50_restore();
|
||||||
|
|
||||||
// open dump file
|
PrintAndLogEx(INFO, "Restoring " _YELLOW_("%s")" to card", filename);
|
||||||
|
|
||||||
|
// read data from dump file; file has to be "bin" or "eml"
|
||||||
|
// (file type is distinguished by file extension)
|
||||||
|
|
||||||
|
memcpy(ext, &filename[strlen(filename) - 4], 4);
|
||||||
|
ext[5] = 0x00;
|
||||||
|
if (memcmp(ext, ".eml", 4) == 0) {
|
||||||
|
|
||||||
|
// read from eml file
|
||||||
|
if (loadFileEML(filename, etd.data, &bytes_read) != PM3_SUCCESS)
|
||||||
|
return PM3_EFILE;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// open bin file
|
||||||
if ((fdump = fopen(filename, "rb")) == NULL) {
|
if ((fdump = fopen(filename, "rb")) == NULL) {
|
||||||
PrintAndLogEx(WARNING, "Could not find file " _YELLOW_("%s"), filename);
|
PrintAndLogEx(WARNING, "Could not find file " _YELLOW_("%s"), filename);
|
||||||
return PM3_EFILE;
|
return PM3_EFILE;
|
||||||
}
|
}
|
||||||
PrintAndLogEx(INFO, "Restoring " _YELLOW_("%s")" to card", filename);
|
|
||||||
|
|
||||||
// read data from dump file
|
// read from bin file
|
||||||
bytes_read = fread(&etd.data, sizeof(uint8_t), sizeof(etd.data), fdump);
|
bytes_read = fread(&etd.data, sizeof(uint8_t), DUMP_FILESIZE, fdump);
|
||||||
if (bytes_read != sizeof(etd.data)) {
|
PrintAndLogEx(SUCCESS, "Loaded " _YELLOW_("%i") " bytes from bin file " _YELLOW_("%s"),
|
||||||
|
bytes_read,
|
||||||
|
filename
|
||||||
|
);
|
||||||
|
|
||||||
|
fclose(fdump);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bytes_read != DUMP_FILESIZE) {
|
||||||
PrintAndLogEx(FAILED, "Read error");
|
PrintAndLogEx(FAILED, "Read error");
|
||||||
return PM3_EFILE;
|
return PM3_EFILE;
|
||||||
}
|
}
|
||||||
fclose(fdump);
|
|
||||||
|
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommandNG(CMD_LF_EM4X50_RESTORE, (uint8_t *)&etd, sizeof(etd));
|
SendCommandNG(CMD_LF_EM4X50_RESTORE, (uint8_t *)&etd, sizeof(etd));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue