mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-03-20 03:48:33 +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;
|
return 0;
|
||||||
}
|
}
|
||||||
length = (length > (DemodBufferLen - offset)) ? DemodBufferLen - offset : length;
|
length = (length > (DemodBufferLen - offset)) ? DemodBufferLen - offset : length;
|
||||||
int numBits = (length) & 0x00FFC; //make sure we don't exceed our string
|
|
||||||
|
|
||||||
if (hexMode) {
|
if (hexMode) {
|
||||||
char *buf = (char *)(DemodBuffer + offset);
|
char *buf = (char *)(DemodBuffer + offset);
|
||||||
numBits = (numBits > sizeof(hex)) ? sizeof(hex) : numBits;
|
int numBits = binarraytohex(hex, sizeof(hex), buf, length);
|
||||||
numBits = binarraytohex(hex, buf, numBits);
|
|
||||||
if (numBits == 0) {
|
if (numBits == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
PrintAndLogEx(NORMAL, "DemodBuffer: %i bits consumed", numBits);
|
||||||
PrintAndLogEx(NORMAL, "DemodBuffer: %s", hex);
|
PrintAndLogEx(NORMAL, "DemodBuffer: %s", hex);
|
||||||
} else {
|
} 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;
|
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
|
// loop through the out_index to make sure we don't go too far
|
||||||
for (out_index = 0; out_index < rowlen; out_index++) {
|
for (out_index = 0; out_index < rowlen; out_index++) {
|
||||||
// set character
|
// set character
|
||||||
|
if (data[in_index] == 7) // Manchester wrong bit marker
|
||||||
|
sprintf(tmp++, ".");
|
||||||
|
else
|
||||||
sprintf(tmp++, "%u", data[in_index]);
|
sprintf(tmp++, "%u", data[in_index]);
|
||||||
// check if a line break is needed and we have room to print it in our array
|
// 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)) {
|
if ((breaks > 0) && !((in_index + 1) % breaks) && (out_index + 1 != rowlen)) {
|
||||||
|
@ -683,24 +686,45 @@ int hextobinstring(char *target, char *source) {
|
||||||
return length;
|
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
|
// return number of bits converted
|
||||||
int binarraytohex(char *target, char *source, int length) {
|
int binarraytohex(char *target, const size_t targetlen, char *source, size_t srclen) {
|
||||||
unsigned char i, x;
|
uint8_t i = 0, x = 0;
|
||||||
int j = length;
|
uint32_t t = 0; // written target chars
|
||||||
|
uint32_t r = 0; // consumed bits
|
||||||
if (j % 4)
|
uint8_t w = 0; // wrong bits separator printed
|
||||||
return 0;
|
for (size_t s = 0 ; s < srclen; s++) {
|
||||||
|
if ((source[s]==0) || (source[s]==1)) {
|
||||||
while (j) {
|
w = 0;
|
||||||
for (i = x = 0 ; i < 4 ; ++i)
|
x += (source[s] << (3 - i));
|
||||||
x += (source[i] << (3 - i));
|
i++;
|
||||||
sprintf(target, "%X", x);
|
if (i == 4) {
|
||||||
++target;
|
if (t >= targetlen - 2) return r;
|
||||||
source += 4;
|
sprintf(target + t, "%X", x);
|
||||||
j -= 4;
|
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
|
// 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 hextobinarray(char *target, char *source);
|
||||||
extern int hextobinstring(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 void binarraytobinstring(char *target, char *source, int length);
|
||||||
extern uint8_t GetParity(uint8_t *string, uint8_t type, 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);
|
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
|
//by marshmellow
|
||||||
//take 10 and 01 and manchester decode
|
//take 10 and 01 and manchester decode
|
||||||
//run through 2 times and take least errCnt
|
//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) {
|
int manrawdecode(uint8_t *bits, size_t *size, uint8_t invert, uint8_t *alignPos) {
|
||||||
|
|
||||||
// sanity check
|
// sanity check
|
||||||
|
|
Loading…
Add table
Reference in a new issue