mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-20 15:13:15 +08:00
lf t55xx restore - now support bin/eml/json formats
This commit is contained in:
parent
536ddd17fd
commit
66a9490fe7
1 changed files with 103 additions and 99 deletions
|
@ -2302,13 +2302,13 @@ static int CmdT55xxDump(const char *Cmd) {
|
||||||
static int CmdT55xxRestore(const char *Cmd) {
|
static int CmdT55xxRestore(const char *Cmd) {
|
||||||
CLIParserContext *ctx;
|
CLIParserContext *ctx;
|
||||||
CLIParserInit(&ctx, "lf t55xx restore",
|
CLIParserInit(&ctx, "lf t55xx restore",
|
||||||
"This command restores T55xx card page 0/1 n blocks",
|
"Restore T55xx card page 0/1 n blocks from (bin/eml/json) dump file",
|
||||||
"lf t55xx restore -f lf-t55xx-00148040-dump.bin"
|
"lf t55xx restore -f lf-t55xx-00148040-dump.bin"
|
||||||
);
|
);
|
||||||
|
|
||||||
void *argtable[] = {
|
void *argtable[] = {
|
||||||
arg_param_begin,
|
arg_param_begin,
|
||||||
arg_str0("f", "filename", "<fn>", "filename of the dump file (bin|eml)"),
|
arg_str0("f", "file", "<fn>", "filename of dump file"),
|
||||||
arg_str0("p", "pwd", "<hex>", "password if target card has password set (4 hex bytes)"),
|
arg_str0("p", "pwd", "<hex>", "password if target card has password set (4 hex bytes)"),
|
||||||
arg_param_end
|
arg_param_end
|
||||||
};
|
};
|
||||||
|
@ -2336,40 +2336,49 @@ static int CmdT55xxRestore(const char *Cmd) {
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
char ext[FILE_PATH_SIZE] = {0};
|
size_t dlen = 0;
|
||||||
uint32_t data[12] = {0};
|
uint8_t *dump = calloc(T55x7_BLOCK_COUNT * 4, sizeof(uint8_t));
|
||||||
size_t datalen = 0;
|
if (dump == NULL) {
|
||||||
|
PrintAndLogEx(WARNING, "Fail, cannot allocate memory");
|
||||||
|
return PM3_EMALLOC;
|
||||||
|
}
|
||||||
|
|
||||||
int retval = PM3_ESOFT;
|
DumpFileType_t dftype = getfiletype(filename);
|
||||||
if (fnlen > 4) { // Holds extension [.bin|.eml]
|
switch (dftype) {
|
||||||
memcpy(ext, &filename[fnlen - 4], 4);
|
case BIN: {
|
||||||
ext[5] = 0x00;
|
res = loadFile_safe(filename, ".bin", (void **)&dump, &dlen);
|
||||||
|
break;
|
||||||
// check if valid file extension and attempt to load data
|
}
|
||||||
if (memcmp(ext, ".bin", 4) == 0) {
|
case EML: {
|
||||||
filename[fnlen - 4] = 0x00;
|
res = loadFileEML_safe(filename, (void **)&dump, &dlen);
|
||||||
retval = loadFile(filename, ".bin", data, sizeof(data), &datalen);
|
break;
|
||||||
|
}
|
||||||
} else if (memcmp(ext, ".eml", 4) == 0) {
|
case JSON: {
|
||||||
filename[fnlen - 4] = 0x00;
|
res = loadFileJSON(filename, dump, T55x7_BLOCK_COUNT * 4, &dlen, NULL);
|
||||||
datalen = 12;
|
break;
|
||||||
retval = loadFileEML(filename, (uint8_t *)data, &datalen);
|
}
|
||||||
|
case DICTIONARY: {
|
||||||
} else {
|
PrintAndLogEx(ERR, "Error: Only BIN/EML/JSON formats allowed");
|
||||||
PrintAndLogEx(WARNING, "\nWarning: invalid dump filename "_YELLOW_("%s")" to restore!\n", filename);
|
free(dump);
|
||||||
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retval != PM3_SUCCESS) {
|
//sanity checks of file processing
|
||||||
return retval;
|
if (res != PM3_SUCCESS) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dlen != T55x7_BLOCK_COUNT * 4) {
|
||||||
|
free(dump);
|
||||||
|
PrintAndLogEx(FAILED, "wrong length of dump file. Expected 48 bytes, got %zu", dlen);
|
||||||
|
return PM3_EFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (datalen == T55x7_BLOCK_COUNT * 4) {
|
|
||||||
// 12 blocks * 4 bytes per block
|
// 12 blocks * 4 bytes per block
|
||||||
|
// this part creates strings to call "lf t55 write" command.
|
||||||
|
PrintAndLogEx(INFO, "Starting to write...");
|
||||||
|
|
||||||
// this fct creats strings to call "lf t55 write" command.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
uint8_t downlink_mode;
|
uint8_t downlink_mode;
|
||||||
char wcmd[100];
|
char wcmd[100];
|
||||||
char pwdopt [14] = {0}; // p XXXXXXXX
|
char pwdopt [14] = {0}; // p XXXXXXXX
|
||||||
|
@ -2377,6 +2386,7 @@ static int CmdT55xxRestore(const char *Cmd) {
|
||||||
if (usepwd)
|
if (usepwd)
|
||||||
snprintf(pwdopt, sizeof(pwdopt), "-p %08X", password);
|
snprintf(pwdopt, sizeof(pwdopt), "-p %08X", password);
|
||||||
|
|
||||||
|
uint32_t *data = (uint32_t*) dump;
|
||||||
uint8_t idx;
|
uint8_t idx;
|
||||||
// Restore endien for writing to card
|
// Restore endien for writing to card
|
||||||
for (idx = 0; idx < 12; idx++) {
|
for (idx = 0; idx < 12; idx++) {
|
||||||
|
@ -2423,7 +2433,7 @@ static int CmdT55xxRestore(const char *Cmd) {
|
||||||
if (CmdT55xxWriteBlock(wcmd) != PM3_SUCCESS) {
|
if (CmdT55xxWriteBlock(wcmd) != PM3_SUCCESS) {
|
||||||
PrintAndLogEx(WARNING, "Warning: error writing blk 0");
|
PrintAndLogEx(WARNING, "Warning: error writing blk 0");
|
||||||
}
|
}
|
||||||
}
|
PrintAndLogEx(INFO, "Done!");
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -2546,7 +2556,7 @@ char *GetBitRateStr(uint32_t id, bool xmode) {
|
||||||
|
|
||||||
char *retStr = buf;
|
char *retStr = buf;
|
||||||
if (xmode) { //xmode bitrate calc is same as em4x05 calc
|
if (xmode) { //xmode bitrate calc is same as em4x05 calc
|
||||||
snprintf(retStr, sizeof(buf), "%u - RF/%d", id, EM4x05_GET_BITRATE(id));
|
snprintf(retStr, sizeof(buf), "%u - RF/%u", id, EM4x05_GET_BITRATE(id));
|
||||||
} else {
|
} else {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -3012,7 +3022,7 @@ static int CmdT55xxChkPwds(const char *Cmd) {
|
||||||
void *argtable[4 + 6] = {
|
void *argtable[4 + 6] = {
|
||||||
arg_param_begin,
|
arg_param_begin,
|
||||||
arg_lit0("m", "fm", "use dictionary from flash memory (RDV4)"),
|
arg_lit0("m", "fm", "use dictionary from flash memory (RDV4)"),
|
||||||
arg_str0("f", "file", "<filename>", "file name"),
|
arg_str0("f", "file", "<fn>", "file name"),
|
||||||
arg_str0(NULL, "em", "<hex>", "EM4100 ID (5 hex bytes)"),
|
arg_str0(NULL, "em", "<hex>", "EM4100 ID (5 hex bytes)"),
|
||||||
};
|
};
|
||||||
uint8_t idx = 4;
|
uint8_t idx = 4;
|
||||||
|
@ -3937,6 +3947,15 @@ static int CmdT55xxSniff(const char *Cmd) {
|
||||||
int opt_width0 = arg_get_int_def(ctx, 4, -1);
|
int opt_width0 = arg_get_int_def(ctx, 4, -1);
|
||||||
CLIParserFree(ctx);
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
|
if (opt_width0 == 0) {
|
||||||
|
PrintAndLogEx(ERR, "Must call with --zero larger than 0");
|
||||||
|
return PM3_EINVARG;
|
||||||
|
}
|
||||||
|
if ((opt_width0 == 0) || (opt_width1 == 0)) {
|
||||||
|
PrintAndLogEx(ERR, "Must call with --one larger than 0");
|
||||||
|
return PM3_EINVARG;
|
||||||
|
}
|
||||||
|
|
||||||
if (opt_width0 > 0 && opt_width1 == -1) {
|
if (opt_width0 > 0 && opt_width1 == -1) {
|
||||||
PrintAndLogEx(ERR, _RED_("Missing sample width for ONE"));
|
PrintAndLogEx(ERR, _RED_("Missing sample width for ONE"));
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
|
@ -3947,15 +3966,6 @@ static int CmdT55xxSniff(const char *Cmd) {
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opt_width0 == 0) {
|
|
||||||
PrintAndLogEx(ERR, "Must call with --zero larger than 0");
|
|
||||||
return PM3_EINVARG;
|
|
||||||
}
|
|
||||||
if ((opt_width0 == 0) || (opt_width1 == 0)) {
|
|
||||||
PrintAndLogEx(ERR, "Must call with --one larger than 0");
|
|
||||||
return PM3_EINVARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t width1 = 0;
|
uint8_t width1 = 0;
|
||||||
uint8_t width0 = 0;
|
uint8_t width0 = 0;
|
||||||
|
|
||||||
|
@ -3993,15 +4003,10 @@ static int CmdT55xxSniff(const char *Cmd) {
|
||||||
00 01 10 11
|
00 01 10 11
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool have_data = false;
|
|
||||||
uint8_t page, blockAddr;
|
uint8_t page, blockAddr;
|
||||||
uint16_t dataLen = 0;
|
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
uint32_t usedPassword, blockData;
|
uint32_t usedPassword, blockData;
|
||||||
int pulseSamples = 0;
|
int pulseSamples = 0, pulseIdx = 0;
|
||||||
int pulseIdx = 0;
|
|
||||||
int minWidth = 1000;
|
|
||||||
int maxWidth = 0;
|
|
||||||
char modeText[100];
|
char modeText[100];
|
||||||
char pwdText[100];
|
char pwdText[100];
|
||||||
char dataText[100];
|
char dataText[100];
|
||||||
|
@ -4024,11 +4029,11 @@ static int CmdT55xxSniff(const char *Cmd) {
|
||||||
// loop though sample buffer
|
// loop though sample buffer
|
||||||
while (idx < GraphTraceLen) {
|
while (idx < GraphTraceLen) {
|
||||||
|
|
||||||
minWidth = 1000;
|
int minWidth = 1000;
|
||||||
maxWidth = 0;
|
int maxWidth = 0;
|
||||||
dataLen = 0;
|
uint16_t dataLen = 0;
|
||||||
data[0] = 0;
|
data[0] = 0;
|
||||||
have_data = false;
|
bool have_data = false;
|
||||||
sprintf(modeText, "Default");
|
sprintf(modeText, "Default");
|
||||||
sprintf(pwdText, " ");
|
sprintf(pwdText, " ");
|
||||||
sprintf(dataText, " ");
|
sprintf(dataText, " ");
|
||||||
|
@ -4110,7 +4115,6 @@ static int CmdT55xxSniff(const char *Cmd) {
|
||||||
// printf ("Fixed | Data end of 80 samples | offset : %llu - datalen %-2d - data : %s --- - Bit 0 width : %d\n",idx,dataLen,data,pulseBuffer[0]);
|
// printf ("Fixed | Data end of 80 samples | offset : %llu - datalen %-2d - data : %s --- - Bit 0 width : %d\n",idx,dataLen,data,pulseBuffer[0]);
|
||||||
|
|
||||||
if (data[0] == '0') { // should never get here..
|
if (data[0] == '0') { // should never get here..
|
||||||
dataLen = 0;
|
|
||||||
data[0] = 0;
|
data[0] = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue