From ebd904a179b4282c66bef3b9c62d8f8c336aae82 Mon Sep 17 00:00:00 2001 From: philsmd Date: Fri, 24 Jan 2020 18:43:13 +0100 Subject: [PATCH] outfile: improved version of OUTFILE_FORMAT assignment --- include/types.h | 2 +- src/interface.c | 2 +- src/modules/module_09710.c | 2 +- src/modules/module_09810.c | 2 +- src/modules/module_10410.c | 2 +- src/outfile.c | 11 ++++++++--- src/user_options.c | 22 ++++++++++------------ 7 files changed, 23 insertions(+), 20 deletions(-) diff --git a/include/types.h b/include/types.h index 057085768..b0237d13b 100644 --- a/include/types.h +++ b/include/types.h @@ -1925,7 +1925,6 @@ typedef struct user_options char *opencl_device_types; char *outfile; char *outfile_check_dir; - char *outfile_format; char *potfile_path; char *restore_file_path; char **rp_files; @@ -1965,6 +1964,7 @@ typedef struct user_options u32 spin_damp; u32 backend_vector_width; u32 outfile_check_timer; + u32 outfile_format; u32 remove_timer; u32 restore_timer; u32 rp_files_cnt; diff --git a/src/interface.c b/src/interface.c index 76ef8b330..9b5ca7b14 100644 --- a/src/interface.c +++ b/src/interface.c @@ -516,7 +516,7 @@ u32 default_kernel_threads_max (MAYBE_UNUSED const hashconfig_t *hashconfig, MAY u32 default_forced_outfile_format (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { - const u32 forced_outfile_format = outfile_format_parse (user_options->outfile_format); + const u32 forced_outfile_format = user_options->outfile_format; return forced_outfile_format; } diff --git a/src/modules/module_09710.c b/src/modules/module_09710.c index f2f8b662a..2f7a5957a 100644 --- a/src/modules/module_09710.c +++ b/src/modules/module_09710.c @@ -99,7 +99,7 @@ const char *module_benchmark_mask (MAYBE_UNUSED const hashconfig_t *hashconfig, u32 module_forced_outfile_format (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { - const u32 forced_outfile_format = 5; + const u32 forced_outfile_format = OUTFILE_FMT_HASH | OUTFILE_FMT_HEXPLAIN; return forced_outfile_format; } diff --git a/src/modules/module_09810.c b/src/modules/module_09810.c index ecbba7c64..fd80151fa 100644 --- a/src/modules/module_09810.c +++ b/src/modules/module_09810.c @@ -98,7 +98,7 @@ const char *module_benchmark_mask (MAYBE_UNUSED const hashconfig_t *hashconfig, u32 module_forced_outfile_format (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { - const u32 forced_outfile_format = 5; + const u32 forced_outfile_format = OUTFILE_FMT_HASH | OUTFILE_FMT_HEXPLAIN; return forced_outfile_format; } diff --git a/src/modules/module_10410.c b/src/modules/module_10410.c index 96624d904..d641ae03c 100644 --- a/src/modules/module_10410.c +++ b/src/modules/module_10410.c @@ -107,7 +107,7 @@ const char *module_benchmark_mask (MAYBE_UNUSED const hashconfig_t *hashconfig, u32 module_forced_outfile_format (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSED const user_options_t *user_options, MAYBE_UNUSED const user_options_extra_t *user_options_extra) { - const u32 forced_outfile_format = 5; + const u32 forced_outfile_format = OUTFILE_FMT_HASH | OUTFILE_FMT_HEXPLAIN; return forced_outfile_format; } diff --git a/src/outfile.c b/src/outfile.c index b04a59a7a..2e49a4597 100644 --- a/src/outfile.c +++ b/src/outfile.c @@ -19,7 +19,7 @@ u32 outfile_format_parse (const char *format_string) { - if (format_string == NULL) return OUTFILE_FORMAT; // default outfile format + if (format_string == NULL) return 0; char *format = hcstrdup (format_string); @@ -29,7 +29,12 @@ u32 outfile_format_parse (const char *format_string) char *next = strtok_r (format, ",", &saveptr); - if (next == NULL) return 0; + if (next == NULL) + { + hcfree (format); + + return 0; + } u32 outfile_format = 0; @@ -484,7 +489,7 @@ int outfile_init (hashcat_ctx_t *hashcat_ctx) outfile_ctx->fp.pfp = NULL; outfile_ctx->filename = user_options->outfile; - outfile_ctx->outfile_format = outfile_format_parse (user_options->outfile_format); + outfile_ctx->outfile_format = user_options->outfile_format; outfile_ctx->outfile_autohex = user_options->outfile_autohex; return 0; diff --git a/src/user_options.c b/src/user_options.c index 9d7fa473e..57e09a7ce 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -219,7 +219,7 @@ int user_options_init (hashcat_ctx_t *hashcat_ctx) user_options->outfile_autohex = OUTFILE_AUTOHEX; user_options->outfile_check_dir = NULL; user_options->outfile_check_timer = OUTFILE_CHECK_TIMER; - user_options->outfile_format = NULL; + user_options->outfile_format = OUTFILE_FORMAT; user_options->outfile = NULL; user_options->potfile_disable = POTFILE_DISABLE; user_options->potfile_path = NULL; @@ -423,7 +423,7 @@ int user_options_getopt (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) case IDX_MARKOV_THRESHOLD: user_options->markov_threshold = hc_strtoul (optarg, NULL, 10); break; case IDX_MARKOV_HCSTAT2: user_options->markov_hcstat2 = optarg; break; case IDX_OUTFILE: user_options->outfile = optarg; break; - case IDX_OUTFILE_FORMAT: user_options->outfile_format = optarg; + case IDX_OUTFILE_FORMAT: user_options->outfile_format = outfile_format_parse (optarg); user_options->outfile_format_chgd = true; break; case IDX_OUTFILE_AUTOHEX_DISABLE: user_options->outfile_autohex = false; break; case IDX_OUTFILE_CHECK_TIMER: user_options->outfile_check_timer = hc_strtoul (optarg, NULL, 10); break; @@ -659,9 +659,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) return -1; } - const u32 outfile_format = outfile_format_parse (user_options->outfile_format); - - if (outfile_format == 0) + if (user_options->outfile_format == 0) { event_log_error (hashcat_ctx, "Invalid --outfile-format value specified."); @@ -672,7 +670,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->outfile_format_chgd == true) { - if (outfile_format > 1) + if (user_options->outfile_format > 1) { event_log_error (hashcat_ctx, "Combining --outfile-format > 1 with --left is not allowed."); @@ -685,21 +683,21 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->outfile_format_chgd == true) { - if (outfile_format & OUTFILE_FMT_CRACKPOS) + if (user_options->outfile_format & OUTFILE_FMT_CRACKPOS) { event_log_error (hashcat_ctx, "Using crack_pos in --outfile-format for --show is not allowed."); return -1; } - if (outfile_format & OUTFILE_FMT_TIME_ABS) + if (user_options->outfile_format & OUTFILE_FMT_TIME_ABS) { event_log_error (hashcat_ctx, "Using the absolute timestamp in --outfile-format for --show is not allowed."); return -1; } - if (outfile_format & OUTFILE_FMT_TIME_REL) + if (user_options->outfile_format & OUTFILE_FMT_TIME_REL) { event_log_error (hashcat_ctx, "Using the relative timestamp in --outfile-format for --show is not allowed."); @@ -1704,7 +1702,7 @@ void user_options_preprocess (hashcat_ctx_t *hashcat_ctx) user_options->hash_mode = 2000; user_options->kernel_accel = 1024; user_options->backend_vector_width = 1; - user_options->outfile_format = hcstrdup ("2"); + user_options->outfile_format = OUTFILE_FMT_PLAIN; user_options->quiet = true; if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) @@ -1738,7 +1736,7 @@ void user_options_preprocess (hashcat_ctx_t *hashcat_ctx) if (user_options->left == true) { - user_options->outfile_format = hcstrdup ("1"); + user_options->outfile_format = OUTFILE_FMT_HASH; } if (user_options->show == true || user_options->left == true) @@ -2845,7 +2843,6 @@ void user_options_logger (hashcat_ctx_t *hashcat_ctx) logfile_top_string (user_options->opencl_device_types); logfile_top_string (user_options->outfile); logfile_top_string (user_options->outfile_check_dir); - logfile_top_string (user_options->outfile_format); logfile_top_string (user_options->potfile_path); logfile_top_string (user_options->restore_file_path); logfile_top_string (user_options->rp_files[0]); @@ -2894,6 +2891,7 @@ void user_options_logger (hashcat_ctx_t *hashcat_ctx) logfile_top_uint (user_options->optimized_kernel_enable); logfile_top_uint (user_options->outfile_autohex); logfile_top_uint (user_options->outfile_check_timer); + logfile_top_uint (user_options->outfile_format); logfile_top_uint (user_options->wordlist_autohex_disable); logfile_top_uint (user_options->potfile_disable); logfile_top_uint (user_options->progress_only);