From 85b1a833fc00ecc8f3d18bfca11440c536ec6147 Mon Sep 17 00:00:00 2001 From: tcprst Date: Mon, 21 Dec 2020 12:17:05 -0500 Subject: [PATCH 1/6] hf legic wipe - now use cliparser --- client/src/cmdhflegic.c | 25 +++++++++++-------------- doc/cliparser_todo.txt | 1 - 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/client/src/cmdhflegic.c b/client/src/cmdhflegic.c index 00eff936d..dd4dde731 100644 --- a/client/src/cmdhflegic.c +++ b/client/src/cmdhflegic.c @@ -86,17 +86,6 @@ static int usage_legic_esave(void) { PrintAndLogEx(NORMAL, _YELLOW_(" hf legic esave 2 f myfile")); return PM3_SUCCESS; } -static int usage_legic_wipe(void) { - PrintAndLogEx(NORMAL, "Fills a LEGIC Prime tags memory with zeros. From byte7 and to the end"); - PrintAndLogEx(NORMAL, "It autodetects card type\n"); - PrintAndLogEx(NORMAL, "Usage: hf legic wipe [h]\n"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : this help"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf legic wipe")); - return PM3_SUCCESS; -} static bool legic_xor(uint8_t *data, uint16_t cardsize) { @@ -1198,10 +1187,18 @@ static int CmdLegicESave(const char *Cmd) { } static int CmdLegicWipe(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf legic wipe", + "Fills a LEGIC Prime tags memory with zeros. From byte7 and to the end\n" + "It autodetects card type", + "hf legic wipe"); - char cmdp = tolower(param_getchar(Cmd, 0)); - - if (cmdp == 'h') return usage_legic_wipe(); + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); // tagtype legic_card_select_t card; diff --git a/doc/cliparser_todo.txt b/doc/cliparser_todo.txt index 30e4578e2..3b636db91 100644 --- a/doc/cliparser_todo.txt +++ b/doc/cliparser_todo.txt @@ -78,7 +78,6 @@ hf legic dump hf legic restore hf legic eload hf legic esave -hf legic wipe hf mf darkside hf mf nested hf mf hardnested From 2f1408d65980291761c83402d1252c1af5632037 Mon Sep 17 00:00:00 2001 From: tcprst Date: Mon, 21 Dec 2020 12:41:14 -0500 Subject: [PATCH 2/6] hf legic dump - now use cliparser --- client/luascripts/hf_legic.lua | 2 +- client/src/cmdhflegic.c | 75 ++++++++++++---------------------- doc/cliparser_todo.txt | 1 - 3 files changed, 26 insertions(+), 52 deletions(-) diff --git a/client/luascripts/hf_legic.lua b/client/luascripts/hf_legic.lua index 744372f83..b8b9931cd 100644 --- a/client/luascripts/hf_legic.lua +++ b/client/luascripts/hf_legic.lua @@ -710,7 +710,7 @@ function readFromPM3() local tag, bytes, infile --infile="legic.temp" infile=os.tmpname() - core.console("hf legic dump f "..infile) + core.console("hf legic dump -f "..infile) tag=readFile(infile..".bin") os.remove(infile) os.remove(infile..".bin") diff --git a/client/src/cmdhflegic.c b/client/src/cmdhflegic.c index dd4dde731..09bbdf90b 100644 --- a/client/src/cmdhflegic.c +++ b/client/src/cmdhflegic.c @@ -28,22 +28,6 @@ static int CmdHelp(const char *Cmd); #define MAX_LENGTH 1024 -static int usage_legic_dump(void) { - PrintAndLogEx(NORMAL, "Read all memory from LEGIC Prime MIM22, MIM256, MIM1024"); - PrintAndLogEx(NORMAL, "and saves bin/eml/json dump file"); - PrintAndLogEx(NORMAL, "It autodetects card type.\n"); - PrintAndLogEx(NORMAL, "Usage: hf legic dump [h] [x] [f ]\n"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : this help"); - PrintAndLogEx(NORMAL, " f : filename w/o '.bin' to dump bytes"); - PrintAndLogEx(NORMAL, " x : deobfuscate dump data (xor with MCC)"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf legic dump - uses UID as filename")); - PrintAndLogEx(NORMAL, _YELLOW_(" hf legic dump f myfile")); - PrintAndLogEx(NORMAL, _YELLOW_(" hf legic dump x")); - return PM3_SUCCESS; -} 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"); @@ -813,38 +797,29 @@ static int CmdLegicReader(const char *Cmd) { } static int CmdLegicDump(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf legic dump", + "Read all memory from LEGIC Prime MIM22, MIM256, MIM1024 and saves bin/eml/json dump file\n" + "It autodetects card type.", + "hf legic dump <-- use UID as filename\n" + "hf legic dump -f myfile <-- use user specified filename\n" + "hf legic dump --deobfuscate <-- use UID as filename and deobfuscate data"); - int fileNameLen = 0; - char filename[FILE_PATH_SIZE] = {0x00}; - char *fptr = filename; - bool errors = false, shall_deobsfuscate = false; - uint16_t dumplen; - uint8_t cmdp = 0; + void *argtable[] = { + arg_param_begin, + arg_str0("f", "file", "", "specify a filename for dump file"), + arg_lit0(NULL, "deobfuscate", "deobfuscate dump data (xor with MCC)"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': - return usage_legic_dump(); - case 'f': - fileNameLen = param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE); - if (!fileNameLen) - errors = true; - if (fileNameLen > FILE_PATH_SIZE - 5) - fileNameLen = FILE_PATH_SIZE - 5; - cmdp += 2; - break; - case 'x': - shall_deobsfuscate = true; - cmdp++; - break; - default: - PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } - } - //Validations - if (errors) return usage_legic_dump(); + int fnlen = 0; + char filename[FILE_PATH_SIZE] = {0}; + CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); + + bool shall_deobsfuscate = arg_get_lit(ctx, 2); + + CLIParserFree(ctx); // tagtype legic_card_select_t card; @@ -852,7 +827,7 @@ static int CmdLegicDump(const char *Cmd) { PrintAndLogEx(WARNING, "Failed to identify tagtype"); return PM3_ESOFT; } - dumplen = card.cardsize; + uint16_t dumplen = card.cardsize; legic_print_type(dumplen, 0); PrintAndLogEx(SUCCESS, "Reading tag memory %d b...", dumplen); @@ -896,10 +871,10 @@ static int CmdLegicDump(const char *Cmd) { } // user supplied filename? - if (fileNameLen < 1) { + if (fnlen < 1) { PrintAndLogEx(INFO, "Using UID as filename"); - fptr += snprintf(fptr, sizeof(filename), "hf-legic-"); - FillFileNameByUID(fptr, data, "-dump", 4); + strcat(filename, "hf-legic-"); + FillFileNameByUID(filename, data, "-dump", 4); } if (shall_deobsfuscate) { diff --git a/doc/cliparser_todo.txt b/doc/cliparser_todo.txt index 3b636db91..d78d347aa 100644 --- a/doc/cliparser_todo.txt +++ b/doc/cliparser_todo.txt @@ -74,7 +74,6 @@ hf felica resetmode hf felica litesim hf felica litedump hf fido info -hf legic dump hf legic restore hf legic eload hf legic esave From ef2dfc8b3b75c7ba1a58256fd344a15732df76b4 Mon Sep 17 00:00:00 2001 From: tcprst Date: Mon, 21 Dec 2020 12:50:12 -0500 Subject: [PATCH 3/6] hf legic restore - now use cliparser --- client/luascripts/hf_legic_clone.lua | 2 +- client/src/cmdhflegic.c | 68 ++++++++-------------------- doc/cliparser_todo.txt | 1 - 3 files changed, 21 insertions(+), 50 deletions(-) diff --git a/client/luascripts/hf_legic_clone.lua b/client/luascripts/hf_legic_clone.lua index ec0c78d25..ec651d35c 100644 --- a/client/luascripts/hf_legic_clone.lua +++ b/client/luascripts/hf_legic_clone.lua @@ -456,7 +456,7 @@ local function writeToTag(plainBytes) -- write data to file if (writeOutputBytes(bytes, "hf-legic-UID-dump.bin")) then -- 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) end end diff --git a/client/src/cmdhflegic.c b/client/src/cmdhflegic.c index 09bbdf90b..95b9567a1 100644 --- a/client/src/cmdhflegic.c +++ b/client/src/cmdhflegic.c @@ -28,19 +28,6 @@ static int CmdHelp(const char *Cmd); #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 ]\n"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : this help"); - PrintAndLogEx(NORMAL, " f : 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) { PrintAndLogEx(NORMAL, "It loads a binary dump into emulator memory\n"); PrintAndLogEx(NORMAL, "Usage: hf legic eload [h] [card memory] [f ]\n"); @@ -891,44 +878,28 @@ static int CmdLegicDump(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}; - bool errors = false, shall_obsfuscate = false, have_filename = false; - size_t numofbytes; - uint8_t cmdp = 0; + void *argtable[] = { + arg_param_begin, + arg_str1("f", "file", "", "specify a filename to restore"), + 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) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': { - 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; + int fnlen = 0; + char filename[FILE_PATH_SIZE] = {0}; + CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); - //Validations - if (errors || cmdp == 0) return usage_legic_restore(); + bool shall_obsfuscate = arg_get_lit(ctx, 2); + + CLIParserFree(ctx); // tagtype legic_card_select_t card; @@ -946,6 +917,7 @@ static int CmdLegicRestore(const char *Cmd) { return PM3_EMALLOC; } + size_t numofbytes; if (loadFile_safe(filename, ".bin", (void **)&data, &numofbytes) != PM3_SUCCESS) { free(data); PrintAndLogEx(WARNING, "Error, reading file"); diff --git a/doc/cliparser_todo.txt b/doc/cliparser_todo.txt index d78d347aa..debef93fb 100644 --- a/doc/cliparser_todo.txt +++ b/doc/cliparser_todo.txt @@ -74,7 +74,6 @@ hf felica resetmode hf felica litesim hf felica litedump hf fido info -hf legic restore hf legic eload hf legic esave hf mf darkside From cd972adce5e4682439c159fbe24cfd43e4b4119b Mon Sep 17 00:00:00 2001 From: tcprst Date: Mon, 21 Dec 2020 14:50:42 -0500 Subject: [PATCH 4/6] hf legic eload - now use cliparser --- client/luascripts/hf_legic_clone.lua | 2 +- client/src/cmdhflegic.c | 99 +++++++++++----------------- doc/cliparser_todo.txt | 1 - 3 files changed, 38 insertions(+), 64 deletions(-) diff --git a/client/luascripts/hf_legic_clone.lua b/client/luascripts/hf_legic_clone.lua index ec651d35c..757d65fa0 100644 --- a/client/luascripts/hf_legic_clone.lua +++ b/client/luascripts/hf_legic_clone.lua @@ -530,7 +530,7 @@ local function main(args) res = res .."\ncreated clone_dump from\n\t"..infile.." crc: "..oldcrc.."\ndump_file:" res = res .."\n\t"..outfile.." crc: "..string.sub(newcrc, -2) res = res .."\nyou may load the new file with:" - res = res ..ansicolors.yellow.."hf legic eload f "..outfile..ansicolors.reset + res = res ..ansicolors.yellow.."hf legic eload -f "..outfile..ansicolors.reset res = res .."\n\nif you don't write to tag immediately ('-w' switch) you will need to recalculate each segmentCRC" res = res .."\nafter writing this dump to a tag!" res = res .."\n\na segmentCRC gets calculated over MCD,MSN0..3, Segment-Header0..3" diff --git a/client/src/cmdhflegic.c b/client/src/cmdhflegic.c index 95b9567a1..3a95621e2 100644 --- a/client/src/cmdhflegic.c +++ b/client/src/cmdhflegic.c @@ -28,20 +28,6 @@ static int CmdHelp(const char *Cmd); #define MAX_LENGTH 1024 -static int usage_legic_eload(void) { - PrintAndLogEx(NORMAL, "It loads a binary dump into emulator memory\n"); - PrintAndLogEx(NORMAL, "Usage: hf legic eload [h] [card memory] [f ]\n"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : this help"); - PrintAndLogEx(NORMAL, " [card memory] : 0 = MIM22"); - PrintAndLogEx(NORMAL, " : 1 = MIM256 (default)"); - PrintAndLogEx(NORMAL, " : 2 = MIM1024"); - PrintAndLogEx(NORMAL, " f : filename w/o .bin to load"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf legic eload 2 f myfile")); - return PM3_SUCCESS; -} static int usage_legic_esave(void) { PrintAndLogEx(NORMAL, "It saves bin/eml/json dump file of emulator memory\n"); PrintAndLogEx(NORMAL, "Usage: hf legic esave [h] [card memory] f \n"); @@ -978,58 +964,47 @@ static int CmdLegicRestore(const char *Cmd) { } static int CmdLegicELoad(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf legic eload", + "Loads a LEGIC binary dump into emulator memory", + "hf legic eload -f myfile -t 0 <- Simulate Type MIM22\n" + "hf legic eload -f myfile -t 1 <- Simulate Type MIM256 (default)\n" + "hf legic eload -f myfile -t 2 <- Simulate Type MIM1024"); - size_t numofbytes = 256; - char filename[FILE_PATH_SIZE] = {0x00}; - bool errors = false, shall_obsfuscate = false, have_filename = false; - uint8_t cmdp = 0; + void *argtable[] = { + arg_param_begin, + arg_str1("f", "file", "", "Specify a filename to restore"), + arg_int0("t", "type", "", "Tag type to simulate."), + 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) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h' : { - return usage_legic_eload(); - } - 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; - } - case '0' : { - numofbytes = 22; - cmdp++; - break; - } - case '1' : { - numofbytes = 256; - cmdp++; - break; - } - case '2' : { - numofbytes = 1024; - cmdp++; - break; - } - default : { - PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } - } + int fnlen = 0; + char filename[FILE_PATH_SIZE] = {0}; + CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); + + size_t numofbytes = 0; + + switch (arg_get_int_def(ctx, 2, 1)) { + case 0: + numofbytes = 22; + break; + case 1: + numofbytes = 256; + break; + case 2: + numofbytes = 1024; + break; + default: + PrintAndLogEx(ERR, "Unknown tag type"); + CLIParserFree(ctx); + return PM3_EINVARG; } - if (have_filename == false) - errors = true; - //Validations - if (errors || strlen(Cmd) == 0) return usage_legic_eload(); + bool shall_obsfuscate = arg_get_lit(ctx, 3); + + CLIParserFree(ctx); // set up buffer uint8_t *data = calloc(numofbytes, sizeof(uint8_t)); diff --git a/doc/cliparser_todo.txt b/doc/cliparser_todo.txt index debef93fb..00bb3781e 100644 --- a/doc/cliparser_todo.txt +++ b/doc/cliparser_todo.txt @@ -74,7 +74,6 @@ hf felica resetmode hf felica litesim hf felica litedump hf fido info -hf legic eload hf legic esave hf mf darkside hf mf nested From f1c4be446cf9230c542850efeb7bbab36a7d71e9 Mon Sep 17 00:00:00 2001 From: tcprst Date: Mon, 21 Dec 2020 15:00:02 -0500 Subject: [PATCH 5/6] hf legic esave - now use cliparser --- client/src/cmdhflegic.c | 101 +++++++++++++++++----------------------- doc/cliparser_todo.txt | 1 - 2 files changed, 42 insertions(+), 60 deletions(-) diff --git a/client/src/cmdhflegic.c b/client/src/cmdhflegic.c index 3a95621e2..512f2dd53 100644 --- a/client/src/cmdhflegic.c +++ b/client/src/cmdhflegic.c @@ -28,22 +28,6 @@ static int CmdHelp(const char *Cmd); #define MAX_LENGTH 1024 -static int usage_legic_esave(void) { - PrintAndLogEx(NORMAL, "It saves bin/eml/json dump file of emulator memory\n"); - PrintAndLogEx(NORMAL, "Usage: hf legic esave [h] [card memory] f \n"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : this help"); - PrintAndLogEx(NORMAL, " [card memory] : 0 = MIM22"); - PrintAndLogEx(NORMAL, " : 1 = MIM256 (default)"); - PrintAndLogEx(NORMAL, " : 2 = MIM1024"); - PrintAndLogEx(NORMAL, " f : filename w/o .bin to load"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf legic esave 2 - uses UID as filename")); - PrintAndLogEx(NORMAL, _YELLOW_(" hf legic esave 2 f myfile")); - return PM3_SUCCESS; -} - static bool legic_xor(uint8_t *data, uint16_t cardsize) { if (cardsize <= 22) { @@ -1032,49 +1016,48 @@ static int CmdLegicELoad(const char *Cmd) { } static int CmdLegicESave(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf legic esave", + "Saves bin/eml/json dump file of emulator memory", + "hf legic esave <- uses UID as filename\n" + "hf legic esave -f myfile -t 0 <- Type MIM22\n" + "hf legic esave -f myfile -t 1 <- Type MIM256 (default)\n" + "hf legic esave -f myfile -t 2 <- Type MIM1024"); + void *argtable[] = { + arg_param_begin, + arg_str0("f", "file", "", "Specify a filename to save"), + arg_int0("t", "type", "", "Tag type"), + arg_lit0(NULL, "deobfuscate", "De-obfuscate dump data (xor with MCC)"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + + int fnlen = 0; char filename[FILE_PATH_SIZE] = {0}; - char *fptr = filename; - int fileNameLen = 0; - size_t numofbytes = 256; - bool errors = false, shall_deobsfuscate = false; - uint8_t cmdp = 0; - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h' : - return usage_legic_esave(); - case 'f' : - fileNameLen = param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE); - if (!fileNameLen) - errors = true; - if (fileNameLen > FILE_PATH_SIZE - 5) - fileNameLen = FILE_PATH_SIZE - 5; - cmdp += 2; - break; - case 'x': - shall_deobsfuscate = true; - cmdp++; - break; - case '0' : - numofbytes = 22; - cmdp++; - break; - case '1' : - numofbytes = 256; - cmdp++; - break; - case '2' : - numofbytes = 1024; - cmdp++; - break; - default : - PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } + CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); + + size_t numofbytes = 0; + + switch (arg_get_int_def(ctx, 2, 1)) { + case 0: + numofbytes = 22; + break; + case 1: + numofbytes = 256; + break; + case 2: + numofbytes = 1024; + break; + default: + PrintAndLogEx(ERR, "Unknown tag type"); + CLIParserFree(ctx); + return PM3_EINVARG; } - //Validations - if (errors || strlen(Cmd) == 0) return usage_legic_esave(); + + bool shall_deobsfuscate = arg_get_lit(ctx, 3); + + CLIParserFree(ctx); // set up buffer uint8_t *data = calloc(numofbytes, sizeof(uint8_t)); @@ -1092,10 +1075,10 @@ static int CmdLegicESave(const char *Cmd) { } // user supplied filename? - if (fileNameLen < 1) { + if (fnlen < 1) { PrintAndLogEx(INFO, "Using UID as filename"); - fptr += snprintf(fptr, sizeof(filename), "hf-legic-"); - FillFileNameByUID(fptr, data, "-dump", 4); + strcat(filename, "hf-legic-"); + FillFileNameByUID(filename, data, "-dump", 4); } if (shall_deobsfuscate) { diff --git a/doc/cliparser_todo.txt b/doc/cliparser_todo.txt index 00bb3781e..daad348a5 100644 --- a/doc/cliparser_todo.txt +++ b/doc/cliparser_todo.txt @@ -74,7 +74,6 @@ hf felica resetmode hf felica litesim hf felica litedump hf fido info -hf legic esave hf mf darkside hf mf nested hf mf hardnested From fce36effb434489dba67dc12598939b89633fba4 Mon Sep 17 00:00:00 2001 From: tcprst Date: Mon, 21 Dec 2020 15:01:30 -0500 Subject: [PATCH 6/6] legic style --- client/src/cmdhflegic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/cmdhflegic.c b/client/src/cmdhflegic.c index 512f2dd53..709cf9390 100644 --- a/client/src/cmdhflegic.c +++ b/client/src/cmdhflegic.c @@ -969,7 +969,7 @@ static int CmdLegicELoad(const char *Cmd) { CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); size_t numofbytes = 0; - + switch (arg_get_int_def(ctx, 2, 1)) { case 0: numofbytes = 22; @@ -1038,7 +1038,7 @@ static int CmdLegicESave(const char *Cmd) { CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); size_t numofbytes = 0; - + switch (arg_get_int_def(ctx, 2, 1)) { case 0: numofbytes = 22;