diff --git a/include/thread.h b/include/thread.h index 2318beb4d..713fe9064 100644 --- a/include/thread.h +++ b/include/thread.h @@ -18,7 +18,7 @@ #if defined (_WIN) -#define hc_thread_create(t,T,f,a) t = CreateThread (T, 0, (LPTHREAD_START_ROUTINE) &f, a, 0, NULL) +#define hc_thread_create(t,f,a) t = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) &f, a, 0, NULL) #define hc_thread_wait(n,a) for (u32 i = 0; i < n; i++) WaitForSingleObject ((a)[i], INFINITE) #define hc_thread_exit(t) ExitThread (t) @@ -29,7 +29,7 @@ #elif defined (_POSIX) -#define hc_thread_create(t,T,f,a) pthread_create (&t, T, f, a) +#define hc_thread_create(t,f,a) pthread_create (&t, NULL, f, a) #define hc_thread_wait(n,a) for (u32 i = 0; i < n; i++) pthread_join ((a)[i], NULL) #define hc_thread_exit(t) pthread_exit (&t) diff --git a/include/types.h b/include/types.h index 0d7004033..c1025dcf2 100644 --- a/include/types.h +++ b/include/types.h @@ -566,6 +566,9 @@ typedef struct hashes hashinfo_t **hash_info; + u8 *out_buf; // allocates [HCBUFSIZ_LARGE]; + u8 *tmp_buf; // allocates [HCBUFSIZ_LARGE]; + } hashes_t; struct hashconfig diff --git a/src/Makefile b/src/Makefile index 9d5b08c84..8e609cdf1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -126,6 +126,7 @@ CFLAGS += -ftrapv # default linux and freebsd thread stack size is 2MB # default windows thread stack size is 1MB # default OSX thread stack size is 512kB +# unfortionally, this option isn't supported by older GCC and clang versions CFLAGS += -Wstack-usage=524288 diff --git a/src/hashcat.c b/src/hashcat.c index 258d5b855..0671d517b 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -178,7 +178,7 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx) thread_param->hashcat_ctx = hashcat_ctx; thread_param->tid = device_id; - hc_thread_create (c_threads[device_id], NULL, thread_autotune, thread_param); + hc_thread_create (c_threads[device_id], thread_autotune, thread_param); } hc_thread_wait (opencl_ctx->devices_cnt, c_threads); @@ -231,55 +231,14 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx) thread_param->hashcat_ctx = hashcat_ctx; thread_param->tid = device_id; - #if defined (__APPLE__) - size_t stackSize; - pthread_attr_t tattr; - pthread_attr_t *attrp = NULL; - - if (pthread_attr_init (&tattr) != 0) - { - event_log_error (hashcat_ctx, "Failed to initialize thread attributes"); - return -1; - } - - if (pthread_attr_getstacksize (&tattr, &stackSize) != 0) - { - event_log_error (hashcat_ctx, "Failed to get thread stack size"); - return -1; - } - - if (stackSize == 0) stackSize = PTHREAD_STACK_MIN; - stackSize *= 2; // mitigate OSX stack overflow - - if (pthread_attr_setstacksize (&tattr, stackSize) != 0) - { - event_log_error (hashcat_ctx, "Failed to set thread stack size"); - return -1; - } - - attrp = &tattr; - #endif - if (user_options_extra->wordlist_mode == WL_MODE_STDIN) { - #if defined (__APPLE__) - hc_thread_create (c_threads[device_id], attrp, thread_calc_stdin, thread_param); - #else - hc_thread_create (c_threads[device_id], NULL, thread_calc_stdin, thread_param); - #endif + hc_thread_create (c_threads[device_id], thread_calc_stdin, thread_param); } else { - #if defined (__APPLE__) - hc_thread_create (c_threads[device_id], attrp, thread_calc, thread_param); - #else - hc_thread_create (c_threads[device_id], NULL, thread_calc, thread_param); - #endif + hc_thread_create (c_threads[device_id], thread_calc, thread_param); } - - #if defined (__APPLE__) - if (attrp) pthread_attr_destroy (attrp); - #endif } hc_thread_wait (opencl_ctx->devices_cnt, c_threads); @@ -709,13 +668,13 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) if (user_options->keyspace == false && user_options->benchmark == false && user_options->stdout_flag == false && user_options->speed_only == false) { - hc_thread_create (inner_threads[inner_threads_cnt], NULL, thread_monitor, hashcat_ctx); + hc_thread_create (inner_threads[inner_threads_cnt], thread_monitor, hashcat_ctx); inner_threads_cnt++; if (outcheck_ctx->enabled == true) { - hc_thread_create (inner_threads[inner_threads_cnt], NULL, thread_outfile_remove, hashcat_ctx); + hc_thread_create (inner_threads[inner_threads_cnt], thread_outfile_remove, hashcat_ctx); inner_threads_cnt++; } diff --git a/src/hashes.c b/src/hashes.c index f7a7542e2..6bbe0fd73 100644 --- a/src/hashes.c +++ b/src/hashes.c @@ -183,11 +183,11 @@ int save_hash (hashcat_ctx_t *hashcat_ctx) fputc (separator, fp); } - char out_buf[HCBUFSIZ_LARGE]; // scratch buffer + u8 *out_buf = hashes->out_buf; out_buf[0] = 0; - ascii_digest (hashcat_ctx, out_buf, salt_pos, digest_pos); + ascii_digest (hashcat_ctx, (char *) out_buf, salt_pos, digest_pos); fprintf (fp, "%s" EOL, out_buf); } @@ -225,17 +225,18 @@ void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, pl { debugfile_ctx_t *debugfile_ctx = hashcat_ctx->debugfile_ctx; loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx; + hashes_t *hashes = hashcat_ctx->hashes; const u32 salt_pos = plain->salt_pos; const u32 digest_pos = plain->digest_pos; // relative // hash - char out_buf[HCBUFSIZ_LARGE]; + u8 *out_buf = hashes->out_buf; out_buf[0] = 0; - ascii_digest (hashcat_ctx, out_buf, salt_pos, digest_pos); + ascii_digest (hashcat_ctx, (char *) out_buf, salt_pos, digest_pos); // plain @@ -264,7 +265,7 @@ void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, pl // no need for locking, we're in a mutex protected function - potfile_write_append (hashcat_ctx, out_buf, plain_ptr, plain_len); + potfile_write_append (hashcat_ctx, (char *) out_buf, plain_ptr, plain_len); // outfile, can be either to file or stdout // if an error occurs opening the file, send to stdout as fallback @@ -274,7 +275,7 @@ void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, pl char tmp_buf[HCBUFSIZ_LARGE]; - const int tmp_len = outfile_write (hashcat_ctx, out_buf, plain_ptr, plain_len, crackpos, NULL, 0, tmp_buf); + const int tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, plain_ptr, plain_len, crackpos, NULL, 0, tmp_buf); outfile_write_close (hashcat_ctx); @@ -1298,6 +1299,18 @@ int hashes_init_stage4 (hashcat_ctx_t *hashcat_ctx) hashes->hashes_cnt = 0; hashes->hashes_buf = NULL; + // starting from here, we should allocate some scratch buffer for later use + + u8 *out_buf = (u8 *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (out_buf); + + hashes->out_buf = out_buf; + + // we need two buffers in parallel + + u8 *tmp_buf = (u8 *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (tmp_buf); + + hashes->tmp_buf = tmp_buf; + return 0; } @@ -1316,6 +1329,9 @@ void hashes_destroy (hashcat_ctx_t *hashcat_ctx) hcfree (hashes->hash_info); + hcfree (hashes->out_buf); + hcfree (hashes->tmp_buf); + memset (hashes, 0, sizeof (hashes_t)); } diff --git a/src/main.c b/src/main.c index e969798a9..d4ecc6515 100644 --- a/src/main.c +++ b/src/main.c @@ -170,7 +170,7 @@ static void main_outerloop_starting (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MA { // see thread_keypress() how to access status information - hc_thread_create (hashcat_user->outer_threads[hashcat_user->outer_threads_cnt], NULL, thread_keypress, hashcat_ctx); + hc_thread_create (hashcat_user->outer_threads[hashcat_user->outer_threads_cnt], thread_keypress, hashcat_ctx); hashcat_user->outer_threads_cnt++; } diff --git a/src/potfile.c b/src/potfile.c index 99a3595d5..ebf1dd246 100644 --- a/src/potfile.c +++ b/src/potfile.c @@ -539,13 +539,15 @@ int potfile_handle_show (hashcat_ctx_t *hashcat_ctx) if (digests_shown[hashes_idx] == 0) continue; - char out_buf[HCBUFSIZ_LARGE]; // scratch buffer + u8 *out_buf = hashes->out_buf; out_buf[0] = 0; - ascii_digest (hashcat_ctx, out_buf, salt_idx, digest_idx); + ascii_digest (hashcat_ctx, (char *) out_buf, salt_idx, digest_idx); - char tmp_buf[HCBUFSIZ_LARGE]; // scratch buffer + u8 *tmp_buf = hashes->tmp_buf; + + tmp_buf[0] = 0; hash_t *hash = &hashes_buf[hashes_idx]; @@ -568,7 +570,7 @@ int potfile_handle_show (hashcat_ctx_t *hashcat_ctx) } } - const int tmp_len = outfile_write (hashcat_ctx, out_buf, (unsigned char *) hash->pw_buf, hash->pw_len, 0, username, user_len, tmp_buf); + const int tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, (u8 *) hash->pw_buf, hash->pw_len, 0, username, user_len, (char *) tmp_buf); EVENT_DATA (EVENT_POTFILE_HASH_SHOW, tmp_buf, tmp_len); } @@ -600,11 +602,11 @@ int potfile_handle_left (hashcat_ctx_t *hashcat_ctx) if (digests_shown[hashes_idx] == 1) continue; - char out_buf[HCBUFSIZ_LARGE]; // scratch buffer + u8 *out_buf = hashes->out_buf; out_buf[0] = 0; - ascii_digest (hashcat_ctx, out_buf, salt_idx, digest_idx); + ascii_digest (hashcat_ctx, (char *) out_buf, salt_idx, digest_idx); hash_t *hash = &hashes_buf[hashes_idx]; @@ -627,9 +629,9 @@ int potfile_handle_left (hashcat_ctx_t *hashcat_ctx) } } - char tmp_buf[HCBUFSIZ_LARGE]; // scratch buffer + u8 *tmp_buf = hashes->tmp_buf; - const int tmp_len = outfile_write (hashcat_ctx, out_buf, NULL, 0, 0, username, user_len, tmp_buf); + const int tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, NULL, 0, 0, username, user_len, (char *) tmp_buf); EVENT_DATA (EVENT_POTFILE_HASH_LEFT, tmp_buf, tmp_len); }