CHG: 'hf mf chk' now correctly tests to read key B, when we specify target keytype B or ?.

CHG: 'hf mf chk'  now correctly init all sector keys to 0xFFFFFFFFFFFF,  so it looks unified.
This commit is contained in:
iceman1001 2016-04-23 11:32:37 +02:00
commit d948e0d140

View file

@ -1168,6 +1168,15 @@ int CmdHF14AMfChk(const char *Cmd) {
return 1; return 1;
} }
// empty e_sector
for(int i = 0; i < SectorsCnt; ++i){
e_sector[i].Key[0] = 0xffffffffffff;
e_sector[i].Key[1] = 0xffffffffffff;
e_sector[i].foundKey[0] = FALSE;
e_sector[i].foundKey[1] = FALSE;
}
uint8_t trgKeyType = 0; uint8_t trgKeyType = 0;
uint32_t max_keys = keycnt > (USB_CMD_DATA_SIZE/6) ? (USB_CMD_DATA_SIZE/6) : keycnt; uint32_t max_keys = keycnt > (USB_CMD_DATA_SIZE/6) ? (USB_CMD_DATA_SIZE/6) : keycnt;
@ -1182,22 +1191,16 @@ int CmdHF14AMfChk(const char *Cmd) {
// skip already found keys. // skip already found keys.
if (e_sector[i].foundKey[trgKeyType]) continue; if (e_sector[i].foundKey[trgKeyType]) continue;
for (uint32_t c = 0; c < keycnt; c += max_keys) { for (uint32_t c = 0; c < keycnt; c += max_keys) {
uint32_t size = keycnt-c > max_keys ? max_keys : keycnt-c; uint32_t size = keycnt-c > max_keys ? max_keys : keycnt-c;
res = mfCheckKeys(b, trgKeyType, true, size, &keyBlock[6*c], &key64); res = mfCheckKeys(b, trgKeyType, true, size, &keyBlock[6*c], &key64);
if (!res) { if (!res) {
//PrintAndLog("Sector:%3d Block:%3d, key type: %C -- Found key [%012"llx"]", i, b, trgKeyType ? 'B':'A', key64);
e_sector[i].Key[trgKeyType] = key64; e_sector[i].Key[trgKeyType] = key64;
e_sector[i].foundKey[trgKeyType] = TRUE; e_sector[i].foundKey[trgKeyType] = TRUE;
break; break;
} else {
e_sector[i].Key[trgKeyType] = 0xffffffffffff;
e_sector[i].foundKey[trgKeyType] = FALSE;
} }
printf("."); printf(".");
fflush(stdout); fflush(stdout);
@ -1210,32 +1213,35 @@ int CmdHF14AMfChk(const char *Cmd) {
printf("\nTime in checkkeys: %.0f ticks\n", (float)t1); printf("\nTime in checkkeys: %.0f ticks\n", (float)t1);
// 20160116 If Sector A is found, but not Sector B, try just reading it of the tag? // 20160116 If Sector A is found, but not Sector B, try just reading it of the tag?
PrintAndLog("testing to read B..."); if ( keyType != 1 ) {
for (i = 0; i < SectorsCnt; i++) {
// KEY A but not KEY B PrintAndLog("testing to read key B...");
if ( e_sector[i].foundKey[0] && !e_sector[i].foundKey[1] ) { for (i = 0; i < SectorsCnt; i++) {
// KEY A but not KEY B
uint8_t sectrail = (FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1); if ( e_sector[i].foundKey[0] && !e_sector[i].foundKey[1] ) {
PrintAndLog("Reading block %d", sectrail); uint8_t sectrail = (FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1);
UsbCommand c = {CMD_MIFARE_READBL, {sectrail, 0, 0}};
num_to_bytes(e_sector[i].Key[0], 6, c.d.asBytes); // KEY A
clearCommandBuffer();
SendCommand(&c);
UsbCommand resp;
if ( !WaitForResponseTimeout(CMD_ACK,&resp,1500)) continue;
uint8_t isOK = resp.arg[0] & 0xff; PrintAndLog("Reading block %d", sectrail);
if (!isOK) continue;
UsbCommand c = {CMD_MIFARE_READBL, {sectrail, 0, 0}};
num_to_bytes(e_sector[i].Key[0], 6, c.d.asBytes); // KEY A
clearCommandBuffer();
SendCommand(&c);
uint8_t *data = resp.d.asBytes; UsbCommand resp;
key64 = bytes_to_num(data+10, 6); if ( !WaitForResponseTimeout(CMD_ACK,&resp,1500)) continue;
if (key64) {
PrintAndLog("Data:%s", sprint_hex(data+10, 6)); uint8_t isOK = resp.arg[0] & 0xff;
e_sector[i].foundKey[1] = 1; if (!isOK) continue;
e_sector[i].Key[1] = key64;
uint8_t *data = resp.d.asBytes;
key64 = bytes_to_num(data+10, 6);
if (key64) {
PrintAndLog("Data:%s", sprint_hex(data+10, 6));
e_sector[i].foundKey[1] = 1;
e_sector[i].Key[1] = key64;
}
} }
} }
} }