From 4c1327a90e82420ef10284fc8f48d6c7f0589210 Mon Sep 17 00:00:00 2001 From: merlokk Date: Mon, 29 Jan 2018 19:39:28 +0200 Subject: [PATCH] fixed parity calc and add parity print. works. --- client/cmdhfmf.c | 1 - client/mifarehost.c | 5 ++++- common/parity.h | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 8435c2c3..0a6e7ca0 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -2599,7 +2599,6 @@ int CmdHF14AMfSniff(const char *Cmd){ } else { 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_inrow(parity, parlen)); if (wantLogToFile) AddLogHex(logHexFileName, isTag ? "TAG: ":"RDR: ", bufPtr, len); if (wantDecrypt) diff --git a/client/mifarehost.c b/client/mifarehost.c index 02afe75e..55dac115 100644 --- a/client/mifarehost.c +++ b/client/mifarehost.c @@ -20,6 +20,7 @@ #include "usb_cmd.h" #include "cmdmain.h" #include "ui.h" +#include "parity.h" #include "util.h" #include "iso14443crc.h" @@ -714,7 +715,9 @@ int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) { memcpy(data, data_src, len); if ((traceCrypto1) && ((traceState == TRACE_IDLE) || (traceState > TRACE_AUTH_OK))) { mf_crypto1_decrypt(traceCrypto1, data, len, 0); - PrintAndLog("dec> %s", sprint_hex(data, len)); + uint8_t parity[16]; + oddparitybuf(data, len, parity); + PrintAndLog("dec> %s [%s]", sprint_hex(data, len), printBitsPar(parity, len)); AddLogHex(logHexFileName, "dec> ", data, len); } diff --git a/common/parity.h b/common/parity.h index 7a257697..90009080 100644 --- a/common/parity.h +++ b/common/parity.h @@ -13,6 +13,7 @@ #include #include +#include extern const uint8_t OddByteParity[256]; @@ -22,8 +23,9 @@ static inline bool oddparity8(const uint8_t x) { } static inline void oddparitybuf(const uint8_t *x, size_t len, uint8_t *parity) { + memset(parity, 0x00, len / 8 + 1); for (int i = 0; i < len; i++) - parity[i / 8] ^= oddparity8(*x >> ((i % 8) * 8) & 0xff) << (i % 8); + parity[i / 8] |= oddparity8(x[i]) << (7 - (i % 8)); } static inline bool evenparity8(const uint8_t x) {