CHG: "hf legic decode" now prints nicely. Still a strange bug for first row..

This commit is contained in:
iceman1001 2016-02-15 19:56:08 +01:00
parent d7fd908447
commit 9827020ac5
3 changed files with 36 additions and 24 deletions

View file

@ -92,7 +92,7 @@ int CmdLegicDecode(const char *Cmd) {
stamp_len = 0xfc - data_buf[6];
PrintAndLog("DCF: %02x %02x, Token_Type=%s (OLE=%01u), Stamp_len=%02u",
PrintAndLog("DCF: %02x %02x, Token Type=%s (OLE=%01u), Stamp len=%02u",
data_buf[5],
data_buf[6],
token_type,
@ -116,6 +116,7 @@ int CmdLegicDecode(const char *Cmd) {
uint32_t segCRC = 0;
PrintAndLog("\nADF: User Area");
printf("-------------------------------------\n");
i = 22;
// 64 potential segements
for ( segmentNum=0; segmentNum<64; segmentNum++ ) {
@ -143,16 +144,16 @@ int CmdLegicDecode(const char *Cmd) {
segCalcCRC = CRC8Legic(segCrcBytes, 8);
segCRC = data_buf[i+4]^crc;
PrintAndLog("Segment %02u: raw header=%02x %02x %02x %02x, flag=%01x (valid=%01u, last=%01u), len=%04u, WRP=%02u, WRC=%02u, RD=%01u, CRC=%02x (%s)",
PrintAndLog("Segment %02u \nraw header=0x%02X 0x%02X 0x%02X 0x%02X \nSegment len: %u, Flag: 0x%X (valid:%01u, last:%01u), WRP: %02u, WRC: %02u, RD: %01u, CRC: 0x%02X (%s)",
segmentNum,
data_buf[i]^crc,
data_buf[i+1]^crc,
data_buf[i+2]^crc,
data_buf[i+3]^crc,
segment_len,
segment_flag,
(segment_flag & 0x4) >> 2,
(segment_flag & 0x8) >> 3,
segment_len,
wrp,
wrc,
((data_buf[i+3]^crc) & 0x80) >> 7,
@ -171,7 +172,7 @@ int CmdLegicDecode(const char *Cmd) {
//is WRC / 8?
// for ( k=i; k < wrc; k += 8)
PrintAndLog("%s", sprint_hex( data_buf+i, wrc ) );
print_hex_break( data_buf+i, wrc, 16);
i += wrc;
}
@ -179,35 +180,36 @@ int CmdLegicDecode(const char *Cmd) {
if ( hasWRP ) {
PrintAndLog("Remaining write protected area: (I %d | K %d | WRC %d | WRP %d WRP_LEN %d)",i, k, wrc, wrp, wrp_len);
// // de-xor?
// if ( data_buf[k] > 0) {
// for (k=i; k < wrp_len; k++)
// data_buf[k] ^= crc;
// }
// de-xor? if not zero, assume it needs xoring.
if ( data_buf[i] > 0) {
for (k=i; k < wrp_len; k++)
data_buf[k] ^= crc;
}
// for (k=i; k < wrp_len; k += 16) {
PrintAndLog("%s", sprint_hex( data_buf+i, wrp_len));
print_hex_break( data_buf+i, wrp_len, 16);
// }
i += wrp_len;
// if( wrp_len == 8 )
// PrintAndLog("Card ID: %2X%02X%02X", data_buf[i-4]^crc, data_buf[i-3]^crc, data_buf[i-2]^crc);
if( wrp_len == 8 )
PrintAndLog("Card ID: %2X%02X%02X", data_buf[i-4]^crc, data_buf[i-3]^crc, data_buf[i-2]^crc);
}
PrintAndLog("Remaining segment payload:");
// if ( data_buf[k] > 0 ) {
// for ( k=i; k < remain_seg_payload_len; k++)
// data_buf[k] ^= crc;
// }
if ( data_buf[i] > 0 ) {
for ( k=i; k < remain_seg_payload_len; k++)
data_buf[k] ^= crc;
}
// for ( k=i; k < remain_seg_payload_len; k++)
PrintAndLog("%s", sprint_hex( data_buf+i, remain_seg_payload_len ) );
print_hex_break( data_buf+i, remain_seg_payload_len, 16);
i += remain_seg_payload_len;
printf("\n-------------------------------------\n");
// end with last segment
if (segment_flag & 0x8) return 0;

View file

@ -97,14 +97,22 @@ void FillFileNameByUID(char *fileName, uint8_t * uid, char *ext, int byteCount)
}
// printing and converting functions
void print_hex(const uint8_t * data, const size_t len)
{
void print_hex(const uint8_t * data, const size_t len) {
size_t i;
for (i=0; i < len; i++)
for (i=0; i < len; ++i)
printf("%02x ", data[i]);
printf("\n");
}
void print_hex_break(const uint8_t *data, const size_t len, uint8_t breaks) {
size_t i;
for ( i = 0; i < len; ++i) {
printf("%02X ", data[i]);
// check if a line break is needed
if ( (breaks > 0) && (i > 0) && !(i % breaks) )
printf("\n");
}
printf("\n");
}
@ -158,9 +166,10 @@ char *sprint_bin(const uint8_t *data, const size_t len) {
char *sprint_hex_ascii(const uint8_t *data, const size_t len) {
static char buf[1024];
memset(buf, 0x00, 1024);
char *tmp = buf;
sprintf(tmp, "%s| %s", sprint_hex(data, len) , data);
memset(buf, 0x00, 1024);
size_t max_len = (len > 1010) ? 1010 : len;
sprintf(tmp, "%s| %s", sprint_hex(data, max_len) , data);
return buf;
}
void num_to_bytes(uint64_t n, size_t len, uint8_t* dest)

View file

@ -45,6 +45,7 @@ void AddLogCurrentDT(char *fileName);
void FillFileNameByUID(char *fileName, uint8_t * uid, char *ext, int byteCount);
void print_hex(const uint8_t * data, const size_t len);
void print_hex_break(const uint8_t *data, const size_t len, const uint8_t breaks);
char *sprint_hex(const uint8_t * data, const size_t len);
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);