Commit Graph
223 Commits
Author SHA1 Message Date
Matthew CarrollandClaude Opus 5 907f21b8cb lf psk demod: do not accept a phase shift from the lead-in
The emitted bit is the running phase, so a shift accepted before the tag answers
toggles curPhase once too often and the rest of the word comes back complemented.

pskFindFirstPhaseShift judged its first measured length, but waveStart starts as
wherever the caller began looking - that length is part of a wave, not a wave,
and any gap beating fc was taken as a shift. Baseline on the first peak instead.
pskRawDemod_ext separately trusted a shift under one bit period in; the clock is
known by then, so look again from a bit period in.

Both are needed - dropping either leaves one of the tags measured inverting on
most reads.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 14:57:15 -07:00
Matthew CarrollandClaude Opus 5 e206d748a2 lf fsk demod: do not fabricate a bit from a leading run
aggregate_bits sized each run of like waves in bits and then forced a zero to
one. That is right mid-stream, where a run rounding to nothing would drop a bit
the tag did send. On the leading run it is wrong: a single subcarrier wave is
about fchigh samples against a bit period of clk, so it rounds to no bits and
was made into one anyway - a bit the tag never sent, shifting every bit after it
and dragging startIdx back by most of a bit period.

Skip a leading run that rounds to nothing and let the next transition be first.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 14:57:14 -07:00
Matthew CarrollandClaude Opus 5 1ebcf225f1 lf nrz demod: start the bitstream at the first edge
The samples before the first level change were counted as bits, and where no
edge arrives inside ten clocks the long-run flush fired first and invented ten
of them out of the quiet lead-in. The count sat on a rounding boundary, so one
sample of jitter in that edge added or dropped a leading bit and rotated the
rest of the word - while startIdx, derived from the same count, held i % clk and
could name no sample.

A level change can only fall on a bit boundary, so start there and report it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 14:57:11 -07:00
iceman1001 ace5d63ff9 hitag2: fix simulation against genuine readers, add restore, fix info
Simulation now completes the full exchange with a genuine Paxton reader in
password mode, and crypto mode read/write passes Proxmark-to-Proxmark.

Firmware:
- SOF was one bit period short. The lead-in that compensated for the lost
  head half bit was removed and nothing replaced it, so readers rejected
  every answer with a second START_AUTH. Default is now 6.
- The edge-detect threshold was latched before being measured, so the value
  chosen depended on whether the Proxmark was in a field when sim started.
  It is now measured on field entry and re-armed when the reader leaves.
- The percentile walk latched on run-scoped variables, so one attempt made
  outside a field poisoned every later one.
- Field loss was detected from TIMESTAMP, which is free-running MCU time and
  never stalls. Detect it from receive silence instead.
- Frames of a length the protocol does not have no longer reach the state
  machine; our own modulation tail was resetting the session and breaking
  every write.
- A dropped edge merges two or three reader bit periods into one gap. Those
  bits were discarded; they are now recovered by decomposition, which is what
  made crypto mode work (AUTH decode 15% -> 100%).
- Threshold selection is limited to 20 and 32 and settles in under 25 ms.

Client:
- lf hitag info printed a hardcoded 0x06 and reported 'Password mode' for
  every tag. It now reads page 3, takes -k (4 bytes password, 6 bytes
  crypto), and says so when the config cannot be read.
- lf hitag restore: writes a dump back in dependency order - user pages,
  then key material, then config last - validates the config byte, and
  prints the credential the tag will require afterwards.
- lf hitag crack2 now reports why it failed instead of a bare 'fail'.
- trace list: bit count moved to its own column, relative mode shows a
  Frame Delay Time row rather than renaming Start/End, --frame and -r
  rejected together.
2026-09-04 13:20:29 +02:00
towelbyte 2e35b95a7c Fix: Replace VLAs with heap alloc in lfdemod signal helpers
Using "data load" on very large trace files (e.g. dumps with 700k samples,
such as COTAG dumps) was causing crashes on some platforms due to stack overflow
since VLA temporary buffers were used.

Replace VLAs in computeSignalProperties() and removeSignalOffset() with
heap-allocated buffers instead.
2026-06-13 00:33:24 +02:00
Philippe Teuwen bd242f6e41 cppcheck ctunullpointerOutOfMemory 2025-03-24 11:33:08 +01:00
iceman1001 72900d1bf9 fix and style 2024-09-06 22:36:44 +02:00
iceman1001 b4ba36c1ff adaptations 2024-04-22 19:58:52 +02:00
iceman1001 bcbe76064d Changed modulation max bit length from 512 to 4096, since we now can get much longer traces 2023-12-01 10:58:33 +01:00
Philippe Teuwen 3aeb5c493f fix a few cppcheck warnings 2023-09-07 22:28:37 +02:00
iceman1001 8e38723149 just in case psk get odd clocks in some old system 2023-07-22 23:27:30 +02:00
iceman1001 c01c0427bb forgot the clock changes. 2023-07-21 17:05:18 +02:00
iceman1001 4d9f97954e allow for clocks larger than 255 to be used from commandline. added the new command data envelope. it creates square signal, similar to askedgedetect.\n adapted find closest clock in order to make clock /8 less prioritized if there are more found clocks. use second best match in those cases. 2023-07-21 14:35:24 +02:00
iceman1001 403385c56c style 2023-07-12 14:00:19 +02:00
Philippe Teuwen 623169fe02 fix some CodeQL warnings 2022-02-16 20:28:38 +01:00
Philippe Teuwen 5a4584358c make style 2022-01-09 14:10:26 +01:00
iceman1001 fe9348768d use calloc instead 2022-01-09 00:33:33 +01:00
Philippe Teuwen 30aa7aa7d1 Adapting license headers, WIP 2022-01-08 00:40:52 +01:00
iceman1001 7efd02b6e0 cppcheck fixes 2022-01-06 22:08:28 +01:00
iceman1001 0bad12fcac cppcheck 2022-01-01 17:45:43 +01:00
Philippe Teuwen 88308ea727 typos 2021-10-10 01:35:45 +02:00
Philippe Teuwen 3cadd2906e Fix clang-13 warnings about unused variables 2021-08-25 10:10:46 +02:00
Philippe Teuwen d88c98a786 Reduce scope of a number of globals:
APDUInFramingEnable atsFSC uid_label_map apdu_in_framing_enable uidmapping KENC_type KMAC_type jpeg_header jpeg2k_header *card_types card_app2_limit iclass_config_types jooks jooks_figures nfc_secret desdefaultkeys aesdefaultkeys k3kdefaultkeys CardAddresses default_3des_keys default_pwd_pack UL_TYPES_ARRAY UL_MEMORY_ARRAY fdxbCountryMapping translateTable invTranslateTable preamble paradox_lut pcf7931_config config DiArray FiArray FArray crc64_table signalprop
2021-08-21 19:56:07 +02:00
Philippe Teuwen ee22a824ce Add support for Electra demodulation 2021-08-04 15:11:30 +02:00
iceman1001 58d8fa0e3b style 2021-04-27 19:16:21 +02:00
iceman1001 a9aea6c726 fix in nr demodulation , which fixes a crash in "lf em 4x05 info" 2021-04-04 07:48:53 +02:00
iceman1001 02c1034caa fix #1175 - biphase demod identification of value clocks now fails if no changes detected 2021-01-28 00:35:14 +01:00
Philippe Teuwen 7cd80611d3 #makestyleday 2020-12-12 14:46:40 +01:00
cyberpunk-re 7a3faa7de8 fix parsing for psk 2020-12-11 00:17:51 +00:00
Philippe Teuwen 3eea2e20bb askdemod_ext: update startIdx in case of weak demodulation too 2020-10-07 22:50:22 +02:00
Philippe Teuwen 4e10c9ec0a move idteck to its own file 2020-09-28 21:09:26 +02:00
Philippe Teuwen f69739da79 make style 2020-06-19 18:34:47 +02:00
tharexde 4d292d3ca0 fixed: first bit of em4x50 word was skipped in case of a "0" -> first transition in raw Manchester decoding is now taken into account 2020-06-14 14:51:48 +02:00
Philippe Teuwen 19be62f7e6 stricter warnings: Wredundant-decls 2020-05-03 12:38:34 +02:00
iceman1001 39fd06f947 cppchecker fix - conditionknown 2020-04-28 22:29:22 +02:00
iceman1001 31125b9d34 cppchecker fix - conditionknown 2020-04-28 22:27:50 +02:00
iceman1001 9a921d6944 style 2020-03-09 17:09:07 +01:00
iceman1001 0be6737ad9 debug state 2020-02-04 17:38:02 +01:00
iceman1001 8696b521ef protect debug messages 2020-02-03 21:38:42 +01:00
iceman1001 0ffb748f5e fix: hi/low should not be same 2019-10-14 21:17:41 +02:00
Philippe Teuwen 395d0f9ebf make style 2019-10-13 00:48:26 +02:00
Philippe Teuwen e4ad1a7471 coverity 227889 227898 - division by zero 2019-10-09 23:01:07 +02:00
Philippe Teuwen 9fac99025b fix bunch of printf api warnings in common/lfdemod.c 2019-10-09 16:40:01 +02:00
iceman1001 1e5e930bf0 clean 2019-10-08 22:04:15 +02:00
iceman1001 9a0ca9c4cd better median for clietside 10%-90% only. thanks for the suggestion @doegox!. Device side still uses old algo 2019-09-22 19:00:11 +02:00
Philippe Teuwen 960d8c4db3 add helper fct manchesterEncodeUint32 2019-09-15 02:09:40 +02:00
Philippe Teuwen d19754567d summer restructuring:
* .h include only the strict minimum for their own parsing
  * this forces all files to include explicitment their needs and not count on far streched dependencies
  * this helps Makefile to rebuild only the minimum
  * according to this rule, most standalone .h are now gone
  * big app.h is gone
  * remove seldom __cplusplus, if c++ happens, everything will have to be done properly anyway
* all unrequired include were removed
* split common/ into common/ (client+arm) and common_arm/ (os+bootloader)
  * bring zlib to common/
  * bring stuff not really/not yet used in common back to armsrc/ or client/
  * bring liblua into client/
  * bring uart into client/
  * move some portions of code around (dbprint, protocols,...)
* rename unused files into *_disabled.[ch] to make it explicit
* rename soft Uarts between 14a, 14b and iclass, so a standalone could use several without clash
* remove PrintAndLogDevice
* move deprecated-hid-flasher from client to tools
* Makefiles
  * treat deps in armsrc/ as in client/
  * client: stop on warning (-Werror), same as for armsrc/

Tested on:

* all standalone modes
* Linux
2019-08-11 21:42:01 +02:00
iceman1001 2fecbb6141 chg: return values. 2019-08-04 19:26:53 +02:00
Philippe Teuwen b0dbbd3683 make style 2019-07-13 00:38:30 +02:00
iceman1001 34d794d9fd debug output 2019-06-08 10:16:15 -04:00