1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-26 01:50:10 +00:00

Move debugfile related stuff to debugfile.c

This commit is contained in:
jsteube 2016-09-13 10:38:59 +02:00
parent ac77ee56e3
commit 376e12efe6
16 changed files with 163 additions and 113 deletions

View File

@ -155,8 +155,7 @@ typedef struct
uint runtime;
uint remove;
uint remove_timer;
uint debug_mode;
char *debug_file;
uint hex_charset;
uint hex_salt;
uint hex_wordlist;
@ -176,9 +175,10 @@ typedef struct
hashconfig_t *hashconfig;
outfile_ctx_t *outfile_ctx;
potfile_ctx_t *potfile_ctx;
loopback_ctx_t *loopback_ctx;
outfile_ctx_t *outfile_ctx;
potfile_ctx_t *potfile_ctx;
loopback_ctx_t *loopback_ctx;
debugfile_ctx_t *debugfile_ctx;
#if defined (HAVE_HWMON)
uint gpu_temp_disable;

View File

@ -6,4 +6,21 @@
#ifndef _DEBUGFILE_H
#define _DEBUGFILE_H
#include <stdio.h>
#define DEBUG_MODE 0
typedef struct
{
FILE *fp;
char *filename;
uint mode;
} debugfile_ctx_t;
int debugfile_init (debugfile_ctx_t *debugfile_ctx, const uint debug_mode, const char *debug_file);
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);
#endif // _DEBUGFILE_H

View File

@ -20,6 +20,7 @@
#include "opencl.h"
#include "outfile.h"
#include "potfile.h"
#include "debugfile.h"
#include "loopback.h"
#include "data.h"

View File

@ -4,4 +4,94 @@
*/
#include "common.h"
#include "types_int.h"
#include "logging.h"
#include "debugfile.h"
int debugfile_init (debugfile_ctx_t *debugfile_ctx, const uint debug_mode, const char *debug_file)
{
if (debug_mode == 0) return 0;
if (debug_file == NULL) return 0;
debugfile_ctx->mode = debug_mode;
debugfile_ctx->filename = (char *) debug_file;
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;
}
return 0;
}
void debugfile_destroy (debugfile_ctx_t *debugfile_ctx)
{
fclose (debugfile_ctx->fp);
}
void debugfile_format_plain (debugfile_ctx_t *debugfile_ctx, const u8 *plain_ptr, const u32 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 (debugfile_ctx->fp, "$HEX[");
for (uint i = 0; i < plain_len; i++)
{
fprintf (debugfile_ctx->fp, "%02x", plain_ptr[i]);
}
fprintf (debugfile_ctx->fp, "]");
}
else
{
fwrite (plain_ptr, plain_len, 1, debugfile_ctx->fp);
}
}
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)
{
const uint debug_mode = debugfile_ctx->mode;
if ((debug_mode == 2) || (debug_mode == 3) || (debug_mode == 4))
{
debugfile_format_plain (debugfile_ctx, orig_plain_ptr, orig_plain_len);
if ((debug_mode == 3) || (debug_mode == 4)) fputc (':', debugfile_ctx->fp);
}
fwrite (rule_buf, rule_len, 1, debugfile_ctx->fp);
if (debug_mode == 4)
{
fputc (':', debugfile_ctx->fp);
debugfile_format_plain (debugfile_ctx, mod_plain_ptr, mod_plain_len);
}
fputc ('\n', debugfile_ctx->fp);
}

View File

@ -5,7 +5,7 @@
#if defined (__APPLE__)
#include <stdio.h>
#endif
#endif // __APPLE__
#include "common.h"
@ -59,6 +59,7 @@
#include "restore.h"
#include "outfile.h"
#include "potfile.h"
#include "debugfile.h"
#include "loopback.h"
#include "data.h"
#include "affinity.h"
@ -206,85 +207,6 @@ int sort_by_hash_no_salt (const void *v1, const void *v2)
#define REMOVE 0
#define REMOVE_TIMER 60
// debug_mode
#define DEBUG_MODE 0
typedef struct
{
FILE *fp;
} debug_ctx_t;
void debug_format_plain (debug_ctx_t *debug_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 (debug_ctx->fp, "$HEX[");
for (uint i = 0; i < plain_len; i++)
{
fprintf (debug_ctx->fp, "%02x", plain_ptr[i]);
}
fprintf (debug_ctx->fp, "]");
}
else
{
fwrite (plain_ptr, plain_len, 1, debug_ctx->fp);
}
}
void format_debug (char *debug_file, uint debug_mode, unsigned char *orig_plain_ptr, uint orig_plain_len, unsigned char *mod_plain_ptr, uint mod_plain_len, char *rule_buf, int rule_len)
{
unsigned char *rule_ptr = (unsigned char *) rule_buf;
debug_ctx_t debug_ctx;
debug_ctx.fp = fopen (debug_file, "ab");
if (debug_ctx.fp == NULL)
{
log_error ("ERROR: Could not open debug-file for writing");
return;
}
if ((debug_mode == 2) || (debug_mode == 3) || (debug_mode == 4))
{
debug_format_plain (&debug_ctx, orig_plain_ptr, orig_plain_len);
if ((debug_mode == 3) || (debug_mode == 4)) fputc (':', debug_ctx.fp);
}
fwrite (rule_ptr, rule_len, 1, debug_ctx.fp);
if (debug_mode == 4)
{
fputc (':', debug_ctx.fp);
debug_format_plain (&debug_ctx, mod_plain_ptr, mod_plain_len);
}
fputc ('\n', debug_ctx.fp);
fclose (debug_ctx.fp);
}
// runtime
#define RUNTIME 0
@ -433,15 +355,20 @@ static void check_checkpoint ()
static void check_hash (hc_device_param_t *device_param, plain_t *plain)
{
uint quiet = data.quiet;
uint debug_mode = data.debug_mode;
char *debug_file = data.debug_file;
debugfile_ctx_t *debugfile_ctx = data.debugfile_ctx;
loopback_ctx_t *loopback_ctx = data.loopback_ctx;
outfile_ctx_t *outfile_ctx = data.outfile_ctx;
potfile_ctx_t *potfile_ctx = data.potfile_ctx;
char debug_rule_buf[BLOCK_SIZE] = { 0 };
int debug_rule_len = 0; // -1 error
uint debug_plain_len = 0;
uint quiet = data.quiet;
u8 debug_plain_ptr[BLOCK_SIZE] = { 0 };
// debugfile
u8 debug_rule_buf[BLOCK_SIZE] = { 0 };
u32 debug_rule_len = 0; // -1 error
u8 debug_plain_ptr[BLOCK_SIZE] = { 0 };
u32 debug_plain_len = 0;
// hash
@ -486,6 +413,8 @@ static void check_hash (hc_device_param_t *device_param, plain_t *plain)
const uint off = device_param->innerloop_pos + il_pos;
const uint debug_mode = debugfile_ctx->mode;
if (debug_mode > 0)
{
debug_rule_len = 0;
@ -495,7 +424,7 @@ static void check_hash (hc_device_param_t *device_param, plain_t *plain)
{
memset (debug_rule_buf, 0, sizeof (debug_rule_buf));
debug_rule_len = kernel_rule_to_cpu_rule (debug_rule_buf, &data.kernel_rules_buf[off]);
debug_rule_len = kernel_rule_to_cpu_rule ((char *) debug_rule_buf, &data.kernel_rules_buf[off]);
}
// save plain
@ -667,9 +596,8 @@ static void check_hash (hc_device_param_t *device_param, plain_t *plain)
// if enabled, update also the potfile
// no need for locking, we're in a mutex protected function
potfile_ctx_t *potfile_ctx = data.potfile_ctx;
if (potfile_ctx->fp)
if (potfile_ctx->fp != NULL)
{
potfile_write_append (potfile_ctx, out_buf, plain_ptr, plain_len);
}
@ -678,7 +606,6 @@ static void check_hash (hc_device_param_t *device_param, plain_t *plain)
// if an error occurs opening the file, send to stdout as fallback
// the fp gets opened for each cracked hash so that the user can modify (move) the outfile while hashcat runs
outfile_ctx_t *outfile_ctx = data.outfile_ctx;
outfile_write_open (outfile_ctx);
@ -698,30 +625,23 @@ static void check_hash (hc_device_param_t *device_param, plain_t *plain)
// if enabled, update also the loopback file
loopback_ctx_t *loopback_ctx = data.loopback_ctx;
if (loopback_ctx->fp)
if (loopback_ctx->fp != NULL)
{
loopback_write_append (loopback_ctx, plain_ptr, plain_len);
}
// (rule) debug mode
// if enabled, update also the (rule) debug file
// the next check implies that:
// - (data.attack_mode == ATTACK_MODE_STRAIGHT)
// - debug_mode > 0
if ((debug_plain_len > 0) || (debug_rule_len > 0))
if (debugfile_ctx->fp != NULL)
{
if (debug_rule_len < 0) debug_rule_len = 0;
// the next check implies that:
// - (data.attack_mode == ATTACK_MODE_STRAIGHT)
// - debug_mode > 0
if ((quiet == 0) && (debug_file == NULL)) clear_prompt ();
format_debug (debug_file, debug_mode, debug_plain_ptr, debug_plain_len, plain_ptr, plain_len, debug_rule_buf, debug_rule_len);
if ((quiet == 0) && (debug_file == NULL))
if ((debug_plain_len > 0) || (debug_rule_len > 0))
{
send_prompt ();
debugfile_write_append (debugfile_ctx, debug_rule_buf, debug_rule_len, debug_plain_ptr, debug_plain_len, plain_ptr, plain_len);
}
}
}
@ -5145,8 +5065,7 @@ int main (int argc, char **argv)
data.runtime = runtime;
data.remove = remove;
data.remove_timer = remove_timer;
data.debug_mode = debug_mode;
data.debug_file = debug_file;
data.username = username;
data.quiet = quiet;
@ -5545,6 +5464,16 @@ int main (int argc, char **argv)
loopback_init (loopback_ctx);
/**
* debugfile
*/
debugfile_ctx_t *debugfile_ctx = mymalloc (sizeof (debugfile_ctx_t));
data.debugfile_ctx = debugfile_ctx;
debugfile_init (debugfile_ctx, debug_mode, debug_file);
/**
* word len
*/
@ -12773,6 +12702,8 @@ int main (int argc, char **argv)
local_free (masks);
debugfile_destroy (debugfile_ctx);
outfile_destroy (outfile_ctx);
potfile_write_close (potfile_ctx);

View File

@ -30,6 +30,7 @@
#include "restore.h"
#include "outfile.h"
#include "potfile.h"
#include "debugfile.h"
#include "loopback.h"
#include "data.h"
#include "hlfmt.h"

View File

@ -23,6 +23,7 @@
#include "thread.h"
#include "outfile.h"
#include "potfile.h"
#include "debugfile.h"
#include "loopback.h"
#include "data.h"

View File

@ -26,6 +26,7 @@
#include "restore.h"
#include "outfile.h"
#include "potfile.h"
#include "debugfile.h"
#include "loopback.h"
#include "data.h"
#include "logfile.h"

View File

@ -29,6 +29,7 @@
#include "restore.h"
#include "outfile.h"
#include "potfile.h"
#include "debugfile.h"
#include "loopback.h"
#include "data.h"
//#include "shared.h"

View File

@ -24,6 +24,7 @@
#include "restore.h"
#include "outfile.h"
#include "potfile.h"
#include "debugfile.h"
#include "loopback.h"
#include "data.h"

View File

@ -23,6 +23,7 @@
#include "restore.h"
#include "outfile.h"
#include "potfile.h"
#include "debugfile.h"
#include "loopback.h"
#include "data.h"

View File

@ -30,6 +30,7 @@
#include "restore.h"
#include "outfile.h"
#include "potfile.h"
#include "debugfile.h"
#include "loopback.h"
#include "data.h"
#include "shared.h"

View File

@ -25,6 +25,7 @@
#include "interface.h"
#include "outfile.h"
#include "potfile.h"
#include "debugfile.h"
#include "loopback.h"
#include "data.h"
//#include "shared.h"

View File

@ -29,6 +29,7 @@
#include "restore.h"
#include "outfile.h"
#include "potfile.h"
#include "debugfile.h"
#include "loopback.h"
#include "data.h"
#include "stdout.h"

View File

@ -22,6 +22,7 @@
#include "restore.h"
#include "outfile.h"
#include "potfile.h"
#include "debugfile.h"
#include "loopback.h"
#include "status.h"
#include "data.h"

View File

@ -30,6 +30,7 @@
#include "restore.h"
#include "outfile.h"
#include "potfile.h"
#include "debugfile.h"
#include "loopback.h"
#include "data.h"
#include "wordlist.h"