From 28eec73445237638e57b5f3c0a09ea524cdf028c Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Wed, 14 Jul 2021 09:57:16 +0200 Subject: [PATCH] added a client preference for delay of execution. This a global delay before each command is parsed. You can unset it with by setting delay to ZERO. The purpose of this setting is for users who want to use the pm3 against a implanted implant where you have to get a good position and arrange the pm3 while pressing . --- CHANGELOG.md | 1 + client/src/cmdmain.c | 2 +- client/src/cmdparser.c | 6 ++++ client/src/preferences.c | 60 +++++++++++++++++++++++++++++++++++++++- client/src/ui.h | 1 + 5 files changed, 68 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f01b04150..3d8fd7363 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Added a new client preference, delay of execution, a delay in ms before a cmd is sent. Good for implants (@iceman1001) - Fix `lf t55xx brute` - now correctly prints last key if it was correct (@scott4290) - Added support python scripts (@salmg) - Add new standalone mode `hf_reblay` - relay 14a over bt (@salmg) diff --git a/client/src/cmdmain.c b/client/src/cmdmain.c index f291b6dfb..8b7c6b29f 100644 --- a/client/src/cmdmain.c +++ b/client/src/cmdmain.c @@ -17,7 +17,7 @@ #include #include -#include // MingW +#include // MingW #include // calloc #include "comms.h" diff --git a/client/src/cmdparser.c b/client/src/cmdparser.c index f67e18608..0d79ebc36 100644 --- a/client/src/cmdparser.c +++ b/client/src/cmdparser.c @@ -15,6 +15,7 @@ #include "ui.h" #include "comms.h" +#include "util_posix.h" // msleep bool AlwaysAvailable(void) { return true; @@ -193,6 +194,11 @@ void CmdsHelp(const command_t Commands[]) { } int CmdsParse(const command_t Commands[], const char *Cmd) { + + if (session.client_exe_delay != 0) { + msleep(session.client_exe_delay); + } + // Help dump children if (strcmp(Cmd, "XX_internal_command_dump_XX") == 0) { dumpCommandsRecursive(Commands, 0, false); diff --git a/client/src/preferences.c b/client/src/preferences.c index 3228498f4..f34d535e3 100644 --- a/client/src/preferences.c +++ b/client/src/preferences.c @@ -243,6 +243,8 @@ void preferences_save_callback(json_t *root) { JsonSaveStr(root, "logging.level", "NORMAL"); } */ + JsonSaveInt(root, "client.exe.delay", session.client_exe_delay); + } void preferences_load_callback(json_t *root) { json_error_t up_error = {0}; @@ -331,6 +333,9 @@ void preferences_load_callback(json_t *root) { if (strncmp(tempStr, "extended", 8) == 0) session.device_debug_level = ddbEXTENDED; } */ + // client command execution delay + if (json_unpack_ex(root, &up_error, 0, "{s:i}", "client.exe.delay", &i1) == 0) + session.client_exe_delay = i1; } // Help Functions @@ -502,6 +507,11 @@ static void showBarModeState(prefShowOpt_t opt) { } } +static void showClientExeDelayState(void) { + PrintAndLogEx(INFO, " Cmd execution delay.... "_GREEN_("%u"), session.client_exe_delay); +} + + static int setCmdEmoji(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "prefs set emoji ", @@ -718,6 +728,35 @@ static int setCmdDeviceDebug (const char *Cmd) } */ + +static int setCmdExeDelay(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "prefs set clientdelay", + "Set presistent preference of delay before executing a command in the client", + "prefs set clientdelay --ms 0 --> unsets any delay\n" + "prefs set clientdelay --ms 1000 --> sets 1000ms delay" + ); + + void *argtable[] = { + arg_param_begin, + arg_int0(NULL, "ms", "", "delay in micro seconds"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + uint16_t new_value = (uint16_t)arg_get_int_def(ctx, 1, 0); + CLIParserFree(ctx); + + if (session.client_exe_delay != new_value) { + showClientExeDelayState(); + session.client_exe_delay = new_value; + showClientExeDelayState(); + preferences_save(); + } else { + showClientExeDelayState(); + } + return PM3_SUCCESS; +} + static int setCmdHint(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "prefs set hints ", @@ -1045,9 +1084,26 @@ static int getCmdSavePaths(const char *Cmd) { return PM3_SUCCESS; } +static int getCmdExeDelay(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "prefs get clientdelay", + "Get preference of delay time before execution of a command in the client", + "prefs get clientdelay" + ); + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); + showClientExeDelayState(); + return PM3_SUCCESS; +} + static command_t CommandTableGet[] = { {"barmode", getCmdBarMode, AlwaysAvailable, "Get bar mode preference"}, {"clientdebug", getCmdDebug, AlwaysAvailable, "Get client debug level preference"}, + {"clientdelay", getCmdExeDelay, AlwaysAvailable, "Get client execution delay preference"}, {"color", getCmdColor, AlwaysAvailable, "Get color support preference"}, {"savepaths", getCmdSavePaths, AlwaysAvailable, "Get file folder "}, // {"devicedebug", getCmdDeviceDebug, AlwaysAvailable, "Get device debug level"}, @@ -1061,6 +1117,7 @@ static command_t CommandTableSet[] = { {"help", setCmdHelp, AlwaysAvailable, "This help"}, {"barmode", setCmdBarMode, AlwaysAvailable, "Set bar mode"}, {"clientdebug", setCmdDebug, AlwaysAvailable, "Set client debug level"}, + {"clientdelay", setCmdExeDelay, AlwaysAvailable, "Set client execution delay"}, {"color", setCmdColor, AlwaysAvailable, "Set color support"}, {"emoji", setCmdEmoji, AlwaysAvailable, "Set emoji display"}, {"hints", setCmdHint, AlwaysAvailable, "Set hint display"}, @@ -1120,8 +1177,9 @@ static int CmdPrefShow(const char *Cmd) { showClientDebugState(prefShowNone); showPlotSliderState(prefShowNone); // showDeviceDebugState(prefShowNone); - showBarModeState(prefShowNone); + showClientExeDelayState(); + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; } diff --git a/client/src/ui.h b/client/src/ui.h index 632a818d3..21ad74be7 100644 --- a/client/src/ui.h +++ b/client/src/ui.h @@ -48,6 +48,7 @@ typedef struct { clientdebugLevel_t client_debug_level; barMode_t bar_mode; // uint8_t device_debug_level; + uint16_t client_exe_delay; char *history_path; pm3_device *current_device; } session_arg_t;