proxmark3/client/src/cmdparser.c

395 lines
12 KiB
C
Raw Normal View History

//-----------------------------------------------------------------------------
2022-01-07 08:58:03 +08:00
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
//
2022-01-07 08:58:03 +08:00
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// See LICENSE.txt for the text of the license.
//-----------------------------------------------------------------------------
// Command parser
//-----------------------------------------------------------------------------
#include "cmdparser.h"
Client cleanup and restructuring. Stage 1... Next Step is refactoring some of the giant functions which are just copy/paste of some other ones with just a few line changes, removing unnecessary 'goto' etc. The MS Windows version is broken with this commit but will be fixed soon. Everything can't be done all at once :P The commands are now hierarchical, for example: "hf 14a read" vs. "hf 14b read". You can also request help: "hf help", "data help", "hf 15 help" etc. Indents are now space-based, not tab-based anymore. Hopefully no one will be trolling about it, considering the suicide-prone work being done here ;) client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h, client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h, client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c, client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h, client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h, client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h, client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h, client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h, client/cmdhflegic.c, client/cmdhflegic.c: New files. client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c, client/proxmark3.h, client/Makefile: Update accordingly. client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes. client/translate.h, client/command.c, client/gui.c, client/usb.c, client/prox.h: Remove. include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd. common/crc16.h: New file. common/crc16.c: Modify accordingly. common/iso14443crc.h: New file. common/iso14443_crc.c: Rename to common/iso14443crc.c: and modify accordingly. armsrc/lfops.c, armsrc/iso14443.c, armsrc/iso14443a.c: include .h files from the common directory instead of including the c files. common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
#include <stdio.h>
#include <string.h>
Client cleanup and restructuring. Stage 1... Next Step is refactoring some of the giant functions which are just copy/paste of some other ones with just a few line changes, removing unnecessary 'goto' etc. The MS Windows version is broken with this commit but will be fixed soon. Everything can't be done all at once :P The commands are now hierarchical, for example: "hf 14a read" vs. "hf 14b read". You can also request help: "hf help", "data help", "hf 15 help" etc. Indents are now space-based, not tab-based anymore. Hopefully no one will be trolling about it, considering the suicide-prone work being done here ;) client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h, client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h, client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c, client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h, client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h, client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h, client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h, client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h, client/cmdhflegic.c, client/cmdhflegic.c: New files. client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c, client/proxmark3.h, client/Makefile: Update accordingly. client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes. client/translate.h, client/command.c, client/gui.c, client/usb.c, client/prox.h: Remove. include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd. common/crc16.h: New file. common/crc16.c: Modify accordingly. common/iso14443crc.h: New file. common/iso14443_crc.c: Rename to common/iso14443crc.c: and modify accordingly. armsrc/lfops.c, armsrc/iso14443.c, armsrc/iso14443a.c: include .h files from the common directory instead of including the c files. common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
#include "ui.h"
#include "comms.h"
#include "util_posix.h" // msleep
Client cleanup and restructuring. Stage 1... Next Step is refactoring some of the giant functions which are just copy/paste of some other ones with just a few line changes, removing unnecessary 'goto' etc. The MS Windows version is broken with this commit but will be fixed soon. Everything can't be done all at once :P The commands are now hierarchical, for example: "hf 14a read" vs. "hf 14b read". You can also request help: "hf help", "data help", "hf 15 help" etc. Indents are now space-based, not tab-based anymore. Hopefully no one will be trolling about it, considering the suicide-prone work being done here ;) client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h, client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h, client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c, client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h, client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h, client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h, client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h, client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h, client/cmdhflegic.c, client/cmdhflegic.c: New files. client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c, client/proxmark3.h, client/Makefile: Update accordingly. client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes. client/translate.h, client/command.c, client/gui.c, client/usb.c, client/prox.h: Remove. include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd. common/crc16.h: New file. common/crc16.c: Modify accordingly. common/iso14443crc.h: New file. common/iso14443_crc.c: Rename to common/iso14443crc.c: and modify accordingly. armsrc/lfops.c, armsrc/iso14443.c, armsrc/iso14443a.c: include .h files from the common directory instead of including the c files. common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
bool AlwaysAvailable(void) {
return true;
}
bool IfPm3Present(void) {
2021-08-22 02:31:05 +08:00
if (g_session.help_dump_mode)
return false;
2021-08-22 02:31:05 +08:00
return g_session.pm3_present;
}
bool IfPm3Rdv4Fw(void) {
if (!IfPm3Present())
return false;
return (g_pm3_capabilities.compiled_with_flash) || (g_pm3_capabilities.compiled_with_smartcard);
}
2019-05-02 03:09:23 +08:00
bool IfPm3Flash(void) {
if (!IfPm3Present())
return false;
if (!g_pm3_capabilities.compiled_with_flash)
return false;
return g_pm3_capabilities.hw_available_flash;
2019-05-02 03:09:23 +08:00
}
bool IfPm3Smartcard(void) {
if (!IfPm3Present())
return false;
if (!g_pm3_capabilities.compiled_with_smartcard)
return false;
return g_pm3_capabilities.hw_available_smartcard;
2019-05-02 03:09:23 +08:00
}
bool IfPm3FpcUsart(void) {
2019-05-02 03:09:23 +08:00
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_fpc_usart;
2019-05-02 03:09:23 +08:00
}
bool IfPm3FpcUsartHost(void) {
2019-05-02 03:09:23 +08:00
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_fpc_usart_host;
}
bool IfPm3FpcUsartHostFromUsb(void) {
// true if FPC USART Host support and if talking from USB-CDC interface
if (!IfPm3Present())
return false;
if (!g_pm3_capabilities.compiled_with_fpc_usart_host)
return false;
2021-08-22 02:21:08 +08:00
return !g_conn.send_via_fpc_usart;
}
bool IfPm3FpcUsartDevFromUsb(void) {
// true if FPC USART developer support and if talking from USB-CDC interface
if (!IfPm3Present())
return false;
if (!g_pm3_capabilities.compiled_with_fpc_usart_dev)
return false;
2021-08-22 02:21:08 +08:00
return !g_conn.send_via_fpc_usart;
2019-05-02 03:09:23 +08:00
}
bool IfPm3FpcUsartFromUsb(void) {
// true if FPC USART Host or developer support and if talking from USB-CDC interface
return IfPm3FpcUsartHostFromUsb() || IfPm3FpcUsartDevFromUsb();
}
2019-05-02 03:09:23 +08:00
bool IfPm3Lf(void) {
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_lf;
2019-05-02 03:09:23 +08:00
}
bool IfPm3Hitag(void) {
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_hitag;
2019-05-02 03:09:23 +08:00
}
2020-06-29 03:39:27 +08:00
bool IfPm3EM4x50(void) {
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_em4x50;
2020-06-29 03:39:27 +08:00
}
bool IfPm3EM4x70(void) {
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_em4x70;
}
bool IfPm3Hfsniff(void) {
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_hfsniff;
}
bool IfPm3Hfplot(void) {
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_hfplot;
}
2019-05-02 03:09:23 +08:00
bool IfPm3Iso14443a(void) {
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_iso14443a;
2019-05-02 03:09:23 +08:00
}
2019-05-02 03:31:34 +08:00
bool IfPm3Iso14443b(void) {
2019-05-02 03:09:23 +08:00
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_iso14443b;
2019-05-02 03:09:23 +08:00
}
bool IfPm3Iso14443(void) {
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_iso14443a || g_pm3_capabilities.compiled_with_iso14443b;
}
2019-05-02 03:09:23 +08:00
bool IfPm3Iso15693(void) {
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_iso15693;
2019-05-02 03:09:23 +08:00
}
bool IfPm3Felica(void) {
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_felica;
2019-05-02 03:09:23 +08:00
}
bool IfPm3Legicrf(void) {
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_legicrf;
2019-05-02 03:09:23 +08:00
}
bool IfPm3Iclass(void) {
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_iclass;
2019-05-02 03:09:23 +08:00
}
2019-08-04 03:17:52 +08:00
bool IfPm3NfcBarcode(void) {
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_nfcbarcode;
2019-08-04 03:17:52 +08:00
}
2019-05-02 03:09:23 +08:00
bool IfPm3Lcd(void) {
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_lcd;
2019-05-02 03:09:23 +08:00
}
2021-12-24 22:09:19 +08:00
bool IfPm3Zx8211(void) {
if (!IfPm3Present())
return false;
return g_pm3_capabilities.compiled_with_zx8211;
}
2019-05-02 03:09:23 +08:00
void CmdsHelp(const command_t Commands[]) {
2019-03-10 06:35:06 +08:00
if (Commands[0].Name == NULL) return;
int i = 0;
while (Commands[i].Name) {
if (Commands[i].IsAvailable()) {
uint8_t old_printAndLog = g_printAndLog;
g_printAndLog &= PRINTANDLOG_PRINT;
2020-09-25 01:51:57 +08:00
if (Commands[i].Name[0] == '-' || Commands[i].Name[0] == ' ') {
PrintAndLogEx(NORMAL, "%-16s %s", Commands[i].Name, Commands[i].Help);
} else {
PrintAndLogEx(NORMAL, _GREEN_("%-16s")" %s", Commands[i].Name, Commands[i].Help);
}
g_printAndLog = old_printAndLog;
}
2019-03-10 06:35:06 +08:00
++i;
}
// empty line needed for the help2json parser
PrintAndLogEx(NORMAL, "");
Client cleanup and restructuring. Stage 1... Next Step is refactoring some of the giant functions which are just copy/paste of some other ones with just a few line changes, removing unnecessary 'goto' etc. The MS Windows version is broken with this commit but will be fixed soon. Everything can't be done all at once :P The commands are now hierarchical, for example: "hf 14a read" vs. "hf 14b read". You can also request help: "hf help", "data help", "hf 15 help" etc. Indents are now space-based, not tab-based anymore. Hopefully no one will be trolling about it, considering the suicide-prone work being done here ;) client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h, client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h, client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c, client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h, client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h, client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h, client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h, client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h, client/cmdhflegic.c, client/cmdhflegic.c: New files. client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c, client/proxmark3.h, client/Makefile: Update accordingly. client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes. client/translate.h, client/command.c, client/gui.c, client/usb.c, client/prox.h: Remove. include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd. common/crc16.h: New file. common/crc16.c: Modify accordingly. common/iso14443crc.h: New file. common/iso14443_crc.c: Rename to common/iso14443crc.c: and modify accordingly. armsrc/lfops.c, armsrc/iso14443.c, armsrc/iso14443a.c: include .h files from the common directory instead of including the c files. common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
}
int CmdsParse(const command_t Commands[], const char *Cmd) {
2021-08-22 02:31:05 +08:00
if (g_session.client_exe_delay != 0) {
msleep(g_session.client_exe_delay);
}
2019-03-10 06:35:06 +08:00
// Help dump children
2019-03-10 07:00:59 +08:00
if (strcmp(Cmd, "XX_internal_command_dump_XX") == 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);
2019-04-19 05:26:12 +08:00
return PM3_SUCCESS;
2019-03-10 06:35:06 +08:00
}
// Markdown help dump children
2019-03-10 07:00:59 +08:00
if (strcmp(Cmd, "XX_internal_command_dump_markdown_XX") == 0) {
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);
2019-04-19 05:26:12 +08:00
return PM3_SUCCESS;
2019-03-10 06:35:06 +08:00
}
2020-09-30 20:27:19 +08:00
2020-09-16 21:29:14 +08:00
if (strcmp(Cmd, "coffee") == 0) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, " ((\n ))\n" _YELLOW_(" .______.\n | |]\n \\ /\n `----´\n\n"));
return PM3_SUCCESS;
}
2020-01-04 23:25:38 +08:00
if (strcmp(Cmd, "star") == 0) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, " \\o o/");
PrintAndLogEx(NORMAL, " v\\ /v");
PrintAndLogEx(NORMAL, " <\\ />");
PrintAndLogEx(NORMAL, " |\\o/|");
PrintAndLogEx(NORMAL, " _\\__o | o__/");
PrintAndLogEx(NORMAL, " |/ \\|");
PrintAndLogEx(NORMAL, " o/ \\o");
PrintAndLogEx(NORMAL, " /v v\\");
PrintAndLogEx(NORMAL, " /> <\\");
PrintAndLogEx(NORMAL, "");
return PM3_SUCCESS;
}
2019-03-10 06:35:06 +08:00
char cmd_name[128];
memset(cmd_name, 0, sizeof(cmd_name));
2020-01-04 23:25:38 +08:00
2020-01-08 05:18:27 +08:00
int len = 0;
2020-01-04 23:25:38 +08:00
// %n == receives an integer of value equal to the number of chars read so far.
// len = max 127
2019-03-10 06:35:06 +08:00
sscanf(Cmd, "%127s%n", cmd_name, &len);
2020-01-04 23:25:38 +08:00
2019-03-10 06:35:06 +08:00
str_lower(cmd_name);
2020-01-04 23:25:38 +08:00
2019-09-05 05:13:51 +08:00
// Comment
if (cmd_name[0] == '#')
return PM3_SUCCESS;
2020-01-04 23:25:38 +08:00
2021-04-19 06:33:59 +08:00
// find args, check for -h / --help
int tmplen = len;
while (Cmd[tmplen] == ' ')
++tmplen;
2021-04-19 07:16:39 +08:00
bool request_help = (strcmp(Cmd + tmplen, "-h") == 0) || (strcmp(Cmd + tmplen, "--help") == 0);
2021-04-19 06:33:59 +08:00
2019-03-10 06:35:06 +08:00
int i = 0;
2019-05-01 05:52:40 +08:00
while (Commands[i].Name) {
if (0 == strcmp(Commands[i].Name, cmd_name)) {
2021-04-19 07:16:39 +08:00
if ((Commands[i].Help[0] == '{') || // always allow parsing categories
request_help || // always allow requesting help
Commands[i].IsAvailable()) {
2019-05-01 05:52:40 +08:00
break;
} else {
PrintAndLogEx(WARNING, "This command is " _YELLOW_("not available") " in this mode");
2019-05-01 05:52:40 +08:00
return PM3_ENOTIMPL;
}
}
2019-03-10 06:35:06 +08:00
++i;
2019-05-01 05:52:40 +08:00
}
2019-03-10 06:35:06 +08:00
/* try to find exactly one prefix-match */
if (!Commands[i].Name) {
int last_match = 0;
int matches = 0;
2019-03-10 07:00:59 +08:00
for (i = 0; Commands[i].Name; i++) {
if (!strncmp(Commands[i].Name, cmd_name, strlen(cmd_name)) && Commands[i].IsAvailable()) {
2019-03-10 06:35:06 +08:00
last_match = i;
matches++;
}
}
if (matches == 1) i = last_match;
}
if (Commands[i].Name) {
while (Cmd[len] == ' ')
2019-03-10 07:00:59 +08:00
++len;
2019-03-10 06:35:06 +08:00
return Commands[i].Parse(Cmd + len);
} else {
// show help for selected hierarchy or if command not recognised
CmdsHelp(Commands);
}
2019-04-19 05:26:12 +08:00
return PM3_SUCCESS;
Client cleanup and restructuring. Stage 1... Next Step is refactoring some of the giant functions which are just copy/paste of some other ones with just a few line changes, removing unnecessary 'goto' etc. The MS Windows version is broken with this commit but will be fixed soon. Everything can't be done all at once :P The commands are now hierarchical, for example: "hf 14a read" vs. "hf 14b read". You can also request help: "hf help", "data help", "hf 15 help" etc. Indents are now space-based, not tab-based anymore. Hopefully no one will be trolling about it, considering the suicide-prone work being done here ;) client/cmdhw.c, client/proxusb.c, client/cmdhw.h, client/proxusb.h, client/cmdmain.c, client/cmdlfhid.c, client/cmdmain.h, client/cmdlfhid.h, client/data.c, client/data.h, client/cmdhf.c, client/cmdlf.c, client/cmdhf.h, client/cmdhf15.c, client/cmdhf14b.c, client/cmdlf.h, client/cmdhf15.h, client/cmdhf14b.h, client/cmddata.c, client/cmddata.h, client/ui.c, client/cmdparser.c, client/cmdlfti.c, client/ui.h, client/cmdlfem4x.c, client/cmdparser.h, client/cmdlfti.h, client/cmdlfem4x.h, client/graph.c, client/graph.h, client/cmdhf14a.c, client/cmdhf14a.h, client/cmdhflegic.c, client/cmdhflegic.c: New files. client/cli.c, client/flasher.c, client/snooper.c, client/proxmark3.c, client/proxmark3.h, client/Makefile: Update accordingly. client/flash.h, client/flash.c, client/proxgui.cpp: Cosmetic changes. client/translate.h, client/command.c, client/gui.c, client/usb.c, client/prox.h: Remove. include/usb_cmd.h (CMD_ACQUIRE_RAW_ADC_SAMPLES_ISO_14443_SIM): Remove dead cmd. common/crc16.h: New file. common/crc16.c: Modify accordingly. common/iso14443crc.h: New file. common/iso14443_crc.c: Rename to common/iso14443crc.c: and modify accordingly. armsrc/lfops.c, armsrc/iso14443.c, armsrc/iso14443a.c: include .h files from the common directory instead of including the c files. common/Makefile.common, armsrc/Makefile: Modify accordingly.
2010-02-04 09:27:07 +08:00
}
2020-06-02 02:30:11 +08:00
static char pparent[512] = {0};
static char *parent = pparent;
void dumpCommandsRecursive(const command_t cmds[], int markdown, bool full_help) {
2019-03-10 06:35:06 +08:00
if (cmds[0].Name == NULL) return;
int i = 0;
int w_cmd = 25;
int w_off = 8;
// First, dump all single commands, which are not a container for
// other commands
if (markdown) {
PrintAndLogEx(NORMAL, "|%-*s|%-*s|%s", w_cmd, "command", w_off, "offline", "description");
PrintAndLogEx(NORMAL, "|%-*s|%-*s|%s", w_cmd, "-------", w_off, "-------", "-----------");
} 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, "-------", "-----------");
2019-03-10 06:35:06 +08:00
}
while (cmds[i].Name) {
2020-01-08 05:18:27 +08:00
2020-01-04 23:25:38 +08:00
if ((cmds[i].Name[0] == '-' || strlen(cmds[i].Name) == 0) && ++i) continue;
2019-03-10 06:35:06 +08:00
if (cmds[i].Help[0] == '{' && ++i) continue;
2020-01-08 05:18:27 +08:00
2020-01-04 23:25:38 +08:00
const char *cmd_offline = "N";
2019-03-10 06:35:06 +08:00
if (cmds[i].IsAvailable())
2019-03-10 06:35:06 +08:00
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 if (full_help) {
PrintAndLogEx(NORMAL, "---------------------------------------------------------------------------------------");
2021-05-06 03:04:48 +08:00
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);
}
2019-03-10 06:35:06 +08:00
++i;
}
PrintAndLogEx(NORMAL, "\n");
2019-03-10 06:35:06 +08:00
i = 0;
// Then, print the categories. These will go into subsections with their own tables
while (cmds[i].Name) {
2020-01-04 23:25:38 +08:00
if ((cmds[i].Name[0] == '-' || strlen(cmds[i].Name) == 0) && ++i) continue;
2019-03-10 07:00:59 +08:00
if (cmds[i].Help[0] != '{' && ++i) continue;
2019-03-10 06:35:06 +08:00
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);
}
2019-03-10 06:35:06 +08:00
char currentparent[512] = {0};
snprintf(currentparent, sizeof currentparent, "%s%s ", parent, cmds[i].Name);
char *old_parent = parent;
parent = currentparent;
// This is what causes the recursion, since commands Parse-implementation
// in turn calls the CmdsParse above.
if (markdown)
2019-03-10 07:00:59 +08:00
cmds[i].Parse("XX_internal_command_dump_markdown_XX");
else if (full_help) {
cmds[i].Parse("XX_internal_command_dump_full_XX");
} else {
2019-03-10 07:00:59 +08:00
cmds[i].Parse("XX_internal_command_dump_XX");
}
2019-03-10 06:35:06 +08:00
parent = old_parent;
++i;
}
}