diff --git a/client/src/cmdhflegic.c b/client/src/cmdhflegic.c index b202ba170..bd63057ce 100644 --- a/client/src/cmdhflegic.c +++ b/client/src/cmdhflegic.c @@ -28,21 +28,6 @@ static int CmdHelp(const char *Cmd); #define MAX_LENGTH 1024 -static int usage_legic_rdbl(void) { - PrintAndLogEx(NORMAL, "Read data from a LEGIC Prime tag\n"); - PrintAndLogEx(NORMAL, "Usage: hf legic rdbl [h] [o ] [l ] [iv ]\n"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h : this help"); - PrintAndLogEx(NORMAL, " o : (hex) offset in data array to start download from"); - PrintAndLogEx(NORMAL, " l : (hex) number of bytes to read"); - PrintAndLogEx(NORMAL, " i : (hex) (optional) Initialization vector to use. Must be odd and 7bits max"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf legic rdbl o 0 l 16 - reads from byte[0] 0x16 bytes(system header)")); - PrintAndLogEx(NORMAL, _YELLOW_(" hf legic rdbl o 0 l 4 iv 55 - reads from byte[0] 0x4 bytes with IV 0x55")); - PrintAndLogEx(NORMAL, _YELLOW_(" hf legic rdbl o 0 l 100 iv 55 - reads 0x100 bytes with IV 0x55")); - return PM3_SUCCESS; -} static int usage_legic_sim(void) { PrintAndLogEx(NORMAL, "Simulates a LEGIC Prime tag. MIM22, MIM256, MIM1024 types can be emulated"); PrintAndLogEx(NORMAL, "Use " _YELLOW_("`hf legic eload`") " to upload a dump into emulator memory\n"); @@ -512,34 +497,32 @@ out: // offset in data memory // number of bytes to read static int CmdLegicRdbl(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf legic rdbl", + "Read data from a LEGIC Prime tag", + "hf legic rdbl -o 0 -l 16 <- reads from byte[0] 16 bytes(system header)\n" + "hf legic rdbl -o 0 -l 4 --iv 55 <- reads from byte[0] 4 bytes with IV 0x55\n" + "hf legic rdbl -o 0 -l 256 --iv 55 <- reads from byte[0] 256 bytes with IV 0x55"); - uint32_t offset = 0, len = 0, iv = 1; - bool errors = false; - uint8_t cmdp = 0; - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h' : - return usage_legic_rdbl(); - case 'o' : - offset = param_get32ex(Cmd, cmdp + 1, 0, 16); - cmdp += 2; - break; - case 'l' : - len = param_get32ex(Cmd, cmdp + 1, 0, 16); - cmdp += 2; - break; - case 'i' : - iv = param_get32ex(Cmd, cmdp + 1, 1, 16); - cmdp += 2; - break; - default : - PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } - } - //Validations - if (errors || strlen(Cmd) == 0) return usage_legic_rdbl(); + void *argtable[] = { + arg_param_begin, + arg_int1("o", "offset", "", "offset in data array to start download from"), + arg_int1("l", "length", "", "number of bytes to read"), + arg_str0(NULL, "iv", "", "Initialization vector to use. Must be odd and 7bits max"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + + int offset = arg_get_int_def(ctx, 1, 0); + + int len = arg_get_int_def(ctx, 2, 0); + + int iv_len = 0; + uint8_t iv[1] = {0x01}; // formerly uidcrc + + CLIGetHexWithReturn(ctx, 3, iv, &iv_len); + + CLIParserFree(ctx); // sanity checks if (len + offset >= MAX_LENGTH) { @@ -557,9 +540,9 @@ static int CmdLegicRdbl(const char *Cmd) { } uint16_t datalen = 0; - int status = legic_read_mem(offset, len, iv, data, &datalen); + int status = legic_read_mem(offset, len, iv[0], data, &datalen); if (status == PM3_SUCCESS) { - PrintAndLogEx(NORMAL, "\n ## | 0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F"); + PrintAndLogEx(NORMAL, " ## | 0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F"); PrintAndLogEx(NORMAL, "-----+------------------------------------------------------------------------------------------------"); print_hex_break(data, datalen, 32); } diff --git a/doc/cliparser_todo.txt b/doc/cliparser_todo.txt index 6e06c5278..c8a21d606 100644 --- a/doc/cliparser_todo.txt +++ b/doc/cliparser_todo.txt @@ -82,7 +82,6 @@ hf legic reader hf legic info hf legic dump hf legic restore -hf legic rdbl hf legic sim hf legic wrbl hf legic eload