From 6e1cf6c0de4be1c8ce5e5c728bf208af30793779 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Fri, 13 Oct 2023 22:51:12 +0200 Subject: [PATCH 1/2] added a C sample of grabbing output --- .../experimental_lib/example_c/01make_test.sh | 1 + .../example_c/02run_test_grab.sh | 3 + client/experimental_lib/example_c/test_grab.c | 67 +++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100755 client/experimental_lib/example_c/02run_test_grab.sh create mode 100644 client/experimental_lib/example_c/test_grab.c diff --git a/client/experimental_lib/example_c/01make_test.sh b/client/experimental_lib/example_c/01make_test.sh index 1ce6357ff..7bda5aa37 100755 --- a/client/experimental_lib/example_c/01make_test.sh +++ b/client/experimental_lib/example_c/01make_test.sh @@ -1,3 +1,4 @@ #!/bin/bash gcc -o test test.c -I../../include -lpm3rrg_rdv4 -L../build -lpthread +gcc -o test_grab test_grab.c -I../../include -lpm3rrg_rdv4 -L../build -lpthread diff --git a/client/experimental_lib/example_c/02run_test_grab.sh b/client/experimental_lib/example_c/02run_test_grab.sh new file mode 100755 index 000000000..2dd6f892b --- /dev/null +++ b/client/experimental_lib/example_c/02run_test_grab.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +LD_LIBRARY_PATH=../build ./test_grab diff --git a/client/experimental_lib/example_c/test_grab.c b/client/experimental_lib/example_c/test_grab.c new file mode 100644 index 000000000..6b093b3ce --- /dev/null +++ b/client/experimental_lib/example_c/test_grab.c @@ -0,0 +1,67 @@ +#include "pm3.h" +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + + int pipefd[2]; + char buf[8196 + 1]; + size_t n; + + if (pipe(pipefd) == -1) { + exit(-1); + } + + int pid = fork(); + if (pid == -1) { + perror("fork"); + exit(-1); + } + + // child + if (pid == 0) { + printf("[INFO] inside child\n"); + + // Redirect stdout to the write end of the pipe + dup2(pipefd[1], STDOUT_FILENO); + + close(pipefd[0]); // Child: close read end of the pipe + close(pipefd[1]); // Close original write end + + pm3 *p; + p = pm3_open("/dev/ttyS9"); + //printf("Device: %s\n", pm3_name_get(p)); + + // Execute the command + pm3_console(p, "hw status"); + pm3_close(p); + _exit(-1); + } else { + + printf("[INFO] inside parent\n"); + // Parent: close write end of the pipe + close(pipefd[1]); + + // Read from the pipe + while (1) { + n = read(pipefd[0], buf, sizeof(buf)); + if (n == -1) { + continue; + } + if (n == 0) { + break; + } else { + // null termination + buf[n] = 0; + if (strstr(buf, "Unique ID") != NULL) { + printf("%s", buf); + } + } + } + + // Close read end + close(pipefd[0]); + } +} From f90434521e210ca093fa2aa18bb268e08cd231a2 Mon Sep 17 00:00:00 2001 From: Self Not Found Date: Sat, 14 Oct 2023 14:04:46 +0800 Subject: [PATCH 2/2] Reduce latency in local TCP connection --- CHANGELOG.md | 1 + client/src/comms.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16037543b..6869596e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ This project uses the changelog in accordance with [keepchangelog](http://keepac - Added `hf iclass creditepurse` command to allow crediting the epurse debit value (@nvx) - Modified `hf iclass configcard` to only support online mode @ATK - Modified `hf iclass configcard` command to generate config cards without a cardhelper module by porting the contents of blocks 7 & 7 from nfc-iclass @ATK + - Changed the timeout of local TCP connections (@wh201906) ## [Raccoon.4.17140][2023-09-09] - Changed text and adjust pm3_test case for mf_aes_brute (@doegox) diff --git a/client/src/comms.c b/client/src/comms.c index a7ed0fd06..d0ec182ab 100644 --- a/client/src/comms.c +++ b/client/src/comms.c @@ -678,7 +678,16 @@ int TestProxmark(pm3_device_t *dev) { if (g_conn.send_via_fpc_usart) { PrintAndLogEx(INFO, "PM3 UART serial baudrate: " _YELLOW_("%u") "\n", g_conn.uart_speed); } else { - int res = uart_reconfigure_timeouts(is_tcp_conn ? UART_TCP_CLIENT_RX_TIMEOUT_MS : UART_USB_CLIENT_RX_TIMEOUT_MS); + int res; + if (is_tcp_conn) { + if (memcmp(g_conn.serial_port_name + 4, "localhost", 9) == 0 || memcmp(g_conn.serial_port_name + 4, "127.0.0.1", 9) == 0) { + res = uart_reconfigure_timeouts(UART_USB_CLIENT_RX_TIMEOUT_MS * 2); + } else { + res = uart_reconfigure_timeouts(UART_TCP_CLIENT_RX_TIMEOUT_MS); + } + } else { + res = uart_reconfigure_timeouts(UART_USB_CLIENT_RX_TIMEOUT_MS); + } if (res != PM3_SUCCESS) { return res; }