From acf0582d5324f70bfda5d180e6533e4d572e695b Mon Sep 17 00:00:00 2001 From: pwpiwi Date: Sun, 12 Mar 2017 15:06:27 +0100 Subject: [PATCH] Provide msclock() as Milliseconds timer for performance measures (#231) - don't use clock(). It has different functionalities in Windows and Linux - move sleep functions to util.h --- client/Makefile | 1 - client/cmdcrc.c | 5 +- client/cmdhf.c | 2 + client/cmdhf14a.c | 4 +- client/cmdhf14a.h | 5 +- client/cmdhfepa.c | 14 +++-- client/cmdhfmf.c | 8 ++- client/cmdhfmfu.c | 5 +- client/cmdlfawid.c | 1 + client/cmdlfem4x.c | 1 + client/cmdlfhitag.c | 1 - client/cmdlfpresco.c | 1 + client/cmdlfpyramid.c | 1 + client/cmdlft55xx.c | 2 + client/cmdmain.c | 1 - client/flash.c | 3 +- client/flasher.c | 2 +- client/hid-flasher/flash.c | 1 - client/hid-flasher/flasher.c | 1 - client/hid-flasher/proxusb.c | 1 - client/loclass/elite_crack.c | 10 ++-- client/nonce2key/nonce2key.c | 23 ++++---- client/proxmark3.c | 1 - client/sleep.c | 28 --------- client/sleep.h | 27 --------- client/snooper.c | 1 - client/ui.c | 3 +- client/util.c | 51 ++++++++++++++++- client/util.h | 108 +++++++++++++++++++---------------- 29 files changed, 162 insertions(+), 150 deletions(-) delete mode 100644 client/sleep.c delete mode 100644 client/sleep.h diff --git a/client/Makefile b/client/Makefile index 9d650c9f..79e0cc31 100644 --- a/client/Makefile +++ b/client/Makefile @@ -54,7 +54,6 @@ endif CORESRCS = uart.c \ util.c \ - sleep.c CMDSRCS = crapto1/crapto1.c\ diff --git a/client/cmdcrc.c b/client/cmdcrc.c index fddf0ac4..01f65f55 100644 --- a/client/cmdcrc.c +++ b/client/cmdcrc.c @@ -8,7 +8,6 @@ // CRC Calculations from the software reveng commands //----------------------------------------------------------------------------- -#include #ifdef _WIN32 # include # include @@ -19,8 +18,8 @@ #include #include -//#include -//#include +#include +#include #include "cmdmain.h" #include "cmdcrc.h" #include "reveng/reveng.h" diff --git a/client/cmdhf.c b/client/cmdhf.c index 17353fb6..cb71b93b 100644 --- a/client/cmdhf.c +++ b/client/cmdhf.c @@ -8,10 +8,12 @@ // High frequency commands //----------------------------------------------------------------------------- +#include #include #include #include "proxmark3.h" #include "util.h" +#include "data.h" #include "ui.h" #include "iso14443crc.h" #include "cmdmain.h" diff --git a/client/cmdhf14a.c b/client/cmdhf14a.c index 3dc501d4..812db8ee 100644 --- a/client/cmdhf14a.c +++ b/client/cmdhf14a.c @@ -431,7 +431,7 @@ int CmdHF14ACUIDs(const char *Cmd) 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 @@ -454,7 +454,7 @@ int CmdHF14ACUIDs(const char *Cmd) PrintAndLog("%s", uid_string); } } - PrintAndLog("End: %u", time(NULL)); + PrintAndLog("End: %" PRIu64, msclock()/1000); return 1; } diff --git a/client/cmdhf14a.h b/client/cmdhf14a.h index aa35dec6..dfdf1f4a 100644 --- a/client/cmdhf14a.h +++ b/client/cmdhf14a.h @@ -12,13 +12,14 @@ #ifndef CMDHF14A_H__ #define CMDHF14A_H__ -int CmdHF14A(const char *Cmd); +#include +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); - char* getTagInfo(uint8_t uid); + #endif diff --git a/client/cmdhfepa.c b/client/cmdhfepa.c index e50ce708..786d0da1 100644 --- a/client/cmdhfepa.c +++ b/client/cmdhfepa.c @@ -8,15 +8,19 @@ // Commands related to the German electronic Identification Card //----------------------------------------------------------------------------- -#include "util.h" +#include "cmdhfepa.h" +#include +#include +#include +#include +#include +#include "util.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); @@ -37,7 +41,7 @@ int CmdHFEPACollectPACENonces(const char *Cmd) 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 @@ -64,7 +68,7 @@ int CmdHFEPACollectPACENonces(const char *Cmd) sleep(d); } } - PrintAndLog("End: %u", time(NULL)); + PrintAndLog("End: %" PRIu64, msclock()/1000); return 1; } diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index eb3dc878..b3f7acb2 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -9,8 +9,10 @@ //----------------------------------------------------------------------------- #include +#include #include #include +#include #include "proxmark3.h" #include "cmdmain.h" #include "util.h" @@ -688,8 +690,8 @@ int CmdHF14AMfNested(const char *Cmd) } } else { // ------------------------------------ multiple sectors working - clock_t time1; - time1 = clock(); + uint64_t msclock1; + msclock1 = msclock(); e_sector = calloc(SectorsCnt, sizeof(sector_t)); if (e_sector == NULL) return 1; @@ -759,7 +761,7 @@ int CmdHF14AMfNested(const char *Cmd) } } - 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); + printf("Time in nested: %1.3f (%1.3f sec per key)\n\n", ((float)(msclock() - msclock1))/1000.0, ((float)(msclock() - msclock1))/iterations/1000.0); PrintAndLog("-----------------------------------------------\nIterations count: %d\n\n", iterations); //print them diff --git a/client/cmdhfmfu.c b/client/cmdhfmfu.c index b3912023..ed8c588d 100644 --- a/client/cmdhfmfu.c +++ b/client/cmdhfmfu.c @@ -8,12 +8,15 @@ // High frequency MIFARE ULTRALIGHT (C) commands //----------------------------------------------------------------------------- +#include "cmdhfmfu.h" + +#include +#include #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" diff --git a/client/cmdlfawid.c b/client/cmdlfawid.c index 1ace6bea..8843e9e0 100644 --- a/client/cmdlfawid.c +++ b/client/cmdlfawid.c @@ -10,6 +10,7 @@ // Low frequency AWID26 commands //----------------------------------------------------------------------------- +#include #include // sscanf #include "proxmark3.h" // Definitions, USB controls, etc #include "ui.h" // PrintAndLog diff --git a/client/cmdlfem4x.c b/client/cmdlfem4x.c index f9103126..d2ccfae8 100644 --- a/client/cmdlfem4x.c +++ b/client/cmdlfem4x.c @@ -14,6 +14,7 @@ #include "proxmark3.h" #include "ui.h" #include "util.h" +#include "data.h" #include "graph.h" #include "cmdparser.h" #include "cmddata.h" diff --git a/client/cmdlfhitag.c b/client/cmdlfhitag.c index ad8fd33b..47a85a1a 100644 --- a/client/cmdlfhitag.c +++ b/client/cmdlfhitag.c @@ -19,7 +19,6 @@ #include "util.h" #include "hitag2.h" #include "hitagS.h" -#include "sleep.h" #include "cmdmain.h" static int CmdHelp(const char *Cmd); diff --git a/client/cmdlfpresco.c b/client/cmdlfpresco.c index c6dbd756..8bb34149 100644 --- a/client/cmdlfpresco.c +++ b/client/cmdlfpresco.c @@ -8,6 +8,7 @@ //----------------------------------------------------------------------------- #include #include +#include #include "cmdlfpresco.h" #include "proxmark3.h" #include "ui.h" diff --git a/client/cmdlfpyramid.c b/client/cmdlfpyramid.c index 7c19fbdb..2494f265 100644 --- a/client/cmdlfpyramid.c +++ b/client/cmdlfpyramid.c @@ -8,6 +8,7 @@ //----------------------------------------------------------------------------- #include #include +#include #include "cmdlfpyramid.h" #include "proxmark3.h" #include "ui.h" diff --git a/client/cmdlft55xx.c b/client/cmdlft55xx.c index 27c84efa..b287ce28 100644 --- a/client/cmdlft55xx.c +++ b/client/cmdlft55xx.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include "proxmark3.h" #include "ui.h" #include "graph.h" diff --git a/client/cmdmain.c b/client/cmdmain.c index 843f9301..44c11aeb 100644 --- a/client/cmdmain.c +++ b/client/cmdmain.c @@ -12,7 +12,6 @@ #include #include #include -#include "sleep.h" #include "cmdparser.h" #include "proxmark3.h" #include "data.h" diff --git a/client/flash.c b/client/flash.c index c840c922..0b940e99 100644 --- a/client/flash.c +++ b/client/flash.c @@ -12,8 +12,9 @@ #include #include #include +#include #include "proxmark3.h" -#include "sleep.h" +#include "util.h" #include "flash.h" #include "elf.h" #include "proxendian.h" diff --git a/client/flasher.c b/client/flasher.c index d6d37706..0c1dbd71 100644 --- a/client/flasher.c +++ b/client/flasher.c @@ -10,8 +10,8 @@ #include #include #include -#include "sleep.h" #include "proxmark3.h" +#include "util.h" #include "flash.h" #include "uart.h" #include "usb_cmd.h" diff --git a/client/hid-flasher/flash.c b/client/hid-flasher/flash.c index 6670d637..da0a17b6 100644 --- a/client/hid-flasher/flash.c +++ b/client/hid-flasher/flash.c @@ -11,7 +11,6 @@ #include #include #include -#include "sleep.h" #include "proxusb.h" #include "flash.h" #include "elf.h" diff --git a/client/hid-flasher/flasher.c b/client/hid-flasher/flasher.c index a4a0e85e..2f0c2007 100644 --- a/client/hid-flasher/flasher.c +++ b/client/hid-flasher/flasher.c @@ -9,7 +9,6 @@ #include #include #include -#include "sleep.h" #include "proxusb.h" #include "flash.h" diff --git a/client/hid-flasher/proxusb.c b/client/hid-flasher/proxusb.c index 3c2b20b4..04dbb784 100644 --- a/client/hid-flasher/proxusb.c +++ b/client/hid-flasher/proxusb.c @@ -18,7 +18,6 @@ #include #include -#include "sleep.h" #include "proxusb.h" #include "proxmark3.h" #include "usb_cmd.h" diff --git a/client/loclass/elite_crack.c b/client/loclass/elite_crack.c index e9814e95..e52c9a6a 100644 --- a/client/loclass/elite_crack.c +++ b/client/loclass/elite_crack.c @@ -40,7 +40,7 @@ #include #include #include -#include +#include "util.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); - clock_t t1 = clock(); + uint64_t t1 = msclock(); 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); - 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 diff --git a/client/nonce2key/nonce2key.c b/client/nonce2key/nonce2key.c index 5378c046..a6a482af 100644 --- a/client/nonce2key/nonce2key.c +++ b/client/nonce2key/nonce2key.c @@ -10,10 +10,9 @@ // MIFARE Darkside hack //----------------------------------------------------------------------------- -#include -#include - #include "nonce2key.h" + +#include #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 - clock_t t1 = clock(); + uint64_t t1 = msclock(); bool isSuccess = false; uint8_t counter=0; @@ -181,8 +180,8 @@ bool mfkey32(nonces_t data, uint64_t *outputkey) { } } 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 @@ -212,7 +211,7 @@ bool tryMfk32_moebius(nonces_t data, uint64_t *outputkey) { 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); @@ -233,8 +232,8 @@ bool tryMfk32_moebius(nonces_t data, uint64_t *outputkey) { } } 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 @@ -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"); - clock_t t1 = clock(); + uint64_t t1 = msclock(); // 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; - 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; } diff --git a/client/proxmark3.c b/client/proxmark3.c index ba8c7205..2ed127a4 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -22,7 +22,6 @@ #include "cmdmain.h" #include "uart.h" #include "ui.h" -#include "sleep.h" #include "cmdparser.h" #include "cmdhw.h" #include "whereami.h" diff --git a/client/sleep.c b/client/sleep.c deleted file mode 100644 index fe397da9..00000000 --- a/client/sleep.c +++ /dev/null @@ -1,28 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (C) 2010 iZsh -// -// 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 -#include -#include -#include - -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 index 81e1dea0..00000000 --- a/client/sleep.h +++ /dev/null @@ -1,27 +0,0 @@ -//----------------------------------------------------------------------------- -// Copyright (C) 2010 iZsh -// -// 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 -# define sleep(n) Sleep(1000 * n) -# define msleep(n) Sleep(n) -#else -# include -# include - void nsleep(uint64_t n); -# define msleep(n) nsleep(1000000 * n) -# define usleep(n) nsleep(1000 * n) -#endif // _WIN32 - -#endif // SLEEP_H__ - diff --git a/client/snooper.c b/client/snooper.c index 30d39de6..14f07063 100644 --- a/client/snooper.c +++ b/client/snooper.c @@ -8,7 +8,6 @@ // Snooper binary //----------------------------------------------------------------------------- -#include "sleep.h" #include "ui.h" #include "proxusb.h" #include "cmdmain.h" diff --git a/client/ui.c b/client/ui.c index ba230e33..5902cb89 100644 --- a/client/ui.c +++ b/client/ui.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include @@ -34,7 +33,7 @@ void PrintAndLog(char *fmt, ...) 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) { diff --git a/client/util.c b/client/util.c index e80f5cc9..81b2d844 100644 --- a/client/util.c +++ b/client/util.c @@ -8,15 +8,26 @@ // utilities //----------------------------------------------------------------------------- -#include +#if !defined(_WIN32) +#define _POSIX_C_SOURCE 199309L // need nanosleep() +#endif + #include "util.h" + +#include +#include +#include +#include +#include +#include +#include "data.h" + #define MAX_BIN_BREAK_LENGTH (3072+384+1) #ifndef _WIN32 #include #include - int ukbhit(void) { int cnt = 0; @@ -42,6 +53,7 @@ int ukbhit(void) } #else + #include int ukbhit(void) { return kbhit(); @@ -591,3 +603,38 @@ void clean_ascii(unsigned char *buf, size_t len) { buf[i] = '.'; } } + + +// Timer functions +#if !defined (_WIN32) +#include + +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 + 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 +} diff --git a/client/util.h b/client/util.h index 7d9943f0..1739498e 100644 --- a/client/util.h +++ b/client/util.h @@ -8,13 +8,11 @@ // utilities //----------------------------------------------------------------------------- -#include -#include //included in data.h -#include -#include -#include -#include //time, gmtime -#include "data.h" //for FILE_PATH_SIZE +#ifndef UTIL_H__ +#define UTIL_H__ + +#include +#include #ifndef ROTR # define ROTR(x,n) (((uintmax_t)(x) >> (n)) | ((uintmax_t)(x) << ((sizeof(x) * 8) - (n)))) @@ -25,54 +23,68 @@ #ifndef MAX # define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif + #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 +# 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__ -- 2.39.2