This commit is contained in:
iceman1001 2019-03-15 00:22:15 +01:00
commit 8f78c9d45e
5 changed files with 68 additions and 45 deletions

View file

@ -417,18 +417,16 @@ 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: %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;
}

View file

@ -348,17 +348,17 @@ static void printHitagConfiguration(uint8_t config) {
memset(msg, 0, sizeof(msg));
// encoding
if (config & 0x1) {
strcat(msg, "Biphase encoding");
strcat(msg, "Biphase encoding");
} else {
strcat(msg, "Manchester encoding");
}
PrintAndLogEx(SUCCESS, "%s", msg);
memset(msg, 0, sizeof(msg));
// version
strcat(msg, "Coding in HITAG 2 operation: %s");
uint8_t foo = (config & 0x6) >> 1;
switch ( foo ) {
switch (foo) {
case 0:
PrintAndLogEx(SUCCESS, "Version: public mode B, Coding: biphase");
PrintAndLogEx(SUCCESS, msg, (config & 0x1) ? "biphase" : "manchester");
@ -366,60 +366,60 @@ static void printHitagConfiguration(uint8_t config) {
case 1:
PrintAndLogEx(SUCCESS, "Version: public mode A, Coding: manchester");
PrintAndLogEx(SUCCESS, msg, (config & 0x1) ? "biphase" : "manchester");
break;
break;
case 2:
PrintAndLogEx(SUCCESS, "Version: public mode C, Coding: biphase");
PrintAndLogEx(SUCCESS, msg, (config & 0x1) ? "biphase" : "manchester");
break;
break;
case 3:
PrintAndLogEx(SUCCESS, "Version: Hitag2");
PrintAndLogEx(SUCCESS, msg, (config & 0x1) ? "biphase" : "manchester");
break;
}
memset(msg, 0, sizeof(msg));
// mode
if (config & 0x8) {
strcat(msg, "Tag is in : " _YELLOW_("Crypto mode") );
strcat(msg, "Tag is in : " _YELLOW_("Crypto mode"));
} else {
strcat(msg, "Tag is in : " _YELLOW_("Password mode") );
strcat(msg, "Tag is in : " _YELLOW_("Password mode"));
}
PrintAndLogEx(SUCCESS, "%s", msg);
PrintAndLogEx(SUCCESS, "%s", msg);
memset(msg, 0, sizeof(msg));
// page access
if (config & 0x10) {
strcat(msg, "Page 6,7 : read only");
} else {
strcat(msg, "Page 6,7 : " _GREEN_("read write"));
}
PrintAndLogEx(SUCCESS, "%s", msg);
PrintAndLogEx(SUCCESS, "%s", msg);
memset(msg, 0, sizeof(msg));
// page access
if (config & 0x20) {
strcat(msg, "Page 4,5 : read only");
} else {
strcat(msg, "Page 4,5 : " _GREEN_("read write"));
}
PrintAndLogEx(SUCCESS, "%s", msg);
PrintAndLogEx(SUCCESS, "%s", msg);
memset(msg, 0, sizeof(msg));
// OTP
if (config & 0x40) {
strcat(msg, "Page 3 : read only. Configuration byte and password tag " _RED_("FIXED / IRREVERSIBLE") );
strcat(msg, "Page 3 : read only. Configuration byte and password tag " _RED_("FIXED / IRREVERSIBLE"));
} else {
strcat(msg, "Page 3 : " _GREEN_("read write"));
}
PrintAndLogEx(SUCCESS, "%s", msg);
}
PrintAndLogEx(SUCCESS, "%s", msg);
memset(msg, 0, sizeof(msg));
// OTP
if (config & 0x80) {
strcat(msg, "Page 1 " _RED_("locked") "\n");
if (config & 0x8) {
strcat(msg + strlen(msg), "Page 2 : " _RED_("locked") );
strcat(msg + strlen(msg), "Page 2 : " _RED_("locked"));
} else {
strcat(msg + strlen(msg), "Page 2 : read only");
}
@ -434,14 +434,14 @@ int CmdLFHitagInfo(const char *Cmd) {
PrintAndLogEx(INFO, "Hitag2 tag information ");
PrintAndLogEx(INFO, "To be done!");
PrintAndLogEx(INFO, "------------------------------------");
char ctmp = tolower(param_getchar(Cmd, 0));
if (ctmp == 'h') return usage_hitag_info();
// read block3, get configuration byte.
// common configurations.
printHitagConfiguration( 0x06 );
printHitagConfiguration(0x06);
//printHitagConfiguration( 0x0E );
//printHitagConfiguration( 0x02 );
//printHitagConfiguration( 0x00 );

View file

@ -252,7 +252,10 @@ 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
sprintf(tmp++, "%u", data[in_index]);
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)) {
// increment and print line break
@ -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;
}
} 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 length;
return r;
}
// convert binary array to human readable binary

View file

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

View file

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