Skip to content

Commit 210b9a7

Browse files
committed
Add -- to proxmark3 client to pass args to scripts
Examples: pm3 -y myscript.py -- -h pm3 -y myscript.py -- --input foo --output bar This enables usage in scripts shebang, e.g. #!/usr/bin/env -S uv run --with pycryptodome pm3 -y
1 parent e10e113 commit 210b9a7

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
33
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...
44

55
## [unreleased][unreleased]
6+
- Added `--` arg separator to client to pass following args to scripts (@doegox)
67
- Fixed ISO14443-4 type B NDEF workflow + parsing (@team-orangeBlue)
78
- Added Snapmaker U1 filament spool KDF in `hf mf keygen` (@Foxushka)
89
- Replaced `hf mf bambukeys` with `hf mf keygen` with multiple KDFs support (@Foxushka)

client/src/proxmark3.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,9 @@ static void show_help(bool showFullHelp, char *exec_name) {
716716

717717
PrintAndLogEx(NORMAL, "\nsyntax: %s [-h|-t|-m|--fulltext]", exec_name);
718718
#ifdef HAVE_PYTHON
719-
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);
719+
PrintAndLogEx(NORMAL, " %s [[-p] <port>] [-b] [-w] [-f] [-d <0|1|2>] [--incognito] [--ncpu <num_cores>] [-c \"<command>\"]|[-l <lua_script_file>]|[-y <python_script_file>]|[-s <cmd_script_file>] [-i] [-- <arg0> <arg1>...]", exec_name);
720720
#else // HAVE_PYTHON
721-
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);
721+
PrintAndLogEx(NORMAL, " %s [[-p] <port>] [-b] [-w] [-f] [-d <0|1|2>] [--incognito] [--ncpu <num_cores>] [-c \"<command>\"]|[-l <lua_script_file>]|[-s <cmd_script_file>] [-i] [-- <arg0> <arg1>...]", exec_name);
722722
#endif // HAVE_PYTHON
723723
PrintAndLogEx(NORMAL, " %s [-p] <port> --flash [--unlock-bootloader] [--image <imagefile>]+ [-w] [-f] [-d <0|1|2>]", exec_name);
724724

@@ -736,16 +736,17 @@ static void show_help(bool showFullHelp, char *exec_name) {
736736
PrintAndLogEx(NORMAL, " --fulltext dump all interactive command's help at once");
737737
PrintAndLogEx(NORMAL, " -m/--markdown dump all interactive command list at once in markdown syntax");
738738
PrintAndLogEx(NORMAL, " -b/--baud serial port speed (only needed for physical UART, not for USB-CDC or BT)");
739-
PrintAndLogEx(NORMAL, " -c/--command <command> execute one Proxmark3 command (or several separated by ';').");
739+
PrintAndLogEx(NORMAL, " --incognito do not use history, prefs file nor log files");
740+
PrintAndLogEx(NORMAL, " --ncpu <num_cores> override number of CPU cores");
741+
PrintAndLogEx(NORMAL, " -c/--command \"<command>\" execute one Proxmark3 command (or several separated by ';').");
740742
PrintAndLogEx(NORMAL, " -l/--lua <lua_script_file> execute Lua script.");
741743
#ifdef HAVE_PYTHON
742744
// Technically, --lua and --py are identical and interexchangeable
743745
PrintAndLogEx(NORMAL, " -y/--py <python_script_file> execute Python script.");
744746
#endif // HAVE_PYTHON
745747
PrintAndLogEx(NORMAL, " -s/--script-file <cmd_script_file> script file with one Proxmark3 command per line");
746748
PrintAndLogEx(NORMAL, " -i/--interactive enter interactive mode after executing the script or the command");
747-
PrintAndLogEx(NORMAL, " --incognito do not use history, prefs file nor log files");
748-
PrintAndLogEx(NORMAL, " --ncpu <num_cores> override number of CPU cores");
749+
PrintAndLogEx(NORMAL, " -- <arg0> <arg1>... all args following -- are passed to the client command line");
749750
PrintAndLogEx(NORMAL, "\nOptions in flasher mode:");
750751
PrintAndLogEx(NORMAL, " --flash flash Proxmark3, requires at least one --image");
751752
PrintAndLogEx(NORMAL, " --reboot-to-bootloader reboot Proxmark3 into bootloader mode");
@@ -1230,6 +1231,30 @@ int main(int argc, char *argv[]) {
12301231
continue;
12311232
}
12321233
#endif // HAVE_PYTHON
1234+
// append all following args to script_cmd
1235+
if (strcmp(argv[i], "--") == 0) {
1236+
bool script_cmd_on_heap = false;
1237+
for (++i; i < argc; i++) {
1238+
int extra_len = strlen(argv[i]) + 1;
1239+
int old_len = script_cmd ? strlen(script_cmd) : 0;
1240+
char *new_cmd = (char *) calloc(old_len + extra_len + 1, sizeof(uint8_t));
1241+
if (new_cmd == NULL) {
1242+
PrintAndLogEx(WARNING, "Failed to allocate memory");
1243+
return 1;
1244+
}
1245+
if (script_cmd) {
1246+
strcpy(new_cmd, script_cmd);
1247+
strcat(new_cmd, " ");
1248+
if (script_cmd_on_heap) {
1249+
free(script_cmd);
1250+
}
1251+
}
1252+
strcat(new_cmd, argv[i]);
1253+
script_cmd = new_cmd;
1254+
script_cmd_on_heap = true;
1255+
}
1256+
continue;
1257+
}
12331258
// go to interactive instead of quitting after a script/command
12341259
if (strcmp(argv[i], "-i") == 0 || strcmp(argv[i], "--interactive") == 0) {
12351260
stayInCommandLoop = true;

pm3

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ fi
424424

425425
# priority to the help options
426426
for ARG; do
427+
if [ "$ARG" == "--" ]; then
428+
break
429+
fi
427430
if [ "$ARG" == "-h" ] || [ "$ARG" == "--help" ]; then
428431
HELP
429432
exit 0

0 commit comments

Comments
 (0)