]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmf.c
CHG: syntax suger, text edit
[proxmark3-svn] / client / cmdhfmf.c
index cf0f5c131199aad6eaf59d937377b1e6149de272..1d516ebc32243f678bcfa17eb6bbcd23861e2d34 100644 (file)
@@ -30,7 +30,7 @@ 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
+       clock_t t1 = clock();\r
        \r
 start:\r
     clearCommandBuffer();\r
@@ -91,9 +91,10 @@ start:
                printf("------------------------------------------------------------------\n");\r
                PrintAndLog("Found valid key: %012"llx" \n", r_key);\r
        }\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
+       t1 = clock() - t1;\r
+       if ( t1 > 0 ){\r
+               PrintAndLog("Time in darkside: %f ticks - %1.2f sec\n", (float)t1, ((float)t1)/CLOCKS_PER_SEC);\r
+       }\r
        return 0;\r
 }\r
 \r
@@ -312,8 +313,10 @@ int CmdHF14AMfDump(const char *Cmd)
        }\r
        \r
        // Read keys A from file\r
+       size_t bytes_read;\r
        for (sectorNo=0; sectorNo<numSectors; sectorNo++) {\r
-               if (fread( keyA[sectorNo], 1, 6, fin ) == 0) {\r
+               bytes_read = fread( keyA[sectorNo], 1, 6, fin );\r
+               if ( bytes_read == 0) {\r
                        PrintAndLog("File reading error.");\r
                        fclose(fin);\r
                        return 2;\r
@@ -322,7 +325,8 @@ int CmdHF14AMfDump(const char *Cmd)
        \r
        // Read keys B from file\r
        for (sectorNo=0; sectorNo<numSectors; sectorNo++) {\r
-               if (fread( keyB[sectorNo], 1, 6, fin ) == 0) {\r
+               bytes_read = fread( keyB[sectorNo], 1, 6, fin );\r
+               if ( bytes_read == 0) {\r
                        PrintAndLog("File reading error.");\r
                        fclose(fin);\r
                        return 2;\r
@@ -479,8 +483,10 @@ int CmdHF14AMfRestore(const char *Cmd)
                return 1;\r
        }\r
        \r
+       size_t bytes_read;\r
        for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {\r
-               if (fread(keyA[sectorNo], 1, 6, fkeys) == 0) {\r
+               bytes_read = fread( keyA[sectorNo], 1, 6, fkeys );\r
+               if ( bytes_read == 0) {\r
                        PrintAndLog("File reading error (dumpkeys.bin).");\r
                        fclose(fkeys);\r
                        return 2;\r
@@ -488,7 +494,8 @@ int CmdHF14AMfRestore(const char *Cmd)
        }\r
 \r
        for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {\r
-               if (fread(keyB[sectorNo], 1, 6, fkeys) == 0) {\r
+               bytes_read = fread( keyB[sectorNo], 1, 6, fkeys );\r
+               if ( bytes_read == 0) {\r
                        PrintAndLog("File reading error (dumpkeys.bin).");\r
                        fclose(fkeys);\r
                        return 2;\r
@@ -506,9 +513,9 @@ int CmdHF14AMfRestore(const char *Cmd)
        for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {\r
                for(blockNo = 0; blockNo < NumBlocksPerSector(sectorNo); blockNo++) {\r
                        UsbCommand c = {CMD_MIFARE_WRITEBL, {FirstBlockOfSector(sectorNo) + blockNo, keyType, 0}};\r
-                       memcpy(c.d.asBytes, key, 6);\r
-                       \r
-                       if (fread(bldata, 1, 16, fdump) == 0) {\r
+                       memcpy(c.d.asBytes, key, 6);                    \r
+                       bytes_read = fread(bldata, 1, 16, fdump);\r
+                       if ( bytes_read == 0) {\r
                                PrintAndLog("File reading error (dumpdata.bin).");\r
                                fclose(fdump);\r
                                return 2;\r
@@ -669,7 +676,7 @@ int CmdHF14AMfNested(const char *Cmd)
                }\r
        }\r
        else { // ------------------------------------  multiple sectors working\r
-               clock_t time1 = clock();\r
+               clock_t t1 = clock();\r
 \r
                e_sector = calloc(SectorsCnt, sizeof(sector));\r
                if (e_sector == NULL) return 1;\r
@@ -770,7 +777,10 @@ int CmdHF14AMfNested(const char *Cmd)
                        }\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
+               t1 = clock() - t1;\r
+               if ( t1 > 0 ) {\r
+                       PrintAndLog("Time in nested: %f ticks %1.2f sec (%1.2f sec per key)\n\n", (float)t1, ((float)t1)/CLOCKS_PER_SEC, ((float)t1)/iterations/CLOCKS_PER_SEC);\r
+               }\r
                \r
                PrintAndLog("-----------------------------------------------\nIterations count: %d\n\n", iterations);\r
                //print them\r
@@ -1125,7 +1135,7 @@ int CmdHF14AMfChk(const char *Cmd)
                }\r
        }\r
        // time\r
-       clock_t time1 = clock();\r
+       clock_t t1 = clock();\r
                \r
        for ( int t = !keyType; t < 2; keyType==2?(t++):(t=2) ) {\r
                int b=blockNo;\r
@@ -1148,8 +1158,10 @@ 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
+       t1 = clock() - t1;\r
+       if ( t1 > 0 ){\r
+               printf("Time in checkkeys: %f 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
        if (transferToEml) {\r
                uint8_t block[16];\r
Impressum, Datenschutz