From 946b4a37d0b38608ab5ed537f031689132ae23ae Mon Sep 17 00:00:00 2001 From: philsmd Date: Mon, 7 Dec 2015 18:31:45 +0100 Subject: [PATCH] implements the enhancement mentioned in issue #10 (cancel on next checkpoint) --- include/shared.h | 21 ++++++++------- include/types.h | 2 ++ src/oclHashcat.c | 40 ++++++++++++++++++++++++----- src/shared.c | 67 ++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 106 insertions(+), 24 deletions(-) diff --git a/include/shared.h b/include/shared.h index 4a987ac63..dc7679a35 100644 --- a/include/shared.h +++ b/include/shared.h @@ -1883,15 +1883,16 @@ extern hc_thread_mutex_t mux_display; * status */ -#define STATUS_STARTING 0 -#define STATUS_INIT 1 -#define STATUS_RUNNING 2 -#define STATUS_PAUSED 3 -#define STATUS_EXHAUSTED 4 -#define STATUS_CRACKED 5 -#define STATUS_ABORTED 6 -#define STATUS_QUIT 7 -#define STATUS_BYPASS 8 +#define STATUS_STARTING 0 +#define STATUS_INIT 1 +#define STATUS_RUNNING 2 +#define STATUS_PAUSED 3 +#define STATUS_EXHAUSTED 4 +#define STATUS_CRACKED 5 +#define STATUS_ABORTED 6 +#define STATUS_QUIT 7 +#define STATUS_BYPASS 8 +#define STATUS_STOP_AT_CHECKPOINT 9 #define ST_0000 "Initializing" #define ST_0001 "Starting" @@ -1902,6 +1903,7 @@ extern hc_thread_mutex_t mux_display; #define ST_0006 "Aborted" #define ST_0007 "Quit" #define ST_0008 "Bypass" +#define ST_0009 "Running (stop at checkpoint)" /** * kernel types @@ -2234,6 +2236,7 @@ restore_data_t *init_restore (int argc, char **argv); void read_restore (const char *eff_restore_file, restore_data_t *rd); void write_restore (const char *new_restore_file, restore_data_t *rd); void cycle_restore (); +void check_checkpoint (); #ifdef WIN diff --git a/include/types.h b/include/types.h index 9864988f9..76c3edfaa 100644 --- a/include/types.h +++ b/include/types.h @@ -1206,6 +1206,8 @@ typedef struct restore_data_t *rd; + uint64_t checkpoint_cur_words; // used for the "stop at next checkpoint" feature + /** * status, timer */ diff --git a/src/oclHashcat.c b/src/oclHashcat.c index 93c75c828..245b29aec 100644 --- a/src/oclHashcat.c +++ b/src/oclHashcat.c @@ -315,7 +315,7 @@ hc_thread_mutex_t mux_display; hc_global_data_t data; -const char *PROMPT = "[s]tatus [p]ause [r]esume [b]ypass [q]uit => "; +const char *PROMPT = "[s]tatus [p]ause [r]esume [b]ypass [c]heckpoint stop [q]uit => "; const char *USAGE_MINI[] = { @@ -1482,7 +1482,7 @@ void status_display () if (data.restore_disable == 0) { - log_info ("Restore point..: %llu/%llu (%.02f%%)", (uint64_t) 0, (uint64_t) 0, (float) 100); + log_info ("Restore.Point..: %llu/%llu (%.02f%%)", (uint64_t) 0, (uint64_t) 0, (float) 100); } } else @@ -1494,7 +1494,7 @@ void status_display () //if (data.restore_disable == 0) //{ - // log_info ("Restore point..: %llu", (unsigned long long int) restore_point); + // log_info ("Restore.Point..: %llu", (unsigned long long int) restore_point); //} } } @@ -2797,6 +2797,8 @@ static void run_cracker (hc_device_param_t *device_param, const uint pw_cnt, con { while (data.devices_status == STATUS_PAUSED) hc_sleep (1); + if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (data.devices_status == STATUS_CRACKED) break; if (data.devices_status == STATUS_ABORTED) break; if (data.devices_status == STATUS_QUIT) break; @@ -2823,6 +2825,8 @@ static void run_cracker (hc_device_param_t *device_param, const uint pw_cnt, con { while (data.devices_status == STATUS_PAUSED) hc_sleep (1); + if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (data.devices_status == STATUS_CRACKED) break; if (data.devices_status == STATUS_ABORTED) break; if (data.devices_status == STATUS_QUIT) break; @@ -3080,6 +3084,8 @@ static void run_cracker (hc_device_param_t *device_param, const uint pw_cnt, con run_kernel (KERN_RUN_2, device_param, pws_cnt); + if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (data.devices_status == STATUS_CRACKED) break; if (data.devices_status == STATUS_ABORTED) break; if (data.devices_status == STATUS_QUIT) break; @@ -3116,6 +3122,8 @@ static void run_cracker (hc_device_param_t *device_param, const uint pw_cnt, con run_kernel (KERN_RUN_3, device_param, pws_cnt); } + if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (data.devices_status == STATUS_CRACKED) break; if (data.devices_status == STATUS_ABORTED) break; if (data.devices_status == STATUS_QUIT) break; @@ -4954,6 +4962,8 @@ static void *thread_calc (void *p) device_param->pws_cnt = 0; } + if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (data.devices_status == STATUS_CRACKED) break; if (data.devices_status == STATUS_ABORTED) break; if (data.devices_status == STATUS_QUIT) break; @@ -5127,18 +5137,24 @@ static void *thread_calc (void *p) device_param->pw_add (device_param, (uint8_t *) line_buf, line_len); + if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (data.devices_status == STATUS_CRACKED) break; if (data.devices_status == STATUS_ABORTED) break; if (data.devices_status == STATUS_QUIT) break; if (data.devices_status == STATUS_BYPASS) break; } + if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (data.devices_status == STATUS_CRACKED) break; if (data.devices_status == STATUS_ABORTED) break; if (data.devices_status == STATUS_QUIT) break; if (data.devices_status == STATUS_BYPASS) break; } + if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (data.devices_status == STATUS_CRACKED) break; if (data.devices_status == STATUS_ABORTED) break; if (data.devices_status == STATUS_QUIT) break; @@ -5197,6 +5213,8 @@ static void *thread_calc (void *p) device_param->pws_cnt = 0; } + if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (data.devices_status == STATUS_CRACKED) break; if (data.devices_status == STATUS_ABORTED) break; if (data.devices_status == STATUS_QUIT) break; @@ -5250,6 +5268,8 @@ static void *thread_calc (void *p) device_param->pws_cnt = 0; } + if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (data.devices_status == STATUS_CRACKED) break; if (data.devices_status == STATUS_ABORTED) break; if (data.devices_status == STATUS_QUIT) break; @@ -17369,6 +17389,7 @@ int main (int argc, char **argv) hc_thread_wait (devices_cnt, c_threads); + local_free (c_threads); data.restore = 0; @@ -17377,6 +17398,8 @@ int main (int argc, char **argv) logfile_sub_var_uint ("status-after-work", data.devices_status); + if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (data.devices_status == STATUS_CRACKED) break; if (data.devices_status == STATUS_ABORTED) break; @@ -17454,6 +17477,8 @@ int main (int argc, char **argv) global_free (subid); } + if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) check_checkpoint (); + if (data.devices_status == STATUS_CRACKED) break; if (data.devices_status == STATUS_ABORTED) break; if (data.devices_status == STATUS_QUIT) break; @@ -17952,10 +17977,11 @@ int main (int argc, char **argv) if (quiet == 0) log_info_nn ("Started: %s", ctime (&proc_start)); if (quiet == 0) log_info_nn ("Stopped: %s", ctime (&proc_stop)); - if (data.devices_status == STATUS_ABORTED) return 2; - if (data.devices_status == STATUS_QUIT) return 2; - if (data.devices_status == STATUS_EXHAUSTED) return 1; - if (data.devices_status == STATUS_CRACKED) return 0; + if (data.devices_status == STATUS_ABORTED) return 2; + if (data.devices_status == STATUS_QUIT) return 2; + if (data.devices_status == STATUS_STOP_AT_CHECKPOINT) return 2; + if (data.devices_status == STATUS_EXHAUSTED) return 1; + if (data.devices_status == STATUS_CRACKED) return 0; return -1; } diff --git a/src/shared.c b/src/shared.c index b669aeb7b..2e7259cc6 100644 --- a/src/shared.c +++ b/src/shared.c @@ -5570,14 +5570,16 @@ char *strstatus (const uint devices_status) { switch (devices_status) { - case STATUS_INIT: return ((char *) ST_0000); break; - case STATUS_STARTING: return ((char *) ST_0001); break; - case STATUS_RUNNING: return ((char *) ST_0002); break; - case STATUS_PAUSED: return ((char *) ST_0003); break; - case STATUS_EXHAUSTED: return ((char *) ST_0004); break; - case STATUS_CRACKED: return ((char *) ST_0005); break; - case STATUS_ABORTED: return ((char *) ST_0006); break; - case STATUS_QUIT: return ((char *) ST_0007); break; + case STATUS_INIT: return ((char *) ST_0000); break; + case STATUS_STARTING: return ((char *) ST_0001); break; + case STATUS_RUNNING: return ((char *) ST_0002); break; + case STATUS_PAUSED: return ((char *) ST_0003); break; + case STATUS_EXHAUSTED: return ((char *) ST_0004); break; + case STATUS_CRACKED: return ((char *) ST_0005); break; + case STATUS_ABORTED: return ((char *) ST_0006); break; + case STATUS_QUIT: return ((char *) ST_0007); break; + case STATUS_BYPASS: return ((char *) ST_0008); break; + case STATUS_STOP_AT_CHECKPOINT: return ((char *) ST_0009); break; } return ((char *) "Unknown"); @@ -8360,6 +8362,28 @@ void bypass () log_info ("Next dictionary / mask in queue selected, bypassing current one"); } +void stop_at_checkpoint () +{ + if (data.devices_status != STATUS_RUNNING) return; + + // this feature only makes sense if --restore-disable was not specified + + if (data.restore_disable == 0) + { + data.devices_status = STATUS_STOP_AT_CHECKPOINT; + + // save the current restore point value + + data.checkpoint_cur_words = get_lowest_words_done (); + + log_info ("Stop at next checkpoint"); + } + else + { + log_info ("WARNING: this feature is disabled when --restore-disable was specified"); + } +} + void myabort () { if (data.devices_status == STATUS_INIT) return; @@ -8772,6 +8796,18 @@ void cycle_restore () } } +void check_checkpoint () +{ + // if (data.restore_disable == 1) break; (this is already implied by previous checks) + + uint64_t words_cur = get_lowest_words_done (); + + if (words_cur != data.checkpoint_cur_words) + { + myabort (); + } +} + /** * adjustments */ @@ -18713,6 +18749,21 @@ void *thread_keypress (void *p) break; + case 'c': + + log_info (""); + + if (benchmark == 1) break; + + stop_at_checkpoint (); + + log_info (""); + + if (quiet == 0) fprintf (stdout, "%s", PROMPT); + if (quiet == 0) fflush (stdout); + + break; + case 'q': log_info ("");