Skip to content

Commit fc2cdbc

Browse files
doegoxcodeflakes
authored andcommitted
Add client option to run Python script
1 parent 1dbe330 commit fc2cdbc

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

client/src/proxmark3.c

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,11 @@ static void set_my_user_directory(void) {
597597
static void show_help(bool showFullHelp, char *exec_name) {
598598

599599
PrintAndLogEx(NORMAL, "\nsyntax: %s [-h|-t|-m|--fulltext]", exec_name);
600+
#ifdef HAVE_PYTHON
601+
PrintAndLogEx(NORMAL, " %s [[-p] <port>] [-b] [-w] [-f] [-c <command>]|[-l <lua_script_file>]|[-y <python_script_file>]|[-s <cmd_script_file>] [-i] [-d <0|1|2>]", exec_name);
602+
#else // HAVE_PYTHON
600603
PrintAndLogEx(NORMAL, " %s [[-p] <port>] [-b] [-w] [-f] [-c <command>]|[-l <lua_script_file>]|[-s <cmd_script_file>] [-i] [-d <0|1|2>]", exec_name);
604+
#endif // HAVE_PYTHON
601605
PrintAndLogEx(NORMAL, " %s [-p] <port> --flash [--unlock-bootloader] [--image <imagefile>]+ [-w] [-f] [-d <0|1|2>]", exec_name);
602606

603607
if (showFullHelp) {
@@ -615,7 +619,11 @@ static void show_help(bool showFullHelp, char *exec_name) {
615619
PrintAndLogEx(NORMAL, " -m/--markdown dump all interactive command list at once in markdown syntax");
616620
PrintAndLogEx(NORMAL, " -b/--baud serial port speed (only needed for physical UART, not for USB-CDC or BT)");
617621
PrintAndLogEx(NORMAL, " -c/--command <command> execute one Proxmark3 command (or several separated by ';').");
618-
PrintAndLogEx(NORMAL, " -l/--lua <lua script file> execute lua script.");
622+
PrintAndLogEx(NORMAL, " -l/--lua <lua_script_file> execute Lua script.");
623+
#ifdef HAVE_PYTHON
624+
// Technically, --lua and --py are identical and interexchangeable
625+
PrintAndLogEx(NORMAL, " -y/--py <python_script_file> execute Python script.");
626+
#endif // HAVE_PYTHON
619627
PrintAndLogEx(NORMAL, " -s/--script-file <cmd_script_file> script file with one Proxmark3 command per line");
620628
PrintAndLogEx(NORMAL, " -i/--interactive enter interactive mode after executing the script or the command");
621629
PrintAndLogEx(NORMAL, " --incognito do not use history, prefs file nor log files");
@@ -631,7 +639,7 @@ static void show_help(bool showFullHelp, char *exec_name) {
631639
PrintAndLogEx(NORMAL, " %s -- runs the pm3 client in OFFLINE mode", exec_name);
632640
PrintAndLogEx(NORMAL, "\n to execute different commands from terminal:\n");
633641
PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" -c \"hf mf chk --1k\" -- execute cmd and quit client", exec_name);
634-
PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" -l hf_read -- execute lua script `hf_read` and quit client", exec_name);
642+
PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" -l hf_read -- execute Lua script `hf_read` and quit client", exec_name);
635643
PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" -s mycmds.txt -- execute each pm3 cmd in file and quit client", exec_name);
636644
PrintAndLogEx(NORMAL, "\n to flash fullimage and bootloader:\n");
637645
PrintAndLogEx(NORMAL, " %s "SERIAL_PORT_EXAMPLE_H" --flash --unlock-bootloader --image bootrom.elf --image fullimage.elf", exec_name);
@@ -756,7 +764,7 @@ void pm3_init(void) {
756764
int main(int argc, char *argv[]) {
757765
pm3_init();
758766
bool waitCOMPort = false;
759-
bool addLuaExec = false;
767+
bool addScriptExec = false;
760768
bool stayInCommandLoop = false;
761769
char *script_cmds_file = NULL;
762770
char *script_cmd = NULL;
@@ -939,21 +947,36 @@ int main(int argc, char *argv[]) {
939947
continue;
940948
}
941949

942-
// execute lua script
950+
// execute Lua script
943951
if (strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "--lua") == 0) {
944952
if (i + 1 == argc || strlen(argv[i + 1]) == 0) {
945-
PrintAndLogEx(ERR, _RED_("ERROR:") " missing lua script specification after -l\n");
953+
PrintAndLogEx(ERR, _RED_("ERROR:") " missing Lua script specification after --lua\n");
946954
show_help(false, exec_name);
947955
return 1;
948956
}
949957
script_cmd = argv[++i];
950958
if (script_cmd == NULL || strlen(script_cmd) == 0) {
951959
return 1;
952960
}
953-
addLuaExec = true;
961+
addScriptExec = true;
954962
continue;
955963
}
956-
964+
#ifdef HAVE_PYTHON
965+
// execute Python script
966+
if (strcmp(argv[i], "-y") == 0 || strcmp(argv[i], "--py") == 0) {
967+
if (i + 1 == argc || strlen(argv[i + 1]) == 0) {
968+
PrintAndLogEx(ERR, _RED_("ERROR:") " missing Python script specification after --py\n");
969+
show_help(false, exec_name);
970+
return 1;
971+
}
972+
script_cmd = argv[++i];
973+
if (script_cmd == NULL || strlen(script_cmd) == 0) {
974+
return 1;
975+
}
976+
addScriptExec = true;
977+
continue;
978+
}
979+
#endif // HAVE_PYTHON
957980
// go to interactive instead of quitting after a script/command
958981
if (strcmp(argv[i], "-i") == 0 || strcmp(argv[i], "--interactive") == 0) {
959982
stayInCommandLoop = true;
@@ -1032,7 +1055,7 @@ int main(int argc, char *argv[]) {
10321055
PrintAndLogEx(ERR, _RED_("ERROR:") " execute command: " _YELLOW_("command not found") ".\n");
10331056
return 2;
10341057
} else {
1035-
if (addLuaExec) {
1058+
if (addScriptExec) {
10361059
// add "script run " to command
10371060
int len = strlen(script_cmd) + 11 + 1;
10381061
char *ctmp = (char *) calloc(len, sizeof(uint8_t));

0 commit comments

Comments
 (0)