added parity print

This commit is contained in:
merlokk 2018-01-25 16:58:59 +02:00
commit 4d16ee4dca
5 changed files with 22 additions and 3 deletions

View file

@ -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;
}

View file

@ -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)

View file

@ -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
// -------------------------------------------------------------------------

View file

@ -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);

View file

@ -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];