From 316694fd08a42eec4592a62141cedfbc4f18d5d2 Mon Sep 17 00:00:00 2001 From: jsteube Date: Wed, 16 Nov 2016 10:22:57 +0100 Subject: [PATCH] Move hc_qsort_r() and hc_bsearch_r() from potfile.c to shared.c - Lets us use them from within all objects --- include/potfile.h | 3 --- include/shared.h | 3 +++ src/potfile.c | 39 +-------------------------------------- src/shared.c | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 41 deletions(-) diff --git a/include/potfile.h b/include/potfile.h index ee9b3dc69..01b2180ef 100644 --- a/include/potfile.h +++ b/include/potfile.h @@ -15,9 +15,6 @@ int sort_by_hash_t_salt (const void *v1, const void *v2); int sort_by_hash_t_salt_hccap (const void *v1, const void *v2); -void hc_qsort_r (void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg); -void *hc_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg); - int potfile_init (hashcat_ctx_t *hashcat_ctx); int potfile_read_open (hashcat_ctx_t *hashcat_ctx); void potfile_read_close (hashcat_ctx_t *hashcat_ctx); diff --git a/include/shared.h b/include/shared.h index c217e1359..f5e6a3cd0 100644 --- a/include/shared.h +++ b/include/shared.h @@ -34,4 +34,7 @@ void setup_seeding (const bool rp_gen_seed_chgd, const u32 rp_gen_seed); int hc_stat (const char *pathname, hc_stat_t *buf); int hc_fstat (int fd, hc_stat_t *buf); +void hc_qsort_r (void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg); +void *hc_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg); + #endif // _SHARED_H diff --git a/src/potfile.c b/src/potfile.c index efb0d4ba2..36f2f323a 100644 --- a/src/potfile.c +++ b/src/potfile.c @@ -13,14 +13,7 @@ #include "outfile.h" #include "potfile.h" #include "locking.h" - -#if defined (_WIN) -#define __WINDOWS__ -#endif -#include "sort_r.h" -#if defined (_WIN) -#undef __WINDOWS__ -#endif +#include "shared.h" // get rid of this later int sort_by_hash (const void *v1, const void *v2, void *v3); @@ -82,36 +75,6 @@ int sort_by_hash_t_salt_hccap (const void *v1, const void *v2) return 0; } -void hc_qsort_r (void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg) -{ - sort_r (base, nmemb, size, compar, arg); -} - -void *hc_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg) -{ - for (size_t l = 0, r = nmemb; r; r >>= 1) - { - const size_t m = r >> 1; - - const size_t c = l + m; - - const char *next = (char *) base + (c * size); - - const int cmp = (*compar) (key, next, arg); - - if (cmp > 0) - { - l += m + 1; - - r--; - } - - if (cmp == 0) return ((void *) next); - } - - return (NULL); -} - int potfile_init (hashcat_ctx_t *hashcat_ctx) { folder_config_t *folder_config = hashcat_ctx->folder_config; diff --git a/src/shared.c b/src/shared.c index 89cb7cd6a..9c8678e39 100644 --- a/src/shared.c +++ b/src/shared.c @@ -141,6 +141,44 @@ void hc_sleep (const u32 sec) #endif } +#if defined (_WIN) +#define __WINDOWS__ +#endif +#include "sort_r.h" +#if defined (_WIN) +#undef __WINDOWS__ +#endif + +void hc_qsort_r (void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg) +{ + sort_r (base, nmemb, size, compar, arg); +} + +void *hc_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg) +{ + for (size_t l = 0, r = nmemb; r; r >>= 1) + { + const size_t m = r >> 1; + + const size_t c = l + m; + + const char *next = (char *) base + (c * size); + + const int cmp = (*compar) (key, next, arg); + + if (cmp > 0) + { + l += m + 1; + + r--; + } + + if (cmp == 0) return ((void *) next); + } + + return (NULL); +} + void setup_environment_variables () { char *compute = getenv ("COMPUTE");