From 4d16ee4dca2b79239b29288b0fe255f4a986658b Mon Sep 17 00:00:00 2001 From: merlokk Date: Thu, 25 Jan 2018 16:58:59 +0200 Subject: [PATCH] added parity print --- armsrc/mifaresniff.c | 2 +- client/cmdhfmf.c | 7 +++++-- client/util.c | 11 +++++++++++ client/util.h | 1 + common/parity.h | 4 ++++ 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/armsrc/mifaresniff.c b/armsrc/mifaresniff.c index 4e573be7..f20f2557 100644 --- a/armsrc/mifaresniff.c +++ b/armsrc/mifaresniff.c @@ -116,7 +116,7 @@ bool RAMFUNC MfSniffLogic(const uint8_t *data, uint16_t len, uint8_t *parity, ui sniffState = SNF_CARD_CMD; } // intentionally no break; case SNF_CARD_CMD:{ - LogTrace(data, len, 0, 0, NULL, reader); + LogTrace(data, len, 0, 0, parity, reader); timerData = GetTickCount(); break; } diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 3b533943..9ac9173c 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -18,6 +18,7 @@ #include "proxmark3.h" #include "cmdmain.h" #include "cmdhfmfhard.h" +#include "parity.h" #include "util.h" #include "util_posix.h" #include "usb_cmd.h" @@ -2485,6 +2486,7 @@ int CmdHF14AMfSniff(const char *Cmd){ uint8_t *buf = NULL; uint16_t bufsize = 0; uint8_t *bufPtr = NULL; + uint8_t parity[16]; char ctmp = param_getchar(Cmd, 0); if ( ctmp == 'h' || ctmp == 'H' ) { @@ -2595,8 +2597,9 @@ int CmdHF14AMfSniff(const char *Cmd){ if (wantDecrypt) mfTraceInit(uid, atqa, sak, wantSaveToEmlFile); } else { - PrintAndLog("%s(%d):%s", isTag ? "TAG":"RDR", num, sprint_hex(bufPtr, len)); - PrintAndLog("p:[%d %d]%s", len, parlen, sprint_hex(bufPtr + len, parlen)); + oddparitybuf(bufPtr, len, parity); + PrintAndLog("%s(%d):%s [%s] c[%s]", isTag ? "TAG":"RDR", num, sprint_hex(bufPtr, len), printBitsPar(bufPtr + len, len), printBitsPar(parity, len)); + PrintAndLog("p:%s %s", sprint_hex(bufPtr + len, parlen), sprint_hex(parity, parlen)); if (wantLogToFile) AddLogHex(logHexFileName, isTag ? "TAG: ":"RDR: ", bufPtr, len); if (wantDecrypt) diff --git a/client/util.c b/client/util.c index 7e6b4074..07a53196 100644 --- a/client/util.c +++ b/client/util.c @@ -356,6 +356,17 @@ char * printBits(size_t const size, void const * const ptr) return buf; } +char * printBitsPar(const uint8_t *b, size_t len) { + static char buf[1024] = {0}; + memset(buf, 0x00, 1024); + + for (int i = 0; i < len; i++) { + buf[i] = ((b[i / 8] << (i % 8)) & 0x80) ? '1':'0'; + } + return buf; +} + + // ------------------------------------------------------------------------- // string parameters lib // ------------------------------------------------------------------------- diff --git a/client/util.h b/client/util.h index fd7ceaff..2e64d7ca 100644 --- a/client/util.h +++ b/client/util.h @@ -54,6 +54,7 @@ extern uint64_t bytes_to_num(uint8_t* src, size_t len); extern void num_to_bytebits(uint64_t n, size_t len, uint8_t *dest); extern void num_to_bytebitsLSBF(uint64_t n, size_t len, uint8_t *dest); extern char *printBits(size_t const size, void const * const ptr); +extern char * printBitsPar(const uint8_t *b, size_t len); extern uint32_t SwapBits(uint32_t value, int nrbits); extern uint8_t *SwapEndian64(const uint8_t *src, const size_t len, const uint8_t blockSize); extern void SwapEndian64ex(const uint8_t *src, const size_t len, const uint8_t blockSize, uint8_t *dest); diff --git a/common/parity.h b/common/parity.h index 615fdeee..7a257697 100644 --- a/common/parity.h +++ b/common/parity.h @@ -21,6 +21,10 @@ static inline bool oddparity8(const uint8_t x) { return OddByteParity[x]; } +static inline void oddparitybuf(const uint8_t *x, size_t len, uint8_t *parity) { + for (int i = 0; i < len; i++) + parity[i / 8] ^= oddparity8(*x >> ((i % 8) * 8) & 0xff) << (i % 8); +} static inline bool evenparity8(const uint8_t x) { return !OddByteParity[x];