From cc3c0a5148088f40adda1073cdb99cbbb3130f0a Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 9 Nov 2015 21:46:57 +0100 Subject: [PATCH] ADD: @piwi's fixes to .history --- client/cmdmain.c | 6 +++--- client/cmdmain.h | 2 +- client/cmdparser.c | 10 ++++++---- client/cmdparser.h | 2 +- client/proxmark3.c | 17 +++++++++-------- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/client/cmdmain.c b/client/cmdmain.c index d31147f9..51aada76 100644 --- a/client/cmdmain.c +++ b/client/cmdmain.c @@ -75,7 +75,7 @@ int CmdLS(const char *Cmd){ int CmdQuit(const char *Cmd) { exit(0); - return 0; + return 99; } int CmdRev(const char *Cmd) @@ -174,8 +174,8 @@ bool WaitForResponse(uint32_t cmd, UsbCommand* response) { // Entry point into our code: called whenever the user types a command and // then presses Enter, which the full command line that they typed. //----------------------------------------------------------------------------- -void CommandReceived(char *Cmd) { - CmdsParse(CommandTable, Cmd); +int CommandReceived(char *Cmd) { + return CmdsParse(CommandTable, Cmd); } //----------------------------------------------------------------------------- diff --git a/client/cmdmain.h b/client/cmdmain.h index aa87052c..9cb3e95d 100644 --- a/client/cmdmain.h +++ b/client/cmdmain.h @@ -14,7 +14,7 @@ #include "usb_cmd.h" #include "cmdparser.h" void UsbCommandReceived(UsbCommand *UC); -void CommandReceived(char *Cmd); +int CommandReceived(char *Cmd); bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeout); bool WaitForResponse(uint32_t cmd, UsbCommand* response); void clearCommandBuffer(); diff --git a/client/cmdparser.c b/client/cmdparser.c index ae67466a..e67bdfe5 100644 --- a/client/cmdparser.c +++ b/client/cmdparser.c @@ -40,17 +40,17 @@ void CmdsLS(const command_t Commands[]) } } -void CmdsParse(const command_t Commands[], const char *Cmd) +int CmdsParse(const command_t Commands[], const char *Cmd) { if(strcmp( Cmd, "XX_internal_command_dump_XX") == 0) {// Help dump children dumpCommandsRecursive(Commands, 0); - return; + return 0; } if(strcmp( Cmd, "XX_internal_command_dump_markdown_XX") == 0) {// Markdown help dump children dumpCommandsRecursive(Commands, 1); - return; + return 0; } char cmd_name[32]; int len = 0; @@ -77,11 +77,13 @@ void CmdsParse(const command_t Commands[], const char *Cmd) if (Commands[i].Name) { while (Cmd[len] == ' ') ++len; - Commands[i].Parse(Cmd + len); + return Commands[i].Parse(Cmd + len); } else { // show help for selected hierarchy or if command not recognised CmdsHelp(Commands); } + + return 0; } char pparent[512] = {0}; diff --git a/client/cmdparser.h b/client/cmdparser.h index 34db902c..97b8f281 100644 --- a/client/cmdparser.h +++ b/client/cmdparser.h @@ -26,7 +26,7 @@ void CmdsHelp(const command_t Commands[]); // Print each command in the command array without help void CmdsLS(const command_t Commands[]); // Parse a command line -void CmdsParse(const command_t Commands[], const char *Cmd); +int CmdsParse(const command_t Commands[], const char *Cmd); void dumpCommandsRecursive(const command_t cmds[], int markdown); #endif diff --git a/client/proxmark3.c b/client/proxmark3.c index 5e5bba80..641690a7 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -155,12 +155,11 @@ static void *main_loop(void *targ) { cmd[strlen(cmd) - 1] = 0x00; if (cmd[0] != 0x00) { - if (strncmp(cmd, "quit", 4) == 0) { - exit(0); + int ret = CommandReceived(cmd); + add_history(cmd); + if (ret == 99) { // exit or quit break; } - CommandReceived(cmd); - add_history(cmd); } free(cmd); } else { @@ -223,7 +222,7 @@ int main(int argc, char* argv[]) { .usb_present = 0, .script_cmds_file = NULL }; - pthread_t main_loop_t; + pthread_t main_loop_threat; sp = uart_open(argv[1]); @@ -258,18 +257,20 @@ int main(int argc, char* argv[]) { // create a mutex to avoid interlacing print commands from our different threads pthread_mutex_init(&print_lock, NULL); - pthread_create(&main_loop_t, NULL, &main_loop, &marg); + pthread_create(&main_loop_threat, NULL, &main_loop, &marg); InitGraphics(argc, argv); MainGraphics(); - pthread_join(main_loop_t, NULL); + pthread_join(main_loop_threat, NULL); // Clean up the port + if (offline == 0) { uart_close(sp); + } // clean up mutex pthread_mutex_destroy(&print_lock); - return 0; + exit(0); } -- 2.39.2