1
0
mirror of https://github.com/hashcat/hashcat.git synced 2025-01-03 12:21:07 +00:00

Update loopback.c function parameters

This commit is contained in:
jsteube 2016-10-06 17:01:29 +02:00
parent 3f05b7c0a7
commit 0885c0ec6b
4 changed files with 101 additions and 88 deletions

View File

@ -11,14 +11,13 @@
#include <errno.h> #include <errno.h>
#include <time.h> #include <time.h>
#define LOOPBACK_FILE "hashcat.loopback" static const char LOOPBACK_FILE[] = "hashcat.loopback";
void loopback_init (loopback_ctx_t *loopback_ctx, const user_options_t *user_options); void loopback_init (hashcat_ctx_t *hashcat_ctx);
void loopback_destroy (loopback_ctx_t *loopback_ctx); void loopback_destroy (hashcat_ctx_t *hashcat_ctx);
int loopback_write_open (loopback_ctx_t *loopback_ctx, const induct_ctx_t *induct_ctx); int loopback_write_open (hashcat_ctx_t *hashcat_ctx);
void loopback_write_close (loopback_ctx_t *loopback_ctx); void loopback_write_close (hashcat_ctx_t *hashcat_ctx);
void loopback_format_plain (loopback_ctx_t *loopback_ctx, const u8 *plain_ptr, const unsigned int plain_len); void loopback_write_append (hashcat_ctx_t *hashcat_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); void loopback_write_unlink (hashcat_ctx_t *hashcat_ctx);
void loopback_write_unlink (loopback_ctx_t *loopback_ctx);
#endif // _LOOPBACK_H #endif // _LOOPBACK_H

View File

@ -120,7 +120,6 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx)
hashes_t *hashes = hashcat_ctx->hashes; hashes_t *hashes = hashcat_ctx->hashes;
induct_ctx_t *induct_ctx = hashcat_ctx->induct_ctx; induct_ctx_t *induct_ctx = hashcat_ctx->induct_ctx;
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx; logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx;
restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx;
@ -399,7 +398,7 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx)
if (user_options->loopback == true) if (user_options->loopback == true)
{ {
loopback_write_open (loopback_ctx, induct_ctx); loopback_write_open (hashcat_ctx);
} }
/** /**
@ -500,7 +499,7 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx)
if (user_options->loopback == true) if (user_options->loopback == true)
{ {
loopback_write_close (loopback_ctx); loopback_write_close (hashcat_ctx);
} }
// print final status // print final status
@ -1237,7 +1236,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
*/ */
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx; logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
status_ctx_t *status_ctx = hashcat_ctx->status_ctx; status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
user_options_t *user_options = hashcat_ctx->user_options; user_options_t *user_options = hashcat_ctx->user_options;
@ -1348,7 +1346,7 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
* loopback init * loopback init
*/ */
loopback_init (loopback_ctx, user_options); loopback_init (hashcat_ctx);
/** /**
* debugfile init * debugfile init
@ -1489,7 +1487,7 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
tuning_db_destroy (hashcat_ctx); tuning_db_destroy (hashcat_ctx);
loopback_destroy (loopback_ctx); loopback_destroy (hashcat_ctx);
dictstat_destroy (hashcat_ctx); dictstat_destroy (hashcat_ctx);

View File

@ -289,7 +289,7 @@ void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, pl
if (loopback_ctx->fp != NULL) if (loopback_ctx->fp != NULL)
{ {
loopback_write_append (loopback_ctx, plain_ptr, plain_len); loopback_write_append (hashcat_ctx, plain_ptr, plain_len);
} }
// if enabled, update also the (rule) debug file // if enabled, update also the (rule) debug file

View File

@ -10,79 +10,10 @@
#include "shared.h" #include "shared.h"
#include "loopback.h" #include "loopback.h"
void loopback_init (loopback_ctx_t *loopback_ctx, const user_options_t *user_options) static void loopback_format_plain (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ptr, const unsigned int plain_len)
{ {
loopback_ctx->enabled = false; loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
if (user_options->benchmark == true) return;
if (user_options->keyspace == true) return;
if (user_options->left == true) return;
if (user_options->opencl_info == 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);
}
void loopback_destroy (loopback_ctx_t *loopback_ctx)
{
if (loopback_ctx->enabled == false) return;
memset (loopback_ctx, 0, sizeof (loopback_ctx_t));
}
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 u32 random_num = get_random_num (0, 9999);
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");
if (loopback_ctx->fp == NULL)
{
log_error ("ERROR: %s: %s", loopback_ctx->filename, strerror (errno));
return -1;
}
return 0;
}
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);
}
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);
}
void loopback_format_plain (loopback_ctx_t *loopback_ctx, const u8 *plain_ptr, const unsigned int plain_len)
{
if (loopback_ctx->enabled == false) return; if (loopback_ctx->enabled == false) return;
int needs_hexify = 0; int needs_hexify = 0;
@ -121,13 +52,98 @@ 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) void loopback_init (hashcat_ctx_t *hashcat_ctx)
{ {
loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
user_options_t *user_options = hashcat_ctx->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->opencl_info == 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);
}
void loopback_destroy (hashcat_ctx_t *hashcat_ctx)
{
loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
if (loopback_ctx->enabled == false) return;
memset (loopback_ctx, 0, sizeof (loopback_ctx_t));
}
int loopback_write_open (hashcat_ctx_t *hashcat_ctx)
{
induct_ctx_t *induct_ctx = hashcat_ctx->induct_ctx;
loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
if (loopback_ctx->enabled == false) return 0;
if (induct_ctx->enabled == false) return 0;
time_t now;
time (&now);
const u32 random_num = get_random_num (0, 9999);
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");
if (loopback_ctx->fp == NULL)
{
log_error ("ERROR: %s: %s", loopback_ctx->filename, strerror (errno));
return -1;
}
return 0;
}
void loopback_write_unlink (hashcat_ctx_t *hashcat_ctx)
{
loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
if (loopback_ctx->enabled == false) return;
if (loopback_ctx->filename == NULL) return;
unlink (loopback_ctx->filename);
}
void loopback_write_close (hashcat_ctx_t *hashcat_ctx)
{
loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
if (loopback_ctx->enabled == false) return;
if (loopback_ctx->fp == NULL) return;
fclose (loopback_ctx->fp);
}
void loopback_write_append (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ptr, const unsigned int plain_len)
{
loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
if (loopback_ctx->enabled == false) return; if (loopback_ctx->enabled == false) return;
FILE *fp = loopback_ctx->fp; FILE *fp = loopback_ctx->fp;
loopback_format_plain (loopback_ctx, plain_ptr, plain_len); loopback_format_plain (hashcat_ctx, plain_ptr, plain_len);
fputc ('\n', fp); fputc ('\n', fp);