From c008b11de38c1de45a843e889d20faf3bd55ad92 Mon Sep 17 00:00:00 2001 From: jsteube Date: Wed, 21 Sep 2016 16:07:49 +0200 Subject: [PATCH] Make more use of new user_options_t* --- include/common.h | 2 + include/hash_management.h | 4 +- include/opencl.h | 6 +- include/session.h | 2 +- include/types.h | 32 +- src/autotune.c | 6 +- src/dispatch.c | 4 +- src/ext_ADL.c | 2 +- src/ext_nvapi.c | 2 +- src/ext_nvml.c | 6 +- src/ext_xnvctrl.c | 12 +- src/hash_management.c | 112 +++---- src/hashcat.c | 639 +++++++++++++++++--------------------- src/monitor.c | 20 +- src/opencl.c | 181 ++++++----- src/outfile_check.c | 2 +- src/session.c | 30 +- src/status.c | 6 +- src/terminal.c | 10 +- src/user_options.c | 162 +++++++--- src/wordlist.c | 10 +- 21 files changed, 591 insertions(+), 659 deletions(-) diff --git a/include/common.h b/include/common.h index b43104c34..fd3e25b9d 100644 --- a/include/common.h +++ b/include/common.h @@ -6,6 +6,8 @@ #ifndef _COMMON_H #define _COMMON_H +#define PROGNAME "hashcat" + #if defined (__linux__) #define _POSIX #elif defined (__APPLE__) diff --git a/include/hash_management.h b/include/hash_management.h index 77833b648..dc456f204 100644 --- a/include/hash_management.h +++ b/include/hash_management.h @@ -17,8 +17,8 @@ void check_hash (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, plai int check_cracked (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, hashes_t *hashes, const uint salt_pos); -int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfile_ctx_t *potfile_ctx, outfile_ctx_t *outfile_ctx, char *hash_or_file, const uint keyspace, const uint quiet, const uint benchmark, const bool opencl_info, const uint stdout_flag, const uint username, const uint remove, const uint show, const uint left); -int hashes_init_stage2 (hashes_t *hashes, const hashconfig_t *hashconfig, opencl_ctx_t *opencl_ctx, const uint username, const uint remove, const uint show); +int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfile_ctx_t *potfile_ctx, outfile_ctx_t *outfile_ctx, user_options_t *user_options, char *hash_or_file); +int hashes_init_stage2 (hashes_t *hashes, const hashconfig_t *hashconfig, opencl_ctx_t *opencl_ctx, user_options_t *user_options); void hashes_destroy (hashes_t *hashes); diff --git a/include/opencl.h b/include/opencl.h index d0c68d9a8..97af1ed89 100644 --- a/include/opencl.h +++ b/include/opencl.h @@ -85,13 +85,13 @@ int run_copy (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashcon int run_cracker (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, hashes_t *hashes, const uint pws_cnt); -int opencl_ctx_init (opencl_ctx_t *opencl_ctx, const char *opencl_platforms, const char *opencl_devices, const char *opencl_device_types, const uint opencl_vector_width, const uint opencl_vector_width_chgd, const uint nvidia_spin_damp, const uint nvidia_spin_damp_chgd, const uint workload_profile, const uint kernel_accel, const uint kernel_accel_chgd, const uint kernel_loops, const uint kernel_loops_chgd, const uint keyspace, const uint stdout_flag); +int opencl_ctx_init (opencl_ctx_t *opencl_ctx, const user_options_t *user_options); void opencl_ctx_destroy (opencl_ctx_t *opencl_ctx); -int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, const tuning_db_t *tuning_db, const uint attack_mode, const bool quiet, const bool force, const bool benchmark, const bool opencl_info, const bool machine_readable, const uint algorithm_pos); +int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, const tuning_db_t *tuning_db, const user_options_t *user_options, const uint algorithm_pos); void opencl_ctx_devices_destroy (opencl_ctx_t *opencl_ctx); -int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, const hashes_t *hashes, const session_ctx_t *session_ctx); +int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, const hashes_t *hashes, const session_ctx_t *session_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra); int opencl_session_destroy (opencl_ctx_t *opencl_ctx); #endif // _OPENCL_H diff --git a/include/session.h b/include/session.h index 56be15af8..92c3c54e0 100644 --- a/include/session.h +++ b/include/session.h @@ -6,7 +6,7 @@ #ifndef _SESSION_H #define _SESSION_H -void session_ctx_init (session_ctx_t *session_ctx, const bool quiet, const bool force, const bool benchmark, const u32 scrypt_tmto, char *cwd, char *install_dir, char *profile_dir, char *session_dir, char *shared_dir, char *cpath_real, const u32 wordlist_mode, char *rule_buf_l, char *rule_buf_r, const int rule_len_l, const int rule_len_r, const u32 kernel_rules_cnt, kernel_rule_t *kernel_rules_buf, const u32 attack_mode, const u32 attack_kern, const u32 bitmap_size, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, u32 *bitmap_s1_a, u32 *bitmap_s1_b, u32 *bitmap_s1_c, u32 *bitmap_s1_d, u32 *bitmap_s2_a, u32 *bitmap_s2_b, u32 *bitmap_s2_c, u32 *bitmap_s2_d); +void session_ctx_init (session_ctx_t *session_ctx, char *cwd, char *install_dir, char *profile_dir, char *session_dir, char *shared_dir, char *cpath_real, const u32 wordlist_mode, const u32 kernel_rules_cnt, kernel_rule_t *kernel_rules_buf,const u32 bitmap_size, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, u32 *bitmap_s1_a, u32 *bitmap_s1_b, u32 *bitmap_s1_c, u32 *bitmap_s1_d, u32 *bitmap_s2_a, u32 *bitmap_s2_b, u32 *bitmap_s2_c, u32 *bitmap_s2_d); void session_ctx_destroy (session_ctx_t *session_ctx); diff --git a/include/types.h b/include/types.h index d86f79d9a..5d5a9fffd 100644 --- a/include/types.h +++ b/include/types.h @@ -513,19 +513,7 @@ typedef struct u32 devices_filter; cl_device_type device_types_filter; - u32 opencl_vector_width; - u32 opencl_vector_width_chgd; - - u32 nvidia_spin_damp; - u32 nvidia_spin_damp_chgd; - - u32 kernel_loops; - u32 kernel_loops_chgd; - - u32 kernel_accel; - u32 kernel_accel_chgd; - - u32 workload_profile; + double target_ms; int need_adl; int need_nvml; @@ -856,18 +844,16 @@ typedef struct typedef struct { u32 attack_kern; + + u32 rule_len_r; + u32 rule_len_l; + int optind; } user_options_extra_t; typedef struct { - bool quiet; - bool force; - bool benchmark; - - u32 scrypt_tmto; - char *cwd; char *install_dir; char *profile_dir; @@ -877,17 +863,9 @@ typedef struct u32 wordlist_mode; - char *rule_buf_l; - char *rule_buf_r; - int rule_len_l; - int rule_len_r; - u32 kernel_rules_cnt; kernel_rule_t *kernel_rules_buf; - u32 attack_mode; - u32 attack_kern; - u32 bitmap_size; u32 bitmap_mask; u32 bitmap_shift1; diff --git a/src/autotune.c b/src/autotune.c index cd7aee160..f27a646da 100644 --- a/src/autotune.c +++ b/src/autotune.c @@ -32,8 +32,6 @@ extern hc_global_data_t data; -static double TARGET_MS_PROFILE[4] = { 2, 12, 96, 480 }; - static double try_run (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig, const u32 kernel_accel, const u32 kernel_loops) { const u32 kernel_power_try = device_param->device_processors * device_param->kernel_threads * kernel_accel; @@ -58,7 +56,7 @@ static double try_run (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param int autotune (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashconfig_t *hashconfig) { - const double target_ms = TARGET_MS_PROFILE[opencl_ctx->workload_profile - 1]; + const double target_ms = opencl_ctx->target_ms; const u32 kernel_accel_min = device_param->kernel_accel_min; const u32 kernel_accel_max = device_param->kernel_accel_max; @@ -296,7 +294,7 @@ int autotune (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hashcon #if defined (DEBUG) - if (data.quiet == 0) + if (data.quiet == false) { clear_prompt (); diff --git a/src/dispatch.c b/src/dispatch.c index 67e16357d..933e9897c 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -40,7 +40,7 @@ extern hc_global_data_t data; static void set_kernel_power_final (const u64 kernel_power_final) { - if (data.quiet == 0) + if (data.quiet == false) { clear_prompt (); @@ -280,7 +280,7 @@ void *thread_calc (void *p) if (opencl_ctx->run_thread_level1 == false) break; - if (data.benchmark == 1) break; + if (data.benchmark == true) break; device_param->words_done = words_fin; } diff --git a/src/ext_ADL.c b/src/ext_ADL.c index 1a2bc4076..01504fcc1 100644 --- a/src/ext_ADL.c +++ b/src/ext_ADL.c @@ -28,7 +28,7 @@ int adl_init (ADL_PTR *adl) if (!adl->lib) { - //if (data.quiet == 0) + //if (data.quiet == false) // log_info ("WARNING: load ADL library failed, proceed without ADL HWMon enabled."); return -1; diff --git a/src/ext_nvapi.c b/src/ext_nvapi.c index 1da3da02b..082f3a6a6 100644 --- a/src/ext_nvapi.c +++ b/src/ext_nvapi.c @@ -27,7 +27,7 @@ int nvapi_init (NVAPI_PTR *nvapi) if (!nvapi->lib) { - //if (data.quiet == 0) + //if (data.quiet == false) // log_info ("WARNING: load NVAPI library failed, proceed without NVAPI HWMon enabled."); return -1; diff --git a/src/ext_nvml.c b/src/ext_nvml.c index d4479cc7e..425e8fec7 100644 --- a/src/ext_nvml.c +++ b/src/ext_nvml.c @@ -36,7 +36,7 @@ int nvml_init (NVML_PTR *nvml) } else { - //if (data.quiet == 0) + //if (data.quiet == false) // log_info ("WARNING: NVML library load failed, proceed without NVML HWMon enabled."); return -1; @@ -46,7 +46,7 @@ int nvml_init (NVML_PTR *nvml) } else { - //if (data.quiet == 0) + //if (data.quiet == false) // log_info ("WARNING: NVML library load failed, proceed without NVML HWMon enabled."); return -1; @@ -65,7 +65,7 @@ int nvml_init (NVML_PTR *nvml) if (!nvml->lib) { - //if (data.quiet == 0) + //if (data.quiet == false) // log_info ("WARNING: NVML library load failed, proceed without NVML HWMon enabled."); return -1; diff --git a/src/ext_xnvctrl.c b/src/ext_xnvctrl.c index 7f89c652d..2abaf530c 100644 --- a/src/ext_xnvctrl.c +++ b/src/ext_xnvctrl.c @@ -26,9 +26,9 @@ int xnvctrl_init (XNVCTRL_PTR *xnvctrl) if (xnvctrl->lib_x11 == NULL) { - //if (data.quiet == 0) log_info ("WARNING: Failed loading the X11 library: %s", dlerror()); - //if (data.quiet == 0) log_info (" Please install libx11-dev package."); - //if (data.quiet == 0) log_info (""); + //if (data.quiet == false) log_info ("WARNING: Failed loading the X11 library: %s", dlerror()); + //if (data.quiet == false) log_info (" Please install libx11-dev package."); + //if (data.quiet == false) log_info (""); return -1; } @@ -37,9 +37,9 @@ int xnvctrl_init (XNVCTRL_PTR *xnvctrl) if (xnvctrl->lib_xnvctrl == NULL) { - //if (data.quiet == 0) log_info ("WARNING: Failed loading the XNVCTRL library: %s", dlerror()); - //if (data.quiet == 0) log_info (" Please install libxnvctrl-dev package."); - //if (data.quiet == 0) log_info (""); + //if (data.quiet == false) log_info ("WARNING: Failed loading the XNVCTRL library: %s", dlerror()); + //if (data.quiet == false) log_info (" Please install libxnvctrl-dev package."); + //if (data.quiet == false) log_info (""); return -1; } diff --git a/src/hash_management.c b/src/hash_management.c index c00c5e7f5..58f2ce3b7 100644 --- a/src/hash_management.c +++ b/src/hash_management.c @@ -469,7 +469,7 @@ void check_hash (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, plai outfile_write_open (outfile_ctx); - if (outfile_ctx->filename == NULL) if (quiet == 0) clear_prompt (); + if (outfile_ctx->filename == NULL) if (quiet == false) clear_prompt (); outfile_write (outfile_ctx, out_buf, plain_ptr, plain_len, crackpos, NULL, 0, hashconfig); @@ -479,7 +479,7 @@ void check_hash (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, plai { if ((opencl_ctx->devices_status != STATUS_CRACKED) && (data.status != 1)) { - if (outfile_ctx->filename == NULL) if (quiet == 0) send_prompt (); + if (outfile_ctx->filename == NULL) if (quiet == false) send_prompt (); } } @@ -626,7 +626,7 @@ int check_cracked (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, ha return 0; } -int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfile_ctx_t *potfile_ctx, outfile_ctx_t *outfile_ctx, char *hash_or_file, const uint keyspace, const uint quiet, const uint benchmark, const bool opencl_info, const uint stdout_flag, const uint username, const uint remove, const uint show, const uint left) +int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfile_ctx_t *potfile_ctx, outfile_ctx_t *outfile_ctx, user_options_t *user_options, char *hash_or_file) { /** * load hashes, part I: find input mode, count hashes @@ -637,7 +637,7 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil uint hashes_avail = 0; - if ((benchmark == 0) && (stdout_flag == 0)) + if ((user_options->benchmark == false) && (user_options->stdout_flag == false)) { struct stat f; @@ -691,7 +691,7 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil return -1; } - if (quiet == 0) log_info_nn ("Counting lines in %s", hashfile); + if (user_options->quiet == false) log_info_nn ("Counting lines in %s", hashfile); hashes_avail = count_lines (fp); @@ -708,7 +708,7 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil hashlist_format = hlfmt_detect (fp, 100, hashconfig); // 100 = max numbers to "scan". could be hashes_avail, too - if ((remove == 1) && (hashlist_format != HLFMT_HASHCAT)) + if ((user_options->remove == 1) && (hashlist_format != HLFMT_HASHCAT)) { log_error ("ERROR: remove not supported in native hashfile-format mode"); @@ -745,7 +745,7 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil digests_buf = (void *) mycalloc (hashes_avail, hashconfig->dgst_size); - if ((username && (remove || show)) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) + if ((user_options->username && (user_options->remove || user_options->show)) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) { u32 hash_pos; @@ -755,12 +755,12 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil hashes_buf[hash_pos].hash_info = hash_info; - if (username && (remove || show || left)) + if (user_options->username && (user_options->remove || user_options->show || user_options->left)) { hash_info->user = (user_t*) mymalloc (sizeof (user_t)); } - if (benchmark) + if (user_options->benchmark) { hash_info->orighash = (char *) mymalloc (256); } @@ -811,18 +811,28 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil uint hashes_cnt = 0; - if (benchmark == 0 && !opencl_info) + if (user_options->benchmark == true) { - if (keyspace == 1) - { - // useless to read hash file for keyspace, cheat a little bit w/ optind - } - else if (stdout_flag == 1) - { - // useless to read hash file for stdout, cheat a little bit w/ optind - } - else if (hashes_avail == 0) + hashconfig_benchmark_defaults ((hashconfig_t *) hashconfig, hashes_buf[0].salt, hashes_buf[0].esalt); + + hashes->hashfile = "-"; + + hashes_cnt = 1; + } + else if (user_options->keyspace == true) + { + } + else if (user_options->stdout_flag == true) + { + } + else if (user_options->opencl_info == true) + { + } + else + { + if (hashes_avail == 0) { + // ??? } else if (hashlist_mode == HL_MODE_ARG) { @@ -917,7 +927,7 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil // hack: append MAC1 and MAC2 s.t. in --show and --left the line matches with the .pot file format (i.e. ESSID:MAC1:MAC2) - if ((show == 1) || (left == 1)) + if ((user_options->show == true) || (user_options->left == true)) { salt_t *tmp_salt = hashes_buf[hashes_cnt].salt; @@ -956,8 +966,8 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil tmp_salt->salt_len += 1 + 12 + 1 + 12; } - if (show == 1) potfile_show_request (potfile_ctx, hashconfig, outfile_ctx, (char *) hashes_buf[hashes_cnt].salt->salt_buf, hashes_buf[hashes_cnt].salt->salt_len, &hashes_buf[hashes_cnt], sort_by_salt_buf); - if (left == 1) potfile_left_request (potfile_ctx, hashconfig, outfile_ctx, (char *) hashes_buf[hashes_cnt].salt->salt_buf, hashes_buf[hashes_cnt].salt->salt_len, &hashes_buf[hashes_cnt], sort_by_salt_buf); + if (user_options->show == true) potfile_show_request (potfile_ctx, hashconfig, outfile_ctx, (char *) hashes_buf[hashes_cnt].salt->salt_buf, hashes_buf[hashes_cnt].salt->salt_len, &hashes_buf[hashes_cnt], sort_by_salt_buf); + if (user_options->left == true) potfile_left_request (potfile_ctx, hashconfig, outfile_ctx, (char *) hashes_buf[hashes_cnt].salt->salt_buf, hashes_buf[hashes_cnt].salt->salt_len, &hashes_buf[hashes_cnt], sort_by_salt_buf); hashes_cnt++; } @@ -1004,8 +1014,8 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil if ((lm_hash_left != NULL) && (lm_hash_right != NULL)) { - if (show == 1) potfile_show_request_lm (potfile_ctx, hashconfig, outfile_ctx, input_buf, input_len, lm_hash_left, lm_hash_right, sort_by_pot); - if (left == 1) potfile_left_request_lm (potfile_ctx, hashconfig, outfile_ctx, input_buf, input_len, lm_hash_left, lm_hash_right, sort_by_pot); + if (user_options->show == true) potfile_show_request_lm (potfile_ctx, hashconfig, outfile_ctx, input_buf, input_len, lm_hash_left, lm_hash_right, sort_by_pot); + if (user_options->left == true) potfile_left_request_lm (potfile_ctx, hashconfig, outfile_ctx, input_buf, input_len, lm_hash_left, lm_hash_right, sort_by_pot); } } else @@ -1014,8 +1024,8 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil if (parser_status == PARSER_OK) { - if (show == 1) potfile_show_request (potfile_ctx, hashconfig, outfile_ctx, input_buf, input_len, &hashes_buf[hashes_cnt], sort_by_pot); - if (left == 1) potfile_left_request (potfile_ctx, hashconfig, outfile_ctx, input_buf, input_len, &hashes_buf[hashes_cnt], sort_by_pot); + if (user_options->show == true) potfile_show_request (potfile_ctx, hashconfig, outfile_ctx, input_buf, input_len, &hashes_buf[hashes_cnt], sort_by_pot); + if (user_options->left == true) potfile_left_request (potfile_ctx, hashconfig, outfile_ctx, input_buf, input_len, &hashes_buf[hashes_cnt], sort_by_pot); } if (parser_status == PARSER_OK) @@ -1034,8 +1044,8 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil if (parser_status == PARSER_OK) { - if (show == 1) potfile_show_request (potfile_ctx, hashconfig, outfile_ctx, input_buf, input_len, &hashes_buf[hashes_cnt], sort_by_pot); - if (left == 1) potfile_left_request (potfile_ctx, hashconfig, outfile_ctx, input_buf, input_len, &hashes_buf[hashes_cnt], sort_by_pot); + if (user_options->show == true) potfile_show_request (potfile_ctx, hashconfig, outfile_ctx, input_buf, input_len, &hashes_buf[hashes_cnt], sort_by_pot); + if (user_options->left == true) potfile_left_request (potfile_ctx, hashconfig, outfile_ctx, input_buf, input_len, &hashes_buf[hashes_cnt], sort_by_pot); } if (parser_status == PARSER_OK) @@ -1091,14 +1101,14 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil continue; } - if (username) + if (user_options->username) { char *user_buf = NULL; int user_len = 0; hlfmt_user (hashlist_format, line_buf, line_len, &user_buf, &user_len, hashconfig); - if (remove || show) + if (user_options->remove || user_options->show) { user_t **user = &hashes_buf[hashes_cnt].hash_info->user; @@ -1159,14 +1169,14 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil hash_t *lm_hash_right = &hashes_buf[hashes_cnt]; - if (data.quiet == 0) if ((hashes_cnt % 0x20000) == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((double) hashes_cnt / hashes_avail) * 100); + if (user_options->quiet == false) if ((hashes_cnt % 0x20000) == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((double) hashes_cnt / hashes_avail) * 100); hashes_cnt++; // show / left - if (show == 1) potfile_show_request_lm (potfile_ctx, hashconfig, outfile_ctx, line_buf, line_len, lm_hash_left, lm_hash_right, sort_by_pot); - if (left == 1) potfile_left_request_lm (potfile_ctx, hashconfig, outfile_ctx, line_buf, line_len, lm_hash_left, lm_hash_right, sort_by_pot); + if (user_options->show == true) potfile_show_request_lm (potfile_ctx, hashconfig, outfile_ctx, line_buf, line_len, lm_hash_left, lm_hash_right, sort_by_pot); + if (user_options->left == true) potfile_left_request_lm (potfile_ctx, hashconfig, outfile_ctx, line_buf, line_len, lm_hash_left, lm_hash_right, sort_by_pot); } else { @@ -1179,10 +1189,10 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil continue; } - if (data.quiet == 0) if ((hashes_cnt % 0x20000) == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((double) hashes_cnt / hashes_avail) * 100); + if (user_options->quiet == false) if ((hashes_cnt % 0x20000) == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((double) hashes_cnt / hashes_avail) * 100); - if (show == 1) potfile_show_request (potfile_ctx, hashconfig, outfile_ctx, line_buf, line_len, &hashes_buf[hashes_cnt], sort_by_pot); - if (left == 1) potfile_left_request (potfile_ctx, hashconfig, outfile_ctx, line_buf, line_len, &hashes_buf[hashes_cnt], sort_by_pot); + if (user_options->show == true) potfile_show_request (potfile_ctx, hashconfig, outfile_ctx, line_buf, line_len, &hashes_buf[hashes_cnt], sort_by_pot); + if (user_options->left == true) potfile_left_request (potfile_ctx, hashconfig, outfile_ctx, line_buf, line_len, &hashes_buf[hashes_cnt], sort_by_pot); hashes_cnt++; } @@ -1198,10 +1208,10 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil continue; } - if (data.quiet == 0) if ((hashes_cnt % 0x20000) == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((double) hashes_cnt / hashes_avail) * 100); + if (user_options->quiet == false) if ((hashes_cnt % 0x20000) == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((double) hashes_cnt / hashes_avail) * 100); - if (show == 1) potfile_show_request (potfile_ctx, hashconfig, outfile_ctx, line_buf, line_len, &hashes_buf[hashes_cnt], sort_by_pot); - if (left == 1) potfile_left_request (potfile_ctx, hashconfig, outfile_ctx, line_buf, line_len, &hashes_buf[hashes_cnt], sort_by_pot); + if (user_options->show == true) potfile_show_request (potfile_ctx, hashconfig, outfile_ctx, line_buf, line_len, &hashes_buf[hashes_cnt], sort_by_pot); + if (user_options->left == true) potfile_left_request (potfile_ctx, hashconfig, outfile_ctx, line_buf, line_len, &hashes_buf[hashes_cnt], sort_by_pot); hashes_cnt++; } @@ -1211,17 +1221,9 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil fclose (fp); - if (data.quiet == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_avail, hashes_avail, 100.00); + if (user_options->quiet == false) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_avail, hashes_avail, 100.00); } } - else - { - hashconfig_benchmark_defaults ((hashconfig_t *) hashconfig, hashes_buf[0].salt, hashes_buf[0].esalt); - - hashes->hashfile = "-"; - - hashes_cnt = 1; - } hashes->hashes_cnt = hashes_cnt; @@ -1237,7 +1239,7 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil return 0; } -int hashes_init_stage2 (hashes_t *hashes, const hashconfig_t *hashconfig, opencl_ctx_t *opencl_ctx, const uint username, const uint remove, const uint show) +int hashes_init_stage2 (hashes_t *hashes, const hashconfig_t *hashconfig, opencl_ctx_t *opencl_ctx, user_options_t *user_options) { hash_t *hashes_buf = hashes->hashes_buf; uint hashes_cnt = hashes->hashes_cnt; @@ -1246,7 +1248,7 @@ int hashes_init_stage2 (hashes_t *hashes, const hashconfig_t *hashconfig, opencl * Remove duplicates */ - if (data.quiet == 0) log_info_nn ("Removing duplicate hashes..."); + if (user_options->quiet == false) log_info_nn ("Removing duplicate hashes..."); hashes_cnt = 1; @@ -1296,7 +1298,7 @@ int hashes_init_stage2 (hashes_t *hashes, const hashconfig_t *hashconfig, opencl salts_buf_new = (salt_t *) mycalloc (1, sizeof (salt_t)); } - if (data.quiet == 0) log_info_nn ("Structuring salts for cracking task..."); + if (user_options->quiet == false) log_info_nn ("Structuring salts for cracking task..."); uint digests_cnt = hashes_cnt; uint digests_done = 0; @@ -1309,11 +1311,11 @@ int hashes_init_stage2 (hashes_t *hashes, const hashconfig_t *hashconfig, opencl hashinfo_t **hash_info = NULL; - if ((username && (remove || show)) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) + if ((user_options->username && (user_options->remove || user_options->show)) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) { hash_info = (hashinfo_t **) mycalloc (hashes_cnt, sizeof (hashinfo_t *)); - if (username && (remove || show)) + if (user_options->username && (user_options->remove || user_options->show)) { uint user_pos; @@ -1362,7 +1364,7 @@ int hashes_init_stage2 (hashes_t *hashes, const hashconfig_t *hashconfig, opencl memcpy (((char *) digests_buf_new) + (0 * hashconfig->dgst_size), hashes_buf[0].digest, hashconfig->dgst_size); - if ((username && (remove || show)) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) + if ((user_options->username && (user_options->remove || user_options->show)) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) { hash_info[0] = hashes_buf[0].hash_info; } @@ -1405,7 +1407,7 @@ int hashes_init_stage2 (hashes_t *hashes, const hashconfig_t *hashconfig, opencl memcpy (((char *) digests_buf_new) + (hashes_pos * hashconfig->dgst_size), hashes_buf[hashes_pos].digest, hashconfig->dgst_size); - if ((username && (remove || show)) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) + if ((user_options->username && (user_options->remove || user_options->show)) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) { hash_info[hashes_pos] = hashes_buf[hashes_pos].hash_info; } diff --git a/src/hashcat.c b/src/hashcat.c index 1a9107fca..11811fe61 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -100,8 +100,6 @@ extern const unsigned int full80; extern const int DEFAULT_BENCHMARK_ALGORITHMS_BUF[]; -static const char PROGNAME[] = "hashcat"; - const int comptime = COMPTIME; @@ -198,14 +196,11 @@ int main (int argc, char **argv) uint usage = USAGE; uint version = VERSION; - uint quiet = QUIET; uint benchmark = BENCHMARK; uint stdout_flag = STDOUT_FLAG; uint show = SHOW; uint left = LEFT; - uint username = USERNAME; uint remove = REMOVE; - uint remove_timer = REMOVE_TIMER; u64 skip = SKIP; u64 limit = LIMIT; uint keyspace = KEYSPACE; @@ -215,8 +210,6 @@ int main (int argc, char **argv) char *debug_file = NULL; char *induction_dir = NULL; char *outfile_check_dir = NULL; - uint force = FORCE; - uint runtime = RUNTIME; uint hash_mode = HASH_MODE; uint attack_mode = ATTACK_MODE; uint markov_disable = MARKOV_DISABLE; @@ -236,40 +229,30 @@ int main (int argc, char **argv) uint loopback = LOOPBACK; uint weak_hash_threshold = WEAK_HASH_THRESHOLD; char *session = NULL; - uint hex_charset = HEX_CHARSET; uint hex_salt = HEX_SALT; - uint hex_wordlist = HEX_WORDLIST; uint rp_gen = RP_GEN; uint rp_gen_func_min = RP_GEN_FUNC_MIN; uint rp_gen_func_max = RP_GEN_FUNC_MAX; - uint rp_gen_seed = RP_GEN_SEED; char *rule_buf_l = (char *) RULE_BUF_L; char *rule_buf_r = (char *) RULE_BUF_R; uint increment = INCREMENT; uint increment_min = INCREMENT_MIN; uint increment_max = INCREMENT_MAX; - char *cpu_affinity = NULL; - bool opencl_info = 0; - char *opencl_devices = NULL; - char *opencl_platforms = NULL; - char *opencl_device_types = NULL; - uint opencl_vector_width = OPENCL_VECTOR_WIDTH; + + + + char *truecrypt_keyfiles = NULL; char *veracrypt_keyfiles = NULL; - uint veracrypt_pim = 0; - uint workload_profile = WORKLOAD_PROFILE; - uint kernel_accel = KERNEL_ACCEL; - uint kernel_loops = KERNEL_LOOPS; - uint nvidia_spin_damp = NVIDIA_SPIN_DAMP; + + uint gpu_temp_disable = GPU_TEMP_DISABLE; #if defined (HAVE_HWMON) uint gpu_temp_abort = GPU_TEMP_ABORT; uint gpu_temp_retain = GPU_TEMP_RETAIN; uint powertune_enable = POWERTUNE_ENABLE; #endif - uint logfile_disable = LOGFILE_DISABLE; uint segment_size = SEGMENT_SIZE; - uint scrypt_tmto = SCRYPT_TMTO; char separator = SEPARATOR; uint bitmap_min = BITMAP_MIN; uint bitmap_max = BITMAP_MAX; @@ -495,16 +478,16 @@ int main (int argc, char **argv) data.eff_restore_file = eff_restore_file; data.new_restore_file = new_restore_file; - if (((show == 1) || (left == 1)) && (restore == 1)) + if (((show == true) || (left == true)) && (restore == true)) { - if (show == 1) log_error ("ERROR: Mixing --restore parameter and --show is not supported"); + if (show == true) log_error ("ERROR: Mixing --restore parameter and --show is not supported"); else log_error ("ERROR: Mixing --restore parameter and --left is not supported"); return -1; } // this allows the user to use --show and --left while cracking (i.e. while another instance of hashcat is running) - if ((show == 1) || (left == 1)) + if ((show == true) || (left == true)) { restore_disable = 1; @@ -521,7 +504,7 @@ int main (int argc, char **argv) * restore file */ - if (restore == 1) + if (restore == true) { read_restore (eff_restore_file, rd); @@ -543,138 +526,10 @@ int main (int argc, char **argv) } uint hash_mode_chgd = 0; - uint runtime_chgd = 0; - uint kernel_loops_chgd = 0; - uint kernel_accel_chgd = 0; - uint nvidia_spin_damp_chgd = 0; - uint attack_mode_chgd = 0; - uint outfile_format_chgd = 0; - uint rp_gen_seed_chgd = 0; - uint remove_timer_chgd = 0; - uint increment_min_chgd = 0; - uint increment_max_chgd = 0; - uint workload_profile_chgd = 0; - uint opencl_vector_width_chgd = 0; - optind = 1; - optopt = 0; - option_index = 0; - while (((c = getopt_long (myargc, myargv, short_options, long_options, &option_index)) != -1) && optopt == 0) - { - switch (c) - { - //case IDX_HELP: usage = 1; break; - //case IDX_VERSION: version = 1; break; - //case IDX_RESTORE: restore = 1; break; - case IDX_QUIET: quiet = 1; break; - //case IDX_SHOW: show = 1; break; - case IDX_SHOW: break; - //case IDX_LEFT: left = 1; break; - case IDX_LEFT: break; - case IDX_USERNAME: username = 1; break; - case IDX_REMOVE: remove = 1; break; - case IDX_REMOVE_TIMER: remove_timer = atoi (optarg); - remove_timer_chgd = 1; break; - case IDX_POTFILE_DISABLE: potfile_disable = 1; break; - case IDX_POTFILE_PATH: potfile_path = optarg; break; - case IDX_DEBUG_MODE: debug_mode = atoi (optarg); break; - case IDX_DEBUG_FILE: debug_file = optarg; break; - case IDX_INDUCTION_DIR: induction_dir = optarg; break; - case IDX_OUTFILE_CHECK_DIR: outfile_check_dir = optarg; break; - case IDX_FORCE: force = 1; break; - case IDX_SKIP: skip = atoll (optarg); break; - case IDX_LIMIT: limit = atoll (optarg); break; - case IDX_KEYSPACE: keyspace = 1; break; - case IDX_BENCHMARK: benchmark = 1; break; - case IDX_STDOUT_FLAG: stdout_flag = 1; break; - case IDX_RESTORE: break; - case IDX_RESTORE_DISABLE: restore_disable = 1; break; - case IDX_STATUS: status = 1; break; - case IDX_STATUS_TIMER: status_timer = atoi (optarg); break; - case IDX_MACHINE_READABLE: machine_readable = 1; break; - case IDX_LOOPBACK: loopback = 1; break; - case IDX_WEAK_HASH_THRESHOLD: weak_hash_threshold = atoi (optarg); break; - //case IDX_SESSION: session = optarg; break; - case IDX_SESSION: break; - case IDX_HASH_MODE: hash_mode = atoi (optarg); - hash_mode_chgd = 1; break; - case IDX_RUNTIME: runtime = atoi (optarg); - runtime_chgd = 1; break; - case IDX_ATTACK_MODE: attack_mode = atoi (optarg); - attack_mode_chgd = 1; break; - case IDX_RP_FILE: rp_files[rp_files_cnt++] = optarg; break; - case IDX_RP_GEN: rp_gen = atoi (optarg); break; - case IDX_RP_GEN_FUNC_MIN: rp_gen_func_min = atoi (optarg); break; - case IDX_RP_GEN_FUNC_MAX: rp_gen_func_max = atoi (optarg); break; - case IDX_RP_GEN_SEED: rp_gen_seed = atoi (optarg); - rp_gen_seed_chgd = 1; break; - case IDX_RULE_BUF_L: rule_buf_l = optarg; break; - case IDX_RULE_BUF_R: rule_buf_r = optarg; break; - case IDX_MARKOV_DISABLE: markov_disable = 1; break; - case IDX_MARKOV_CLASSIC: markov_classic = 1; break; - case IDX_MARKOV_THRESHOLD: markov_threshold = atoi (optarg); break; - case IDX_MARKOV_HCSTAT: markov_hcstat = optarg; break; - case IDX_OUTFILE: outfile = optarg; break; - case IDX_OUTFILE_FORMAT: outfile_format = atoi (optarg); - outfile_format_chgd = 1; break; - case IDX_OUTFILE_AUTOHEX_DISABLE: outfile_autohex = 0; break; - case IDX_OUTFILE_CHECK_TIMER: outfile_check_timer = atoi (optarg); break; - case IDX_HEX_CHARSET: hex_charset = 1; break; - case IDX_HEX_SALT: hex_salt = 1; break; - case IDX_HEX_WORDLIST: hex_wordlist = 1; break; - case IDX_CPU_AFFINITY: cpu_affinity = optarg; break; - case IDX_OPENCL_INFO: opencl_info = 1; break; - case IDX_OPENCL_DEVICES: opencl_devices = optarg; break; - case IDX_OPENCL_PLATFORMS: opencl_platforms = optarg; break; - case IDX_OPENCL_DEVICE_TYPES: opencl_device_types = optarg; break; - case IDX_OPENCL_VECTOR_WIDTH: opencl_vector_width = atoi (optarg); - opencl_vector_width_chgd = 1; break; - case IDX_WORKLOAD_PROFILE: workload_profile = atoi (optarg); - workload_profile_chgd = 1; break; - case IDX_KERNEL_ACCEL: kernel_accel = atoi (optarg); - kernel_accel_chgd = 1; break; - case IDX_KERNEL_LOOPS: kernel_loops = atoi (optarg); - kernel_loops_chgd = 1; break; - case IDX_NVIDIA_SPIN_DAMP: nvidia_spin_damp = atoi (optarg); - nvidia_spin_damp_chgd = 1; break; - case IDX_GPU_TEMP_DISABLE: gpu_temp_disable = 1; break; - #if defined (HAVE_HWMON) - case IDX_GPU_TEMP_ABORT: gpu_temp_abort = atoi (optarg); break; - case IDX_GPU_TEMP_RETAIN: gpu_temp_retain = atoi (optarg); break; - case IDX_POWERTUNE_ENABLE: powertune_enable = 1; break; - #endif // HAVE_HWMON - case IDX_LOGFILE_DISABLE: logfile_disable = 1; break; - case IDX_TRUECRYPT_KEYFILES: truecrypt_keyfiles = optarg; break; - case IDX_VERACRYPT_KEYFILES: veracrypt_keyfiles = optarg; break; - case IDX_VERACRYPT_PIM: veracrypt_pim = atoi (optarg); break; - case IDX_SEGMENT_SIZE: segment_size = atoi (optarg); break; - case IDX_SCRYPT_TMTO: scrypt_tmto = atoi (optarg); break; - case IDX_SEPARATOR: separator = optarg[0]; break; - case IDX_BITMAP_MIN: bitmap_min = atoi (optarg); break; - case IDX_BITMAP_MAX: bitmap_max = atoi (optarg); break; - case IDX_INCREMENT: increment = 1; break; - case IDX_INCREMENT_MIN: increment_min = atoi (optarg); - increment_min_chgd = 1; break; - case IDX_INCREMENT_MAX: increment_max = atoi (optarg); - increment_max_chgd = 1; break; - case IDX_CUSTOM_CHARSET_1: custom_charset_1 = optarg; break; - case IDX_CUSTOM_CHARSET_2: custom_charset_2 = optarg; break; - case IDX_CUSTOM_CHARSET_3: custom_charset_3 = optarg; break; - case IDX_CUSTOM_CHARSET_4: custom_charset_4 = optarg; break; - - default: - log_error ("ERROR: Invalid argument specified"); - return -1; - } - } - if (optopt != 0) - { - log_error ("ERROR: Invalid argument specified"); - return -1; - } const int rc_user_options_parse = user_options_parse (user_options, myargc, myargv); @@ -690,6 +545,142 @@ int main (int argc, char **argv) if (rc_user_options_sanity == -1) return -1; + // temporarily start + + + + if (1) + { + attack_mode = user_options->attack_mode; + benchmark = user_options->benchmark; + bitmap_max = user_options->bitmap_max; + bitmap_min = user_options->bitmap_min; + custom_charset_1 = user_options->custom_charset_1; + custom_charset_2 = user_options->custom_charset_2; + custom_charset_3 = user_options->custom_charset_3; + custom_charset_4 = user_options->custom_charset_4; + debug_file = user_options->debug_file; + debug_mode = user_options->debug_mode; + + gpu_temp_abort = user_options->gpu_temp_abort; + gpu_temp_disable = user_options->gpu_temp_disable; + gpu_temp_retain = user_options->gpu_temp_retain; + hash_mode_chgd = user_options->hash_mode_chgd; + hash_mode = user_options->hash_mode; + + hex_salt = user_options->hex_salt; + + increment_max = user_options->increment_max; + increment_min = user_options->increment_min; + increment = user_options->increment; + induction_dir = user_options->induction_dir; + + + + + keyspace = user_options->keyspace; + left = user_options->left; + limit = user_options->limit; + + loopback = user_options->loopback; + machine_readable = user_options->machine_readable; + markov_classic = user_options->markov_classic; + markov_disable = user_options->markov_disable; + markov_hcstat = user_options->markov_hcstat; + markov_threshold = user_options->markov_threshold; + + + + + + + + + outfile_autohex = user_options->outfile_autohex; + outfile_check_dir = user_options->outfile_check_dir; + outfile_check_timer = user_options->outfile_check_timer; + outfile_format = user_options->outfile_format; + outfile = user_options->outfile; + potfile_disable = user_options->potfile_disable; + potfile_path = user_options->potfile_path; + powertune_enable = user_options->powertune_enable; + + + remove = user_options->remove; + restore_disable = user_options->restore_disable; + restore_timer = user_options->restore_timer; + restore = user_options->restore; + rp_files_cnt = user_options->rp_files_cnt; + rp_files = user_options->rp_files; + rp_gen_func_max = user_options->rp_gen_func_max; + rp_gen_func_min = user_options->rp_gen_func_min; + + rp_gen = user_options->rp_gen; + rule_buf_l = user_options->rule_buf_l; + rule_buf_r = user_options->rule_buf_r; + + + segment_size = user_options->segment_size; + separator = user_options->separator; + session = user_options->session; + show = user_options->show; + skip = user_options->skip; + status_timer = user_options->status_timer; + status = user_options->status; + stdout_flag = user_options->stdout_flag; + truecrypt_keyfiles = user_options->truecrypt_keyfiles; + usage = user_options->usage; + + veracrypt_keyfiles = user_options->veracrypt_keyfiles; + + version = user_options->version; + weak_hash_threshold = user_options->weak_hash_threshold; + + + data.restore = user_options->restore; + data.restore_timer = user_options->restore_timer; + data.restore_disable = user_options->restore_disable; + data.status = user_options->status; + data.status_timer = user_options->status_timer; + data.machine_readable = user_options->machine_readable; + data.loopback = user_options->loopback; + data.runtime = user_options->runtime; + data.remove = user_options->remove; + data.remove_timer = user_options->remove_timer; + data.username = user_options->username; + + data.hex_charset = user_options->hex_charset; + data.hex_salt = user_options->hex_salt; + data.hex_wordlist = user_options->hex_wordlist; + data.rp_files = user_options->rp_files; + data.rp_files_cnt = user_options->rp_files_cnt; + data.rp_gen = user_options->rp_gen; + data.rp_gen_seed = user_options->rp_gen_seed; + data.force = user_options->force; + data.benchmark = user_options->benchmark; + data.skip = user_options->skip; + data.limit = user_options->limit; + data.custom_charset_1 = user_options->custom_charset_1; + data.custom_charset_2 = user_options->custom_charset_2; + data.custom_charset_3 = user_options->custom_charset_3; + data.custom_charset_4 = user_options->custom_charset_4; + #if defined (HAVE_HWMONO) + data.powertune_enable = user_options->powertune_enable; + #endif + data.logfile_disable = user_options->logfile_disable; + data.truecrypt_keyfiles = user_options->truecrypt_keyfiles; + data.veracrypt_keyfiles = user_options->veracrypt_keyfiles; + data.veracrypt_pim = user_options->veracrypt_pim; + data.scrypt_tmto = user_options->scrypt_tmto; + + //wordlist_mode = user_options_extra->wordlist_mode; + //attack_kern = user_options_extra->attack_kern; + + + //data.wordlist_mode = wordlist_mode; + //data.attack_kern = attack_kern; + + } /** * Inform user things getting started, @@ -697,11 +688,11 @@ int main (int argc, char **argv) * - we do not need to check algorithm_pos */ - if (quiet == 0) + if (user_options->quiet == false) { - if (benchmark == 1) + if (benchmark == true) { - if (machine_readable == 0) + if (machine_readable == false) { log_info ("%s (%s) starting in benchmark-mode...", PROGNAME, VERSION_TAG); log_info (""); @@ -711,22 +702,22 @@ int main (int argc, char **argv) log_info ("# %s (%s) %s", PROGNAME, VERSION_TAG, ctime (&proc_start)); } } - else if (restore == 1) + else if (restore == true) { log_info ("%s (%s) starting in restore-mode...", PROGNAME, VERSION_TAG); log_info (""); } - else if (stdout_flag == 1) + else if (stdout_flag == true) { // do nothing } - else if (keyspace == 1) + else if (keyspace == true) { // do nothing } else { - if ((show == 1) || (left == 1)) + if ((show == true) || (left == true)) { // do nothing } @@ -746,54 +737,57 @@ int main (int argc, char **argv) if (attack_mode != ATTACK_MODE_BF) { - if (induction_dir == NULL) + if ((user_options->keyspace == false) && (user_options->benchmark == false) && (user_options->opencl_info == false)) { - induction_directory = (char *) mymalloc (session_size); + if (induction_dir == NULL) + { + induction_directory = (char *) mymalloc (session_size); - snprintf (induction_directory, session_size - 1, "%s/%s.%s", session_dir, session, INDUCT_DIR); + snprintf (induction_directory, session_size - 1, "%s/%s.%s", session_dir, session, INDUCT_DIR); - // create induction folder if it does not already exist + // create induction folder if it does not already exist - if (keyspace == 0) - { - if (rmdir (induction_directory) == -1) + if (keyspace == false) { - if (errno == ENOENT) + if (rmdir (induction_directory) == -1) { - // good, we can ignore - } - else if (errno == ENOTEMPTY) - { - char *induction_directory_mv = (char *) mymalloc (session_size); + if (errno == ENOENT) + { + // good, we can ignore + } + else if (errno == ENOTEMPTY) + { + char *induction_directory_mv = (char *) mymalloc (session_size); + + snprintf (induction_directory_mv, session_size - 1, "%s/%s.induct.%d", session_dir, session, (int) proc_start); - snprintf (induction_directory_mv, session_size - 1, "%s/%s.induct.%d", session_dir, session, (int) proc_start); + if (rename (induction_directory, induction_directory_mv) != 0) + { + log_error ("ERROR: Rename directory %s to %s: %s", induction_directory, induction_directory_mv, strerror (errno)); - if (rename (induction_directory, induction_directory_mv) != 0) + return -1; + } + } + else { - log_error ("ERROR: Rename directory %s to %s: %s", induction_directory, induction_directory_mv, strerror (errno)); + log_error ("ERROR: %s: %s", induction_directory, strerror (errno)); return -1; } } - else + + if (mkdir (induction_directory, 0700) == -1) { log_error ("ERROR: %s: %s", induction_directory, strerror (errno)); return -1; } } - - if (mkdir (induction_directory, 0700) == -1) - { - log_error ("ERROR: %s: %s", induction_directory, strerror (errno)); - - return -1; - } } - } - else - { - induction_directory = induction_dir; + else + { + induction_directory = induction_dir; + } } } @@ -815,21 +809,19 @@ int main (int argc, char **argv) char *outfile_check_directory = NULL; - if (outfile_check_dir == NULL) - { - outfile_check_directory = (char *) mymalloc (session_size); - - snprintf (outfile_check_directory, session_size - 1, "%s/%s.%s", session_dir, session, OUTFILES_DIR); - } - else + if ((user_options->keyspace == false) && (user_options->benchmark == false) && (user_options->opencl_info == false)) { - outfile_check_directory = outfile_check_dir; - } + if (outfile_check_dir == NULL) + { + outfile_check_directory = (char *) mymalloc (session_size); - data.outfile_check_directory = outfile_check_directory; + snprintf (outfile_check_directory, session_size - 1, "%s/%s.%s", session_dir, session, OUTFILES_DIR); + } + else + { + outfile_check_directory = outfile_check_dir; + } - if (keyspace == 0) - { struct stat outfile_check_stat; if (stat (outfile_check_directory, &outfile_check_stat) == 0) @@ -854,99 +846,37 @@ int main (int argc, char **argv) } } - /** - * special other stuff - */ - - if (hash_mode == 9710) - { - outfile_format = 5; - outfile_format_chgd = 1; - } - - if (hash_mode == 9810) - { - outfile_format = 5; - outfile_format_chgd = 1; - } - - if (hash_mode == 10410) - { - outfile_format = 5; - outfile_format_chgd = 1; - } - - /** - * store stuff - */ - - data.restore = restore; - data.restore_timer = restore_timer; - data.restore_disable = restore_disable; - data.status = status; - data.status_timer = status_timer; - data.machine_readable = machine_readable; - data.loopback = loopback; - data.runtime = runtime; - data.remove = remove; - data.remove_timer = remove_timer; - - data.username = username; - data.quiet = quiet; - - data.hex_charset = hex_charset; - data.hex_salt = hex_salt; - data.hex_wordlist = hex_wordlist; - data.rp_files = rp_files; - data.rp_files_cnt = rp_files_cnt; - data.rp_gen = rp_gen; - data.rp_gen_seed = rp_gen_seed; - data.force = force; - data.benchmark = benchmark; - data.skip = skip; - data.limit = limit; - data.custom_charset_1 = custom_charset_1; - data.custom_charset_2 = custom_charset_2; - data.custom_charset_3 = custom_charset_3; - data.custom_charset_4 = custom_charset_4; - #if defined (HAVE_HWMONO) - data.powertune_enable = powertune_enable; - #endif - data.logfile_disable = logfile_disable; - data.truecrypt_keyfiles = truecrypt_keyfiles; - data.veracrypt_keyfiles = veracrypt_keyfiles; - data.veracrypt_pim = veracrypt_pim; - data.scrypt_tmto = scrypt_tmto; + data.outfile_check_directory = outfile_check_directory; /** * cpu affinity */ - if (cpu_affinity) + if (user_options->cpu_affinity) { - set_cpu_affinity (cpu_affinity); + set_cpu_affinity (user_options->cpu_affinity); } - if (rp_gen_seed_chgd == 0) + if (user_options->rp_gen_seed_chgd == false) { - srand (proc_start); + srand (user_options->rp_gen_seed); } else { - srand (rp_gen_seed); + srand (proc_start); } /** * logfile init */ - if (logfile_disable == 0) + if (user_options->logfile_disable == 0) { - size_t logfile_size = strlen (session_dir) + 1 + strlen (session) + 32; + size_t logfile_size = strlen (session_dir) + 1 + strlen (user_options->session) + 32; char *logfile = (char *) mymalloc (logfile_size); - snprintf (logfile, logfile_size - 1, "%s/%s.log", session_dir, session); + snprintf (logfile, logfile_size - 1, "%s/%s.log", session_dir, user_options->session); data.logfile = logfile; @@ -1048,7 +978,7 @@ int main (int argc, char **argv) data.opencl_ctx = opencl_ctx; - const int rc_opencl_init = opencl_ctx_init (opencl_ctx, opencl_platforms, opencl_devices, opencl_device_types, opencl_vector_width, opencl_vector_width_chgd, nvidia_spin_damp, nvidia_spin_damp_chgd, workload_profile, kernel_accel, kernel_accel_chgd, kernel_loops, kernel_loops_chgd, keyspace, stdout_flag); + const int rc_opencl_init = opencl_ctx_init (opencl_ctx, user_options); if (rc_opencl_init == -1) { @@ -1061,7 +991,7 @@ int main (int argc, char **argv) * benchmark */ - if (benchmark == 1) + if (benchmark == true) { /** * disable useless stuff for benchmark @@ -1072,7 +1002,7 @@ int main (int argc, char **argv) restore_disable = 1; potfile_disable = 1; weak_hash_threshold = 0; - nvidia_spin_damp = 0; + gpu_temp_disable = 1; outfile_check_timer = 0; @@ -1094,13 +1024,6 @@ int main (int argc, char **argv) attack_mode = ATTACK_MODE_BF; user_options_extra->attack_kern = ATTACK_KERN_BF; - - if (workload_profile_chgd == 0) - { - workload_profile = 3; - - opencl_ctx->workload_profile = workload_profile; - } } data.attack_mode = attack_mode; @@ -1123,7 +1046,7 @@ int main (int argc, char **argv) { // enable status (in stdin mode) whenever we do not use --stdout together with an outfile - if (stdout_flag == 0) status = 1; + if (stdout_flag == false) status = 1; else if (outfile != NULL) status = 1; data.status = status; @@ -1135,7 +1058,7 @@ int main (int argc, char **argv) data.shutdown_outer = 0; - if (keyspace == 0 && benchmark == 0 && stdout_flag == 0) + if (keyspace == false && benchmark == false && stdout_flag == false) { if ((data.wordlist_mode == WL_MODE_FILE) || (data.wordlist_mode == WL_MODE_MASK)) { @@ -1158,7 +1081,7 @@ int main (int argc, char **argv) const int *algorithms = DEFAULT_BENCHMARK_ALGORITHMS_BUF; - if (benchmark == 1 && hash_mode_chgd == 0) algorithm_max = DEFAULT_BENCHMARK_ALGORITHMS_CNT; + if (benchmark == true && hash_mode_chgd == false) algorithm_max = DEFAULT_BENCHMARK_ALGORITHMS_CNT; for (algorithm_pos = 0; algorithm_pos < algorithm_max; algorithm_pos++) { @@ -1188,16 +1111,14 @@ int main (int argc, char **argv) * update hash_mode in case of multihash benchmark */ - if (benchmark == 1) + if (benchmark == true) { - if (hash_mode_chgd == 0) + if (hash_mode_chgd == false) { hash_mode = algorithms[algorithm_pos]; } - quiet = 1; - - data.quiet = quiet; + user_options->quiet = true; } /** @@ -1236,7 +1157,7 @@ int main (int argc, char **argv) potfile_init (potfile_ctx, profile_dir, potfile_path, potfile_disable); - if (show == 1 || left == 1) + if (show == true || left == true) { outfile_write_open (outfile_ctx); @@ -1259,7 +1180,7 @@ int main (int argc, char **argv) data.hashes = hashes; - const int rc_hashes_init_stage1 = hashes_init_stage1 (hashes, hashconfig, potfile_ctx, outfile_ctx, myargv[user_options_extra->optind], keyspace, quiet, benchmark, opencl_info, stdout_flag, username, remove, show, left); + const int rc_hashes_init_stage1 = hashes_init_stage1 (hashes, hashconfig, potfile_ctx, outfile_ctx, user_options, myargv[user_options_extra->optind]); if (rc_hashes_init_stage1 == -1) return -1; @@ -1268,7 +1189,7 @@ int main (int argc, char **argv) logfile_top_uint (hashes->hashlist_mode); logfile_top_uint (hashes->hashlist_format); - if ((keyspace == 0) && (stdout_flag == 0)) + if ((user_options->keyspace == false) && (user_options->stdout_flag == false) && (user_options->opencl_info == false)) { if (hashes->hashes_cnt == 0) { @@ -1278,13 +1199,13 @@ int main (int argc, char **argv) } } - if (show == 1 || left == 1) + if (show == true || left == true) { outfile_write_close (outfile_ctx); potfile_hash_free (potfile_ctx, hashconfig); - if (data.quiet == 0) log_info_nn (""); + if (user_options->quiet == false) log_info_nn (""); return 0; } @@ -1297,7 +1218,7 @@ int main (int argc, char **argv) if (potfile_disable == 0) { - if (data.quiet == 0) log_info_nn ("Comparing hashes with potfile entries..."); + if (user_options->quiet == false) log_info_nn ("Comparing hashes with potfile entries..."); potfile_remove_cracks = potfile_remove_parse (potfile_ctx, hashconfig, hashes); } @@ -1308,7 +1229,7 @@ int main (int argc, char **argv) uint hashes_cnt_orig = hashes->hashes_cnt; - const int rc_hashes_init_stage2 = hashes_init_stage2 (hashes, hashconfig, opencl_ctx, username, remove, show); + const int rc_hashes_init_stage2 = hashes_init_stage2 (hashes, hashconfig, opencl_ctx, user_options); if (rc_hashes_init_stage2 == -1) return -1; @@ -1386,7 +1307,7 @@ int main (int argc, char **argv) dictstat_init (dictstat_ctx, profile_dir); - if (keyspace == 0) + if (keyspace == false) { dictstat_read (dictstat_ctx); } @@ -1476,7 +1397,7 @@ int main (int argc, char **argv) for (bitmap_bits = bitmap_min; bitmap_bits < bitmap_max; bitmap_bits++) { - if (data.quiet == 0) log_info_nn ("Generating bitmap tables with %u bits...", bitmap_bits); + if (user_options->quiet == false) log_info_nn ("Generating bitmap tables with %u bits...", bitmap_bits); bitmap_nums = 1u << bitmap_bits; @@ -1756,7 +1677,7 @@ int main (int argc, char **argv) } } - const int rc_devices_init = opencl_ctx_devices_init (opencl_ctx, hashconfig, tuning_db, attack_mode, quiet, force, benchmark, opencl_info, machine_readable, algorithm_pos); + const int rc_devices_init = opencl_ctx_devices_init (opencl_ctx, hashconfig, tuning_db, user_options, algorithm_pos); if (rc_devices_init == -1) { @@ -1962,7 +1883,7 @@ int main (int argc, char **argv) * enable custom signal handler(s) */ - if (benchmark == 0) + if (benchmark == false) { hc_signal (sigHandler_default); } @@ -1975,7 +1896,7 @@ int main (int argc, char **argv) * inform the user */ - if (data.quiet == 0) + if (user_options->quiet == false) { log_info ("Hashes: %u digests; %u unique digests, %u unique salts", hashes_cnt_orig, hashes->digests_cnt, hashes->salts_cnt); @@ -2026,7 +1947,7 @@ int main (int argc, char **argv) log_info ("Watchdog: Temperature retain trigger set to %uc", gpu_temp_retain); } - if (data.quiet == 0) log_info (""); + if (user_options->quiet == false) log_info (""); #endif } @@ -2268,20 +2189,20 @@ int main (int argc, char **argv) #endif // HAVE_HWMON #if defined (DEBUG) - if (benchmark == 1) log_info ("Hashmode: %d", hashconfig->hash_mode); + if (benchmark == true) log_info ("Hashmode: %d", hashconfig->hash_mode); #endif - if (data.quiet == 0) log_info_nn ("Initializing device kernels and memory..."); + if (user_options->quiet == false) log_info_nn ("Initializing device kernels and memory..."); session_ctx_t *session_ctx = (session_ctx_t *) mymalloc (sizeof (session_ctx_t)); data.session_ctx = session_ctx; - session_ctx_init (session_ctx, quiet, force, benchmark, scrypt_tmto, cwd, install_dir, profile_dir, session_dir, shared_dir, cpath_real, wordlist_mode, rule_buf_l, rule_buf_r, rule_len_l, rule_len_r, kernel_rules_cnt, kernel_rules_buf, attack_mode, user_options_extra->attack_kern, bitmap_size, bitmap_mask, bitmap_shift1, bitmap_shift2, bitmap_s1_a, bitmap_s1_b, bitmap_s1_c, bitmap_s1_d, bitmap_s2_a, bitmap_s2_b, bitmap_s2_c, bitmap_s2_d); + session_ctx_init (session_ctx, cwd, install_dir, profile_dir, session_dir, shared_dir, cpath_real, wordlist_mode, kernel_rules_cnt, kernel_rules_buf, bitmap_size, bitmap_mask, bitmap_shift1, bitmap_shift2, bitmap_s1_a, bitmap_s1_b, bitmap_s1_c, bitmap_s1_d, bitmap_s2_a, bitmap_s2_b, bitmap_s2_c, bitmap_s2_d); - opencl_session_begin (opencl_ctx, hashconfig, hashes, session_ctx); + opencl_session_begin (opencl_ctx, hashconfig, hashes, session_ctx, user_options, user_options_extra); - if (data.quiet == 0) log_info_nn (""); + if (user_options->quiet == false) log_info_nn (""); /** * Store initial fanspeed if gpu_temp_retain is enabled @@ -2356,13 +2277,13 @@ int main (int argc, char **argv) * In benchmark-mode, inform user which algorithm is checked */ - if (benchmark == 1) + if (benchmark == true) { - if (machine_readable == 0) + if (machine_readable == false) { - quiet = 0; + //quiet = 0; - data.quiet = quiet; + //user_options->quiet = quiet; char *hash_type = strhashtype (hashconfig->hash_mode); // not a bug @@ -2464,7 +2385,7 @@ int main (int argc, char **argv) { // do not allow --keyspace w/ a directory - if (keyspace == 1) + if (keyspace == true) { log_error ("ERROR: Keyspace parameter is not allowed together with a directory"); @@ -2589,11 +2510,11 @@ int main (int argc, char **argv) data.combs_cnt = 1; - data.quiet = 1; + //user_options->quiet = 1; const u64 words1_cnt = count_words (wl_data, fp1, dictfile1, dictstat_ctx); - data.quiet = quiet; + //user_options->quiet = quiet; if (words1_cnt == 0) { @@ -2607,11 +2528,11 @@ int main (int argc, char **argv) data.combs_cnt = 1; - data.quiet = 1; + //user_options->quiet = 1; const u64 words2_cnt = count_words (wl_data, fp2, dictfile2, dictstat_ctx); - data.quiet = quiet; + //user_options->quiet = quiet; if (words2_cnt == 0) { @@ -2666,7 +2587,7 @@ int main (int argc, char **argv) maskcnt = 0; - if (benchmark == 0) + if (benchmark == false) { mask = myargv[user_options_extra->optind + 1]; @@ -2908,7 +2829,7 @@ int main (int argc, char **argv) { // do not allow --keyspace w/ a directory - if (keyspace == 1) + if (keyspace == true) { log_error ("ERROR: Keyspace parameter is not allowed together with a directory"); @@ -3087,7 +3008,7 @@ int main (int argc, char **argv) { // do not allow --keyspace w/ a directory - if (keyspace == 1) + if (keyspace == true) { log_error ("ERROR: Keyspace parameter is not allowed together with a directory"); @@ -3185,7 +3106,7 @@ int main (int argc, char **argv) break; } - if (data.quiet == 0) log_info_nn ("Checking for weak hashes..."); + if (user_options->quiet == false) log_info_nn ("Checking for weak hashes..."); for (uint salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) { @@ -3194,7 +3115,7 @@ int main (int argc, char **argv) // Display hack, guarantee that there is at least one \r before real start - //if (data.quiet == 0) log_info (""); + //if (user_options->quiet == false) log_info (""); } /** @@ -3211,7 +3132,7 @@ int main (int argc, char **argv) * Outfile remove */ - if (keyspace == 0 && benchmark == 0 && stdout_flag == 0) + if (keyspace == false && benchmark == false && stdout_flag == false) { hc_thread_create (inner_threads[inner_threads_cnt], thread_monitor, NULL); @@ -3248,7 +3169,7 @@ int main (int argc, char **argv) * main loop */ - if (data.quiet == 0) + if (user_options->quiet == false) { if (potfile_remove_cracks > 0) { @@ -3533,7 +3454,7 @@ int main (int argc, char **argv) if (attack_mode != ATTACK_MODE_BF) { - if (keyspace == 0) + if ((user_options->keyspace == false) && (user_options->benchmark == false) && (user_options->opencl_info == false)) { induction_dictionaries = scan_directory (induction_directory); @@ -3564,7 +3485,7 @@ int main (int argc, char **argv) * prevent the user from using --keyspace together w/ maskfile and or dictfile */ - if (keyspace == 1) + if (keyspace == true) { if ((maskcnt > 1) || (dictcnt > 1)) { @@ -3604,7 +3525,7 @@ int main (int argc, char **argv) data.cpt_total = 0; - if (data.restore == 0) + if (data.restore == false) { rd->words_cur = skip; @@ -4054,7 +3975,7 @@ int main (int argc, char **argv) data.words_base = words_base; - if (keyspace == 1) + if (keyspace == true) { log_info ("%" PRIu64 "", words_base); @@ -4097,7 +4018,7 @@ int main (int argc, char **argv) * Update dictionary statistic */ - if (keyspace == 0) + if (keyspace == false) { dictstat_write (dictstat_ctx); } @@ -4186,7 +4107,7 @@ int main (int argc, char **argv) { if (data.words_base < kernel_power_all) { - if (quiet == 0) + if (user_options->quiet == false) { clear_prompt (); @@ -4217,15 +4138,15 @@ int main (int argc, char **argv) if ((wordlist_mode == WL_MODE_FILE) || (wordlist_mode == WL_MODE_MASK)) { - if ((quiet == 0) && (status == 0) && (benchmark == 0)) + if ((user_options->quiet == false) && (status == 0) && (benchmark == false)) { - if (quiet == 0) send_prompt (); + if (user_options->quiet == false) send_prompt (); } } else if (wordlist_mode == WL_MODE_STDIN) { - if (data.quiet == 0) log_info ("Starting attack in stdin mode..."); - if (data.quiet == 0) log_info (""); + if (user_options->quiet == false) log_info ("Starting attack in stdin mode..."); + if (user_options->quiet == false) log_info (""); } time_t runtime_start; @@ -4275,23 +4196,26 @@ int main (int argc, char **argv) if (attack_mode != ATTACK_MODE_BF) { - induction_dictionaries = scan_directory (induction_directory); + if ((user_options->keyspace == false) && (user_options->benchmark == false) && (user_options->opencl_info == false)) + { + induction_dictionaries = scan_directory (induction_directory); - induction_dictionaries_cnt = count_dictionaries (induction_dictionaries); + induction_dictionaries_cnt = count_dictionaries (induction_dictionaries); + } } - if (benchmark == 1) + if (benchmark == true) { status_benchmark (opencl_ctx, hashconfig); - if (machine_readable == 0) + if (machine_readable == false) { log_info (""); } } else { - if (quiet == 0) + if (user_options->quiet == false) { clear_prompt (); @@ -4683,28 +4607,25 @@ int main (int argc, char **argv) if (induction_dir == NULL) { - if (attack_mode != ATTACK_MODE_BF) + if (rmdir (induction_directory) == -1) { - if (rmdir (induction_directory) == -1) + if (errno == ENOENT) { - if (errno == ENOENT) - { - // good, we can ignore - } - else if (errno == ENOTEMPTY) - { - // good, we can ignore - } - else - { - log_error ("ERROR: %s: %s", induction_directory, strerror (errno)); - - return -1; - } + // good, we can ignore } + else if (errno == ENOTEMPTY) + { + // good, we can ignore + } + else + { + log_error ("ERROR: %s: %s", induction_directory, strerror (errno)); - local_free (induction_directory); + return -1; + } } + + local_free (induction_directory); } // outfile-check directory @@ -4741,8 +4662,8 @@ int main (int argc, char **argv) logfile_top_msg ("STOP"); - if (quiet == 0) log_info_nn ("Started: %s", ctime (&proc_start)); - if (quiet == 0) log_info_nn ("Stopped: %s", ctime (&proc_stop)); + if (user_options->quiet == false) log_info_nn ("Started: %s", ctime (&proc_start)); + if (user_options->quiet == false) log_info_nn ("Stopped: %s", ctime (&proc_stop)); u32 rc_final = -1; diff --git a/src/monitor.c b/src/monitor.c index 396602606..83f107f99 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -154,7 +154,7 @@ void *thread_monitor (void *p) { if (slowdown_warnings < 3) { - if (data.quiet == 0) clear_prompt (); + if (data.quiet == false) clear_prompt (); log_info ("WARNING: Drivers temperature threshold hit on GPU #%d, expect performance to drop...", device_id + 1); @@ -163,7 +163,7 @@ void *thread_monitor (void *p) log_info (""); } - if (data.quiet == 0) send_prompt (); + if (data.quiet == false) send_prompt (); slowdown_warnings++; } @@ -287,7 +287,7 @@ void *thread_monitor (void *p) { restore_left--; - if (restore_left == 0) + if (restore_left == false) { if (data.restore_disable == 0) cycle_restore (opencl_ctx); @@ -316,9 +316,9 @@ void *thread_monitor (void *p) if (runtime_left <= 0) { - if (data.benchmark == 0) + if (data.benchmark == false) { - if (data.quiet == 0) log_info ("\nNOTE: Runtime limit reached, aborting...\n"); + if (data.quiet == false) log_info ("\nNOTE: Runtime limit reached, aborting...\n"); } myabort (opencl_ctx); @@ -329,7 +329,7 @@ void *thread_monitor (void *p) { remove_left--; - if (remove_left == 0) + if (remove_left == false) { if (hashes->digests_saved != hashes->digests_done) { @@ -346,17 +346,17 @@ void *thread_monitor (void *p) { status_left--; - if (status_left == 0) + if (status_left == false) { hc_thread_mutex_lock (mux_display); - if (data.quiet == 0) clear_prompt (); + if (data.quiet == false) clear_prompt (); - if (data.quiet == 0) log_info (""); + if (data.quiet == false) log_info (""); status_display (opencl_ctx, hashconfig, hashes); - if (data.quiet == 0) log_info (""); + if (data.quiet == false) log_info (""); hc_thread_mutex_unlock (mux_display); diff --git a/src/opencl.c b/src/opencl.c index d52128274..93327f7ca 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -44,6 +44,8 @@ extern hc_thread_mutex_t mux_hwmon; extern const int comptime; +static double TARGET_MS_PROFILE[4] = { 2, 12, 96, 480 }; + char *strstatus (const uint devices_status) { switch (devices_status) @@ -355,7 +357,7 @@ int choose_kernel (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, ha device_param->speed_ms[speed_pos] = speed_ms; - if (data.benchmark == 1) + if (data.benchmark == true) { if (speed_ms > 4096) myabort (opencl_ctx); } @@ -1047,7 +1049,7 @@ int run_cracker (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hash device_param->kernel_params_buf32[30] = innerloop_left; // i think we can get rid of this - if (innerloop_left == 0) + if (innerloop_left == false) { puts ("bug, how should this happen????\n"); @@ -1227,7 +1229,7 @@ int run_cracker (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hash } } - if (data.benchmark == 1) + if (data.benchmark == true) { hc_timer_set (&device_param->timer_speed); } @@ -1240,7 +1242,7 @@ int run_cracker (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hash * result */ - if (data.benchmark == 0) + if (data.benchmark == false) { check_cracked (opencl_ctx, device_param, hashconfig, hashes, salt_pos); } @@ -1288,7 +1290,7 @@ int run_cracker (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hash * benchmark */ - if (data.benchmark == 1) break; + if (data.benchmark == true) break; if (opencl_ctx->run_thread_level2 == false) break; } @@ -1303,11 +1305,11 @@ int run_cracker (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, hash return 0; } -int opencl_ctx_init (opencl_ctx_t *opencl_ctx, const char *opencl_platforms, const char *opencl_devices, const char *opencl_device_types, const uint opencl_vector_width, const uint opencl_vector_width_chgd, const uint nvidia_spin_damp, const uint nvidia_spin_damp_chgd, const uint workload_profile, const uint kernel_accel, const uint kernel_accel_chgd, const uint kernel_loops, const uint kernel_loops_chgd, const uint keyspace, const uint stdout_flag) +int opencl_ctx_init (opencl_ctx_t *opencl_ctx, const user_options_t *user_options) { - if (keyspace == 1) + if (user_options->keyspace == true) { - opencl_ctx->disable = 1; + opencl_ctx->disable = true; return 0; } @@ -1315,21 +1317,12 @@ int opencl_ctx_init (opencl_ctx_t *opencl_ctx, const char *opencl_platforms, con hc_thread_mutex_init (opencl_ctx->mux_dispatcher); hc_thread_mutex_init (opencl_ctx->mux_counter); - opencl_ctx->devices_status = STATUS_INIT; - opencl_ctx->run_main_level1 = true; - opencl_ctx->run_main_level2 = true; - opencl_ctx->run_main_level3 = true; - opencl_ctx->run_thread_level1 = true; - opencl_ctx->run_thread_level2 = true; - opencl_ctx->opencl_vector_width_chgd = opencl_vector_width_chgd; - opencl_ctx->opencl_vector_width = opencl_vector_width; - opencl_ctx->nvidia_spin_damp_chgd = nvidia_spin_damp_chgd; - opencl_ctx->nvidia_spin_damp = nvidia_spin_damp; - opencl_ctx->kernel_accel_chgd = kernel_accel_chgd; - opencl_ctx->kernel_accel = kernel_accel; - opencl_ctx->kernel_loops_chgd = kernel_loops_chgd; - opencl_ctx->kernel_loops = kernel_loops; - opencl_ctx->workload_profile = workload_profile; + opencl_ctx->devices_status = STATUS_INIT; + opencl_ctx->run_main_level1 = true; + opencl_ctx->run_main_level2 = true; + opencl_ctx->run_main_level3 = true; + opencl_ctx->run_thread_level1 = true; + opencl_ctx->run_thread_level2 = true; opencl_ctx->ocl = (OCL_PTR *) mymalloc (sizeof (OCL_PTR)); @@ -1348,7 +1341,7 @@ int opencl_ctx_init (opencl_ctx_t *opencl_ctx, const char *opencl_platforms, con * OpenCL platform selection */ - u32 opencl_platforms_filter = setup_opencl_platforms_filter (opencl_platforms); + u32 opencl_platforms_filter = setup_opencl_platforms_filter (user_options->opencl_platforms); opencl_ctx->opencl_platforms_filter = opencl_platforms_filter; @@ -1356,7 +1349,7 @@ int opencl_ctx_init (opencl_ctx_t *opencl_ctx, const char *opencl_platforms, con * OpenCL device selection */ - u32 devices_filter = setup_devices_filter (opencl_devices); + u32 devices_filter = setup_devices_filter (user_options->opencl_devices); opencl_ctx->devices_filter = devices_filter; @@ -1364,7 +1357,7 @@ int opencl_ctx_init (opencl_ctx_t *opencl_ctx, const char *opencl_platforms, con * OpenCL device type selection */ - cl_device_type device_types_filter = setup_device_types_filter (opencl_device_types); + cl_device_type device_types_filter = setup_device_types_filter (user_options->opencl_device_types); opencl_ctx->device_types_filter = device_types_filter; @@ -1412,7 +1405,7 @@ int opencl_ctx_init (opencl_ctx_t *opencl_ctx, const char *opencl_platforms, con } } - if (opencl_device_types == NULL) + if (user_options->opencl_device_types == NULL) { /** * OpenCL device types: @@ -1469,7 +1462,7 @@ int opencl_ctx_init (opencl_ctx_t *opencl_ctx, const char *opencl_platforms, con // In another case, when the user uses --stdout, using CPU devices is much faster to setup // If we have a CPU device, force it to be used - if (stdout_flag == 1) + if (user_options->stdout_flag == true) { if (device_types_all & CL_DEVICE_TYPE_CPU) { @@ -1506,7 +1499,7 @@ void opencl_ctx_destroy (opencl_ctx_t *opencl_ctx) myfree (opencl_ctx); } -int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, const tuning_db_t *tuning_db, const uint attack_mode, const bool quiet, const bool force, const bool benchmark, const bool opencl_info, const bool machine_readable, const uint algorithm_pos) +int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, const tuning_db_t *tuning_db, const user_options_t *user_options, const uint algorithm_pos) { if (opencl_ctx->disable == 1) return 0; @@ -1528,7 +1521,7 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc u32 devices_active = 0; - if (opencl_info) + if (user_options->opencl_info == true) { fprintf (stdout, "OpenCL Info:\n"); } @@ -1606,7 +1599,7 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc platform_skipped = 2; } - if (opencl_info) + if (user_options->opencl_info == true) { char platform_name[HCBUFSIZ_TINY] = { 0 }; @@ -1633,9 +1626,9 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc fprintf (stdout, "\nPlatform ID #%u\n Vendor : %s\n Name : %s\n Version : %s\n\n", platform_id, platform_vendor, platform_name, platform_version); } - if ((benchmark == 1 || quiet == 0) && (algorithm_pos == 0)) + if ((user_options->benchmark == true || user_options->quiet == false) && (algorithm_pos == 0)) { - if (machine_readable == 0) + if (user_options->machine_readable == false) { if (platform_skipped == 0) { @@ -1841,11 +1834,11 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc cl_uint vector_width; - if (opencl_ctx->opencl_vector_width_chgd == 0) + if (user_options->opencl_vector_width_chgd == false) { // tuning db - tuning_db_entry_t *tuningdb_entry = tuning_db_search (tuning_db, device_param->device_name, device_param->device_type, attack_mode, hashconfig->hash_mode); + tuning_db_entry_t *tuningdb_entry = tuning_db_search (tuning_db, device_param->device_name, device_param->device_type, user_options->attack_mode, hashconfig->hash_mode); if (tuningdb_entry == NULL || tuningdb_entry->vector_width == -1) { @@ -1879,7 +1872,7 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc } else { - vector_width = opencl_ctx->opencl_vector_width; + vector_width = user_options->opencl_vector_width; } if (vector_width > 16) vector_width = 16; @@ -2112,7 +2105,7 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc { if (device_param->device_vendor_id == VENDOR_ID_AMD_USE_INTEL) { - if (force == 0) + if (user_options->force == 0) { if (algorithm_pos == 0) { @@ -2245,11 +2238,11 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc // Value is given as number between 0-100 // By default 100% - device_param->nvidia_spin_damp = (double) opencl_ctx->nvidia_spin_damp; + device_param->nvidia_spin_damp = (double) user_options->nvidia_spin_damp; - if (opencl_ctx->nvidia_spin_damp_chgd == 0) + if (user_options->nvidia_spin_damp_chgd == false) { - if (attack_mode == ATTACK_MODE_STRAIGHT) + if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) { /** * the workaround is not a friend of rule based attacks @@ -2268,7 +2261,7 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc // display results - if (opencl_info) + if (user_options->opencl_info == true) { char *format = " Device ID #%u\n Type : %s\n Vendor ID : %u\n Vendor : %s\n Name : %s\n Processor(s) : %u\n Clock : %u\n Memory : %lu/%lu MB allocatable\n OpenCL Version : %s\n\n"; @@ -2283,9 +2276,9 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc myfree (device_opencl_version); - if ((benchmark == 1 || quiet == 0) && (algorithm_pos == 0)) + if ((user_options->benchmark == true || user_options->quiet == false) && (algorithm_pos == 0)) { - if (machine_readable == 0) + if (user_options->machine_readable == false) { if (device_param->skipped == 0) { @@ -2313,7 +2306,7 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc { if (platform_vendor_id == VENDOR_ID_AMD) { - int catalyst_check = (force == 1) ? 0 : 1; + int catalyst_check = (user_options->force == 1) ? 0 : 1; int catalyst_warn = 0; @@ -2363,8 +2356,8 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc { if (device_param->kernel_exec_timeout != 0) { - if (quiet == 0) log_info ("- Device #%u: WARNING! Kernel exec timeout is not disabled, it might cause you errors of code 702", device_id + 1); - if (quiet == 0) log_info (" See the wiki on how to disable it: https://hashcat.net/wiki/doku.php?id=timeout_patch"); + if (user_options->quiet == false) log_info ("- Device #%u: WARNING! Kernel exec timeout is not disabled, it might cause you errors of code 702", device_id + 1); + if (user_options->quiet == false) log_info (" See the wiki on how to disable it: https://hashcat.net/wiki/doku.php?id=timeout_patch"); } } } @@ -2374,7 +2367,7 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc { if (platform_vendor_id == VENDOR_ID_AMD) { - if (force == 0) + if (user_options->force == 0) { log_info (""); log_info ("ATTENTION! OpenCL support for CPU of catalyst driver is not reliable."); @@ -2399,7 +2392,7 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc device_param->kernel_loops_min = 1; device_param->kernel_loops_max = 1024; - tuning_db_entry_t *tuningdb_entry = tuning_db_search (tuning_db, device_param->device_name, device_param->device_type, attack_mode, hashconfig->hash_mode); + tuning_db_entry_t *tuningdb_entry = tuning_db_search (tuning_db, device_param->device_name, device_param->device_type, user_options->attack_mode, hashconfig->hash_mode); if (tuningdb_entry != NULL) { @@ -2414,11 +2407,11 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc if (_kernel_loops) { - if (opencl_ctx->workload_profile == 1) + if (user_options->workload_profile == 1) { _kernel_loops = (_kernel_loops > 8) ? _kernel_loops / 8 : 1; } - else if (opencl_ctx->workload_profile == 2) + else if (user_options->workload_profile == 2) { _kernel_loops = (_kernel_loops > 4) ? _kernel_loops / 4 : 1; } @@ -2430,16 +2423,16 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc // commandline parameters overwrite tuningdb entries - if (opencl_ctx->kernel_accel_chgd == 1) + if (user_options->kernel_accel_chgd == true) { - device_param->kernel_accel_min = opencl_ctx->kernel_accel; - device_param->kernel_accel_max = opencl_ctx->kernel_accel; + device_param->kernel_accel_min = user_options->kernel_accel; + device_param->kernel_accel_max = user_options->kernel_accel; } - if (opencl_ctx->kernel_loops_chgd == 1) + if (user_options->kernel_loops_chgd == true) { - device_param->kernel_loops_min = opencl_ctx->kernel_loops; - device_param->kernel_loops_max = opencl_ctx->kernel_loops; + device_param->kernel_loops_min = user_options->kernel_loops; + device_param->kernel_loops_max = user_options->kernel_loops; } /** @@ -2454,18 +2447,18 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc devices_cnt++; } - if ((benchmark == 1 || quiet == 0) && (algorithm_pos == 0)) + if ((user_options->benchmark == true || user_options->quiet == false) && (algorithm_pos == 0)) { - if (machine_readable == 0) + if (user_options->machine_readable == false) { log_info (""); } } } - if (opencl_info) + if (user_options->opencl_info == true) { - exit(0); + exit (0); } if (devices_active == 0) @@ -2489,6 +2482,8 @@ int opencl_ctx_devices_init (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashc } } + opencl_ctx->target_ms = TARGET_MS_PROFILE[user_options->workload_profile - 1]; + opencl_ctx->devices_cnt = devices_cnt; opencl_ctx->devices_active = devices_active; @@ -2523,7 +2518,7 @@ void opencl_ctx_devices_destroy (opencl_ctx_t *opencl_ctx) opencl_ctx->need_xnvctrl = 0; } -int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, const hashes_t *hashes, const session_ctx_t *session_ctx) +int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, const hashes_t *hashes, const session_ctx_t *session_ctx, const user_options_t *user_options, const user_options_extra_t *user_options_extra) { for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { @@ -2681,9 +2676,9 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf uint tmto_start = 0; uint tmto_stop = 10; - if (session_ctx->scrypt_tmto) + if (user_options->scrypt_tmto) { - tmto_start = session_ctx->scrypt_tmto; + tmto_start = user_options->scrypt_tmto; } else { @@ -2729,14 +2724,14 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf if ((size_scrypt / 4) > device_param->device_maxmem_alloc) { - if (session_ctx->quiet == 0) log_info ("WARNING: Not enough single-block device memory allocatable to use --scrypt-tmto %d, increasing...", tmto); + if (user_options->quiet == false) log_info ("WARNING: Not enough single-block device memory allocatable to use --scrypt-tmto %d, increasing...", tmto); continue; } if (size_scrypt > device_param->device_global_mem) { - if (session_ctx->quiet == 0) log_info ("WARNING: Not enough total device memory allocatable to use --scrypt-tmto %d, increasing...", tmto); + if (user_options->quiet == false) log_info ("WARNING: Not enough total device memory allocatable to use --scrypt-tmto %d, increasing...", tmto); continue; } @@ -2756,7 +2751,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf return -1; } - if (session_ctx->quiet == 0) log_info ("SCRYPT tmto optimizer value set to: %u, mem: %" PRIu64 "\n", scrypt_tmto_final, size_scrypt); + if (user_options->quiet == false) log_info ("SCRYPT tmto optimizer value set to: %u, mem: %" PRIu64 "\n", scrypt_tmto_final, size_scrypt); } size_t size_scrypt4 = size_scrypt / 4; @@ -2765,7 +2760,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf * some algorithms need a fixed kernel-loops count */ - if (hashconfig->hash_mode == 1500 && session_ctx->attack_mode == ATTACK_MODE_BF) + if (hashconfig->hash_mode == 1500 && user_options->attack_mode == ATTACK_MODE_BF) { const u32 kernel_loops_fixed = 1024; @@ -2773,7 +2768,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf device_param->kernel_loops_max = kernel_loops_fixed; } - if (hashconfig->hash_mode == 3000 && session_ctx->attack_mode == ATTACK_MODE_BF) + if (hashconfig->hash_mode == 3000 && user_options->attack_mode == ATTACK_MODE_BF) { const u32 kernel_loops_fixed = 1024; @@ -2805,7 +2800,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf device_param->kernel_loops_max = kernel_loops_fixed; } - if (hashconfig->hash_mode == 14000 && session_ctx->attack_mode == ATTACK_MODE_BF) + if (hashconfig->hash_mode == 14000 && user_options->attack_mode == ATTACK_MODE_BF) { const u32 kernel_loops_fixed = 1024; @@ -2813,7 +2808,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf device_param->kernel_loops_max = kernel_loops_fixed; } - if (hashconfig->hash_mode == 14100 && session_ctx->attack_mode == ATTACK_MODE_BF) + if (hashconfig->hash_mode == 14100 && user_options->attack_mode == ATTACK_MODE_BF) { const u32 kernel_loops_fixed = 1024; @@ -3000,7 +2995,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf /* if (kernel_accel_max < kernel_accel) { - if (session_ctx->quiet == 0) log_info ("- Device #%u: Reduced maximum kernel-accel to %u", device_id + 1, kernel_accel_max); + if (user_options->quiet == false) log_info ("- Device #%u: Reduced maximum kernel-accel to %u", device_id + 1, kernel_accel_max); device_param->kernel_accel = kernel_accel_max; } @@ -3110,7 +3105,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf char source_file[256] = { 0 }; - generate_source_kernel_filename (hashconfig->attack_exec, session_ctx->attack_kern, hashconfig->kern_type, session_ctx->shared_dir, source_file); + generate_source_kernel_filename (hashconfig->attack_exec, user_options_extra->attack_kern, hashconfig->kern_type, session_ctx->shared_dir, source_file); struct stat sst; @@ -3127,7 +3122,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf char cached_file[256] = { 0 }; - generate_cached_kernel_filename (hashconfig->attack_exec, session_ctx->attack_kern, hashconfig->kern_type, session_ctx->profile_dir, device_name_chksum, cached_file); + generate_cached_kernel_filename (hashconfig->attack_exec, user_options_extra->attack_kern, hashconfig->kern_type, session_ctx->profile_dir, device_name_chksum, cached_file); int cached = 1; @@ -3150,7 +3145,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf { if (cached == 0) { - if (session_ctx->quiet == 0) log_info ("- Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); + if (user_options->quiet == false) log_info ("- Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); load_kernel (source_file, 1, kernel_lengths, kernel_sources); @@ -3366,7 +3361,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf * word generator kernel */ - if (session_ctx->attack_mode != ATTACK_MODE_STRAIGHT) + if (user_options->attack_mode != ATTACK_MODE_STRAIGHT) { /** * kernel mp source filename @@ -3412,8 +3407,8 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf if (cached == 0) { - if (session_ctx->quiet == 0) log_info ("- Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); - if (session_ctx->quiet == 0) log_info (""); + if (user_options->quiet == false) log_info ("- Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); + if (user_options->quiet == false) log_info (""); load_kernel (source_file, 1, kernel_lengths, kernel_sources); @@ -3555,7 +3550,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf char source_file[256] = { 0 }; - generate_source_kernel_amp_filename (session_ctx->attack_kern, session_ctx->shared_dir, source_file); + generate_source_kernel_amp_filename (user_options_extra->attack_kern, session_ctx->shared_dir, source_file); struct stat sst; @@ -3572,7 +3567,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf char cached_file[256] = { 0 }; - generate_cached_kernel_amp_filename (session_ctx->attack_kern, session_ctx->profile_dir, device_name_chksum, cached_file); + generate_cached_kernel_amp_filename (user_options_extra->attack_kern, session_ctx->profile_dir, device_name_chksum, cached_file); int cached = 1; @@ -3593,8 +3588,8 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf if (cached == 0) { - if (session_ctx->quiet == 0) log_info ("- Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); - if (session_ctx->quiet == 0) log_info (""); + if (user_options->quiet == false) log_info ("- Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); + if (user_options->quiet == false) log_info (""); load_kernel (source_file, 1, kernel_lengths, kernel_sources); @@ -3691,7 +3686,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf else { #if defined (DEBUG) - if (session_ctx->quiet == 0) log_info ("- Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size); + if (user_options->quiet == false) log_info ("- Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size); #endif load_kernel (cached_file, 1, kernel_lengths, kernel_sources); @@ -3731,7 +3726,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf // some algorithm collide too fast, make that impossible - if (session_ctx->benchmark == 1) + if (user_options->benchmark == true) { ((uint *) hashes->digests_buf)[0] = -1u; ((uint *) hashes->digests_buf)[1] = -1u; @@ -3795,7 +3790,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf * special buffers */ - if (session_ctx->attack_kern == ATTACK_KERN_STRAIGHT) + if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) { CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_rules, NULL, &device_param->d_rules); CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_rules_c, NULL, &device_param->d_rules_c); @@ -3816,7 +3811,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf return -1; } } - else if (session_ctx->attack_kern == ATTACK_KERN_COMBI) + else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) { CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_combs, NULL, &device_param->d_combs); CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_combs, NULL, &device_param->d_combs_c); @@ -3830,7 +3825,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf return -1; } } - else if (session_ctx->attack_kern == ATTACK_KERN_BF) + else if (user_options_extra->attack_kern == ATTACK_KERN_BF) { CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_bfs, NULL, &device_param->d_bfs); CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_bfs, NULL, &device_param->d_bfs_c); @@ -4092,7 +4087,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf } } - if (session_ctx->attack_mode == ATTACK_MODE_BF) + if (user_options->attack_mode == ATTACK_MODE_BF) { if (hashconfig->opts_type & OPTS_TYPE_PT_BITSLICE) { @@ -4278,7 +4273,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf // MP start - if (session_ctx->attack_mode == ATTACK_MODE_BF) + if (user_options->attack_mode == ATTACK_MODE_BF) { CL_err |= hc_clCreateKernel (opencl_ctx->ocl, device_param->program_mp, "l_markov", &device_param->kernel_mp_l); CL_err |= hc_clCreateKernel (opencl_ctx->ocl, device_param->program_mp, "r_markov", &device_param->kernel_mp_r); @@ -4313,7 +4308,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf } } } - else if (session_ctx->attack_mode == ATTACK_MODE_HYBRID1) + else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) { CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program_mp, "C_markov", &device_param->kernel_mp); @@ -4333,7 +4328,7 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf return -1; } } - else if (session_ctx->attack_mode == ATTACK_MODE_HYBRID2) + else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) { CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program_mp, "C_markov", &device_param->kernel_mp); @@ -4428,18 +4423,18 @@ int opencl_session_begin (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconf * special buffers */ - if (session_ctx->attack_kern == ATTACK_KERN_STRAIGHT) + if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) { run_kernel_bzero (opencl_ctx, device_param, device_param->d_rules_c, size_rules_c); } - else if (session_ctx->attack_kern == ATTACK_KERN_COMBI) + else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) { run_kernel_bzero (opencl_ctx, device_param, device_param->d_combs, size_combs); run_kernel_bzero (opencl_ctx, device_param, device_param->d_combs_c, size_combs); run_kernel_bzero (opencl_ctx, device_param, device_param->d_root_css_buf, size_root_css); run_kernel_bzero (opencl_ctx, device_param, device_param->d_markov_css_buf, size_markov_css); } - else if (session_ctx->attack_kern == ATTACK_KERN_BF) + else if (user_options_extra->attack_kern == ATTACK_KERN_BF) { run_kernel_bzero (opencl_ctx, device_param, device_param->d_bfs, size_bfs); run_kernel_bzero (opencl_ctx, device_param, device_param->d_bfs_c, size_bfs); diff --git a/src/outfile_check.c b/src/outfile_check.c index 041064b82..1ab30c8e6 100644 --- a/src/outfile_check.c +++ b/src/outfile_check.c @@ -79,7 +79,7 @@ void *thread_outfile_remove (void *p) check_left--; - if (check_left == 0) + if (check_left == false) { struct stat outfile_check_stat; diff --git a/src/session.c b/src/session.c index 85e72ac6d..007b4c588 100644 --- a/src/session.c +++ b/src/session.c @@ -7,14 +7,8 @@ #include "types.h" #include "session.h" -void session_ctx_init (session_ctx_t *session_ctx, const bool quiet, const bool force, const bool benchmark, const u32 scrypt_tmto, char *cwd, char *install_dir, char *profile_dir, char *session_dir, char *shared_dir, char *cpath_real, const u32 wordlist_mode, char *rule_buf_l, char *rule_buf_r, const int rule_len_l, const int rule_len_r, const u32 kernel_rules_cnt, kernel_rule_t *kernel_rules_buf, const u32 attack_mode, const u32 attack_kern, const u32 bitmap_size, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, u32 *bitmap_s1_a, u32 *bitmap_s1_b, u32 *bitmap_s1_c, u32 *bitmap_s1_d, u32 *bitmap_s2_a, u32 *bitmap_s2_b, u32 *bitmap_s2_c, u32 *bitmap_s2_d) +void session_ctx_init (session_ctx_t *session_ctx, char *cwd, char *install_dir, char *profile_dir, char *session_dir, char *shared_dir, char *cpath_real, const u32 wordlist_mode, const u32 kernel_rules_cnt, kernel_rule_t *kernel_rules_buf,const u32 bitmap_size, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, u32 *bitmap_s1_a, u32 *bitmap_s1_b, u32 *bitmap_s1_c, u32 *bitmap_s1_d, u32 *bitmap_s2_a, u32 *bitmap_s2_b, u32 *bitmap_s2_c, u32 *bitmap_s2_d) { - session_ctx->quiet = quiet; - session_ctx->force = force; - session_ctx->benchmark = benchmark; - - session_ctx->scrypt_tmto = scrypt_tmto; - session_ctx->cwd = cwd; session_ctx->install_dir = install_dir; session_ctx->profile_dir = profile_dir; @@ -24,17 +18,9 @@ void session_ctx_init (session_ctx_t *session_ctx, const bool quiet, const bool session_ctx->wordlist_mode = wordlist_mode; - session_ctx->rule_buf_l = rule_buf_l; - session_ctx->rule_buf_r = rule_buf_r; - session_ctx->rule_len_l = rule_len_l; - session_ctx->rule_len_r = rule_len_r; - session_ctx->kernel_rules_cnt = kernel_rules_cnt; session_ctx->kernel_rules_buf = kernel_rules_buf; - session_ctx->attack_mode = attack_mode; - session_ctx->attack_kern = attack_kern; - session_ctx->bitmap_size = bitmap_size; session_ctx->bitmap_mask = bitmap_mask; session_ctx->bitmap_shift1 = bitmap_shift1; @@ -52,12 +38,6 @@ void session_ctx_init (session_ctx_t *session_ctx, const bool quiet, const bool void session_ctx_destroy (session_ctx_t *session_ctx) { - session_ctx->quiet = false; - session_ctx->force = false; - session_ctx->benchmark = false; - - session_ctx->scrypt_tmto = 0; - session_ctx->cwd = NULL; session_ctx->install_dir = NULL; session_ctx->profile_dir = NULL; @@ -67,17 +47,9 @@ void session_ctx_destroy (session_ctx_t *session_ctx) session_ctx->wordlist_mode = 0; - session_ctx->rule_buf_l = NULL; - session_ctx->rule_buf_r = NULL; - session_ctx->rule_len_l = 0; - session_ctx->rule_len_r = 0; - session_ctx->kernel_rules_buf = NULL; session_ctx->kernel_rules_cnt = 0; - session_ctx->attack_mode = 0; - session_ctx->attack_kern = 0; - session_ctx->bitmap_size = 0; session_ctx->bitmap_mask = 0; session_ctx->bitmap_shift1 = 0; diff --git a/src/status.c b/src/status.c index 0341f799f..e649ab48a 100644 --- a/src/status.c +++ b/src/status.c @@ -300,7 +300,7 @@ void status_display (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig, c // in this case some required buffers are free'd, ascii_digest() would run into segfault if (data.shutdown_inner == 1) return; - if (data.machine_readable == 1) + if (data.machine_readable == true) { status_display_machine_readable (opencl_ctx, hashes); @@ -1144,7 +1144,7 @@ void status_benchmark_automate (opencl_ctx_t *opencl_ctx, const hashconfig_t *ha speed_ms[device_id] = device_param->speed_ms[0]; } - double hashes_dev_ms[DEVICES_MAX] = { 0 }; + u64 hashes_dev_ms[DEVICES_MAX] = { 0 }; for (uint device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { @@ -1181,7 +1181,7 @@ void status_benchmark (opencl_ctx_t *opencl_ctx, const hashconfig_t *hashconfig) if (data.shutdown_inner == 1) return; - if (data.machine_readable == 1) + if (data.machine_readable == true) { status_benchmark_automate (opencl_ctx, hashconfig); diff --git a/src/terminal.c b/src/terminal.c index b1c9bbb17..ce2d72d6f 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -99,7 +99,7 @@ void *thread_keypress (void *p) log_info (""); - if (quiet == 0) send_prompt (); + if (quiet == false) send_prompt (); break; @@ -111,7 +111,7 @@ void *thread_keypress (void *p) log_info (""); - if (quiet == 0) send_prompt (); + if (quiet == false) send_prompt (); break; @@ -123,7 +123,7 @@ void *thread_keypress (void *p) log_info (""); - if (quiet == 0) send_prompt (); + if (quiet == false) send_prompt (); break; @@ -135,7 +135,7 @@ void *thread_keypress (void *p) log_info (""); - if (quiet == 0) send_prompt (); + if (quiet == false) send_prompt (); break; @@ -147,7 +147,7 @@ void *thread_keypress (void *p) log_info (""); - if (quiet == 0) send_prompt (); + if (quiet == false) send_prompt (); break; diff --git a/src/user_options.c b/src/user_options.c index 7a7ebbe4f..4e924404c 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -239,49 +239,42 @@ int user_options_parse (user_options_t *user_options, int myargc, char **myargv) { user_options->show = false; user_options->left = false; - user_options->quiet = true; user_options->gpu_temp_disable = true; user_options->potfile_disable = true; + user_options->powertune_enable = false; user_options->restore = false; user_options->restore_disable = true; user_options->restore_timer = 0; user_options->markov_disable = true; user_options->logfile_disable = true; user_options->weak_hash_threshold = 0; + user_options->nvidia_spin_damp = 0; user_options->status = false; user_options->status_timer = 0; user_options->outfile_check_timer = 0; } - if (user_options->opencl_info == true) - { - user_options->session = "opencl_info"; - } - - if (user_options->keyspace == true) - { - user_options->session = "keyspace"; - } - if (user_options->benchmark == true) { - user_options->session = "benchmark"; - } + user_options->attack_mode = ATTACK_MODE_BF; + user_options->session = "benchmark"; - if (user_options->stdout_flag == true) - { - user_options->session = "stdout"; + if (user_options->workload_profile_chgd == false) + { + user_options->workload_profile = 3; + } } - if (user_options->opencl_info == true) + if (user_options->keyspace == true) { - user_options->opencl_platforms = NULL; - user_options->opencl_devices = NULL; - user_options->opencl_device_types = mystrdup ("1,2,3"); + user_options->session = "keyspace"; + user_options->quiet = true; } if (user_options->stdout_flag == true) { + user_options->session = "stdout"; + user_options->quiet = true; user_options->hash_mode = 2000; user_options->outfile_format = OUTFILE_FMT_PLAIN; user_options->force = true; @@ -290,6 +283,15 @@ int user_options_parse (user_options_t *user_options, int myargc, char **myargv) user_options->opencl_vector_width = 1; } + if (user_options->opencl_info == true) + { + user_options->session = "opencl_info"; + user_options->quiet = true; + user_options->opencl_platforms = NULL; + user_options->opencl_devices = NULL; + user_options->opencl_device_types = mystrdup ("1,2,3"); + } + if (user_options->left == true) { user_options->outfile_format = OUTFILE_FMT_HASH; @@ -310,12 +312,40 @@ int user_options_parse (user_options_t *user_options, int myargc, char **myargv) user_options->weak_hash_threshold = 0; } + if (user_options->hash_mode == 9710) + { + user_options->outfile_format = 5; + user_options->outfile_format_chgd = 1; + } + + if (user_options->hash_mode == 9810) + { + user_options->outfile_format = 5; + user_options->outfile_format_chgd = 1; + } + + if (user_options->hash_mode == 10410) + { + user_options->outfile_format = 5; + user_options->outfile_format_chgd = 1; + } + + if (user_options->session == NULL) + { + user_options->session = (char *) PROGNAME; + } + return 0; } int user_options_sanity (user_options_t *user_options, int myargc, char **myargv, user_options_extra_t *user_options_extra) { - if (user_options->attack_mode > 7) + if ((user_options->attack_mode != ATTACK_MODE_STRAIGHT) + && (user_options->attack_mode != ATTACK_MODE_COMBI) + && (user_options->attack_mode != ATTACK_MODE_BF) + && (user_options->attack_mode != ATTACK_MODE_HYBRID1) + && (user_options->attack_mode != ATTACK_MODE_HYBRID2) + && (user_options->attack_mode != ATTACK_MODE_NONE)) { log_error ("ERROR: Invalid attack-mode specified"); @@ -336,7 +366,7 @@ int user_options_sanity (user_options_t *user_options, int myargc, char **myargv return -1; } - if (user_options->username == 1) + if (user_options->username == true) { if ((user_options->hash_mode == 2500) || (user_options->hash_mode == 5200) @@ -356,7 +386,7 @@ int user_options_sanity (user_options_t *user_options, int myargc, char **myargv return -1; } - if (user_options->left == 1) + if (user_options->left == true) { if (user_options->outfile_format_chgd == true) { @@ -366,7 +396,7 @@ int user_options_sanity (user_options_t *user_options, int myargc, char **myargv } } - if (user_options->show == 1) + if (user_options->show == true) { if (user_options->outfile_format_chgd == true) { @@ -397,35 +427,35 @@ int user_options_sanity (user_options_t *user_options, int myargc, char **myargv return -1; } - if ((user_options->increment == 1) && (user_options->attack_mode == ATTACK_MODE_STRAIGHT)) + if ((user_options->increment == true) && (user_options->attack_mode == ATTACK_MODE_STRAIGHT)) { log_error ("ERROR: Increment is not allowed in attack-mode 0"); return -1; } - if ((user_options->increment == 0) && (user_options->increment_min_chgd == true)) + if ((user_options->increment == true) && (user_options->increment_min_chgd == true)) { log_error ("ERROR: Increment-min is only supported combined with increment switch"); return -1; } - if ((user_options->increment == 0) && (user_options->increment_max_chgd == true)) + if ((user_options->increment == true) && (user_options->increment_max_chgd == true)) { log_error ("ERROR: Increment-max is only supported combined with increment switch"); return -1; } - if (user_options->rp_files_cnt && user_options->rp_gen) + if (user_options->rp_files_cnt > 0 && user_options->rp_gen == true) { log_error ("ERROR: Use of both rules-file and rules-generate is not supported"); return -1; } - if (user_options->rp_files_cnt || user_options->rp_gen) + if (user_options->rp_files_cnt > 0 || user_options->rp_gen == true) { if (user_options->attack_mode != ATTACK_MODE_STRAIGHT) { @@ -444,7 +474,7 @@ int user_options_sanity (user_options_t *user_options, int myargc, char **myargv if (user_options->kernel_accel_chgd == true) { - if (user_options->force == 0) + if (user_options->force == false) { log_info ("The manual use of the -n option (or --kernel-accel) is outdated"); log_info ("Please consider using the -w option instead"); @@ -471,7 +501,7 @@ int user_options_sanity (user_options_t *user_options, int myargc, char **myargv if (user_options->kernel_loops_chgd == true) { - if (user_options->force == 0) + if (user_options->force == false) { log_info ("The manual use of the -u option (or --kernel-loops) is outdated"); log_info ("Please consider using the -w option instead"); @@ -503,23 +533,26 @@ int user_options_sanity (user_options_t *user_options, int myargc, char **myargv return -1; } - if (user_options->opencl_vector_width_chgd == true && (!is_power_of_2 (user_options->opencl_vector_width) || user_options->opencl_vector_width > 16)) + if (user_options->opencl_vector_width_chgd == true) { - log_error ("ERROR: opencl-vector-width %i not allowed", user_options->opencl_vector_width); + if (is_power_of_2 (user_options->opencl_vector_width) == false || user_options->opencl_vector_width > 16) + { + log_error ("ERROR: opencl-vector-width %i not allowed", user_options->opencl_vector_width); - return -1; + return -1; + } } - if (user_options->show == 1 || user_options->left == 1) + if (user_options->show == true || user_options->left == true) { - if (user_options->remove == 1) + if (user_options->remove == true) { log_error ("ERROR: Mixing remove parameter not allowed with show parameter or left parameter"); return -1; } - if (user_options->potfile_disable == 1) + if (user_options->potfile_disable == true) { log_error ("ERROR: Mixing potfile-disable parameter not allowed with show parameter or left parameter"); @@ -527,9 +560,9 @@ int user_options_sanity (user_options_t *user_options, int myargc, char **myargv } } - if (user_options->show == 1) + if (user_options->show == true) { - if (user_options->outfile_autohex == 0) + if (user_options->outfile_autohex == false) { log_error ("ERROR: Mixing outfile-autohex-disable parameter not allowed with show parameter"); @@ -537,15 +570,15 @@ int user_options_sanity (user_options_t *user_options, int myargc, char **myargv } } - if (user_options->keyspace == 1) + if (user_options->keyspace == true) { - if (user_options->show == 1) + if (user_options->show == true) { log_error ("ERROR: Combining show parameter with keyspace parameter is not allowed"); return -1; } - else if (user_options->left == 1) + else if (user_options->left == true) { log_error ("ERROR: Combining left parameter with keyspace parameter is not allowed"); @@ -555,7 +588,7 @@ int user_options_sanity (user_options_t *user_options, int myargc, char **myargv if (user_options->remove_timer_chgd == true) { - if (user_options->remove == 0) + if (user_options->remove == false) { log_error ("ERROR: Parameter remove-timer require parameter remove enabled"); @@ -570,7 +603,7 @@ int user_options_sanity (user_options_t *user_options, int myargc, char **myargv } } - if (user_options->loopback == 1) + if (user_options->loopback == true) { if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) { @@ -651,9 +684,9 @@ int user_options_sanity (user_options_t *user_options, int myargc, char **myargv return -1; } - if (user_options->benchmark == 1) + if (user_options->benchmark == true) { - if (myargv[optind] != 0) + if (myargv[optind] != NULL) { log_error ("ERROR: Invalid argument for benchmark mode specified"); @@ -670,6 +703,15 @@ int user_options_sanity (user_options_t *user_options, int myargc, char **myargv } } } + else if (user_options->opencl_info == true) + { + if (user_options_extra->optind != myargc) + { + usage_mini_print (myargv[0]); + + return -1; + } + } else { if (user_options_extra->attack_kern == ATTACK_KERN_NONE) @@ -734,18 +776,18 @@ int user_options_extra_init (user_options_t *user_options, int myargc, char **my user_options_extra->optind = optind; - if (user_options->benchmark == 1) + if (user_options->benchmark == true) { } else { - if (user_options->stdout_flag == 1) // no hash here + if (user_options->stdout_flag == true) // no hash here { user_options_extra->optind--; } - if (user_options->keyspace == 1) + if (user_options->keyspace == true) { int num_additional_params = 1; @@ -760,5 +802,27 @@ int user_options_extra_init (user_options_t *user_options, int myargc, char **my } } + user_options_extra->rule_len_l = (int) strlen (user_options->rule_buf_l); + user_options_extra->rule_len_r = (int) strlen (user_options->rule_buf_r); + + /* + user_options_extra->wordlist_mode = ((user_options_extra->optind + 1) < myargc) ? WL_MODE_FILE : WL_MODE_STDIN; + + if (user_options->attack_mode == ATTACK_MODE_BF) + { + user_options_extra->wordlist_mode = WL_MODE_MASK; + } + */ + + /* still needed? + if (user_options_extra->wordlist_mode == WL_MODE_STDIN) + { + // enable status (in stdin mode) whenever we do not use --stdout together with an outfile + + if (user_options->stdout_flag == true) user_options->status = true; + else if (user_options->outfile) user_options->status = true; + } + */ + return 0; } diff --git a/src/wordlist.c b/src/wordlist.c index af4548388..c63fcd59a 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -334,8 +334,8 @@ u64 count_words (wl_data_t *wl_data, FILE *fd, const char *dictfile, dictstat_ct keyspace *= data.combs_cnt; } - if (data.quiet == 0) log_info ("Cache-hit dictionary stats %s: %" PRIu64 " bytes, %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, d.stat.st_size, cached_cnt, keyspace); - if (data.quiet == 0) log_info (""); + if (data.quiet == false) log_info ("Cache-hit dictionary stats %s: %" PRIu64 " bytes, %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, d.stat.st_size, cached_cnt, keyspace); + if (data.quiet == false) log_info (""); hc_signal (sigHandler_default); @@ -411,13 +411,13 @@ u64 count_words (wl_data_t *wl_data, FILE *fd, const char *dictfile, dictstat_ct double percent = (double) comp / (double) d.stat.st_size; - if (data.quiet == 0) log_info_nn ("Generating dictionary stats for %s: %" PRIu64 " bytes (%.2f%%), %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, comp, percent * 100, cnt2, cnt); + if (data.quiet == false) log_info_nn ("Generating dictionary stats for %s: %" PRIu64 " bytes (%.2f%%), %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, comp, percent * 100, cnt2, cnt); time (&prev); } - if (data.quiet == 0) log_info ("Generated dictionary stats for %s: %" PRIu64 " bytes, %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, comp, cnt2, cnt); - if (data.quiet == 0) log_info (""); + if (data.quiet == false) log_info ("Generated dictionary stats for %s: %" PRIu64 " bytes, %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, comp, cnt2, cnt); + if (data.quiet == false) log_info (""); dictstat_append (dictstat_ctx, &d);