diff --git a/include/hashcat.h b/include/hashcat.h index ed47ab4a4..51302b567 100644 --- a/include/hashcat.h +++ b/include/hashcat.h @@ -6,9 +6,17 @@ #ifndef _HASHCAT_H #define _HASHCAT_H -int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_folder, int argc, char **argv, const int comptime); +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_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t)); -void hashcat_ctx_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_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); + +char *hashcat_get_log (hashcat_ctx_t *hashcat_ctx); +int hashcat_get_status (hashcat_ctx_t *hashcat_ctx, hashcat_status_t *hashcat_status); #endif // _HASHCAT_H diff --git a/include/restore.h b/include/restore.h index f42760638..7a238e700 100644 --- a/include/restore.h +++ b/include/restore.h @@ -29,8 +29,6 @@ int cycle_restore (hashcat_ctx_t *hashcat_ctx); void unlink_restore (hashcat_ctx_t *hashcat_ctx); -void stop_at_checkpoint (hashcat_ctx_t *hashcat_ctx); - int restore_ctx_init (hashcat_ctx_t *hashcat_ctx, int argc, char **argv); void restore_ctx_destroy (hashcat_ctx_t *hashcat_ctx); diff --git a/include/status.h b/include/status.h index 2799f5def..eccea7bf7 100644 --- a/include/status.h +++ b/include/status.h @@ -12,16 +12,23 @@ double get_avg_exec_time (hc_device_param_t *device_param, const int last_num_entries); -void status_display_machine_readable (hashcat_ctx_t *hashcat_ctx); -void status_display (hashcat_ctx_t *hashcat_ctx); -void status_benchmark_automate (hashcat_ctx_t *hashcat_ctx); -void status_benchmark (hashcat_ctx_t *hashcat_ctx); +char *status_get_session (const hashcat_ctx_t *hashcat_ctx); +char *status_get_status_string (const hashcat_ctx_t *hashcat_ctx); +char *status_get_hash_type (const hashcat_ctx_t *hashcat_ctx); +char *status_get_hash_target (const hashcat_ctx_t *hashcat_ctx); -int status_progress_init (hashcat_ctx_t *hashcat_ctx); -void status_progress_destroy (hashcat_ctx_t *hashcat_ctx); -void status_progress_reset (hashcat_ctx_t *hashcat_ctx); +int status_get_input_mode (const hashcat_ctx_t *hashcat_ctx); +char *status_get_input_base (const hashcat_ctx_t *hashcat_ctx); +char *status_get_input_mod (const hashcat_ctx_t *hashcat_ctx); +char *status_get_input_charset (const hashcat_ctx_t *hashcat_ctx); +int status_get_input_masks_pos (const hashcat_ctx_t *hashcat_ctx); +int status_get_input_masks_cnt (const hashcat_ctx_t *hashcat_ctx); -int status_ctx_init (hashcat_ctx_t *hashcat_ctx); -void status_ctx_destroy (hashcat_ctx_t *hashcat_ctx); +int status_progress_init (hashcat_ctx_t *hashcat_ctx); +void status_progress_destroy (hashcat_ctx_t *hashcat_ctx); +void status_progress_reset (hashcat_ctx_t *hashcat_ctx); + +int status_ctx_init (hashcat_ctx_t *hashcat_ctx); +void status_ctx_destroy (hashcat_ctx_t *hashcat_ctx); #endif // _STATUS_H diff --git a/include/terminal.h b/include/terminal.h index 7312ba675..284411387 100644 --- a/include/terminal.h +++ b/include/terminal.h @@ -42,3 +42,8 @@ int tty_getchar(); int tty_fix(); #endif // _TERMINAL_H + +void status_display_machine_readable (hashcat_ctx_t *hashcat_ctx); +void status_display (hashcat_ctx_t *hashcat_ctx); +void status_benchmark_automate (hashcat_ctx_t *hashcat_ctx); +void status_benchmark (hashcat_ctx_t *hashcat_ctx); diff --git a/include/thread.h b/include/thread.h index 907af8aaa..713fe9064 100644 --- a/include/thread.h +++ b/include/thread.h @@ -56,12 +56,12 @@ void hc_signal (void (callback) (int)); #endif */ -void mycracked (hashcat_ctx_t *hashcat_ctx); -void myabort (hashcat_ctx_t *hashcat_ctx); -void myquit (hashcat_ctx_t *hashcat_ctx); -void bypass (hashcat_ctx_t *hashcat_ctx); - -void SuspendThreads (hashcat_ctx_t *hashcat_ctx); -void ResumeThreads (hashcat_ctx_t *hashcat_ctx); +int mycracked (hashcat_ctx_t *hashcat_ctx); +int myabort (hashcat_ctx_t *hashcat_ctx); +int myquit (hashcat_ctx_t *hashcat_ctx); +int bypass (hashcat_ctx_t *hashcat_ctx); +int SuspendThreads (hashcat_ctx_t *hashcat_ctx); +int ResumeThreads (hashcat_ctx_t *hashcat_ctx); +int stop_at_checkpoint (hashcat_ctx_t *hashcat_ctx); #endif // _THREAD_H diff --git a/include/types.h b/include/types.h index 91d8e0a75..38472b3cf 100644 --- a/include/types.h +++ b/include/types.h @@ -1452,6 +1452,49 @@ typedef struct hashcat_ctx } hashcat_ctx_t; +typedef struct +{ + bool skipped; + + +} device_info_t; + +typedef enum input_mode +{ + INPUT_MODE_NONE = 0, + INPUT_MODE_STRAIGHT_FILE = 1, + INPUT_MODE_STRAIGHT_FILE_RULES_FILE = 2, + INPUT_MODE_STRAIGHT_FILE_RULES_GEN = 3, + INPUT_MODE_STRAIGHT_STDIN = 4, + INPUT_MODE_STRAIGHT_STDIN_RULES_FILE = 5, + INPUT_MODE_STRAIGHT_STDIN_RULES_GEN = 6, + INPUT_MODE_COMBINATOR_BASE_LEFT = 7, + INPUT_MODE_COMBINATOR_BASE_RIGHT = 8, + INPUT_MODE_MASK = 9, + INPUT_MODE_MASK_CS = 10, + INPUT_MODE_HYBRID1 = 11, + INPUT_MODE_HYBRID1_CS = 12, + INPUT_MODE_HYBRID2 = 13, + INPUT_MODE_HYBRID2_CS = 14, + +} input_mode_t; + +typedef struct +{ + char *status; + char *session; + int input_mode; + char *input_base; + char *input_mod; + char *input_charset; + char *hash_type; + char *hash_target; + + device_info_t device_info_buf[DEVICES_MAX]; + int device_info_cnt; + +} hashcat_status_t; + typedef struct thread_param { u32 tid; diff --git a/src/hashcat.c b/src/hashcat.c index 9f96a1827..f4c6688da 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -55,78 +55,6 @@ extern const u32 DEFAULT_BENCHMARK_ALGORITHMS_CNT; extern const u32 DEFAULT_BENCHMARK_ALGORITHMS_BUF[]; -int hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t)) -{ - if (event == NULL) - { - fprintf (stderr, "Event callback function is mandatory\n"); - - return -1; - } - - hashcat_ctx->event = event; - - hashcat_ctx->bitmap_ctx = (bitmap_ctx_t *) hcmalloc (hashcat_ctx, sizeof (bitmap_ctx_t)); VERIFY_PTR (hashcat_ctx->bitmap_ctx); - hashcat_ctx->combinator_ctx = (combinator_ctx_t *) hcmalloc (hashcat_ctx, sizeof (combinator_ctx_t)); VERIFY_PTR (hashcat_ctx->combinator_ctx); - hashcat_ctx->cpt_ctx = (cpt_ctx_t *) hcmalloc (hashcat_ctx, sizeof (cpt_ctx_t)); VERIFY_PTR (hashcat_ctx->cpt_ctx); - hashcat_ctx->debugfile_ctx = (debugfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (debugfile_ctx_t)); VERIFY_PTR (hashcat_ctx->debugfile_ctx); - hashcat_ctx->dictstat_ctx = (dictstat_ctx_t *) hcmalloc (hashcat_ctx, sizeof (dictstat_ctx_t)); VERIFY_PTR (hashcat_ctx->dictstat_ctx); - hashcat_ctx->event_ctx = (event_ctx_t *) hcmalloc (hashcat_ctx, sizeof (event_ctx_t)); VERIFY_PTR (hashcat_ctx->event_ctx); - hashcat_ctx->folder_config = (folder_config_t *) hcmalloc (hashcat_ctx, sizeof (folder_config_t)); VERIFY_PTR (hashcat_ctx->folder_config); - hashcat_ctx->hashcat_user = (hashcat_user_t *) hcmalloc (hashcat_ctx, sizeof (hashcat_user_t)); VERIFY_PTR (hashcat_ctx->hashcat_user); - hashcat_ctx->hashconfig = (hashconfig_t *) hcmalloc (hashcat_ctx, sizeof (hashconfig_t)); VERIFY_PTR (hashcat_ctx->hashconfig); - hashcat_ctx->hashes = (hashes_t *) hcmalloc (hashcat_ctx, sizeof (hashes_t)); VERIFY_PTR (hashcat_ctx->hashes); - hashcat_ctx->hwmon_ctx = (hwmon_ctx_t *) hcmalloc (hashcat_ctx, sizeof (hwmon_ctx_t)); VERIFY_PTR (hashcat_ctx->hwmon_ctx); - hashcat_ctx->induct_ctx = (induct_ctx_t *) hcmalloc (hashcat_ctx, sizeof (induct_ctx_t)); VERIFY_PTR (hashcat_ctx->induct_ctx); - hashcat_ctx->logfile_ctx = (logfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (logfile_ctx_t)); VERIFY_PTR (hashcat_ctx->logfile_ctx); - hashcat_ctx->loopback_ctx = (loopback_ctx_t *) hcmalloc (hashcat_ctx, sizeof (loopback_ctx_t)); VERIFY_PTR (hashcat_ctx->loopback_ctx); - hashcat_ctx->mask_ctx = (mask_ctx_t *) hcmalloc (hashcat_ctx, sizeof (mask_ctx_t)); VERIFY_PTR (hashcat_ctx->mask_ctx); - hashcat_ctx->opencl_ctx = (opencl_ctx_t *) hcmalloc (hashcat_ctx, sizeof (opencl_ctx_t)); VERIFY_PTR (hashcat_ctx->opencl_ctx); - hashcat_ctx->outcheck_ctx = (outcheck_ctx_t *) hcmalloc (hashcat_ctx, sizeof (outcheck_ctx_t)); VERIFY_PTR (hashcat_ctx->outcheck_ctx); - hashcat_ctx->outfile_ctx = (outfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (outfile_ctx_t)); VERIFY_PTR (hashcat_ctx->outfile_ctx); - hashcat_ctx->potfile_ctx = (potfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (potfile_ctx_t)); VERIFY_PTR (hashcat_ctx->potfile_ctx); - hashcat_ctx->restore_ctx = (restore_ctx_t *) hcmalloc (hashcat_ctx, sizeof (restore_ctx_t)); VERIFY_PTR (hashcat_ctx->restore_ctx); - hashcat_ctx->status_ctx = (status_ctx_t *) hcmalloc (hashcat_ctx, sizeof (status_ctx_t)); VERIFY_PTR (hashcat_ctx->status_ctx); - hashcat_ctx->straight_ctx = (straight_ctx_t *) hcmalloc (hashcat_ctx, sizeof (straight_ctx_t)); VERIFY_PTR (hashcat_ctx->straight_ctx); - hashcat_ctx->tuning_db = (tuning_db_t *) hcmalloc (hashcat_ctx, sizeof (tuning_db_t)); VERIFY_PTR (hashcat_ctx->tuning_db); - hashcat_ctx->user_options_extra = (user_options_extra_t *) hcmalloc (hashcat_ctx, sizeof (user_options_extra_t)); VERIFY_PTR (hashcat_ctx->user_options_extra); - hashcat_ctx->user_options = (user_options_t *) hcmalloc (hashcat_ctx, sizeof (user_options_t)); VERIFY_PTR (hashcat_ctx->user_options); - hashcat_ctx->wl_data = (wl_data_t *) hcmalloc (hashcat_ctx, sizeof (wl_data_t)); VERIFY_PTR (hashcat_ctx->wl_data); - - return 0; -} - -void hashcat_ctx_destroy (hashcat_ctx_t *hashcat_ctx) -{ - hcfree (hashcat_ctx->bitmap_ctx); - hcfree (hashcat_ctx->combinator_ctx); - hcfree (hashcat_ctx->cpt_ctx); - hcfree (hashcat_ctx->debugfile_ctx); - hcfree (hashcat_ctx->dictstat_ctx); - hcfree (hashcat_ctx->event_ctx); - hcfree (hashcat_ctx->folder_config); - hcfree (hashcat_ctx->hashconfig); - hcfree (hashcat_ctx->hashes); - hcfree (hashcat_ctx->hwmon_ctx); - hcfree (hashcat_ctx->induct_ctx); - hcfree (hashcat_ctx->logfile_ctx); - hcfree (hashcat_ctx->loopback_ctx); - hcfree (hashcat_ctx->mask_ctx); - hcfree (hashcat_ctx->opencl_ctx); - hcfree (hashcat_ctx->outcheck_ctx); - hcfree (hashcat_ctx->outfile_ctx); - hcfree (hashcat_ctx->potfile_ctx); - hcfree (hashcat_ctx->restore_ctx); - hcfree (hashcat_ctx->status_ctx); - hcfree (hashcat_ctx->straight_ctx); - hcfree (hashcat_ctx->tuning_db); - hcfree (hashcat_ctx->user_options_extra); - hcfree (hashcat_ctx->user_options); - hcfree (hashcat_ctx->wl_data); - - memset (hashcat_ctx, 0, sizeof (hashcat_ctx_t)); -} - // inner2_loop iterates through wordlists, then calls kernel execution static int inner2_loop (hashcat_ctx_t *hashcat_ctx) @@ -809,7 +737,79 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) return 0; } -int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_folder, int argc, char **argv, const int comptime) +int hashcat_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t)) +{ + if (event == NULL) + { + fprintf (stderr, "Event callback function is mandatory\n"); + + return -1; + } + + hashcat_ctx->event = event; + + hashcat_ctx->bitmap_ctx = (bitmap_ctx_t *) hcmalloc (hashcat_ctx, sizeof (bitmap_ctx_t)); VERIFY_PTR (hashcat_ctx->bitmap_ctx); + hashcat_ctx->combinator_ctx = (combinator_ctx_t *) hcmalloc (hashcat_ctx, sizeof (combinator_ctx_t)); VERIFY_PTR (hashcat_ctx->combinator_ctx); + hashcat_ctx->cpt_ctx = (cpt_ctx_t *) hcmalloc (hashcat_ctx, sizeof (cpt_ctx_t)); VERIFY_PTR (hashcat_ctx->cpt_ctx); + hashcat_ctx->debugfile_ctx = (debugfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (debugfile_ctx_t)); VERIFY_PTR (hashcat_ctx->debugfile_ctx); + hashcat_ctx->dictstat_ctx = (dictstat_ctx_t *) hcmalloc (hashcat_ctx, sizeof (dictstat_ctx_t)); VERIFY_PTR (hashcat_ctx->dictstat_ctx); + hashcat_ctx->event_ctx = (event_ctx_t *) hcmalloc (hashcat_ctx, sizeof (event_ctx_t)); VERIFY_PTR (hashcat_ctx->event_ctx); + hashcat_ctx->folder_config = (folder_config_t *) hcmalloc (hashcat_ctx, sizeof (folder_config_t)); VERIFY_PTR (hashcat_ctx->folder_config); + hashcat_ctx->hashcat_user = (hashcat_user_t *) hcmalloc (hashcat_ctx, sizeof (hashcat_user_t)); VERIFY_PTR (hashcat_ctx->hashcat_user); + hashcat_ctx->hashconfig = (hashconfig_t *) hcmalloc (hashcat_ctx, sizeof (hashconfig_t)); VERIFY_PTR (hashcat_ctx->hashconfig); + hashcat_ctx->hashes = (hashes_t *) hcmalloc (hashcat_ctx, sizeof (hashes_t)); VERIFY_PTR (hashcat_ctx->hashes); + hashcat_ctx->hwmon_ctx = (hwmon_ctx_t *) hcmalloc (hashcat_ctx, sizeof (hwmon_ctx_t)); VERIFY_PTR (hashcat_ctx->hwmon_ctx); + hashcat_ctx->induct_ctx = (induct_ctx_t *) hcmalloc (hashcat_ctx, sizeof (induct_ctx_t)); VERIFY_PTR (hashcat_ctx->induct_ctx); + hashcat_ctx->logfile_ctx = (logfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (logfile_ctx_t)); VERIFY_PTR (hashcat_ctx->logfile_ctx); + hashcat_ctx->loopback_ctx = (loopback_ctx_t *) hcmalloc (hashcat_ctx, sizeof (loopback_ctx_t)); VERIFY_PTR (hashcat_ctx->loopback_ctx); + hashcat_ctx->mask_ctx = (mask_ctx_t *) hcmalloc (hashcat_ctx, sizeof (mask_ctx_t)); VERIFY_PTR (hashcat_ctx->mask_ctx); + hashcat_ctx->opencl_ctx = (opencl_ctx_t *) hcmalloc (hashcat_ctx, sizeof (opencl_ctx_t)); VERIFY_PTR (hashcat_ctx->opencl_ctx); + hashcat_ctx->outcheck_ctx = (outcheck_ctx_t *) hcmalloc (hashcat_ctx, sizeof (outcheck_ctx_t)); VERIFY_PTR (hashcat_ctx->outcheck_ctx); + hashcat_ctx->outfile_ctx = (outfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (outfile_ctx_t)); VERIFY_PTR (hashcat_ctx->outfile_ctx); + hashcat_ctx->potfile_ctx = (potfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (potfile_ctx_t)); VERIFY_PTR (hashcat_ctx->potfile_ctx); + hashcat_ctx->restore_ctx = (restore_ctx_t *) hcmalloc (hashcat_ctx, sizeof (restore_ctx_t)); VERIFY_PTR (hashcat_ctx->restore_ctx); + hashcat_ctx->status_ctx = (status_ctx_t *) hcmalloc (hashcat_ctx, sizeof (status_ctx_t)); VERIFY_PTR (hashcat_ctx->status_ctx); + hashcat_ctx->straight_ctx = (straight_ctx_t *) hcmalloc (hashcat_ctx, sizeof (straight_ctx_t)); VERIFY_PTR (hashcat_ctx->straight_ctx); + hashcat_ctx->tuning_db = (tuning_db_t *) hcmalloc (hashcat_ctx, sizeof (tuning_db_t)); VERIFY_PTR (hashcat_ctx->tuning_db); + hashcat_ctx->user_options_extra = (user_options_extra_t *) hcmalloc (hashcat_ctx, sizeof (user_options_extra_t)); VERIFY_PTR (hashcat_ctx->user_options_extra); + hashcat_ctx->user_options = (user_options_t *) hcmalloc (hashcat_ctx, sizeof (user_options_t)); VERIFY_PTR (hashcat_ctx->user_options); + hashcat_ctx->wl_data = (wl_data_t *) hcmalloc (hashcat_ctx, sizeof (wl_data_t)); VERIFY_PTR (hashcat_ctx->wl_data); + + return 0; +} + +void hashcat_destroy (hashcat_ctx_t *hashcat_ctx) +{ + hcfree (hashcat_ctx->bitmap_ctx); + hcfree (hashcat_ctx->combinator_ctx); + hcfree (hashcat_ctx->cpt_ctx); + hcfree (hashcat_ctx->debugfile_ctx); + hcfree (hashcat_ctx->dictstat_ctx); + hcfree (hashcat_ctx->event_ctx); + hcfree (hashcat_ctx->folder_config); + hcfree (hashcat_ctx->hashconfig); + hcfree (hashcat_ctx->hashes); + hcfree (hashcat_ctx->hwmon_ctx); + hcfree (hashcat_ctx->induct_ctx); + hcfree (hashcat_ctx->logfile_ctx); + hcfree (hashcat_ctx->loopback_ctx); + hcfree (hashcat_ctx->mask_ctx); + hcfree (hashcat_ctx->opencl_ctx); + hcfree (hashcat_ctx->outcheck_ctx); + hcfree (hashcat_ctx->outfile_ctx); + hcfree (hashcat_ctx->potfile_ctx); + hcfree (hashcat_ctx->restore_ctx); + hcfree (hashcat_ctx->status_ctx); + hcfree (hashcat_ctx->straight_ctx); + hcfree (hashcat_ctx->tuning_db); + hcfree (hashcat_ctx->user_options_extra); + hcfree (hashcat_ctx->user_options); + hcfree (hashcat_ctx->wl_data); + + 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) { logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx; status_ctx_t *status_ctx = hashcat_ctx->status_ctx; @@ -1088,10 +1088,67 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold if (status_ctx->devices_status == STATUS_CRACKED) rc_final = 0; } - status_ctx_destroy (hashcat_ctx); - event_ctx_destroy (hashcat_ctx); + // 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; } + +int hashcat_session_pause (hashcat_ctx_t *hashcat_ctx) +{ + return SuspendThreads (hashcat_ctx); +} + +int hashcat_session_resume (hashcat_ctx_t *hashcat_ctx) +{ + return ResumeThreads (hashcat_ctx); +} + +int hashcat_session_bypass (hashcat_ctx_t *hashcat_ctx) +{ + return bypass (hashcat_ctx); +} + +int hashcat_session_checkpoint (hashcat_ctx_t *hashcat_ctx) +{ + return stop_at_checkpoint (hashcat_ctx); +} + +int hashcat_session_quit (hashcat_ctx_t *hashcat_ctx) +{ + return myabort (hashcat_ctx); +} + +char *hashcat_get_log (hashcat_ctx_t *hashcat_ctx) +{ + event_ctx_t *event_ctx = hashcat_ctx->event_ctx; + + return event_ctx->msg_buf; +} + +int hashcat_get_status (hashcat_ctx_t *hashcat_ctx, hashcat_status_t *hashcat_status) +{ + memset (hashcat_status, 0, sizeof (hashcat_status_t)); + + hashcat_status->session = status_get_session (hashcat_ctx); + hashcat_status->status = status_get_status_string (hashcat_ctx); + hashcat_status->input_mode = status_get_input_mode (hashcat_ctx); + hashcat_status->input_base = status_get_input_base (hashcat_ctx); + hashcat_status->input_mod = status_get_input_mod (hashcat_ctx); + hashcat_status->input_charset = status_get_input_charset (hashcat_ctx); + hashcat_status->hash_type = status_get_hash_type (hashcat_ctx); + hashcat_status->hash_target = status_get_hash_target (hashcat_ctx); + + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + if (status_ctx->devices_status == STATUS_INIT) return -1; + if (status_ctx->devices_status == STATUS_AUTOTUNE) return -1; + + if (status_ctx->shutdown_inner == true) return -1; + + + return 0; +} diff --git a/src/main.c b/src/main.c index 74cac2222..6c9c8a3d7 100644 --- a/src/main.c +++ b/src/main.c @@ -550,7 +550,7 @@ int main (int argc, char **argv) hashcat_ctx_t *hashcat_ctx = (hashcat_ctx_t *) malloc (sizeof (hashcat_ctx_t)); VERIFY_PTR (hashcat_ctx); - const int rc_hashcat_init = hashcat_ctx_init (hashcat_ctx, event); + const int rc_hashcat_init = hashcat_init (hashcat_ctx, event); if (rc_hashcat_init == -1) return -1; @@ -603,11 +603,11 @@ int main (int argc, char **argv) // now run hashcat - const int rc_hashcat = hashcat (hashcat_ctx, install_folder, shared_folder, argc, argv, COMPTIME); + const int rc_hashcat = hashcat_session_run (hashcat_ctx, install_folder, shared_folder, argc, argv, COMPTIME); // finished with hashcat, clean up - hashcat_ctx_destroy (hashcat_ctx); + hashcat_destroy (hashcat_ctx); free (hashcat_ctx); diff --git a/src/main_shared.c b/src/main_shared.c index 328165e8b..7312b94d4 100644 --- a/src/main_shared.c +++ b/src/main_shared.c @@ -38,7 +38,7 @@ int main () assert (hashcat_ctx); - const int rc_hashcat_init = hashcat_ctx_init (hashcat_ctx, event); + const int rc_hashcat_init = hashcat_init (hashcat_ctx, event); if (rc_hashcat_init == -1) return -1; @@ -69,20 +69,32 @@ int main () // now run hashcat - const int rc_hashcat = hashcat (hashcat_ctx, NULL, NULL, 0, NULL, 0); + const int rc_hashcat = hashcat_session_run (hashcat_ctx, NULL, NULL, 0, NULL, 0); if (rc_hashcat == 0) { - puts ("YAY, all hashes cracked!!"); + hashcat_status_t hashcat_status; + + const int rc = hashcat_get_status (hashcat_ctx, &hashcat_status); + + printf ("Session: %s\n", hashcat_status.session); + printf ("Status: %s\n", hashcat_status.status); + + if (rc == 0) + { + printf ("%d\n", hashcat_status.device_info_cnt); + + } + } else if (rc_hashcat == -1) { - event_ctx_t *event_ctx = hashcat_ctx->event_ctx; + char *msg = hashcat_get_log (hashcat_ctx); - fprintf (stderr, "%s\n", event_ctx->msg_buf); + fprintf (stderr, "%s\n", msg); } - hashcat_ctx_destroy (hashcat_ctx); + hashcat_destroy (hashcat_ctx); free (hashcat_ctx); diff --git a/src/restore.c b/src/restore.c index cf1c5a0c3..db9a7df3d 100644 --- a/src/restore.c +++ b/src/restore.c @@ -349,44 +349,6 @@ void unlink_restore (hashcat_ctx_t *hashcat_ctx) } } -void stop_at_checkpoint (hashcat_ctx_t *hashcat_ctx) -{ - restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - - // this feature only makes sense if --restore-disable was not specified - - if (restore_ctx->enabled == false) - { - event_log_warning (hashcat_ctx, "This feature is disabled when --restore-disable is specified"); - - return; - } - - if (status_ctx->devices_status != STATUS_RUNNING) return; - - if ((status_ctx->run_thread_level1 == true) && (status_ctx->run_thread_level2 == true)) - { - status_ctx->run_main_level1 = false; - status_ctx->run_main_level2 = false; - status_ctx->run_main_level3 = false; - status_ctx->run_thread_level1 = false; - status_ctx->run_thread_level2 = true; - - event_log_info (hashcat_ctx, "Checkpoint enabled: Will quit at next Restore Point update"); - } - else - { - status_ctx->run_main_level1 = true; - status_ctx->run_main_level2 = true; - status_ctx->run_main_level3 = true; - status_ctx->run_thread_level1 = true; - status_ctx->run_thread_level2 = true; - - event_log_info (hashcat_ctx, "Checkpoint disabled: Restore Point updates will no longer be monitored"); - } -} - int restore_ctx_init (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) { folder_config_t *folder_config = hashcat_ctx->folder_config; diff --git a/src/status.c b/src/status.c index 572c49a35..4167aa7d2 100644 --- a/src/status.c +++ b/src/status.c @@ -25,98 +25,31 @@ static const char ST_0005[] = "Cracked"; static const char ST_0006[] = "Aborted"; static const char ST_0007[] = "Quit"; static const char ST_0008[] = "Bypass"; +static const char ST_9999[] = "Unknown! Bug!"; -static void format_timer_display (struct tm *tm, char *buf, size_t len) +static char *status_get_rules_file (const hashcat_ctx_t *hashcat_ctx) { - const char *time_entities_s[] = { "year", "day", "hour", "min", "sec" }; - const char *time_entities_m[] = { "years", "days", "hours", "mins", "secs" }; + const user_options_t *user_options = hashcat_ctx->user_options; - if (tm->tm_year - 70) + if (user_options->rp_files_cnt > 0) { - char *time_entity1 = ((tm->tm_year - 70) == 1) ? (char *) time_entities_s[0] : (char *) time_entities_m[0]; - char *time_entity2 = ( tm->tm_yday == 1) ? (char *) time_entities_s[1] : (char *) time_entities_m[1]; + char *tmp_buf = (char *) malloc (HCBUFSIZ_TINY); - snprintf (buf, len - 1, "%d %s, %d %s", tm->tm_year - 70, time_entity1, tm->tm_yday, time_entity2); - } - else if (tm->tm_yday) - { - char *time_entity1 = (tm->tm_yday == 1) ? (char *) time_entities_s[1] : (char *) time_entities_m[1]; - char *time_entity2 = (tm->tm_hour == 1) ? (char *) time_entities_s[2] : (char *) time_entities_m[2]; - - snprintf (buf, len - 1, "%d %s, %d %s", tm->tm_yday, time_entity1, tm->tm_hour, time_entity2); - } - else if (tm->tm_hour) - { - char *time_entity1 = (tm->tm_hour == 1) ? (char *) time_entities_s[2] : (char *) time_entities_m[2]; - char *time_entity2 = (tm->tm_min == 1) ? (char *) time_entities_s[3] : (char *) time_entities_m[3]; - - snprintf (buf, len - 1, "%d %s, %d %s", tm->tm_hour, time_entity1, tm->tm_min, time_entity2); - } - else if (tm->tm_min) - { - char *time_entity1 = (tm->tm_min == 1) ? (char *) time_entities_s[3] : (char *) time_entities_m[3]; - char *time_entity2 = (tm->tm_sec == 1) ? (char *) time_entities_s[4] : (char *) time_entities_m[4]; - - snprintf (buf, len - 1, "%d %s, %d %s", tm->tm_min, time_entity1, tm->tm_sec, time_entity2); - } - else - { - char *time_entity1 = (tm->tm_sec == 1) ? (char *) time_entities_s[4] : (char *) time_entities_m[4]; - - snprintf (buf, len - 1, "%d %s", tm->tm_sec, time_entity1); - } -} - -static void format_speed_display (double val, char *buf, size_t len) -{ - if (val <= 0) - { - buf[0] = '0'; - buf[1] = ' '; - buf[2] = 0; - - return; - } + int tmp_len = 0; - char units[7] = { ' ', 'k', 'M', 'G', 'T', 'P', 'E' }; + u32 i; - u32 level = 0; + for (i = 0; i < user_options->rp_files_cnt - 1; i++) + { + tmp_len += snprintf (tmp_buf + tmp_len, HCBUFSIZ_TINY - tmp_len - 1, "%s, ", user_options->rp_files[i]); + } - while (val > 99999) - { - val /= 1000; + tmp_len += snprintf (tmp_buf + tmp_len, HCBUFSIZ_TINY - tmp_len - 1, "%s", user_options->rp_files[i]); - level++; + return tmp_buf; // yes, user need to free() } - /* generate output */ - - if (level == 0) - { - snprintf (buf, len - 1, "%.0f ", val); - } - else - { - snprintf (buf, len - 1, "%.1f %c", val, units[level]); - } -} - -static char *strstatus (const u32 devices_status) -{ - switch (devices_status) - { - case STATUS_INIT: return ((char *) ST_0000); - case STATUS_AUTOTUNE: return ((char *) ST_0001); - case STATUS_RUNNING: return ((char *) ST_0002); - case STATUS_PAUSED: return ((char *) ST_0003); - case STATUS_EXHAUSTED: return ((char *) ST_0004); - case STATUS_CRACKED: return ((char *) ST_0005); - case STATUS_ABORTED: return ((char *) ST_0006); - case STATUS_QUIT: return ((char *) ST_0007); - case STATUS_BYPASS: return ((char *) ST_0008); - } - - return ((char *) "Uninitialized! Bug!"); + return NULL; } double get_avg_exec_time (hc_device_param_t *device_param, const int last_num_entries) @@ -146,1202 +79,340 @@ double get_avg_exec_time (hc_device_param_t *device_param, const int last_num_en return exec_ms_sum / exec_ms_cnt; } -void status_display_machine_readable (hashcat_ctx_t *hashcat_ctx) +char *status_get_session (const hashcat_ctx_t *hashcat_ctx) { - combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; - hashes_t *hashes = hashcat_ctx->hashes; - mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; - user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; - user_options_t *user_options = hashcat_ctx->user_options; - - if (status_ctx->devices_status == STATUS_INIT) - { - event_log_error (hashcat_ctx, "status view is not available during initialization phase"); - - return; - } - - if (status_ctx->devices_status == STATUS_AUTOTUNE) - { - event_log_error (hashcat_ctx, "status view is not available during autotune phase"); - - return; - } - - FILE *out = stdout; - - fprintf (out, "STATUS\t%u\t", status_ctx->devices_status); - - /** - * speed new - */ - - fprintf (out, "SPEED\t"); - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; - - u64 speed_cnt = 0; - double speed_ms = 0; - - for (int i = 0; i < SPEED_CACHE; i++) - { - speed_cnt += device_param->speed_cnt[i]; - speed_ms += device_param->speed_ms[i]; - } - - speed_cnt /= SPEED_CACHE; - speed_ms /= SPEED_CACHE; - - fprintf (out, "%" PRIu64 "\t%f\t", speed_cnt, speed_ms); - } - - /** - * exec time - */ - - fprintf (out, "EXEC_RUNTIME\t"); - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; + const user_options_t *user_options = hashcat_ctx->user_options; - double exec_ms_avg = get_avg_exec_time (device_param, EXEC_CACHE); - - fprintf (out, "%f\t", exec_ms_avg); - } - - /** - * words_cur - */ - - u64 words_cur = get_lowest_words_done (hashcat_ctx); - - fprintf (out, "CURKU\t%" PRIu64 "\t", words_cur); - - /** - * counter - */ - - u64 progress_total = status_ctx->words_cnt * hashes->salts_cnt; - - u64 all_done = 0; - u64 all_rejected = 0; - u64 all_restored = 0; - - for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) - { - all_done += status_ctx->words_progress_done[salt_pos]; - all_rejected += status_ctx->words_progress_rejected[salt_pos]; - all_restored += status_ctx->words_progress_restored[salt_pos]; - } - - u64 progress_cur = all_restored + all_done + all_rejected; - u64 progress_end = progress_total; - - u64 progress_skip = 0; - - if (user_options->skip) - { - progress_skip = MIN (user_options->skip, status_ctx->words_base) * hashes->salts_cnt; - - if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_skip *= straight_ctx->kernel_rules_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_skip *= combinator_ctx->combs_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_skip *= mask_ctx->bfs_cnt; - } - - if (user_options->limit) - { - progress_end = MIN (user_options->limit, status_ctx->words_base) * hashes->salts_cnt; - - if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_end *= straight_ctx->kernel_rules_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_end *= combinator_ctx->combs_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_end *= mask_ctx->bfs_cnt; - } - - u64 progress_cur_relative_skip = progress_cur - progress_skip; - u64 progress_end_relative_skip = progress_end - progress_skip; - - fprintf (out, "PROGRESS\t%" PRIu64 "\t%" PRIu64 "\t", progress_cur_relative_skip, progress_end_relative_skip); - - /** - * cracks - */ - - fprintf (out, "RECHASH\t%u\t%u\t", hashes->digests_done, hashes->digests_cnt); - fprintf (out, "RECSALT\t%u\t%u\t", hashes->salts_done, hashes->salts_cnt); - - /** - * temperature - */ - - if (user_options->gpu_temp_disable == false) - { - fprintf (out, "TEMP\t"); - - hc_thread_mutex_lock (status_ctx->mux_hwmon); - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; - - int temp = hm_get_temperature_with_device_id (hashcat_ctx, device_id); - - fprintf (out, "%d\t", temp); - } - - hc_thread_mutex_unlock (status_ctx->mux_hwmon); - } - - /** - * flush - */ - - fputs (EOL, out); - fflush (out); + return user_options->session; } -void status_display (hashcat_ctx_t *hashcat_ctx) +char *status_get_status_string (const hashcat_ctx_t *hashcat_ctx) { - combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; - cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - hashes_t *hashes = hashcat_ctx->hashes; - mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; - user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; - user_options_t *user_options = hashcat_ctx->user_options; - - if (status_ctx->devices_status == STATUS_INIT) - { - event_log_error (hashcat_ctx, "status view is not available during initialization phase"); - - return; - } - - if (status_ctx->devices_status == STATUS_AUTOTUNE) - { - event_log_error (hashcat_ctx, "status view is not available during autotune phase"); - - return; - } - - // in this case some required buffers are free'd, ascii_digest() would run into segfault - if (status_ctx->shutdown_inner == 1) return; - - if (user_options->machine_readable == true) - { - status_display_machine_readable (hashcat_ctx); - - return; - } - - char tmp_buf[1000] = { 0 }; - - u32 tmp_len = 0; - - event_log_info (hashcat_ctx, "Session.Name...: %s", user_options->session); - - char *status_type = strstatus (status_ctx->devices_status); - - u32 hash_mode = hashconfig->hash_mode; - - char *hash_type = strhashtype (hash_mode); // not a bug - - event_log_info (hashcat_ctx, "Status.........: %s", status_type); - - /** - * show rules - */ - - if (user_options->rp_files_cnt) - { - u32 i; + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - for (i = 0, tmp_len = 0; i < user_options->rp_files_cnt - 1 && tmp_len < sizeof (tmp_buf); i++) - { - tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, "File (%s), ", user_options->rp_files[i]); - } - - snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, "File (%s)", user_options->rp_files[i]); - - event_log_info (hashcat_ctx, "Rules.Type.....: %s", tmp_buf); - - tmp_len = 0; - } - - if (user_options->rp_gen) - { - event_log_info (hashcat_ctx, "Rules.Type.....: Generated (%u)", user_options->rp_gen); + const int devices_status = status_ctx->devices_status; - if (user_options->rp_gen_seed) - { - event_log_info (hashcat_ctx, "Rules.Seed.....: %u", user_options->rp_gen_seed); - } - } - - /** - * show input - */ - - char *custom_charset_1 = user_options->custom_charset_1; - char *custom_charset_2 = user_options->custom_charset_2; - char *custom_charset_3 = user_options->custom_charset_3; - char *custom_charset_4 = user_options->custom_charset_4; - - if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) - { - if (user_options_extra->wordlist_mode == WL_MODE_FILE) - { - event_log_info (hashcat_ctx, "Input.Mode.....: File (%s)", straight_ctx->dict); - } - else if (user_options_extra->wordlist_mode == WL_MODE_STDIN) - { - event_log_info (hashcat_ctx, "Input.Mode.....: Pipe"); - } - } - else if (user_options->attack_mode == ATTACK_MODE_COMBI) + switch (devices_status) { - event_log_info (hashcat_ctx, "Input.Left.....: File (%s)", combinator_ctx->dict1); - event_log_info (hashcat_ctx, "Input.Right....: File (%s)", combinator_ctx->dict2); + case STATUS_INIT: return ((char *) ST_0000); + case STATUS_AUTOTUNE: return ((char *) ST_0001); + case STATUS_RUNNING: return ((char *) ST_0002); + case STATUS_PAUSED: return ((char *) ST_0003); + case STATUS_EXHAUSTED: return ((char *) ST_0004); + case STATUS_CRACKED: return ((char *) ST_0005); + case STATUS_ABORTED: return ((char *) ST_0006); + case STATUS_QUIT: return ((char *) ST_0007); + case STATUS_BYPASS: return ((char *) ST_0008); } - else if (user_options->attack_mode == ATTACK_MODE_BF) - { - char *mask = mask_ctx->mask; - - if (mask != NULL) - { - u32 mask_len = mask_ctx->css_cnt; - - tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, "Mask (%s)", mask); - if (mask_len > 0) - { - if (hashconfig->opti_type & OPTI_TYPE_SINGLE_HASH) - { - if (hashconfig->opti_type & OPTI_TYPE_APPENDED_SALT) - { - mask_len -= hashes->salts_buf[0].salt_len; - } - } - - if (hashconfig->opts_type & OPTS_TYPE_PT_UNICODE) mask_len /= 2; - - tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, " [%i]", mask_len); - } - - if (mask_ctx->masks_cnt > 1) - { - const int maks_pos_done = ((status_ctx->devices_status == STATUS_EXHAUSTED) && (status_ctx->run_main_level1 == true)) ? 1 : 0; - - double mask_percentage = (double) (mask_ctx->masks_pos + maks_pos_done) / (double) mask_ctx->masks_cnt; - - tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, " (%.02f%%)", mask_percentage * 100); - } - - event_log_info (hashcat_ctx, "Input.Mode.....: %s", tmp_buf); - - if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL)) - { - if (custom_charset_1 == NULL) custom_charset_1 = "Undefined"; - if (custom_charset_2 == NULL) custom_charset_2 = "Undefined"; - if (custom_charset_3 == NULL) custom_charset_3 = "Undefined"; - if (custom_charset_4 == NULL) custom_charset_4 = "Undefined"; - - event_log_info (hashcat_ctx, "Custom.Charset.: -1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4); - } - } - - tmp_len = 0; - } - else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) - { - event_log_info (hashcat_ctx, "Input.Left.....: File (%s)", straight_ctx->dict); - event_log_info (hashcat_ctx, "Input.Right....: Mask (%s) [%i]", mask_ctx->mask, mask_ctx->css_cnt); - - if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL)) - { - if (custom_charset_1 == NULL) custom_charset_1 = "Undefined"; - if (custom_charset_2 == NULL) custom_charset_2 = "Undefined"; - if (custom_charset_3 == NULL) custom_charset_3 = "Undefined"; - if (custom_charset_4 == NULL) custom_charset_4 = "Undefined"; + return ((char *) ST_9999); +} - event_log_info (hashcat_ctx, "Custom.Charset.: -1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4); - } - } - else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) - { - event_log_info (hashcat_ctx, "Input.Left.....: Mask (%s) [%i]", mask_ctx->mask, mask_ctx->css_cnt); - event_log_info (hashcat_ctx, "Input.Right....: File (%s)", straight_ctx->dict); +char *status_get_hash_type (const hashcat_ctx_t *hashcat_ctx) +{ + const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL)) - { - if (custom_charset_1 == NULL) custom_charset_1 = "Undefined"; - if (custom_charset_2 == NULL) custom_charset_2 = "Undefined"; - if (custom_charset_3 == NULL) custom_charset_3 = "Undefined"; - if (custom_charset_4 == NULL) custom_charset_4 = "Undefined"; + return strhashtype (hashconfig->hash_mode); +} - event_log_info (hashcat_ctx, "Custom.Charset.: -1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4); - } - } +char *status_get_hash_target (const hashcat_ctx_t *hashcat_ctx) +{ + const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + const hashes_t *hashes = hashcat_ctx->hashes; if (hashes->digests_cnt == 1) { if (hashconfig->hash_mode == 2500) { + char *tmp_buf = (char *) malloc (HCBUFSIZ_TINY); + wpa_t *wpa = (wpa_t *) hashes->esalts_buf; - event_log_info (hashcat_ctx, "Hash.Target....: %s (%02x:%02x:%02x:%02x:%02x:%02x <-> %02x:%02x:%02x:%02x:%02x:%02x)", - (char *) hashes->salts_buf[0].salt_buf, - wpa->orig_mac1[0], - wpa->orig_mac1[1], - wpa->orig_mac1[2], - wpa->orig_mac1[3], - wpa->orig_mac1[4], - wpa->orig_mac1[5], - wpa->orig_mac2[0], - wpa->orig_mac2[1], - wpa->orig_mac2[2], - wpa->orig_mac2[3], - wpa->orig_mac2[4], - wpa->orig_mac2[5]); + snprintf (tmp_buf, HCBUFSIZ_TINY - 1, "%s (%02x:%02x:%02x:%02x:%02x:%02x <-> %02x:%02x:%02x:%02x:%02x:%02x)", + (char *) hashes->salts_buf[0].salt_buf, + wpa->orig_mac1[0], + wpa->orig_mac1[1], + wpa->orig_mac1[2], + wpa->orig_mac1[3], + wpa->orig_mac1[4], + wpa->orig_mac1[5], + wpa->orig_mac2[0], + wpa->orig_mac2[1], + wpa->orig_mac2[2], + wpa->orig_mac2[3], + wpa->orig_mac2[4], + wpa->orig_mac2[5]); + + return tmp_buf; } else if (hashconfig->hash_mode == 5200) { - event_log_info (hashcat_ctx, "Hash.Target....: File (%s)", hashes->hashfile); + return hashes->hashfile; } else if (hashconfig->hash_mode == 9000) { - event_log_info (hashcat_ctx, "Hash.Target....: File (%s)", hashes->hashfile); + return hashes->hashfile; } else if ((hashconfig->hash_mode >= 6200) && (hashconfig->hash_mode <= 6299)) { - event_log_info (hashcat_ctx, "Hash.Target....: File (%s)", hashes->hashfile); + return hashes->hashfile; } else if ((hashconfig->hash_mode >= 13700) && (hashconfig->hash_mode <= 13799)) { - event_log_info (hashcat_ctx, "Hash.Target....: File (%s)", hashes->hashfile); + return hashes->hashfile; } else { - char out_buf[HCBUFSIZ_LARGE] = { 0 }; + char *tmp_buf = (char *) malloc (HCBUFSIZ_TINY); - ascii_digest (hashcat_ctx, out_buf, 0, 0); + ascii_digest ((hashcat_ctx_t *) hashcat_ctx, tmp_buf, 0, 0); - // limit length - if (strlen (out_buf) > 40) - { - out_buf[41] = '.'; - out_buf[42] = '.'; - out_buf[43] = '.'; - out_buf[44] = 0; - } - - event_log_info (hashcat_ctx, "Hash.Target....: %s", out_buf); + return tmp_buf; } } else { if (hashconfig->hash_mode == 3000) { + char *tmp_buf = (char *) malloc (HCBUFSIZ_TINY); + char out_buf1[32] = { 0 }; char out_buf2[32] = { 0 }; - ascii_digest (hashcat_ctx, out_buf1, 0, 0); - ascii_digest (hashcat_ctx, out_buf2, 0, 1); - - event_log_info (hashcat_ctx, "Hash.Target....: %s, %s", out_buf1, out_buf2); - } - else - { - event_log_info (hashcat_ctx, "Hash.Target....: File (%s)", hashes->hashfile); - } - } - - event_log_info (hashcat_ctx, "Hash.Type......: %s", hash_type); - - /** - * speed new - */ - - u64 speed_cnt[DEVICES_MAX] = { 0 }; - double speed_ms[DEVICES_MAX] = { 0 }; - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; + ascii_digest ((hashcat_ctx_t *) hashcat_ctx, out_buf1, 0, 0); + ascii_digest ((hashcat_ctx_t *) hashcat_ctx, out_buf2, 0, 1); - speed_cnt[device_id] = 0; - speed_ms[device_id] = 0; + snprintf (tmp_buf, HCBUFSIZ_TINY - 1, "%s, %s", out_buf1, out_buf2); - for (int i = 0; i < SPEED_CACHE; i++) - { - speed_cnt[device_id] += device_param->speed_cnt[i]; - speed_ms[device_id] += device_param->speed_ms[i]; + return tmp_buf; } - - speed_cnt[device_id] /= SPEED_CACHE; - speed_ms[device_id] /= SPEED_CACHE; - } - - double hashes_all_ms = 0; - - double hashes_dev_ms[DEVICES_MAX] = { 0 }; - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; - - hashes_dev_ms[device_id] = 0; - - if (speed_ms[device_id] > 0) - { - hashes_dev_ms[device_id] = (double) speed_cnt[device_id] / speed_ms[device_id]; - - hashes_all_ms += hashes_dev_ms[device_id]; - } - } - - /** - * exec time - */ - - double exec_all_ms[DEVICES_MAX] = { 0 }; - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; - - double exec_ms_avg = get_avg_exec_time (device_param, EXEC_CACHE); - - exec_all_ms[device_id] = exec_ms_avg; - } - - /** - * timers - */ - - double ms_running = hc_timer_get (status_ctx->timer_running); - - double ms_paused = status_ctx->ms_paused; - - if (status_ctx->devices_status == STATUS_PAUSED) - { - double ms_paused_tmp = hc_timer_get (status_ctx->timer_paused); - - ms_paused += ms_paused_tmp; - } - - #if defined (_WIN) - - __time64_t sec_run = (__time64_t) ms_running / 1000; - - #else - - time_t sec_run = (time_t) ms_running / 1000; - - #endif - - if (sec_run) - { - char display_run[32] = { 0 }; - - struct tm tm_run; - - struct tm *tmp = NULL; - - #if defined (_WIN) - - tmp = _gmtime64 (&sec_run); - - #else - - tmp = gmtime (&sec_run); - - #endif - - if (tmp != NULL) - { - memset (&tm_run, 0, sizeof (tm_run)); - - memcpy (&tm_run, tmp, sizeof (tm_run)); - - format_timer_display (&tm_run, display_run, sizeof (tm_run)); - - char *start = ctime (&status_ctx->proc_start); - - size_t start_len = strlen (start); - - if (start[start_len - 1] == '\n') start[start_len - 1] = 0; - if (start[start_len - 2] == '\r') start[start_len - 2] = 0; - - event_log_info (hashcat_ctx, "Time.Started...: %s (%s)", start, display_run); - } - } - else - { - event_log_info (hashcat_ctx, "Time.Started...: 0 secs"); - } - - /** - * counters - */ - - u64 progress_total = status_ctx->words_cnt * hashes->salts_cnt; - - u64 all_done = 0; - u64 all_rejected = 0; - u64 all_restored = 0; - - u64 progress_noneed = 0; - - for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) - { - all_done += status_ctx->words_progress_done[salt_pos]; - all_rejected += status_ctx->words_progress_rejected[salt_pos]; - all_restored += status_ctx->words_progress_restored[salt_pos]; - - // Important for ETA only - - if (hashes->salts_shown[salt_pos] == 1) + else { - const u64 all = status_ctx->words_progress_done[salt_pos] - + status_ctx->words_progress_rejected[salt_pos] - + status_ctx->words_progress_restored[salt_pos]; - - const u64 left = status_ctx->words_cnt - all; - - progress_noneed += left; + return hashes->hashfile; } } - u64 progress_cur = all_restored + all_done + all_rejected; - u64 progress_end = progress_total; + return NULL; +} - u64 progress_skip = 0; +int status_get_input_mode (const hashcat_ctx_t *hashcat_ctx) +{ + const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; + const user_options_t *user_options = hashcat_ctx->user_options; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; - if (user_options->skip) - { - progress_skip = MIN (user_options->skip, status_ctx->words_base) * hashes->salts_cnt; + bool has_wordlist = false; + bool has_rule_file = false; + bool has_rule_gen = false; + bool has_base_left = false; + bool has_mask_cs = false; - if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_skip *= straight_ctx->kernel_rules_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_skip *= combinator_ctx->combs_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_skip *= mask_ctx->bfs_cnt; - } + if (user_options_extra->wordlist_mode == WL_MODE_FILE) has_wordlist = true; - if (user_options->limit) - { - progress_end = MIN (user_options->limit, status_ctx->words_base) * hashes->salts_cnt; + if (user_options->rp_files_cnt > 0) has_rule_file = true; + if (user_options->rp_gen > 0) has_rule_gen = true; - if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_end *= straight_ctx->kernel_rules_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_end *= combinator_ctx->combs_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_end *= mask_ctx->bfs_cnt; - } + if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_LEFT) has_base_left = true; - u64 progress_cur_relative_skip = progress_cur - progress_skip; - u64 progress_end_relative_skip = progress_end - progress_skip; + if (user_options->custom_charset_1) has_mask_cs = true; + if (user_options->custom_charset_2) has_mask_cs = true; + if (user_options->custom_charset_3) has_mask_cs = true; + if (user_options->custom_charset_4) has_mask_cs = true; - if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) { - if (status_ctx->devices_status != STATUS_CRACKED) + if (has_wordlist == true) { - #if defined (_WIN) - __time64_t sec_etc = 0; - #else - time_t sec_etc = 0; - #endif - - if (hashes_all_ms > 0) + if (has_rule_file == true) { - u64 progress_left_relative_skip = progress_end_relative_skip - progress_cur_relative_skip; - - u64 ms_left = (u64) ((progress_left_relative_skip - progress_noneed) / hashes_all_ms); - - sec_etc = ms_left / 1000; + return INPUT_MODE_STRAIGHT_FILE_RULES_FILE; } - - #define SEC10YEARS (60 * 60 * 24 * 365 * 10) - - if (sec_etc == 0) + else if (has_rule_gen == true) { - //log_info ("Time.Estimated.: 0 secs"); - } - else if ((u64) sec_etc > SEC10YEARS) - { - event_log_info (hashcat_ctx, "Time.Estimated.: > 10 Years"); + return INPUT_MODE_STRAIGHT_FILE_RULES_GEN; } else { - char display_etc[32] = { 0 }; - char display_runtime[32] = { 0 }; - - struct tm tm_etc; - struct tm tm_runtime; - - struct tm *tmp = NULL; - - #if defined (_WIN) - tmp = _gmtime64 (&sec_etc); - #else - tmp = gmtime (&sec_etc); - #endif - - if (tmp != NULL) - { - memcpy (&tm_etc, tmp, sizeof (tm_etc)); - - format_timer_display (&tm_etc, display_etc, sizeof (display_etc)); - - time_t now; - - time (&now); - - now += sec_etc; - - char *etc = ctime (&now); - - size_t etc_len = strlen (etc); - - if (etc[etc_len - 1] == '\n') etc[etc_len - 1] = 0; - if (etc[etc_len - 2] == '\r') etc[etc_len - 2] = 0; - - if (user_options->runtime) - { - time_t runtime_cur; - - time (&runtime_cur); - - #if defined (_WIN) - - __time64_t runtime_left = status_ctx->proc_start + user_options->runtime + status_ctx->prepare_time + (ms_paused / 1000) - runtime_cur; - - tmp = _gmtime64 (&runtime_left); - - #else - - time_t runtime_left = status_ctx->proc_start + user_options->runtime + status_ctx->prepare_time + (ms_paused / 1000) - runtime_cur; - - tmp = gmtime (&runtime_left); - - #endif - - if ((tmp != NULL) && (runtime_left > 0) && (runtime_left < sec_etc)) - { - memcpy (&tm_runtime, tmp, sizeof (tm_runtime)); - - format_timer_display (&tm_runtime, display_runtime, sizeof (display_runtime)); - - event_log_info (hashcat_ctx, "Time.Estimated.: %s (%s), but limited (%s)", etc, display_etc, display_runtime); - } - else - { - event_log_info (hashcat_ctx, "Time.Estimated.: %s (%s), but limit exceeded", etc, display_etc); - } - } - else - { - event_log_info (hashcat_ctx, "Time.Estimated.: %s (%s)", etc, display_etc); - } - } + return INPUT_MODE_STRAIGHT_FILE; } } - } - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; - - char display_dev_cur[16] = { 0 }; - - strncpy (display_dev_cur, "0.00", 4); - - format_speed_display ((double) hashes_dev_ms[device_id] * 1000, display_dev_cur, sizeof (display_dev_cur)); - - event_log_info (hashcat_ctx, "Speed.Dev.#%d...: %9sH/s (%0.2fms)", device_id + 1, display_dev_cur, exec_all_ms[device_id]); - } - - char display_all_cur[16] = { 0 }; - - strncpy (display_all_cur, "0.00", 4); - - format_speed_display ((double) hashes_all_ms * 1000, display_all_cur, sizeof (display_all_cur)); - - if (opencl_ctx->devices_active > 1) event_log_info (hashcat_ctx, "Speed.Dev.#*...: %9sH/s", display_all_cur); - - const double digests_percent = (double) hashes->digests_done / hashes->digests_cnt; - const double salts_percent = (double) hashes->salts_done / hashes->salts_cnt; - - event_log_info (hashcat_ctx, "Recovered......: %u/%u (%.2f%%) Digests, %u/%u (%.2f%%) Salts", hashes->digests_done, hashes->digests_cnt, digests_percent * 100, hashes->salts_done, hashes->salts_cnt, salts_percent * 100); - - // crack-per-time - - if (hashes->digests_cnt > 100) - { - time_t now = time (NULL); - - int cpt_cur_min = 0; - int cpt_cur_hour = 0; - int cpt_cur_day = 0; - - for (int i = 0; i < CPT_BUF; i++) + else { - const u32 cracked = cpt_ctx->cpt_buf[i].cracked; - const time_t timestamp = cpt_ctx->cpt_buf[i].timestamp; - - if ((timestamp + 60) > now) + if (has_rule_file == true) { - cpt_cur_min += cracked; + return INPUT_MODE_STRAIGHT_STDIN_RULES_FILE; } - - if ((timestamp + 3600) > now) + else if (has_rule_gen == true) { - cpt_cur_hour += cracked; + return INPUT_MODE_STRAIGHT_STDIN_RULES_GEN; } - - if ((timestamp + 86400) > now) + else { - cpt_cur_day += cracked; + return INPUT_MODE_STRAIGHT_STDIN; } } - - double ms_real = ms_running - ms_paused; - - double cpt_avg_min = (double) cpt_ctx->cpt_total / ((ms_real / 1000) / 60); - double cpt_avg_hour = (double) cpt_ctx->cpt_total / ((ms_real / 1000) / 3600); - double cpt_avg_day = (double) cpt_ctx->cpt_total / ((ms_real / 1000) / 86400); - - if ((cpt_ctx->cpt_start + 86400) < now) - { - event_log_info (hashcat_ctx, "Recovered/Time.: CUR:%u,%u,%u AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", - cpt_cur_min, - cpt_cur_hour, - cpt_cur_day, - cpt_avg_min, - cpt_avg_hour, - cpt_avg_day); - } - else if ((cpt_ctx->cpt_start + 3600) < now) - { - event_log_info (hashcat_ctx, "Recovered/Time.: CUR:%u,%u,N/A AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", - cpt_cur_min, - cpt_cur_hour, - cpt_avg_min, - cpt_avg_hour, - cpt_avg_day); - } - else if ((cpt_ctx->cpt_start + 60) < now) + } + else if (user_options->attack_mode == ATTACK_MODE_COMBI) + { + if (has_base_left == true) { - event_log_info (hashcat_ctx, "Recovered/Time.: CUR:%u,N/A,N/A AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", - cpt_cur_min, - cpt_avg_min, - cpt_avg_hour, - cpt_avg_day); + return INPUT_MODE_COMBINATOR_BASE_LEFT; } else { - event_log_info (hashcat_ctx, "Recovered/Time.: CUR:N/A,N/A,N/A AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", - cpt_avg_min, - cpt_avg_hour, - cpt_avg_day); + return INPUT_MODE_COMBINATOR_BASE_RIGHT; } } - - // Restore point - - u64 restore_point = get_lowest_words_done (hashcat_ctx); - - u64 restore_total = status_ctx->words_base; - - double percent_restore = 0; - - if (restore_total != 0) percent_restore = (double) restore_point / (double) restore_total; - - if (progress_end_relative_skip) + else if (user_options->attack_mode == ATTACK_MODE_BF) { - if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + if (has_mask_cs == true) { - double percent_finished = (double) progress_cur_relative_skip / (double) progress_end_relative_skip; - double percent_rejected = 0.0; - - if (progress_cur) - { - percent_rejected = (double) (all_rejected) / (double) progress_cur; - } - - event_log_info (hashcat_ctx, "Progress.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", progress_cur_relative_skip, progress_end_relative_skip, percent_finished * 100); - event_log_info (hashcat_ctx, "Rejected.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", all_rejected, progress_cur_relative_skip, percent_rejected * 100); - - if (user_options->restore_disable == false) - { - if (percent_finished != 1) - { - event_log_info (hashcat_ctx, "Restore.Point..: %" PRIu64 "/%" PRIu64 " (%.02f%%)", restore_point, restore_total, percent_restore * 100); - } - } + return INPUT_MODE_MASK_CS; + } + else + { + return INPUT_MODE_MASK; } } - else + else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) { - if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + if (has_mask_cs == true) { - event_log_info (hashcat_ctx, "Progress.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); - event_log_info (hashcat_ctx, "Rejected.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); - - if (user_options->restore_disable == false) - { - event_log_info (hashcat_ctx, "Restore.Point..: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); - } + return INPUT_MODE_HYBRID1_CS; } else { - event_log_info (hashcat_ctx, "Progress.......: %" PRIu64 "", progress_cur_relative_skip); - event_log_info (hashcat_ctx, "Rejected.......: %" PRIu64 "", all_rejected); - - // --restore not allowed if stdin is used -- really? why? - - //if (user_options->restore_disable == false) - //{ - // event_log_info (hashcat_ctx, "Restore.Point..: %" PRIu64 "", restore_point); - //} + return INPUT_MODE_HYBRID1; } } - - if (status_ctx->run_main_level1 == false) return; - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; - - if ((device_param->outerloop_left == 0) || (device_param->innerloop_left == 0)) + if (has_mask_cs == true) { - if (user_options_extra->attack_kern == ATTACK_KERN_BF) - { - event_log_info (hashcat_ctx, "Candidates.#%d..: [Generating]", device_id + 1); - } - else - { - event_log_info (hashcat_ctx, "Candidates.#%d..: [Copying]", device_id + 1); - } - - continue; - } - - const u32 outerloop_first = 0; - const u32 outerloop_last = device_param->outerloop_left - 1; - - const u32 innerloop_first = 0; - const u32 innerloop_last = device_param->innerloop_left - 1; - - plain_t plain1 = { 0, 0, 0, outerloop_first, innerloop_first }; - plain_t plain2 = { 0, 0, 0, outerloop_last, innerloop_last }; - - u32 plain_buf1[16] = { 0 }; - u32 plain_buf2[16] = { 0 }; - - u8 *plain_ptr1 = (u8 *) plain_buf1; - u8 *plain_ptr2 = (u8 *) plain_buf2; - - int plain_len1 = 0; - int plain_len2 = 0; - - build_plain (hashcat_ctx, device_param, &plain1, plain_buf1, &plain_len1); - build_plain (hashcat_ctx, device_param, &plain2, plain_buf2, &plain_len2); - - bool need_hex1 = need_hexify (plain_ptr1, plain_len1); - bool need_hex2 = need_hexify (plain_ptr2, plain_len2); - - if ((need_hex1 == true) || (need_hex2 == true)) - { - exec_hexify (plain_ptr1, plain_len1, plain_ptr1); - exec_hexify (plain_ptr2, plain_len2, plain_ptr2); - - plain_ptr1[plain_len1 * 2] = 0; - plain_ptr2[plain_len2 * 2] = 0; - - event_log_info (hashcat_ctx, "Candidates.#%d..: $HEX[%s] -> $HEX[%s]", device_id + 1, plain_ptr1, plain_ptr2); + return INPUT_MODE_HYBRID2_CS; } else { - event_log_info (hashcat_ctx, "Candidates.#%d..: %s -> %s", device_id + 1, plain_ptr1, plain_ptr2); + return INPUT_MODE_HYBRID2; } } - if (user_options->gpu_temp_disable == false) - { - hc_thread_mutex_lock (status_ctx->mux_hwmon); - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; - - const int num_temperature = hm_get_temperature_with_device_id (hashcat_ctx, device_id); - const int num_fanspeed = hm_get_fanspeed_with_device_id (hashcat_ctx, device_id); - const int num_utilization = hm_get_utilization_with_device_id (hashcat_ctx, device_id); - const int num_corespeed = hm_get_corespeed_with_device_id (hashcat_ctx, device_id); - const int num_memoryspeed = hm_get_memoryspeed_with_device_id (hashcat_ctx, device_id); - const int num_buslanes = hm_get_buslanes_with_device_id (hashcat_ctx, device_id); - const int num_throttle = hm_get_throttle_with_device_id (hashcat_ctx, device_id); - - char output_buf[256] = { 0 }; - - int output_len = 0; - - if (num_temperature >= 0) - { - snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Temp:%3uc", num_temperature); - - output_len = strlen (output_buf); - } - - if (num_fanspeed >= 0) - { - snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Fan:%3u%%", num_fanspeed); - - output_len = strlen (output_buf); - } - - if (num_utilization >= 0) - { - snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Util:%3u%%", num_utilization); - - output_len = strlen (output_buf); - } - - if (num_corespeed >= 0) - { - snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Core:%4uMhz", num_corespeed); - - output_len = strlen (output_buf); - } - - if (num_memoryspeed >= 0) - { - snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Mem:%4uMhz", num_memoryspeed); - - output_len = strlen (output_buf); - } - - if (num_buslanes >= 0) - { - snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Lanes:%u", num_buslanes); - - output_len = strlen (output_buf); - } - - if (num_throttle >= 0) - { - snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " *Throttled*"); - - output_len = strlen (output_buf); - } - - if (output_len == 0) - { - snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " N/A"); - - output_len = strlen (output_buf); - } - - event_log_info (hashcat_ctx, "HWMon.Dev.#%d...:%s", device_id + 1, output_buf); - } - - hc_thread_mutex_unlock (status_ctx->mux_hwmon); - } + return INPUT_MODE_NONE; } -void status_benchmark_automate (hashcat_ctx_t *hashcat_ctx) +char *status_get_input_base (const hashcat_ctx_t *hashcat_ctx) { - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + const user_options_t *user_options = hashcat_ctx->user_options; - if (status_ctx->devices_status == STATUS_INIT) + if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) { - event_log_error (hashcat_ctx, "status view is not available during initialization phase"); + const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; - return; + return straight_ctx->dict; } - - if (status_ctx->devices_status == STATUS_AUTOTUNE) + else if (user_options->attack_mode == ATTACK_MODE_COMBI) { - event_log_error (hashcat_ctx, "status view is not available during autotune phase"); + const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; - return; + if (combinator_ctx->combs_mode == INPUT_MODE_COMBINATOR_BASE_LEFT) + { + return combinator_ctx->dict1; + } + else + { + return combinator_ctx->dict2; + } } - - u64 speed_cnt[DEVICES_MAX] = { 0 }; - double speed_ms[DEVICES_MAX] = { 0 }; - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + else if (user_options->attack_mode == ATTACK_MODE_BF) { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; + const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; - speed_cnt[device_id] = device_param->speed_cnt[0]; - speed_ms[device_id] = device_param->speed_ms[0]; + return mask_ctx->mask; } - - u64 hashes_dev_ms[DEVICES_MAX] = { 0 }; - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; + const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; - hashes_dev_ms[device_id] = 0; - - if (speed_ms[device_id] > 0) - { - hashes_dev_ms[device_id] = (double) speed_cnt[device_id] / speed_ms[device_id]; - } + return straight_ctx->dict; } - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; + const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; - event_log_info (hashcat_ctx, "%u:%u:%" PRIu64 "", device_id + 1, hashconfig->hash_mode, (hashes_dev_ms[device_id] * 1000)); + return straight_ctx->dict; } + + return NULL; } -void status_benchmark (hashcat_ctx_t *hashcat_ctx) +char *status_get_input_mod (const hashcat_ctx_t *hashcat_ctx) { - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - user_options_t *user_options = hashcat_ctx->user_options; + const user_options_t *user_options = hashcat_ctx->user_options; - if (status_ctx->devices_status == STATUS_INIT) + if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) { - event_log_error (hashcat_ctx, "status view is not available during initialization phase"); - - return; + return status_get_rules_file (hashcat_ctx); } - - if (status_ctx->devices_status == STATUS_AUTOTUNE) + else if (user_options->attack_mode == ATTACK_MODE_COMBI) { - event_log_error (hashcat_ctx, "status view is not available during autotune phase"); + const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; - return; + if (combinator_ctx->combs_mode == INPUT_MODE_COMBINATOR_BASE_LEFT) + { + return combinator_ctx->dict2; + } + else + { + return combinator_ctx->dict1; + } } - - if (status_ctx->shutdown_inner == 1) return; - - if (user_options->machine_readable == true) + else if (user_options->attack_mode == ATTACK_MODE_BF) { - status_benchmark_automate (hashcat_ctx); - return; } - - u64 speed_cnt[DEVICES_MAX] = { 0 }; - double speed_ms[DEVICES_MAX] = { 0 }; - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; + const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; - speed_cnt[device_id] = device_param->speed_cnt[0]; - speed_ms[device_id] = device_param->speed_ms[0]; + return mask_ctx->mask; } - - double hashes_all_ms = 0; - - double hashes_dev_ms[DEVICES_MAX] = { 0 }; - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; - if (device_param->skipped) continue; - - hashes_dev_ms[device_id] = 0; - - if (speed_ms[device_id] > 0) - { - hashes_dev_ms[device_id] = (double) speed_cnt[device_id] / speed_ms[device_id]; - - hashes_all_ms += hashes_dev_ms[device_id]; - } + return mask_ctx->mask; } - /** - * exec time - */ - - double exec_all_ms[DEVICES_MAX] = { 0 }; - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; + return NULL; +} - double exec_ms_avg = get_avg_exec_time (device_param, EXEC_CACHE); +char *status_get_input_charset (const hashcat_ctx_t *hashcat_ctx) +{ + const user_options_t *user_options = hashcat_ctx->user_options; - exec_all_ms[device_id] = exec_ms_avg; - } + const char *custom_charset_1 = user_options->custom_charset_1; + const char *custom_charset_2 = user_options->custom_charset_2; + const char *custom_charset_3 = user_options->custom_charset_3; + const char *custom_charset_4 = user_options->custom_charset_4; - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL)) { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + char *tmp_buf = (char *) malloc (HCBUFSIZ_TINY); - if (device_param->skipped) continue; + if (custom_charset_1 == NULL) custom_charset_1 = "Undefined"; + if (custom_charset_2 == NULL) custom_charset_2 = "Undefined"; + if (custom_charset_3 == NULL) custom_charset_3 = "Undefined"; + if (custom_charset_4 == NULL) custom_charset_4 = "Undefined"; - char display_dev_cur[16] = { 0 }; + snprintf (tmp_buf, HCBUFSIZ_TINY - 1, "-1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4); - strncpy (display_dev_cur, "0.00", 4); - - format_speed_display ((double) hashes_dev_ms[device_id] * 1000, display_dev_cur, sizeof (display_dev_cur)); - - if (opencl_ctx->devices_active >= 10) - { - event_log_info (hashcat_ctx, "Speed.Dev.#%d: %9sH/s (%0.2fms)", device_id + 1, display_dev_cur, exec_all_ms[device_id]); - } - else - { - event_log_info (hashcat_ctx, "Speed.Dev.#%d.: %9sH/s (%0.2fms)", device_id + 1, display_dev_cur, exec_all_ms[device_id]); - } + return tmp_buf; } - char display_all_cur[16] = { 0 }; - - strncpy (display_all_cur, "0.00", 4); - - format_speed_display ((double) hashes_all_ms * 1000, display_all_cur, sizeof (display_all_cur)); - - if (opencl_ctx->devices_active > 1) event_log_info (hashcat_ctx, "Speed.Dev.#*.: %9sH/s", display_all_cur); + return NULL; } + int status_progress_init (hashcat_ctx_t *hashcat_ctx) { status_ctx_t *status_ctx = hashcat_ctx->status_ctx; diff --git a/src/terminal.c b/src/terminal.c index da1762842..2dc2094ad 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -6,11 +6,15 @@ #include "common.h" #include "types.h" #include "event.h" +#include "convert.h" #include "thread.h" #include "timer.h" #include "status.h" #include "restore.h" #include "shared.h" +#include "hwmon.h" +#include "interface.h" +#include "outfile.h" #include "terminal.h" const char *PROMPT = "[s]tatus [p]ause [r]esume [b]ypass [c]heckpoint [q]uit => "; @@ -228,7 +232,7 @@ static void keypress (hashcat_ctx_t *hashcat_ctx) event_log_info (hashcat_ctx, ""); - myabort (hashcat_ctx); + myquit (hashcat_ctx); break; } @@ -439,3 +443,1125 @@ int tty_fix() return 0; } #endif + +static void format_timer_display (struct tm *tm, char *buf, size_t len) +{ + const char *time_entities_s[] = { "year", "day", "hour", "min", "sec" }; + const char *time_entities_m[] = { "years", "days", "hours", "mins", "secs" }; + + if (tm->tm_year - 70) + { + char *time_entity1 = ((tm->tm_year - 70) == 1) ? (char *) time_entities_s[0] : (char *) time_entities_m[0]; + char *time_entity2 = ( tm->tm_yday == 1) ? (char *) time_entities_s[1] : (char *) time_entities_m[1]; + + snprintf (buf, len - 1, "%d %s, %d %s", tm->tm_year - 70, time_entity1, tm->tm_yday, time_entity2); + } + else if (tm->tm_yday) + { + char *time_entity1 = (tm->tm_yday == 1) ? (char *) time_entities_s[1] : (char *) time_entities_m[1]; + char *time_entity2 = (tm->tm_hour == 1) ? (char *) time_entities_s[2] : (char *) time_entities_m[2]; + + snprintf (buf, len - 1, "%d %s, %d %s", tm->tm_yday, time_entity1, tm->tm_hour, time_entity2); + } + else if (tm->tm_hour) + { + char *time_entity1 = (tm->tm_hour == 1) ? (char *) time_entities_s[2] : (char *) time_entities_m[2]; + char *time_entity2 = (tm->tm_min == 1) ? (char *) time_entities_s[3] : (char *) time_entities_m[3]; + + snprintf (buf, len - 1, "%d %s, %d %s", tm->tm_hour, time_entity1, tm->tm_min, time_entity2); + } + else if (tm->tm_min) + { + char *time_entity1 = (tm->tm_min == 1) ? (char *) time_entities_s[3] : (char *) time_entities_m[3]; + char *time_entity2 = (tm->tm_sec == 1) ? (char *) time_entities_s[4] : (char *) time_entities_m[4]; + + snprintf (buf, len - 1, "%d %s, %d %s", tm->tm_min, time_entity1, tm->tm_sec, time_entity2); + } + else + { + char *time_entity1 = (tm->tm_sec == 1) ? (char *) time_entities_s[4] : (char *) time_entities_m[4]; + + snprintf (buf, len - 1, "%d %s", tm->tm_sec, time_entity1); + } +} + +static void format_speed_display (double val, char *buf, size_t len) +{ + if (val <= 0) + { + buf[0] = '0'; + buf[1] = ' '; + buf[2] = 0; + + return; + } + + char units[7] = { ' ', 'k', 'M', 'G', 'T', 'P', 'E' }; + + u32 level = 0; + + while (val > 99999) + { + val /= 1000; + + level++; + } + + /* generate output */ + + if (level == 0) + { + snprintf (buf, len - 1, "%.0f ", val); + } + else + { + snprintf (buf, len - 1, "%.1f %c", val, units[level]); + } +} + +void status_display_machine_readable (hashcat_ctx_t *hashcat_ctx) +{ + combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; + hashes_t *hashes = hashcat_ctx->hashes; + mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; + user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + user_options_t *user_options = hashcat_ctx->user_options; + + if (status_ctx->devices_status == STATUS_INIT) + { + event_log_error (hashcat_ctx, "status view is not available during initialization phase"); + + return; + } + + if (status_ctx->devices_status == STATUS_AUTOTUNE) + { + event_log_error (hashcat_ctx, "status view is not available during autotune phase"); + + return; + } + + FILE *out = stdout; + + fprintf (out, "STATUS\t%u\t", status_ctx->devices_status); + + /** + * speed new + */ + + fprintf (out, "SPEED\t"); + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + u64 speed_cnt = 0; + double speed_ms = 0; + + for (int i = 0; i < SPEED_CACHE; i++) + { + speed_cnt += device_param->speed_cnt[i]; + speed_ms += device_param->speed_ms[i]; + } + + speed_cnt /= SPEED_CACHE; + speed_ms /= SPEED_CACHE; + + fprintf (out, "%" PRIu64 "\t%f\t", speed_cnt, speed_ms); + } + + /** + * exec time + */ + + fprintf (out, "EXEC_RUNTIME\t"); + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + double exec_ms_avg = get_avg_exec_time (device_param, EXEC_CACHE); + + fprintf (out, "%f\t", exec_ms_avg); + } + + /** + * words_cur + */ + + u64 words_cur = get_lowest_words_done (hashcat_ctx); + + fprintf (out, "CURKU\t%" PRIu64 "\t", words_cur); + + /** + * counter + */ + + u64 progress_total = status_ctx->words_cnt * hashes->salts_cnt; + + u64 all_done = 0; + u64 all_rejected = 0; + u64 all_restored = 0; + + for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) + { + all_done += status_ctx->words_progress_done[salt_pos]; + all_rejected += status_ctx->words_progress_rejected[salt_pos]; + all_restored += status_ctx->words_progress_restored[salt_pos]; + } + + u64 progress_cur = all_restored + all_done + all_rejected; + u64 progress_end = progress_total; + + u64 progress_skip = 0; + + if (user_options->skip) + { + progress_skip = MIN (user_options->skip, status_ctx->words_base) * hashes->salts_cnt; + + if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_skip *= straight_ctx->kernel_rules_cnt; + else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_skip *= combinator_ctx->combs_cnt; + else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_skip *= mask_ctx->bfs_cnt; + } + + if (user_options->limit) + { + progress_end = MIN (user_options->limit, status_ctx->words_base) * hashes->salts_cnt; + + if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_end *= straight_ctx->kernel_rules_cnt; + else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_end *= combinator_ctx->combs_cnt; + else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_end *= mask_ctx->bfs_cnt; + } + + u64 progress_cur_relative_skip = progress_cur - progress_skip; + u64 progress_end_relative_skip = progress_end - progress_skip; + + fprintf (out, "PROGRESS\t%" PRIu64 "\t%" PRIu64 "\t", progress_cur_relative_skip, progress_end_relative_skip); + + /** + * cracks + */ + + fprintf (out, "RECHASH\t%u\t%u\t", hashes->digests_done, hashes->digests_cnt); + fprintf (out, "RECSALT\t%u\t%u\t", hashes->salts_done, hashes->salts_cnt); + + /** + * temperature + */ + + if (user_options->gpu_temp_disable == false) + { + fprintf (out, "TEMP\t"); + + hc_thread_mutex_lock (status_ctx->mux_hwmon); + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + int temp = hm_get_temperature_with_device_id (hashcat_ctx, device_id); + + fprintf (out, "%d\t", temp); + } + + hc_thread_mutex_unlock (status_ctx->mux_hwmon); + } + + /** + * flush + */ + + fputs (EOL, out); + fflush (out); +} + +void status_display (hashcat_ctx_t *hashcat_ctx) +{ + combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; + cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; + hashes_t *hashes = hashcat_ctx->hashes; + mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; + user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + user_options_t *user_options = hashcat_ctx->user_options; + + if (status_ctx->devices_status == STATUS_INIT) + { + event_log_error (hashcat_ctx, "Status view is not available during initialization phase"); + + return; + } + + if (status_ctx->devices_status == STATUS_AUTOTUNE) + { + event_log_error (hashcat_ctx, "Status view is not available during autotune phase"); + + return; + } + + if (status_ctx->shutdown_inner == true) + { + // 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"); + + return; + } + + if (user_options->machine_readable == true) + { + status_display_machine_readable (hashcat_ctx); + + return; + } + + /** + * show something + */ + + event_log_info (hashcat_ctx, "Session........: %s", status_get_session (hashcat_ctx)); + event_log_info (hashcat_ctx, "Status.........: %s", status_get_status_string (hashcat_ctx)); + event_log_info (hashcat_ctx, "Hash.Type......: %s", status_get_hash_type (hashcat_ctx)); + event_log_info (hashcat_ctx, "Hash.Target....: %s", status_get_hash_target (hashcat_ctx)); + + const int input_mode = status_get_input_mode (hashcat_ctx); + + switch (input_mode) + { + case INPUT_MODE_STRAIGHT_FILE: + event_log_info (hashcat_ctx, "Input.Base.....: File (%s)", status_get_input_base (hashcat_ctx)); + break; + case INPUT_MODE_STRAIGHT_FILE_RULES_FILE: + event_log_info (hashcat_ctx, "Input.Base.....: File (%s)", status_get_input_base (hashcat_ctx)); + event_log_info (hashcat_ctx, "Input.Mod......: Rules (%s)", status_get_input_mod (hashcat_ctx)); + break; + case INPUT_MODE_STRAIGHT_FILE_RULES_GEN: + event_log_info (hashcat_ctx, "Input.Base.....: File (%s)", status_get_input_base (hashcat_ctx)); + event_log_info (hashcat_ctx, "Input.Mod......: Rules (Generated)"); + break; + case INPUT_MODE_STRAIGHT_STDIN: + event_log_info (hashcat_ctx, "Input.Base.....: Pipe"); + break; + case INPUT_MODE_STRAIGHT_STDIN_RULES_FILE: + event_log_info (hashcat_ctx, "Input.Base.....: Pipe"); + event_log_info (hashcat_ctx, "Input.Mod......: Rules (%s)", status_get_input_mod (hashcat_ctx)); + break; + case INPUT_MODE_STRAIGHT_STDIN_RULES_GEN: + event_log_info (hashcat_ctx, "Input.Base.....: Pipe"); + event_log_info (hashcat_ctx, "Input.Mod......: Rules (Generated)"); + break; + case INPUT_MODE_COMBINATOR_BASE_LEFT: + event_log_info (hashcat_ctx, "Input.Base.....: File (%s), Left Side", status_get_input_base (hashcat_ctx)); + event_log_info (hashcat_ctx, "Input.Mod......: File (%s), Right Side", status_get_input_mod (hashcat_ctx)); + break; + case INPUT_MODE_COMBINATOR_BASE_RIGHT: + event_log_info (hashcat_ctx, "Input.Base.....: File (%s), Right Side", status_get_input_base (hashcat_ctx)); + event_log_info (hashcat_ctx, "Input.Mod......: File (%s), Left Side", status_get_input_mod (hashcat_ctx)); + break; + case INPUT_MODE_MASK: + event_log_info (hashcat_ctx, "Input.Mask.....: %s", status_get_input_base (hashcat_ctx)); + break; + case INPUT_MODE_MASK_CS: + event_log_info (hashcat_ctx, "Input.Mask.....: %s", status_get_input_base (hashcat_ctx)); + event_log_info (hashcat_ctx, "Input.Charset..: %s", status_get_input_charset (hashcat_ctx)); + break; + case INPUT_MODE_HYBRID1: + event_log_info (hashcat_ctx, "Input.Base.....: File (%s), Left Side", status_get_input_base (hashcat_ctx)); + event_log_info (hashcat_ctx, "Input.Mod......: Mask (%s), Right Side", status_get_input_mod (hashcat_ctx)); + break; + case INPUT_MODE_HYBRID1_CS: + event_log_info (hashcat_ctx, "Input.Base.....: File (%s), Left Side", status_get_input_base (hashcat_ctx)); + event_log_info (hashcat_ctx, "Input.Mod......: Mask (%s), Right Side", status_get_input_mod (hashcat_ctx)); + event_log_info (hashcat_ctx, "Input.Charset..: %s", status_get_input_charset (hashcat_ctx)); + break; + case INPUT_MODE_HYBRID2: + event_log_info (hashcat_ctx, "Input.Base.....: File (%s), Right Side", status_get_input_base (hashcat_ctx)); + event_log_info (hashcat_ctx, "Input.Mod......: Mask (%s), Left Side", status_get_input_mod (hashcat_ctx)); + break; + case INPUT_MODE_HYBRID2_CS: + event_log_info (hashcat_ctx, "Input.Base.....: File (%s), Right Side", status_get_input_base (hashcat_ctx)); + event_log_info (hashcat_ctx, "Input.Mod......: Mask (%s), Left Side", status_get_input_mod (hashcat_ctx)); + event_log_info (hashcat_ctx, "Input.Charset..: %s", status_get_input_charset (hashcat_ctx)); + break; + } + + /** + * speed new + */ + + u64 speed_cnt[DEVICES_MAX] = { 0 }; + double speed_ms[DEVICES_MAX] = { 0 }; + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + speed_cnt[device_id] = 0; + speed_ms[device_id] = 0; + + for (int i = 0; i < SPEED_CACHE; i++) + { + speed_cnt[device_id] += device_param->speed_cnt[i]; + speed_ms[device_id] += device_param->speed_ms[i]; + } + + speed_cnt[device_id] /= SPEED_CACHE; + speed_ms[device_id] /= SPEED_CACHE; + } + + double hashes_all_ms = 0; + + double hashes_dev_ms[DEVICES_MAX] = { 0 }; + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + hashes_dev_ms[device_id] = 0; + + if (speed_ms[device_id] > 0) + { + hashes_dev_ms[device_id] = (double) speed_cnt[device_id] / speed_ms[device_id]; + + hashes_all_ms += hashes_dev_ms[device_id]; + } + } + + /** + * exec time + */ + + double exec_all_ms[DEVICES_MAX] = { 0 }; + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + double exec_ms_avg = get_avg_exec_time (device_param, EXEC_CACHE); + + exec_all_ms[device_id] = exec_ms_avg; + } + + /** + * timers + */ + + double ms_running = hc_timer_get (status_ctx->timer_running); + + double ms_paused = status_ctx->ms_paused; + + if (status_ctx->devices_status == STATUS_PAUSED) + { + double ms_paused_tmp = hc_timer_get (status_ctx->timer_paused); + + ms_paused += ms_paused_tmp; + } + + #if defined (_WIN) + + __time64_t sec_run = (__time64_t) ms_running / 1000; + + #else + + time_t sec_run = (time_t) ms_running / 1000; + + #endif + + if (sec_run) + { + char display_run[32] = { 0 }; + + struct tm tm_run; + + struct tm *tmp = NULL; + + #if defined (_WIN) + + tmp = _gmtime64 (&sec_run); + + #else + + tmp = gmtime (&sec_run); + + #endif + + if (tmp != NULL) + { + memset (&tm_run, 0, sizeof (tm_run)); + + memcpy (&tm_run, tmp, sizeof (tm_run)); + + format_timer_display (&tm_run, display_run, sizeof (tm_run)); + + char *start = ctime (&status_ctx->proc_start); + + size_t start_len = strlen (start); + + if (start[start_len - 1] == '\n') start[start_len - 1] = 0; + if (start[start_len - 2] == '\r') start[start_len - 2] = 0; + + event_log_info (hashcat_ctx, "Time.Started...: %s (%s)", start, display_run); + } + } + else + { + event_log_info (hashcat_ctx, "Time.Started...: 0 secs"); + } + + /** + * counters + */ + + u64 progress_total = status_ctx->words_cnt * hashes->salts_cnt; + + u64 all_done = 0; + u64 all_rejected = 0; + u64 all_restored = 0; + + u64 progress_noneed = 0; + + for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) + { + all_done += status_ctx->words_progress_done[salt_pos]; + all_rejected += status_ctx->words_progress_rejected[salt_pos]; + all_restored += status_ctx->words_progress_restored[salt_pos]; + + // Important for ETA only + + if (hashes->salts_shown[salt_pos] == 1) + { + const u64 all = status_ctx->words_progress_done[salt_pos] + + status_ctx->words_progress_rejected[salt_pos] + + status_ctx->words_progress_restored[salt_pos]; + + const u64 left = status_ctx->words_cnt - all; + + progress_noneed += left; + } + } + + u64 progress_cur = all_restored + all_done + all_rejected; + u64 progress_end = progress_total; + + u64 progress_skip = 0; + + if (user_options->skip) + { + progress_skip = MIN (user_options->skip, status_ctx->words_base) * hashes->salts_cnt; + + if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_skip *= straight_ctx->kernel_rules_cnt; + else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_skip *= combinator_ctx->combs_cnt; + else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_skip *= mask_ctx->bfs_cnt; + } + + if (user_options->limit) + { + progress_end = MIN (user_options->limit, status_ctx->words_base) * hashes->salts_cnt; + + if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_end *= straight_ctx->kernel_rules_cnt; + else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_end *= combinator_ctx->combs_cnt; + else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_end *= mask_ctx->bfs_cnt; + } + + u64 progress_cur_relative_skip = progress_cur - progress_skip; + u64 progress_end_relative_skip = progress_end - progress_skip; + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + if (status_ctx->devices_status != STATUS_CRACKED) + { + #if defined (_WIN) + __time64_t sec_etc = 0; + #else + time_t sec_etc = 0; + #endif + + if (hashes_all_ms > 0) + { + u64 progress_left_relative_skip = progress_end_relative_skip - progress_cur_relative_skip; + + u64 ms_left = (u64) ((progress_left_relative_skip - progress_noneed) / hashes_all_ms); + + sec_etc = ms_left / 1000; + } + + #define SEC10YEARS (60 * 60 * 24 * 365 * 10) + + if (sec_etc == 0) + { + //log_info ("Time.Estimated.: 0 secs"); + } + else if ((u64) sec_etc > SEC10YEARS) + { + event_log_info (hashcat_ctx, "Time.Estimated.: > 10 Years"); + } + else + { + char display_etc[32] = { 0 }; + char display_runtime[32] = { 0 }; + + struct tm tm_etc; + struct tm tm_runtime; + + struct tm *tmp = NULL; + + #if defined (_WIN) + tmp = _gmtime64 (&sec_etc); + #else + tmp = gmtime (&sec_etc); + #endif + + if (tmp != NULL) + { + memcpy (&tm_etc, tmp, sizeof (tm_etc)); + + format_timer_display (&tm_etc, display_etc, sizeof (display_etc)); + + time_t now; + + time (&now); + + now += sec_etc; + + char *etc = ctime (&now); + + size_t etc_len = strlen (etc); + + if (etc[etc_len - 1] == '\n') etc[etc_len - 1] = 0; + if (etc[etc_len - 2] == '\r') etc[etc_len - 2] = 0; + + if (user_options->runtime) + { + time_t runtime_cur; + + time (&runtime_cur); + + #if defined (_WIN) + + __time64_t runtime_left = status_ctx->proc_start + user_options->runtime + status_ctx->prepare_time + (ms_paused / 1000) - runtime_cur; + + tmp = _gmtime64 (&runtime_left); + + #else + + time_t runtime_left = status_ctx->proc_start + user_options->runtime + status_ctx->prepare_time + (ms_paused / 1000) - runtime_cur; + + tmp = gmtime (&runtime_left); + + #endif + + if ((tmp != NULL) && (runtime_left > 0) && (runtime_left < sec_etc)) + { + memcpy (&tm_runtime, tmp, sizeof (tm_runtime)); + + format_timer_display (&tm_runtime, display_runtime, sizeof (display_runtime)); + + event_log_info (hashcat_ctx, "Time.Estimated.: %s (%s), but limited (%s)", etc, display_etc, display_runtime); + } + else + { + event_log_info (hashcat_ctx, "Time.Estimated.: %s (%s), but limit exceeded", etc, display_etc); + } + } + else + { + event_log_info (hashcat_ctx, "Time.Estimated.: %s (%s)", etc, display_etc); + } + } + } + } + } + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + char display_dev_cur[16] = { 0 }; + + strncpy (display_dev_cur, "0.00", 4); + + format_speed_display ((double) hashes_dev_ms[device_id] * 1000, display_dev_cur, sizeof (display_dev_cur)); + + event_log_info (hashcat_ctx, "Speed.Dev.#%d...: %9sH/s (%0.2fms)", device_id + 1, display_dev_cur, exec_all_ms[device_id]); + } + + char display_all_cur[16] = { 0 }; + + strncpy (display_all_cur, "0.00", 4); + + format_speed_display ((double) hashes_all_ms * 1000, display_all_cur, sizeof (display_all_cur)); + + if (opencl_ctx->devices_active > 1) event_log_info (hashcat_ctx, "Speed.Dev.#*...: %9sH/s", display_all_cur); + + const double digests_percent = (double) hashes->digests_done / hashes->digests_cnt; + const double salts_percent = (double) hashes->salts_done / hashes->salts_cnt; + + event_log_info (hashcat_ctx, "Recovered......: %u/%u (%.2f%%) Digests, %u/%u (%.2f%%) Salts", hashes->digests_done, hashes->digests_cnt, digests_percent * 100, hashes->salts_done, hashes->salts_cnt, salts_percent * 100); + + // crack-per-time + + if (hashes->digests_cnt > 100) + { + time_t now = time (NULL); + + int cpt_cur_min = 0; + int cpt_cur_hour = 0; + int cpt_cur_day = 0; + + for (int i = 0; i < CPT_BUF; i++) + { + const u32 cracked = cpt_ctx->cpt_buf[i].cracked; + const time_t timestamp = cpt_ctx->cpt_buf[i].timestamp; + + if ((timestamp + 60) > now) + { + cpt_cur_min += cracked; + } + + if ((timestamp + 3600) > now) + { + cpt_cur_hour += cracked; + } + + if ((timestamp + 86400) > now) + { + cpt_cur_day += cracked; + } + } + + double ms_real = ms_running - ms_paused; + + double cpt_avg_min = (double) cpt_ctx->cpt_total / ((ms_real / 1000) / 60); + double cpt_avg_hour = (double) cpt_ctx->cpt_total / ((ms_real / 1000) / 3600); + double cpt_avg_day = (double) cpt_ctx->cpt_total / ((ms_real / 1000) / 86400); + + if ((cpt_ctx->cpt_start + 86400) < now) + { + event_log_info (hashcat_ctx, "Recovered/Time.: CUR:%u,%u,%u AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", + cpt_cur_min, + cpt_cur_hour, + cpt_cur_day, + cpt_avg_min, + cpt_avg_hour, + cpt_avg_day); + } + else if ((cpt_ctx->cpt_start + 3600) < now) + { + event_log_info (hashcat_ctx, "Recovered/Time.: CUR:%u,%u,N/A AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", + cpt_cur_min, + cpt_cur_hour, + cpt_avg_min, + cpt_avg_hour, + cpt_avg_day); + } + else if ((cpt_ctx->cpt_start + 60) < now) + { + event_log_info (hashcat_ctx, "Recovered/Time.: CUR:%u,N/A,N/A AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", + cpt_cur_min, + cpt_avg_min, + cpt_avg_hour, + cpt_avg_day); + } + else + { + event_log_info (hashcat_ctx, "Recovered/Time.: CUR:N/A,N/A,N/A AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", + cpt_avg_min, + cpt_avg_hour, + cpt_avg_day); + } + } + + // Restore point + + u64 restore_point = get_lowest_words_done (hashcat_ctx); + + u64 restore_total = status_ctx->words_base; + + double percent_restore = 0; + + if (restore_total != 0) percent_restore = (double) restore_point / (double) restore_total; + + if (progress_end_relative_skip) + { + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + double percent_finished = (double) progress_cur_relative_skip / (double) progress_end_relative_skip; + double percent_rejected = 0.0; + + if (progress_cur) + { + percent_rejected = (double) (all_rejected) / (double) progress_cur; + } + + event_log_info (hashcat_ctx, "Progress.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", progress_cur_relative_skip, progress_end_relative_skip, percent_finished * 100); + event_log_info (hashcat_ctx, "Rejected.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", all_rejected, progress_cur_relative_skip, percent_rejected * 100); + + if (user_options->restore_disable == false) + { + if (percent_finished != 1) + { + event_log_info (hashcat_ctx, "Restore.Point..: %" PRIu64 "/%" PRIu64 " (%.02f%%)", restore_point, restore_total, percent_restore * 100); + } + } + } + } + else + { + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + event_log_info (hashcat_ctx, "Progress.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); + event_log_info (hashcat_ctx, "Rejected.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); + + if (user_options->restore_disable == false) + { + event_log_info (hashcat_ctx, "Restore.Point..: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); + } + } + else + { + event_log_info (hashcat_ctx, "Progress.......: %" PRIu64 "", progress_cur_relative_skip); + event_log_info (hashcat_ctx, "Rejected.......: %" PRIu64 "", all_rejected); + + // --restore not allowed if stdin is used -- really? why? + + //if (user_options->restore_disable == false) + //{ + // event_log_info (hashcat_ctx, "Restore.Point..: %" PRIu64 "", restore_point); + //} + } + } + + if (status_ctx->run_main_level1 == false) return; + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + if ((device_param->outerloop_left == 0) || (device_param->innerloop_left == 0)) + { + if (user_options_extra->attack_kern == ATTACK_KERN_BF) + { + event_log_info (hashcat_ctx, "Candidates.#%d..: [Generating]", device_id + 1); + } + else + { + event_log_info (hashcat_ctx, "Candidates.#%d..: [Copying]", device_id + 1); + } + + continue; + } + + const u32 outerloop_first = 0; + const u32 outerloop_last = device_param->outerloop_left - 1; + + const u32 innerloop_first = 0; + const u32 innerloop_last = device_param->innerloop_left - 1; + + plain_t plain1 = { 0, 0, 0, outerloop_first, innerloop_first }; + plain_t plain2 = { 0, 0, 0, outerloop_last, innerloop_last }; + + u32 plain_buf1[16] = { 0 }; + u32 plain_buf2[16] = { 0 }; + + u8 *plain_ptr1 = (u8 *) plain_buf1; + u8 *plain_ptr2 = (u8 *) plain_buf2; + + int plain_len1 = 0; + int plain_len2 = 0; + + build_plain (hashcat_ctx, device_param, &plain1, plain_buf1, &plain_len1); + build_plain (hashcat_ctx, device_param, &plain2, plain_buf2, &plain_len2); + + bool need_hex1 = need_hexify (plain_ptr1, plain_len1); + bool need_hex2 = need_hexify (plain_ptr2, plain_len2); + + if ((need_hex1 == true) || (need_hex2 == true)) + { + exec_hexify (plain_ptr1, plain_len1, plain_ptr1); + exec_hexify (plain_ptr2, plain_len2, plain_ptr2); + + plain_ptr1[plain_len1 * 2] = 0; + plain_ptr2[plain_len2 * 2] = 0; + + event_log_info (hashcat_ctx, "Candidates.#%d..: $HEX[%s] -> $HEX[%s]", device_id + 1, plain_ptr1, plain_ptr2); + } + else + { + event_log_info (hashcat_ctx, "Candidates.#%d..: %s -> %s", device_id + 1, plain_ptr1, plain_ptr2); + } + } + + if (user_options->gpu_temp_disable == false) + { + hc_thread_mutex_lock (status_ctx->mux_hwmon); + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + const int num_temperature = hm_get_temperature_with_device_id (hashcat_ctx, device_id); + const int num_fanspeed = hm_get_fanspeed_with_device_id (hashcat_ctx, device_id); + const int num_utilization = hm_get_utilization_with_device_id (hashcat_ctx, device_id); + const int num_corespeed = hm_get_corespeed_with_device_id (hashcat_ctx, device_id); + const int num_memoryspeed = hm_get_memoryspeed_with_device_id (hashcat_ctx, device_id); + const int num_buslanes = hm_get_buslanes_with_device_id (hashcat_ctx, device_id); + const int num_throttle = hm_get_throttle_with_device_id (hashcat_ctx, device_id); + + char output_buf[256] = { 0 }; + + int output_len = 0; + + if (num_temperature >= 0) + { + snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Temp:%3uc", num_temperature); + + output_len = strlen (output_buf); + } + + if (num_fanspeed >= 0) + { + snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Fan:%3u%%", num_fanspeed); + + output_len = strlen (output_buf); + } + + if (num_utilization >= 0) + { + snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Util:%3u%%", num_utilization); + + output_len = strlen (output_buf); + } + + if (num_corespeed >= 0) + { + snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Core:%4uMhz", num_corespeed); + + output_len = strlen (output_buf); + } + + if (num_memoryspeed >= 0) + { + snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Mem:%4uMhz", num_memoryspeed); + + output_len = strlen (output_buf); + } + + if (num_buslanes >= 0) + { + snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Lanes:%u", num_buslanes); + + output_len = strlen (output_buf); + } + + if (num_throttle >= 0) + { + snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " *Throttled*"); + + output_len = strlen (output_buf); + } + + if (output_len == 0) + { + snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " N/A"); + + output_len = strlen (output_buf); + } + + event_log_info (hashcat_ctx, "HWMon.Dev.#%d...:%s", device_id + 1, output_buf); + } + + hc_thread_mutex_unlock (status_ctx->mux_hwmon); + } +} + +void status_benchmark_automate (hashcat_ctx_t *hashcat_ctx) +{ + hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + if (status_ctx->devices_status == STATUS_INIT) + { + event_log_error (hashcat_ctx, "status view is not available during initialization phase"); + + return; + } + + if (status_ctx->devices_status == STATUS_AUTOTUNE) + { + event_log_error (hashcat_ctx, "status view is not available during autotune phase"); + + return; + } + + u64 speed_cnt[DEVICES_MAX] = { 0 }; + double speed_ms[DEVICES_MAX] = { 0 }; + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + speed_cnt[device_id] = device_param->speed_cnt[0]; + speed_ms[device_id] = device_param->speed_ms[0]; + } + + u64 hashes_dev_ms[DEVICES_MAX] = { 0 }; + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + hashes_dev_ms[device_id] = 0; + + if (speed_ms[device_id] > 0) + { + hashes_dev_ms[device_id] = (double) speed_cnt[device_id] / speed_ms[device_id]; + } + } + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + event_log_info (hashcat_ctx, "%u:%u:%" PRIu64 "", device_id + 1, hashconfig->hash_mode, (hashes_dev_ms[device_id] * 1000)); + } +} + +void status_benchmark (hashcat_ctx_t *hashcat_ctx) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + user_options_t *user_options = hashcat_ctx->user_options; + + if (status_ctx->devices_status == STATUS_INIT) + { + event_log_error (hashcat_ctx, "status view is not available during initialization phase"); + + return; + } + + if (status_ctx->devices_status == STATUS_AUTOTUNE) + { + event_log_error (hashcat_ctx, "status view is not available during autotune phase"); + + return; + } + + if (status_ctx->shutdown_inner == 1) return; + + if (user_options->machine_readable == true) + { + status_benchmark_automate (hashcat_ctx); + + return; + } + + u64 speed_cnt[DEVICES_MAX] = { 0 }; + double speed_ms[DEVICES_MAX] = { 0 }; + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + speed_cnt[device_id] = device_param->speed_cnt[0]; + speed_ms[device_id] = device_param->speed_ms[0]; + } + + double hashes_all_ms = 0; + + double hashes_dev_ms[DEVICES_MAX] = { 0 }; + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + hashes_dev_ms[device_id] = 0; + + if (speed_ms[device_id] > 0) + { + hashes_dev_ms[device_id] = (double) speed_cnt[device_id] / speed_ms[device_id]; + + hashes_all_ms += hashes_dev_ms[device_id]; + } + } + + /** + * exec time + */ + + double exec_all_ms[DEVICES_MAX] = { 0 }; + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + double exec_ms_avg = get_avg_exec_time (device_param, EXEC_CACHE); + + exec_all_ms[device_id] = exec_ms_avg; + } + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped) continue; + + char display_dev_cur[16] = { 0 }; + + strncpy (display_dev_cur, "0.00", 4); + + format_speed_display ((double) hashes_dev_ms[device_id] * 1000, display_dev_cur, sizeof (display_dev_cur)); + + if (opencl_ctx->devices_active >= 10) + { + event_log_info (hashcat_ctx, "Speed.Dev.#%d: %9sH/s (%0.2fms)", device_id + 1, display_dev_cur, exec_all_ms[device_id]); + } + else + { + event_log_info (hashcat_ctx, "Speed.Dev.#%d.: %9sH/s (%0.2fms)", device_id + 1, display_dev_cur, exec_all_ms[device_id]); + } + } + + char display_all_cur[16] = { 0 }; + + strncpy (display_all_cur, "0.00", 4); + + format_speed_display ((double) hashes_all_ms * 1000, display_all_cur, sizeof (display_all_cur)); + + if (opencl_ctx->devices_active > 1) event_log_info (hashcat_ctx, "Speed.Dev.#*.: %9sH/s", display_all_cur); +} diff --git a/src/thread.c b/src/thread.c index bedba5f78..b97c8b2b8 100644 --- a/src/thread.c +++ b/src/thread.c @@ -116,7 +116,7 @@ void hc_signal (void (callback) (int)) #endif */ -void mycracked (hashcat_ctx_t *hashcat_ctx) +int mycracked (hashcat_ctx_t *hashcat_ctx) { status_ctx_t *status_ctx = hashcat_ctx->status_ctx; @@ -129,13 +129,16 @@ void mycracked (hashcat_ctx_t *hashcat_ctx) status_ctx->run_main_level3 = false; status_ctx->run_thread_level1 = false; status_ctx->run_thread_level2 = false; + + return 0; } -void myabort (hashcat_ctx_t *hashcat_ctx) +int myabort (hashcat_ctx_t *hashcat_ctx) { status_ctx_t *status_ctx = hashcat_ctx->status_ctx; //those checks create problems in benchmark mode, it's simply too short of a timeframe where it's running as STATUS_RUNNING + // not sure if this is still valid, but abort is also called by gpu temp monitor //if (status_ctx->devices_status != STATUS_RUNNING) return; status_ctx->devices_status = STATUS_ABORTED; @@ -145,13 +148,15 @@ void myabort (hashcat_ctx_t *hashcat_ctx) status_ctx->run_main_level3 = false; status_ctx->run_thread_level1 = false; status_ctx->run_thread_level2 = false; + + return 0; } -void myquit (hashcat_ctx_t *hashcat_ctx) +int myquit (hashcat_ctx_t *hashcat_ctx) { status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - //if (status_ctx->devices_status != STATUS_RUNNING) return; + if (status_ctx->devices_status != STATUS_RUNNING) return -1; status_ctx->devices_status = STATUS_QUIT; @@ -160,13 +165,15 @@ void myquit (hashcat_ctx_t *hashcat_ctx) status_ctx->run_main_level3 = false; status_ctx->run_thread_level1 = false; status_ctx->run_thread_level2 = false; + + return 0; } -void bypass (hashcat_ctx_t *hashcat_ctx) +int bypass (hashcat_ctx_t *hashcat_ctx) { status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - //if (status_ctx->devices_status != STATUS_RUNNING) return; + if (status_ctx->devices_status != STATUS_RUNNING) return -1; status_ctx->devices_status = STATUS_BYPASS; @@ -175,28 +182,77 @@ void bypass (hashcat_ctx_t *hashcat_ctx) status_ctx->run_main_level3 = true; status_ctx->run_thread_level1 = false; status_ctx->run_thread_level2 = false; + + return 0; } -void SuspendThreads (hashcat_ctx_t *hashcat_ctx) +int SuspendThreads (hashcat_ctx_t *hashcat_ctx) { status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - if (status_ctx->devices_status != STATUS_RUNNING) return; + if (status_ctx->devices_status != STATUS_RUNNING) return -1; hc_timer_set (&status_ctx->timer_paused); status_ctx->devices_status = STATUS_PAUSED; + + return 0; } -void ResumeThreads (hashcat_ctx_t *hashcat_ctx) +int ResumeThreads (hashcat_ctx_t *hashcat_ctx) { status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - if (status_ctx->devices_status != STATUS_PAUSED) return; + if (status_ctx->devices_status != STATUS_PAUSED) return -1; double ms_paused = hc_timer_get (status_ctx->timer_paused); status_ctx->ms_paused += ms_paused; status_ctx->devices_status = STATUS_RUNNING; + + return 0; +} + +int stop_at_checkpoint (hashcat_ctx_t *hashcat_ctx) +{ + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + if (status_ctx->devices_status != STATUS_RUNNING) return -1; + + // this feature only makes sense if --restore-disable was not specified + + restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; + + if (restore_ctx->enabled == false) + { + event_log_warning (hashcat_ctx, "This feature is disabled when --restore-disable is specified"); + + return -1; + } + + // Enable or Disable + + if ((status_ctx->run_thread_level1 == true) && (status_ctx->run_thread_level2 == true)) + { + status_ctx->run_main_level1 = false; + status_ctx->run_main_level2 = false; + status_ctx->run_main_level3 = false; + status_ctx->run_thread_level1 = false; + status_ctx->run_thread_level2 = true; + + event_log_info (hashcat_ctx, "Checkpoint enabled: Will quit at next Restore Point update"); + } + else + { + status_ctx->run_main_level1 = true; + status_ctx->run_main_level2 = true; + status_ctx->run_main_level3 = true; + status_ctx->run_thread_level1 = true; + status_ctx->run_thread_level2 = true; + + event_log_info (hashcat_ctx, "Checkpoint disabled: Restore Point updates will no longer be monitored"); + } + + return 0; }