This repository has been archived by the owner on Aug 30, 2022. It is now read-only.
forked from hashcat/hashcat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debugfile.c
150 lines (113 loc) · 3.67 KB
/
debugfile.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#include "common.h"
#include "types.h"
#include "event.h"
#include "shared.h"
#include "locking.h"
#include "debugfile.h"
static void debugfile_format_plain (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ptr, const u32 plain_len)
{
debugfile_ctx_t *debugfile_ctx = hashcat_ctx->debugfile_ctx;
if (debugfile_ctx->enabled == false) return;
int needs_hexify = 0;
for (u32 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)
{
hc_fprintf (&debugfile_ctx->fp, "$HEX[");
for (u32 i = 0; i < plain_len; i++)
{
hc_fprintf (&debugfile_ctx->fp, "%02x", plain_ptr[i]);
}
hc_fprintf (&debugfile_ctx->fp, "]");
}
else
{
hc_fwrite ((void *)plain_ptr, plain_len, 1, &debugfile_ctx->fp);
}
}
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)
{
debugfile_ctx_t *debugfile_ctx = hashcat_ctx->debugfile_ctx;
if (debugfile_ctx->enabled == false) return;
const u32 debug_mode = debugfile_ctx->mode;
if ((debug_mode == 2) || (debug_mode == 3) || (debug_mode == 4))
{
debugfile_format_plain (hashcat_ctx, orig_plain_ptr, orig_plain_len);
if ((debug_mode == 3) || (debug_mode == 4)) hc_fputc (':', &debugfile_ctx->fp);
}
hc_fwrite ((void *)rule_buf, rule_len, 1, &debugfile_ctx->fp);
if (debug_mode == 4)
{
hc_fputc (':', &debugfile_ctx->fp);
debugfile_format_plain (hashcat_ctx, mod_plain_ptr, mod_plain_len);
}
hc_fwrite (EOL, strlen (EOL), 1, &debugfile_ctx->fp);
}
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;
if (user_options->benchmark == true) return 0;
if (user_options->hash_info == true) return 0;
if (user_options->keyspace == true) return 0;
if (user_options->left == true) return 0;
if (user_options->backend_info == true) return 0;
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;
debugfile_ctx->enabled = true;
debugfile_ctx->mode = user_options->debug_mode;
debugfile_ctx->filename = user_options->debug_file;
if (debugfile_ctx->filename)
{
if (hc_fopen (&debugfile_ctx->fp, debugfile_ctx->filename, "ab") == false)
{
event_log_error (hashcat_ctx, "Could not open --debug-file file for writing.");
return -1;
}
if (hc_lockfile (&debugfile_ctx->fp) == -1)
{
hc_fclose (&debugfile_ctx->fp);
event_log_error (hashcat_ctx, "%s: %s", debugfile_ctx->filename, strerror (errno));
return -1;
}
}
else
{
debugfile_ctx->fp.is_gzip = false;
debugfile_ctx->fp.pfp = stdout;
debugfile_ctx->fp.fd = fileno (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)
{
hc_unlockfile (&debugfile_ctx->fp);
hc_fclose (&debugfile_ctx->fp);
}
memset (debugfile_ctx, 0, sizeof (debugfile_ctx_t));
}