From 9db2a04449a6cb89881ea540146a1726ea4102c7 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 13 Dec 2020 01:44:03 +0100 Subject: [PATCH] fix: rem - now handles cliparse and strings correct --- client/src/cmdmain.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/client/src/cmdmain.c b/client/src/cmdmain.c index 9b26512f1..4d393756f 100644 --- a/client/src/cmdmain.c +++ b/client/src/cmdmain.c @@ -165,19 +165,35 @@ int CmdRem(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "rem", "Add a text line in log file", - "rem" + "rem my message -> adds a timestamp with `my message`" ); void *argtable[] = { arg_param_begin, + arg_strx1(NULL, NULL, NULL, "message line you want inserted"), arg_param_end }; - CLIExecWithReturn(ctx, Cmd, argtable, true); - CLIParserFree(ctx); + CLIExecWithReturn(ctx, Cmd, argtable, false); + struct arg_str* foo = arg_get_str(ctx, 1); + size_t count = 0; + size_t len = 0; + do { + count += strlen(foo->sval[len]); + } while (len++ < (foo->count - 1)); + + char s[count + foo->count]; + memset(s, 0, sizeof(s)); + + len = 0; + do { + snprintf(s + strlen(s), sizeof(s) - strlen(s), "%s ", foo->sval[len]); + } while (len++ < (foo->count - 1)); + + CLIParserFree(ctx); char buf[22] = {0}; AppendDate(buf, sizeof(buf), NULL); - PrintAndLogEx(NORMAL, "%s remark: %s", buf, Cmd); + PrintAndLogEx(SUCCESS, "%s remark: %s", buf, s); return PM3_SUCCESS; }