getUID() hardcoded ISO15_HIGH_SPEED, so every scan step ran at 1 out of 4
even with -2. A tag that only answers at 1 out of 256 could not be found,
and the modulation changed halfway through the exchange.
Pass fast down from the callers that have -2. readHF15Uid (hf search),
hf 15 csetuid and hf 15 implant have no such option and keep high speed;
note that csetuid's -2 selects the gen2 magic command, not the data rate.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Found by a shellcheck pass and a cross-check of the package key table against
the keys the checks actually record.
- The "Packages to install" section was gated on the resolved package names
being non-empty, but pkgs_for_keys() yields nothing when the package manager
is nix or unrecognised. Both of those branches were therefore dead code: a
NixOS user never saw the nix-shell tools/shell.nix line the Linux install
doc promises, and an unknown distro printed nothing at all. Gate on the keys
instead, and say something useful when no package names are known.
- clang had no entry in any package table, so a missing clang was recorded and
then silently dropped from the install line. Added for apt, pacman, dnf and
zypper; left out for brew and port, where clang is the system compiler.
- A post-release such as 4.1.2.post1 was reported as not matching ==4.1.2,
because the version tuples were compared at different lengths. Zero-pad to
the longer one. A real mismatch is still caught.
- Quote the prefix in ${VENV_DIR#$PM3PATH/} and ${py#$PM3PATH/}: unquoted it is
a glob pattern, so a repo path containing [ or * printed a wrong hint path.
- in_list() iterated $* instead of $2, and one hint wrapped a variable in a
pointless $(echo ...).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The loop threw away each subshell's status and had no set -e, so a failed
docker build left no trace but docker's own error text, buried in the
scrollback of 17 image builds. Worse, a for loop exits with the status of its
last iteration, so the script returned 0 whenever the final entry succeeded,
no matter how many earlier ones had failed.
Collect the failures and print them as a summary, exit 1 if there are any.
A name in the list with no matching directory is counted as a failure too
rather than passing by as a one-line cd error, which is how ubuntu-24.10 has
been quietly skipped since that directory went away.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Running on battery with no adapter attached, the AW32001 latches VIN_FAULT
in REG09, so `hw status` printed the charger detail line at normal debug
level on every PM5 with a BWM and no input power.
Gate the line on the fault bits minus VIN_FAULT when REG08 PG_STAT says
there is no input power. The line itself still decodes the real fault
byte, so VIN_FAULT is unchanged in the output when the line does print.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The release matrix built PM3GENERIC and PM3RDV4 only, so every release went
out without PM5 ever being compiled, even though AGENTS.md asks for both and
PM5 has build options no other platform has.
Adds three firmware builds, covering every PLATFORM_EXTRAS token Makefile.hal
accepts for PM5 plus its own standalone mode and size switch: a bare build on
a flash-backed standalone, BWM with GDB_GATEWAY, and NO_LOWBATT_SHUTDOWN plus
NO_LOWBATT_BEEP with SKIP_CEP=1 and no standalone. BTADDON and FPC_USART_DEV
are rejected on PM5, which also rules out HF_CARDHOPPER and HF_REBLAY, so
there is no line for those. SMARTCARD is left out too: the token is accepted
but PM5 does not compile i2c.
Adds a cmake client build as well. That one passes PLATFORM to cmake, not to
make, because client/CMakeLists.txt reads it at configure time to set
-DDEFAULT_PM5; passed to make it would be ignored and the build would not be
a PM5 client at all.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
- StCheckSig() ignored the result of hexstr_to_byte_array(). Signature
blocks with a character that is not hex gave a 32-byte signature set
only up to that character, the rest printed from an uninitialised
buffer. The buffer is now zeroed, and such blocks print "Signature
blocks are not a hex string" and return PM3_ESOFT.
- The two returns without a signature now say why: "No signature,
block 63 is not K04S", or the block and the error it answered.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The block size of the system info is masked with 0x1F, as in
hf 15 info: its top 3 bits are RFU.
- Without a memory size in the system info, the dump reads up to 128
blocks of --bs bytes, fewer when they do not fit in the 2048-byte
buffer (64 with --bs 32), instead of refusing --bs above 16.
- --bs above 32, the largest ISO15693 block, is set to 32 with a
warning. It was stored in a uint8_t, so --bs 256 became 0 and
--bs 260 became 4.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- NxpTestEAS() reported "EAS ... is not active" also when hw tearoff
had stopped EAS ALARM. It now returns PM3_ETEAROFF. No answer is still
"not active", for PM3_ETIMEOUT and PM3_EPARTIAL alike: the SLIX
tested here sends nothing to EAS ALARM with its EAS mode disabled,
and the firmware returned PM3_EPARTIAL in 7 of 12 runs, with no tag
answer in the trace.
- ISO15_ERROR_HANDLING_CARD_RESPONSE tested d[0] instead of its own
parameter. It now uses (data)[0] and (data)[1].
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A first-run check for a freshly cloned repo, so a new user finds out what is
missing before a build fails halfway through.
Checks the host toolchain (GNU make, gcc/g++, pkg-config, git, gcc >= 8 for
Qt6), the arm-none-eabi toolchain plus a linkable ARM C library, the required
client libraries (readline, bz2, lz4, libcrypto) and the optional ones, the
bundled-fallback ones, a Python venv with tools/requirements.txt, and on Linux
the dialout/uucp membership, the udev blacklist rule, ModemManager and the
rights on /dev/ttyACM*. Also the tracked .dummy files that hold the firmware
object directories in git, since nothing recreates those.
Detection is by probe, not by querying the package manager: pkg-config where a
.pc file exists, otherwise a real compile-and-link of the header with its -l
flag. Python requirements are compared offline through importlib.metadata.
The device side is covered too: it resolves PLATFORM and PLATFORM_EXTRAS the
way make does, rejects unknown platforms and the combinations Makefile.hal
errors on later (BWM off PM5, BTADDON on PM5, ...), and when there is no
Makefile.platform at all it lists the platforms and offers to write one for the
device the user picks, rather than silently building an RDV4 image.
It changes nothing by default. It asks before creating a venv and before
writing a Makefile.platform, and only --install touches the package manager.
Missing items are mapped to package names for apt, pacman, dnf, zypper, brew
and port and printed as one paste-ready line; NixOS is pointed at
tools/shell.nix.
make configure runs it. The script stays directly callable because make stops
on an invalid PLATFORM before it could run any target.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
strlen() of the directory literal made the path buffer a VLA that
Apple clang folds to a constant and rejects under -Werror
(-Wgnu-folding-constant). Size it with sizeof and build it with one
snprintf.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Default level is down to 7 lines:
- Battery: charge %, voltage, temperature and charge state on one line,
draw and runtime left while discharging; capacity and health
- BWM: firmware, chip, link speed and BLE state on one line
- Power: power save with the auto-off triggers, Flipper link
Charge %, health and temperature are colour coded. Charger detail is
shown on a fault or FET_DIS. Charge profile, raw gauge values, chip
and heap details and the idle / sleep counters need hw dbg -3. A
negative temperature now keeps its sign.
pm5_battery_test.py parses the new Charge / Capacity lines.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Parsing:
- all subcommands parse through the argtable: --on/--off, -m <mode>,
-u <on|off> via CLIGetOptionList, wifi --status/--stop; no more
sscanf positional words, so every option shows in the help
- wifi status and stop split into helpers; help examples aligned, the
SSID example shows quoting
Output:
- 20 column labels as in hw status, state colour coded
- autooff: 4 lines; the idle timer shows when a client pauses it,
USB / client / BLE inputs only in client debug mode
- wifi --status, wifipower and the bring-up share one WiFi state line
- ble status: the factory passkey is shown red; the pairing hint shows
only while pairing is off, the passkey hint only for the default key
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- BWM sets the same six defines as make (status, power LED, auto-off,
low-batt beep and shutdown), not only WITH_BWM_FORWARD
- accept the NO_LOWBATT_BEEP / NO_LOWBATT_SHUTDOWN tokens
- enable CEP on PM5 (SKIP_CEP to drop it) and build pm5_cep.c
- enable SEOS unless SKIP_SEOS
- at32_unit_test.c: drop its CEP SPI copies when pm5_cep.c is built
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VPATH += ../armsrc also resolved obj/libarmlib.a to armsrc's copy, so
the armlib sub-make was skipped and ld failed on the missing
bootrom/obj/libarmlib.a. A vpath %.c limits the search to sources.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kvsprintf wrote the NUL through PCHAR, which also bumped the return
count, so sprintf("abc") returned 4 instead of 3. Appending with
p += sprintf(p, ...) then left a NUL between the pieces and only the
first one was printed. %n reported the same off-by-one. Nothing else in
the firmware used the return value.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two of the phases left after the state file and table build fixes.
PartialSumProperty() evaluated each of the 16 four bit suffixes as its own
chain of filter() calls, but the suffixes share prefixes, so walking them as
a binary tree needs 31 calls instead of about 64. Output verified identical
for all 2^21 state and half combinations.
update_allbitflips_array() accumulated an AND over 256 state arrays for the
even and the odd half one after the other, although the halves share no data.
Run them side by side.
init_part_sum_bitarrays 1.095 s -> 0.425 s
update_allbitflips_array 0.847 s -> 0.520 s
Key still recovered on a hard prng 4K, live and from a nonce file, and by
hf mf hardnested -t.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The check rejected ncpus >= detected_cpus, so on a 12 core host --ncpu 12
failed with "invalid number of CPU cores: --ncpu 12 (available: 12)" and the
highest value accepted was one less than what the client uses by default.
Reject only more than detected.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
hf mf hardnested with stats enabled appends to hardnested_stats.txt in the
directory the client was started in, usually the source root, where it was
left behind by make clean.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
init_part_sum_bitarrays() walked all 2^20 states twice per half of the
state, once for Sum(a0) and once for Sum(a8), so PartialSumProperty() ran
four million times although two million distinct results exist. Each state
then set its 16 bits one at a time, 67 million set_bit24() calls in total.
Walk the states once and use what the two bit patterns actually are:
- a0 sets state << 4 | 0..f, which is one aligned half word
- a8 sets state | 0..f << 20, the same pattern repeated every 2^20 bits,
so fill the lowest block and copy it up
Same tables, 3.5 s -> 1.5 s. With the state file search fix the whole attack
on a 4K target goes 54 s -> 22 s, key recovered unchanged.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
init_bitflip_bitarrays() called searchFile() for each of the 2 * 1023 bitflip
state tables, and for a table that is not present it called it three times,
once per supported extension. searchFile() walks the configured default paths,
so each lookup stats file.default.savepath, dumppath and tracepath.
Those preferences often point somewhere slow. With them on a Windows drive
under WSL, where a stat costs ~6.6 ms, the ~6000 stats cost more than half of
the whole attack. Loading the small LZ4 tables was slower than the 700 MB of
raw ones, because a missing raw table meant a second search.
All the tables live in one directory, so search for the first one only and
build the remaining paths from the directory it was found in. A broken install
with no tables behaves as before.
Table load on a FM11RF08S-era 4K target, with default preferences:
raw tables present: 33.3 s -> 0.48 s
LZ4 tables only: 36.5 s -> 1.09 s
whole attack: 54 s -> 24 s, same key recovered
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
- DSFID, AFI, memory size and IC reference were read at fixed
positions, so on a tag without DSFID or AFI the block size and
count came from the wrong bytes. They are now read after the
fields the tag really sent.
- A memory larger than the 2048-byte dump buffer overflowed it. It
is now refused.
- A block answer shorter than the block size was copied as a full
block. It is now reported and not copied.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- AFI, memory size and IC reference were read at fixed positions,
so a tag without DSFID or AFI showed wrong values. They are now
read after the fields the tag really sent. The block count no
longer wraps to 0 on a tag with 256 blocks.
- The NXP DSFID and password protection pointer lock bits were read
from the wrong bits. They are now bits 0x04 and 0x08, as in the
SLIX2 datasheet (table 73).
- The ST25TV signature, 32 bytes, overflowed a 16-byte buffer. On a
tag error the signature read now frees its request and drops the
field. When the tag has no signature, it drops the field and
returns success, so hf 15 info no longer ends with an error.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The SLIX tested here sends no answer to EAS ALARM when its EAS
mode is disabled, and hf 15 info ended with an error. It now
reports the EAS mode as not active.
- The two error helpers of the hf 15 commands printed the flags
byte instead of the error code. They now print the error code.
hf 15 info also prints the errors 0F and 10, which the helpers
keep silent.
- The option -2 (1 out of 256) now also applies to the NXP and ST
requests sent after the system info.
- A UID given with -u was sent in the wrong byte order, so no tag
answered. It is now sent LSB first, as hf 15 rdbl does. A -u that
is not 8 bytes long is refused instead of scanning.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fm11_prioritize_defaults() walked the whole candidate list once per
dictionary key, and it is called for each sector with tens of thousands of
candidates and ~85k dictionary keys, so it did on the order of 10^10
comparisons per run.
Index the candidate keys first and skip a dictionary key that is not in the
list, which is nearly all of them. A key that is present still takes the
original scan, so the resulting order is unchanged. Falls back to the plain
scan when the index cannot be allocated.
Same key table recovered on a FM11RF08S, hf mf sen 6.1 s -> 5.2 s offline
and 7.4 s -> 6.6 s for a full run.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
fm11_key_matches_nonce() runs once per dictionary key per unknown key slot,
up to 85442 * 34 times. For every one of them it malloc'd a cipher state,
clocked two full 32 bit keystream words and only then compared the first,
although nearly every key fails on the first byte.
Keep the state on the stack, compare a byte at a time and stop at the first
mismatch, and clock the second word only for a key that survives. Same keys
accepted, about 6x less time in that phase (2.9 s -> 0.5 s for a full 34 slot
scan of the 85k dictionary).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Nested and static nested recovery ran lfsr_recovery32 once per nonce and
intersected two ~2^16 candidate lists. The cipher state is linear while the
nonce is fed in, so the states for one nonce are those for the other xored
with a known difference. Checking both keystreams inside a single recovery
leaves about one candidate instead of two large lists.
lfsr_recovery32_dual() does that: it skips the early bit times where the
difference prunes little (start chosen per call from an exact per bit match
probability, falling back to 0 on overflow), scans the first pass 64 states
at a time through a bit packed filter table, extends the tables branch free
in cache sized chunks, and replaces the 512 scattered sort buckets with one
contiguous counting sort.
lfsr_recovery32() is rebuilt on the same machinery, so hf mf sen, mfkey32,
mfkey64 and the nested tools all gain. It stays single threaded because
nested_util.c already calls it from four threads. recover() takes the second
keystream as optional extra state; the plain path is unchanged.
Both return the same key sets as before, verified against the old code under
ASan/UBSan over random and degenerate nonce pairs.
nested per key: ~390 ms -> ~4 ms
lfsr_recovery32 per call: ~270 ms -> ~165 ms
peak RSS, single nonce: 47.6 MB -> 27.6 MB
tools/mfc/protocol links pthread now, as the other two mfc tool dirs do.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
With iclass the script answers the SAM's e-purse UPDATE in place of
the card. It sent the second half of the new value, then 87 02 and two
bytes of the first half. A card answers the two halves swapped.
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>