diff --git a/include/cpt.h b/include/cpt.h index 7242e9183..1211924a7 100644 --- a/include/cpt.h +++ b/include/cpt.h @@ -10,7 +10,7 @@ #include #include -int cpt_ctx_init (cpt_ctx_t *cpt_ctx); +int cpt_ctx_init (cpt_ctx_t *cpt_ctx, const user_options_t *user_options); void cpt_ctx_destroy (cpt_ctx_t *cpt_ctx); void cpt_ctx_reset (cpt_ctx_t *cpt_ctx); diff --git a/include/debugfile.h b/include/debugfile.h index 0eb9ed5cb..0bb08ee5c 100644 --- a/include/debugfile.h +++ b/include/debugfile.h @@ -8,7 +8,7 @@ #include -int debugfile_init (debugfile_ctx_t *debugfile_ctx, const uint debug_mode, const char *debug_file); +int debugfile_init (debugfile_ctx_t *debugfile_ctx, const user_options_t *user_options); void debugfile_destroy (debugfile_ctx_t *debugfile_ctx); void debugfile_format_plain (debugfile_ctx_t *debugfile_ctx, const u8 *plain_ptr, const u32 plain_len); void debugfile_write_append (debugfile_ctx_t *debugfile_ctx, const u8 *rule_buf, const u32 rule_len, const u8 *mod_plain_ptr, const u32 mod_plain_len, const u8 *orig_plain_ptr, const u32 orig_plain_len); diff --git a/include/types.h b/include/types.h index 1796bf55f..9d093654c 100644 --- a/include/types.h +++ b/include/types.h @@ -800,6 +800,8 @@ typedef aes_context_t aes_ctx; typedef struct { + bool enabled; + FILE *fp; char *filename; u32 mode; @@ -1128,6 +1130,8 @@ typedef struct typedef struct { + bool enabled; + u32 bitmap_bits; u32 bitmap_nums; u32 bitmap_size; @@ -1255,6 +1259,8 @@ typedef struct typedef struct { + bool enabled; + cpt_t *cpt_buf; int cpt_pos; time_t cpt_start; diff --git a/src/bitmap.c b/src/bitmap.c index ad01e391c..23a68c68f 100644 --- a/src/bitmap.c +++ b/src/bitmap.c @@ -60,6 +60,17 @@ static u32 generate_bitmaps (const u32 digests_cnt, const u32 dgst_size, const u void bitmap_ctx_init (bitmap_ctx_t *bitmap_ctx, const user_options_t *user_options, const hashconfig_t *hashconfig, const hashes_t *hashes) { + bitmap_ctx->enabled = false; + + if (user_options->keyspace == true) return; + if (user_options->left == true) return; + if (user_options->show == true) return; + if (user_options->stdout_flag == true) return; + if (user_options->usage == true) return; + if (user_options->version == true) return; + + bitmap_ctx->enabled = true; + /** * generate bitmap tables */ @@ -130,6 +141,8 @@ void bitmap_ctx_init (bitmap_ctx_t *bitmap_ctx, const user_options_t *user_optio void bitmap_ctx_destroy (bitmap_ctx_t *bitmap_ctx) { + if (bitmap_ctx->enabled == false) return; + bitmap_ctx->bitmap_size = 0; bitmap_ctx->bitmap_mask = 0; bitmap_ctx->bitmap_shift1 = 0; diff --git a/src/combinator.c b/src/combinator.c index df21f9797..2a6baab08 100644 --- a/src/combinator.c +++ b/src/combinator.c @@ -12,10 +12,13 @@ int combinator_ctx_init (combinator_ctx_t *combinator_ctx, const user_options_t *user_options) { - memset (combinator_ctx, 0, sizeof (combinator_ctx_t)); - combinator_ctx->enabled = false; + if (user_options->left == true) return 0; + if (user_options->show == true) return 0; + if (user_options->usage == true) return 0; + if (user_options->version == true) return 0; + if ((user_options->attack_mode != ATTACK_MODE_COMBI) && (user_options->attack_mode != ATTACK_MODE_HYBRID1) && (user_options->attack_mode != ATTACK_MODE_HYBRID2)) return 0; diff --git a/src/cpt.c b/src/cpt.c index 3f87a955e..5c0b3a311 100644 --- a/src/cpt.c +++ b/src/cpt.c @@ -9,8 +9,19 @@ #include "logging.h" #include "cpt.h" -int cpt_ctx_init (cpt_ctx_t *cpt_ctx) +int cpt_ctx_init (cpt_ctx_t *cpt_ctx, const user_options_t *user_options) { + cpt_ctx->enabled = false; + + if (user_options->keyspace == true) return 0; + if (user_options->left == true) return 0; + if (user_options->show == true) return 0; + if (user_options->stdout_flag == true) return 0; + if (user_options->usage == true) return 0; + if (user_options->version == true) return 0; + + cpt_ctx->enabled = true; + cpt_ctx->cpt_buf = (cpt_t *) mycalloc (CPT_BUF, sizeof (cpt_t)); cpt_ctx->cpt_total = 0; @@ -22,6 +33,8 @@ int cpt_ctx_init (cpt_ctx_t *cpt_ctx) void cpt_ctx_destroy (cpt_ctx_t *cpt_ctx) { + if (cpt_ctx->enabled == false) return; + myfree (cpt_ctx->cpt_buf); myfree (cpt_ctx); @@ -29,6 +42,8 @@ void cpt_ctx_destroy (cpt_ctx_t *cpt_ctx) void cpt_ctx_reset (cpt_ctx_t *cpt_ctx) { + if (cpt_ctx->enabled == false) return; + memset (cpt_ctx->cpt_buf, 0, CPT_BUF * sizeof (cpt_t)); cpt_ctx->cpt_total = 0; diff --git a/src/debugfile.c b/src/debugfile.c index 9708e635c..b8aa8be69 100644 --- a/src/debugfile.c +++ b/src/debugfile.c @@ -5,26 +5,43 @@ #include "common.h" #include "types.h" +#include "memory.h" #include "logging.h" #include "debugfile.h" -int debugfile_init (debugfile_ctx_t *debugfile_ctx, const uint debug_mode, const char *debug_file) +int debugfile_init (debugfile_ctx_t *debugfile_ctx, const user_options_t *user_options) { - if (debug_mode == 0) return 0; + debugfile_ctx->enabled = false; - if (debug_file == NULL) return 0; + if (user_options->benchmark == true) return 0; + if (user_options->keyspace == true) return 0; + if (user_options->left == true) return 0; + if (user_options->show == true) return 0; + if (user_options->stdout_flag == true) return 0; + if (user_options->usage == true) return 0; + if (user_options->version == true) return 0; + if (user_options->debug_mode == 0) return 0; - debugfile_ctx->mode = debug_mode; + debugfile_ctx->enabled = true; - debugfile_ctx->filename = (char *) debug_file; + debugfile_ctx->mode = user_options->debug_mode; - debugfile_ctx->fp = fopen (debugfile_ctx->filename, "ab"); - - if (debugfile_ctx->fp == NULL) + if (debugfile_ctx->filename) { - log_error ("ERROR: Could not open debug-file for writing"); + debugfile_ctx->filename = user_options->debug_file; - return -1; + debugfile_ctx->fp = fopen (debugfile_ctx->filename, "ab"); + + if (debugfile_ctx->fp == NULL) + { + log_error ("ERROR: Could not open debug-file for writing"); + + return -1; + } + } + else + { + debugfile_ctx->fp = stdout; } return 0; @@ -32,13 +49,19 @@ int debugfile_init (debugfile_ctx_t *debugfile_ctx, const uint debug_mode, const void debugfile_destroy (debugfile_ctx_t *debugfile_ctx) { - if (debugfile_ctx->fp == NULL) return; + if (debugfile_ctx->enabled == false) return; + + if (debugfile_ctx->filename == NULL) return; fclose (debugfile_ctx->fp); + + myfree (debugfile_ctx); } void debugfile_format_plain (debugfile_ctx_t *debugfile_ctx, const u8 *plain_ptr, const u32 plain_len) { + if (debugfile_ctx->enabled == false) return; + int needs_hexify = 0; for (uint i = 0; i < plain_len; i++) @@ -77,6 +100,8 @@ void debugfile_format_plain (debugfile_ctx_t *debugfile_ctx, const u8 *plain_ptr void debugfile_write_append (debugfile_ctx_t *debugfile_ctx, const u8 *rule_buf, const u32 rule_len, const u8 *mod_plain_ptr, const u32 mod_plain_len, const u8 *orig_plain_ptr, const u32 orig_plain_len) { + if (debugfile_ctx->enabled == false) return; + const uint debug_mode = debugfile_ctx->mode; if ((debug_mode == 2) || (debug_mode == 3) || (debug_mode == 4)) diff --git a/src/hashcat.c b/src/hashcat.c index 9cc8aae6c..ace1e48a0 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -1308,7 +1308,7 @@ static int outer_loop (status_ctx_t *status_ctx, user_options_t *user_options, u data.cpt_ctx = cpt_ctx; - cpt_ctx_init (cpt_ctx); + cpt_ctx_init (cpt_ctx, user_options); /** * Wordlist allocate buffer @@ -1863,7 +1863,7 @@ int main (int argc, char **argv) data.debugfile_ctx = debugfile_ctx; - debugfile_init (debugfile_ctx, user_options->debug_mode, user_options->debug_file); + debugfile_init (debugfile_ctx, user_options); /** * cpu affinity diff --git a/src/hwmon.c b/src/hwmon.c index 416c116bb..51fbf409b 100644 --- a/src/hwmon.c +++ b/src/hwmon.c @@ -801,6 +801,10 @@ int hwmon_ctx_init (hwmon_ctx_t *hwmon_ctx, const user_options_t *user_options, hwmon_ctx->enabled = false; if (user_options->gpu_temp_disable == true) return 0; + if (user_options->show == true) return 0; + if (user_options->left == true) return 0; + if (user_options->keyspace == true) return 0; + if (user_options->stdout_flag == true) return 0; hwmon_ctx->hm_device = (hm_attrs_t *) mycalloc (DEVICES_MAX, sizeof (hm_attrs_t));