From c7999c66bc289023917b2178cb981f2c47585f45 Mon Sep 17 00:00:00 2001 From: jsteube Date: Fri, 6 Jan 2017 08:45:40 +0100 Subject: [PATCH] Returncode: Added dedicated returncode (see docs/status_codes.txt) for shutdowns caused by --runtime and checkpoint keypress --- docs/changes.txt | 1 + docs/status_codes.txt | 2 ++ include/thread.h | 2 ++ include/types.h | 20 +++++++++++--------- src/hashcat.c | 17 +++++++++++++---- src/monitor.c | 2 +- src/status.c | 22 +++++++++++++--------- src/thread.c | 32 ++++++++++++++++++++++++++++++-- 8 files changed, 73 insertions(+), 25 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 2d8c5341b..0b41b7bc4 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -61,6 +61,7 @@ - OpenCL Runtime: Updated hashcat.hctune for Iris Pro GPU on OSX - Potfile: In v3.10 already, the default potfile suffix changed but the note about was missing. The "hashcat.pot" became "hashcat.potfile" - Potfile: Added old potfile detection, show warning message +- Returncode: Added dedicated returncode (see docs/status_codes.txt) for shutdowns caused by --runtime and checkpoint keypress - Sanity: Added sanity check to disallow --speed-only in combination with -i - Sanity: Added sanity check to disallow --loopback in combination with --runtime - Threads: Replaced all calls to ctime() with ctime_r() to ensure thread safety diff --git a/docs/status_codes.txt b/docs/status_codes.txt index 3282ff725..0c8c831b4 100644 --- a/docs/status_codes.txt +++ b/docs/status_codes.txt @@ -6,3 +6,5 @@ status codes on exit: 0 = OK/cracked 1 = exhausted 2 = aborted + 3 = aborted by checkpoint + 4 = aborted by runtime diff --git a/include/thread.h b/include/thread.h index 713fe9064..4c9547917 100644 --- a/include/thread.h +++ b/include/thread.h @@ -57,6 +57,8 @@ void hc_signal (void (callback) (int)); */ int mycracked (hashcat_ctx_t *hashcat_ctx); +int myabort_runtime (hashcat_ctx_t *hashcat_ctx); +int myabort_checkpoint (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); diff --git a/include/types.h b/include/types.h index 177ac508e..9f040e5a6 100644 --- a/include/types.h +++ b/include/types.h @@ -160,15 +160,17 @@ typedef enum vendor_id typedef enum status_rc { - STATUS_INIT = 0, - STATUS_AUTOTUNE = 1, - STATUS_RUNNING = 2, - STATUS_PAUSED = 3, - STATUS_EXHAUSTED = 4, - STATUS_CRACKED = 5, - STATUS_ABORTED = 6, - STATUS_QUIT = 7, - STATUS_BYPASS = 8, + STATUS_INIT = 0, + STATUS_AUTOTUNE = 1, + STATUS_RUNNING = 2, + STATUS_PAUSED = 3, + STATUS_EXHAUSTED = 4, + STATUS_CRACKED = 5, + STATUS_ABORTED = 6, + STATUS_QUIT = 7, + STATUS_BYPASS = 8, + STATUS_ABORTED_CHECKPOINT = 9, + STATUS_ABORTED_RUNTIME = 10, } status_rc_t; diff --git a/src/hashcat.c b/src/hashcat.c index 061689d31..3bd809485 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -241,8 +241,15 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx) hcfree (threads_param); + if ((status_ctx->devices_status == STATUS_RUNNING) && (status_ctx->checkpoint_shutdown == true)) + { + myabort_checkpoint (hashcat_ctx); + } + if ((status_ctx->devices_status != STATUS_CRACKED) && (status_ctx->devices_status != STATUS_ABORTED) + && (status_ctx->devices_status != STATUS_ABORTED_CHECKPOINT) + && (status_ctx->devices_status != STATUS_ABORTED_RUNTIME) && (status_ctx->devices_status != STATUS_QUIT) && (status_ctx->devices_status != STATUS_BYPASS)) { @@ -1112,10 +1119,12 @@ int hashcat_session_execute (hashcat_ctx_t *hashcat_ctx) if (rc_final == 0) { - if (status_ctx->devices_status == STATUS_ABORTED) rc_final = 2; - if (status_ctx->devices_status == STATUS_QUIT) rc_final = 2; - if (status_ctx->devices_status == STATUS_EXHAUSTED) rc_final = 1; - if (status_ctx->devices_status == STATUS_CRACKED) rc_final = 0; + if (status_ctx->devices_status == STATUS_ABORTED_RUNTIME) rc_final = 4; + if (status_ctx->devices_status == STATUS_ABORTED_CHECKPOINT) rc_final = 3; + if (status_ctx->devices_status == STATUS_ABORTED) rc_final = 2; + if (status_ctx->devices_status == STATUS_QUIT) rc_final = 2; + if (status_ctx->devices_status == STATUS_EXHAUSTED) rc_final = 1; + if (status_ctx->devices_status == STATUS_CRACKED) rc_final = 0; } // done diff --git a/src/monitor.c b/src/monitor.c index b051ae37e..176e79a1c 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -290,7 +290,7 @@ static int monitor (hashcat_ctx_t *hashcat_ctx) { EVENT_DATA (EVENT_MONITOR_RUNTIME_LIMIT, NULL, 0); - myabort (hashcat_ctx); + myabort_runtime (hashcat_ctx); } } diff --git a/src/status.c b/src/status.c index 69ae21b5f..2508a6030 100644 --- a/src/status.c +++ b/src/status.c @@ -27,6 +27,8 @@ 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_0009[] = "Aborted (Checkpoint)"; +static const char ST_0010[] = "Aborted (Runtime)"; static const char ST_9999[] = "Unknown! Bug!"; static const char UNITS[7] = { ' ', 'k', 'M', 'G', 'T', 'P', 'E' }; @@ -196,15 +198,17 @@ char *status_get_status_string (const hashcat_ctx_t *hashcat_ctx) 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); + 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); + case STATUS_ABORTED_CHECKPOINT: return ((char *) ST_0009); + case STATUS_ABORTED_RUNTIME: return ((char *) ST_0010); } return ((char *) ST_9999); diff --git a/src/thread.c b/src/thread.c index 2d40e3d28..05b98fbe7 100644 --- a/src/thread.c +++ b/src/thread.c @@ -120,8 +120,6 @@ int mycracked (hashcat_ctx_t *hashcat_ctx) { status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - //if (status_ctx->devices_status != STATUS_RUNNING) return; - status_ctx->devices_status = STATUS_CRACKED; status_ctx->run_main_level1 = false; @@ -133,6 +131,36 @@ int mycracked (hashcat_ctx_t *hashcat_ctx) return 0; } +int myabort_checkpoint (hashcat_ctx_t *hashcat_ctx) +{ + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + status_ctx->devices_status = STATUS_ABORTED_CHECKPOINT; + + 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 = false; + + return 0; +} + +int myabort_runtime (hashcat_ctx_t *hashcat_ctx) +{ + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + status_ctx->devices_status = STATUS_ABORTED_RUNTIME; + + 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 = false; + + return 0; +} + int myabort (hashcat_ctx_t *hashcat_ctx) { status_ctx_t *status_ctx = hashcat_ctx->status_ctx;