mirror of
https://github.com/hashcat/hashcat.git
synced 2024-11-23 00:28:11 +00:00
Move loopback related stuff to loopback.c
This commit is contained in:
parent
533a87b685
commit
bd5bc294e6
@ -142,7 +142,7 @@ typedef struct
|
||||
char *induction_directory;
|
||||
char *outfile_check_directory;
|
||||
uint loopback;
|
||||
char *loopback_file;
|
||||
|
||||
uint restore;
|
||||
uint restore_timer;
|
||||
uint restore_disable;
|
||||
@ -177,8 +177,8 @@ typedef struct
|
||||
hashconfig_t *hashconfig;
|
||||
|
||||
outfile_ctx_t *outfile_ctx;
|
||||
|
||||
potfile_ctx_t *potfile_ctx;
|
||||
loopback_ctx_t *loopback_ctx;
|
||||
|
||||
#if defined (HAVE_HWMON)
|
||||
uint gpu_temp_disable;
|
||||
|
@ -6,4 +6,27 @@
|
||||
#ifndef _LOOPBACK_H
|
||||
#define _LOOPBACK_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#define LOOPBACK 0
|
||||
#define LOOPBACK_FILE "hashcat.loopback"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FILE *fp;
|
||||
char *filename;
|
||||
|
||||
} loopback_ctx_t;
|
||||
|
||||
void loopback_init (loopback_ctx_t *loopback_ctx);
|
||||
void loopback_destroy (loopback_ctx_t *loopback_ctx);
|
||||
int loopback_write_open (loopback_ctx_t *loopback_ctx, const char *induction_directory);
|
||||
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);
|
||||
void loopback_write_unlink (loopback_ctx_t *loopback_ctx);
|
||||
|
||||
#endif // _LOOPBACK_H
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "opencl.h"
|
||||
#include "outfile.h"
|
||||
#include "potfile.h"
|
||||
#include "loopback.h"
|
||||
#include "data.h"
|
||||
|
||||
hc_global_data_t data;
|
||||
|
130
src/hashcat.c
130
src/hashcat.c
@ -59,6 +59,7 @@
|
||||
#include "restore.h"
|
||||
#include "outfile.h"
|
||||
#include "potfile.h"
|
||||
#include "loopback.h"
|
||||
#include "data.h"
|
||||
#include "affinity.h"
|
||||
#include "bitmap.h"
|
||||
@ -72,7 +73,6 @@
|
||||
#include "version.h"
|
||||
#include "benchmark.h"
|
||||
#include "outfile_check.h"
|
||||
#include "loopback.h"
|
||||
#include "weak_hash.h"
|
||||
#include "hash_management.h"
|
||||
#include "remove.h"
|
||||
@ -110,51 +110,6 @@ const int comptime = COMPTIME;
|
||||
// outfile_check
|
||||
#define OUTFILE_CHECK_TIMER 5
|
||||
|
||||
// loopback
|
||||
#define LOOPBACK 0
|
||||
#define LOOPBACK_FILE "hashcat.loopback"
|
||||
typedef struct
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
} loopback_ctx_t;
|
||||
void loopback_format_plain (loopback_ctx_t *loopback_ctx, const unsigned char *plain_ptr, const uint plain_len)
|
||||
{
|
||||
int needs_hexify = 0;
|
||||
|
||||
for (uint i = 0; i < plain_len; i++)
|
||||
{
|
||||
if (plain_ptr[i] < 0x20)
|
||||
{
|
||||
needs_hexify = 1;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (plain_ptr[i] > 0x7f)
|
||||
{
|
||||
needs_hexify = 1;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (needs_hexify == 1)
|
||||
{
|
||||
fprintf (loopback_ctx->fp, "$HEX[");
|
||||
|
||||
for (uint i = 0; i < plain_len; i++)
|
||||
{
|
||||
fprintf (loopback_ctx->fp, "%02x", plain_ptr[i]);
|
||||
}
|
||||
|
||||
fprintf (loopback_ctx->fp, "]");
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite (plain_ptr, plain_len, 1, loopback_ctx->fp);
|
||||
}
|
||||
}
|
||||
|
||||
// weak_hash
|
||||
#define WEAK_HASH_THRESHOLD 100
|
||||
@ -479,7 +434,6 @@ static void check_checkpoint ()
|
||||
static void check_hash (hc_device_param_t *device_param, plain_t *plain)
|
||||
{
|
||||
uint quiet = data.quiet;
|
||||
uint loopback = data.loopback;
|
||||
uint debug_mode = data.debug_mode;
|
||||
char *debug_file = data.debug_file;
|
||||
|
||||
@ -742,24 +696,13 @@ static void check_hash (hc_device_param_t *device_param, plain_t *plain)
|
||||
}
|
||||
}
|
||||
|
||||
// loopback
|
||||
// if enabled, update also the loopback file
|
||||
|
||||
if (loopback)
|
||||
loopback_ctx_t *loopback_ctx = data.loopback_ctx;
|
||||
|
||||
if (loopback_ctx->fp)
|
||||
{
|
||||
char *loopback_file = data.loopback_file;
|
||||
|
||||
loopback_ctx_t loopback_ctx;
|
||||
|
||||
loopback_ctx.fp = fopen (loopback_file, "ab");
|
||||
|
||||
if (loopback_ctx.fp != NULL)
|
||||
{
|
||||
loopback_format_plain (&loopback_ctx, plain_ptr, plain_len);
|
||||
|
||||
fputc ('\n', loopback_ctx.fp);
|
||||
|
||||
fclose (loopback_ctx.fp);
|
||||
}
|
||||
loopback_write_append (loopback_ctx, plain_ptr, plain_len);
|
||||
}
|
||||
|
||||
// (rule) debug mode
|
||||
@ -5111,14 +5054,6 @@ int main (int argc, char **argv)
|
||||
|
||||
data.induction_directory = induction_directory;
|
||||
|
||||
/**
|
||||
* loopback
|
||||
*/
|
||||
|
||||
size_t loopback_size = strlen (session_dir) + 1 + session_size + strlen (LOOPBACK_FILE) + 12;
|
||||
|
||||
char *loopback_file = (char *) mymalloc (loopback_size);
|
||||
|
||||
/**
|
||||
* tuning db
|
||||
*/
|
||||
@ -5600,6 +5535,16 @@ int main (int argc, char **argv)
|
||||
SUPPRESS_OUTPUT = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* loopback
|
||||
*/
|
||||
|
||||
loopback_ctx_t *loopback_ctx = mymalloc (sizeof (loopback_ctx_t));
|
||||
|
||||
data.loopback_ctx = loopback_ctx;
|
||||
|
||||
loopback_init (loopback_ctx);
|
||||
|
||||
/**
|
||||
* word len
|
||||
*/
|
||||
@ -12226,23 +12171,6 @@ int main (int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Update loopback file
|
||||
*/
|
||||
|
||||
if (loopback == 1)
|
||||
{
|
||||
time_t now;
|
||||
|
||||
time (&now);
|
||||
|
||||
uint random_num = get_random_num (0, 9999);
|
||||
|
||||
snprintf (loopback_file, loopback_size - 1, "%s/%s.%d_%i", induction_directory, LOOPBACK_FILE, (int) now, random_num);
|
||||
|
||||
data.loopback_file = loopback_file;
|
||||
}
|
||||
|
||||
/*
|
||||
* Update dictionary statistic
|
||||
*/
|
||||
@ -12252,6 +12180,15 @@ int main (int argc, char **argv)
|
||||
dictstat_write (dictstat_ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update loopback file
|
||||
*/
|
||||
|
||||
if (loopback == 1)
|
||||
{
|
||||
loopback_write_open (loopback_ctx, induction_directory);
|
||||
}
|
||||
|
||||
/**
|
||||
* create autotune threads
|
||||
*/
|
||||
@ -12430,6 +12367,15 @@ int main (int argc, char **argv)
|
||||
dictpos--;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update loopback file
|
||||
*/
|
||||
|
||||
if (loopback == 1)
|
||||
{
|
||||
loopback_write_close (loopback_ctx);
|
||||
}
|
||||
|
||||
time_t runtime_stop;
|
||||
|
||||
time (&runtime_stop);
|
||||
@ -12835,6 +12781,8 @@ int main (int argc, char **argv)
|
||||
|
||||
dictstat_destroy (dictstat_ctx);
|
||||
|
||||
loopback_destroy (loopback_ctx);
|
||||
|
||||
local_free (all_kernel_rules_cnt);
|
||||
local_free (all_kernel_rules_buf);
|
||||
|
||||
@ -12910,12 +12858,6 @@ int main (int argc, char **argv)
|
||||
|
||||
tuning_db_destroy (tuning_db);
|
||||
|
||||
// loopback
|
||||
|
||||
local_free (loopback_file);
|
||||
|
||||
if (loopback == 1) unlink (loopback_file);
|
||||
|
||||
// induction directory
|
||||
|
||||
if (induction_dir == NULL)
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "restore.h"
|
||||
#include "outfile.h"
|
||||
#include "potfile.h"
|
||||
#include "loopback.h"
|
||||
#include "data.h"
|
||||
#include "hlfmt.h"
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "thread.h"
|
||||
#include "outfile.h"
|
||||
#include "potfile.h"
|
||||
#include "loopback.h"
|
||||
#include "data.h"
|
||||
|
||||
hc_thread_mutex_t mux_hwmon;
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "restore.h"
|
||||
#include "outfile.h"
|
||||
#include "potfile.h"
|
||||
#include "loopback.h"
|
||||
#include "data.h"
|
||||
#include "logfile.h"
|
||||
|
||||
|
101
src/loopback.c
101
src/loopback.c
@ -4,4 +4,105 @@
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "types_int.h"
|
||||
#include "memory.h"
|
||||
#include "logging.h"
|
||||
#include "shared.h"
|
||||
#include "loopback.h"
|
||||
|
||||
void loopback_init (loopback_ctx_t *loopback_ctx)
|
||||
{
|
||||
loopback_ctx->fp = NULL;
|
||||
|
||||
loopback_ctx->filename = (char *) mymalloc (HCBUFSIZ_TINY);
|
||||
}
|
||||
|
||||
void loopback_destroy (loopback_ctx_t *loopback_ctx)
|
||||
{
|
||||
myfree (loopback_ctx->filename);
|
||||
}
|
||||
|
||||
int loopback_write_open (loopback_ctx_t *loopback_ctx, const char *induction_directory)
|
||||
{
|
||||
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);
|
||||
|
||||
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->filename == NULL) return;
|
||||
|
||||
unlink (loopback_ctx->filename);
|
||||
}
|
||||
|
||||
void loopback_write_close (loopback_ctx_t *loopback_ctx)
|
||||
{
|
||||
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)
|
||||
{
|
||||
int needs_hexify = 0;
|
||||
|
||||
for (uint i = 0; i < plain_len; i++)
|
||||
{
|
||||
if (plain_ptr[i] < 0x20)
|
||||
{
|
||||
needs_hexify = 1;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (plain_ptr[i] > 0x7f)
|
||||
{
|
||||
needs_hexify = 1;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (needs_hexify == 1)
|
||||
{
|
||||
fprintf (loopback_ctx->fp, "$HEX[");
|
||||
|
||||
for (uint i = 0; i < plain_len; i++)
|
||||
{
|
||||
fprintf (loopback_ctx->fp, "%02x", plain_ptr[i]);
|
||||
}
|
||||
|
||||
fprintf (loopback_ctx->fp, "]");
|
||||
}
|
||||
else
|
||||
{
|
||||
fwrite (plain_ptr, plain_len, 1, loopback_ctx->fp);
|
||||
}
|
||||
}
|
||||
|
||||
void loopback_write_append (loopback_ctx_t *loopback_ctx, const u8 *plain_ptr, const unsigned int plain_len)
|
||||
{
|
||||
FILE *fp = loopback_ctx->fp;
|
||||
|
||||
loopback_format_plain (loopback_ctx, plain_ptr, plain_len);
|
||||
|
||||
fputc ('\n', fp);
|
||||
|
||||
fflush (fp);
|
||||
}
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "restore.h"
|
||||
#include "outfile.h"
|
||||
#include "potfile.h"
|
||||
#include "loopback.h"
|
||||
#include "data.h"
|
||||
//#include "shared.h"
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "restore.h"
|
||||
#include "outfile.h"
|
||||
#include "potfile.h"
|
||||
#include "loopback.h"
|
||||
#include "data.h"
|
||||
|
||||
extern hc_global_data_t data;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "restore.h"
|
||||
#include "outfile.h"
|
||||
#include "potfile.h"
|
||||
#include "loopback.h"
|
||||
#include "data.h"
|
||||
|
||||
extern hc_global_data_t data;
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "restore.h"
|
||||
#include "outfile.h"
|
||||
#include "potfile.h"
|
||||
#include "loopback.h"
|
||||
#include "data.h"
|
||||
#include "shared.h"
|
||||
#include "rp_cpu.h"
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "interface.h"
|
||||
#include "outfile.h"
|
||||
#include "potfile.h"
|
||||
#include "loopback.h"
|
||||
#include "data.h"
|
||||
//#include "shared.h"
|
||||
#include "status.h"
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "restore.h"
|
||||
#include "outfile.h"
|
||||
#include "potfile.h"
|
||||
#include "loopback.h"
|
||||
#include "data.h"
|
||||
#include "stdout.h"
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "restore.h"
|
||||
#include "outfile.h"
|
||||
#include "potfile.h"
|
||||
#include "loopback.h"
|
||||
#include "status.h"
|
||||
#include "data.h"
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "restore.h"
|
||||
#include "outfile.h"
|
||||
#include "potfile.h"
|
||||
#include "loopback.h"
|
||||
#include "data.h"
|
||||
#include "wordlist.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user