Fix sprint_bin usages in hf mfu and felica

This commit is contained in:
Philippe Teuwen 2021-08-22 16:53:15 +02:00
commit 0d7f93a8e7
9 changed files with 34 additions and 25 deletions

View file

@ -274,7 +274,7 @@ int printDemodBuff(uint8_t offset, bool strip_leading, bool invert, bool print_h
}
PrintAndLogEx(SUCCESS, "DemodBuffer:\n%s", hex);
} else {
PrintAndLogEx(SUCCESS, "DemodBuffer:\n%s", sprint_bin_break(buf + offset, len, 32));
PrintAndLogEx(SUCCESS, "DemodBuffer:\n%s", sprint_bytebits_bin_break(buf + offset, len, 32));
}
p = NULL;
@ -585,7 +585,7 @@ static int Cmdmandecoderaw(const char *Cmd) {
}
PrintAndLogEx(INFO, "Manchester decoded %s", (invert) ? "( inverted )" : "");
PrintAndLogEx(INFO, "%s", sprint_bin_break(bits, size, 32));
PrintAndLogEx(INFO, "%s", sprint_bytebits_bin_break(bits, size, 32));
// try decode EM410x
if (err_cnt == 0) {
@ -660,7 +660,7 @@ static int CmdBiphaseDecodeRaw(const char *Cmd) {
}
PrintAndLogEx(INFO, "Biphase decoded using offset %d%s", offset, (invert) ? "( inverted )" : "");
PrintAndLogEx(INFO, "%s", sprint_bin_break(bits, size, 32));
PrintAndLogEx(INFO, "%s", sprint_bytebits_bin_break(bits, size, 32));
setDemodBuff(bits, size, 0);
setClockGrid(g_DemodClock * 2, g_DemodStartIdx + g_DemodClock * offset);

View file

@ -620,7 +620,7 @@ int getAWIDBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *bits) {
if (bitLen != 88)
return PM3_ESOFT;
PrintAndLogEx(DEBUG, "awid raw bits:\n %s \n", sprint_bin(bits, bitLen));
PrintAndLogEx(DEBUG, "awid raw bits:\n %s \n", sprint_bytebits_bin(bits, bitLen));
return PM3_SUCCESS;
}

View file

@ -69,7 +69,7 @@ static void em410x_construct_emul_graph(uint8_t *uid, uint8_t clock, uint8_t gap
for (uint8_t j = 0; j < 8; j++) {
bs[j] = (uid[i] >> (7 - j) & 1);
}
PrintAndLogEx(DEBUG, "EM ID[%d] 0x%02x (%s)", i, uid[i], sprint_bin(bs, 4));
PrintAndLogEx(DEBUG, "EM ID[%d] 0x%02x (%s)", i, uid[i], sprint_bytebits_bin(bs, 4));
for (uint8_t j = 0; j < 2; j++) {
// append each bit

View file

@ -203,7 +203,7 @@ static int CmdFDXBdemodBI(const char *Cmd) {
if (g_debugMode) {
PrintAndLogEx(DEBUG, "Start marker %d; Size %d", preambleIndex, size);
char *bin = sprint_bin_break(bs, size, 16);
char *bin = sprint_bytebits_bin_break(bs, size, 16);
PrintAndLogEx(DEBUG, "DEBUG BinStream:\n%s", bin);
}
return PM3_SUCCESS;
@ -578,7 +578,7 @@ int demodFDXB(bool verbose) {
if (g_debugMode) {
PrintAndLogEx(DEBUG, "Start marker %d; Size %zu", preambleIndex, size);
char *bin = sprint_bin_break(g_DemodBuffer, size, 16);
char *bin = sprint_bytebits_bin_break(g_DemodBuffer, size, 16);
PrintAndLogEx(DEBUG, "DEBUG bin stream:\n%s", bin);
}

View file

@ -427,7 +427,7 @@ int getGuardBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *guardBits) {
num_to_bytebitsLSBF(rawbytes[i], 8, pre + (i * 8));
PrintAndLogEx(DEBUG, " Raw | %s", sprint_hex(rawbytes, sizeof(rawbytes)));
PrintAndLogEx(DEBUG, " Raw | %s", sprint_bin(pre, 96));
PrintAndLogEx(DEBUG, " Raw | %s", sprint_bytebits_bin(pre, 96));
// add spacer bit 0 every 4 bits, starting with index 0,
// 12 bytes, 24 nibbles. 24+1 extra bites. 3bytes. ie 9bytes | 1byte xorkey, 8bytes rawdata (72bits, should be enough for a 40bit wiegand)
@ -441,7 +441,7 @@ int getGuardBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *guardBits) {
guardBits[4] = 1;
guardBits[5] = 0;
PrintAndLogEx(DEBUG, " FIN | %s\n", sprint_bin(guardBits, 96));
PrintAndLogEx(DEBUG, " FIN | %s\n", sprint_bytebits_bin(guardBits, 96));
return PM3_SUCCESS;
}

View file

@ -93,7 +93,7 @@ int demodIOProx(bool verbose) {
if (idx == 0) {
if (g_debugMode) {
PrintAndLogEx(DEBUG, "DEBUG: Error - IO prox data not found - FSK Bits: %zu", size);
if (size > 92) PrintAndLogEx(DEBUG, "%s", sprint_bin_break(bits, 92, 16));
if (size > 92) PrintAndLogEx(DEBUG, "%s", sprint_bytebits_bin_break(bits, 92, 16));
}
return PM3_ESOFT;
}
@ -419,7 +419,7 @@ int getIOProxBits(uint8_t version, uint8_t fc, uint16_t cn, uint8_t *bits) {
memcpy(bits, pre, sizeof(pre));
PrintAndLogEx(SUCCESS, "IO raw bits:\n %s \n", sprint_bin(bits, 64));
PrintAndLogEx(SUCCESS, "IO raw bits:\n %s \n", sprint_bytebits_bin(bits, 64));
return PM3_SUCCESS;
}

View file

@ -1303,7 +1303,7 @@ void printT55xxBlock(uint8_t blockNum, bool page1) {
T55x7_SaveBlockData((page1) ? blockNum + 8 : blockNum, val);
PrintAndLogEx(SUCCESS, " %02d | %08X | %s | %s", blockNum, val, sprint_bin(g_DemodBuffer + config.offset, 32), sprint_ascii(bytes, 4));
PrintAndLogEx(SUCCESS, " %02d | %08X | %s | %s", blockNum, val, sprint_bytebits_bin(g_DemodBuffer + config.offset, 32), sprint_ascii(bytes, 4));
}
static bool testModulation(uint8_t mode, uint8_t modread) {
@ -1508,7 +1508,7 @@ int CmdT55xxSpecial(const char *Cmd) {
uint32_t blockData = PackBits(0, 32, bits);
PrintAndLogEx(NORMAL, "%02d | 0x%08X | %s", j, blockData, sprint_bin(bits, 32));
PrintAndLogEx(NORMAL, "%02d | 0x%08X | %s", j, blockData, sprint_bytebits_bin(bits, 32));
}
return PM3_SUCCESS;
}
@ -1861,8 +1861,8 @@ void printT55x7Trace(t55x7_tracedata_t data, uint8_t repeat) {
PrintAndLogEx(INFO, " Die Number..... %d", data.dw);
PrintAndLogEx(INFO, "-------------------------------------------------------------");
PrintAndLogEx(INFO, " Raw Data - Page 1");
PrintAndLogEx(INFO, " Block 1... %08X - %s", data.bl1, sprint_bin(g_DemodBuffer + config.offset + repeat, 32));
PrintAndLogEx(INFO, " Block 2... %08X - %s", data.bl2, sprint_bin(g_DemodBuffer + config.offset + repeat + 32, 32));
PrintAndLogEx(INFO, " Block 1... %08X - %s", data.bl1, sprint_bytebits_bin(g_DemodBuffer + config.offset + repeat, 32));
PrintAndLogEx(INFO, " Block 2... %08X - %s", data.bl2, sprint_bytebits_bin(g_DemodBuffer + config.offset + repeat + 32, 32));
PrintAndLogEx(NORMAL, "");
/*
@ -1902,8 +1902,8 @@ void printT5555Trace(t5555_tracedata_t data, uint8_t repeat) {
PrintAndLogEx(INFO, " Die Number..... %d", data.dw);
PrintAndLogEx(INFO, "-------------------------------------------------------------");
PrintAndLogEx(INFO, " Raw Data - Page 1");
PrintAndLogEx(INFO, " Block 1... %08X - %s", data.bl1, sprint_bin(g_DemodBuffer + config.offset + repeat, 32));
PrintAndLogEx(INFO, " Block 2... %08X - %s", data.bl2, sprint_bin(g_DemodBuffer + config.offset + repeat + 32, 32));
PrintAndLogEx(INFO, " Block 1... %08X - %s", data.bl1, sprint_bytebits_bin(g_DemodBuffer + config.offset + repeat, 32));
PrintAndLogEx(INFO, " Block 2... %08X - %s", data.bl2, sprint_bytebits_bin(g_DemodBuffer + config.offset + repeat + 32, 32));
/*
** Q5 **
@ -2185,7 +2185,7 @@ static int CmdT55xxInfo(const char *Cmd) {
if (gotdata)
PrintAndLogEx(INFO, " " _GREEN_("%08X"), block0);
else
PrintAndLogEx(INFO, " " _GREEN_("%08X") " - %s", block0, sprint_bin(g_DemodBuffer + config.offset, 32));
PrintAndLogEx(INFO, " " _GREEN_("%08X") " - %s", block0, sprint_bytebits_bin(g_DemodBuffer + config.offset, 32));
if (((!gotdata) && (!config.Q5)) || (gotdata && (!dataasq5))) {
PrintAndLogEx(INFO, "--- " _CYAN_("Fingerprint") " ------------");

View file

@ -298,7 +298,7 @@ char *sprint_hex_inrow_spaces(const uint8_t *data, const size_t len, size_t spac
return buf;
}
char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t breaks) {
char *sprint_bytebits_bin_break(const uint8_t *data, const size_t len, const uint8_t breaks) {
// make sure we don't go beyond our char array memory
size_t rowlen = (len > MAX_BIN_BREAK_LENGTH) ? MAX_BIN_BREAK_LENGTH : len;
@ -369,8 +369,15 @@ void sprint_bin_break_ex(uint8_t *src, size_t srclen, char *dest , uint8_t break
}
*/
char *sprint_bytebits_bin(const uint8_t *data, const size_t len) {
return sprint_bytebits_bin_break(data, len, 0);
}
char *sprint_bin(const uint8_t *data, const size_t len) {
return sprint_bin_break(data, len, 0);
size_t binlen = (len*8 > MAX_BIN_BREAK_LENGTH) ? MAX_BIN_BREAK_LENGTH : len*8;
static uint8_t buf[MAX_BIN_BREAK_LENGTH];
bytes_to_bytebits(data, binlen/8, buf);
return sprint_bytebits_bin_break(buf, binlen, 0);
}
char *sprint_hex_ascii(const uint8_t *data, const size_t len) {
@ -474,14 +481,15 @@ void num_to_bytebitsLSBF(uint64_t n, size_t len, uint8_t *dest) {
}
}
void bytes_to_bytebits(void *src, size_t srclen, void *dest) {
void bytes_to_bytebits(const void *src, const size_t srclen, void *dest) {
uint8_t *s = (uint8_t *)src;
uint8_t *d = (uint8_t *)dest;
uint32_t i = srclen * 8;
while (srclen--) {
uint8_t b = s[srclen];
size_t j = srclen;
while (j--) {
uint8_t b = s[j];
d[--i] = (b >> 0) & 1;
d[--i] = (b >> 1) & 1;
d[--i] = (b >> 2) & 1;

View file

@ -47,7 +47,8 @@ char *sprint_hex_inrow(const uint8_t *data, const size_t len);
char *sprint_hex_inrow_ex(const uint8_t *data, const size_t len, const size_t min_str_len);
char *sprint_hex_inrow_spaces(const uint8_t *data, const size_t len, size_t spaces_between);
char *sprint_bin(const uint8_t *data, const size_t len);
char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t breaks);
char *sprint_bytebits_bin(const uint8_t *data, const size_t len);
char *sprint_bytebits_bin_break(const uint8_t *data, const size_t len, const uint8_t breaks);
char *sprint_hex_ascii(const uint8_t *data, const size_t len);
char *sprint_ascii(const uint8_t *data, const size_t len);
char *sprint_ascii_ex(const uint8_t *data, const size_t len, const size_t min_str_len);
@ -59,7 +60,7 @@ void print_blocks(uint32_t *data, size_t len);
int hex_to_bytes(const char *hexValue, uint8_t *bytesValue, size_t maxBytesValueLen);
void num_to_bytebits(uint64_t n, size_t len, uint8_t *dest);
void num_to_bytebitsLSBF(uint64_t n, size_t len, uint8_t *dest);
void bytes_to_bytebits(void *src, size_t srclen, void *dest);
void bytes_to_bytebits(const void *src, const size_t srclen, void *dest);
// Swap endian on arrays up to 64bytes.
uint8_t *SwapEndian64(const uint8_t *src, const size_t len, const uint8_t blockSize);