Add some additional start-up checks

pull/533/head
jsteube 8 years ago
parent 3a563ce2e9
commit 52068e25d5

@ -19,7 +19,7 @@
int sort_by_dictstat (const void *s1, const void *s2);
void dictstat_init (hashcat_ctx_t *hashcat_ctx);
int dictstat_init (hashcat_ctx_t *hashcat_ctx);
void dictstat_destroy (hashcat_ctx_t *hashcat_ctx);
void dictstat_read (hashcat_ctx_t *hashcat_ctx);
int dictstat_write (hashcat_ctx_t *hashcat_ctx);

@ -10,6 +10,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
#include <errno.h>
// logfile_append() checks for logfile_disable internally to make it easier from here
@ -36,7 +37,7 @@
void logfile_generate_topid (hashcat_ctx_t *hashcat_ctx);
void logfile_generate_subid (hashcat_ctx_t *hashcat_ctx);
void logfile_append (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...);
void logfile_init (hashcat_ctx_t *hashcat_ctx);
int logfile_init (hashcat_ctx_t *hashcat_ctx);
void logfile_destroy (hashcat_ctx_t *hashcat_ctx);
#endif // _LOGFILE_H

@ -13,7 +13,7 @@
static const char LOOPBACK_FILE[] = "hashcat.loopback";
void loopback_init (hashcat_ctx_t *hashcat_ctx);
int loopback_init (hashcat_ctx_t *hashcat_ctx);
void loopback_destroy (hashcat_ctx_t *hashcat_ctx);
int loopback_write_open (hashcat_ctx_t *hashcat_ctx);
void loopback_write_close (hashcat_ctx_t *hashcat_ctx);

@ -14,9 +14,9 @@ void build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_para
void build_crackpos (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u64 *out_pos);
void build_debugdata (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u8 *debug_rule_buf, int *debug_rule_len, u8 *debug_plain_ptr, int *debug_plain_len);
void outfile_init (hashcat_ctx_t *hashcat_ctx);
int outfile_init (hashcat_ctx_t *hashcat_ctx);
void outfile_destroy (hashcat_ctx_t *hashcat_ctx);
void outfile_write_open (hashcat_ctx_t *hashcat_ctx);
int outfile_write_open (hashcat_ctx_t *hashcat_ctx);
void outfile_write_close (hashcat_ctx_t *hashcat_ctx);
void outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const unsigned char *plain_ptr, const u32 plain_len, const u64 crackpos, const unsigned char *username, const u32 user_len);
int outfile_and_hashfile (hashcat_ctx_t *hashcat_ctx);

@ -20,7 +20,7 @@ int sort_by_hash_t_salt_hccap (const void *v1, const void *v2);
void hc_qsort_r (void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg);
void *hc_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg);
void potfile_init (hashcat_ctx_t *hashcat_ctx);
int potfile_init (hashcat_ctx_t *hashcat_ctx);
int potfile_read_open (hashcat_ctx_t *hashcat_ctx);
void potfile_read_parse (hashcat_ctx_t *hashcat_ctx);
void potfile_read_close (hashcat_ctx_t *hashcat_ctx);

@ -23,7 +23,7 @@ int sort_by_dictstat (const void *s1, const void *s2)
return memcmp (&d1->stat, &d2->stat, sizeof (struct stat));
}
void dictstat_init (hashcat_ctx_t *hashcat_ctx)
int dictstat_init (hashcat_ctx_t *hashcat_ctx)
{
dictstat_ctx_t *dictstat_ctx = hashcat_ctx->dictstat_ctx;
folder_config_t *folder_config = hashcat_ctx->folder_config;
@ -31,23 +31,35 @@ void dictstat_init (hashcat_ctx_t *hashcat_ctx)
dictstat_ctx->enabled = false;
if (user_options->benchmark == true) return;
if (user_options->keyspace == true) return;
if (user_options->left == true) return;
if (user_options->opencl_info == true) return;
if (user_options->show == true) return;
if (user_options->usage == true) return;
if (user_options->version == true) return;
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->usage == true) return 0;
if (user_options->version == true) return 0;
if (user_options->attack_mode == ATTACK_MODE_BF) return;
if (user_options->attack_mode == ATTACK_MODE_BF) return 0;
dictstat_ctx->enabled = true;
dictstat_ctx->filename = (char *) mymalloc (HCBUFSIZ_TINY);
dictstat_ctx->base = (dictstat_t *) mycalloc (MAX_DICTSTAT, sizeof (dictstat_t));
dictstat_ctx->cnt = 0;
snprintf (dictstat_ctx->filename, HCBUFSIZ_TINY - 1, "%s/hashcat.dictstat", folder_config->profile_dir);
FILE *fp = fopen (dictstat_ctx->filename, "wb");
if (fp == NULL)
{
log_error ("ERROR: %s: %s", dictstat_ctx->filename, strerror (errno));
return -1;
}
fclose (fp);
return 0;
}
void dictstat_destroy (hashcat_ctx_t *hashcat_ctx)

@ -1252,7 +1252,9 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
* folder
*/
folder_config_init (hashcat_ctx, install_folder, shared_folder);
const int rc_folder_config_init = folder_config_init (hashcat_ctx, install_folder, shared_folder);
if (rc_folder_config_init == -1) return -1;
/**
* restore
@ -1280,7 +1282,9 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
* logfile init
*/
logfile_init (hashcat_ctx);
const int rc_logfile_init = logfile_init (hashcat_ctx);
if (rc_logfile_init == -1) return -1;
logfile_generate_topid (hashcat_ctx);
@ -1316,7 +1320,9 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
* outfile itself
*/
outfile_init (hashcat_ctx);
const int rc_outfile_init = outfile_init (hashcat_ctx);
if (rc_outfile_init == -1) return -1;
/**
* Sanity check for hashfile vs outfile (should not point to the same physical file)
@ -1332,13 +1338,16 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
* plus it depends on hash_mode, so we continue using it in outer_loop
*/
potfile_init (hashcat_ctx);
const int rc_potfile_init = potfile_init (hashcat_ctx);
if (rc_potfile_init == -1) return -1;
/**
* dictstat init
*/
dictstat_init (hashcat_ctx);
const int rc_dictstat_init = dictstat_init (hashcat_ctx);
if (rc_dictstat_init == -1) return -1;
dictstat_read (hashcat_ctx);
@ -1346,13 +1355,17 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
* loopback init
*/
loopback_init (hashcat_ctx);
const int rc_loopback_init = loopback_init (hashcat_ctx);
if (rc_loopback_init == -1) return -1;
/**
* debugfile init
*/
debugfile_init (hashcat_ctx);
const int rc_debugfile_init = debugfile_init (hashcat_ctx);
if (rc_debugfile_init == -1) return -1;
/**
* cpu affinity
@ -1369,12 +1382,7 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
const int rc_opencl_init = opencl_ctx_init (hashcat_ctx);
if (rc_opencl_init == -1)
{
log_error ("ERROR: opencl_ctx_init() failed");
return -1;
}
if (rc_opencl_init == -1) return -1;
/**
* Init OpenCL devices
@ -1382,25 +1390,14 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold
const int rc_devices_init = opencl_ctx_devices_init (hashcat_ctx, comptime);
if (rc_devices_init == -1)
{
log_error ("ERROR: opencl_ctx_devices_init() failed");
return -1;
}
if (rc_devices_init == -1) return -1;
/**
* HM devices: init
*/
const int rc_hwmon_init = hwmon_ctx_init (hashcat_ctx);
if (rc_hwmon_init == -1)
{
log_error ("ERROR: hwmon_ctx_init() failed");
return -1;
}
if (rc_hwmon_init == -1) return -1;
/**
* keypress thread

@ -1041,15 +1041,18 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
hashes->hashes_cnt = hashes_cnt;
if (user_options->quiet == false) log_info_nn ("Sorting Hashes...");
if (hashconfig->is_salted)
{
hc_qsort_r (hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash, (void *) hashconfig);
}
else
if (hashes_cnt)
{
hc_qsort_r (hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash_no_salt, (void *) hashconfig);
if (user_options->quiet == false) log_info_nn ("Sorting Hashes...");
if (hashconfig->is_salted)
{
hc_qsort_r (hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash, (void *) hashconfig);
}
else
{
hc_qsort_r (hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash_no_salt, (void *) hashconfig);
}
}
return 0;

@ -10,6 +10,7 @@
#include "common.h"
#include "types.h"
#include "memory.h"
#include "logging.h"
#include "logfile.h"
static int logfile_generate_id ()
@ -68,13 +69,13 @@ void logfile_append (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
fclose (fp);
}
void logfile_init (hashcat_ctx_t *hashcat_ctx)
int logfile_init (hashcat_ctx_t *hashcat_ctx)
{
folder_config_t *folder_config = hashcat_ctx->folder_config;
logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx;
user_options_t *user_options = hashcat_ctx->user_options;
if (user_options->logfile_disable == true) return;
if (user_options->logfile_disable == true) return 0;
logfile_ctx->logfile = (char *) mymalloc (HCBUFSIZ_TINY);
@ -84,6 +85,19 @@ void logfile_init (hashcat_ctx_t *hashcat_ctx)
logfile_ctx->topid = (char *) mymalloc (HCBUFSIZ_TINY);
logfile_ctx->enabled = true;
FILE *fp = fopen (logfile_ctx->logfile, "wb");
if (fp == NULL)
{
log_error ("ERROR: %s: %s", logfile_ctx->logfile, strerror (errno));
return -1;
}
fclose (fp);
return 0;
}
void logfile_destroy (hashcat_ctx_t *hashcat_ctx)

@ -52,27 +52,27 @@ static void loopback_format_plain (hashcat_ctx_t *hashcat_ctx, const u8 *plain_p
}
}
void loopback_init (hashcat_ctx_t *hashcat_ctx)
int loopback_init (hashcat_ctx_t *hashcat_ctx)
{
loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
user_options_t *user_options = hashcat_ctx->user_options;
loopback_ctx->enabled = false;
if (user_options->benchmark == true) return;
if (user_options->keyspace == true) return;
if (user_options->left == true) return;
if (user_options->opencl_info == 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;
loopback_ctx->enabled = true;
loopback_ctx->fp = NULL;
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;
loopback_ctx->enabled = true;
loopback_ctx->fp = NULL;
loopback_ctx->filename = (char *) mymalloc (HCBUFSIZ_TINY);
return 0;
}
void loopback_destroy (hashcat_ctx_t *hashcat_ctx)

@ -299,7 +299,7 @@ static void outfile_format_plain (hashcat_ctx_t *hashcat_ctx, const unsigned cha
}
}
void outfile_init (hashcat_ctx_t *hashcat_ctx)
int outfile_init (hashcat_ctx_t *hashcat_ctx)
{
outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx;
user_options_t *user_options = hashcat_ctx->user_options;
@ -317,6 +317,12 @@ void outfile_init (hashcat_ctx_t *hashcat_ctx)
outfile_ctx->outfile_format = user_options->outfile_format;
outfile_ctx->outfile_autohex = user_options->outfile_autohex;
const int rc = outfile_write_open (hashcat_ctx);
if (rc == -1) return -1;
return 0;
}
void outfile_destroy (hashcat_ctx_t *hashcat_ctx)
@ -326,11 +332,11 @@ void outfile_destroy (hashcat_ctx_t *hashcat_ctx)
memset (outfile_ctx, 0, sizeof (outfile_ctx_t));
}
void outfile_write_open (hashcat_ctx_t *hashcat_ctx)
int outfile_write_open (hashcat_ctx_t *hashcat_ctx)
{
outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx;
if (outfile_ctx->filename == NULL) return;
if (outfile_ctx->filename == NULL) return 0;
outfile_ctx->fp = fopen (outfile_ctx->filename, "ab");
@ -338,9 +344,10 @@ void outfile_write_open (hashcat_ctx_t *hashcat_ctx)
{
log_error ("ERROR: %s: %s", outfile_ctx->filename, strerror (errno));
outfile_ctx->fp = stdout;
outfile_ctx->filename = NULL;
return -1;
}
return 0;
}
void outfile_write_close (hashcat_ctx_t *hashcat_ctx)

@ -188,7 +188,7 @@ static void potfile_format_plain (hashcat_ctx_t *hashcat_ctx, const unsigned cha
}
}
void potfile_init (hashcat_ctx_t *hashcat_ctx)
int potfile_init (hashcat_ctx_t *hashcat_ctx)
{
folder_config_t *folder_config = hashcat_ctx->folder_config;
potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
@ -196,13 +196,13 @@ void potfile_init (hashcat_ctx_t *hashcat_ctx)
potfile_ctx->enabled = false;
if (user_options->benchmark == true) return;
if (user_options->keyspace == true) return;
if (user_options->opencl_info == true) return;
if (user_options->stdout_flag == true) return;
if (user_options->usage == true) return;
if (user_options->version == true) return;
if (user_options->potfile_disable == true) return;
if (user_options->benchmark == true) return 0;
if (user_options->keyspace == true) return 0;
if (user_options->opencl_info == 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->potfile_disable == true) return 0;
potfile_ctx->enabled = true;
@ -219,10 +219,18 @@ void potfile_init (hashcat_ctx_t *hashcat_ctx)
potfile_ctx->fp = NULL;
}
const int rc = potfile_write_open (hashcat_ctx);
if (rc == -1) return -1;
potfile_write_close (hashcat_ctx);
potfile_ctx->pot = NULL;
potfile_ctx->pot_cnt = 0;
potfile_ctx->pot_avail = 0;
potfile_ctx->pot_hashes_avail = 0;
return 0;
}
void potfile_destroy (hashcat_ctx_t *hashcat_ctx)

Loading…
Cancel
Save