1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-22 08:08:10 +00:00

Update debugfile.c and hashes.c function parameters

This commit is contained in:
jsteube 2016-10-06 10:55:14 +02:00
parent 702c175f84
commit 684a28af36
6 changed files with 117 additions and 85 deletions

View File

@ -8,9 +8,8 @@
#include <stdio.h>
int debugfile_init (debugfile_ctx_t *debugfile_ctx, const user_options_t *user_options);
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);
int debugfile_init (hashcat_ctx_t *hashcat_ctx);
void debugfile_destroy (hashcat_ctx_t *hashcat_ctx);
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);
#endif // _DEBUGFILE_H

View File

@ -11,18 +11,18 @@ int sort_by_salt (const void *v1, const void *v2);
int sort_by_hash (const void *v1, const void *v2, void *v3);
int sort_by_hash_no_salt (const void *v1, const void *v2, void *v3);
void save_hash (const user_options_t *user_options, const hashconfig_t *hashconfig, const hashes_t *hashes);
void save_hash (hashcat_ctx_t *hashcat_ctx);
void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain);
int check_cracked (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 salt_pos);
int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfile_ctx_t *potfile_ctx, outfile_ctx_t *outfile_ctx, user_options_t *user_options, char *hash_or_file);
int hashes_init_stage2 (hashes_t *hashes, const hashconfig_t *hashconfig, user_options_t *user_options, status_ctx_t *status_ctx);
int hashes_init_stage3 (hashes_t *hashes, hashconfig_t *hashconfig, user_options_t *user_options);
int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx);
int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx);
int hashes_init_stage3 (hashcat_ctx_t *hashcat_ctx);
void hashes_destroy (hashes_t *hashes);
void hashes_destroy (hashcat_ctx_t *hashcat_ctx);
void hashes_logger (const hashes_t *hashes, const logfile_ctx_t *logfile_ctx);
void hashes_logger (hashcat_ctx_t *hashcat_ctx);
#endif // _HASH_MANAGEMENT_H

View File

@ -9,59 +9,10 @@
#include "logging.h"
#include "debugfile.h"
int debugfile_init (debugfile_ctx_t *debugfile_ctx, const user_options_t *user_options)
static void debugfile_format_plain (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ptr, const u32 plain_len)
{
debugfile_ctx->enabled = false;
debugfile_ctx_t *debugfile_ctx = hashcat_ctx->debugfile_ctx;
if (user_options->benchmark == true) return 0;
if (user_options->keyspace == true) return 0;
if (user_options->left == true) return 0;
if (user_options->opencl_info == true) return 0;
if (user_options->show == true) return 0;
if (user_options->stdout_flag == 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;
if (debugfile_ctx->filename)
{
debugfile_ctx->filename = user_options->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;
}
}
else
{
debugfile_ctx->fp = stdout;
}
return 0;
}
void debugfile_destroy (debugfile_ctx_t *debugfile_ctx)
{
if (debugfile_ctx->enabled == false) return;
if (debugfile_ctx->filename)
{
fclose (debugfile_ctx->fp);
}
memset (debugfile_ctx, 0, sizeof (debugfile_ctx_t));
}
void debugfile_format_plain (debugfile_ctx_t *debugfile_ctx, const u8 *plain_ptr, const u32 plain_len)
{
if (debugfile_ctx->enabled == false) return;
int needs_hexify = 0;
@ -100,15 +51,17 @@ void debugfile_format_plain (debugfile_ctx_t *debugfile_ctx, const u8 *plain_ptr
}
}
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)
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 (debugfile_ctx, orig_plain_ptr, orig_plain_len);
debugfile_format_plain (hashcat_ctx, orig_plain_ptr, orig_plain_len);
if ((debug_mode == 3) || (debug_mode == 4)) fputc (':', debugfile_ctx->fp);
}
@ -119,8 +72,64 @@ void debugfile_write_append (debugfile_ctx_t *debugfile_ctx, const u8 *rule_buf,
{
fputc (':', debugfile_ctx->fp);
debugfile_format_plain (debugfile_ctx, mod_plain_ptr, mod_plain_len);
debugfile_format_plain (hashcat_ctx, mod_plain_ptr, mod_plain_len);
}
fputc ('\n', 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->keyspace == true) return 0;
if (user_options->left == true) return 0;
if (user_options->opencl_info == true) return 0;
if (user_options->show == true) return 0;
if (user_options->stdout_flag == 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;
if (debugfile_ctx->filename)
{
debugfile_ctx->filename = user_options->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;
}
}
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));
}

View File

@ -763,7 +763,6 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
hashes_t *hashes = hashcat_ctx->hashes;
hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx;
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx;
outcheck_ctx_t *outcheck_ctx = hashcat_ctx->outcheck_ctx;
@ -818,7 +817,7 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
* load hashes, stage 1
*/
const int rc_hashes_init_stage1 = hashes_init_stage1 (hashes, hashconfig, potfile_ctx, outfile_ctx, user_options, user_options_extra->hc_hash);
const int rc_hashes_init_stage1 = hashes_init_stage1 (hashcat_ctx);
if (rc_hashes_init_stage1 == -1) return -1;
@ -864,7 +863,7 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
const u32 hashes_cnt_orig = hashes->hashes_cnt;
const int rc_hashes_init_stage2 = hashes_init_stage2 (hashes, hashconfig, user_options, status_ctx);
const int rc_hashes_init_stage2 = hashes_init_stage2 (hashcat_ctx);
if (rc_hashes_init_stage2 == -1) return -1;
@ -882,7 +881,7 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
log_info ("");
}
hashes_destroy (hashes);
hashes_destroy (hashcat_ctx);
hashconfig_destroy (hashconfig);
@ -895,11 +894,11 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
* load hashes, stage 3, automatic Optimizers
*/
const int rc_hashes_init_stage3 = hashes_init_stage3 (hashes, hashconfig, user_options);
const int rc_hashes_init_stage3 = hashes_init_stage3 (hashcat_ctx);
if (rc_hashes_init_stage3 == -1) return -1;
hashes_logger (hashes, logfile_ctx);
hashes_logger (hashcat_ctx);
/**
* bitmaps
@ -1224,7 +1223,7 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx)
straight_ctx_destroy (hashcat_ctx);
hashes_destroy (hashes);
hashes_destroy (hashcat_ctx);
hashconfig_destroy (hashconfig);
@ -1249,7 +1248,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
* main init
*/
debugfile_ctx_t *debugfile_ctx = hashcat_ctx->debugfile_ctx;
dictstat_ctx_t *dictstat_ctx = hashcat_ctx->dictstat_ctx;
folder_config_t *folder_config = hashcat_ctx->folder_config;
hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx;
@ -1378,7 +1376,7 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
* debugfile init
*/
debugfile_init (debugfile_ctx, user_options);
debugfile_init (hashcat_ctx);
/**
* cpu affinity
@ -1509,7 +1507,7 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
// free memory
debugfile_destroy (debugfile_ctx);
debugfile_destroy (hashcat_ctx);
tuning_db_destroy (tuning_db);

View File

@ -117,8 +117,12 @@ int sort_by_hash_no_salt (const void *v1, const void *v2, void *v3)
return sort_by_digest_p0p1 (d1, d2, v3);
}
void save_hash (const user_options_t *user_options, const hashconfig_t *hashconfig, const hashes_t *hashes)
void save_hash (hashcat_ctx_t *hashcat_ctx)
{
hashes_t *hashes = hashcat_ctx->hashes;
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
user_options_t *user_options = hashcat_ctx->user_options;
char *hashfile = hashes->hashfile;
char new_hashfile[256] = { 0 };
@ -299,7 +303,7 @@ void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, pl
if ((debug_plain_len > 0) || (debug_rule_len > 0))
{
debugfile_write_append (debugfile_ctx, debug_rule_buf, debug_rule_len, debug_plain_ptr, debug_plain_len, plain_ptr, plain_len);
debugfile_write_append (hashcat_ctx, debug_rule_buf, debug_rule_len, debug_plain_ptr, debug_plain_len, plain_ptr, plain_len);
}
}
}
@ -430,8 +434,17 @@ int check_cracked (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param,
return 0;
}
int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfile_ctx_t *potfile_ctx, outfile_ctx_t *outfile_ctx, user_options_t *user_options, char *hash_or_file)
int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
{
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
hashes_t *hashes = hashcat_ctx->hashes;
outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx;
potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
user_options_t *user_options = hashcat_ctx->user_options;
user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
char *hash_or_file = user_options_extra->hc_hash;
/**
* load hashes, part I: find input mode, count hashes
*/
@ -1045,10 +1058,15 @@ int hashes_init_stage1 (hashes_t *hashes, const hashconfig_t *hashconfig, potfil
return 0;
}
int hashes_init_stage2 (hashes_t *hashes, const hashconfig_t *hashconfig, user_options_t *user_options, status_ctx_t *status_ctx)
int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx)
{
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
hashes_t *hashes = hashcat_ctx->hashes;
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
user_options_t *user_options = hashcat_ctx->user_options;
hash_t *hashes_buf = hashes->hashes_buf;
u32 hashes_cnt = hashes->hashes_cnt;
u32 hashes_cnt = hashes->hashes_cnt;
/**
* Remove duplicates
@ -1259,8 +1277,12 @@ int hashes_init_stage2 (hashes_t *hashes, const hashconfig_t *hashconfig, user_o
return 0;
}
int hashes_init_stage3 (hashes_t *hashes, hashconfig_t *hashconfig, user_options_t *user_options)
int hashes_init_stage3 (hashcat_ctx_t *hashcat_ctx)
{
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
hashes_t *hashes = hashcat_ctx->hashes;
user_options_t *user_options = hashcat_ctx->user_options;
hashconfig_general_defaults (hashconfig, hashes, user_options);
if (hashes->salts_cnt == 1)
@ -1305,8 +1327,10 @@ int hashes_init_stage3 (hashes_t *hashes, hashconfig_t *hashconfig, user_options
return 0;
}
void hashes_destroy (hashes_t *hashes)
void hashes_destroy (hashcat_ctx_t *hashcat_ctx)
{
hashes_t *hashes = hashcat_ctx->hashes;
myfree (hashes->digests_buf);
myfree (hashes->digests_shown);
myfree (hashes->digests_shown_tmp);
@ -1321,8 +1345,11 @@ void hashes_destroy (hashes_t *hashes)
memset (hashes, 0, sizeof (hashes_t));
}
void hashes_logger (const hashes_t *hashes, const logfile_ctx_t *logfile_ctx)
void hashes_logger (hashcat_ctx_t *hashcat_ctx)
{
hashes_t *hashes = hashcat_ctx->hashes;
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
logfile_top_string (hashes->hashfile);
logfile_top_uint (hashes->hashlist_mode);
logfile_top_uint (hashes->hashlist_format);

View File

@ -19,7 +19,6 @@
static void monitor (hashcat_ctx_t *hashcat_ctx)
{
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
hashes_t *hashes = hashcat_ctx->hashes;
hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx;
opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx;
@ -304,7 +303,7 @@ static void monitor (hashcat_ctx_t *hashcat_ctx)
{
hashes->digests_saved = hashes->digests_done;
save_hash (user_options, hashconfig, hashes);
save_hash (hashcat_ctx);
}
remove_left = user_options->remove_timer;
@ -340,7 +339,7 @@ static void monitor (hashcat_ctx_t *hashcat_ctx)
{
if (hashes->digests_saved != hashes->digests_done)
{
save_hash (user_options, hashconfig, hashes);
save_hash (hashcat_ctx);
}
}