2016-09-11 09:42:19 +00:00
|
|
|
/**
|
2016-09-11 20:20:15 +00:00
|
|
|
* Author......: See docs/credits.txt
|
2016-09-11 09:42:19 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
2016-09-16 15:01:18 +00:00
|
|
|
#include "types.h"
|
2016-10-08 21:55:05 +00:00
|
|
|
#include "event.h"
|
2017-07-06 08:35:25 +00:00
|
|
|
#include "shared.h"
|
2016-11-05 10:33:29 +00:00
|
|
|
#include "locking.h"
|
2019-03-31 15:39:00 +00:00
|
|
|
#include "debugfile.h"
|
2016-09-13 08:38:59 +00:00
|
|
|
|
2016-10-06 08:55:14 +00:00
|
|
|
static void debugfile_format_plain (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ptr, const u32 plain_len)
|
2016-09-13 08:38:59 +00:00
|
|
|
{
|
2016-10-06 08:55:14 +00:00
|
|
|
debugfile_ctx_t *debugfile_ctx = hashcat_ctx->debugfile_ctx;
|
2016-09-13 08:38:59 +00:00
|
|
|
|
2016-09-30 09:48:14 +00:00
|
|
|
if (debugfile_ctx->enabled == false) return;
|
|
|
|
|
2016-09-13 08:38:59 +00:00
|
|
|
int needs_hexify = 0;
|
|
|
|
|
2016-10-04 09:22:08 +00:00
|
|
|
for (u32 i = 0; i < plain_len; i++)
|
2016-09-13 08:38:59 +00:00
|
|
|
{
|
|
|
|
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[");
|
|
|
|
|
2016-10-04 09:22:08 +00:00
|
|
|
for (u32 i = 0; i < plain_len; i++)
|
2016-09-13 08:38:59 +00:00
|
|
|
{
|
|
|
|
fprintf (debugfile_ctx->fp, "%02x", plain_ptr[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf (debugfile_ctx->fp, "]");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-06 08:35:25 +00:00
|
|
|
hc_fwrite (plain_ptr, plain_len, 1, debugfile_ctx->fp);
|
2016-09-13 08:38:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-06 08:55:14 +00:00
|
|
|
void debugfile_write_append (hashcat_ctx_t *hashcat_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)
|
2016-09-13 08:38:59 +00:00
|
|
|
{
|
2016-10-06 08:55:14 +00:00
|
|
|
debugfile_ctx_t *debugfile_ctx = hashcat_ctx->debugfile_ctx;
|
|
|
|
|
2016-09-30 09:48:14 +00:00
|
|
|
if (debugfile_ctx->enabled == false) return;
|
|
|
|
|
2016-10-04 09:22:08 +00:00
|
|
|
const u32 debug_mode = debugfile_ctx->mode;
|
2016-09-13 08:38:59 +00:00
|
|
|
|
|
|
|
if ((debug_mode == 2) || (debug_mode == 3) || (debug_mode == 4))
|
|
|
|
{
|
2016-10-06 08:55:14 +00:00
|
|
|
debugfile_format_plain (hashcat_ctx, orig_plain_ptr, orig_plain_len);
|
2016-09-13 08:38:59 +00:00
|
|
|
|
|
|
|
if ((debug_mode == 3) || (debug_mode == 4)) fputc (':', debugfile_ctx->fp);
|
|
|
|
}
|
|
|
|
|
2017-07-06 08:35:25 +00:00
|
|
|
hc_fwrite (rule_buf, rule_len, 1, debugfile_ctx->fp);
|
2016-09-13 08:38:59 +00:00
|
|
|
|
|
|
|
if (debug_mode == 4)
|
|
|
|
{
|
|
|
|
fputc (':', debugfile_ctx->fp);
|
|
|
|
|
2016-10-06 08:55:14 +00:00
|
|
|
debugfile_format_plain (hashcat_ctx, mod_plain_ptr, mod_plain_len);
|
2016-09-13 08:38:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-06 08:35:25 +00:00
|
|
|
hc_fwrite (EOL, strlen (EOL), 1, debugfile_ctx->fp);
|
2016-09-13 08:38:59 +00:00
|
|
|
}
|
2016-10-06 08:55:14 +00:00
|
|
|
|
|
|
|
int debugfile_init (hashcat_ctx_t *hashcat_ctx)
|
|
|
|
{
|
|
|
|
debugfile_ctx_t *debugfile_ctx = hashcat_ctx->debugfile_ctx;
|
|
|
|
user_options_t *user_options = hashcat_ctx->user_options;
|
|
|
|
|
|
|
|
debugfile_ctx->enabled = false;
|
|
|
|
|
2017-08-22 09:09:46 +00:00
|
|
|
if (user_options->benchmark == true) return 0;
|
|
|
|
if (user_options->example_hashes == true) return 0;
|
|
|
|
if (user_options->keyspace == true) return 0;
|
|
|
|
if (user_options->left == true) return 0;
|
2019-05-01 13:52:56 +00:00
|
|
|
if (user_options->backend_info == true) return 0;
|
2017-08-22 09:09:46 +00:00
|
|
|
if (user_options->show == true) return 0;
|
|
|
|
if (user_options->stdout_flag == true) return 0;
|
|
|
|
if (user_options->speed_only == true) return 0;
|
|
|
|
if (user_options->progress_only == true) return 0;
|
|
|
|
if (user_options->usage == true) return 0;
|
|
|
|
if (user_options->version == true) return 0;
|
|
|
|
if (user_options->debug_mode == 0) return 0;
|
2016-10-06 08:55:14 +00:00
|
|
|
|
|
|
|
debugfile_ctx->enabled = true;
|
|
|
|
|
|
|
|
debugfile_ctx->mode = user_options->debug_mode;
|
|
|
|
|
2016-10-30 11:36:21 +00:00
|
|
|
debugfile_ctx->filename = user_options->debug_file;
|
|
|
|
|
2016-10-06 08:55:14 +00:00
|
|
|
if (debugfile_ctx->filename)
|
|
|
|
{
|
2016-11-20 22:15:54 +00:00
|
|
|
FILE *fp = fopen (debugfile_ctx->filename, "ab");
|
2016-10-06 08:55:14 +00:00
|
|
|
|
2016-11-20 22:15:54 +00:00
|
|
|
if (fp == NULL)
|
2016-10-06 08:55:14 +00:00
|
|
|
{
|
2017-04-02 07:50:06 +00:00
|
|
|
event_log_error (hashcat_ctx, "Could not open --debug-file file for writing.");
|
2016-10-06 08:55:14 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-11-05 10:33:29 +00:00
|
|
|
|
2016-11-20 22:15:54 +00:00
|
|
|
if (lock_file (fp) == -1)
|
2016-11-05 10:33:29 +00:00
|
|
|
{
|
2016-11-20 22:15:54 +00:00
|
|
|
fclose (fp);
|
|
|
|
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", debugfile_ctx->filename, strerror (errno));
|
2016-11-05 10:33:29 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-11-20 22:15:54 +00:00
|
|
|
|
|
|
|
debugfile_ctx->fp = fp;
|
2016-10-06 08:55:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debugfile_ctx->fp = stdout;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void debugfile_destroy (hashcat_ctx_t *hashcat_ctx)
|
|
|
|
{
|
|
|
|
debugfile_ctx_t *debugfile_ctx = hashcat_ctx->debugfile_ctx;
|
|
|
|
|
|
|
|
if (debugfile_ctx->enabled == false) return;
|
|
|
|
|
|
|
|
if (debugfile_ctx->filename)
|
|
|
|
{
|
|
|
|
fclose (debugfile_ctx->fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset (debugfile_ctx, 0, sizeof (debugfile_ctx_t));
|
|
|
|
}
|