Skip to content

Commit

Permalink
pm3_console() in Python/Lua/C: replace passthru by capture and quiet
Browse files Browse the repository at this point in the history
  • Loading branch information
doegox committed Oct 29, 2024
1 parent 57ec287 commit de96479
Show file tree
Hide file tree
Showing 16 changed files with 4,382 additions and 4,234 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
- Changed `pm3_console()` - Python/Lua/C: replace `passthru` by `capture` and `quiet` (@doegox)
- Fixed `hf iclass list` - annotation crc handled better (@iceman1001)
- Fixed `hf_mf_uscuid_prog.lua` - bad divisions and code style fixes (@iceman1001)
- Changed `hf iclass info` - now checks for cards silicon version (@antiklesys)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
ln -s build/proxmark3 .
)
ln -s ../pyscripts/pm3.py
ln -s ../lualibs/dkjson.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash

cd ..
make -j
(
cd ..
make -j
)
ln -s ../pyscripts/pm3.py
ln -s ../lualibs/dkjson.lua
2 changes: 1 addition & 1 deletion client/experimental_client_with_swig/testembedded.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ for line in p.grabbed_output:gmatch("[^\r\n]+") do
end

print("Device:", p.name)
p:console("Rem passthru remark! :coffee:", true)
p:console("Rem passthru remark! :coffee:", false, false)

local json = require("dkjson")
print("Fetching prefs:")
Expand Down
2 changes: 1 addition & 1 deletion client/experimental_client_with_swig/testembedded.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if "uC:" in line:
print(line)
print("Device:", p.name)
p.console("Rem passthru remark! :coffee:", True)
p.console("Rem passthru remark! :coffee:", capture=False, quiet=False)

import json
print("Fetching prefs:")
Expand Down
2 changes: 1 addition & 1 deletion client/experimental_lib/example_c/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ int main(int argc, char *argv[]) {
}
pm3 *p;
p = pm3_open(argv[1]);
pm3_console(p, "hw status", true);
pm3_console(p, "hw status", false, false);
pm3_close(p);
}
2 changes: 1 addition & 1 deletion client/experimental_lib/example_c/test_grab.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int main(int argc, char *argv[]) {
p = pm3_open(argv[1]);

// Execute the command
pm3_console(p, "hw status", false);
pm3_console(p, "hw status", true, true);

const char *buf = pm3_grabbed_output_get(p);
const char *line_start = buf;
Expand Down
2 changes: 1 addition & 1 deletion client/experimental_lib/example_lua/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ for line in p.grabbed_output:gmatch("[^\r\n]+") do
end

print("Device:", p.name)
p:console("Rem passthru remark! :coffee:", true)
p:console("Rem passthru remark! :coffee:", false, false)

local json = require("dkjson")
print("Fetching prefs:")
Expand Down
2 changes: 1 addition & 1 deletion client/experimental_lib/example_py/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if "uC:" in line:
print(line)
print("Device:", p.name)
p.console("Rem passthru remark! :coffee:", True)
p.console("Rem passthru remark! :coffee:", capture=False, quiet=False)

import json
print("Fetching prefs:")
Expand Down
2 changes: 1 addition & 1 deletion client/include/pm3.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
typedef struct pm3_device pm3;

pm3 *pm3_open(const char *port);
int pm3_console(pm3 *dev, const char *cmd, bool passthru);
int pm3_console(pm3 *dev, const char *cmd, bool capture, bool quiet);
const char *pm3_grabbed_output_get(pm3 *dev);
const char *pm3_name_get(pm3 *dev);
void pm3_close(pm3 *dev);
Expand Down
2 changes: 1 addition & 1 deletion client/pyscripts/fm11rf08s_recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def print_key(sec, key_type, key):
cmd = f"hf mf fchk -f keys_{uid:08x}.dic --no-default --dump"
if args.debug:
print(cmd)
p.console(cmd, passthru=True)
p.console(cmd, capture=False, quiet=False)
else:
print()
print(plus + color("found keys:", fg="green"))
Expand Down
4 changes: 2 additions & 2 deletions client/pyscripts/pm3.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def __init__(self, *args):
_pm3.pm3_swiginit(self, _pm3.new_pm3(*args))
__swig_destroy__ = _pm3.delete_pm3

def console(self, cmd, passthru=False):
return _pm3.pm3_console(self, cmd, passthru)
def console(self, cmd, capture=True, quiet=True):
return _pm3.pm3_console(self, cmd, capture, quiet)
name = property(_pm3.pm3_name_get)
grabbed_output = property(_pm3.pm3_grabbed_output_get)

Expand Down
6 changes: 4 additions & 2 deletions client/src/pm3.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ void pm3_close(pm3_device_t *dev) {
free_grabber();
}

int pm3_console(pm3_device_t *dev, const char *cmd, bool passthru) {
int pm3_console(pm3_device_t *dev, const char *cmd, bool capture, bool quiet) {
// For now, there is no real device context:
(void) dev;
uint8_t prev_printAndLog = g_printAndLog;
if (! passthru) {
if (capture) {
g_printAndLog |= PRINTANDLOG_GRAB;
}
if (quiet) {
g_printAndLog &= ~PRINTANDLOG_PRINT;
}
int ret = CommandReceived(cmd);
Expand Down
9 changes: 6 additions & 3 deletions client/src/pm3.i
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@

#ifdef PYWRAP
#include <Python.h>
%typemap(default) bool passthru {
$1 = Py_False;
%typemap(default) bool capture {
$1 = Py_True;
}
%typemap(default) bool quiet {
$1 = Py_True;
}
#endif
typedef struct {
Expand All @@ -37,7 +40,7 @@ typedef struct {
pm3_close($self);
}
}
int console(char *cmd, bool passthru = false);
int console(char *cmd, bool capture = true, bool quiet = true);
char const * const name;
char const * const grabbed_output;
}
Expand Down
Loading

0 comments on commit de96479

Please sign in to comment.