From 008a0b5ab48f818b4253052a7f9b75a80cd58f08 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Mon, 19 Apr 2021 02:54:16 +0200 Subject: [PATCH] First attempt at dumping all help: proxmark3 --fulltext --- client/src/cmdparser.c | 38 ++++++++++++++++++++++++++++++-------- client/src/cmdparser.h | 2 +- client/src/proxmark3.c | 23 ++++++++++++++++------- 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/client/src/cmdparser.c b/client/src/cmdparser.c index 23ca61ba5..1f5476b48 100644 --- a/client/src/cmdparser.c +++ b/client/src/cmdparser.c @@ -195,12 +195,22 @@ void CmdsHelp(const command_t Commands[]) { int CmdsParse(const command_t Commands[], const char *Cmd) { // Help dump children if (strcmp(Cmd, "XX_internal_command_dump_XX") == 0) { - dumpCommandsRecursive(Commands, 0); + dumpCommandsRecursive(Commands, 0, false); + return PM3_SUCCESS; + } + // Help dump children with help + if (strcmp(Cmd, "XX_internal_command_dump_full_XX") == 0) { + dumpCommandsRecursive(Commands, 0, true); return PM3_SUCCESS; } // Markdown help dump children if (strcmp(Cmd, "XX_internal_command_dump_markdown_XX") == 0) { - dumpCommandsRecursive(Commands, 1); + dumpCommandsRecursive(Commands, 1, false); + return PM3_SUCCESS; + } + // Markdown help dump children with help + if (strcmp(Cmd, "XX_internal_command_dump_markdown_help_XX") == 0) { + dumpCommandsRecursive(Commands, 1, true); return PM3_SUCCESS; } @@ -290,7 +300,7 @@ int CmdsParse(const command_t Commands[], const char *Cmd) { static char pparent[512] = {0}; static char *parent = pparent; -void dumpCommandsRecursive(const command_t cmds[], int markdown) { +void dumpCommandsRecursive(const command_t cmds[], int markdown, bool full_help) { if (cmds[0].Name == NULL) return; int i = 0; @@ -301,7 +311,7 @@ void dumpCommandsRecursive(const command_t cmds[], int markdown) { if (markdown) { PrintAndLogEx(NORMAL, "|%-*s|%-*s|%s", w_cmd, "command", w_off, "offline", "description"); PrintAndLogEx(NORMAL, "|%-*s|%-*s|%s", w_cmd, "-------", w_off, "-------", "-----------"); - } else { + } else if (! full_help) { PrintAndLogEx(NORMAL, "%-*s|%-*s|%s", w_cmd, "command", w_off, "offline", "description"); PrintAndLogEx(NORMAL, "%-*s|%-*s|%s", w_cmd, "-------", w_off, "-------", "-----------"); } @@ -317,8 +327,13 @@ void dumpCommandsRecursive(const command_t cmds[], int markdown) { cmd_offline = "Y"; if (markdown) PrintAndLogEx(NORMAL, "|`%s%-*s`|%-*s|`%s`", parent, w_cmd - (int)strlen(parent) - 2, cmds[i].Name, w_off, cmd_offline, cmds[i].Help); - else + else if (full_help) { + PrintAndLogEx(NORMAL, "---------------------------------------------------------------------------------------"); + PrintAndLogEx(NORMAL, _RED_("%s%-*s\n") "available offline: %s", parent, w_cmd - (int)strlen(parent), cmds[i].Name, cmds[i].IsAvailable()?_GREEN_("yes"):_RED_("no")); + cmds[i].Parse("--help"); + } else { PrintAndLogEx(NORMAL, "%s%-*s|%-*s|%s", parent, w_cmd - (int)strlen(parent), cmds[i].Name, w_off, cmd_offline, cmds[i].Help); + } ++i; } PrintAndLogEx(NORMAL, "\n"); @@ -330,8 +345,12 @@ void dumpCommandsRecursive(const command_t cmds[], int markdown) { if ((cmds[i].Name[0] == '-' || strlen(cmds[i].Name) == 0) && ++i) continue; if (cmds[i].Help[0] != '{' && ++i) continue; - PrintAndLogEx(NORMAL, "### %s%s\n\n %s\n", parent, cmds[i].Name, cmds[i].Help); - + if (full_help) { + PrintAndLogEx(NORMAL, "======================================================================================="); + PrintAndLogEx(NORMAL, _RED_("%s%s\n\n ")_CYAN_("%s\n"), parent, cmds[i].Name, cmds[i].Help); + } else { + PrintAndLogEx(NORMAL, "### %s%s\n\n %s\n", parent, cmds[i].Name, cmds[i].Help); + } char currentparent[512] = {0}; snprintf(currentparent, sizeof currentparent, "%s%s ", parent, cmds[i].Name); char *old_parent = parent; @@ -340,8 +359,11 @@ void dumpCommandsRecursive(const command_t cmds[], int markdown) { // in turn calls the CmdsParse above. if (markdown) cmds[i].Parse("XX_internal_command_dump_markdown_XX"); - else + else if (full_help) { + cmds[i].Parse("XX_internal_command_dump_full_XX"); + } else { cmds[i].Parse("XX_internal_command_dump_XX"); + } parent = old_parent; ++i; diff --git a/client/src/cmdparser.h b/client/src/cmdparser.h index ff59df705..9b0933329 100644 --- a/client/src/cmdparser.h +++ b/client/src/cmdparser.h @@ -54,6 +54,6 @@ void CmdsHelp(const command_t Commands[]); void CmdsLS(const command_t Commands[]); // Parse a command line int CmdsParse(const command_t Commands[], const char *Cmd); -void dumpCommandsRecursive(const command_t cmds[], int markdown); +void dumpCommandsRecursive(const command_t cmds[], int markdown, bool full_help); #endif diff --git a/client/src/proxmark3.c b/client/src/proxmark3.c index 18dcf6bb5..030ed9b56 100644 --- a/client/src/proxmark3.c +++ b/client/src/proxmark3.c @@ -455,14 +455,14 @@ check_script: } #ifndef LIBPM3 -static void dumpAllHelp(int markdown) { +static void dumpAllHelp(int markdown, bool full_help) { session.help_dump_mode = true; PrintAndLogEx(NORMAL, "\n%sProxmark3 command dump%s\n\n", markdown ? "# " : "", markdown ? "" : "\n======================"); PrintAndLogEx(NORMAL, "Some commands are available only if a Proxmark3 is actually connected.%s\n", markdown ? " " : ""); PrintAndLogEx(NORMAL, "Check column \"offline\" for their availability.\n"); PrintAndLogEx(NORMAL, "\n"); command_t *cmds = getTopLevelCommandTable(); - dumpCommandsRecursive(cmds, markdown); + dumpCommandsRecursive(cmds, markdown, full_help); session.help_dump_mode = false; } #endif //LIBPM3 @@ -553,7 +553,7 @@ static void set_my_user_directory(void) { #ifndef LIBPM3 static void show_help(bool showFullHelp, char *exec_name) { - PrintAndLogEx(NORMAL, "\nsyntax: %s [-h|-t|-m]", exec_name); + PrintAndLogEx(NORMAL, "\nsyntax: %s [-h|-t|-m|--fulltext]", exec_name); PrintAndLogEx(NORMAL, " %s [[-p] ] [-b] [-w] [-f] [-c ]|[-l ]|[-s ] [-i] [-d <0|1|2>]", exec_name); PrintAndLogEx(NORMAL, " %s [-p] --flash [--unlock-bootloader] [--image ]+ [-w] [-f] [-d <0|1|2>]", exec_name); @@ -567,8 +567,9 @@ static void show_help(bool showFullHelp, char *exec_name) { PrintAndLogEx(NORMAL, " -f/--flush output will be flushed after every print"); PrintAndLogEx(NORMAL, " -d/--debug <0|1|2> set debugmode"); PrintAndLogEx(NORMAL, "\nOptions in client mode:"); - PrintAndLogEx(NORMAL, " -t/--text dump all interactive command's help at once"); - PrintAndLogEx(NORMAL, " -m/--markdown dump all interactive help at once in markdown syntax"); + PrintAndLogEx(NORMAL, " -t/--text dump all interactive command list at once"); + PrintAndLogEx(NORMAL, " --fulltext dump all interactive command's help at once"); + PrintAndLogEx(NORMAL, " -m/--markdown dump all interactive command list at once in markdown syntax"); PrintAndLogEx(NORMAL, " -b/--baud serial port speed (only needed for physical UART, not for USB-CDC or BT)"); PrintAndLogEx(NORMAL, " -c/--command execute one Proxmark3 command (or several separated by ';')."); PrintAndLogEx(NORMAL, " -l/--lua execute lua script."); @@ -823,14 +824,22 @@ int main(int argc, char *argv[]) { if (strcmp(argv[i], "-t") == 0 || strcmp(argv[i], "--text") == 0) { g_printAndLog = PRINTANDLOG_PRINT; show_help(false, exec_name); - dumpAllHelp(0); + dumpAllHelp(0, false); + return 0; + } + + // dump help + if (strcmp(argv[i], "--fulltext") == 0) { + g_printAndLog = PRINTANDLOG_PRINT; + show_help(false, exec_name); + dumpAllHelp(0, true); return 0; } // dump markup if (strcmp(argv[i], "-m") == 0 || strcmp(argv[i], "--markdown") == 0) { g_printAndLog = PRINTANDLOG_PRINT; - dumpAllHelp(1); + dumpAllHelp(1, false); return 0; } // print client version