hf legic restore - now use cliparser

This commit is contained in:
tcprst 2020-12-21 12:50:12 -05:00
parent 2f1408d659
commit ef2dfc8b3b
No known key found for this signature in database
GPG key ID: 9145EAF5121AED25
3 changed files with 21 additions and 50 deletions

View file

@ -456,7 +456,7 @@ local function writeToTag(plainBytes)
-- write data to file -- write data to file
if (writeOutputBytes(bytes, "hf-legic-UID-dump.bin")) then if (writeOutputBytes(bytes, "hf-legic-UID-dump.bin")) then
-- write pm3-buffer to Tag -- write pm3-buffer to Tag
cmd = ('hf legic restore f hf-legic-UID-dump') cmd = ('hf legic restore -f hf-legic-UID-dump')
core.console(cmd) core.console(cmd)
end end
end end

View file

@ -28,19 +28,6 @@ static int CmdHelp(const char *Cmd);
#define MAX_LENGTH 1024 #define MAX_LENGTH 1024
static int usage_legic_restore(void) {
PrintAndLogEx(NORMAL, "Reads binary file and it autodetects card type and verifies that the file has the same size");
PrintAndLogEx(NORMAL, "Then write the data back to card. All bytes except the first 7bytes [UID(4) MCC(1) DCF(2)]\n");
PrintAndLogEx(NORMAL, "Usage: hf legic restore [h] [x] [f <filename w/o .bin>]\n");
PrintAndLogEx(NORMAL, "Options:");
PrintAndLogEx(NORMAL, " h : this help");
PrintAndLogEx(NORMAL, " f <filename> : filename w/o '.bin' to restore bytes on to card from");
PrintAndLogEx(NORMAL, " x : obfuscate dump data (xor with MCC)");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, _YELLOW_(" hf legic restore f myfile"));
return PM3_SUCCESS;
}
static int usage_legic_eload(void) { static int usage_legic_eload(void) {
PrintAndLogEx(NORMAL, "It loads a binary dump into emulator memory\n"); PrintAndLogEx(NORMAL, "It loads a binary dump into emulator memory\n");
PrintAndLogEx(NORMAL, "Usage: hf legic eload [h] [card memory] [f <file name w/o `.bin`>]\n"); PrintAndLogEx(NORMAL, "Usage: hf legic eload [h] [card memory] [f <file name w/o `.bin`>]\n");
@ -891,44 +878,28 @@ static int CmdLegicDump(const char *Cmd) {
} }
static int CmdLegicRestore(const char *Cmd) { static int CmdLegicRestore(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf legic restore",
"Reads binary file and it autodetects card type and verifies that the file has the same size\n"
"Then write the data back to card. All bytes except the first 7bytes [UID(4) MCC(1) DCF(2)]",
"hf legic restore -f myfile <-- use user specified filename\n"
"hf legic restore -f myfile --obfuscate <-- use UID as filename and deobfuscate data");
char filename[FILE_PATH_SIZE] = {0x00}; void *argtable[] = {
bool errors = false, shall_obsfuscate = false, have_filename = false; arg_param_begin,
size_t numofbytes; arg_str1("f", "file", "<filename>", "specify a filename to restore"),
uint8_t cmdp = 0; arg_lit0(NULL, "obfuscate", "obfuscate dump data (xor with MCC)"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { int fnlen = 0;
switch (tolower(param_getchar(Cmd, cmdp))) { char filename[FILE_PATH_SIZE] = {0};
case 'h': { CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
errors = true;
break;
}
case 'f': {
if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) {
PrintAndLogEx(FAILED, "Filename too long");
break;
}
have_filename = true;
cmdp += 2;
break;
}
case 'x': {
shall_obsfuscate = true;
cmdp++;
break;
}
default: {
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
errors = true;
break;
}
}
}
if (have_filename == false)
errors = true;
//Validations bool shall_obsfuscate = arg_get_lit(ctx, 2);
if (errors || cmdp == 0) return usage_legic_restore();
CLIParserFree(ctx);
// tagtype // tagtype
legic_card_select_t card; legic_card_select_t card;
@ -946,6 +917,7 @@ static int CmdLegicRestore(const char *Cmd) {
return PM3_EMALLOC; return PM3_EMALLOC;
} }
size_t numofbytes;
if (loadFile_safe(filename, ".bin", (void **)&data, &numofbytes) != PM3_SUCCESS) { if (loadFile_safe(filename, ".bin", (void **)&data, &numofbytes) != PM3_SUCCESS) {
free(data); free(data);
PrintAndLogEx(WARNING, "Error, reading file"); PrintAndLogEx(WARNING, "Error, reading file");

View file

@ -74,7 +74,6 @@ hf felica resetmode
hf felica litesim hf felica litesim
hf felica litedump hf felica litedump
hf fido info hf fido info
hf legic restore
hf legic eload hf legic eload
hf legic esave hf legic esave
hf mf darkside hf mf darkside