From 3f05b7c0a715a1f8543f0ec3a67b43f75c7afaa4 Mon Sep 17 00:00:00 2001 From: jsteube Date: Thu, 6 Oct 2016 16:55:17 +0200 Subject: [PATCH] Update dictstat.c function parameters --- include/dictstat.h | 12 ++++++------ src/dictstat.c | 26 ++++++++++++++++++++------ src/hashcat.c | 10 ++++------ src/wordlist.c | 5 ++--- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/include/dictstat.h b/include/dictstat.h index 054d1e553..cbe11fbb7 100644 --- a/include/dictstat.h +++ b/include/dictstat.h @@ -19,11 +19,11 @@ int sort_by_dictstat (const void *s1, const void *s2); -void dictstat_init (dictstat_ctx_t *dictstat_ctx, const user_options_t *user_options, const folder_config_t *folder_config); -void dictstat_destroy (dictstat_ctx_t *dictstat_ctx); -void dictstat_read (dictstat_ctx_t *dictstat_ctx); -int dictstat_write (dictstat_ctx_t *dictstat_ctx); -u64 dictstat_find (dictstat_ctx_t *dictstat_ctx, dictstat_t *d); -void dictstat_append (dictstat_ctx_t *dictstat_ctx, dictstat_t *d); +void dictstat_init (hashcat_ctx_t *hashcat_ctx); +void dictstat_destroy (hashcat_ctx_t *hashcat_ctx); +void dictstat_read (hashcat_ctx_t *hashcat_ctx); +int dictstat_write (hashcat_ctx_t *hashcat_ctx); +u64 dictstat_find (hashcat_ctx_t *hashcat_ctx, dictstat_t *d); +void dictstat_append (hashcat_ctx_t *hashcat_ctx, dictstat_t *d); #endif // _DICTSTAT_H diff --git a/src/dictstat.c b/src/dictstat.c index 806141258..8f3d270ff 100644 --- a/src/dictstat.c +++ b/src/dictstat.c @@ -23,8 +23,12 @@ int sort_by_dictstat (const void *s1, const void *s2) return memcmp (&d1->stat, &d2->stat, sizeof (struct stat)); } -void dictstat_init (dictstat_ctx_t *dictstat_ctx, const user_options_t *user_options, const folder_config_t *folder_config) +void dictstat_init (hashcat_ctx_t *hashcat_ctx) { + dictstat_ctx_t *dictstat_ctx = hashcat_ctx->dictstat_ctx; + folder_config_t *folder_config = hashcat_ctx->folder_config; + user_options_t *user_options = hashcat_ctx->user_options; + dictstat_ctx->enabled = false; if (user_options->benchmark == true) return; @@ -46,8 +50,10 @@ void dictstat_init (dictstat_ctx_t *dictstat_ctx, const user_options_t *user_opt snprintf (dictstat_ctx->filename, HCBUFSIZ_TINY - 1, "%s/hashcat.dictstat", folder_config->profile_dir); } -void dictstat_destroy (dictstat_ctx_t *dictstat_ctx) +void dictstat_destroy (hashcat_ctx_t *hashcat_ctx) { + dictstat_ctx_t *dictstat_ctx = hashcat_ctx->dictstat_ctx; + if (dictstat_ctx->enabled == false) return; myfree (dictstat_ctx->filename); @@ -56,8 +62,10 @@ void dictstat_destroy (dictstat_ctx_t *dictstat_ctx) memset (dictstat_ctx, 0, sizeof (dictstat_ctx_t)); } -void dictstat_read (dictstat_ctx_t *dictstat_ctx) +void dictstat_read (hashcat_ctx_t *hashcat_ctx) { + dictstat_ctx_t *dictstat_ctx = hashcat_ctx->dictstat_ctx; + if (dictstat_ctx->enabled == false) return; FILE *fp = fopen (dictstat_ctx->filename, "rb"); @@ -90,8 +98,10 @@ void dictstat_read (dictstat_ctx_t *dictstat_ctx) fclose (fp); } -int dictstat_write (dictstat_ctx_t *dictstat_ctx) +int dictstat_write (hashcat_ctx_t *hashcat_ctx) { + dictstat_ctx_t *dictstat_ctx = hashcat_ctx->dictstat_ctx; + if (dictstat_ctx->enabled == false) return 0; FILE *fp = fopen (dictstat_ctx->filename, "wb"); @@ -110,8 +120,10 @@ int dictstat_write (dictstat_ctx_t *dictstat_ctx) return 0; } -u64 dictstat_find (dictstat_ctx_t *dictstat_ctx, dictstat_t *d) +u64 dictstat_find (hashcat_ctx_t *hashcat_ctx, dictstat_t *d) { + dictstat_ctx_t *dictstat_ctx = hashcat_ctx->dictstat_ctx; + if (dictstat_ctx->enabled == false) return 0; dictstat_t *d_cache = (dictstat_t *) lfind (d, dictstat_ctx->base, &dictstat_ctx->cnt, sizeof (dictstat_t), sort_by_dictstat); @@ -121,8 +133,10 @@ u64 dictstat_find (dictstat_ctx_t *dictstat_ctx, dictstat_t *d) return d_cache->cnt; } -void dictstat_append (dictstat_ctx_t *dictstat_ctx, dictstat_t *d) +void dictstat_append (hashcat_ctx_t *hashcat_ctx, dictstat_t *d) { + dictstat_ctx_t *dictstat_ctx = hashcat_ctx->dictstat_ctx; + if (dictstat_ctx->enabled == false) return; if (dictstat_ctx->cnt == MAX_DICTSTAT) diff --git a/src/hashcat.c b/src/hashcat.c index 5d50399cf..f81f3475f 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -1236,8 +1236,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold * main init */ - dictstat_ctx_t *dictstat_ctx = hashcat_ctx->dictstat_ctx; - folder_config_t *folder_config = hashcat_ctx->folder_config; logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx; loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx; status_ctx_t *status_ctx = hashcat_ctx->status_ctx; @@ -1342,9 +1340,9 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold * dictstat init */ - dictstat_init (dictstat_ctx, user_options, folder_config); + dictstat_init (hashcat_ctx); - dictstat_read (dictstat_ctx); + dictstat_read (hashcat_ctx); /** * loopback init @@ -1483,7 +1481,7 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold // final update dictionary cache - dictstat_write (dictstat_ctx); + dictstat_write (hashcat_ctx); // free memory @@ -1493,7 +1491,7 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold loopback_destroy (loopback_ctx); - dictstat_destroy (dictstat_ctx); + dictstat_destroy (hashcat_ctx); potfile_destroy (hashcat_ctx); diff --git a/src/wordlist.c b/src/wordlist.c index 42c5ac2a2..2e73bc6c6 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -272,7 +272,6 @@ void pw_add (hc_device_param_t *device_param, const u8 *pw_buf, const int pw_len u64 count_words (hashcat_ctx_t *hashcat_ctx, FILE *fd, const char *dictfile) { combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; - dictstat_ctx_t *dictstat_ctx = hashcat_ctx->dictstat_ctx; straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; user_options_t *user_options = hashcat_ctx->user_options; @@ -306,7 +305,7 @@ u64 count_words (hashcat_ctx_t *hashcat_ctx, FILE *fd, const char *dictfile) if (d.stat.st_size == 0) return 0; - const u64 cached_cnt = dictstat_find (dictstat_ctx, &d); + const u64 cached_cnt = dictstat_find (hashcat_ctx, &d); if (run_rule_engine (user_options_extra->rule_len_l, user_options->rule_buf_l) == 0) { @@ -408,7 +407,7 @@ u64 count_words (hashcat_ctx_t *hashcat_ctx, FILE *fd, const char *dictfile) if (user_options->quiet == false) log_info ("Generated dictionary stats for %s: %" PRIu64 " bytes, %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, comp, cnt2, cnt); if (user_options->quiet == false) log_info (""); - dictstat_append (dictstat_ctx, &d); + dictstat_append (hashcat_ctx, &d); //hc_signal (sigHandler_default);