mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 22:03:42 -07:00
fix mem leak and add new pacs style decoding when reading block 7
This commit is contained in:
parent
eb8c2d1b6a
commit
8f7d7a2dd4
1 changed files with 26 additions and 17 deletions
|
@ -1371,6 +1371,8 @@ static int iclass_decode_credentials_new_pacs(uint8_t *d) {
|
||||||
return PM3_EINVARG;
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(binstr);
|
||||||
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(INFO, "Wiegand decode");
|
PrintAndLogEx(INFO, "Wiegand decode");
|
||||||
wiegand_message_t packed = initialize_message_object(top, mid, bot, 0);
|
wiegand_message_t packed = initialize_message_object(top, mid, bot, 0);
|
||||||
|
@ -2783,9 +2785,9 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) {
|
||||||
}
|
}
|
||||||
case 7: {
|
case 7: {
|
||||||
|
|
||||||
uint8_t dec_data[8];
|
uint8_t dec_data[PICOPASS_BLOCK_SIZE];
|
||||||
|
|
||||||
uint64_t a = bytes_to_num(data, 8);
|
uint64_t a = bytes_to_num(data, PICOPASS_BLOCK_SIZE);
|
||||||
bool starts = (leadingzeros(a) < 12);
|
bool starts = (leadingzeros(a) < 12);
|
||||||
bool ones = (bitcount64(a) > 16 && bitcount64(a) < 48);
|
bool ones = (bitcount64(a) > 16 && bitcount64(a) < 48);
|
||||||
|
|
||||||
|
@ -2798,25 +2800,32 @@ static int CmdHFiClass_ReadBlock(const char *Cmd) {
|
||||||
PrintAndLogEx(INFO, "data looks unencrypted, trying to decode");
|
PrintAndLogEx(INFO, "data looks unencrypted, trying to decode");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memcmp(dec_data, empty, 8) != 0) {
|
bool has_new_pacs = iclass_detect_new_pacs(dec_data);
|
||||||
|
bool has_values = (memcmp(dec_data, empty, PICOPASS_BLOCK_SIZE) != 0) && (memcmp(dec_data, zeros, PICOPASS_BLOCK_SIZE) != 0);
|
||||||
|
|
||||||
//todo: remove preamble/sentinel
|
if (has_values) {
|
||||||
uint32_t top = 0, mid = 0, bot = 0;
|
|
||||||
|
|
||||||
char hexstr[16 + 1] = {0};
|
if (has_new_pacs) {
|
||||||
hex_to_buffer((uint8_t *)hexstr, dec_data, 8, sizeof(hexstr) - 1, 0, 0, true);
|
iclass_decode_credentials_new_pacs(dec_data);
|
||||||
hexstring_to_u96(&top, &mid, &bot, hexstr);
|
} else {
|
||||||
|
//todo: remove preamble/sentinel
|
||||||
|
uint32_t top = 0, mid = 0, bot = 0;
|
||||||
|
|
||||||
char binstr[64 + 1];
|
char hexstr[16 + 1] = {0};
|
||||||
hextobinstring(binstr, hexstr);
|
hex_to_buffer((uint8_t *)hexstr, dec_data, PICOPASS_BLOCK_SIZE, sizeof(hexstr) - 1, 0, 0, true);
|
||||||
char *pbin = binstr;
|
hexstring_to_u96(&top, &mid, &bot, hexstr);
|
||||||
while (strlen(pbin) && *(++pbin) == '0');
|
|
||||||
|
|
||||||
PrintAndLogEx(SUCCESS, " bin : %s", pbin);
|
char binstr[64 + 1];
|
||||||
PrintAndLogEx(INFO, "");
|
hextobinstring(binstr, hexstr);
|
||||||
PrintAndLogEx(INFO, "------------------------------ " _CYAN_("Wiegand") " -------------------------------");
|
char *pbin = binstr;
|
||||||
wiegand_message_t packed = initialize_message_object(top, mid, bot, 0);
|
while (strlen(pbin) && *(++pbin) == '0');
|
||||||
HIDTryUnpack(&packed);
|
|
||||||
|
PrintAndLogEx(SUCCESS, " bin : %s", pbin);
|
||||||
|
PrintAndLogEx(INFO, "");
|
||||||
|
PrintAndLogEx(INFO, "------------------------------ " _CYAN_("Wiegand") " -------------------------------");
|
||||||
|
wiegand_message_t packed = initialize_message_object(top, mid, bot, 0);
|
||||||
|
HIDTryUnpack(&packed);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(INFO, "no credential found");
|
PrintAndLogEx(INFO, "no credential found");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue