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