From f3fc5d96c41f8a33074d748092cfef7861330e15 Mon Sep 17 00:00:00 2001 From: jsteube Date: Sat, 29 Oct 2016 15:12:45 +0200 Subject: [PATCH] Limit status_ctx access with a flag, easier to test --- include/types.h | 2 ++ src/hashcat.c | 27 +++++---------------------- src/status.c | 10 ++++------ 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/include/types.h b/include/types.h index 65ac45f92..433af2abe 100644 --- a/include/types.h +++ b/include/types.h @@ -1402,6 +1402,8 @@ typedef struct status_ctx * main status */ + bool accessible; + u32 devices_status; /** diff --git a/src/hashcat.c b/src/hashcat.c index 067dbff5e..6e5db2dc9 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -223,6 +223,8 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx) status_ctx->devices_status = STATUS_RUNNING; + status_ctx->accessible = true; + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { thread_param_t *thread_param = threads_param + device_id; @@ -269,6 +271,8 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx) EVENT (EVENT_CRACKER_FINISHED); + status_ctx->accessible = false; + // mark sub logfile logfile_sub_var_uint ("status-after-work", status_ctx->devices_status); @@ -1169,28 +1173,7 @@ int hashcat_get_status (hashcat_ctx_t *hashcat_ctx, hashcat_status_t *hashcat_st if (status_ctx == NULL) return -1; // ways too early - /* - if (status_ctx->devices_status == STATUS_INIT) - { - event_log_error (hashcat_ctx, "Status view is not available during initialization phase"); - - return -1; - } - - if (status_ctx->devices_status == STATUS_AUTOTUNE) - { - event_log_error (hashcat_ctx, "Status view is not available during autotune phase"); - - return -1; - } - - if (status_ctx->devices_status == STATUS_RUNNING) - { - event_log_error (hashcat_ctx, "Status view is not available during autotune phase"); - - return -1; - } - */ + if (status_ctx->accessible == false) return -1; // either too early or too late hashcat_status->digests_cnt = status_get_digests_cnt (hashcat_ctx); hashcat_status->digests_done = status_get_digests_done (hashcat_ctx); diff --git a/src/status.c b/src/status.c index ebc37ab4e..95983620f 100644 --- a/src/status.c +++ b/src/status.c @@ -530,9 +530,7 @@ char *status_get_input_candidates_dev (const hashcat_ctx_t *hashcat_ctx, const i const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; - if (status_ctx->devices_status == STATUS_INIT) return NULL; - if (status_ctx->devices_status == STATUS_AUTOTUNE) return NULL; - if (status_ctx->devices_status == STATUS_AUTOTUNE) return NULL; + if (status_ctx->accessible == false) return NULL; hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; @@ -1247,7 +1245,7 @@ int status_get_cpt_cur_min (const hashcat_ctx_t *hashcat_ctx) const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - if (status_ctx->devices_status != STATUS_RUNNING) return 0; + if (status_ctx->accessible == false) return 0; const time_t now = time (NULL); @@ -1272,7 +1270,7 @@ int status_get_cpt_cur_hour (const hashcat_ctx_t *hashcat_ctx) const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - if (status_ctx->devices_status != STATUS_RUNNING) return 0; + if (status_ctx->accessible == false) return 0; const time_t now = time (NULL); @@ -1297,7 +1295,7 @@ int status_get_cpt_cur_day (const hashcat_ctx_t *hashcat_ctx) const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - if (status_ctx->devices_status != STATUS_RUNNING) return 0; + if (status_ctx->accessible == false) return 0; const time_t now = time (NULL);