Add partial byte annotation in Hitag traces

Example:
[usb] pm3 --> trace load -f traces/lf_HitagS256_dump.trace
[+] loaded 287 bytes from binary file traces/lf_HitagS256_dump.trace
[+] Recorded Activity (TraceLen = 287 bytes)
[?] try `trace list -1 -t ...` to view trace.  Remember the `-1` param
[usb] pm3 --> trace list -1 -t hitags -c
[+] Recorded activity (trace len = 287 bytes)
[=] start = start of start frame end = end of frame. src = source of transfer
[=] Hitag1 / Hitag2 / HitagS - Timings in ETU (8us)

      Start |        End | Src | Data (! denotes parity error)
------------+------------+-----+-----------------------------------------
          0 |          0 | Rdr |18(5)
        117 |        117 | Tag |0f(4) 2c  ab  cc  b3  cf  32  bf [2f]
          0 |          0 | Rdr |00(5) 21  a5  b4  73 [8c]
        117 |        117 | Tag |0f(4) c9  00  00  aa [75]
          0 |          0 | Rdr |0c(4) 00 [ab]
        117 |        117 | Tag |0f(4) 21  a5  b4  73 [53]
          0 |          0 | Rdr |0c(4) 01 [b6]
        117 |        117 | Tag |0f(4) c9  00  00  aa [75]
          0 |          0 | Rdr |0c(4) 02 [91]
        117 |        117 | Tag |0f(4) 48  54  4f  4e [2c]
          0 |          0 | Rdr |0c(4) 03 [8c]
        117 |        117 | Tag |0f(4) 4d  49  4b  52 [1e]
          0 |          0 | Rdr |0c(4) 04 [df]
        117 |        117 | Tag |0f(4) 00  00  00  00 [a6]
          0 |          0 | Rdr |0c(4) 05 [c2]
        117 |        117 | Tag |0f(4) 00  00  00  00 [a6]
          0 |          0 | Rdr |0c(4) 06 [e5]
        117 |        117 | Tag |0f(4) 00  00  00  00 [a6]
          0 |          0 | Rdr |0c(4) 07 [f8]
        117 |        117 | Tag |0f(4) 57  5f  4f  4b [88]
          0 |          0 | Rdr |0c(4) 08 [43]
This commit is contained in:
Philippe Teuwen committed 2021-12-29 23:48:16 +01:00
1 parent e5c20fc850
commit 323f70ff7a
6 files changed
+57 -23

No files matched your search

+29 -4
View File
@@ -240,7 +240,8 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr
sprintf(line[0], "<empty trace - possible error>");
}
}
uint8_t partialbytebuff = 0;
uint8_t offset = 0;
for (int j = 0; j < data_len && j / 18 < 18; j++) {
uint8_t parityBits = parityBytes[j >> 3];
if (protocol != LEGIC
@@ -270,6 +271,18 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr
snprintf(line[j / 18] + ((j % 18) * 4), 120, "%02x! ", frame[j]);
}
} else if (((protocol == PROTO_HITAG1) || (protocol == PROTO_HITAG2) || (protocol == PROTO_HITAGS)) && (parityBytes[0] > 0)){
// handle partial bytes
uint8_t nbits = parityBytes[0];
if (j==0) {
partialbytebuff = frame[0] << nbits;
snprintf(line[0], 120, "%02x(%i) ", frame[0] >> (8 - nbits), nbits);
offset = 2;
} else {
uint8_t byte = partialbytebuff | (frame[j] >> (8 - nbits));
partialbytebuff = frame[j] << nbits;
snprintf(line[j / 18] + ((j % 18) * 4) + offset, 120, "%02x ", byte);
}
} else {
snprintf(line[j / 18] + ((j % 18) * 4), 120, "%02x ", frame[j]);
}
@@ -278,11 +291,23 @@ static uint16_t printTraceLine(uint16_t tracepos, uint16_t traceLen, uint8_t *tr
if (markCRCBytes) {
//CRC-command
if (crcStatus == 0 || crcStatus == 1) {
char *pos1 = line[(data_len - 2) / 18] + (((data_len - 2) % 18) * 4) - 1;
if (((protocol == PROTO_HITAG1) || (protocol == PROTO_HITAGS)) && (data_len > 1)) {
// notes hitag S:
// pm3 is using UID REQUEST Adv -> SOF is 111(AC) then 111111(MC)
// first tag response is AC encoded Currently, recorded trace is garbage
// for unknown reason, recorded SOF in trace is 1111 instead of 111111 (or should be even skipped)
// CRC on tag response is SOF excluded
char *pos1 = line[(data_len - 1) / 18] + (((data_len - 1) % 18) * 4) + offset - 1;
(*pos1) = '[';
char *pos2 = line[(data_len) / 18] + (((data_len) % 18) * 4) - 1;
char *pos2 = line[(data_len) / 18] + (((data_len) % 18) * 4) + offset - 2;
sprintf(pos2, "%c", ']');
} else {
if (crcStatus == 0 || crcStatus == 1) {
char *pos1 = line[(data_len - 2) / 18] + (((data_len - 2) % 18) * 4) - 1;
(*pos1) = '[';
char *pos2 = line[(data_len) / 18] + (((data_len) % 18) * 4) - 1;
sprintf(pos2, "%c", ']');
}
}
}