From e1010ffba11d3c029861aea3f39b3543241e29db Mon Sep 17 00:00:00 2001 From: jsteube Date: Sun, 23 Oct 2016 17:31:22 +0200 Subject: [PATCH] Prepare library user access to OpenCL device information without running an attack --- include/hashcat.h | 4 +- include/terminal.h | 4 +- include/types.h | 11 ++--- src/event.c | 40 +++++++++++------ src/hashcat.c | 108 +++++++++++++++++++++++++-------------------- src/hashes.c | 4 -- src/induct.c | 3 +- src/main.c | 61 ++++++++++++------------- src/main_shared.c | 33 +++++++++----- src/monitor.c | 6 ++- src/opencl.c | 58 +++++++++++++----------- src/restore.c | 12 ++--- src/status.c | 22 ++++++--- src/terminal.c | 18 +++++--- src/user_options.c | 16 +++---- 15 files changed, 226 insertions(+), 174 deletions(-) diff --git a/include/hashcat.h b/include/hashcat.h index 51302b567..cf57ba2b0 100644 --- a/include/hashcat.h +++ b/include/hashcat.h @@ -9,12 +9,14 @@ int hashcat_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t)); void hashcat_destroy (hashcat_ctx_t *hashcat_ctx); -int hashcat_session_run (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_folder, int argc, char **argv, const int comptime); +int hashcat_session_init (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_folder, int argc, char **argv, const int comptime); +int hashcat_session_run (hashcat_ctx_t *hashcat_ctx); int hashcat_session_pause (hashcat_ctx_t *hashcat_ctx); int hashcat_session_resume (hashcat_ctx_t *hashcat_ctx); int hashcat_session_bypass (hashcat_ctx_t *hashcat_ctx); int hashcat_session_checkpoint (hashcat_ctx_t *hashcat_ctx); int hashcat_session_quit (hashcat_ctx_t *hashcat_ctx); +int hashcat_session_destroy (hashcat_ctx_t *hashcat_ctx); char *hashcat_get_log (hashcat_ctx_t *hashcat_ctx); int hashcat_get_status (hashcat_ctx_t *hashcat_ctx, hashcat_status_t *hashcat_status); diff --git a/include/terminal.h b/include/terminal.h index 284411387..eb417f307 100644 --- a/include/terminal.h +++ b/include/terminal.h @@ -23,10 +23,10 @@ #include #endif // _WIN -void welcome_screen (hashcat_ctx_t *hashcat_ctx, const time_t proc_start, const char *version_tag); +void welcome_screen (hashcat_ctx_t *hashcat_ctx, const char *version_tag); void goodbye_screen (hashcat_ctx_t *hashcat_ctx, const time_t proc_start, const time_t proc_stop); -int setup_console (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx); +int setup_console (); void send_prompt (); void clear_prompt (); diff --git a/include/types.h b/include/types.h index 180816eae..5e6bd6214 100644 --- a/include/types.h +++ b/include/types.h @@ -88,8 +88,6 @@ typedef enum event_identifier EVENT_LOG_INFO = 0x00000001, EVENT_LOG_WARNING = 0x00000002, EVENT_LOG_ERROR = 0x00000003, - EVENT_WELCOME_SCREEN = 0x00000011, - EVENT_GOODBYE_SCREEN = 0x00000012, EVENT_OUTERLOOP_STARTING = 0x00000031, EVENT_OUTERLOOP_MAINSCREEN = 0x00000032, EVENT_OUTERLOOP_FINISHED = 0x00000033, @@ -1435,9 +1433,6 @@ typedef struct status_ctx time_t prepare_start; time_t prepare_time; - time_t proc_start; - time_t proc_stop; - hc_timer_t timer_running; // timer on current dict hc_timer_t timer_paused; // timer on current dict @@ -1485,8 +1480,14 @@ typedef struct hashlist_parse } hashlist_parse_t; +#define MAX_OLD_EVENTS 10 + typedef struct event_ctx { + char old_buf[MAX_OLD_EVENTS][HCBUFSIZ_TINY]; + int old_len[MAX_OLD_EVENTS]; + int old_cnt; + char msg_buf[HCBUFSIZ_TINY]; int msg_len; bool msg_newline; diff --git a/src/event.c b/src/event.c index 8a1f339bf..cc696d092 100644 --- a/src/event.c +++ b/src/event.c @@ -10,30 +10,44 @@ void event_call (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len) { - bool need_mux = true; + event_ctx_t *event_ctx = hashcat_ctx->event_ctx; + + bool is_log = false; switch (id) { - case EVENT_LOG_INFO: need_mux = false; - case EVENT_LOG_WARNING: need_mux = false; - case EVENT_LOG_ERROR: need_mux = false; + case EVENT_LOG_INFO: is_log = true; + case EVENT_LOG_WARNING: is_log = true; + case EVENT_LOG_ERROR: is_log = true; } - if (need_mux == true) + if (is_log == false) { - event_ctx_t *event_ctx = hashcat_ctx->event_ctx; - hc_thread_mutex_lock (event_ctx->mux_event); } hashcat_ctx->event (id, hashcat_ctx, buf, len); - if (need_mux == true) + if (is_log == false) { - event_ctx_t *event_ctx = hashcat_ctx->event_ctx; - hc_thread_mutex_unlock (event_ctx->mux_event); } + + // add more back logs in case user wants to access them + + if (is_log == false) + { + for (int i = MAX_OLD_EVENTS - 1; i >= 1; i--) + { + memcpy (event_ctx->old_buf[i], event_ctx->old_buf[i - 1], event_ctx->old_len[i - 1]); + + event_ctx->old_len[i] = event_ctx->old_len[i - 1]; + } + + memcpy (event_ctx->old_buf[0], buf, len); + + event_ctx->old_len[0] = len; + } } static int event_log (const char *fmt, va_list ap, char *s, const size_t sz) @@ -171,9 +185,9 @@ int event_ctx_init (hashcat_ctx_t *hashcat_ctx) { event_ctx_t *event_ctx = hashcat_ctx->event_ctx; - hc_thread_mutex_init (event_ctx->mux_event); + memset (event_ctx, 0, sizeof (event_ctx_t)); - event_ctx->msg_len = 0; + hc_thread_mutex_init (event_ctx->mux_event); return 0; } @@ -183,6 +197,4 @@ void event_ctx_destroy (hashcat_ctx_t *hashcat_ctx) event_ctx_t *event_ctx = hashcat_ctx->event_ctx; hc_thread_mutex_delete (event_ctx->mux_event); - - event_ctx->msg_len = 0; } diff --git a/src/hashcat.c b/src/hashcat.c index a1f184ab1..d91776b94 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -829,10 +829,8 @@ void hashcat_destroy (hashcat_ctx_t *hashcat_ctx) memset (hashcat_ctx, 0, sizeof (hashcat_ctx_t)); } -int hashcat_session_run (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_folder, int argc, char **argv, const int comptime) +int hashcat_session_init (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_folder, int argc, char **argv, const int comptime) { - logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; user_options_t *user_options = hashcat_ctx->user_options; /** @@ -851,8 +849,6 @@ int hashcat_session_run (hashcat_ctx_t *hashcat_ctx, char *install_folder, char if (rc_status_init == -1) return -1; - EVENT (EVENT_WELCOME_SCREEN); - /** * folder */ @@ -885,14 +881,6 @@ int hashcat_session_run (hashcat_ctx_t *hashcat_ctx, char *install_folder, char if (rc_logfile_init == -1) return -1; - logfile_generate_topid (hashcat_ctx); - - logfile_top_msg ("START"); - - // add all user options to logfile in case we want to debug some user session - - user_options_logger (hashcat_ctx); - /** * cpu affinity */ @@ -973,8 +961,6 @@ int hashcat_session_run (hashcat_ctx_t *hashcat_ctx, char *install_folder, char if (rc_dictstat_init == -1) return -1; - dictstat_read (hashcat_ctx); - /** * loopback init */ @@ -1015,6 +1001,31 @@ int hashcat_session_run (hashcat_ctx_t *hashcat_ctx, char *install_folder, char if (rc_hwmon_init == -1) return -1; + return 0; +} + +int hashcat_session_run (hashcat_ctx_t *hashcat_ctx) +{ + logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + user_options_t *user_options = hashcat_ctx->user_options; + + // add all user options to logfile in case we want to debug some user session + + user_options_logger (hashcat_ctx); + + // start logfile entry + + const time_t proc_start = time (NULL); + + logfile_generate_topid (hashcat_ctx); + + logfile_top_msg ("START"); + + // read dictionary cache + + dictstat_read (hashcat_ctx); + /** * outer loop */ @@ -1072,34 +1083,15 @@ int hashcat_session_run (hashcat_ctx_t *hashcat_ctx, char *install_folder, char // final logfile entry - time (&status_ctx->proc_stop); + const time_t proc_stop = time (NULL); - logfile_top_uint (status_ctx->proc_start); - logfile_top_uint (status_ctx->proc_stop); + logfile_top_uint (proc_start); + logfile_top_uint (proc_stop); logfile_top_msg ("STOP"); // free memory - EVENT (EVENT_GOODBYE_SCREEN); - - debugfile_destroy (hashcat_ctx); - dictstat_destroy (hashcat_ctx); - folder_config_destroy (hashcat_ctx); - hwmon_ctx_destroy (hashcat_ctx); - induct_ctx_destroy (hashcat_ctx); - logfile_destroy (hashcat_ctx); - loopback_destroy (hashcat_ctx); - opencl_ctx_destroy (hashcat_ctx); - opencl_ctx_devices_destroy (hashcat_ctx); - outcheck_ctx_destroy (hashcat_ctx); - outfile_destroy (hashcat_ctx); - potfile_destroy (hashcat_ctx); - restore_ctx_destroy (hashcat_ctx); - tuning_db_destroy (hashcat_ctx); - user_options_destroy (hashcat_ctx); - user_options_extra_destroy (hashcat_ctx); - if (rc_final == 0) { if (status_ctx->devices_status == STATUS_ABORTED) rc_final = 2; @@ -1108,10 +1100,6 @@ int hashcat_session_run (hashcat_ctx_t *hashcat_ctx, char *install_folder, char if (status_ctx->devices_status == STATUS_CRACKED) rc_final = 0; } - // do not clear status and event so we can access them from main.c after hashcat_session_run() finishes - //status_ctx_destroy (hashcat_ctx); - //event_ctx_destroy (hashcat_ctx); - // done return rc_final; @@ -1142,6 +1130,30 @@ int hashcat_session_quit (hashcat_ctx_t *hashcat_ctx) return myabort (hashcat_ctx); } +int hashcat_session_destroy (hashcat_ctx_t *hashcat_ctx) +{ + debugfile_destroy (hashcat_ctx); + dictstat_destroy (hashcat_ctx); + folder_config_destroy (hashcat_ctx); + hwmon_ctx_destroy (hashcat_ctx); + induct_ctx_destroy (hashcat_ctx); + logfile_destroy (hashcat_ctx); + loopback_destroy (hashcat_ctx); + opencl_ctx_destroy (hashcat_ctx); + opencl_ctx_devices_destroy (hashcat_ctx); + outcheck_ctx_destroy (hashcat_ctx); + outfile_destroy (hashcat_ctx); + potfile_destroy (hashcat_ctx); + restore_ctx_destroy (hashcat_ctx); + tuning_db_destroy (hashcat_ctx); + user_options_destroy (hashcat_ctx); + user_options_extra_destroy (hashcat_ctx); + status_ctx_destroy (hashcat_ctx); + event_ctx_destroy (hashcat_ctx); + + return 0; +} + char *hashcat_get_log (hashcat_ctx_t *hashcat_ctx) { event_ctx_t *event_ctx = hashcat_ctx->event_ctx; @@ -1153,6 +1165,11 @@ int hashcat_get_status (hashcat_ctx_t *hashcat_ctx, hashcat_status_t *hashcat_st { const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + memset (hashcat_status, 0, sizeof (hashcat_status_t)); + + if (status_ctx == NULL) return -1; // ways too early + + /* if (status_ctx->devices_status == STATUS_INIT) { event_log_error (hashcat_ctx, "Status view is not available during initialization phase"); @@ -1167,16 +1184,13 @@ int hashcat_get_status (hashcat_ctx_t *hashcat_ctx, hashcat_status_t *hashcat_st return -1; } - if (status_ctx->shutdown_inner == true) + if (status_ctx->devices_status == STATUS_RUNNING) { - // in this case some required buffers are free'd, ascii_digest() would run into segfault - - event_log_error (hashcat_ctx, "Status view is not available during shutdown phase"); + event_log_error (hashcat_ctx, "Status view is not available during autotune phase"); return -1; } - - memset (hashcat_status, 0, sizeof (hashcat_status_t)); + */ hashcat_status->digests_cnt = status_get_digests_cnt (hashcat_ctx); hashcat_status->digests_done = status_get_digests_done (hashcat_ctx); diff --git a/src/hashes.c b/src/hashes.c index b859b862b..a07614dcb 100644 --- a/src/hashes.c +++ b/src/hashes.c @@ -321,10 +321,6 @@ int check_cracked (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, if (num_cracked) { - // display hack (for weak hashes etc, it could be that there is still something to clear on the current line) - // still needed? - //event_log_info_nn (hashcat_ctx, ""); - plain_t *cracked = (plain_t *) hccalloc (hashcat_ctx, num_cracked, sizeof (plain_t)); VERIFY_PTR (cracked); CL_err = hc_clEnqueueReadBuffer (hashcat_ctx, device_param->command_queue, device_param->d_plain_bufs, CL_TRUE, 0, num_cracked * sizeof (plain_t), cracked, 0, NULL, NULL); diff --git a/src/induct.c b/src/induct.c index 757157419..bfd646ee5 100644 --- a/src/induct.c +++ b/src/induct.c @@ -25,7 +25,6 @@ int induct_ctx_init (hashcat_ctx_t *hashcat_ctx) { folder_config_t *folder_config = hashcat_ctx->folder_config; induct_ctx_t *induct_ctx = hashcat_ctx->induct_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; user_options_t *user_options = hashcat_ctx->user_options; induct_ctx->enabled = false; @@ -61,7 +60,7 @@ int induct_ctx_init (hashcat_ctx_t *hashcat_ctx) { char *root_directory_mv = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (root_directory_mv); - snprintf (root_directory_mv, HCBUFSIZ_TINY - 1, "%s/%s.induct.%d", folder_config->session_dir, user_options->session, (int) status_ctx->proc_start); + snprintf (root_directory_mv, HCBUFSIZ_TINY - 1, "%s/%s.induct.%d", folder_config->session_dir, user_options->session, (int) time (NULL)); if (rename (root_directory, root_directory_mv) != 0) { diff --git a/src/main.c b/src/main.c index 8cc3656e8..ef3f37ef4 100644 --- a/src/main.c +++ b/src/main.c @@ -146,34 +146,6 @@ static void main_log_error (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSE main_log (hashcat_ctx, stderr, LOGLEVEL_ERROR); } -static void main_welcome_screen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) -{ - // sets dos window size (windows only) - - setup_console (hashcat_ctx); - - // Inform user things getting started - - const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - //const user_options_t *user_options = hashcat_ctx->user_options; - - //if (user_options->machine_readable == true) return; - - welcome_screen (hashcat_ctx, status_ctx->proc_start, VERSION_TAG); -} - -static void main_goodbye_screen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) -{ - // Inform user we're done - - const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - const user_options_t *user_options = hashcat_ctx->user_options; - - if (user_options->machine_readable == true) return; - - goodbye_screen (hashcat_ctx, status_ctx->proc_start, status_ctx->proc_stop); -} - static void main_outerloop_starting (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) { const user_options_t *user_options = hashcat_ctx->user_options; @@ -816,8 +788,6 @@ void event (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const siz case EVENT_LOG_INFO: main_log_info (hashcat_ctx, buf, len); break; case EVENT_LOG_WARNING: main_log_warning (hashcat_ctx, buf, len); break; case EVENT_LOG_ERROR: main_log_error (hashcat_ctx, buf, len); break; - case EVENT_WELCOME_SCREEN: main_welcome_screen (hashcat_ctx, buf, len); break; - case EVENT_GOODBYE_SCREEN: main_goodbye_screen (hashcat_ctx, buf, len); break; case EVENT_OUTERLOOP_STARTING: main_outerloop_starting (hashcat_ctx, buf, len); break; case EVENT_OUTERLOOP_FINISHED: main_outerloop_finished (hashcat_ctx, buf, len); break; case EVENT_OUTERLOOP_MAINSCREEN: main_outerloop_mainscreen (hashcat_ctx, buf, len); break; @@ -860,6 +830,12 @@ void event (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const siz int main (int argc, char **argv) { + // this increases the size on windows dox boxes + + setup_console (); + + const time_t proc_start = time (NULL); + // hashcat main context hashcat_ctx_t *hashcat_ctx = (hashcat_ctx_t *) malloc (sizeof (hashcat_ctx_t)); VERIFY_PTR (hashcat_ctx); @@ -915,15 +891,34 @@ int main (int argc, char **argv) return 0; } - // now run hashcat + // init a hashcat session; this initializes opencl devices, hwmon, etc + + welcome_screen (hashcat_ctx, VERSION_TAG); - const int rc_hashcat = hashcat_session_run (hashcat_ctx, install_folder, shared_folder, argc, argv, COMPTIME); + const int rc_session_init = hashcat_session_init (hashcat_ctx, install_folder, shared_folder, argc, argv, COMPTIME); + + int rc_final = -1; + + if (rc_session_init == 0) + { + // now run hashcat + + rc_final = hashcat_session_run (hashcat_ctx); + } + + // finish the hashcat session, this shuts down opencl devices, hwmon, etc + + hashcat_session_destroy (hashcat_ctx); // finished with hashcat, clean up + const time_t proc_stop = time (NULL); + + goodbye_screen (hashcat_ctx, proc_start, proc_stop); + hashcat_destroy (hashcat_ctx); free (hashcat_ctx); - return rc_hashcat; + return rc_final; } diff --git a/src/main_shared.c b/src/main_shared.c index 986aee4ec..84dc34f88 100644 --- a/src/main_shared.c +++ b/src/main_shared.c @@ -67,33 +67,44 @@ int main () user_options->hash_mode = 0; // MD5 user_options->workload_profile = 3; - // now run hashcat + // init a hashcat session; this initializes opencl devices, hwmon, etc + // it does not actually run the attack but from here you can access opencl devices and hwmon information - const int rc_hashcat = hashcat_session_run (hashcat_ctx, NULL, NULL, 0, NULL, 0); + const int rc_init = hashcat_session_init (hashcat_ctx, NULL, NULL, 0, NULL, 0); - if (rc_hashcat == 0) + if (rc_init == 0) { - hashcat_status_t hashcat_status; + // this one actually starts the cracking - const int rc = hashcat_get_status (hashcat_ctx, &hashcat_status); + const int rc_run = hashcat_session_run (hashcat_ctx); - printf ("Session: %s\n", hashcat_status.session); - printf ("Status: %s\n", hashcat_status.status_string); - - if (rc == 0) + if (rc_run == 0) { - printf ("%d\n", hashcat_status.device_info_cnt); + hashcat_status_t hashcat_status; + + hashcat_get_status (hashcat_ctx, &hashcat_status); + printf ("Session: %s\n", hashcat_status.session); + printf ("Status: %s\n", hashcat_status.status_string); } + else if (rc_run == -1) + { + char *msg = hashcat_get_log (hashcat_ctx); + fprintf (stderr, "%s\n", msg); + } } - else if (rc_hashcat == -1) + else { char *msg = hashcat_get_log (hashcat_ctx); fprintf (stderr, "%s\n", msg); } + // always destroy those regardless of what the returncodes from the init functions are + + hashcat_session_destroy (hashcat_ctx); + hashcat_destroy (hashcat_ctx); free (hashcat_ctx); diff --git a/src/monitor.c b/src/monitor.c index 1fe99ca73..203b3f9c9 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -33,7 +33,11 @@ int get_runtime_left (const hashcat_ctx_t *hashcat_ctx) time (&runtime_cur); - const int runtime_left = status_ctx->proc_start + user_options->runtime + status_ctx->prepare_time + (msec_paused / 1000) - runtime_cur; + const int runtime_left = status_ctx->runtime_start + + status_ctx->prepare_time + + user_options->runtime + + (msec_paused / 1000) + - runtime_cur; return runtime_left; } diff --git a/src/opencl.c b/src/opencl.c index c77e3d9b2..c846f1a9d 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -302,21 +302,19 @@ int ocl_init (hashcat_ctx_t *hashcat_ctx) if (ocl->lib == NULL) { - event_log_error (hashcat_ctx, - "Can't find an OpenCL ICD loader library" EOL - "" EOL - #if defined (__linux__) - "You're probably missing the \"ocl-icd-libopencl1\" package (Debian/Ubuntu)" EOL - "Run: sudo apt-get install ocl-icd-libopencl1" EOL - "" EOL - #elif defined (_WIN) - "You're probably missing the OpenCL runtime installation" EOL - "* AMD users require AMD drivers 14.9 or later (recommended 15.12 exact)" EOL - "* Intel users require Intel OpenCL Runtime 14.2 or later (recommended 16.1 or later)" EOL - "* NVidia users require NVidia drivers 346.59 or later (recommended 367.27 or later)" EOL - "" EOL - #endif - ); + event_log_error (hashcat_ctx, "Can't find an OpenCL ICD loader library"); + event_log_error (hashcat_ctx, ""); + #if defined (__linux__) + event_log_error (hashcat_ctx, "You're probably missing the \"ocl-icd-libopencl1\" package (Debian/Ubuntu)"); + event_log_error (hashcat_ctx, "Run: sudo apt-get install ocl-icd-libopencl1"); + event_log_error (hashcat_ctx, ""); + #elif defined (_WIN) + event_log_error (hashcat_ctx, "You're probably missing the OpenCL runtime installation"); + event_log_error (hashcat_ctx, "* AMD users require AMD drivers 14.9 or later (recommended 15.12 exact)"); + event_log_error (hashcat_ctx, "* Intel users require Intel OpenCL Runtime 14.2 or later (recommended 16.1 or later)"); + event_log_error (hashcat_ctx, "* NVidia users require NVidia drivers 346.59 or later (recommended 367.27 or later)"); + event_log_error (hashcat_ctx, ""); + #endif return -1; } @@ -3248,8 +3246,10 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) return -1; } - if (user_options->quiet == false) event_log_info (hashcat_ctx, "SCRYPT tmto optimizer value set to: %u, mem: %" PRIu64, scrypt_tmto_final, size_scrypt); - if (user_options->quiet == false) event_log_info (hashcat_ctx, ""); + #if defined (DEBUG) + if (user_options->quiet == false) event_log_warning (hashcat_ctx, "SCRYPT tmto optimizer value set to: %u, mem: %" PRIu64, scrypt_tmto_final, size_scrypt); + if (user_options->quiet == false) event_log_warning (hashcat_ctx, ""); + #endif } size_t size_scrypt4 = size_scrypt / 4; @@ -3356,7 +3356,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) /* if (kernel_accel_max < kernel_accel) { - if (user_options->quiet == false) event_log_info (hashcat_ctx, "* Device #%u: Reduced maximum kernel-accel to %u", device_id + 1, kernel_accel_max); + if (user_options->quiet == false) event_log_warning (hashcat_ctx, "* Device #%u: Reduced maximum kernel-accel to %u", device_id + 1, kernel_accel_max); device_param->kernel_accel = kernel_accel_max; } @@ -3452,7 +3452,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) strncpy (build_opts, build_opts_new, sizeof (build_opts)); #if defined (DEBUG) - event_log_info (hashcat_ctx, "* Device #%u: build_opts '%s'", device_id + 1, build_opts); + event_log_warning (hashcat_ctx, "* Device #%u: build_opts '%s'", device_id + 1, build_opts); #endif /** @@ -3506,7 +3506,9 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) { if (cached == 0) { - if (user_options->quiet == false) event_log_info_nn (hashcat_ctx, "Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); + #if defined (DEBUG) + if (user_options->quiet == false) event_log_warning (hashcat_ctx, "Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); + #endif const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, 1, kernel_lengths, kernel_sources); @@ -3573,7 +3575,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) else { #if defined (DEBUG) - event_log_info (hashcat_ctx, "Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size); + event_log_warning (hashcat_ctx, "Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size); #endif const int rc_read_kernel = read_kernel_binary (hashcat_ctx, cached_file, 1, kernel_lengths, kernel_sources); @@ -3592,7 +3594,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) else { #if defined (DEBUG) - event_log_info (hashcat_ctx, "Device #%u: Kernel %s (%ld bytes)", device_id + 1, source_file, sst.st_size); + event_log_warning (hashcat_ctx, "Device #%u: Kernel %s (%ld bytes)", device_id + 1, source_file, sst.st_size); #endif const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, 1, kernel_lengths, kernel_sources); @@ -3710,7 +3712,9 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (cached == 0) { - if (user_options->quiet == false) event_log_info_nn (hashcat_ctx, "Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); + #if defined (DEBUG) + if (user_options->quiet == false) event_log_warning (hashcat_ctx, "Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); + #endif const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, 1, kernel_lengths, kernel_sources); @@ -3775,7 +3779,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) else { #if defined (DEBUG) - event_log_info (hashcat_ctx, "Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size); + event_log_warning (hashcat_ctx, "Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size); #endif const int rc_read_kernel = read_kernel_binary (hashcat_ctx, cached_file, 1, kernel_lengths, kernel_sources); @@ -3850,7 +3854,9 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (cached == 0) { - if (user_options->quiet == false) event_log_info_nn (hashcat_ctx, "Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); + #if defined (DEBUG) + if (user_options->quiet == false) event_log_warning (hashcat_ctx, "Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); + #endif const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, 1, kernel_lengths, kernel_sources); @@ -3915,7 +3921,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) else { #if defined (DEBUG) - if (user_options->quiet == false) event_log_info (hashcat_ctx, "Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size); + if (user_options->quiet == false) event_log_warning (hashcat_ctx, "Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size); #endif const int rc_read_kernel = read_kernel_binary (hashcat_ctx, cached_file, 1, kernel_lengths, kernel_sources); diff --git a/src/restore.c b/src/restore.c index f077da273..4a62c8866 100644 --- a/src/restore.c +++ b/src/restore.c @@ -202,15 +202,15 @@ static int read_restore (hashcat_ctx_t *hashcat_ctx) fclose (fp); - event_log_warning (hashcat_ctx, "Changing current working directory to '%s'" EOL, rd->cwd); + event_log_warning (hashcat_ctx, "Changing current working directory to '%s'", rd->cwd); + event_log_warning (hashcat_ctx, ""); if (chdir (rd->cwd)) { - event_log_error (hashcat_ctx, - "The directory '%s' does not exist. It is needed to restore (--restore) the session." EOL - "You could either create this directory or update the .restore file using e.g. the analyze_hc_restore.pl tool:" EOL - "https://github.com/philsmd/analyze_hc_restore" EOL - "The directory must contain all files and folders mentioned within the command line.", rd->cwd); + event_log_error (hashcat_ctx, "The directory '%s' does not exist. It is needed to restore (--restore) the session.", rd->cwd); + event_log_error (hashcat_ctx, "You could either create this directory or update the .restore file using e.g. the analyze_hc_restore.pl tool:"); + event_log_error (hashcat_ctx, "https://github.com/philsmd/analyze_hc_restore"); + event_log_error (hashcat_ctx, "The directory must contain all files and folders mentioned within the command line."); return -1; } diff --git a/src/status.c b/src/status.c index 9da7f1144..273b379e1 100644 --- a/src/status.c +++ b/src/status.c @@ -527,8 +527,13 @@ char *status_get_input_charset (const hashcat_ctx_t *hashcat_ctx) char *status_get_input_candidates_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id) { const opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + if (status_ctx->devices_status == STATUS_INIT) return NULL; + if (status_ctx->devices_status == STATUS_AUTOTUNE) return NULL; + if (status_ctx->devices_status == STATUS_AUTOTUNE) return NULL; + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; char *display = (char *) malloc (HCBUFSIZ_TINY); @@ -1239,7 +1244,10 @@ char *status_get_speed_sec_dev (const hashcat_ctx_t *hashcat_ctx, const int devi int status_get_cpt_cur_min (const hashcat_ctx_t *hashcat_ctx) { - const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; + const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + if (status_ctx->devices_status != STATUS_RUNNING) return 0; const time_t now = time (NULL); @@ -1261,7 +1269,10 @@ int status_get_cpt_cur_min (const hashcat_ctx_t *hashcat_ctx) int status_get_cpt_cur_hour (const hashcat_ctx_t *hashcat_ctx) { - const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; + const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + if (status_ctx->devices_status != STATUS_RUNNING) return 0; const time_t now = time (NULL); @@ -1283,7 +1294,10 @@ int status_get_cpt_cur_hour (const hashcat_ctx_t *hashcat_ctx) int status_get_cpt_cur_day (const hashcat_ctx_t *hashcat_ctx) { - const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; + const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + if (status_ctx->devices_status != STATUS_RUNNING) return 0; const time_t now = time (NULL); @@ -1529,8 +1543,6 @@ int status_ctx_init (hashcat_ctx_t *hashcat_ctx) hc_thread_mutex_init (status_ctx->mux_display); hc_thread_mutex_init (status_ctx->mux_hwmon); - time (&status_ctx->proc_start); - return 0; } diff --git a/src/terminal.c b/src/terminal.c index 20e40810f..309fc809a 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -21,9 +21,9 @@ const char *PROMPT = "[s]tatus [p]ause [r]esume [b]ypass [c]heckpoint [q]uit => "; -void welcome_screen (hashcat_ctx_t *hashcat_ctx, const time_t proc_start, const char *version_tag) +void welcome_screen (hashcat_ctx_t *hashcat_ctx, const char *version_tag) { - user_options_t *user_options = hashcat_ctx->user_options; + const user_options_t *user_options = hashcat_ctx->user_options; if (user_options->quiet == true) return; if (user_options->keyspace == true) return; @@ -40,7 +40,7 @@ void welcome_screen (hashcat_ctx_t *hashcat_ctx, const time_t proc_start, const } else { - event_log_info (hashcat_ctx, "# %s (%s) %s", PROGNAME, version_tag, ctime (&proc_start)); + event_log_info (hashcat_ctx, "# %s (%s)", PROGNAME, version_tag); } } else if (user_options->restore == true) @@ -74,28 +74,28 @@ void goodbye_screen (hashcat_ctx_t *hashcat_ctx, const time_t proc_start, const event_log_info_nn (hashcat_ctx, "Stopped: %s", ctime (&proc_stop)); } -int setup_console (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx) +int setup_console () { #if defined (_WIN) SetConsoleWindowSize (132); if (_setmode (_fileno (stdin), _O_BINARY) == -1) { - event_log_error (hashcat_ctx, "%s: %s", "stdin", strerror (errno)); + fprintf (stderr, "%s: %s", "stdin", strerror (errno)); return -1; } if (_setmode (_fileno (stdout), _O_BINARY) == -1) { - event_log_error (hashcat_ctx, "%s: %s", "stdout", strerror (errno)); + fprintf (stderr, "%s: %s", "stdin", strerror (errno)); return -1; } if (_setmode (_fileno (stderr), _O_BINARY) == -1) { - event_log_error (hashcat_ctx, "%s: %s", "stderr", strerror (errno)); + fprintf (stderr, "%s: %s", "stdin", strerror (errno)); return -1; } @@ -823,6 +823,8 @@ void status_display (hashcat_ctx_t *hashcat_ctx) if (device_info->skipped_dev == true) continue; + if (device_info->input_candidates_dev == NULL) continue; + event_log_info (hashcat_ctx, "Candidates.#%d..: %s", device_id + 1, device_info->input_candidates_dev); @@ -836,6 +838,8 @@ void status_display (hashcat_ctx_t *hashcat_ctx) if (device_info->skipped_dev == true) continue; + if (device_info->hwmon_dev == NULL) continue; + event_log_info (hashcat_ctx, "HWMon.Dev.#%d...: %s", device_id + 1, device_info->hwmon_dev); diff --git a/src/user_options.c b/src/user_options.c index ea1657f91..061bab63c 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -508,11 +508,9 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->force == false) { - event_log_error (hashcat_ctx, - "The manual use of the -n option (or --kernel-accel) is outdated." EOL - "Please consider using the -w option instead." EOL - "You can use --force to override this but do not post error reports if you do so." - ); + event_log_error (hashcat_ctx, "The manual use of the -n option (or --kernel-accel) is outdated."); + event_log_error (hashcat_ctx, "Please consider using the -w option instead."); + event_log_error (hashcat_ctx, "You can use --force to override this but do not post error reports if you do so."); return -1; } @@ -536,11 +534,9 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->force == false) { - event_log_error (hashcat_ctx, - "The manual use of the -u option (or --kernel-loops) is outdated." EOL - "Please consider using the -w option instead." EOL - "You can use --force to override this but do not post error reports if you do so." - ); + event_log_error (hashcat_ctx, "The manual use of the -u option (or --kernel-loops) is outdated."); + event_log_error (hashcat_ctx, "Please consider using the -w option instead."); + event_log_error (hashcat_ctx, "You can use --force to override this but do not post error reports if you do so."); return -1; }