}\r
}\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
+ 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
+ uint8_t *data = resp.d.asBytes;\r
+\r
+ if (isOK) {\r
+\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
+ \r
PrintAndLog("Time in nested: %1.3f (%1.3f sec per key)\n\n", ((float)clock() - time1)/CLOCKS_PER_SEC, ((float)clock() - time1)/iterations/CLOCKS_PER_SEC);\r
\r
PrintAndLog("-----------------------------------------------\nIterations count: %d\n\n", iterations);\r
PrintAndLog("|---|----------------|---|----------------|---|");\r
for (i = 0; i < SectorsCnt; i++) {\r
PrintAndLog("|%03d| %012"llx" | %d | %012"llx" | %d |", i,\r
- e_sector[i].Key[0], e_sector[i].foundKey[0], e_sector[i].Key[1], e_sector[i].foundKey[1]);\r
+ e_sector[i].Key[0], \r
+ e_sector[i].foundKey[0], \r
+ e_sector[i].Key[1], \r
+ e_sector[i].foundKey[1]\r
+ );\r
}\r
PrintAndLog("|---|----------------|---|----------------|---|");\r
\r
if (!p) {\r
PrintAndLog("Cannot allocate memory for defKeys");\r
free(keyBlock);\r
- free(f);\r
+ fclose(f);\r
return 2;\r
}\r
keyBlock = p;\r
\r
uint64_t corr_uid = 0;\r
if ( memcmp(data, "\x00\x00\x00\x00", 4) == 0 ) {\r
- corr_uid = (data[3] << 24) | (data[2] << 16) | (data[1] << 8) | data[0];\r
+ corr_uid = ((uint64_t)(data[3] << 24)) | (data[2] << 16) | (data[1] << 8) | data[0];\r
tryMfk32(corr_uid, data, key);\r
} else {\r
corr_uid |= (uint64_t)data[2] << 48; \r
\r
if (mfCSetBlock(blockNum, buf8, NULL, flags)) {\r
PrintAndLog("Can't set magic card block: %d", blockNum);\r
+ fclose(f);\r
return 3;\r
}\r
blockNum++;\r