From 4aebe51407fc1bbc12fae6d6e5bf08d2dae2be88 Mon Sep 17 00:00:00 2001 From: jsteube Date: Fri, 30 Sep 2016 12:07:49 +0200 Subject: [PATCH] Make loopback support modular --- include/loopback.h | 4 ++-- include/types.h | 2 ++ src/hashcat.c | 4 ++-- src/loopback.c | 34 +++++++++++++++++++++++++++++++--- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/include/loopback.h b/include/loopback.h index 019d9bc73..1b67f9fc2 100644 --- a/include/loopback.h +++ b/include/loopback.h @@ -13,9 +13,9 @@ #define LOOPBACK_FILE "hashcat.loopback" -void loopback_init (loopback_ctx_t *loopback_ctx); +void loopback_init (loopback_ctx_t *loopback_ctx, const user_options_t *user_options); void loopback_destroy (loopback_ctx_t *loopback_ctx); -int loopback_write_open (loopback_ctx_t *loopback_ctx, const char *induction_directory); +int loopback_write_open (loopback_ctx_t *loopback_ctx, const induct_ctx_t *induct_ctx); void loopback_write_close (loopback_ctx_t *loopback_ctx); void loopback_format_plain (loopback_ctx_t *loopback_ctx, const u8 *plain_ptr, const unsigned int plain_len); void loopback_write_append (loopback_ctx_t *loopback_ctx, const u8 *plain_ptr, const unsigned int plain_len); diff --git a/include/types.h b/include/types.h index 9d093654c..97674fc7e 100644 --- a/include/types.h +++ b/include/types.h @@ -854,6 +854,8 @@ typedef struct typedef struct { + bool enabled; + FILE *fp; char *filename; diff --git a/src/hashcat.c b/src/hashcat.c index ace1e48a0..58194015b 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -336,7 +336,7 @@ static int inner2_loop (status_ctx_t *status_ctx, user_options_t *user_options, if (user_options->loopback == true) { - loopback_write_open (loopback_ctx, induct_ctx->root_directory); + loopback_write_open (loopback_ctx, induct_ctx); } /** @@ -1853,7 +1853,7 @@ int main (int argc, char **argv) data.loopback_ctx = loopback_ctx; - loopback_init (loopback_ctx); + loopback_init (loopback_ctx, user_options); /** * debugfile init diff --git a/src/loopback.c b/src/loopback.c index 3f83069fd..3ff0ab5d7 100644 --- a/src/loopback.c +++ b/src/loopback.c @@ -10,8 +10,20 @@ #include "shared.h" #include "loopback.h" -void loopback_init (loopback_ctx_t *loopback_ctx) +void loopback_init (loopback_ctx_t *loopback_ctx, const user_options_t *user_options) { + loopback_ctx->enabled = false; + + if (user_options->benchmark == true) return; + 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; + + loopback_ctx->enabled = true; + loopback_ctx->fp = NULL; loopback_ctx->filename = (char *) mymalloc (HCBUFSIZ_TINY); @@ -19,18 +31,26 @@ void loopback_init (loopback_ctx_t *loopback_ctx) void loopback_destroy (loopback_ctx_t *loopback_ctx) { + if (loopback_ctx->enabled == false) return; + myfree (loopback_ctx->filename); + + myfree (loopback_ctx); } -int loopback_write_open (loopback_ctx_t *loopback_ctx, const char *induction_directory) +int loopback_write_open (loopback_ctx_t *loopback_ctx, const induct_ctx_t *induct_ctx) { + if (loopback_ctx->enabled == false) return 0; + + if (induct_ctx->enabled == false) return 0; + time_t now; time (&now); const uint random_num = get_random_num (0, 9999); - snprintf (loopback_ctx->filename, HCBUFSIZ_TINY - 1, "%s/%s.%d_%u", induction_directory, LOOPBACK_FILE, (int) now, random_num); + snprintf (loopback_ctx->filename, HCBUFSIZ_TINY - 1, "%s/%s.%d_%u", induct_ctx->root_directory, LOOPBACK_FILE, (int) now, random_num); loopback_ctx->fp = fopen (loopback_ctx->filename, "ab"); @@ -46,6 +66,8 @@ int loopback_write_open (loopback_ctx_t *loopback_ctx, const char *induction_dir void loopback_write_unlink (loopback_ctx_t *loopback_ctx) { + if (loopback_ctx->enabled == false) return; + if (loopback_ctx->filename == NULL) return; unlink (loopback_ctx->filename); @@ -53,6 +75,8 @@ void loopback_write_unlink (loopback_ctx_t *loopback_ctx) void loopback_write_close (loopback_ctx_t *loopback_ctx) { + if (loopback_ctx->enabled == false) return; + if (loopback_ctx->fp == NULL) return; fclose (loopback_ctx->fp); @@ -60,6 +84,8 @@ void loopback_write_close (loopback_ctx_t *loopback_ctx) void loopback_format_plain (loopback_ctx_t *loopback_ctx, const u8 *plain_ptr, const unsigned int plain_len) { + if (loopback_ctx->enabled == false) return; + int needs_hexify = 0; for (uint i = 0; i < plain_len; i++) @@ -98,6 +124,8 @@ void loopback_format_plain (loopback_ctx_t *loopback_ctx, const u8 *plain_ptr, c void loopback_write_append (loopback_ctx_t *loopback_ctx, const u8 *plain_ptr, const unsigned int plain_len) { + if (loopback_ctx->enabled == false) return; + FILE *fp = loopback_ctx->fp; loopback_format_plain (loopback_ctx, plain_ptr, plain_len);