diff --git a/src/hashcat.c b/src/hashcat.c index 5211522ff..e8a9b6a69 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -54,9 +54,6 @@ #include "brain.h" #endif -// hashcat_ctx stored globally for signal handling -hashcat_ctx_t *hc_ctx; - // inner2_loop iterates through wordlists, then calls kernel execution static int inner2_loop (hashcat_ctx_t *hashcat_ctx) @@ -1095,8 +1092,7 @@ int hashcat_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct h hashcat_ctx->user_options_extra = (user_options_extra_t *) hcmalloc (sizeof (user_options_extra_t)); hashcat_ctx->user_options = (user_options_t *) hcmalloc (sizeof (user_options_t)); hashcat_ctx->wl_data = (wl_data_t *) hcmalloc (sizeof (wl_data_t)); - - hc_ctx = hashcat_ctx; + return 0; } diff --git a/src/main.c b/src/main.c index 5f58c2440..99932c9fb 100644 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,9 @@ int _dowildcard = -1; #endif +// hashcat_ctx stored globally for signal handling +hashcat_ctx_t *hc_ctx; + static void main_log_clear_line (MAYBE_UNUSED const size_t prev_len, MAYBE_UNUSED FILE *fp) { if (!is_stdout_terminal ()) return; @@ -1284,6 +1287,10 @@ int main (int argc, char **argv) return 0; } + // Initializing the hashcat ctx global pointer for the signal handler + + hc_ctx = hashcat_ctx; + // init a hashcat session; this initializes backend devices, hwmon, etc welcome_screen (hashcat_ctx, VERSION_TAG); diff --git a/src/thread.c b/src/thread.c index 130b3520f..2c84d4c8b 100644 --- a/src/thread.c +++ b/src/thread.c @@ -92,16 +92,24 @@ void hc_signal (BOOL WINAPI (callback) (DWORD)) void sigHandler_default (int sig) { - myabort (hc_ctx); + if (hc_ctx) + { + hc_ctx = NULL; + myabort (hc_ctx); + } - signal (sig, NULL); + // signal (sig, NULL); } void sigHandler_benchmark (int sig) { - myquit (hc_ctx); + if (hc_ctx) + { + hc_ctx = NULL; + myquit (hc_ctx); + } - signal (sig, NULL); + // signal (sig, NULL); } void hc_signal (void (callback) (int))