]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
Provide msclock() as Milliseconds timer for performance measures (#231)
authorpwpiwi <pwpiwi@users.noreply.github.com>
Sun, 12 Mar 2017 14:06:27 +0000 (15:06 +0100)
committerGitHub <noreply@github.com>
Sun, 12 Mar 2017 14:06:27 +0000 (15:06 +0100)
- don't use clock(). It has different functionalities in Windows and Linux
- move sleep functions to util.h

29 files changed:
client/Makefile
client/cmdcrc.c
client/cmdhf.c
client/cmdhf14a.c
client/cmdhf14a.h
client/cmdhfepa.c
client/cmdhfmf.c
client/cmdhfmfu.c
client/cmdlfawid.c
client/cmdlfem4x.c
client/cmdlfhitag.c
client/cmdlfpresco.c
client/cmdlfpyramid.c
client/cmdlft55xx.c
client/cmdmain.c
client/flash.c
client/flasher.c
client/hid-flasher/flash.c
client/hid-flasher/flasher.c
client/hid-flasher/proxusb.c
client/loclass/elite_crack.c
client/nonce2key/nonce2key.c
client/proxmark3.c
client/sleep.c [deleted file]
client/sleep.h [deleted file]
client/snooper.c
client/ui.c
client/util.c
client/util.h

index 9d650c9f8a8c4db603682cf3a969ca7eef7afd02..79e0cc31d3a05c016c322c8135fb91949c4db33b 100644 (file)
@@ -54,7 +54,6 @@ endif
 
 CORESRCS =     uart.c \
                util.c \
 
 CORESRCS =     uart.c \
                util.c \
-               sleep.c
 
 
 CMDSRCS =      crapto1/crapto1.c\
 
 
 CMDSRCS =      crapto1/crapto1.c\
index fddf0ac4d53283253bab7a50554485f22a8f1e89..01f65f553930c2a0a5859c69e6fadfd627ea7a3f 100644 (file)
@@ -8,7 +8,6 @@
 // CRC Calculations from the software reveng commands
 //-----------------------------------------------------------------------------
 
 // CRC Calculations from the software reveng commands
 //-----------------------------------------------------------------------------
 
-#include <stdlib.h>
 #ifdef _WIN32
 #  include <io.h>
 #  include <fcntl.h>
 #ifdef _WIN32
 #  include <io.h>
 #  include <fcntl.h>
@@ -19,8 +18,8 @@
 
 #include <stdio.h>
 #include <string.h>
 
 #include <stdio.h>
 #include <string.h>
-//#include <stdlib.h>
-//#include <ctype.h>
+#include <stdlib.h>
+#include <ctype.h>
 #include "cmdmain.h"
 #include "cmdcrc.h"
 #include "reveng/reveng.h"
 #include "cmdmain.h"
 #include "cmdcrc.h"
 #include "reveng/reveng.h"
index 17353fb66288ad6d61e4b7b8d68a1e88a7de8f35..cb71b93b4f568367bfce75eba6fa8fd21fe8e6b0 100644 (file)
@@ -8,10 +8,12 @@
 // High frequency commands
 //-----------------------------------------------------------------------------
 
 // High frequency commands
 //-----------------------------------------------------------------------------
 
+#include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include "proxmark3.h"
 #include "util.h"
 #include <stdio.h>
 #include <string.h>
 #include "proxmark3.h"
 #include "util.h"
+#include "data.h"
 #include "ui.h"
 #include "iso14443crc.h"
 #include "cmdmain.h"
 #include "ui.h"
 #include "iso14443crc.h"
 #include "cmdmain.h"
index 3dc501d479f6baa9314e3765afa1f3a253d2a759..812db8ee0d85506630119de580162e2e4884dae4 100644 (file)
@@ -431,7 +431,7 @@ int CmdHF14ACUIDs(const char *Cmd)
        n = n > 0 ? n : 1;
 
        PrintAndLog("Collecting %d UIDs", n);
        n = n > 0 ? n : 1;
 
        PrintAndLog("Collecting %d UIDs", n);
-       PrintAndLog("Start: %u", time(NULL));
+       PrintAndLog("Start: %" PRIu64, msclock()/1000);
        // repeat n times
        for (int i = 0; i < n; i++) {
                // execute anticollision procedure
        // repeat n times
        for (int i = 0; i < n; i++) {
                // execute anticollision procedure
@@ -454,7 +454,7 @@ int CmdHF14ACUIDs(const char *Cmd)
                        PrintAndLog("%s", uid_string);
                }
        }
                        PrintAndLog("%s", uid_string);
                }
        }
-       PrintAndLog("End: %u", time(NULL));
+       PrintAndLog("End: %" PRIu64, msclock()/1000);
 
        return 1;
 }
 
        return 1;
 }
index aa35dec6d18d7718ed6a1d2c3cbdb8368747f78e..dfdf1f4ab6092600bd1a671959f14ee6412fc094 100644 (file)
 #ifndef CMDHF14A_H__
 #define CMDHF14A_H__
 
 #ifndef CMDHF14A_H__
 #define CMDHF14A_H__
 
-int CmdHF14A(const char *Cmd);
+#include <stdint.h>
 
 
+int CmdHF14A(const char *Cmd);
 int CmdHF14AList(const char *Cmd);
 int CmdHF14AMifare(const char *Cmd);
 int CmdHF14AReader(const char *Cmd);
 int CmdHF14ASim(const char *Cmd);
 int CmdHF14ASnoop(const char *Cmd);
 int CmdHF14AList(const char *Cmd);
 int CmdHF14AMifare(const char *Cmd);
 int CmdHF14AReader(const char *Cmd);
 int CmdHF14ASim(const char *Cmd);
 int CmdHF14ASnoop(const char *Cmd);
-
 char* getTagInfo(uint8_t uid);
 char* getTagInfo(uint8_t uid);
+
 #endif
 #endif
index e50ce7082f9c2f973f72fee21e3e5d2b22966c01..786d0da1831a89e2bed31185ede8768955ae0c1e 100644 (file)
@@ -8,15 +8,19 @@
 // Commands related to the German electronic Identification Card
 //-----------------------------------------------------------------------------
 
 // Commands related to the German electronic Identification Card
 //-----------------------------------------------------------------------------
 
-#include "util.h"
+#include "cmdhfepa.h"
 
 
+#include <inttypes.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
+#include "util.h"
 #include "proxmark3.h"
 #include "ui.h"
 #include "cmdparser.h"
 #include "common.h"
 #include "cmdmain.h"
 #include "proxmark3.h"
 #include "ui.h"
 #include "cmdparser.h"
 #include "common.h"
 #include "cmdmain.h"
-#include "sleep.h"
-#include "cmdhfepa.h"
 
 static int CmdHelp(const char *Cmd);
 
 
 static int CmdHelp(const char *Cmd);
 
@@ -37,7 +41,7 @@ int CmdHFEPACollectPACENonces(const char *Cmd)
        n = n > 0 ? n : 1;
 
        PrintAndLog("Collecting %u %u-byte nonces", n, m);
        n = n > 0 ? n : 1;
 
        PrintAndLog("Collecting %u %u-byte nonces", n, m);
-       PrintAndLog("Start: %u", time(NULL));
+       PrintAndLog("Start: %" PRIu64 , msclock()/1000);
        // repeat n times
        for (unsigned int i = 0; i < n; i++) {
                // execute PACE
        // repeat n times
        for (unsigned int i = 0; i < n; i++) {
                // execute PACE
@@ -64,7 +68,7 @@ int CmdHFEPACollectPACENonces(const char *Cmd)
                        sleep(d);
                }
        }
                        sleep(d);
                }
        }
-       PrintAndLog("End: %u", time(NULL));
+       PrintAndLog("End: %" PRIu64, msclock()/1000);
 
        return 1;
 }
 
        return 1;
 }
index eb3dc878f15adc79fcd3349d96ef00824b2e0916..b3f7acb2a1e1d0f12a16e2dd7341fdfc172e4d7e 100644 (file)
@@ -9,8 +9,10 @@
 //-----------------------------------------------------------------------------\r
 \r
 #include <inttypes.h>\r
 //-----------------------------------------------------------------------------\r
 \r
 #include <inttypes.h>\r
+#include <string.h>\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
+#include <ctype.h>\r
 #include "proxmark3.h"\r
 #include "cmdmain.h"\r
 #include "util.h"\r
 #include "proxmark3.h"\r
 #include "cmdmain.h"\r
 #include "util.h"\r
@@ -688,8 +690,8 @@ int CmdHF14AMfNested(const char *Cmd)
                }\r
        }\r
        else { // ------------------------------------  multiple sectors working\r
                }\r
        }\r
        else { // ------------------------------------  multiple sectors working\r
-               clock_t time1;\r
-               time1 = clock();\r
+               uint64_t msclock1;\r
+               msclock1 = msclock();\r
 \r
                e_sector = calloc(SectorsCnt, sizeof(sector_t));\r
                if (e_sector == NULL) return 1;\r
 \r
                e_sector = calloc(SectorsCnt, sizeof(sector_t));\r
                if (e_sector == NULL) return 1;\r
@@ -759,7 +761,7 @@ int CmdHF14AMfNested(const char *Cmd)
                        }\r
                }\r
 \r
                        }\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
+               printf("Time in nested: %1.3f (%1.3f sec per key)\n\n", ((float)(msclock() - msclock1))/1000.0, ((float)(msclock() - msclock1))/iterations/1000.0);\r
                \r
                PrintAndLog("-----------------------------------------------\nIterations count: %d\n\n", iterations);\r
                //print them\r
                \r
                PrintAndLog("-----------------------------------------------\nIterations count: %d\n\n", iterations);\r
                //print them\r
index b3912023a2a769ace2926376894ba93020218873..ed8c588d3e4750a9c3edf0aee508799a665324d5 100644 (file)
@@ -8,12 +8,15 @@
 // High frequency MIFARE ULTRALIGHT (C) commands
 //-----------------------------------------------------------------------------
 
 // High frequency MIFARE ULTRALIGHT (C) commands
 //-----------------------------------------------------------------------------
 
+#include "cmdhfmfu.h"
+
+#include <stdint.h>
+#include <stdio.h>
 #include "proxmark3.h"
 #include "usb_cmd.h"
 #include "cmdmain.h"
 #include "ui.h"
 #include "loclass/des.h"
 #include "proxmark3.h"
 #include "usb_cmd.h"
 #include "cmdmain.h"
 #include "ui.h"
 #include "loclass/des.h"
-#include "cmdhfmfu.h"
 #include "cmdhfmf.h"
 #include "cmdhf14a.h"
 #include "mifare.h"
 #include "cmdhfmf.h"
 #include "cmdhf14a.h"
 #include "mifare.h"
index 1ace6bea23a0efb22db405842b1fda691a2c100f..8843e9e0cf6de146e8e605bebfee01fa3766113a 100644 (file)
@@ -10,6 +10,7 @@
 // Low frequency AWID26 commands
 //-----------------------------------------------------------------------------
 
 // Low frequency AWID26 commands
 //-----------------------------------------------------------------------------
 
+#include <string.h>
 #include <stdio.h>      // sscanf
 #include "proxmark3.h"  // Definitions, USB controls, etc
 #include "ui.h"         // PrintAndLog
 #include <stdio.h>      // sscanf
 #include "proxmark3.h"  // Definitions, USB controls, etc
 #include "ui.h"         // PrintAndLog
index f9103126ea99863931b8b943e8ea0dbafef4acfd..d2ccfae8ef05768320979b3ea0e4730d1f51f73a 100644 (file)
@@ -14,6 +14,7 @@
 #include "proxmark3.h"
 #include "ui.h"
 #include "util.h"
 #include "proxmark3.h"
 #include "ui.h"
 #include "util.h"
+#include "data.h"
 #include "graph.h"
 #include "cmdparser.h"
 #include "cmddata.h"
 #include "graph.h"
 #include "cmdparser.h"
 #include "cmddata.h"
index ad8fd33bf4886077b1b43ee62009e08e58af697c..47a85a1afcab361c025eb71a92906655c33d8205 100644 (file)
@@ -19,7 +19,6 @@
 #include "util.h"
 #include "hitag2.h"
 #include "hitagS.h"
 #include "util.h"
 #include "hitag2.h"
 #include "hitagS.h"
-#include "sleep.h"
 #include "cmdmain.h"
 
 static int CmdHelp(const char *Cmd);
 #include "cmdmain.h"
 
 static int CmdHelp(const char *Cmd);
index c6dbd7561f42a6ed307ab4ff36e74182be63ad6b..8bb341496b39e2062c3d7063aa3fb5a19c574618 100644 (file)
@@ -8,6 +8,7 @@
 //-----------------------------------------------------------------------------
 #include <string.h>
 #include <inttypes.h>
 //-----------------------------------------------------------------------------
 #include <string.h>
 #include <inttypes.h>
+#include <stdio.h>
 #include "cmdlfpresco.h"
 #include "proxmark3.h"
 #include "ui.h"
 #include "cmdlfpresco.h"
 #include "proxmark3.h"
 #include "ui.h"
index 7c19fbdba3971b6be18b9a19bc126c621ccc84c7..2494f2655529b72aee15378caee412e3c5349435 100644 (file)
@@ -8,6 +8,7 @@
 //-----------------------------------------------------------------------------
 #include <string.h>
 #include <inttypes.h>
 //-----------------------------------------------------------------------------
 #include <string.h>
 #include <inttypes.h>
+#include <stdio.h>
 #include "cmdlfpyramid.h"
 #include "proxmark3.h"
 #include "ui.h"
 #include "cmdlfpyramid.h"
 #include "proxmark3.h"
 #include "ui.h"
index 27c84efa536efc80dbcd95c35ac03f0e57ef266e..b287ce28efec268a710783ee506e159d8d8c7273 100644 (file)
@@ -10,6 +10,8 @@
 #include <stdio.h>\r
 #include <string.h>\r
 #include <inttypes.h>\r
 #include <stdio.h>\r
 #include <string.h>\r
 #include <inttypes.h>\r
+#include <ctype.h>\r
+#include <time.h>\r
 #include "proxmark3.h"\r
 #include "ui.h"\r
 #include "graph.h"\r
 #include "proxmark3.h"\r
 #include "ui.h"\r
 #include "graph.h"\r
index 843f9301dc0b554e39f5327ededdf5729e3f67f7..44c11aeb7965d065992f0a6417c6fe73c0c84d47 100644 (file)
@@ -12,7 +12,6 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
-#include "sleep.h"
 #include "cmdparser.h"
 #include "proxmark3.h"
 #include "data.h"
 #include "cmdparser.h"
 #include "proxmark3.h"
 #include "data.h"
index c840c92215224192624f3fe6f51971c0e97f8eb0..0b940e99df6bbf687f1cd3d9acf693a3ccc376a5 100644 (file)
@@ -12,8 +12,9 @@
 #include <string.h>
 #include <stdlib.h>
 #include <inttypes.h>
 #include <string.h>
 #include <stdlib.h>
 #include <inttypes.h>
+#include <unistd.h>
 #include "proxmark3.h"
 #include "proxmark3.h"
-#include "sleep.h"
+#include "util.h"
 #include "flash.h"
 #include "elf.h"
 #include "proxendian.h"
 #include "flash.h"
 #include "elf.h"
 #include "proxendian.h"
index d6d37706cf3b5b4d367664427cb93a4d6df94277..0c1dbd71f1794a1fe4a6a33f2792f057878b5363 100644 (file)
@@ -10,8 +10,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <inttypes.h>
 #include <stdlib.h>
 #include <string.h>
 #include <inttypes.h>
-#include "sleep.h"
 #include "proxmark3.h"
 #include "proxmark3.h"
+#include "util.h"
 #include "flash.h"
 #include "uart.h"
 #include "usb_cmd.h"
 #include "flash.h"
 #include "uart.h"
 #include "usb_cmd.h"
index 6670d637dca187bff1c7944961dbe20101198620..da0a17b619afee364b19fc42a4320e5b181b0790 100644 (file)
@@ -11,7 +11,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include "sleep.h"
 #include "proxusb.h"
 #include "flash.h"
 #include "elf.h"
 #include "proxusb.h"
 #include "flash.h"
 #include "elf.h"
index a4a0e85e7c73254e360fef2add6a1420aa652f12..2f0c20072d925389d2365923dc9082597cc19bc0 100644 (file)
@@ -9,7 +9,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "sleep.h"
 #include "proxusb.h"
 #include "flash.h"
 
 #include "proxusb.h"
 #include "flash.h"
 
index 3c2b20b4c13fdf6ffc182ff24a0a155b2dd903f0..04dbb784b85ce9b3270a4aabaec31fa0c4a290de 100644 (file)
@@ -18,7 +18,6 @@
 #include <strings.h>
 #include <errno.h>
 
 #include <strings.h>
 #include <errno.h>
 
-#include "sleep.h"
 #include "proxusb.h"
 #include "proxmark3.h"
 #include "usb_cmd.h"
 #include "proxusb.h"
 #include "proxmark3.h"
 #include "usb_cmd.h"
index e9814e95e6d13604b98931f5e7aae6638addad17..e52c9a6a3fad585898843f91d17ba3017dceb36a 100644 (file)
@@ -40,7 +40,7 @@
 #include <stdbool.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdbool.h>
 #include <string.h>
 #include <stdio.h>
-#include <time.h>
+#include "util.h"
 #include "cipherutils.h"
 #include "cipher.h"
 #include "ikeys.h"
 #include "cipherutils.h"
 #include "cipher.h"
 #include "ikeys.h"
@@ -512,7 +512,7 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[])
        uint8_t i;
        int errors = 0;
        size_t itemsize = sizeof(dumpdata);
        uint8_t i;
        int errors = 0;
        size_t itemsize = sizeof(dumpdata);
-       clock_t t1 = clock();
+       uint64_t t1 = msclock();
 
        dumpdata* attack = (dumpdata* ) malloc(itemsize);
 
 
        dumpdata* attack = (dumpdata* ) malloc(itemsize);
 
@@ -522,9 +522,9 @@ int bruteforceDump(uint8_t dump[], size_t dumpsize, uint16_t keytable[])
                errors += bruteforceItem(*attack, keytable);
        }
        free(attack);
                errors += bruteforceItem(*attack, keytable);
        }
        free(attack);
-       t1 = clock() - t1;
-       float diff = ((float)t1 / CLOCKS_PER_SEC );
-       prnlog("\nPerformed full crack in %f seconds",diff);
+       t1 = msclock() - t1;
+       float diff = (float)t1 / 1000.0;
+       prnlog("\nPerformed full crack in %f seconds", diff);
 
        // Pick out the first 16 bytes of the keytable.
        // The keytable is now in 16-bit ints, where the upper 8 bits
 
        // Pick out the first 16 bytes of the keytable.
        // The keytable is now in 16-bit ints, where the upper 8 bits
index 5378c0466ae80685cdd6bc4352b1549c9da3f153..a6a482af5a831b95b7a0da94b01c3598386e1113 100644 (file)
 // MIFARE Darkside hack
 //-----------------------------------------------------------------------------
 
 // MIFARE Darkside hack
 //-----------------------------------------------------------------------------
 
-#include <inttypes.h>
-#include <time.h>
-
 #include "nonce2key.h"
 #include "nonce2key.h"
+
+#include <inttypes.h>
 #include "mifarehost.h"
 #include "ui.h"
 #include "util.h"
 #include "mifarehost.h"
 #include "ui.h"
 #include "util.h"
@@ -160,7 +159,7 @@ bool mfkey32(nonces_t data, uint64_t *outputkey) {
        uint32_t ar0_enc = data.ar;  // first encrypted reader response
        uint32_t nr1_enc = data.nr2; // second encrypted reader challenge
        uint32_t ar1_enc = data.ar2; // second encrypted reader response
        uint32_t ar0_enc = data.ar;  // first encrypted reader response
        uint32_t nr1_enc = data.nr2; // second encrypted reader challenge
        uint32_t ar1_enc = data.ar2; // second encrypted reader response
-       clock_t t1 = clock();
+       uint64_t t1 = msclock();
        bool isSuccess = false;
        uint8_t counter=0;
 
        bool isSuccess = false;
        uint8_t counter=0;
 
@@ -181,8 +180,8 @@ bool mfkey32(nonces_t data, uint64_t *outputkey) {
                }
        }
        isSuccess = (counter == 1);
                }
        }
        isSuccess = (counter == 1);
-       t1 = clock() - t1;
-       //if ( t1 > 0 ) PrintAndLog("Time in mfkey32: %.0f ticks \nFound %d possible keys", (float)t1, counter);
+       t1 = msclock() - t1;
+       //if ( t1 > 0 ) PrintAndLog("Time in mfkey32: %.1f seconds \nFound %d possible keys", (float)t1/1000.0, counter);
        *outputkey = ( isSuccess ) ? outkey : 0;
        crypto1_destroy(s);
        /* //un-comment to save all keys to a stats.txt file 
        *outputkey = ( isSuccess ) ? outkey : 0;
        crypto1_destroy(s);
        /* //un-comment to save all keys to a stats.txt file 
@@ -212,7 +211,7 @@ bool tryMfk32_moebius(nonces_t data, uint64_t *outputkey) {
        int counter = 0;
        
        //PrintAndLog("Enter mfkey32_moebius");
        int counter = 0;
        
        //PrintAndLog("Enter mfkey32_moebius");
-       clock_t t1 = clock();
+       uint64_t t1 = msclock();
 
        s = lfsr_recovery32(ar0_enc ^ prng_successor(nt0, 64), 0);
   
 
        s = lfsr_recovery32(ar0_enc ^ prng_successor(nt0, 64), 0);
   
@@ -233,8 +232,8 @@ bool tryMfk32_moebius(nonces_t data, uint64_t *outputkey) {
                }
        }
        isSuccess       = (counter == 1);
                }
        }
        isSuccess       = (counter == 1);
-       t1 = clock() - t1;
-       //if ( t1 > 0 ) PrintAndLog("Time in mfkey32_moebius: %.0f ticks \nFound %d possible keys", (float)t1,counter);
+       t1 = msclock() - t1;
+       //if ( t1 > 0 ) PrintAndLog("Time in mfkey32_moebius: %.1f seconds \nFound %d possible keys", (float)t1/1000.0, counter);
        *outputkey = ( isSuccess ) ? outkey : 0;
        crypto1_destroy(s);
        /* // un-comment to output all keys to stats.txt
        *outputkey = ( isSuccess ) ? outkey : 0;
        crypto1_destroy(s);
        /* // un-comment to output all keys to stats.txt
@@ -265,7 +264,7 @@ int tryMfk64(uint32_t uid, uint32_t nt, uint32_t nr_enc, uint32_t ar_enc, uint32
        struct Crypto1State *revstate;
        
        PrintAndLog("Enter mfkey64");
        struct Crypto1State *revstate;
        
        PrintAndLog("Enter mfkey64");
-       clock_t t1 = clock();
+       uint64_t t1 = msclock();
        
        // Extract the keystream from the messages
        ks2 = ar_enc ^ prng_successor(nt, 64);
        
        // Extract the keystream from the messages
        ks2 = ar_enc ^ prng_successor(nt, 64);
@@ -280,8 +279,8 @@ int tryMfk64(uint32_t uid, uint32_t nt, uint32_t nr_enc, uint32_t ar_enc, uint32
        crypto1_destroy(revstate);
        *outputkey = key;
        
        crypto1_destroy(revstate);
        *outputkey = key;
        
-       t1 = clock() - t1;
-       if ( t1 > 0 ) PrintAndLog("Time in mfkey64: %.0f ticks \n", (float)t1);
+       t1 = msclock() - t1;
+       if ( t1 > 0 ) PrintAndLog("Time in mfkey64: %.1f seconds \n", (float)t1/1000.0);
        return 0;
 }
 
        return 0;
 }
 
index ba8c7205287d877e406fd97197258bb35461cde7..2ed127a4f934d2eb736c567af1de07d3d1e77af5 100644 (file)
@@ -22,7 +22,6 @@
 #include "cmdmain.h"
 #include "uart.h"
 #include "ui.h"
 #include "cmdmain.h"
 #include "uart.h"
 #include "ui.h"
-#include "sleep.h"
 #include "cmdparser.h"
 #include "cmdhw.h"
 #include "whereami.h"
 #include "cmdparser.h"
 #include "cmdhw.h"
 #include "whereami.h"
diff --git a/client/sleep.c b/client/sleep.c
deleted file mode 100644 (file)
index fe397da..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-//-----------------------------------------------------------------------------
-// Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
-//
-// This code is licensed to you under the terms of the GNU GPL, version 2 or,
-// at your option, any later version. See the LICENSE.txt file for the text of
-// the license.
-//-----------------------------------------------------------------------------
-// platform-independant sleep macros
-//-----------------------------------------------------------------------------
-
-#ifndef _WIN32
-
-#define _POSIX_C_SOURCE        199309L
-#include "sleep.h"
-#include <time.h>
-#include <stdio.h>
-#include <sys/time.h>
-#include <errno.h>
-
-void nsleep(uint64_t n) {
-  struct timespec timeout;
-  timeout.tv_sec = n/1000000000;
-  timeout.tv_nsec = n%1000000000;
-  while (nanosleep(&timeout, &timeout) && errno == EINTR);
-}
-
-#endif // _WIN32
-
diff --git a/client/sleep.h b/client/sleep.h
deleted file mode 100644 (file)
index 81e1dea..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-//-----------------------------------------------------------------------------
-// Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
-//
-// This code is licensed to you under the terms of the GNU GPL, version 2 or,
-// at your option, any later version. See the LICENSE.txt file for the text of
-// the license.
-//-----------------------------------------------------------------------------
-// platform-independant sleep macros
-//-----------------------------------------------------------------------------
-
-#ifndef SLEEP_H__
-#define SLEEP_H__
-
-#ifdef _WIN32
-# include <windows.h>
-# define sleep(n) Sleep(1000 * n)
-# define msleep(n) Sleep(n)
-#else
-# include <inttypes.h>
-# include <unistd.h>
-  void nsleep(uint64_t n);
-# define msleep(n) nsleep(1000000 * n)
-# define usleep(n) nsleep(1000 * n)
-#endif // _WIN32
-
-#endif // SLEEP_H__
-
index 30d39de6628a34f1fb8fe3efb73fd28a0046810c..14f0706314d253008a2949a61f57ac01993fe9ea 100644 (file)
@@ -8,7 +8,6 @@
 // Snooper binary
 //-----------------------------------------------------------------------------
 
 // Snooper binary
 //-----------------------------------------------------------------------------
 
-#include "sleep.h"
 #include "ui.h"
 #include "proxusb.h"
 #include "cmdmain.h"
 #include "ui.h"
 #include "proxusb.h"
 #include "cmdmain.h"
index ba230e3316fa70a35f0d7bc5cbd8a129c4422927..5902cb89923f980a0318b4819aac17ec4831b40c 100644 (file)
@@ -12,7 +12,6 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include <time.h>
 #include <readline/readline.h>
 #include <pthread.h>
 
 #include <readline/readline.h>
 #include <pthread.h>
 
@@ -34,7 +33,7 @@ void PrintAndLog(char *fmt, ...)
        static FILE *logfile = NULL;
        static int logging=1;
 
        static FILE *logfile = NULL;
        static int logging=1;
 
-       // lock this section to avoid interlacing prints from different threats
+       // lock this section to avoid interlacing prints from different threads
        pthread_mutex_lock(&print_lock);
   
        if (logging && !logfile) {
        pthread_mutex_lock(&print_lock);
   
        if (logging && !logfile) {
index e80f5cc9d59efeb7fe1cabee909db4bcb49ed1d5..81b2d844f4376bdda269f6e3850a5c9925915216 100644 (file)
@@ -8,15 +8,26 @@
 // utilities
 //-----------------------------------------------------------------------------
 
 // utilities
 //-----------------------------------------------------------------------------
 
-#include <ctype.h>
+#if !defined(_WIN32)
+#define _POSIX_C_SOURCE        199309L                 // need nanosleep()
+#endif
+
 #include "util.h"
 #include "util.h"
+
+#include <stdint.h>
+#include <string.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include "data.h"
+
 #define MAX_BIN_BREAK_LENGTH   (3072+384+1)
 
 #ifndef _WIN32
 #include <termios.h>
 #include <sys/ioctl.h> 
 
 #define MAX_BIN_BREAK_LENGTH   (3072+384+1)
 
 #ifndef _WIN32
 #include <termios.h>
 #include <sys/ioctl.h> 
 
-
 int ukbhit(void)
 {
   int cnt = 0;
 int ukbhit(void)
 {
   int cnt = 0;
@@ -42,6 +53,7 @@ int ukbhit(void)
 }
 
 #else
 }
 
 #else
+
 #include <conio.h>
 int ukbhit(void) {
        return kbhit();
 #include <conio.h>
 int ukbhit(void) {
        return kbhit();
@@ -591,3 +603,38 @@ void clean_ascii(unsigned char *buf, size_t len) {
       buf[i] = '.';
   }
 }
       buf[i] = '.';
   }
 }
+
+
+// Timer functions
+#if !defined (_WIN32)
+#include <errno.h>
+
+static void nsleep(uint64_t n) {
+  struct timespec timeout;
+  timeout.tv_sec = n/1000000000;
+  timeout.tv_nsec = n%1000000000;
+  while (nanosleep(&timeout, &timeout) && errno == EINTR);
+}
+
+void msleep(uint32_t n) {
+       nsleep(1000000 * n);
+}
+
+#endif // _WIN32
+
+// a milliseconds timer for performance measurement
+uint64_t msclock() {
+#if defined(_WIN32)
+#include <sys/types.h>
+       struct _timeb t;
+       if (_ftime_s(&t)) {
+               return 0;
+       } else {
+               return 1000 * t.time + t.millitm;
+       }
+#else
+       struct timespec t;
+       clock_gettime(CLOCK_MONOTONIC, &t);
+       return (t.tv_sec * 1000 + t.tv_nsec / 1000000);
+#endif
+}
index 7d9943f0616aa333ff0810ed0666219a74a1c710..1739498eeaf8d4ab4844951ecb332d64f90f10a9 100644 (file)
@@ -8,13 +8,11 @@
 // utilities
 //-----------------------------------------------------------------------------
 
 // utilities
 //-----------------------------------------------------------------------------
 
-#include <stdio.h>
-#include <stdint.h>  //included in data.h
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <time.h>    //time, gmtime
-#include "data.h"    //for FILE_PATH_SIZE
+#ifndef UTIL_H__
+#define UTIL_H__
+
+#include <stdint.h>
+#include <stddef.h>
 
 #ifndef ROTR
 # define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n))))
 
 #ifndef ROTR
 # define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n))))
 #ifndef MAX
 # define MAX(a, b) (((a) > (b)) ? (a) : (b))
 #endif
 #ifndef MAX
 # define MAX(a, b) (((a) > (b)) ? (a) : (b))
 #endif
+
 #define EVEN                        0
 #define ODD                         1
 
 #define EVEN                        0
 #define ODD                         1
 
-int ukbhit(void);
+extern int ukbhit(void);
+
+extern void AddLogLine(char *fileName, char *extData, char *c);
+extern void AddLogHex(char *fileName, char *extData, const uint8_t * data, const size_t len);
+extern void AddLogUint64(char *fileName, char *extData, const uint64_t data);
+extern void AddLogCurrentDT(char *fileName);
+extern void FillFileNameByUID(char *fileName, uint8_t * uid, char *ext, int byteCount);
+
+extern void print_hex(const uint8_t * data, const size_t len);
+extern char *sprint_hex(const uint8_t * data, const size_t len);
+extern char *sprint_bin(const uint8_t * data, const size_t len);
+extern char *sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t breaks);
+extern char *sprint_hex_ascii(const uint8_t *data, const size_t len);
+extern char *sprint_ascii(const uint8_t *data, const size_t len);
+
+extern void num_to_bytes(uint64_t n, size_t len, uint8_t* dest);
+extern uint64_t bytes_to_num(uint8_t* src, size_t len);
+extern void num_to_bytebits(uint64_t   n, size_t len, uint8_t *dest);
+extern void num_to_bytebitsLSBF(uint64_t n, size_t len, uint8_t *dest);
+extern char *printBits(size_t const size, void const * const ptr);
+extern uint8_t *SwapEndian64(const uint8_t *src, const size_t len, const uint8_t blockSize);
+extern void SwapEndian64ex(const uint8_t *src, const size_t len, const uint8_t blockSize, uint8_t *dest);
 
 
-void AddLogLine(char *fileName, char *extData, char *c);
-void AddLogHex(char *fileName, char *extData, const uint8_t * data, const size_t len);
-void AddLogUint64(char *fileName, char *extData, const uint64_t data);
-void AddLogCurrentDT(char *fileName);
-void FillFileNameByUID(char *fileName, uint8_t * uid, char *ext, int byteCount);
+extern char param_getchar(const char *line, int paramnum);
+extern int param_getptr(const char *line, int *bg, int *en, int paramnum);
+extern uint8_t param_get8(const char *line, int paramnum);
+extern uint8_t param_get8ex(const char *line, int paramnum, int deflt, int base);
+extern uint32_t param_get32ex(const char *line, int paramnum, int deflt, int base);
+extern uint64_t param_get64ex(const char *line, int paramnum, int deflt, int base);
+extern uint8_t param_getdec(const char *line, int paramnum, uint8_t *destination);
+extern uint8_t param_isdec(const char *line, int paramnum);
+extern int param_gethex(const char *line, int paramnum, uint8_t * data, int hexcnt);
+extern int param_gethex_ex(const char *line, int paramnum, uint8_t * data, int *hexcnt);
+extern int param_getstr(const char *line, int paramnum, char * str);
 
 
-void print_hex(const uint8_t * data, const size_t len);
-char * sprint_hex(const uint8_t * data, const size_t len);
-char * sprint_bin(const uint8_t * data, const size_t len);
-char * sprint_bin_break(const uint8_t *data, const size_t len, const uint8_t breaks);
-char * sprint_hex_ascii(const uint8_t *data, const size_t len);
-char * sprint_ascii(const uint8_t *data, const size_t len);
+extern int hextobinarray( char *target,  char *source);
+extern int hextobinstring( char *target,  char *source);
+extern int binarraytohex( char *target,  char *source,  int length);
+extern void binarraytobinstring(char *target,  char *source,  int length);
+extern uint8_t GetParity( uint8_t *string, uint8_t type,  int length);
+extern void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length);
 
 
-void num_to_bytes(uint64_t n, size_t len, uint8_t* dest);
-uint64_t bytes_to_num(uint8_t* src, size_t len);
-void num_to_bytebits(uint64_t  n, size_t len, uint8_t *dest);
-void num_to_bytebitsLSBF(uint64_t n, size_t len, uint8_t *dest);
-char * printBits(size_t const size, void const * const ptr);
-uint8_t *SwapEndian64(const uint8_t *src, const size_t len, const uint8_t blockSize);
-void SwapEndian64ex(const uint8_t *src, const size_t len, const uint8_t blockSize, uint8_t *dest);
+extern void xor(unsigned char *dst, unsigned char *src, size_t len);
+extern int32_t le24toh(uint8_t data[3]);
+extern uint32_t le32toh (uint8_t *data);
+extern void rol(uint8_t *data, const size_t len);
 
 
-char param_getchar(const char *line, int paramnum);
-int param_getptr(const char *line, int *bg, int *en, int paramnum);
-uint8_t param_get8(const char *line, int paramnum);
-uint8_t param_get8ex(const char *line, int paramnum, int deflt, int base);
-uint32_t param_get32ex(const char *line, int paramnum, int deflt, int base);
-uint64_t param_get64ex(const char *line, int paramnum, int deflt, int base);
-uint8_t param_getdec(const char *line, int paramnum, uint8_t *destination);
-uint8_t param_isdec(const char *line, int paramnum);
-int param_gethex(const char *line, int paramnum, uint8_t * data, int hexcnt);
-int param_gethex_ex(const char *line, int paramnum, uint8_t * data, int *hexcnt);
-int param_getstr(const char *line, int paramnum, char * str);
+extern void clean_ascii(unsigned char *buf, size_t len);
 
 
- int hextobinarray( char *target,  char *source);
- int hextobinstring( char *target,  char *source);
- int binarraytohex( char *target,  char *source,  int length);
-void binarraytobinstring(char *target,  char *source,  int length);
-uint8_t GetParity( uint8_t *string, uint8_t type,  int length);
-void wiegand_add_parity(uint8_t *target, uint8_t *source, uint8_t length);
+// timer functions/macros
+#ifdef _WIN32
+# include <windows.h>
+# define sleep(n) Sleep(1000 *(n))
+# define msleep(n) Sleep((n))
+#else
+extern void msleep(uint32_t n);                // sleep n milliseconds
+#endif // _WIN32
 
 
-void xor(unsigned char *dst, unsigned char *src, size_t len);
-int32_t le24toh(uint8_t data[3]);
-uint32_t le32toh (uint8_t *data);
-void rol(uint8_t *data, const size_t len);
+extern uint64_t msclock();                     // a milliseconds clock
 
 
-void clean_ascii(unsigned char *buf, size_t len);
+#endif // UTIL_H__
Impressum, Datenschutz