1
mirror of https://github.com/hashcat/hashcat synced 2024-11-13 17:28:58 +01:00

Make bitmaps, cracks-per-time and debugfile support modular

This commit is contained in:
jsteube 2016-09-30 11:48:14 +02:00
parent 0d8b179d40
commit 8034fb31b8
9 changed files with 84 additions and 18 deletions

View File

@ -10,7 +10,7 @@
#include <errno.h>
#include <time.h>
int cpt_ctx_init (cpt_ctx_t *cpt_ctx);
int cpt_ctx_init (cpt_ctx_t *cpt_ctx, const user_options_t *user_options);
void cpt_ctx_destroy (cpt_ctx_t *cpt_ctx);
void cpt_ctx_reset (cpt_ctx_t *cpt_ctx);

View File

@ -8,7 +8,7 @@
#include <stdio.h>
int debugfile_init (debugfile_ctx_t *debugfile_ctx, const uint debug_mode, const char *debug_file);
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);

View File

@ -800,6 +800,8 @@ typedef aes_context_t aes_ctx;
typedef struct
{
bool enabled;
FILE *fp;
char *filename;
u32 mode;
@ -1128,6 +1130,8 @@ typedef struct
typedef struct
{
bool enabled;
u32 bitmap_bits;
u32 bitmap_nums;
u32 bitmap_size;
@ -1255,6 +1259,8 @@ typedef struct
typedef struct
{
bool enabled;
cpt_t *cpt_buf;
int cpt_pos;
time_t cpt_start;

View File

@ -60,6 +60,17 @@ static u32 generate_bitmaps (const u32 digests_cnt, const u32 dgst_size, const u
void bitmap_ctx_init (bitmap_ctx_t *bitmap_ctx, const user_options_t *user_options, const hashconfig_t *hashconfig, const hashes_t *hashes)
{
bitmap_ctx->enabled = false;
if (user_options->keyspace == true) return;
if (user_options->left == true) return;
if (user_options->show == true) return;
if (user_options->stdout_flag == true) return;
if (user_options->usage == true) return;
if (user_options->version == true) return;
bitmap_ctx->enabled = true;
/**
* generate bitmap tables
*/
@ -130,6 +141,8 @@ void bitmap_ctx_init (bitmap_ctx_t *bitmap_ctx, const user_options_t *user_optio
void bitmap_ctx_destroy (bitmap_ctx_t *bitmap_ctx)
{
if (bitmap_ctx->enabled == false) return;
bitmap_ctx->bitmap_size = 0;
bitmap_ctx->bitmap_mask = 0;
bitmap_ctx->bitmap_shift1 = 0;

View File

@ -12,10 +12,13 @@
int combinator_ctx_init (combinator_ctx_t *combinator_ctx, const user_options_t *user_options)
{
memset (combinator_ctx, 0, sizeof (combinator_ctx_t));
combinator_ctx->enabled = false;
if (user_options->left == true) return 0;
if (user_options->show == true) return 0;
if (user_options->usage == true) return 0;
if (user_options->version == true) return 0;
if ((user_options->attack_mode != ATTACK_MODE_COMBI)
&& (user_options->attack_mode != ATTACK_MODE_HYBRID1)
&& (user_options->attack_mode != ATTACK_MODE_HYBRID2)) return 0;

View File

@ -9,8 +9,19 @@
#include "logging.h"
#include "cpt.h"
int cpt_ctx_init (cpt_ctx_t *cpt_ctx)
int cpt_ctx_init (cpt_ctx_t *cpt_ctx, const user_options_t *user_options)
{
cpt_ctx->enabled = false;
if (user_options->keyspace == true) return 0;
if (user_options->left == 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;
cpt_ctx->enabled = true;
cpt_ctx->cpt_buf = (cpt_t *) mycalloc (CPT_BUF, sizeof (cpt_t));
cpt_ctx->cpt_total = 0;
@ -22,6 +33,8 @@ int cpt_ctx_init (cpt_ctx_t *cpt_ctx)
void cpt_ctx_destroy (cpt_ctx_t *cpt_ctx)
{
if (cpt_ctx->enabled == false) return;
myfree (cpt_ctx->cpt_buf);
myfree (cpt_ctx);
@ -29,6 +42,8 @@ void cpt_ctx_destroy (cpt_ctx_t *cpt_ctx)
void cpt_ctx_reset (cpt_ctx_t *cpt_ctx)
{
if (cpt_ctx->enabled == false) return;
memset (cpt_ctx->cpt_buf, 0, CPT_BUF * sizeof (cpt_t));
cpt_ctx->cpt_total = 0;

View File

@ -5,18 +5,30 @@
#include "common.h"
#include "types.h"
#include "memory.h"
#include "logging.h"
#include "debugfile.h"
int debugfile_init (debugfile_ctx_t *debugfile_ctx, const uint debug_mode, const char *debug_file)
int debugfile_init (debugfile_ctx_t *debugfile_ctx, const user_options_t *user_options)
{
if (debug_mode == 0) return 0;
debugfile_ctx->enabled = false;
if (debug_file == NULL) return 0;
if (user_options->benchmark == true) return 0;
if (user_options->keyspace == true) return 0;
if (user_options->left == 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->mode = debug_mode;
debugfile_ctx->enabled = true;
debugfile_ctx->filename = (char *) debug_file;
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");
@ -26,19 +38,30 @@ int debugfile_init (debugfile_ctx_t *debugfile_ctx, const uint debug_mode, const
return -1;
}
}
else
{
debugfile_ctx->fp = stdout;
}
return 0;
}
void debugfile_destroy (debugfile_ctx_t *debugfile_ctx)
{
if (debugfile_ctx->fp == NULL) return;
if (debugfile_ctx->enabled == false) return;
if (debugfile_ctx->filename == NULL) return;
fclose (debugfile_ctx->fp);
myfree (debugfile_ctx);
}
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;
for (uint i = 0; i < plain_len; i++)
@ -77,6 +100,8 @@ 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)
{
if (debugfile_ctx->enabled == false) return;
const uint debug_mode = debugfile_ctx->mode;
if ((debug_mode == 2) || (debug_mode == 3) || (debug_mode == 4))

View File

@ -1308,7 +1308,7 @@ static int outer_loop (status_ctx_t *status_ctx, user_options_t *user_options, u
data.cpt_ctx = cpt_ctx;
cpt_ctx_init (cpt_ctx);
cpt_ctx_init (cpt_ctx, user_options);
/**
* Wordlist allocate buffer
@ -1863,7 +1863,7 @@ int main (int argc, char **argv)
data.debugfile_ctx = debugfile_ctx;
debugfile_init (debugfile_ctx, user_options->debug_mode, user_options->debug_file);
debugfile_init (debugfile_ctx, user_options);
/**
* cpu affinity

View File

@ -801,6 +801,10 @@ int hwmon_ctx_init (hwmon_ctx_t *hwmon_ctx, const user_options_t *user_options,
hwmon_ctx->enabled = false;
if (user_options->gpu_temp_disable == true) return 0;
if (user_options->show == true) return 0;
if (user_options->left == true) return 0;
if (user_options->keyspace == true) return 0;
if (user_options->stdout_flag == true) return 0;
hwmon_ctx->hm_device = (hm_attrs_t *) mycalloc (DEVICES_MAX, sizeof (hm_attrs_t));