From 7423c59c5f09cd99170daad83ace62eea34b712a Mon Sep 17 00:00:00 2001 From: tcprst Date: Sat, 28 Nov 2020 17:37:23 -0500 Subject: [PATCH] hf lto info, dump - now use cliparser --- client/src/cmdhflto.c | 88 ++++++++++++------------------------------- doc/cliparser_todo.md | 2 - 2 files changed, 25 insertions(+), 65 deletions(-) diff --git a/client/src/cmdhflto.c b/client/src/cmdhflto.c index 69dab2108..28c71c37f 100644 --- a/client/src/cmdhflto.c +++ b/client/src/cmdhflto.c @@ -13,6 +13,7 @@ #include #include #include +#include "cliparser.h" #include "cmdparser.h" // command_t #include "comms.h" #include "cmdtrace.h" @@ -36,16 +37,6 @@ static int CmdHelp(const char *Cmd); -static int usage_lto_info(void) { - PrintAndLogEx(NORMAL, "Usage: hf lto info [h]"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h this help"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf lto info")); - return PM3_SUCCESS; -} - static int usage_lto_rdbl(void) { PrintAndLogEx(NORMAL, "Usage: hf lto rdbl [h] s e "); PrintAndLogEx(NORMAL, "Options:"); @@ -70,17 +61,6 @@ static int usage_lto_wrbl(void) { return PM3_SUCCESS; } -static int usage_lto_dump(void) { - PrintAndLogEx(NORMAL, "Usage: hf lto dump [h|p] f "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h this help"); - PrintAndLogEx(NORMAL, " f file name"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hf lto dump f myfile")); - return PM3_SUCCESS; -} - static int usage_lto_restore(void) { PrintAndLogEx(NORMAL, "Usage: hf lto restore [h] f "); PrintAndLogEx(NORMAL, "Options:"); @@ -173,24 +153,16 @@ static int lto_select(uint8_t *id_response, uint8_t id_len, uint8_t *type_respon } static int CmdHfLTOInfo(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf lto info", + "Get info from LTO tags", + "hf lto info"); - uint8_t cmdp = 0; - bool errors = false; - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': - return usage_lto_info(); - default: - PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } - } - - //Validations - if (errors) { - return usage_lto_info(); - } + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); return infoLTO(true); } @@ -504,35 +476,25 @@ int dumpLTO(uint8_t *dump, bool verbose) { } static int CmdHfLTODump(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "hf lto dump", + "Dump data from LTO tag", + "hf lto dump -f myfile"); - uint8_t cmdp = 0; - bool errors = false; - uint32_t dump_len = CM_MEM_MAX_SIZE; + void *argtable[] = { + arg_param_begin, + arg_str1("f", "file", "", "specify a filename for dumpfile"), + 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, FILE_PATH_SIZE, &fnlen); - while (param_getchar(Cmd, cmdp) != 0x00 && !errors) { - switch (tolower(param_getchar(Cmd, cmdp))) { - case 'h': - return usage_lto_dump(); - case 'f': - if (param_getstr(Cmd, cmdp + 1, filename, FILE_PATH_SIZE) >= FILE_PATH_SIZE) { - PrintAndLogEx(FAILED, "filename too long"); - errors = true; - break; - } - cmdp += 2; - break; - default: - PrintAndLogEx(WARNING, "unknown parameter '%c'", param_getchar(Cmd, cmdp)); - errors = true; - break; - } - } + CLIParserFree(ctx); - if (errors) { - usage_lto_dump(); - return PM3_EINVARG; - } + uint32_t dump_len = CM_MEM_MAX_SIZE; uint8_t *dump = calloc(dump_len, sizeof(uint8_t)); if (!dump) { diff --git a/doc/cliparser_todo.md b/doc/cliparser_todo.md index a02619f13..ce009de1a 100644 --- a/doc/cliparser_todo.md +++ b/doc/cliparser_todo.md @@ -101,9 +101,7 @@ hf legic crc hf legic eload hf legic esave hf legic wipe -hf lto dump hf lto restore -hf lto info hf lto rdbl hf lto wrbl hf lto list