From 3664f02670ef41fbace800e72648a0dd672005bc Mon Sep 17 00:00:00 2001 From: jsteube Date: Thu, 22 Sep 2016 11:35:08 +0200 Subject: [PATCH] Get rid of global get_next_word_func function pointer variable --- include/types.h | 19 +++++++++------ include/wordlist.h | 3 +++ src/dispatch.c | 19 +++++---------- src/hashcat.c | 61 ++++++++++++++++++++-------------------------- src/wordlist.c | 45 +++++++++++++++++++++++++++++++--- 5 files changed, 87 insertions(+), 60 deletions(-) diff --git a/include/types.h b/include/types.h index 639978463..82fa21839 100644 --- a/include/types.h +++ b/include/types.h @@ -736,6 +736,8 @@ typedef struct u32 cnt; u32 pos; + void (*func) (char *, u32, u32 *, u32 *); + } wl_data_t; typedef struct @@ -1015,14 +1017,15 @@ typedef struct char *custom_charset_3; char *custom_charset_4; - hashconfig_t *hashconfig; - hashes_t *hashes; - - outfile_ctx_t *outfile_ctx; - potfile_ctx_t *potfile_ctx; - loopback_ctx_t *loopback_ctx; - debugfile_ctx_t *debugfile_ctx; - session_ctx_t *session_ctx; + hashconfig_t *hashconfig; + hashes_t *hashes; + user_options_t *user_options; + user_options_extra_t *user_options_extra; + outfile_ctx_t *outfile_ctx; + potfile_ctx_t *potfile_ctx; + loopback_ctx_t *loopback_ctx; + debugfile_ctx_t *debugfile_ctx; + session_ctx_t *session_ctx; u32 gpu_temp_disable; u32 gpu_temp_abort; diff --git a/include/wordlist.h b/include/wordlist.h index c12b0b60f..2551c1fa6 100644 --- a/include/wordlist.h +++ b/include/wordlist.h @@ -20,4 +20,7 @@ void pw_add (hc_device_param_t *device_param, const u8 *pw_buf, const int pw_len u64 count_words (wl_data_t *wl_data, FILE *fd, const char *dictfile, dictstat_ctx_t *dictstat_ctx); +void wl_data_init (wl_data_t *wl_data, const user_options_t *user_options, const hashconfig_t *hashconfig); +void wl_data_destroy (wl_data_t *wl_data); + #endif // _WORDLIST_H diff --git a/src/dispatch.c b/src/dispatch.c index 933e9897c..8f028809d 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -241,10 +241,10 @@ void *thread_calc (void *p) if (device_param->skipped) return NULL; - opencl_ctx_t *opencl_ctx = data.opencl_ctx; - - hashconfig_t *hashconfig = data.hashconfig; - hashes_t *hashes = data.hashes; + opencl_ctx_t *opencl_ctx = data.opencl_ctx; + user_options_t *user_options = data.user_options; + hashconfig_t *hashconfig = data.hashconfig; + hashes_t *hashes = data.hashes; const uint attack_mode = data.attack_mode; const uint attack_kern = data.attack_kern; @@ -287,8 +287,6 @@ void *thread_calc (void *p) } else { - const uint segment_size = data.segment_size; - char *dictfile = data.dictfile; if (attack_mode == ATTACK_MODE_COMBI) @@ -350,11 +348,7 @@ void *thread_calc (void *p) wl_data_t *wl_data = (wl_data_t *) mymalloc (sizeof (wl_data_t)); - wl_data->buf = (char *) mymalloc (segment_size); - wl_data->avail = segment_size; - wl_data->incr = segment_size; - wl_data->cnt = 0; - wl_data->pos = 0; + wl_data_init (wl_data, user_options, hashconfig); u64 words_cur = 0; @@ -495,8 +489,7 @@ void *thread_calc (void *p) fclose (device_param->combs_fp); } - free (wl_data->buf); - free (wl_data); + wl_data_destroy (wl_data); fclose (fd); } diff --git a/src/hashcat.c b/src/hashcat.c index 2c1aee215..5e458cb4d 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -93,8 +93,6 @@ extern int SUPPRESS_OUTPUT; extern hc_thread_mutex_t mux_hwmon; extern hc_thread_mutex_t mux_display; -extern void (*get_next_word_func) (char *, u32, u32 *, u32 *); - extern const unsigned int full01; extern const unsigned int full80; @@ -102,16 +100,8 @@ extern const int DEFAULT_BENCHMARK_ALGORITHMS_BUF[]; const int comptime = COMPTIME; -int main (int argc, char **argv) +static void setup_environment_variables () { - #if defined (_WIN) - SetConsoleWindowSize (132); - #endif - - /** - * To help users a bit - */ - char *compute = getenv ("COMPUTE"); if (compute) @@ -142,8 +132,26 @@ int main (int argc, char **argv) if (getenv ("POCL_KERNEL_CACHE") == NULL) putenv ((char *) "POCL_KERNEL_CACHE=0"); +} +static void setup_umask () +{ umask (077); +} + +int main (int argc, char **argv) +{ + #if defined (_WIN) + SetConsoleWindowSize (132); + #endif + + /** + * To help users a bit + */ + + setup_environment_variables (); + + setup_umask (); /** * Real init @@ -194,6 +202,8 @@ int main (int argc, char **argv) user_options_t *user_options = (user_options_t *) mymalloc (sizeof (user_options_t)); + data.user_options = user_options; + user_options_init (user_options, argc, argv); const int rc_user_options_parse1 = user_options_parse (user_options, argc, argv); @@ -254,6 +264,8 @@ int main (int argc, char **argv) user_options_extra_t *user_options_extra = (user_options_extra_t *) mymalloc (sizeof (user_options_extra_t)); + data.user_options_extra = user_options_extra; + const int rc_user_options_extra_init = user_options_extra_init (user_options, myargc, myargv, user_options_extra); if (rc_user_options_extra_init == -1) return -1; @@ -855,22 +867,6 @@ int main (int argc, char **argv) } } - /** - * choose dictionary parser - */ - - get_next_word_func = get_next_word_std; - - if (hashconfig->opts_type & OPTS_TYPE_PT_UPPER) - { - get_next_word_func = get_next_word_uc; - } - - if (hashconfig->hash_type == HASH_TYPE_LM) // yes that's fine that way - { - get_next_word_func = get_next_word_lm; - } - /** * dictstat */ @@ -1872,11 +1868,7 @@ int main (int argc, char **argv) wl_data_t *wl_data = (wl_data_t *) mymalloc (sizeof (wl_data_t)); - wl_data->buf = (char *) mymalloc (user_options->segment_size); - wl_data->avail = user_options->segment_size; - wl_data->incr = user_options->segment_size; - wl_data->cnt = 0; - wl_data->pos = 0; + wl_data_init (wl_data, user_options, hashconfig); cs_t *css_buf = NULL; uint css_cnt = 0; @@ -4069,12 +4061,11 @@ int main (int argc, char **argv) loopback_destroy (loopback_ctx); + wl_data_destroy (wl_data); + local_free (all_kernel_rules_cnt); local_free (all_kernel_rules_buf); - local_free (wl_data->buf); - local_free (wl_data); - local_free (bitmap_s1_a); local_free (bitmap_s1_b); local_free (bitmap_s1_c); diff --git a/src/wordlist.c b/src/wordlist.c index c63fcd59a..37d66ef4c 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -37,8 +37,6 @@ extern hc_global_data_t data; -void (*get_next_word_func) (char *, u32, u32 *, u32 *); - uint convert_from_hex (char *line_buf, const uint line_len) { if (line_len & 1) return (line_len); // not in hex @@ -212,7 +210,7 @@ void get_next_word (wl_data_t *wl_data, FILE *fd, char **out_buf, uint *out_len) char *ptr = wl_data->buf + wl_data->pos; - get_next_word_func (ptr, wl_data->cnt - wl_data->pos, &len, &off); + wl_data->func (ptr, wl_data->cnt - wl_data->pos, &len, &off); wl_data->pos += off; @@ -363,7 +361,7 @@ u64 count_words (wl_data_t *wl_data, FILE *fd, const char *dictfile, dictstat_ct u32 len; u32 off; - get_next_word_func (wl_data->buf + i, wl_data->cnt - i, &len, &off); + wl_data->func (wl_data->buf + i, wl_data->cnt - i, &len, &off); if (run_rule_engine (data.rule_len_l, data.rule_buf_l)) { @@ -425,3 +423,42 @@ u64 count_words (wl_data_t *wl_data, FILE *fd, const char *dictfile, dictstat_ct return (cnt); } + +void wl_data_init (wl_data_t *wl_data, const user_options_t *user_options, const hashconfig_t *hashconfig) +{ + wl_data->buf = (char *) mymalloc (user_options->segment_size); + wl_data->avail = user_options->segment_size; + wl_data->incr = user_options->segment_size; + wl_data->cnt = 0; + wl_data->pos = 0; + + /** + * choose dictionary parser + */ + + wl_data->func = get_next_word_std; + + if (hashconfig->opts_type & OPTS_TYPE_PT_UPPER) + { + wl_data->func = get_next_word_uc; + } + + if (hashconfig->hash_type == HASH_TYPE_LM) // yes that's fine that way + { + wl_data->func = get_next_word_lm; + } +} + +void wl_data_destroy (wl_data_t *wl_data) +{ + myfree (wl_data->buf); + + wl_data->func = NULL; + wl_data->buf = NULL; + wl_data->avail = 0; + wl_data->incr = 0; + wl_data->cnt = 0; + wl_data->pos = 0; + + myfree (wl_data); +}