Add client option -i to stay in interactive mode after a script or command

From 5a3f474331
with some fix in the logical flow
This commit is contained in:
Philippe Teuwen 2019-08-04 15:34:18 +02:00
parent 88d2a61c0b
commit 1cb039255e
6 changed files with 28 additions and 15 deletions

View file

@ -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... 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] ## [unreleased][unreleased]
- Add client option `-i` to stay in interactive mode after a script or command (@DidierStevens/@doegox)
- Add VSCode tasks (@ViRb3) - Add VSCode tasks (@ViRb3)
- Better warn user of hardcoded hitag info (@ViRb3) - Better warn user of hardcoded hitag info (@ViRb3)
- Format and docs hitag (@ViRb3) - Format and docs hitag (@ViRb3)

View file

@ -15,14 +15,14 @@
static ProxGuiQT *gui = NULL; static ProxGuiQT *gui = NULL;
static WorkerThread *main_loop_thread = NULL; static WorkerThread *main_loop_thread = NULL;
WorkerThread::WorkerThread(char *script_cmds_file, char *script_cmd) : script_cmds_file(script_cmds_file), script_cmd(script_cmd) { WorkerThread::WorkerThread(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) : script_cmds_file(script_cmds_file), script_cmd(script_cmd), stayInCommandLoop(stayInCommandLoop) {
} }
WorkerThread::~WorkerThread() { WorkerThread::~WorkerThread() {
} }
void WorkerThread::run() { void WorkerThread::run() {
main_loop(script_cmds_file, script_cmd); main_loop(script_cmds_file, script_cmd, stayInCommandLoop);
} }
extern "C" void ShowGraphWindow(void) { extern "C" void ShowGraphWindow(void) {
@ -53,12 +53,12 @@ extern "C" void MainGraphics(void) {
gui->MainLoop(); gui->MainLoop();
} }
extern "C" void InitGraphics(int argc, char **argv, char *script_cmds_file, char *script_cmd) { extern "C" void InitGraphics(int argc, char **argv, char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
#ifdef Q_WS_X11 #ifdef Q_WS_X11
if (getenv("DISPLAY") == NULL) if (getenv("DISPLAY") == NULL)
return; return;
#endif #endif
main_loop_thread = new WorkerThread(script_cmds_file, script_cmd); main_loop_thread = new WorkerThread(script_cmds_file, script_cmd, stayInCommandLoop);
gui = new ProxGuiQT(argc, argv, main_loop_thread); gui = new ProxGuiQT(argc, argv, main_loop_thread);
} }

View file

@ -22,7 +22,7 @@ void ShowGraphWindow(void);
void HideGraphWindow(void); void HideGraphWindow(void);
void RepaintGraphWindow(void); void RepaintGraphWindow(void);
void MainGraphics(void); void MainGraphics(void);
void InitGraphics(int argc, char **argv, char *script_cmds_file, char *script_cmd); void InitGraphics(int argc, char **argv, char *script_cmds_file, char *script_cmd, bool stayInCommandLoop);
void ExitGraphics(void); void ExitGraphics(void);
#ifndef MAX_GRAPH_TRACE_LEN #ifndef MAX_GRAPH_TRACE_LEN
#define MAX_GRAPH_TRACE_LEN (40000 * 8) #define MAX_GRAPH_TRACE_LEN (40000 * 8)

View file

@ -93,12 +93,13 @@ class ProxWidget : public QWidget {
class WorkerThread : public QThread { class WorkerThread : public QThread {
Q_OBJECT; Q_OBJECT;
public: public:
WorkerThread(char *, char *); WorkerThread(char *, char *, bool);
~WorkerThread(); ~WorkerThread();
void run(); void run();
private: private:
char *script_cmds_file; char *script_cmds_file;
char *script_cmd; char *script_cmd;
bool stayInCommandLoop;
}; };
class ProxGuiQT : public QObject { class ProxGuiQT : public QObject {

View file

@ -70,7 +70,7 @@ void
__attribute__((force_align_arg_pointer)) __attribute__((force_align_arg_pointer))
#endif #endif
#endif #endif
main_loop(char *script_cmds_file, char *script_cmd) { main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop) {
char *cmd = NULL; char *cmd = NULL;
bool execCommand = (script_cmd != NULL); bool execCommand = (script_cmd != NULL);
@ -138,7 +138,7 @@ main_loop(char *script_cmds_file, char *script_cmd) {
script_cmd_len -= len; script_cmd_len -= len;
} else { } else {
// exit after exec command // exit after exec command
if (script_cmd) if (script_cmd && !stayInCommandLoop)
break; break;
// if there is a pipe from stdin // if there is a pipe from stdin
@ -206,6 +206,9 @@ main_loop(char *script_cmds_file, char *script_cmd) {
cmd = NULL; cmd = NULL;
} else { } else {
PrintAndLogEx(NORMAL, "\n"); PrintAndLogEx(NORMAL, "\n");
if (script_cmds_file && stayInCommandLoop)
stayInCommandLoop = false;
else
break; break;
} }
} // end while } // end while
@ -266,7 +269,7 @@ static void show_help(bool showFullHelp, char *exec_name) {
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "syntax: %s [-h|-t|-m]\n", exec_name); PrintAndLogEx(NORMAL, "syntax: %s [-h|-t|-m]\n", exec_name);
PrintAndLogEx(NORMAL, " %s [[-p] <port>] [-b] [-w] [-f] [-c <command>]|[-l <lua_script_file>]|[-s <cmd_script_file>]\n", exec_name); PrintAndLogEx(NORMAL, " %s [[-p] <port>] [-b] [-w] [-f] [-c <command>]|[-l <lua_script_file>]|[-s <cmd_script_file>] [-i]\n", exec_name);
if (showFullHelp) { if (showFullHelp) {
PrintAndLogEx(NORMAL, "options:"); PrintAndLogEx(NORMAL, "options:");
@ -280,6 +283,7 @@ static void show_help(bool showFullHelp, char *exec_name) {
PrintAndLogEx(NORMAL, " -c/--command <command> execute one Proxmark3 command (or several separated by ';')."); PrintAndLogEx(NORMAL, " -c/--command <command> execute one Proxmark3 command (or several separated by ';').");
PrintAndLogEx(NORMAL, " -l/--lua <lua script file> execute lua script."); PrintAndLogEx(NORMAL, " -l/--lua <lua script file> execute lua script.");
PrintAndLogEx(NORMAL, " -s/--script-file <cmd_script_file> script file with one Proxmark3 command per line"); PrintAndLogEx(NORMAL, " -s/--script-file <cmd_script_file> script file with one Proxmark3 command per line");
PrintAndLogEx(NORMAL, " -i/--interactive enter interactive mode after executing the script or the command");
PrintAndLogEx(NORMAL, "\nsamples:"); PrintAndLogEx(NORMAL, "\nsamples:");
PrintAndLogEx(NORMAL, " %s -h\n", exec_name); PrintAndLogEx(NORMAL, " %s -h\n", exec_name);
PrintAndLogEx(NORMAL, " %s -m\n", exec_name); PrintAndLogEx(NORMAL, " %s -m\n", exec_name);
@ -302,6 +306,7 @@ int main(int argc, char *argv[]) {
session.help_dump_mode = false; session.help_dump_mode = false;
bool waitCOMPort = false; bool waitCOMPort = false;
bool addLuaExec = false; bool addLuaExec = false;
bool stayInCommandLoop = false;
char *script_cmds_file = NULL; char *script_cmds_file = NULL;
char *script_cmd = NULL; char *script_cmd = NULL;
char *port = NULL; char *port = NULL;
@ -438,6 +443,12 @@ int main(int argc, char *argv[]) {
continue; continue;
} }
// go to interactive instead of quitting after a script/command
if(strcmp(argv[i], "-i") == 0 || strcmp(argv[i], "--interactive") == 0){
stayInCommandLoop = true;
continue;
}
// We got an unknown parameter // We got an unknown parameter
PrintAndLogEx(ERR, _RED_("ERROR:") "invalid parameter: " _YELLOW_("%s") "\n", argv[i]); PrintAndLogEx(ERR, _RED_("ERROR:") "invalid parameter: " _YELLOW_("%s") "\n", argv[i]);
show_help(false, exec_name); show_help(false, exec_name);
@ -512,21 +523,21 @@ int main(int argc, char *argv[]) {
#ifdef HAVE_GUI #ifdef HAVE_GUI
# ifdef _WIN32 # ifdef _WIN32
InitGraphics(argc, argv, script_cmds_file, script_cmd); InitGraphics(argc, argv, script_cmds_file, script_cmd, stayInCommandLoop);
MainGraphics(); MainGraphics();
# else # else
// for *nix distro's, check enviroment variable to verify a display // for *nix distro's, check enviroment variable to verify a display
char *display = getenv("DISPLAY"); char *display = getenv("DISPLAY");
if (display && strlen(display) > 1) { if (display && strlen(display) > 1) {
InitGraphics(argc, argv, script_cmds_file, script_cmd); InitGraphics(argc, argv, script_cmds_file, script_cmd, stayInCommandLoop);
MainGraphics(); MainGraphics();
} else { } else {
main_loop(script_cmds_file, script_cmd); main_loop(script_cmds_file, script_cmd, stayInCommandLoop);
} }
# endif # endif
#else #else
main_loop(script_cmds_file, script_cmd); main_loop(script_cmds_file, script_cmd, stayInCommandLoop);
#endif #endif
// Clean up the port // Clean up the port

View file

@ -26,7 +26,7 @@ extern "C" {
const char *get_my_executable_path(void); const char *get_my_executable_path(void);
const char *get_my_executable_directory(void); const char *get_my_executable_directory(void);
void main_loop(char *script_cmds_file, char *script_cmd); void main_loop(char *script_cmds_file, char *script_cmd, bool stayInCommandLoop);
#ifdef __cplusplus #ifdef __cplusplus
} }