1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-22 16:18:09 +00:00

Make loopback support modular

This commit is contained in:
jsteube 2016-09-30 12:07:49 +02:00
parent ea2eef72f2
commit 4aebe51407
4 changed files with 37 additions and 7 deletions

View File

@ -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);

View File

@ -854,6 +854,8 @@ typedef struct
typedef struct
{
bool enabled;
FILE *fp;
char *filename;

View File

@ -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

View File

@ -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);