Commit Graph
248 Commits
Author SHA1 Message Date
iceman1001andClaude Opus 5 (1M context) ee2d55fafb hf mfdes: put a DESFire card image in emulator memory
Adds the on-device card image a DESFire simulation will read, the client
side that packs a dump into it, and eload / esave / eview.

The layout is in include/desfire_em.h. Tables grow up from the header,
file data grows down from the end, and an allocation only has to leave
the two frontiers apart -- so a three-file card spends a few hundred
bytes rather than a worst case, and the space between them is what the
card has left. The PICC is application 000000 and uses the same struct
as any other application, so key settings and keys are always stated
against an AID. Delete sets a tombstone rather than compacting, which is
not a shortcut: a real card does not reclaim on delete either, measured
as 2080 bytes free with zero applications before an experiment and 2560
after FormatPICC.

Two size limits, and a reader only ever sees the first. cardsize is what
the emulated card claims to hold, so GetFreeMem answers from that and
CreateFile will refuse with OUT_OF_EEPROM when it runs out. Without it a
card impersonating a 2K part would report 7434 bytes free, which no 2K
part does. The image size is what emulator memory physically holds, is
the harder limit, and is never visible.

cardsize is anchored to the free memory the real card reported when the
dump was taken -- observed free plus what we reserve for the same content
-- so the emulation answers what its original answered. That is also a
check on the reservation rule rather than only a convenience: for the
bench card it computed 576 bytes spent, and 1984 + 576 is 2560, exactly
what that card reports when formatted.

Reservation follows what CommitTransaction covers. Backup data, value and
record files each get a shadow region because writes to them are staged
until commit; a standard data file writes through and does not. Sizes
round to a 32 byte granule, which is the granule a real card allocates in.
It deliberately does not reproduce NXP's allocator -- that is
undocumented and does not fit a simple model, a declared 1024 byte record
file costs 1088 on silicon -- so what matters is that the figure is
self-consistent and shrinks as the reader writes.

No new device command. Emulator memory is one shared region, so
CMD_HF_MIFARE_EML_MEMSET and BIG_BUF_EML already reach it, and both
inherit the bounds checking those paths gained earlier.

Verified with the client only, no simulation yet: packing a dump taken
from a DESFire EV2 and walking it back reproduces every field including
file contents byte for byte, the same round trip through the device via
eload and esave is identical, and an image too large is refused by name
rather than truncated -- 'Out of emulator memory laying out AID 112233
file 00: needs 4066 more bytes'.

Co-Authored-By: Claude Opus 5 (1M context)
2026-09-14 19:48:45 +02:00
iceman1001andClaude Opus 5 (1M context) 8fd9bcbebc hf mfdes: dump a whole card to json, and view it back
'hf mfdes dump' walked one application and printed it. It now walks
every application on the PICC, keeps what it reads, and saves a
'hf-mfdes-<UID>-dump.json' card image. '--aid' / '--isoid' / '--dfname'
still narrow it to one application, '--ns' skips the save.

The format is 'mfdes v1', written and read in fileutils.c and documented
in doc/mfdes_dump_format.md. Two decisions worth stating:

 - The PICC level is application 000000, so every key in the file says
   which AID it opens. Key version and key value are separate: a version
   with no key is the normal shape for a key that was found but never
   recovered, and a missing key never means the key is zero.

 - Every file carries a 'Read' flag. A file whose contents could not be
   fetched is recorded as unread with no data at all, rather than as a
   run of zeros. A simulator built on this must not confuse '8 bytes of
   00' with 'we could not read 8 bytes'.

'hf mfdes view -f <fn>' prints such a file with no device attached.

With no '--keys', the dump looks for 'hf-mfdes-<UID>-keys.json' by
itself, so a 'hf mfdes chk -j' run is picked up on the next dump without
naming the file again.

Two fixes fell out of testing against a DESFire EV2:

 - DesfireSetKey() calls DesfireClearContext(), which wipes command set,
   comm mode, KDF and UID, not just the key. Swapping in a per-application
   key that way left the context at 'Communication mode: n/a' and
   DesfireFillFileList() then returned junk file ids. Use
   DesfireSetKeyNoClear().

 - GetVersion and the originality signature are answered unauthenticated.
   Asking for them from inside the authenticated session produced a
   'Wrong communication mode' warning and a run of MAC mismatches.

hex_to_buffer() treats hex_max_len as a byte count while every sprint_hex*
caller passes sizeof(buf) - 1, a character count, so it writes two or
three times the buffer size. Measured, sprint_hex_inrow overflowed at
4098 input bytes. Doubling UTIL_BUFFER_SIZE_SPRINT to 16384 moves that to
8192; the mixed semantics still need auditing across ~30 call sites.

Co-Authored-By: Claude Opus 5 (1M context)
2026-09-14 09:11:38 +02:00
iceman1001 8e3c439358 text 2026-09-12 21:50:19 +02:00
iceman1001 cb75a05553 text 2026-09-12 15:14:13 +02:00
iceman1001andClaude Opus 5 (1M context) a967560335 hf thinfilm sim - shorter frame gap
The inter frame delay was 3600us for a 128 bit payload and 2400us for 256 bit,
sized so that either one holds a constant 4.8ms repeat period.  That is the wrong
target.  A Kovio tag is never transacted with - the reader captures it during a
poll slot and hands the bytes up as an activation, see
nfa_dm_disc_handle_kovio_activation() in libnfc-nci, which reads the barcode
straight out of rf_tech_param.param.pk.uid - so the only thing that matters is how often a frame is on the air.

Measured repeat period before today was 8.66ms, ie 14% duty cycle.  A fixed 500us
gap takes a 128 bit payload to roughly 2.2ms.  The gap cannot go to zero, a reader
needs unmodulated carrier to find the frame start and our own demod wants three
quiet bytes, but 500us is an order of magnitude clear of that.

Also drop the 'not correct' caveat from 'hf thinfilm list', the sim side traces
properly now.

Tested on RDV4 against an Android reader.  Builds clean for PM3RDV4 and PM5.

Co-Authored-By: Claude Opus 5 (1M context)
2026-09-12 14:17:13 +02:00
iceman1001 2610d0cfc2 text 2026-09-11 10:42:33 +02:00
Iceman 9f641c3ced Merge pull request #3427 from Sanduuz/feature/st25ta_ndef_sim
Added support for emulating ST25TA tag (IKEA Rothult) with custom NDEF response
2026-09-07 15:38:46 +07:00
iceman1001 1a34aac8df texts 2026-09-04 13:32:54 +02:00
iceman1001 35c098d489 make style 2026-08-29 17:42:29 +02:00
Sanduuz 4b67c017a2 make style 2026-08-28 14:53:34 +03:00
iceman1001 77a9f45db6 texts 2026-08-28 01:16:30 +02:00
iceman1001 f6e0119f5f added PACE (--can) support to emrtd commands. 2026-08-21 22:32:06 +02:00
iceman1001 6411ba1ee4 add 2026-07-30 17:06:36 +02:00
iceman1001 19cc98c532 hooked up the new DSP code. Should improve the t55xx commands 2026-07-30 16:43:09 +02:00
iceman1001 436de5d43e style 2026-07-26 23:38:51 +02:00
YoungJules 862a338feb hf legic: rename repeat fill to fill 2026-07-25 19:39:23 +02:00
YoungJules 8b3c67dac3 doc: mention legic wrbl repeat fill 2026-07-25 14:07:09 +02:00
iceman1001 2c6e607110 style 2026-07-15 16:39:15 +02:00
歐歪 f0c3dccdb6 Added hf mf gdmgetblk/gdmgethidblk/gdmsethidblk/gdmsetuid/gdmwipe/gdmsetsig ,improved hf mf gdmparsecfg/gdmsetblk and rename hf mf gdmcfg commands 2026-07-13 21:48:48 +08:00
iceman1001 005f4abb1a texts 2026-07-07 22:50:22 +02:00
iceman1001 c6d01e6e72 update helptexts 2026-06-29 23:51:37 +02:00
Philippe Teuwen 5666cdf4e8 make style 2026-06-23 00:03:16 +02:00
Philippe Teuwen efcc34a698 make style 2026-06-07 23:01:20 +02:00
kormax 73d0388141 Add 'hf mfdes getversion' command 2026-06-07 16:24:31 +03:00
YoungJules 8462363e61 legic: clarify restore and migration flow 2026-06-05 21:08:18 +02:00
Connor Milligan 590edbcc3f Native client support for mfulc desbrute 2026-05-22 00:19:07 +02:00
Philippe Teuwen d078e8a62b make style 2026-05-21 20:54:44 +02:00
iceman1001 cbb572afad style 2026-05-11 14:36:17 +02:00
kormax 7484af6c87 Drop old 'hf 14b calypso' and 'hf 14b mobib' commands 2026-05-03 08:08:15 +03:00
iceman1001 eb54497704 added the command "hf iclass liberate" , it checks for drm markers and removes them, thus liberates them. Now if someone wants to make drm tags, they can easily just make a "hf iclass drm" command with the reverse of this command 2026-04-21 11:17:11 +07:00
iceman1001 6af1a8e432 updated help text for `lf realy 2026-04-11 09:04:55 +07:00
iceman1001 489940cf76 helptexts 2026-04-02 19:43:24 +07:00
iceman1001 6542a35585 update helptexts 2026-03-20 09:45:15 +07:00
xNovyz 52676ebbd4 style: whitespace fixes 2026-03-11 22:41:21 +01:00
xNovyz 286df8f4eb feat(14b): add interactive hf 14b tearoff command
Add an interactive command for performing tear-off attacks on ST25TB/SRx
monotonic counter blocks. This exploits EEPROM tearing to increment
counters that normally can only be decremented, based on the
near-field-chaos project by SecLabz.

The command sweeps tear-off timing from --start downward in --adj
microsecond steps, automatically consolidates partial writes, verifies
stability across multiple reads, and reports progress in real-time with
color-coded output.

Performance optimizations:
- One-time full iso14443b_setup() at start; subsequent field cycles use
  lightweight tearoff_field_on()/tearoff_field_off() that skip FPGA
  bitstream reload and buffer reallocation
- Periodic CMD_WTX keepalives to prevent USB timeouts during long attacks
- Calls FpgaResetBitstream() on exit to ensure clean FPGA state

Usage: hf 14b tearoff -b <block> -d <target> [--start <us>] [--adj <us>]
2026-03-11 21:43:37 +01:00
Philippe Teuwen b62658f5ac make style 2026-02-21 12:43:25 +01:00
Philippe Teuwen 1cf446fa7f make commands 2026-02-06 13:07:16 +01:00
Philippe Teuwen a26892a891 Add hf mfu cchk/aeschk and options to hf mf cauth/aesauth 2026-01-19 21:47:49 +01:00
Aaron Tulino (Aaronjamt) e0fd7414c2 Update docs 2025-12-21 20:55:26 -07:00
Henry Gabryjelski 1cfeb79003 automated from make style 2025-11-17 01:27:32 -08:00
Foxushka b380132cbb Replaced hf mf bambukeys with hf mf keygen with multiple KDFs support, use table for key output
Added Snapmaker U1 filament RFID KDF in `hf mf keygen`
2025-11-10 20:58:49 +03:00
iceman1001 ed516550ca added "data qrcode" command to generate QR codes from inside the PM3 client 2025-11-10 16:20:00 +01:00
Michael Wiesinger 737a6dc3d7 Fix help description for lf indala brute 2025-11-07 21:02:14 +01:00
Philippe Teuwen 4aac77aaa2 support for Ultralight AES auth in hf mfu info/rdbl/wrbl/dump/ndefread/wipe/setkey 2025-10-04 02:00:23 +02:00
iceman1001 d6aeda7075 style 2025-08-29 14:01:34 +02:00
iceman1001 e578d75e66 style 2025-08-20 10:55:49 +02:00
iceman1001 8ab2f2b5a0 style 2025-08-12 19:06:38 +02:00
iceman1001 a0df90af18 style 2025-08-04 19:53:08 +02:00
iceman1001 ee2f5595ee added a lf t55xx view command to view t55xx dump files 2025-07-28 15:46:09 +02:00
iceman1001 ed84b1fcf4 style 2025-07-13 15:55:44 +02:00