From 9075984c7f6cc41437ba9534f4c83810a42d8c06 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 9 Dec 2023 10:18:44 +0100 Subject: [PATCH] modified lf fdx demod, different text style and raw now shows all bytes not just crc bytes --- CHANGELOG.md | 1 + client/src/cmdlffdxb.c | 51 +++++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c660d2011..15a2f4dca 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] + - Changed `lf fdx demod` - now raw bytes shows all data (@iceman1001) - Changed `data num` - now can print reversed and inverse (@iceman1001) - Fixed `hf mf sim -ix` never returning console (@datatags) - Added standalone mode `hf_unisniff` combining 14a/14b/15 sniffing with extra flash save options (@hazardousvoltage) diff --git a/client/src/cmdlffdxb.c b/client/src/cmdlffdxb.c index e30d4f108..0c3330739 100644 --- a/client/src/cmdlffdxb.c +++ b/client/src/cmdlffdxb.c @@ -488,12 +488,13 @@ static const char *mapFDBX(uint16_t countryCode) { //see ASKDemod for what args are accepted //almost the same demod as cmddata.c/CmdFDXBdemodBI int demodFDXB(bool verbose) { - //Differential Biphase / di-phase (inverted biphase) - //get binary from ask wave + // Differential Biphase / di-phase (inverted biphase) + // get binary from ask wave if (ASKbiphaseDemod(0, 32, 1, 100, false) != PM3_SUCCESS) { PrintAndLogEx(DEBUG, "DEBUG: Error - FDX-B ASKbiphaseDemod failed"); return PM3_ESOFT; } + size_t size = g_DemodBufferLen; int preambleIndex = detectFDXB(g_DemodBuffer, &size); if (preambleIndex < 0) { @@ -513,7 +514,6 @@ int demodFDXB(bool verbose) { setDemodBuff(g_DemodBuffer, 128, preambleIndex); setClockGrid(g_DemodClock, g_DemodStartIdx + (preambleIndex * g_DemodClock)); - // remove marker bits (1's every 9th digit after preamble) (pType = 2) size = removeParity(g_DemodBuffer, 11, 9, 2, 117); if (size != 104) { @@ -521,7 +521,7 @@ int demodFDXB(bool verbose) { return PM3_ESOFT; } - //got a good demod + // got a good demod uint8_t offset; // ISO: bits 27..64 uint64_t NationalCode = ((uint64_t)(bytebits_to_byteLSBF(g_DemodBuffer + 32, 6)) << 32) | bytebits_to_byteLSBF(g_DemodBuffer, 32); @@ -559,31 +559,35 @@ int demodFDXB(bool verbose) { offset += 16; uint32_t extended = bytebits_to_byteLSBF(g_DemodBuffer + offset, 24); - uint64_t rawid = (uint64_t)(bytebits_to_byte(g_DemodBuffer, 32)) << 32 | bytebits_to_byte(g_DemodBuffer + 32, 32); - uint8_t raw[8]; - num_to_bytes(rawid, 8, raw); + uint8_t raw[13] = {0}; + for (int i = 0; i < sizeof(raw); i++) { + raw[i] = bytebits_to_byte(g_DemodBuffer + (i * 8), 8); + } - if (!verbose) { + if (verbose == false) { PROMPT_CLEARLINE; - PrintAndLogEx(SUCCESS, "Animal ID " _GREEN_("%04u-%012"PRIu64), countryCode, NationalCode); + PrintAndLogEx(SUCCESS, "Animal ID........... " _GREEN_("%04u-%012"PRIu64), countryCode, NationalCode); return PM3_SUCCESS; } - PrintAndLogEx(SUCCESS, "FDX-B / ISO 11784/5 Animal"); - PrintAndLogEx(SUCCESS, "Animal ID " _GREEN_("%03u-%012"PRIu64), countryCode, NationalCode); - PrintAndLogEx(SUCCESS, "National Code " _GREEN_("%012" PRIu64) " (0x%" PRIX64 ")", NationalCode, NationalCode); - PrintAndLogEx(SUCCESS, "Country Code " _GREEN_("%03u") " - %s", countryCode, mapFDBX(countryCode)); - PrintAndLogEx(SUCCESS, "Reserved/RFU %u (0x%04X)", reservedCode, reservedCode); - PrintAndLogEx(SUCCESS, " Animal bit set? %s", animalBit ? _YELLOW_("True") : "False"); - PrintAndLogEx(SUCCESS, " Data block? %s [value 0x%X]", dataBlockBit ? _YELLOW_("True") : "False", extended); - PrintAndLogEx(SUCCESS, " RUDI bit? %s", rudiBit ? _YELLOW_("True") " (advanced transponder)" : "False"); - PrintAndLogEx(SUCCESS, " User Info? %u %s", userInfo, userInfo == 0 ? "(RFU)" : ""); - PrintAndLogEx(SUCCESS, " Replacement No? %u %s", replacementNr, replacementNr == 0 ? "(RFU)" : ""); + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(SUCCESS, _CYAN_("FDX-B / ISO 11784/5 Animal")); + PrintAndLogEx(SUCCESS, "Animal ID......... " _GREEN_("%03u-%012"PRIu64), countryCode, NationalCode); + PrintAndLogEx(SUCCESS, "National Code..... " _GREEN_("%012" PRIu64) " ( 0x%" PRIX64 " )", NationalCode, NationalCode); + PrintAndLogEx(SUCCESS, "Country Code...... " _GREEN_("%03u") " - %s", countryCode, mapFDBX(countryCode)); + PrintAndLogEx(SUCCESS, "Reserved/RFU...... %u (0x%04X)", reservedCode, reservedCode); + PrintAndLogEx(SUCCESS, "Animal bit set?... %s", animalBit ? _YELLOW_("True") : "False"); + PrintAndLogEx(SUCCESS, "Data block?....... %s ( 0x%X )", dataBlockBit ? _YELLOW_("True") : "False", extended); + PrintAndLogEx(SUCCESS, "RUDI bit?......... %s", rudiBit ? _YELLOW_("True") " ( advanced transponder )" : "False"); + PrintAndLogEx(SUCCESS, "User Info?........ %u %s", userInfo, (userInfo == 0) ? "( RFU )" : ""); + PrintAndLogEx(SUCCESS, "Replacement No?... %u %s", replacementNr, replacementNr == 0 ? "( RFU )" : ""); + + // crc only calculated over NORMAL data (8 bytes) uint8_t c[] = {0, 0}; - compute_crc(CRC_11784, raw, sizeof(raw), &c[0], &c[1]); - PrintAndLogEx(SUCCESS, "CRC-16 0x%04X ( %s )", crc, (crc == (c[1] << 8 | c[0])) ? _GREEN_("ok") : _RED_("fail")); + compute_crc(CRC_11784, raw, 8, &c[0], &c[1]); + PrintAndLogEx(SUCCESS, "CRC-16............ 0x%04X ( %s )", crc, (crc == (c[1] << 8 | c[0])) ? _GREEN_("ok") : _RED_("fail")); // iceman: crc doesn't protect the extended data? - PrintAndLogEx(SUCCESS, "Raw " _GREEN_("%s"), sprint_hex(raw, 8)); + PrintAndLogEx(SUCCESS, "Raw............... " _GREEN_("%s"), sprint_hex(raw, sizeof(raw))); if (g_debugMode) { PrintAndLogEx(DEBUG, "Start marker %d; Size %zu", preambleIndex, size); @@ -601,12 +605,13 @@ int demodFDXB(bool verbose) { float bt_C = (bt_F - 32) / 1.8; PrintAndLogEx(NORMAL, ""); PrintAndLogEx(SUCCESS, "Bio-Thermo detected"); - PrintAndLogEx(INFO, " temperature " _GREEN_("%.1f")" F / " _GREEN_("%.1f") " C", bt_F, bt_C); + PrintAndLogEx(INFO, " temperature... " _GREEN_("%.1f")" F / " _GREEN_("%.1f") " C", bt_F, bt_C); } // set block 0 for later //g_DemodConfig = T55x7_MODULATION_DIPHASE | T55x7_BITRATE_RF_32 | 4 << T55x7_MAXBLOCK_SHIFT; + PrintAndLogEx(NORMAL, ""); return PM3_SUCCESS; }