diff --git a/include/dictstat.h b/include/dictstat.h index 0e1398964..054d1e553 100644 --- a/include/dictstat.h +++ b/include/dictstat.h @@ -19,7 +19,7 @@ int sort_by_dictstat (const void *s1, const void *s2); -void dictstat_init (dictstat_ctx_t *dictstat_ctx, char *profile_dir); +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); diff --git a/include/types.h b/include/types.h index a4d36dc28..907f99409 100644 --- a/include/types.h +++ b/include/types.h @@ -775,6 +775,8 @@ typedef struct typedef struct { + bool enabled; + char *filename; dictstat_t *base; diff --git a/src/dictstat.c b/src/dictstat.c index b1a680c9f..3e938d978 100644 --- a/src/dictstat.c +++ b/src/dictstat.c @@ -26,23 +26,35 @@ 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, char *profile_dir) +void dictstat_init (dictstat_ctx_t *dictstat_ctx, const user_options_t *user_options, const folder_config_t *folder_config) { + dictstat_ctx->enabled = false; + + if (user_options->show == true) return; + if (user_options->left == true) return; + if (user_options->keyspace == true) return; + if (user_options->benchmark == true) return; + dictstat_ctx->filename = (char *) mymalloc (HCBUFSIZ_TINY); dictstat_ctx->base = (dictstat_t *) mycalloc (MAX_DICTSTAT, sizeof (dictstat_t)); dictstat_ctx->cnt = 0; + dictstat_ctx->enabled = true; - generate_dictstat_filename (profile_dir, dictstat_ctx->filename); + generate_dictstat_filename (folder_config->profile_dir, dictstat_ctx->filename); } void dictstat_destroy (dictstat_ctx_t *dictstat_ctx) { + if (dictstat_ctx->enabled == false) return; + myfree (dictstat_ctx->filename); myfree (dictstat_ctx->base); } void dictstat_read (dictstat_ctx_t *dictstat_ctx) { + if (dictstat_ctx->enabled == false) return; + FILE *fp = fopen (dictstat_ctx->filename, "rb"); if (fp == NULL) @@ -99,6 +111,8 @@ void dictstat_read (dictstat_ctx_t *dictstat_ctx) int dictstat_write (dictstat_ctx_t *dictstat_ctx) { + if (dictstat_ctx->enabled == false) return 0; + FILE *fp = fopen (dictstat_ctx->filename, "wb"); if (fp == NULL) @@ -117,6 +131,8 @@ int dictstat_write (dictstat_ctx_t *dictstat_ctx) u64 dictstat_find (dictstat_ctx_t *dictstat_ctx, dictstat_t *d) { + 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); if (d_cache == NULL) return 0; @@ -126,6 +142,8 @@ u64 dictstat_find (dictstat_ctx_t *dictstat_ctx, dictstat_t *d) void dictstat_append (dictstat_ctx_t *dictstat_ctx, dictstat_t *d) { + if (dictstat_ctx->enabled == false) return; + if (dictstat_ctx->cnt == MAX_DICTSTAT) { log_error ("ERROR: There are too many entries in the %s database. You have to remove/rename it.", dictstat_ctx->filename); diff --git a/src/hashcat.c b/src/hashcat.c index d88ebfd47..1f1c529e8 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -203,7 +203,7 @@ static void setup_seeding (const user_options_t *user_options, const time_t proc } } -static int outer_loop (user_options_t *user_options, user_options_extra_t *user_options_extra, int myargc, char **myargv, folder_config_t *folder_config, logfile_ctx_t *logfile_ctx, tuning_db_t *tuning_db, induct_ctx_t *induct_ctx, outcheck_ctx_t *outcheck_ctx, outfile_ctx_t *outfile_ctx, potfile_ctx_t *potfile_ctx, rules_ctx_t *rules_ctx, opencl_ctx_t *opencl_ctx) +static int outer_loop (user_options_t *user_options, user_options_extra_t *user_options_extra, int myargc, char **myargv, folder_config_t *folder_config, logfile_ctx_t *logfile_ctx, tuning_db_t *tuning_db, induct_ctx_t *induct_ctx, outcheck_ctx_t *outcheck_ctx, outfile_ctx_t *outfile_ctx, potfile_ctx_t *potfile_ctx, rules_ctx_t *rules_ctx, dictstat_ctx_t *dictstat_ctx, opencl_ctx_t *opencl_ctx) { opencl_ctx->devices_status = STATUS_INIT; @@ -350,19 +350,6 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ bitmap_ctx_init (bitmap_ctx, user_options, hashconfig, hashes); - /** - * dictstat - */ - - dictstat_ctx_t *dictstat_ctx = mymalloc (sizeof (dictstat_ctx_t)); - - dictstat_init (dictstat_ctx, folder_config->profile_dir); - - if (user_options->keyspace == false) - { - dictstat_read (dictstat_ctx); - } - /** * loopback */ @@ -1061,6 +1048,12 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ } #endif + /** + * dictstat + */ + + dictstat_read (dictstat_ctx); + /** * dictionary pad */ @@ -2689,10 +2682,7 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ * Update dictionary statistic */ - if (user_options->keyspace == false) - { - dictstat_write (dictstat_ctx); - } + dictstat_write (dictstat_ctx); /** * Update loopback file @@ -3180,8 +3170,6 @@ static int outer_loop (user_options_t *user_options, user_options_extra_t *user_ potfile_write_close (potfile_ctx); - dictstat_destroy (dictstat_ctx); - loopback_destroy (loopback_ctx); wl_data_destroy (wl_data); @@ -3440,6 +3428,14 @@ int main (int argc, char **argv) potfile_init (potfile_ctx, folder_config->profile_dir, user_options->potfile_path, user_options->potfile_disable); + /** + * dictstat init + */ + + dictstat_ctx_t *dictstat_ctx = mymalloc (sizeof (dictstat_ctx_t)); + + dictstat_init (dictstat_ctx, user_options, folder_config); + /** * cpu affinity */ @@ -3521,7 +3517,7 @@ int main (int argc, char **argv) if (user_options->hash_mode_chgd == true) { - const int rc = outer_loop (user_options, user_options_extra, myargc, myargv, folder_config, logfile_ctx, tuning_db, induct_ctx, outcheck_ctx, outfile_ctx, potfile_ctx, rules_ctx, opencl_ctx); + const int rc = outer_loop (user_options, user_options_extra, myargc, myargv, folder_config, logfile_ctx, tuning_db, induct_ctx, outcheck_ctx, outfile_ctx, potfile_ctx, rules_ctx, dictstat_ctx, opencl_ctx); if (rc == -1) return -1; } @@ -3531,7 +3527,7 @@ int main (int argc, char **argv) { user_options->hash_mode = DEFAULT_BENCHMARK_ALGORITHMS_BUF[algorithm_pos]; - const int rc = outer_loop (user_options, user_options_extra, myargc, myargv, folder_config, logfile_ctx, tuning_db, induct_ctx, outcheck_ctx, outfile_ctx, potfile_ctx, rules_ctx, opencl_ctx); + const int rc = outer_loop (user_options, user_options_extra, myargc, myargv, folder_config, logfile_ctx, tuning_db, induct_ctx, outcheck_ctx, outfile_ctx, potfile_ctx, rules_ctx, dictstat_ctx, opencl_ctx); if (rc == -1) return -1; } @@ -3539,7 +3535,7 @@ int main (int argc, char **argv) } else { - const int rc = outer_loop (user_options, user_options_extra, myargc, myargv, folder_config, logfile_ctx, tuning_db, induct_ctx, outcheck_ctx, outfile_ctx, potfile_ctx, rules_ctx, opencl_ctx); + const int rc = outer_loop (user_options, user_options_extra, myargc, myargv, folder_config, logfile_ctx, tuning_db, induct_ctx, outcheck_ctx, outfile_ctx, potfile_ctx, rules_ctx, dictstat_ctx, opencl_ctx); if (rc == -1) return -1; } @@ -3571,10 +3567,12 @@ int main (int argc, char **argv) tuning_db_destroy (tuning_db); - induct_ctx_destroy (induct_ctx); + dictstat_destroy (dictstat_ctx); potfile_destroy (potfile_ctx); + induct_ctx_destroy (induct_ctx); + outfile_destroy (outfile_ctx); outcheck_ctx_destroy (outcheck_ctx); diff --git a/src/potfile.c b/src/potfile.c index eb1a0130d..7fe635689 100644 --- a/src/potfile.c +++ b/src/potfile.c @@ -110,7 +110,7 @@ void potfile_init (potfile_ctx_t *potfile_ctx, const char *profile_dir, const ch { potfile_ctx->disable = potfile_disable; - if (potfile_ctx->disable == 1) return; + if (potfile_ctx->disable == true) return; potfile_ctx->fp = NULL; @@ -133,28 +133,28 @@ void potfile_init (potfile_ctx_t *potfile_ctx, const char *profile_dir, const ch void potfile_format_plain (potfile_ctx_t *potfile_ctx, const unsigned char *plain_ptr, const uint plain_len) { - if (potfile_ctx->disable == 1) return; + if (potfile_ctx->disable == true) return; - int needs_hexify = 0; + bool needs_hexify = false; for (uint i = 0; i < plain_len; i++) { if (plain_ptr[i] < 0x20) { - needs_hexify = 1; + needs_hexify = true; break; } if (plain_ptr[i] > 0x7f) { - needs_hexify = 1; + needs_hexify = true; break; } } - if (needs_hexify == 1) + if (needs_hexify == true) { fprintf (potfile_ctx->fp, "$HEX["); @@ -173,7 +173,7 @@ void potfile_format_plain (potfile_ctx_t *potfile_ctx, const unsigned char *plai int potfile_read_open (potfile_ctx_t *potfile_ctx) { - if (potfile_ctx->disable == 1) return 0; + if (potfile_ctx->disable == true) return 0; potfile_ctx->fp = fopen (potfile_ctx->filename, "rb"); @@ -189,7 +189,7 @@ int potfile_read_open (potfile_ctx_t *potfile_ctx) void potfile_read_parse (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig) { - if (potfile_ctx->disable == 1) return; + if (potfile_ctx->disable == true) return; if (potfile_ctx->fp == NULL) return; @@ -296,7 +296,7 @@ void potfile_read_parse (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashcon void potfile_read_close (potfile_ctx_t *potfile_ctx) { - if (potfile_ctx->disable == 1) return; + if (potfile_ctx->disable == true) return; if (potfile_ctx->fp == NULL) return; @@ -305,7 +305,7 @@ void potfile_read_close (potfile_ctx_t *potfile_ctx) int potfile_write_open (potfile_ctx_t *potfile_ctx) { - if (potfile_ctx->disable == 1) return 0; + if (potfile_ctx->disable == true) return 0; potfile_ctx->fp = fopen (potfile_ctx->filename, "ab"); @@ -321,14 +321,14 @@ int potfile_write_open (potfile_ctx_t *potfile_ctx) void potfile_write_close (potfile_ctx_t *potfile_ctx) { - if (potfile_ctx->disable == 1) return; + if (potfile_ctx->disable == true) return; fclose (potfile_ctx->fp); } void potfile_write_append (potfile_ctx_t *potfile_ctx, const char *out_buf, u8 *plain_ptr, unsigned int plain_len) { - if (potfile_ctx->disable == 1) return; + if (potfile_ctx->disable == true) return; FILE *fp = potfile_ctx->fp; @@ -343,7 +343,7 @@ void potfile_write_append (potfile_ctx_t *potfile_ctx, const char *out_buf, u8 * void potfile_hash_alloc (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig, const uint num) { - if (potfile_ctx->disable == 1) return; + if (potfile_ctx->disable == true) return; uint pos = 0; @@ -373,7 +373,7 @@ void potfile_hash_alloc (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashcon void potfile_hash_free (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig) { - if (potfile_ctx->disable == 1) return; + if (potfile_ctx->disable == true) return; for (uint i = 0; i < potfile_ctx->pot_cnt; i++) { @@ -393,11 +393,13 @@ void potfile_hash_free (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconf myfree (hashes_buf->esalt); } } + + myfree (potfile_ctx->pot); } void potfile_show_request (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig, outfile_ctx_t *outfile_ctx, char *input_buf, int input_len, hash_t *hashes_buf, int (*sort_by_pot) (const void *, const void *)) { - if (potfile_ctx->disable == 1) return; + if (potfile_ctx->disable == true) return; pot_t pot_key; @@ -436,7 +438,7 @@ void potfile_show_request (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashc void potfile_left_request (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig, outfile_ctx_t *outfile_ctx, char *input_buf, int input_len, hash_t *hashes_buf, int (*sort_by_pot) (const void *, const void *)) { - if (potfile_ctx->disable == 1) return; + if (potfile_ctx->disable == true) return; pot_t pot_key; @@ -456,7 +458,7 @@ void potfile_left_request (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashc void potfile_show_request_lm (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig, outfile_ctx_t *outfile_ctx, char *input_buf, int input_len, hash_t *hash_left, hash_t *hash_right, int (*sort_by_pot) (const void *, const void *)) { - if (potfile_ctx->disable == 1) return; + if (potfile_ctx->disable == true) return; // left @@ -578,7 +580,7 @@ void potfile_show_request_lm (potfile_ctx_t *potfile_ctx, const hashconfig_t *ha void potfile_left_request_lm (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig, outfile_ctx_t *outfile_ctx, char *input_buf, int input_len, hash_t *hash_left, hash_t *hash_right, int (*sort_by_pot) (const void *, const void *)) { - if (potfile_ctx->disable == 1) return; + if (potfile_ctx->disable == true) return; // left @@ -660,7 +662,7 @@ void potfile_left_request_lm (potfile_ctx_t *potfile_ctx, const hashconfig_t *ha int potfile_remove_parse (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig, const hashes_t *hashes) { - if (potfile_ctx->disable == 1) return 0; + if (potfile_ctx->disable == true) return 0; hash_t *hashes_buf = hashes->hashes_buf; uint hashes_cnt = hashes->hashes_cnt; @@ -871,7 +873,7 @@ int potfile_remove_parse (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashco void potfile_destroy (potfile_ctx_t *potfile_ctx) { - if (potfile_ctx->disable == 1) return; + if (potfile_ctx->disable == true) return; myfree (potfile_ctx->filename); }