]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
CHG: 'hf mf chk' now correctly tests to read key B, when we specify target keytype...
authoriceman1001 <iceman@iuse.se>
Sat, 23 Apr 2016 09:32:37 +0000 (11:32 +0200)
committericeman1001 <iceman@iuse.se>
Sat, 23 Apr 2016 09:32:37 +0000 (11:32 +0200)
CHG: 'hf mf chk'  now correctly init all sector keys to 0xFFFFFFFFFFFF,  so it looks unified.

client/cmdhfmf.c

index ec5d4487ce90068bc63794b2db2f85c5050a570d..1c866dc9318d6001e37b2d90f570b3a3cc671c47 100644 (file)
@@ -1168,6 +1168,15 @@ int CmdHF14AMfChk(const char *Cmd) {
                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
@@ -1182,22 +1191,16 @@ int CmdHF14AMfChk(const char *Cmd) {
                        \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
@@ -1210,32 +1213,35 @@ int CmdHF14AMfChk(const char *Cmd) {
                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
Impressum, Datenschutz