mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 13:23:51 -07:00
begin of dynamic capabilities handling in client
This commit is contained in:
parent
5a6929c533
commit
ca43afa19b
55 changed files with 554 additions and 536 deletions
|
@ -17,11 +17,27 @@
|
|||
#include "proxmark3.h"
|
||||
#include "comms.h"
|
||||
|
||||
bool AlwaysAvailable(void) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IfPm3Present(void) {
|
||||
if (session.help_dump_mode)
|
||||
return false;
|
||||
return session.pm3_present;
|
||||
}
|
||||
|
||||
bool IfPm3Hfsniff(void) {
|
||||
if (!IfPm3Present())
|
||||
return false;
|
||||
return pm3_capabilities.compiled_with_hfsniff;
|
||||
}
|
||||
|
||||
void CmdsHelp(const command_t Commands[]) {
|
||||
if (Commands[0].Name == NULL) return;
|
||||
int i = 0;
|
||||
while (Commands[i].Name) {
|
||||
if (session.pm3_present || Commands[i].Offline)
|
||||
if (Commands[i].IsAvailable())
|
||||
PrintAndLogEx(NORMAL, "%-16s %s", Commands[i].Name, Commands[i].Help);
|
||||
++i;
|
||||
}
|
||||
|
@ -46,7 +62,7 @@ int CmdsParse(const command_t Commands[], const char *Cmd) {
|
|||
int i = 0;
|
||||
while (Commands[i].Name) {
|
||||
if (0 == strcmp(Commands[i].Name, cmd_name)) {
|
||||
if (session.pm3_present || Commands[i].Offline) {
|
||||
if (Commands[i].IsAvailable()) {
|
||||
break;
|
||||
} else {
|
||||
PrintAndLogEx(WARNING, "This command is only available in " _YELLOW_("online") "mode");
|
||||
|
@ -62,7 +78,7 @@ int CmdsParse(const command_t Commands[], const char *Cmd) {
|
|||
int matches = 0;
|
||||
|
||||
for (i = 0; Commands[i].Name; i++) {
|
||||
if (!strncmp(Commands[i].Name, cmd_name, strlen(cmd_name)) && (session.pm3_present || Commands[i].Offline)) {
|
||||
if (!strncmp(Commands[i].Name, cmd_name, strlen(cmd_name)) && Commands[i].IsAvailable()) {
|
||||
last_match = i;
|
||||
matches++;
|
||||
}
|
||||
|
@ -94,33 +110,33 @@ void dumpCommandsRecursive(const command_t cmds[], int markdown) {
|
|||
// First, dump all single commands, which are not a container for
|
||||
// other commands
|
||||
if (markdown) {
|
||||
PrintAndLogEx(NORMAL, "|%-*s|%-*s|%s\n", w_cmd, "command", w_off, "offline", "description");
|
||||
PrintAndLogEx(NORMAL, "|%-*s|%-*s|%s\n", w_cmd, "-------", w_off, "-------", "-----------");
|
||||
PrintAndLogEx(NORMAL, "|%-*s|%-*s|%s", w_cmd, "command", w_off, "offline", "description");
|
||||
PrintAndLogEx(NORMAL, "|%-*s|%-*s|%s", w_cmd, "-------", w_off, "-------", "-----------");
|
||||
} else {
|
||||
PrintAndLogEx(NORMAL, "%-*s|%-*s|%s\n", w_cmd, "command", w_off, "offline", "description");
|
||||
PrintAndLogEx(NORMAL, "%-*s|%-*s|%s\n", w_cmd, "-------", w_off, "-------", "-----------");
|
||||
PrintAndLogEx(NORMAL, "%-*s|%-*s|%s", w_cmd, "command", w_off, "offline", "description");
|
||||
PrintAndLogEx(NORMAL, "%-*s|%-*s|%s", w_cmd, "-------", w_off, "-------", "-----------");
|
||||
}
|
||||
|
||||
while (cmds[i].Name) {
|
||||
const char *cmd_offline = "N";
|
||||
if (cmds[i].Help[0] == '{' && ++i) continue;
|
||||
|
||||
if (cmds[i].Offline)
|
||||
if (cmds[i].IsAvailable())
|
||||
cmd_offline = "Y";
|
||||
if (markdown)
|
||||
PrintAndLogEx(NORMAL, "|`%s%-*s`|%-*s|`%s`\n", parent, w_cmd - (int)strlen(parent) - 2, cmds[i].Name, w_off, cmd_offline, cmds[i].Help);
|
||||
PrintAndLogEx(NORMAL, "|`%s%-*s`|%-*s|`%s`", parent, w_cmd - (int)strlen(parent) - 2, cmds[i].Name, w_off, cmd_offline, cmds[i].Help);
|
||||
else
|
||||
PrintAndLogEx(NORMAL, "%s%-*s|%-*s|%s\n", parent, w_cmd - (int)strlen(parent), cmds[i].Name, w_off, cmd_offline, cmds[i].Help);
|
||||
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\n");
|
||||
PrintAndLogEx(NORMAL, "\n");
|
||||
i = 0;
|
||||
|
||||
// Then, print the categories. These will go into subsections with their own tables
|
||||
while (cmds[i].Name) {
|
||||
if (cmds[i].Help[0] != '{' && ++i) continue;
|
||||
|
||||
PrintAndLogEx(NORMAL, "### %s%s\n\n %s\n\n", parent, cmds[i].Name, cmds[i].Help);
|
||||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue