]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmf.c
CHG: syntax suger..
[proxmark3-svn] / client / cmdhfmf.c
index d354952b10d8a2ab8d227c7f9b4ed92b4bb4dbe9..adfd5ecb588e2483688c2ab8e8b30f23d127c940 100644 (file)
@@ -65,11 +65,6 @@ start:
                UsbCommand resp;\r
                if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {\r
                        isOK  = resp.arg[0];\r
-                       uid = (uint32_t)bytes_to_num(resp.d.asBytes +  0, 4);\r
-                       nt =  (uint32_t)bytes_to_num(resp.d.asBytes +  4, 4);\r
-                       par_list = bytes_to_num(resp.d.asBytes +  8, 8);\r
-                       ks_list = bytes_to_num(resp.d.asBytes +  16, 8);\r
-                       nr = bytes_to_num(resp.d.asBytes + 24, 4);\r
                        printf("\n\n");\r
                        switch (isOK) {\r
                                case -1 : PrintAndLog("Button pressed. Aborted.\n"); break;\r
@@ -79,6 +74,11 @@ start:
                                                  PrintAndLog("generating polynomial with 16 effective bits only, but shows unexpected behaviour.\n"); break;\r
                                default: ;\r
                        }\r
+                       uid = (uint32_t)bytes_to_num(resp.d.asBytes +  0, 4);\r
+                       nt =  (uint32_t)bytes_to_num(resp.d.asBytes +  4, 4);\r
+                       par_list = bytes_to_num(resp.d.asBytes +  8, 8);\r
+                       ks_list = bytes_to_num(resp.d.asBytes +  16, 8);\r
+                       nr = bytes_to_num(resp.d.asBytes + 24, 4);\r
                        break;\r
                }\r
        }       \r
@@ -101,7 +101,7 @@ start:
        \r
        t1 = clock() - t1;\r
        if ( t1 > 0 )\r
-               PrintAndLog("Time in darkside: %.0f ticks - %4.2f sec\n", (float)t1, ((float)t1)/CLOCKS_PER_SEC);\r
+               PrintAndLog("Time in darkside: %.0f ticks\n", (float)t1);\r
        return 0;\r
 }\r
 \r
@@ -593,10 +593,11 @@ int CmdHF14AMfNested(const char *Cmd)
                PrintAndLog("t - transfer keys into emulator memory");\r
                PrintAndLog("d - write keys to binary file");\r
                PrintAndLog(" ");\r
-               PrintAndLog("      sample1: hf mf nested 1 0 A FFFFFFFFFFFF ");\r
-               PrintAndLog("      sample2: hf mf nested 1 0 A FFFFFFFFFFFF t ");\r
-               PrintAndLog("      sample3: hf mf nested 1 0 A FFFFFFFFFFFF d ");\r
-               PrintAndLog("      sample4: hf mf nested o 0 A FFFFFFFFFFFF 4 A");\r
+               PrintAndLog(" samples:");\r
+               PrintAndLog("              hf mf nested 1 0 A FFFFFFFFFFFF ");\r
+               PrintAndLog("              hf mf nested 1 0 A FFFFFFFFFFFF t ");\r
+               PrintAndLog("              hf mf nested 1 0 A FFFFFFFFFFFF d ");\r
+               PrintAndLog("              hf mf nested o 0 A FFFFFFFFFFFF 4 A");\r
                return 0;\r
        }       \r
        \r
@@ -706,13 +707,14 @@ int CmdHF14AMfNested(const char *Cmd)
                }\r
                clock_t t2 = clock() - t1;\r
                if ( t2 > 0 )\r
-                       PrintAndLog("Time to check 6 known keys: %.0f ticks %4.2f sec", (float)t2, ((float)t2)/CLOCKS_PER_SEC);\r
-       \r
+                       PrintAndLog("Time to check 6 known keys: %.0f ticks", (float)t2 );\r
+\r
+               PrintAndLog("enter nested..."); \r
                \r
                // nested sectors\r
                iterations = 0;\r
-               PrintAndLog("enter nested...");\r
                bool calibrate = true;\r
+\r
                for (i = 0; i < NESTED_SECTOR_RETRY; i++) {\r
                        for (uint8_t sectorNo = 0; sectorNo < SectorsCnt; ++sectorNo) {\r
                                for (trgKeyType = 0; trgKeyType < 2; ++trgKeyType) { \r
@@ -742,6 +744,10 @@ int CmdHF14AMfNested(const char *Cmd)
                                }\r
                        }\r
                }\r
+               \r
+               t1 = clock() - t1;\r
+               if ( t1 > 0 )\r
+                       PrintAndLog("Time in nested: %.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("trying to read key B...");\r
@@ -768,15 +774,12 @@ int CmdHF14AMfNested(const char *Cmd)
                                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].foundKey[1] = TRUE;\r
                                        e_sector[i].Key[1] = key64;\r
                                }\r
                        }\r
                }\r
-               \r
-               t1 = clock() - t1;\r
-               if ( t1 > 0 )\r
-                       PrintAndLog("Time in nested: %.0f ticks %4.2f sec (%4.2f sec per key)\n", (float)t1, ((float)t1)/CLOCKS_PER_SEC, ((float)t1)/iterations/CLOCKS_PER_SEC);\r
+\r
                \r
                //print them\r
                printKeyTable( SectorsCnt, e_sector );\r
@@ -1047,7 +1050,7 @@ int CmdHF14AMfChk(const char *Cmd)
                                }\r
                                keyBlock = p;\r
                        }\r
-                       PrintAndLog("check key[%2d] %02x%02x%02x%02x%02x%02x", keycnt,\r
+                       PrintAndLog("key[%2d] %02x%02x%02x%02x%02x%02x", keycnt,\r
                        (keyBlock + 6*keycnt)[0],(keyBlock + 6*keycnt)[1], (keyBlock + 6*keycnt)[2],\r
                        (keyBlock + 6*keycnt)[3], (keyBlock + 6*keycnt)[4],     (keyBlock + 6*keycnt)[5], 6);\r
                        keycnt++;\r
@@ -1087,7 +1090,7 @@ int CmdHF14AMfChk(const char *Cmd)
                                        }\r
                                        memset(keyBlock + 6 * keycnt, 0, 6);\r
                                        num_to_bytes(strtoll(buf, NULL, 16), 6, keyBlock + 6*keycnt);\r
-                                       PrintAndLog("check custom key[%2d] %012"llx, keycnt, bytes_to_num(keyBlock + 6*keycnt, 6));\r
+                                       PrintAndLog("check key[%2d] %012"llx, keycnt, bytes_to_num(keyBlock + 6*keycnt, 6));\r
                                        keycnt++;\r
                                        memset(buf, 0, sizeof(buf));\r
                                }\r
@@ -1104,7 +1107,7 @@ int CmdHF14AMfChk(const char *Cmd)
        if (keycnt == 0) {\r
                PrintAndLog("No key specified, trying default keys");\r
                for (;keycnt < defaultKeysSize; keycnt++)\r
-                       PrintAndLog("check default key[%2d] %02x%02x%02x%02x%02x%02x", keycnt,\r
+                       PrintAndLog("key[%2d] %02x%02x%02x%02x%02x%02x", keycnt,\r
                                (keyBlock + 6*keycnt)[0],(keyBlock + 6*keycnt)[1], (keyBlock + 6*keycnt)[2],\r
                                (keyBlock + 6*keycnt)[3], (keyBlock + 6*keycnt)[4],     (keyBlock + 6*keycnt)[5], 6);\r
        }\r
@@ -1117,19 +1120,20 @@ int CmdHF14AMfChk(const char *Cmd)
        }\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
        // time\r
        clock_t t1 = clock();\r
        \r
        // check keys.\r
-       for (trgKeyType = 0; trgKeyType < 2; ++trgKeyType) {\r
+       for (trgKeyType = !keyType;  trgKeyType < 2;  (keyType==2) ? (++trgKeyType) : (trgKeyType=2) ) {\r
+\r
                int b = blockNo;\r
                for (int i = 0; i < SectorsCnt; ++i) {\r
                        \r
                        // skip already found keys.\r
                        if (e_sector[i].foundKey[trgKeyType]) continue;\r
                        \r
-                       uint32_t max_keys = keycnt > (USB_CMD_DATA_SIZE/6) ? (USB_CMD_DATA_SIZE/6) : keycnt;\r
                        \r
                        for (uint32_t c = 0; c < keycnt; c += max_keys) {\r
                                \r
@@ -1137,7 +1141,7 @@ int CmdHF14AMfChk(const char *Cmd)
                                \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
+                                       //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
@@ -1146,10 +1150,15 @@ int CmdHF14AMfChk(const char *Cmd)
                                        e_sector[i].Key[trgKeyType] = 0xffffffffffff;\r
                                        e_sector[i].foundKey[trgKeyType] = FALSE;\r
                                }\r
+                               printf(".");\r
                        }\r
                        b < 127 ? ( b +=4 ) : ( b += 16 );      \r
                }\r
        }\r
+       t1 = clock() - t1;\r
+       if ( t1 > 0 )\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
@@ -1180,10 +1189,7 @@ int CmdHF14AMfChk(const char *Cmd)
                        }\r
                }\r
        }\r
-       \r
-       t1 = clock() - t1;\r
-       if ( t1 > 0 )\r
-               printf("Time in checkkeys: %.0f ticks  %1.2f sec (%1.2f sec per key)\n\n", (float)t1, ((float)t1)/CLOCKS_PER_SEC, ((float)t1)/keycnt/CLOCKS_PER_SEC);\r
+\r
 \r
        //print them\r
        printKeyTable( SectorsCnt, e_sector );\r
@@ -1713,11 +1719,13 @@ int CmdHF14AMfCSetUID(const char *Cmd)
        int argi=0;\r
 \r
        if (strlen(Cmd) < 1 || param_getchar(Cmd, argi) == 'h') {\r
-               PrintAndLog("Usage:  hf mf csetuid <UID 8 hex symbols> [ATQA 4 hex symbols SAK 2 hex symbols] [w]");\r
-               PrintAndLog("sample:  hf mf csetuid 01020304");\r
-               PrintAndLog("sample:  hf mf csetuid 01020304 0004 08 w");\r
                PrintAndLog("Set UID, ATQA, and SAK for magic Chinese card (only works with such cards)");\r
                PrintAndLog("If you also want to wipe the card then add 'w' at the end of the command line.");\r
+               PrintAndLog("");\r
+               PrintAndLog("Usage:  hf mf csetuid <UID 8 hex symbols> [ATQA 4 hex symbols SAK 2 hex symbols] [w]");\r
+               PrintAndLog("");\r
+               PrintAndLog("sample:  hf mf csetuid 01020304");\r
+               PrintAndLog("         hf mf csetuid 01020304 0004 08 w");\r
                return 0;\r
        }\r
 \r
@@ -1758,7 +1766,7 @@ int CmdHF14AMfCSetUID(const char *Cmd)
 \r
        PrintAndLog("--wipe card:%s  uid:%s", (wipeCard)?"YES":"NO", sprint_hex(uid, 4));\r
 \r
-       res = mfCSetUID(uid, (atqaPresent)?atqa:NULL, (atqaPresent)?sak:NULL, oldUid, wipeCard);\r
+       res = mfCSetUID(uid, (atqaPresent) ? atqa : NULL, (atqaPresent) ? sak : NULL, oldUid, wipeCard);\r
        if (res) {\r
                        PrintAndLog("Can't set UID. error=%d", res);\r
                        return 1;\r
Impressum, Datenschutz