mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-03-18 03:00:58 +08:00
binarraytohex: handle Manchester wrong bit markers
This commit is contained in:
parent
da5ad8438c
commit
f1a0e57f65
4 changed files with 46 additions and 22 deletions
|
@ -417,18 +417,17 @@ int CmdPrintDemodBuff(const char *Cmd) {
|
|||
return 0;
|
||||
}
|
||||
length = (length > (DemodBufferLen - offset)) ? DemodBufferLen - offset : length;
|
||||
int numBits = (length) & 0x00FFC; //make sure we don't exceed our string
|
||||
|
||||
if (hexMode) {
|
||||
char *buf = (char *)(DemodBuffer + offset);
|
||||
numBits = (numBits > sizeof(hex)) ? sizeof(hex) : numBits;
|
||||
numBits = binarraytohex(hex, buf, numBits);
|
||||
int numBits = binarraytohex(hex, sizeof(hex), buf, length);
|
||||
if (numBits == 0) {
|
||||
return 0;
|
||||
}
|
||||
PrintAndLogEx(NORMAL, "DemodBuffer: %i bits consumed", numBits);
|
||||
PrintAndLogEx(NORMAL, "DemodBuffer: %s", hex);
|
||||
} else {
|
||||
PrintAndLogEx(NORMAL, "DemodBuffer:\n%s", sprint_bin_break(DemodBuffer + offset, numBits, 16));
|
||||
PrintAndLogEx(NORMAL, "DemodBuffer:\n%s", sprint_bin_break(DemodBuffer + offset, length, 16));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -252,6 +252,9 @@ char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t brea
|
|||
// loop through the out_index to make sure we don't go too far
|
||||
for (out_index = 0; out_index < rowlen; out_index++) {
|
||||
// set character
|
||||
if (data[in_index] == 7) // Manchester wrong bit marker
|
||||
sprintf(tmp++, ".");
|
||||
else
|
||||
sprintf(tmp++, "%u", data[in_index]);
|
||||
// check if a line break is needed and we have room to print it in our array
|
||||
if ((breaks > 0) && !((in_index + 1) % breaks) && (out_index + 1 != rowlen)) {
|
||||
|
@ -683,24 +686,45 @@ int hextobinstring(char *target, char *source) {
|
|||
return length;
|
||||
}
|
||||
|
||||
// convert binary array of 0x00/0x01 values to hex (safe to do in place as target will always be shorter than source)
|
||||
// convert binary array of 0x00/0x01 values to hex
|
||||
// return number of bits converted
|
||||
int binarraytohex(char *target, char *source, int length) {
|
||||
unsigned char i, x;
|
||||
int j = length;
|
||||
|
||||
if (j % 4)
|
||||
return 0;
|
||||
|
||||
while (j) {
|
||||
for (i = x = 0 ; i < 4 ; ++i)
|
||||
x += (source[i] << (3 - i));
|
||||
sprintf(target, "%X", x);
|
||||
++target;
|
||||
source += 4;
|
||||
j -= 4;
|
||||
int binarraytohex(char *target, const size_t targetlen, char *source, size_t srclen) {
|
||||
uint8_t i = 0, x = 0;
|
||||
uint32_t t = 0; // written target chars
|
||||
uint32_t r = 0; // consumed bits
|
||||
uint8_t w = 0; // wrong bits separator printed
|
||||
for (size_t s = 0 ; s < srclen; s++) {
|
||||
if ((source[s]==0) || (source[s]==1)) {
|
||||
w = 0;
|
||||
x += (source[s] << (3 - i));
|
||||
i++;
|
||||
if (i == 4) {
|
||||
if (t >= targetlen - 2) return r;
|
||||
sprintf(target + t, "%X", x);
|
||||
t++;
|
||||
r+=4;
|
||||
x = 0;
|
||||
i = 0;
|
||||
}
|
||||
return length;
|
||||
} else {
|
||||
if (i > 0) {
|
||||
if (t >= targetlen - 5) return r;
|
||||
w = 0;
|
||||
sprintf(target + t, "%X[%i]", x, i);
|
||||
t+=4;
|
||||
r+=i;
|
||||
x = 0;
|
||||
i = 0;
|
||||
}
|
||||
if (w == 0) {
|
||||
if (t >= targetlen - 2) return r;
|
||||
sprintf(target + t, " ");
|
||||
t++;
|
||||
}
|
||||
r++;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
// convert binary array to human readable binary
|
||||
|
|
|
@ -241,7 +241,7 @@ extern int param_getstr(const char *line, int paramnum, char *str, size_t buffer
|
|||
|
||||
extern int hextobinarray(char *target, char *source);
|
||||
extern int hextobinstring(char *target, char *source);
|
||||
extern int binarraytohex(char *target, char *source, int length);
|
||||
extern int binarraytohex(char *target, const size_t targetlen, char *source, size_t srclen);
|
||||
extern void binarraytobinstring(char *target, char *source, int length);
|
||||
extern uint8_t GetParity(uint8_t *string, uint8_t type, int length);
|
||||
extern void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length);
|
||||
|
|
|
@ -1357,6 +1357,7 @@ int BiphaseRawDecode(uint8_t *bits, size_t *size, int *offset, int invert) {
|
|||
//by marshmellow
|
||||
//take 10 and 01 and manchester decode
|
||||
//run through 2 times and take least errCnt
|
||||
// "7" indicates 00 or 11 wrong bit
|
||||
int manrawdecode(uint8_t *bits, size_t *size, uint8_t invert, uint8_t *alignPos) {
|
||||
|
||||
// sanity check
|
||||
|
|
Loading…
Reference in a new issue