mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
lf t55xx restore - now uses cliparser
This commit is contained in:
parent
d5ea600289
commit
450c7fab5b
1 changed files with 110 additions and 112 deletions
|
@ -209,20 +209,6 @@ static int usage_t55xx_info(void) {
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usage_t55xx_restore(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: lf t55xx restore f <filename> [p password]");
|
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
|
||||||
PrintAndLogEx(NORMAL, " f <filename> - filename of the dump file (.bin/.eml)");
|
|
||||||
PrintAndLogEx(NORMAL, " p <password> - optional password if target card has password set");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" Assumes lf t55 detect has been run first!"));
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" lf t55xx restore f lf-t55xx-00148040-dump.bin"));
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int usage_t55xx_clonehelp(void) {
|
static int usage_t55xx_clonehelp(void) {
|
||||||
PrintAndLogEx(NORMAL, "For cloning specific techs on T55xx tags, see commands available in corresponding LF sub-menus, e.g.:");
|
PrintAndLogEx(NORMAL, "For cloning specific techs on T55xx tags, see commands available in corresponding LF sub-menus, e.g.:");
|
||||||
PrintAndLogEx(NORMAL, _GREEN_("lf awid clone"));
|
PrintAndLogEx(NORMAL, _GREEN_("lf awid clone"));
|
||||||
|
@ -2197,7 +2183,7 @@ static int CmdT55xxDump(const char *Cmd) {
|
||||||
// 1 (help) + 3 (two user specified params) + (5 T55XX_DLMODE_SINGLE)
|
// 1 (help) + 3 (two user specified params) + (5 T55XX_DLMODE_SINGLE)
|
||||||
void *argtable[4 + 5] = {
|
void *argtable[4 + 5] = {
|
||||||
arg_param_begin,
|
arg_param_begin,
|
||||||
arg_str0("f", "filename", "<fn>", "filename (default is generated on blk 0"),
|
arg_str0("f", "filename", "<fn>", "filename (default is generated on blk 0)"),
|
||||||
arg_lit0("o", "override", "override, force pwd read despite danger to card"),
|
arg_lit0("o", "override", "override, force pwd read despite danger to card"),
|
||||||
arg_str0("p", "pwd", "<hex>", "password (4 hex bytes)"),
|
arg_str0("p", "pwd", "<hex>", "password (4 hex bytes)"),
|
||||||
};
|
};
|
||||||
|
@ -2297,78 +2283,88 @@ static int CmdT55xxDump(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdT55xxRestore(const char *Cmd) {
|
static int CmdT55xxRestore(const char *Cmd) {
|
||||||
bool errors = false;
|
CLIParserContext *ctx;
|
||||||
uint8_t cmdp = 0;
|
CLIParserInit(&ctx, "lf t55xx restore",
|
||||||
char preferredName[FILE_PATH_SIZE] = {0};
|
"This command restores T55xx card page 0/1 n blocks",
|
||||||
char ext[FILE_PATH_SIZE] = {0};
|
"lf t55xx restore -f lf-t55xx-00148040-dump.bin"
|
||||||
int success = PM3_ESOFT;
|
);
|
||||||
uint32_t password = 0x00;
|
|
||||||
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_str0("f", "filename", "<fn>", "filename of the dump file (bin|eml)"),
|
||||||
|
arg_str0("p", "pwd", "<hex>", "password if target card has password set (4 hex bytes)"),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||||
|
|
||||||
|
int fnlen = 0;
|
||||||
|
char filename[FILE_PATH_SIZE] = {0};
|
||||||
|
CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, sizeof(filename), &fnlen);
|
||||||
|
|
||||||
bool usepwd = false;
|
bool usepwd = false;
|
||||||
|
uint32_t password = 0;
|
||||||
|
int res = arg_get_u32_hexstr_def_nlen(ctx, 2, 0, &password, 4, true);
|
||||||
|
if (res == 0 || res == 2) {
|
||||||
|
PrintAndLogEx(ERR, "Password should be 4 hex bytes");
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
return PM3_EINVARG;
|
||||||
|
}
|
||||||
|
if (res == 1) {
|
||||||
|
usepwd = true;
|
||||||
|
}
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
|
if (fnlen == 0) {
|
||||||
|
PrintAndLogEx(ERR, "Must specify a filename");
|
||||||
|
return PM3_EINVARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
char ext[FILE_PATH_SIZE] = {0};
|
||||||
uint32_t data[12] = {0};
|
uint32_t data[12] = {0};
|
||||||
size_t datalen = 0;
|
size_t datalen = 0;
|
||||||
uint8_t blockidx;
|
|
||||||
|
int retval = PM3_ESOFT;
|
||||||
|
if (fnlen > 4) { // Holds extension [.bin|.eml]
|
||||||
|
memcpy(ext, &filename[fnlen - 4], 4);
|
||||||
|
ext[5] = 0x00;
|
||||||
|
|
||||||
|
// check if valid file extension and attempt to load data
|
||||||
|
if (memcmp(ext, ".bin", 4) == 0) {
|
||||||
|
filename[fnlen - 4] = 0x00;
|
||||||
|
retval = loadFile(filename, ".bin", data, sizeof(data), &datalen);
|
||||||
|
|
||||||
|
} else if (memcmp(ext, ".eml", 4) == 0) {
|
||||||
|
filename[fnlen - 4] = 0x00;
|
||||||
|
datalen = 12;
|
||||||
|
retval = loadFileEML(filename, (uint8_t *)data, &datalen);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
PrintAndLogEx(WARNING, "\nWarning: invalid dump filename "_YELLOW_("%s")" to restore!\n", filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (retval != PM3_SUCCESS) {
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (datalen == T55x7_BLOCK_COUNT * 4) {
|
||||||
|
// 12 blocks * 4 bytes per block
|
||||||
|
|
||||||
|
// this fct creats strings to call "lf t55 write" command.
|
||||||
|
//
|
||||||
|
//
|
||||||
uint8_t downlink_mode;
|
uint8_t downlink_mode;
|
||||||
char writeCmdOpt[100];
|
char writeCmdOpt[100];
|
||||||
char pwdOpt [11] = {0}; // p XXXXXXXX
|
char pwdOpt [11] = {0}; // p XXXXXXXX
|
||||||
|
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
|
||||||
case 'h':
|
|
||||||
return usage_t55xx_restore();
|
|
||||||
case 'f':
|
|
||||||
param_getstr(Cmd, cmdp + 1, preferredName, FILE_PATH_SIZE);
|
|
||||||
if (strlen(preferredName) == 0)
|
|
||||||
errors = true;
|
|
||||||
cmdp += 2;
|
|
||||||
break;
|
|
||||||
case 'p':
|
|
||||||
password = param_get32ex(Cmd, cmdp + 1, 0, 16);
|
|
||||||
usepwd = true;
|
|
||||||
cmdp += 2;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
|
||||||
errors = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// File name expected to be .eml .bin or .json so sould be at least 4
|
|
||||||
if (errors || (strlen(preferredName) == 0)) return usage_t55xx_restore();
|
|
||||||
|
|
||||||
// split file name into prefix and ext.
|
|
||||||
int fnLength;
|
|
||||||
|
|
||||||
fnLength = strlen(preferredName);
|
|
||||||
|
|
||||||
success = PM3_ESOFT;
|
|
||||||
if (fnLength > 4) { // Holds extension [.bin|.eml]
|
|
||||||
memcpy(ext, &preferredName[fnLength - 4], 4);
|
|
||||||
ext[5] = 0x00;
|
|
||||||
|
|
||||||
// check if valid file extension and attempt to load data
|
|
||||||
|
|
||||||
if (memcmp(ext, ".bin", 4) == 0) {
|
|
||||||
preferredName[fnLength - 4] = 0x00;
|
|
||||||
success = loadFile(preferredName, ".bin", data, sizeof(data), &datalen);
|
|
||||||
|
|
||||||
} else if (memcmp(ext, ".eml", 4) == 0) {
|
|
||||||
preferredName[fnLength - 4] = 0x00;
|
|
||||||
datalen = 12;
|
|
||||||
success = loadFileEML(preferredName, (uint8_t *)data, &datalen);
|
|
||||||
|
|
||||||
} else
|
|
||||||
PrintAndLogEx(WARNING, "\nWarning: invalid dump filename "_YELLOW_("%s")" to restore!\n", preferredName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (success == PM3_SUCCESS) { // Got data, so write to cards
|
|
||||||
if (datalen == T55x7_BLOCK_COUNT * 4) { // 12 blocks * 4 bytes per block
|
|
||||||
if (usepwd)
|
if (usepwd)
|
||||||
snprintf(pwdOpt, sizeof(pwdOpt), "p %08X", password);
|
snprintf(pwdOpt, sizeof(pwdOpt), "p %08X", password);
|
||||||
|
|
||||||
|
uint8_t idx;
|
||||||
// Restore endien for writing to card
|
// Restore endien for writing to card
|
||||||
for (blockidx = 0; blockidx < 12; blockidx++)
|
for (idx = 0; idx < 12; idx++) {
|
||||||
data[blockidx] = BSWAP_32(data[blockidx]);
|
data[idx] = BSWAP_32(data[idx]);
|
||||||
|
}
|
||||||
|
|
||||||
// Have data ready, lets write
|
// Have data ready, lets write
|
||||||
// Order
|
// Order
|
||||||
|
@ -2380,23 +2376,26 @@ static int CmdT55xxRestore(const char *Cmd) {
|
||||||
downlink_mode = (data[11] >> 10) & 3;
|
downlink_mode = (data[11] >> 10) & 3;
|
||||||
|
|
||||||
// write out blocks 1-7 page 0
|
// write out blocks 1-7 page 0
|
||||||
for (blockidx = 1; blockidx <= 7; blockidx++) {
|
for (idx = 1; idx <= 7; idx++) {
|
||||||
snprintf(writeCmdOpt, sizeof(writeCmdOpt), "b %d d %08X %s", blockidx, data[blockidx], pwdOpt);
|
snprintf(writeCmdOpt, sizeof(writeCmdOpt), "b %d d %08X %s", idx, data[idx], pwdOpt);
|
||||||
|
|
||||||
if (CmdT55xxWriteBlock(writeCmdOpt) != PM3_SUCCESS)
|
if (CmdT55xxWriteBlock(writeCmdOpt) != PM3_SUCCESS) {
|
||||||
PrintAndLogEx(WARNING, "Warning: error writing blk %d", blockidx);
|
PrintAndLogEx(WARNING, "Warning: error writing blk %d", idx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if password was set on the "blank" update as we may have just changed it
|
// if password was set on the "blank" update as we may have just changed it
|
||||||
if (usepwd)
|
if (usepwd) {
|
||||||
snprintf(pwdOpt, sizeof(pwdOpt), "p %08X", data[7]);
|
snprintf(pwdOpt, sizeof(pwdOpt), "p %08X", data[7]);
|
||||||
|
}
|
||||||
|
|
||||||
// write out blocks 1-3 page 1
|
// write out blocks 1-3 page 1
|
||||||
for (blockidx = 9; blockidx <= 11; blockidx++) {
|
for (idx = 9; idx <= 11; idx++) {
|
||||||
snprintf(writeCmdOpt, sizeof(writeCmdOpt), "b %d 1 d %08X %s", blockidx - 8, data[blockidx], pwdOpt);
|
snprintf(writeCmdOpt, sizeof(writeCmdOpt), "b %d 1 d %08X %s", idx - 8, data[idx], pwdOpt);
|
||||||
|
|
||||||
if (CmdT55xxWriteBlock(writeCmdOpt) != PM3_SUCCESS)
|
if (CmdT55xxWriteBlock(writeCmdOpt) != PM3_SUCCESS) {
|
||||||
PrintAndLogEx(WARNING, "Warning: error writing blk %d", blockidx);
|
PrintAndLogEx(WARNING, "Warning: error writing blk %d", idx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update downlink mode for the page 0 config write.
|
// Update downlink mode for the page 0 config write.
|
||||||
|
@ -2404,11 +2403,10 @@ static int CmdT55xxRestore(const char *Cmd) {
|
||||||
|
|
||||||
// Write the page 0 config
|
// Write the page 0 config
|
||||||
snprintf(writeCmdOpt, sizeof(writeCmdOpt), "b 0 d %08X %s", data[0], pwdOpt);
|
snprintf(writeCmdOpt, sizeof(writeCmdOpt), "b 0 d %08X %s", data[0], pwdOpt);
|
||||||
if (CmdT55xxWriteBlock(writeCmdOpt) != PM3_SUCCESS)
|
if (CmdT55xxWriteBlock(writeCmdOpt) != PM3_SUCCESS) {
|
||||||
PrintAndLogEx(WARNING, "Warning: error writing blk 0");
|
PrintAndLogEx(WARNING, "Warning: error writing blk 0");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue