mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
fix: 'hf legic info' - unsegmented card now uses card size to calc remaining length. Also made the output at bit more clear and colorful
This commit is contained in:
parent
8aa5b42cdf
commit
d8ab476022
1 changed files with 67 additions and 51 deletions
|
@ -180,7 +180,7 @@ int CmdLegicInfo(const char *Cmd) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLogEx(SUCCESS, "Reading tag memory %d b...", card.cardsize);
|
PrintAndLogEx(SUCCESS, "Reading full tag memory of %d bytes...", card.cardsize);
|
||||||
|
|
||||||
// allocate receiver buffer
|
// allocate receiver buffer
|
||||||
uint8_t *data = calloc(card.cardsize, sizeof(uint8_t));
|
uint8_t *data = calloc(card.cardsize, sizeof(uint8_t));
|
||||||
|
@ -200,7 +200,7 @@ int CmdLegicInfo(const char *Cmd) {
|
||||||
crc = data[4];
|
crc = data[4];
|
||||||
uint32_t calc_crc = CRC8Legic(data, 4);
|
uint32_t calc_crc = CRC8Legic(data, 4);
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "\nCDF: System Area");
|
PrintAndLogEx(NORMAL, _YELLOW_("CDF: System Area") );
|
||||||
PrintAndLogEx(NORMAL, "------------------------------------------------------");
|
PrintAndLogEx(NORMAL, "------------------------------------------------------");
|
||||||
PrintAndLogEx(NORMAL, "MCD: %02x, MSN: %02x %02x %02x, MCC: %02x %s",
|
PrintAndLogEx(NORMAL, "MCD: %02x, MSN: %02x %02x %02x, MCC: %02x %s",
|
||||||
data[0],
|
data[0],
|
||||||
|
@ -208,7 +208,7 @@ int CmdLegicInfo(const char *Cmd) {
|
||||||
data[2],
|
data[2],
|
||||||
data[3],
|
data[3],
|
||||||
data[4],
|
data[4],
|
||||||
(calc_crc == crc) ? "OK" : "Fail"
|
(calc_crc == crc) ? _GREEN_("OK") : _RED_("Fail")
|
||||||
);
|
);
|
||||||
|
|
||||||
// MCD = Manufacturer ID (should be list meaning something?)
|
// MCD = Manufacturer ID (should be list meaning something?)
|
||||||
|
@ -271,7 +271,7 @@ int CmdLegicInfo(const char *Cmd) {
|
||||||
strncpy(token_type, "IM", sizeof(token_type) - 1);
|
strncpy(token_type, "IM", sizeof(token_type) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "DCF: %d (%02x %02x), Token Type=%s (OLE=%01u)",
|
PrintAndLogEx(NORMAL, "DCF: %d (%02x %02x), Token Type = %s (OLE = %01u)",
|
||||||
dcf,
|
dcf,
|
||||||
data[5],
|
data[5],
|
||||||
data[6],
|
data[6],
|
||||||
|
@ -284,7 +284,7 @@ int CmdLegicInfo(const char *Cmd) {
|
||||||
if (dcf != 0xFFFF) {
|
if (dcf != 0xFFFF) {
|
||||||
|
|
||||||
if (bIsSegmented) {
|
if (bIsSegmented) {
|
||||||
PrintAndLogEx(NORMAL, "WRP=%02u, WRC=%01u, RD=%01u, SSC=%02x",
|
PrintAndLogEx(NORMAL, "WRP = %02u, WRC = %01u, RD = %01u, SSC = %02X",
|
||||||
data[7] & 0x0f,
|
data[7] & 0x0f,
|
||||||
(data[7] & 0x70) >> 4,
|
(data[7] & 0x70) >> 4,
|
||||||
(data[7] & 0x80) >> 7,
|
(data[7] & 0x80) >> 7,
|
||||||
|
@ -303,7 +303,8 @@ int CmdLegicInfo(const char *Cmd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
PrintAndLogEx(NORMAL, "------------------------------------------------------");
|
||||||
|
|
||||||
uint8_t segCrcBytes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
uint8_t segCrcBytes[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
uint32_t segCalcCRC = 0;
|
uint32_t segCalcCRC = 0;
|
||||||
uint32_t segCRC = 0;
|
uint32_t segCRC = 0;
|
||||||
|
@ -312,7 +313,7 @@ int CmdLegicInfo(const char *Cmd) {
|
||||||
if (dcf > 60000)
|
if (dcf > 60000)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "\nADF: User Area");
|
PrintAndLogEx(NORMAL, _YELLOW_("\nADF: User Area") );
|
||||||
PrintAndLogEx(NORMAL, "------------------------------------------------------");
|
PrintAndLogEx(NORMAL, "------------------------------------------------------");
|
||||||
|
|
||||||
if (bIsSegmented) {
|
if (bIsSegmented) {
|
||||||
|
@ -345,27 +346,31 @@ int CmdLegicInfo(const char *Cmd) {
|
||||||
segCalcCRC = CRC8Legic(segCrcBytes, 8);
|
segCalcCRC = CRC8Legic(segCrcBytes, 8);
|
||||||
segCRC = data[i + 4] ^ crc;
|
segCRC = data[i + 4] ^ crc;
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "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)",
|
PrintAndLogEx(NORMAL, "Segment | %02u ", segmentNum);
|
||||||
segmentNum,
|
PrintAndLogEx(NORMAL, "raw header | 0x%02X 0x%02X 0x%02X 0x%02X",
|
||||||
data[i] ^ crc,
|
data[i] ^ crc,
|
||||||
data[i + 1] ^ crc,
|
data[i + 1] ^ crc,
|
||||||
data[i + 2] ^ crc,
|
data[i + 2] ^ crc,
|
||||||
data[i + 3] ^ crc,
|
data[i + 3] ^ crc
|
||||||
segment_len,
|
);
|
||||||
segment_flag,
|
PrintAndLogEx(NORMAL, "Segment len | %u, Flag: 0x%X (valid:%01u, last:%01u)",
|
||||||
(segment_flag & 0x4) >> 2,
|
segment_len,
|
||||||
(segment_flag & 0x8) >> 3,
|
segment_flag,
|
||||||
wrp,
|
(segment_flag & 0x4) >> 2,
|
||||||
wrc,
|
(segment_flag & 0x8) >> 3
|
||||||
((data[i + 3]^crc) & 0x80) >> 7,
|
);
|
||||||
segCRC,
|
PrintAndLogEx(NORMAL, " | WRP: %02u, WRC: %02u, RD: %01u, CRC: 0x%02X (%s)",
|
||||||
(segCRC == segCalcCRC) ? "OK" : "fail"
|
wrp,
|
||||||
);
|
wrc,
|
||||||
|
((data[i + 3] ^ crc) & 0x80) >> 7,
|
||||||
|
segCRC,
|
||||||
|
(segCRC == segCalcCRC) ? _GREEN_("OK") : _RED_("Fail")
|
||||||
|
);
|
||||||
|
|
||||||
i += 5;
|
i += 5;
|
||||||
|
|
||||||
if (hasWRC) {
|
if (hasWRC) {
|
||||||
PrintAndLogEx(NORMAL, "WRC protected area: (I %d | K %d| WRC %d)", i, k, wrc);
|
PrintAndLogEx(NORMAL, "\nWRC protected area: (I %d | K %d| WRC %d)", i, k, wrc);
|
||||||
PrintAndLogEx(NORMAL, "\nrow | data");
|
PrintAndLogEx(NORMAL, "\nrow | data");
|
||||||
PrintAndLogEx(NORMAL, "-----+------------------------------------------------");
|
PrintAndLogEx(NORMAL, "-----+------------------------------------------------");
|
||||||
|
|
||||||
|
@ -373,7 +378,7 @@ int CmdLegicInfo(const char *Cmd) {
|
||||||
data[k] ^= crc;
|
data[k] ^= crc;
|
||||||
|
|
||||||
print_hex_break(data + i, wrc, 16);
|
print_hex_break(data + i, wrc, 16);
|
||||||
|
PrintAndLogEx(NORMAL, "-----+------------------------------------------------\n");
|
||||||
i += wrc;
|
i += wrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,27 +391,30 @@ int CmdLegicInfo(const char *Cmd) {
|
||||||
data[k] ^= crc;
|
data[k] ^= crc;
|
||||||
|
|
||||||
print_hex_break(data + i, wrp_len, 16);
|
print_hex_break(data + i, wrp_len, 16);
|
||||||
|
PrintAndLogEx(NORMAL, "-----+------------------------------------------------\n");
|
||||||
i += wrp_len;
|
i += wrp_len;
|
||||||
|
|
||||||
// does this one work? (Answer: Only if KGH/BGH is used with BCD encoded card number! So maybe this will show just garbage...)
|
// does this one work? (Answer: Only if KGH/BGH is used with BCD encoded card number! So maybe this will show just garbage...)
|
||||||
if (wrp_len == 8)
|
if (wrp_len == 8) {
|
||||||
PrintAndLogEx(NORMAL, "Card ID: %2X%02X%02X", data[i - 4]^crc, data[i - 3]^crc, data[i - 2]^crc);
|
PrintAndLogEx(NORMAL, "Card ID: " _YELLOW_("%2X%02X%02X"),
|
||||||
|
data[i - 4] ^ crc,
|
||||||
|
data[i - 3] ^ crc,
|
||||||
|
data[i - 2] ^ crc
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (remain_seg_payload_len > 0 ) {
|
||||||
|
PrintAndLogEx(NORMAL, "Remaining segment payload: (I %d | K %d | Remain LEN %d)", i, k, remain_seg_payload_len);
|
||||||
|
PrintAndLogEx(NORMAL, "\nrow | data");
|
||||||
|
PrintAndLogEx(NORMAL, "-----+------------------------------------------------");
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "Remaining segment payload: (I %d | K %d | Remain LEN %d)", i, k, remain_seg_payload_len);
|
for (k = i; k < (i + remain_seg_payload_len); ++k)
|
||||||
PrintAndLogEx(NORMAL, "\nrow | data");
|
data[k] ^= crc;
|
||||||
PrintAndLogEx(NORMAL, "-----+------------------------------------------------");
|
|
||||||
|
|
||||||
for (k = i; k < (i + remain_seg_payload_len); ++k)
|
|
||||||
data[k] ^= crc;
|
|
||||||
|
|
||||||
print_hex_break(data + i, remain_seg_payload_len, 16);
|
|
||||||
|
|
||||||
i += remain_seg_payload_len;
|
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "-----+------------------------------------------------\n");
|
|
||||||
|
|
||||||
|
print_hex_break(data + i, remain_seg_payload_len, 16);
|
||||||
|
PrintAndLogEx(NORMAL, "-----+------------------------------------------------\n");
|
||||||
|
i += remain_seg_payload_len;
|
||||||
|
}
|
||||||
// end with last segment
|
// end with last segment
|
||||||
if (segment_flag & 0x8)
|
if (segment_flag & 0x8)
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -424,7 +432,7 @@ int CmdLegicInfo(const char *Cmd) {
|
||||||
bool hasWRC = (wrc > 0);
|
bool hasWRC = (wrc > 0);
|
||||||
bool hasWRP = (wrp > wrc);
|
bool hasWRP = (wrp > wrc);
|
||||||
int wrp_len = (wrp - wrc);
|
int wrp_len = (wrp - wrc);
|
||||||
int remain_seg_payload_len = (1024 - 22 - wrp); // Any chance to get physical card size here!?
|
int remain_seg_payload_len = (card.cardsize - 22 - wrp);
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "Unsegmented card - WRP: %02u, WRC: %02u, RD: %01u",
|
PrintAndLogEx(NORMAL, "Unsegmented card - WRP: %02u, WRC: %02u, RD: %01u",
|
||||||
wrp,
|
wrp,
|
||||||
|
@ -437,6 +445,7 @@ int CmdLegicInfo(const char *Cmd) {
|
||||||
PrintAndLogEx(NORMAL, "\nrow | data");
|
PrintAndLogEx(NORMAL, "\nrow | data");
|
||||||
PrintAndLogEx(NORMAL, "-----+------------------------------------------------");
|
PrintAndLogEx(NORMAL, "-----+------------------------------------------------");
|
||||||
print_hex_break(data + i, wrc, 16);
|
print_hex_break(data + i, wrc, 16);
|
||||||
|
PrintAndLogEx(NORMAL, "-----+------------------------------------------------\n");
|
||||||
i += wrc;
|
i += wrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -445,20 +454,27 @@ int CmdLegicInfo(const char *Cmd) {
|
||||||
PrintAndLogEx(NORMAL, "\nrow | data");
|
PrintAndLogEx(NORMAL, "\nrow | data");
|
||||||
PrintAndLogEx(NORMAL, "-----+------------------------------------------------");
|
PrintAndLogEx(NORMAL, "-----+------------------------------------------------");
|
||||||
print_hex_break(data + i, wrp_len, 16);
|
print_hex_break(data + i, wrp_len, 16);
|
||||||
|
PrintAndLogEx(NORMAL, "-----+------------------------------------------------\n");
|
||||||
i += wrp_len;
|
i += wrp_len;
|
||||||
|
|
||||||
// does this one work? (Answer: Only if KGH/BGH is used with BCD encoded card number! So maybe this will show just garbage...)
|
// Q: does this one work?
|
||||||
if (wrp_len == 8)
|
// A: Only if KGH/BGH is used with BCD encoded card number. Maybe this will show just garbage
|
||||||
PrintAndLogEx(NORMAL, "Card ID: %2X%02X%02X", data[i - 4], data[i - 3], data[i - 2]);
|
if (wrp_len == 8) {
|
||||||
|
PrintAndLogEx(NORMAL, "Card ID: " _YELLOW_("%2X%02X%02X"),
|
||||||
|
data[i - 4],
|
||||||
|
data[i - 3],
|
||||||
|
data[i - 2]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "Remaining segment payload: (I %d | Remain LEN %d)", i, remain_seg_payload_len);
|
if ( i > 0 ) {
|
||||||
PrintAndLogEx(NORMAL, "\nrow | data");
|
PrintAndLogEx(NORMAL, "Remaining segment payload: (I %d | Remain LEN %d)", i, remain_seg_payload_len);
|
||||||
PrintAndLogEx(NORMAL, "-----+------------------------------------------------");
|
PrintAndLogEx(NORMAL, "\nrow | data");
|
||||||
print_hex_break(data + i, remain_seg_payload_len, 16);
|
PrintAndLogEx(NORMAL, "-----+------------------------------------------------");
|
||||||
// i += remain_seg_payload_len;
|
print_hex_break(data + i, remain_seg_payload_len, 16);
|
||||||
|
PrintAndLogEx(NORMAL, "-----+------------------------------------------------\n");
|
||||||
PrintAndLogEx(NORMAL, "-----+------------------------------------------------\n");
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue