From 02872796aae5256d5b07842bee3a8bbf346b8920 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 22 Apr 2024 09:26:25 +0200 Subject: [PATCH] should wait for a reply from device that sniffing is done --- CHANGELOG.md | 2 ++ client/src/cmdhfcryptorf.c | 2 ++ common/util_posix.c | 30 ++++++++++++++++++++++++++++-- common/util_posix.h | 6 +++--- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fb4060b8..4aa22f8a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] +- Addeded a micro second clock in the client (@iceman1001) +- Fix `hf mfdes read` - buffer overflow when reading large files (@iceman1001) - Changed `hf 15 csetuid` - now supports gen2 command (@iceman1001) - Changed `hf mfp info` - to identify Ev2 (@iceman1001) - Updated Graph Markers implementation to include temporary markers and marker labels (@HACKhalo2) diff --git a/client/src/cmdhfcryptorf.c b/client/src/cmdhfcryptorf.c index 909c5f110..8f765ed66 100644 --- a/client/src/cmdhfcryptorf.c +++ b/client/src/cmdhfcryptorf.c @@ -93,6 +93,8 @@ static int CmdHFCryptoRFSniff(const char *Cmd) { clearCommandBuffer(); SendCommandNG(CMD_HF_ISO14443B_SNIFF, NULL, 0); + PacketResponseNG resp; + WaitForResponse(CMD_HF_ISO14443B_SNIFF, &resp); PrintAndLogEx(HINT, "Try `" _YELLOW_("hf cryptorf list") "` to view captured tracelog"); PrintAndLogEx(HINT, "Try `" _YELLOW_("trace save -f hf_cryptorf_mytrace") "` to save tracelog for later analysing"); diff --git a/common/util_posix.c b/common/util_posix.c index f1764533d..4bc28f80f 100644 --- a/common/util_posix.c +++ b/common/util_posix.c @@ -18,7 +18,7 @@ // ensure availability even with -std=c99; must be included before #if !defined(_WIN32) -//#define _POSIX_C_SOURCE 199309L // need nanosleep() + #define _POSIX_C_SOURCE 200112L // need localtime_r() #else #include @@ -116,7 +116,6 @@ int _civet_safe_clock_gettime(int clk_id, struct timespec *t) { #endif - // a milliseconds timer for performance measurement uint64_t msclock(void) { #if defined(_WIN32) @@ -143,3 +142,30 @@ uint64_t msclock(void) { #endif } +// a micro seconds timer for performance measurement +uint64_t usclock(void) { +#if defined(_WIN32) +#include + + // WORKAROUND FOR MinGW (some versions - use if normal code does not compile) + // It has no _ftime_s and needs explicit inclusion of timeb.h +#include + struct _timeb t; + _ftime(&t); + return 1000 * (uint64_t)t.time + t.millitm; + +// NORMAL CODE (use _ftime_s) + //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 (1000 * (uint64_t)t.tv_sec + t.tv_nsec / 1000); + return (1000 * (uint64_t)t.tv_sec + (t.tv_nsec / 1000)); +#endif +} + diff --git a/common/util_posix.h b/common/util_posix.h index 08c4b3193..8f7ffb091 100644 --- a/common/util_posix.h +++ b/common/util_posix.h @@ -26,9 +26,9 @@ # define sleep(n) Sleep(1000 *(n)) # define msleep(n) Sleep((n)) #else -void msleep(uint32_t n); // sleep n milliseconds +void msleep(uint32_t n); // sleep n milliseconds #endif // _WIN32 -uint64_t msclock(void); // a milliseconds clock - +uint64_t msclock(void); // a milliseconds clock +uint64_t usclock(void); // a microseconds clock #endif