From 04a30e6071b99b9b26ca156db7239a84a602b70c Mon Sep 17 00:00:00 2001 From: jsteube Date: Sun, 26 Nov 2017 10:50:22 +0100 Subject: [PATCH] Show [r]esume in prompt in pause mode only and show [p]ause in prompt in resume mode only Fixes https://github.com/hashcat/hashcat/issues/1459 --- docs/changes.txt | 6 ++++ include/terminal.h | 4 +-- src/autotune.c | 4 +-- src/main.c | 36 +++++++++---------- src/terminal.c | 87 ++++++++++++++++++++++++++++++++-------------- 5 files changed, 89 insertions(+), 48 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 9ef37abc4..f895126ec 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -14,6 +14,12 @@ - Fixed a hash parsing problem for 7-Zip hashes: allow a longer crc32 data length field within the hash format - Fixed the output of --show if $HEX[] passwords are present within the potfile +## +## Improvements +## + +- Show [r]esume in prompt in pause mode only and show [p]ause in prompt in resume mode only + ## ## Technical ## diff --git a/include/terminal.h b/include/terminal.h index 7bbcc3acf..161cc7600 100644 --- a/include/terminal.h +++ b/include/terminal.h @@ -26,8 +26,8 @@ void goodbye_screen (hashcat_ctx_t *hashcat_ctx, const hc_time_t proc_start, con int setup_console (void); -void send_prompt (void); -void clear_prompt (void); +void send_prompt (hashcat_ctx_t *hashcat_ctx); +void clear_prompt (hashcat_ctx_t *hashcat_ctx); void *thread_keypress (void *p); diff --git a/src/autotune.c b/src/autotune.c index ff639f3e7..459877e82 100644 --- a/src/autotune.c +++ b/src/autotune.c @@ -340,7 +340,7 @@ static int autotune (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param if (user_options->quiet == false) { - clear_prompt (); + clear_prompt (hashcat_ctx); printf ( @@ -350,7 +350,7 @@ static int autotune (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param device_param->device_id + 1, kernel_loops ); - send_prompt (); + send_prompt (hashcat_ctx); } #endif diff --git a/src/main.c b/src/main.c index a3174303a..8f5049059 100644 --- a/src/main.c +++ b/src/main.c @@ -234,7 +234,7 @@ static void main_cracker_starting (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYB { event_log_info_nn (hashcat_ctx, NULL); - send_prompt (); + send_prompt (hashcat_ctx); } } else if (user_options_extra->wordlist_mode == WL_MODE_STDIN) @@ -261,7 +261,7 @@ static void main_cracker_finished (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYB { if ((user_options->speed_only == false) && (user_options->quiet == false)) { - clear_prompt (); + clear_prompt (hashcat_ctx); } } @@ -322,7 +322,7 @@ static void main_cracker_hash_cracked (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { - if (outfile_ctx->filename == NULL) if (user_options->quiet == false) clear_prompt (); + if (outfile_ctx->filename == NULL) if (user_options->quiet == false) clear_prompt (hashcat_ctx); } hc_fwrite (buf, len, 1, stdout); @@ -332,7 +332,7 @@ static void main_cracker_hash_cracked (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, { if (status_ctx->devices_status != STATUS_CRACKED) { - if (outfile_ctx->filename == NULL) if (user_options->quiet == false) send_prompt (); + if (outfile_ctx->filename == NULL) if (user_options->quiet == false) send_prompt (hashcat_ctx); } } } @@ -571,12 +571,12 @@ static void main_set_kernel_power_final (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx if (user_options->quiet == true) return; - clear_prompt (); + clear_prompt (hashcat_ctx); event_log_advice (hashcat_ctx, "Approaching final keyspace - workload adjusted."); event_log_advice (hashcat_ctx, NULL); - send_prompt (); + send_prompt (hashcat_ctx); } static void main_monitor_throttle1 (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) @@ -588,7 +588,7 @@ static void main_monitor_throttle1 (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAY if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { - clear_prompt (); + clear_prompt (hashcat_ctx); } const u32 *device_id = (const u32 *) buf; @@ -597,7 +597,7 @@ static void main_monitor_throttle1 (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAY if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { - send_prompt (); + send_prompt (hashcat_ctx); } } @@ -610,7 +610,7 @@ static void main_monitor_throttle2 (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAY if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { - clear_prompt (); + clear_prompt (hashcat_ctx); } const u32 *device_id = (const u32 *) buf; @@ -619,7 +619,7 @@ static void main_monitor_throttle2 (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAY if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { - send_prompt (); + send_prompt (hashcat_ctx); } } @@ -632,7 +632,7 @@ static void main_monitor_throttle3 (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAY if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { - clear_prompt (); + clear_prompt (hashcat_ctx); } const u32 *device_id = (const u32 *) buf; @@ -642,7 +642,7 @@ static void main_monitor_throttle3 (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAY if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { - send_prompt (); + send_prompt (hashcat_ctx); } } @@ -656,7 +656,7 @@ static void main_monitor_performance_hint (MAYBE_UNUSED hashcat_ctx_t *hashcat_c if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { - clear_prompt (); + clear_prompt (hashcat_ctx); } event_log_advice (hashcat_ctx, "Cracking performance lower than expected?"); @@ -689,7 +689,7 @@ static void main_monitor_performance_hint (MAYBE_UNUSED hashcat_ctx_t *hashcat_c if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { - send_prompt (); + send_prompt (hashcat_ctx); } } @@ -702,7 +702,7 @@ static void main_monitor_temp_abort (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MA if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { - clear_prompt (); + clear_prompt (hashcat_ctx); } const u32 *device_id = (const u32 *) buf; @@ -719,7 +719,7 @@ static void main_monitor_runtime_limit (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { - clear_prompt (); + clear_prompt (hashcat_ctx); } event_log_warning (hashcat_ctx, "Runtime limit reached, aborting..."); @@ -737,7 +737,7 @@ static void main_monitor_status_refresh (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx { if (user_options->quiet == false) { - //clear_prompt (); + //clear_prompt (hashcat_ctx); event_log_info (hashcat_ctx, NULL); event_log_info (hashcat_ctx, NULL); @@ -752,7 +752,7 @@ static void main_monitor_status_refresh (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx { event_log_info (hashcat_ctx, NULL); - send_prompt (); + send_prompt (hashcat_ctx); } } diff --git a/src/terminal.c b/src/terminal.c index ea3ed6b2e..5c808b3ad 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -21,7 +21,8 @@ static const size_t TERMINAL_LINE_LENGTH = 79; -static const char *PROMPT = "[s]tatus [p]ause [r]esume [b]ypass [c]heckpoint [q]uit => "; +static const char *PROMPT_ACTIVE = "[s]tatus [p]ause [b]ypass [c]heckpoint [q]uit => "; +static const char *PROMPT_PAUSED = "[s]tatus [r]esume [b]ypass [c]heckpoint [q]uit => "; void welcome_screen (hashcat_ctx_t *hashcat_ctx, const char *version_tag) { @@ -124,18 +125,40 @@ int setup_console () return 0; } -void send_prompt () +void send_prompt (hashcat_ctx_t *hashcat_ctx) { - fprintf (stdout, "%s", PROMPT); + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + if (status_ctx->devices_status == STATUS_PAUSED) + { + fprintf (stdout, "%s", PROMPT_PAUSED); + } + else + { + fprintf (stdout, "%s", PROMPT_ACTIVE); + } fflush (stdout); } -void clear_prompt () +void clear_prompt (hashcat_ctx_t *hashcat_ctx) { + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + size_t prompt_sz = 0; + + if (status_ctx->devices_status == STATUS_PAUSED) + { + prompt_sz = strlen (PROMPT_PAUSED); + } + else + { + prompt_sz = strlen (PROMPT_ACTIVE); + } + fputc ('\r', stdout); - for (size_t i = 0; i < strlen (PROMPT); i++) + for (size_t i = 0; i < prompt_sz; i++) { fputc (' ', stdout); } @@ -186,7 +209,7 @@ static void keypress (hashcat_ctx_t *hashcat_ctx) event_log_info (hashcat_ctx, NULL); - if (quiet == false) send_prompt (); + if (quiet == false) send_prompt (hashcat_ctx); break; @@ -200,41 +223,47 @@ static void keypress (hashcat_ctx_t *hashcat_ctx) event_log_info (hashcat_ctx, NULL); - if (quiet == false) send_prompt (); + if (quiet == false) send_prompt (hashcat_ctx); break; case 'p': - event_log_info (hashcat_ctx, NULL); - - SuspendThreads (hashcat_ctx); - - if (status_ctx->devices_status == STATUS_PAUSED) + if (status_ctx->devices_status != STATUS_PAUSED) { - event_log_info (hashcat_ctx, "Paused"); + event_log_info (hashcat_ctx, NULL); + + SuspendThreads (hashcat_ctx); + + if (status_ctx->devices_status == STATUS_PAUSED) + { + event_log_info (hashcat_ctx, "Paused"); + } + + event_log_info (hashcat_ctx, NULL); } - event_log_info (hashcat_ctx, NULL); - - if (quiet == false) send_prompt (); + if (quiet == false) send_prompt (hashcat_ctx); break; case 'r': - event_log_info (hashcat_ctx, NULL); - - ResumeThreads (hashcat_ctx); - - if (status_ctx->devices_status == STATUS_RUNNING) + if (status_ctx->devices_status == STATUS_PAUSED) { - event_log_info (hashcat_ctx, "Resumed"); + event_log_info (hashcat_ctx, NULL); + + ResumeThreads (hashcat_ctx); + + if (status_ctx->devices_status != STATUS_PAUSED) + { + event_log_info (hashcat_ctx, "Resumed"); + } + + event_log_info (hashcat_ctx, NULL); } - event_log_info (hashcat_ctx, NULL); - - if (quiet == false) send_prompt (); + if (quiet == false) send_prompt (hashcat_ctx); break; @@ -255,7 +284,7 @@ static void keypress (hashcat_ctx_t *hashcat_ctx) event_log_info (hashcat_ctx, NULL); - if (quiet == false) send_prompt (); + if (quiet == false) send_prompt (hashcat_ctx); break; @@ -265,6 +294,12 @@ static void keypress (hashcat_ctx_t *hashcat_ctx) myquit (hashcat_ctx); + break; + + default: + + if (quiet == false) send_prompt (hashcat_ctx); + break; }