From 4dea429157af1b2e1050fff2ba727ba2a5c73a21 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 19 Apr 2021 14:35:09 +0200 Subject: [PATCH] hf 14a list helptext handling by CmdTraceListAlias, to be generalized if ok --- client/src/cmdhf14a.c | 11 ++++++----- client/src/cmdtrace.c | 31 +++++++++++++++++++++++++++++++ client/src/cmdtrace.h | 1 + 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index cc7266db4..8c09b990c 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -171,12 +171,13 @@ static uint16_t frameLength = 0; uint16_t atsFSC[] = {16, 24, 32, 40, 48, 64, 96, 128, 256}; static int CmdHF14AList(const char *Cmd) { - char args[128] = {0}; - if (strlen(Cmd) == 0) { - snprintf(args, sizeof(args), "-t 14a"); - } else { - strncpy(args, Cmd, sizeof(args) - 1); + int ret = CmdTraceListAlias(Cmd, "hf 14a list"); + if (ret != PM3_SUCCESS) { + return ret; } + char args[128] = {0}; + snprintf(args, sizeof(args), "-t 14a "); + strncat(args, Cmd, sizeof(args) - strlen(args)); return CmdTraceList(args); } diff --git a/client/src/cmdtrace.c b/client/src/cmdtrace.c index 36314feb9..50f67ff05 100644 --- a/client/src/cmdtrace.c +++ b/client/src/cmdtrace.c @@ -591,6 +591,37 @@ static int CmdTraceSave(const char *Cmd) { return PM3_SUCCESS; } +int CmdTraceListAlias(const char *Cmd, const char *alias) { + CLIParserContext *ctx; + char example[200] = {0}; + sprintf(example, + "%s -f -> show frame delay times\n" + "%s -1 -> use trace buffer ", + alias, alias); + CLIParserInit(&ctx, alias, + "Alias of `trace list -t` with selected protocol data to annotate trace buffer\n" + "You can load a trace from file (see `trace load -h`) or it be downloaded from device by default\n" + "It accepts all other arguments of `trace list`. Note that some might not be relevant for this specific protocol", + example + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0("1", "buffer", "use data from trace buffer"), + arg_lit0("f", NULL, "show frame delay times"), + arg_lit0("c", NULL, "mark CRC bytes"), + arg_lit0("r", NULL, "show relative times (gap and duration)"), + arg_lit0("u", NULL, "display times in microseconds instead of clock cycles"), + arg_lit0("x", NULL, "show hexdump to convert to pcap(ng)\n" + " or to import into Wireshark using encapsulation type \"ISO 14443\""), + arg_strx0(NULL, "dict", "", "use dictionary keys file"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); + return PM3_SUCCESS; +} + int CmdTraceList(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "trace list", diff --git a/client/src/cmdtrace.h b/client/src/cmdtrace.h index acef66884..d4a9cd108 100644 --- a/client/src/cmdtrace.h +++ b/client/src/cmdtrace.h @@ -15,5 +15,6 @@ int CmdTrace(const char *Cmd); int CmdTraceList(const char *Cmd); +int CmdTraceListAlias(const char *Cmd, const char *alias); #endif