diff --git a/include/outfile.h b/include/outfile.h index a2f109a1e..3f6dcc44c 100644 --- a/include/outfile.h +++ b/include/outfile.h @@ -28,6 +28,6 @@ void outfile_format_plain (outfile_ctx_t *outfile_ctx, const unsigned char *pl void outfile_write_open (outfile_ctx_t *outfile_ctx); void outfile_write_close (outfile_ctx_t *outfile_ctx); void outfile_write (outfile_ctx_t *outfile_ctx, const char *out_buf, const unsigned char *plain_ptr, const uint plain_len, const u64 crackpos, const unsigned char *username, const uint user_len, const hashconfig_t *hashconfig); -int outfile_and_hashfile (outfile_ctx_t *outfile_ctx, hashes_t *hashes); +int outfile_and_hashfile (outfile_ctx_t *outfile_ctx, const char *hashfile); #endif // _OUTFILE_H diff --git a/src/hash_management.c b/src/hash_management.c index 75d7e63ab..b3df6b9e4 100644 --- a/src/hash_management.c +++ b/src/hash_management.c @@ -1225,6 +1225,15 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil hashes->hashes_cnt = hashes_cnt; + if (hashconfig->is_salted) + { + qsort (hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash); + } + else + { + qsort (hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash_no_salt); + } + return 0; } @@ -1239,15 +1248,6 @@ int hashes_init_stage2 (hashes_t *hashes, const hashconfig_t *hashconfig, opencl if (data.quiet == 0) log_info_nn ("Removing duplicate hashes..."); - if (hashconfig->is_salted) - { - qsort (hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash); - } - else - { - qsort (hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash_no_salt); - } - hashes_cnt = 1; for (uint hashes_pos = 1; hashes_pos < hashes->hashes_cnt; hashes_pos++) diff --git a/src/hashcat.c b/src/hashcat.c index 8fc097faf..232364790 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -1840,35 +1840,6 @@ int main (int argc, char **argv) if (rc_hashconfig == -1) return -1; - /** - * 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 - */ - - dictstat_ctx_t *dictstat_ctx = mymalloc (sizeof (dictstat_ctx_t)); - - dictstat_init (dictstat_ctx, profile_dir); - - if (keyspace == 0) - { - dictstat_read (dictstat_ctx); - } - /** * outfile */ @@ -1879,10 +1850,13 @@ int main (int argc, char **argv) outfile_init (outfile_ctx, outfile, outfile_format, outfile_autohex); - if (show == 1 || left == 1) - { - outfile_write_open (outfile_ctx); - } + /** + * Sanity check for hashfile vs outfile (should not point to the same physical file) + */ + + const int rc_outfile_and_hashfile = outfile_and_hashfile (outfile_ctx, myargv[optind]); + + if (rc_outfile_and_hashfile == -1) return -1; /** * potfile @@ -1896,6 +1870,8 @@ int main (int argc, char **argv) if (show == 1 || left == 1) { + outfile_write_open (outfile_ctx); + SUPPRESS_OUTPUT = 1; potfile_read_open (potfile_ctx); @@ -1907,47 +1883,6 @@ int main (int argc, char **argv) SUPPRESS_OUTPUT = 0; } - /** - * loopback - */ - - loopback_ctx_t *loopback_ctx = mymalloc (sizeof (loopback_ctx_t)); - - data.loopback_ctx = loopback_ctx; - - loopback_init (loopback_ctx); - - /** - * debugfile - */ - - debugfile_ctx_t *debugfile_ctx = mymalloc (sizeof (debugfile_ctx_t)); - - data.debugfile_ctx = debugfile_ctx; - - debugfile_init (debugfile_ctx, debug_mode, debug_file); - - /** - * word len - */ - - uint pw_min = hashconfig_general_pw_min (hashconfig); - uint pw_max = hashconfig_general_pw_max (hashconfig); - - /** - * charsets : keep them together for more easy maintainnce - */ - - cs_t mp_sys[6] = { { { 0 }, 0 } }; - cs_t mp_usr[4] = { { { 0 }, 0 } }; - - mp_setup_sys (mp_sys); - - if (custom_charset_1) mp_setup_usr (mp_sys, mp_usr, custom_charset_1, 0, hashconfig); - if (custom_charset_2) mp_setup_usr (mp_sys, mp_usr, custom_charset_2, 1, hashconfig); - if (custom_charset_3) mp_setup_usr (mp_sys, mp_usr, custom_charset_3, 2, hashconfig); - if (custom_charset_4) mp_setup_usr (mp_sys, mp_usr, custom_charset_4, 3, hashconfig); - /** * load hashes, stage 1 */ @@ -1975,10 +1910,6 @@ int main (int argc, char **argv) } } - /** - * If this was show/left request we're done here - */ - if (show == 1 || left == 1) { outfile_write_close (outfile_ctx); @@ -1990,14 +1921,6 @@ int main (int argc, char **argv) return 0; } - /** - * Sanity check for hashfile vs outfile (should not point to the same physical file) - */ - - const int rc_outfile_and_hashfile = outfile_and_hashfile (outfile_ctx, hashes); - - if (rc_outfile_and_hashfile == -1) return -1; - /** * Potfile removes */ @@ -2072,6 +1995,76 @@ 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 + */ + + dictstat_ctx_t *dictstat_ctx = mymalloc (sizeof (dictstat_ctx_t)); + + dictstat_init (dictstat_ctx, profile_dir); + + if (keyspace == 0) + { + dictstat_read (dictstat_ctx); + } + + /** + * loopback + */ + + loopback_ctx_t *loopback_ctx = mymalloc (sizeof (loopback_ctx_t)); + + data.loopback_ctx = loopback_ctx; + + loopback_init (loopback_ctx); + + /** + * debugfile + */ + + debugfile_ctx_t *debugfile_ctx = mymalloc (sizeof (debugfile_ctx_t)); + + data.debugfile_ctx = debugfile_ctx; + + debugfile_init (debugfile_ctx, debug_mode, debug_file); + + /** + * word len + */ + + uint pw_min = hashconfig_general_pw_min (hashconfig); + uint pw_max = hashconfig_general_pw_max (hashconfig); + + /** + * charsets : keep them together for more easy maintainnce + */ + + cs_t mp_sys[6] = { { { 0 }, 0 } }; + cs_t mp_usr[4] = { { { 0 }, 0 } }; + + mp_setup_sys (mp_sys); + + if (custom_charset_1) mp_setup_usr (mp_sys, mp_usr, custom_charset_1, 0, hashconfig); + if (custom_charset_2) mp_setup_usr (mp_sys, mp_usr, custom_charset_2, 1, hashconfig); + if (custom_charset_3) mp_setup_usr (mp_sys, mp_usr, custom_charset_3, 2, hashconfig); + if (custom_charset_4) mp_setup_usr (mp_sys, mp_usr, custom_charset_4, 3, hashconfig); + /** * Some algorithm, like descrypt, can benefit from JIT compilation */ diff --git a/src/outfile.c b/src/outfile.c index 0fe4a82cf..997f91d82 100644 --- a/src/outfile.c +++ b/src/outfile.c @@ -156,16 +156,14 @@ void outfile_write (outfile_ctx_t *outfile_ctx, const char *out_buf, const unsig fputs (EOL, outfile_ctx->fp); } -int outfile_and_hashfile (outfile_ctx_t *outfile_ctx, hashes_t *hashes) +int outfile_and_hashfile (outfile_ctx_t *outfile_ctx, const char *hashfile) { + if (hashfile == NULL) return 0; + char *outfile = outfile_ctx->filename; if (outfile == NULL) return 0; - char *hashfile = hashes->hashfile; - - if (hashfile == NULL) return 0; - #if defined (_POSIX) struct stat tmpstat_outfile; struct stat tmpstat_hashfile;