From aeb3705237883ca3893a5d80a91c925d1ffdd942 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Fri, 6 Nov 2026 22:27:28 +0100 Subject: [PATCH] data rawdemod: stop cutting --max, --samples and --p2 clock to 8 bits The values went through uint8_t or & 0xFF, so --max 300 ran with 44 and --samples 1000 with 232. The --fs clocks stay 8-bit in the FSK demod and are now refused above 255. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + client/src/cmddata.c | 30 ++++++++++++++++++------------ tools/pm3_tests.sh | 3 +++ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e135b090..00e44d29c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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] +- Fixed `data rawdemod` - `--max`, `--samples` and the `--p2` clock no longer wrap above 255, `--fs` refuses values above 255 (@matrix) - Fixed `mfulc_des_brute` build on macOS without `openssl@3.6` - OpenSSL is found with `brew --prefix openssl` as in `mfd_aes_brute` (@matrix) - Fixed CI - ProxSpace installs its packages again, WSL builds in its own file system, Ubuntu skips the slow Azure apt mirror (@matrix) - Fixed `recovery.bin` on the AT91 platforms - the bootrom is padded to 0x102000 again, so the OS image is at its load address (@matrix) diff --git a/client/src/cmddata.c b/client/src/cmddata.c index 91f09ebcc..29f6ff0fe 100644 --- a/client/src/cmddata.c +++ b/client/src/cmddata.c @@ -474,8 +474,8 @@ static int Cmdaskmandemod(const char *Cmd) { uint16_t clk = (uint16_t)arg_get_int_def(ctx, 2, 0); bool invert = arg_get_lit(ctx, 3); bool st = arg_get_lit(ctx, 4); - uint8_t max_err = (uint8_t)arg_get_int_def(ctx, 5, 100) & 0xFF; - size_t max_len = (size_t)arg_get_int_def(ctx, 6, 0) & 0xFF; + int max_err = arg_get_int_def(ctx, 5, 100); + size_t max_len = (size_t)arg_get_int_def(ctx, 6, 0); CLIParserFree(ctx); return ASKDemod_ext(clk, invert, max_err, max_len, amplify, true, true, 1, &st); @@ -718,7 +718,7 @@ static int Cmdaskbiphdemod(const char *Cmd) { uint16_t clk = (uint16_t)arg_get_int_def(ctx, 1, 0); bool invert = arg_get_lit(ctx, 2); int offset = arg_get_int_def(ctx, 3, 0); - uint8_t max_err = (uint8_t)arg_get_int_def(ctx, 4, 50) & 0xFF; + int max_err = arg_get_int_def(ctx, 4, 50); CLIParserFree(ctx); return ASKbiphaseDemod(offset, clk, invert, max_err, true); @@ -751,8 +751,8 @@ static int Cmdaskrawdemod(const char *Cmd) { uint16_t clk = (uint16_t)arg_get_int_def(ctx, 2, 0); bool invert = arg_get_lit(ctx, 3); bool st = arg_get_lit(ctx, 4); - uint8_t max_err = (uint8_t)arg_get_int_def(ctx, 5, 100) & 0xFF; - size_t max_len = (size_t)arg_get_int_def(ctx, 6, 0) & 0xFF; + int max_err = arg_get_int_def(ctx, 5, 100); + size_t max_len = (size_t)arg_get_int_def(ctx, 6, 0); CLIParserFree(ctx); return ASKDemod_ext(clk, invert, max_err, max_len, amplify, true, false, 0, &st); @@ -1348,12 +1348,18 @@ static int CmdFSKrawdemod(const char *Cmd) { }; CLIExecWithReturn(ctx, Cmd, argtable, true); - uint8_t clk = (uint8_t)arg_get_int_def(ctx, 1, 0) & 0xFF; + int clk = arg_get_int_def(ctx, 1, 0); bool invert = arg_get_lit(ctx, 2); - uint8_t fchigh = (uint8_t)arg_get_int_def(ctx, 3, 0) & 0xFF; - uint8_t fclow = (uint8_t)arg_get_int_def(ctx, 4, 0) & 0xFF; + int fchigh = arg_get_int_def(ctx, 3, 0); + int fclow = arg_get_int_def(ctx, 4, 0); CLIParserFree(ctx); + // the fsk demod holds them in a byte + if (clk < 0 || clk > 0xFF || fchigh < 0 || fchigh > 0xFF || fclow < 0 || fclow > 0xFF) { + PrintAndLogEx(FAILED, "Clock and field clocks must be 0 - 255"); + return PM3_EINVARG; + } + return FSKrawDemod(clk, invert, fchigh, fclow, true); } @@ -1694,7 +1700,7 @@ static int CmdNRZrawDemod(const char *Cmd) { uint16_t clk = (uint16_t)arg_get_int_def(ctx, 1, 0); bool invert = arg_get_lit(ctx, 2); - uint8_t max_err = (uint8_t)arg_get_int_def(ctx, 3, 100) & 0xFF; + int max_err = arg_get_int_def(ctx, 3, 100); CLIParserFree(ctx); return NRZrawDemod(clk, invert, max_err, true); @@ -1724,7 +1730,7 @@ int CmdPSK1rawDemod(const char *Cmd) { uint16_t clk = (uint16_t)arg_get_int_def(ctx, 1, 0); bool invert = arg_get_lit(ctx, 2); - uint8_t max_err = (uint8_t)arg_get_int_def(ctx, 3, 100) & 0xFF; + int max_err = arg_get_int_def(ctx, 3, 100); CLIParserFree(ctx); int ans = PSKDemod(clk, invert, max_err, true); @@ -1760,9 +1766,9 @@ static int CmdPSK2rawDemod(const char *Cmd) { }; CLIExecWithReturn(ctx, Cmd, argtable, true); - uint8_t clk = (uint8_t)arg_get_int_def(ctx, 1, 0) & 0xFF; + uint16_t clk = (uint16_t)arg_get_int_def(ctx, 1, 0); bool invert = arg_get_lit(ctx, 2); - uint8_t max_err = (uint8_t)arg_get_int_def(ctx, 3, 100) & 0xFF; + int max_err = arg_get_int_def(ctx, 3, 100); CLIParserFree(ctx); int ans = PSKDemod(clk, invert, max_err, true); diff --git a/tools/pm3_tests.sh b/tools/pm3_tests.sh index 6999c87d5..675fdd4dd 100755 --- a/tools/pm3_tests.sh +++ b/tools/pm3_tests.sh @@ -471,6 +471,9 @@ while true; do if ! CheckExecute "data qrcode odd hex" "$CLIENTBIN -c 'data qrcode -d a' 2>&1" "QR data must contain an even number of hex digits"; then break; fi if ! CheckExecute "data qrcode spaced hex" "$CLIENTBIN -c 'data qrcode -d \"aa bb\"' 2>&1" "Spaces are not supported; encode a space byte as 20"; then break; fi if ! CheckExecute "data modulation keeps trace" "$CLIENTBIN -c 'data load -f traces/lf_Q5_mod-psk1-32-4.pm3; data modulation; data autocorr -w 99999'" "smaller than trace \\( 20000 samples \\)"; then break; fi + if ! CheckExecute "data rawdemod fs clock range" "$CLIENTBIN -c 'data rawdemod --fs -c 300' 2>&1" "Clock and field clocks must be 0 - 255"; then break; fi + if ! CheckExecute "data rawdemod ar samples" "$CLIENTBIN -c 'data load -f traces/lf_ATA5577_keri.pm3; data setdebugmode -1; data rawdemod --ar --samples 1000' 2>&1" "maxLen 1000"; then break; fi + if ! CheckExecute "data rawdemod am max errors" "$CLIENTBIN -c 'data load -f traces/lf_EM4102-1.pm3; data setdebugmode -1; data rawdemod --am --max 300' 2>&1" "maxErr 300"; then break; fi if ! CheckExecute "mfu pwdgen test" "$CLIENTBIN -c 'hf mfu pwdgen --test'" "Selftest ok"; then break; fi if ! CheckExecute "mfu keygen test" "$CLIENTBIN -c 'hf mfu keygen --uid 11223344556677'" "80 B1 C2 71 D8 A0"; then break; fi if ! CheckExecute "jooki encode test" "$CLIENTBIN -c 'hf jooki encode --test'" "04 28 F4 DA F0 4A 81 \( ok \)"; then break; fi