]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmf.c
CHG: minor change initializing array.
[proxmark3-svn] / client / cmdhfmf.c
index 94a0b217d1d3707dc6d688a2171c5c90600c4d66..00252661d04360cd1e29ddd93ac825deee377a03 100644 (file)
@@ -20,7 +20,8 @@ int CmdHF14AMifare(const char *Cmd)
        uint32_t nt = 0, nr = 0;\r
        uint64_t par_list = 0, ks_list = 0, r_key = 0;\r
        int16_t isOK = 0;\r
-\r
+       int tmpchar; \r
+       \r
        UsbCommand c = {CMD_READER_MIFARE, {true, 0, 0}};\r
 \r
        // message\r
@@ -29,20 +30,25 @@ int CmdHF14AMifare(const char *Cmd)
        printf("Press button on the proxmark3 device to abort both proxmark3 and client.\n");\r
        printf("-------------------------------------------------------------------------\n");\r
 \r
+       clock_t t = clock();\r
        \r
 start:\r
     clearCommandBuffer();\r
     SendCommand(&c);\r
        \r
        //flush queue\r
-       while (ukbhit()) getchar();\r
+       while (ukbhit()) {\r
+               tmpchar = getchar();\r
+               (void)tmpchar;\r
+       }\r
 \r
        // wait cycle\r
        while (true) {\r
         printf(".");\r
                fflush(stdout);\r
                if (ukbhit()) {\r
-                       getchar();\r
+                       tmpchar = getchar();\r
+                       (void)tmpchar;\r
                        printf("\naborted via keyboard!\n");\r
                        break;\r
                }\r
@@ -85,8 +91,9 @@ start:
                printf("------------------------------------------------------------------\n");\r
                PrintAndLog("Found valid key: %012"llx" \n", r_key);\r
        }\r
-       \r
-       PrintAndLog("");\r
+       t = clock() - t;\r
+       //printf("Time in darkside: %d ticks - %1.2f seconds\n", t, ((float)t)/CLOCKS_PER_SEC);\r
+       printf("Time in darkside: %Lf ticks - %1.2Lf seconds\n", (long double)t, ((long double)t)/CLOCKS_PER_SEC);\r
        return 0;\r
 }\r
 \r
@@ -662,8 +669,7 @@ int CmdHF14AMfNested(const char *Cmd)
                }\r
        }\r
        else { // ------------------------------------  multiple sectors working\r
-               clock_t time1;\r
-               time1 = clock();\r
+               clock_t time1 = clock();\r
 \r
                e_sector = calloc(SectorsCnt, sizeof(sector));\r
                if (e_sector == NULL) return 1;\r
@@ -733,7 +739,38 @@ int CmdHF14AMfNested(const char *Cmd)
                        }\r
                }\r
 \r
-               printf("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
+               // 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.2f (%1.2f 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
                //print them\r
@@ -742,7 +779,11 @@ int CmdHF14AMfNested(const char *Cmd)
                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
@@ -894,7 +935,7 @@ int CmdHF14AMfNestedHard(const char *Cmd)
                        slow?"Yes":"No",\r
                        tests);\r
 \r
-       int16_t isOK = mfnestedhard(blockNo, keyType, key, trgBlockNo, trgKeyType, know_target_key?trgkey:NULL, nonce_file_read, nonce_file_write, slow);\r
+       int16_t isOK = mfnestedhard(blockNo, keyType, key, trgBlockNo, trgKeyType, know_target_key?trgkey:NULL, nonce_file_read, nonce_file_write, slow, tests);\r
 \r
        if (isOK) {\r
                switch (isOK) {\r
@@ -1043,7 +1084,7 @@ int CmdHF14AMfChk(const char *Cmd)
                                                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
@@ -1083,7 +1124,9 @@ int CmdHF14AMfChk(const char *Cmd)
                        }\r
                }\r
        }\r
-       \r
+       // time\r
+       clock_t time1 = clock();\r
+               \r
        for ( int t = !keyType; t < 2; keyType==2?(t++):(t=2) ) {\r
                int b=blockNo;\r
                for (int i = 0; i < SectorsCnt; ++i) {\r
@@ -1105,6 +1148,8 @@ int CmdHF14AMfChk(const char *Cmd)
                        b<127?(b+=4):(b+=16);   \r
                }\r
        }\r
+       printf("Time in checkkeys: %1.3f (%1.3f sec per key)\n\n", ((float)clock() - time1)/CLOCKS_PER_SEC, ((float)clock() - time1)/keycnt/CLOCKS_PER_SEC);\r
+               \r
 \r
        if (transferToEml) {\r
                uint8_t block[16];\r
@@ -1223,7 +1268,7 @@ int CmdHF14AMf1kSim(const char *Cmd)
                                        \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
@@ -1784,6 +1829,7 @@ int CmdHF14AMfCLoad(const char *Cmd)
 \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
@@ -1971,6 +2017,7 @@ int CmdHF14AMfSniff(const char *Cmd){
        bool wantSaveToEmlFile = 0;\r
 \r
        //var \r
+       int tmpchar;\r
        int res = 0;\r
        int len = 0;\r
        int blockLen = 0;\r
@@ -2021,7 +2068,8 @@ int CmdHF14AMfSniff(const char *Cmd){
                printf(".");\r
                fflush(stdout);\r
                if (ukbhit()) {\r
-                       getchar();\r
+                       tmpchar = getchar();\r
+                       (void)tmpchar;\r
                        printf("\naborted via keyboard!\n");\r
                        break;\r
                }\r
Impressum, Datenschutz