From a10a8427cb73d261823198e5511c037b4af70817 Mon Sep 17 00:00:00 2001 From: philsmd Date: Wed, 4 Oct 2017 12:23:37 +0200 Subject: [PATCH] fixed the nanosecond access time problem, also working on macos now --- include/common.h | 21 ++++++++++++--------- src/dictstat.c | 4 ++-- src/wordlist.c | 4 ++-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/include/common.h b/include/common.h index b1e07ff20..8317e2bbe 100644 --- a/include/common.h +++ b/include/common.h @@ -75,18 +75,21 @@ but this is nededed for VS compiler which doesn't have inline keyword but has __ #define MAYBE_UNUSED __attribute__((unused)) -/* Check if we also need to use/set the nanoseconds for the file stats: -The linux manual says that the only valid way to check for nanosecond resolution is to follow this rule: -"The nanosecond components of each timestamp are available via names of the form st_atim.tv_nsec -if the _BSD_SOURCE or _SVID_SOURCE feature test macro is defined" -*/ +/* + * Check if the system uses nanoseconds for file timestamps. + * In case the system uses nanoseconds we set some custom macros here, + * e.g. the (nanosecond) access time macros for dictstat + */ -#if defined (_BSD_SOURCE) -#define WITH_NANOSECONDS_IN_STAT 1 +#if defined (__linux__) +#include +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,48) +#define STAT_NANOSECONDS_ACCESS_TIME st_atim.tv_nsec +#endif #endif -#if defined (_SVID_SOURCE) -#define WITH_NANOSECONDS_IN_STAT 1 +#if defined (__APPLE__) +#define STAT_NANOSECONDS_ACCESS_TIME st_atimespec.tv_nsec #endif // config section diff --git a/src/dictstat.c b/src/dictstat.c index 67953ada9..1118c5b6d 100644 --- a/src/dictstat.c +++ b/src/dictstat.c @@ -19,8 +19,8 @@ int sort_by_dictstat (const void *s1, const void *s2) d2->stat.st_atime = d1->stat.st_atime; - #if defined (WITH_NANOSECONDS_IN_STAT) - d2->stat.st_atim.tv_nsec = d1->stat.st_atim.tv_nsec; + #if defined (STAT_NANOSECONDS_ACCESS_TIME) + d2->stat.STAT_NANOSECONDS_ACCESS_TIME = d1->stat.STAT_NANOSECONDS_ACCESS_TIME; #endif const int rc_from = strcmp (d1->encoding_from, d2->encoding_from); diff --git a/src/wordlist.c b/src/wordlist.c index 2f89cdafc..465e65ff9 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -293,8 +293,8 @@ int count_words (hashcat_ctx_t *hashcat_ctx, FILE *fd, const char *dictfile, u64 d.stat.st_rdev = 0; d.stat.st_atime = 0; - #if defined (WITH_NANOSECONDS_IN_STAT) - d.stat.st_atim.tv_nsec = 0; + #if defined (STAT_NANOSECONDS_ACCESS_TIME) + d.stat.STAT_NANOSECONDS_ACCESS_TIME = 0; #endif #if defined (_POSIX)