mirror of
https://github.com/hashcat/hashcat.git
synced 2024-11-22 16:18:09 +00:00
Move count_words() to wordlist.c
This commit is contained in:
parent
2678592484
commit
533a87b685
@ -6,6 +6,8 @@
|
||||
#ifndef _THREAD_H
|
||||
#define _THREAD_H
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#if defined (_POSIX)
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
@ -46,4 +48,21 @@ typedef pthread_mutex_t hc_thread_mutex_t;
|
||||
|
||||
#endif
|
||||
|
||||
#if defined (_WIN)
|
||||
|
||||
BOOL WINAPI sigHandler_default (DWORD sig);
|
||||
BOOL WINAPI sigHandler_benchmark (DWORD sig);
|
||||
void hc_signal (BOOL WINAPI (callback) (DWORD));
|
||||
|
||||
#else
|
||||
|
||||
void sigHandler_default (int sig);
|
||||
void sigHandler_benchmark (int sig);
|
||||
void hc_signal (void (callback) (int));
|
||||
|
||||
#endif
|
||||
|
||||
void myabort ();
|
||||
void myquit ();
|
||||
|
||||
#endif // _THREAD_H
|
||||
|
@ -31,4 +31,6 @@ void get_next_word (wl_data_t *wl_data, FILE *fd, char **out_buf, uint *out_len)
|
||||
|
||||
void pw_add (hc_device_param_t *device_param, const u8 *pw_buf, const int pw_len);
|
||||
|
||||
u64 count_words (wl_data_t *wl_data, FILE *fd, const char *dictfile, dictstat_ctx_t *dictstat_ctx);
|
||||
|
||||
#endif // _WORDLIST_H
|
||||
|
251
src/hashcat.c
251
src/hashcat.c
@ -67,8 +67,8 @@
|
||||
#include "hlfmt.h"
|
||||
#include "filenames.h"
|
||||
#include "stdout.h"
|
||||
#include "wordlist.h"
|
||||
#include "dictstat.h"
|
||||
#include "wordlist.h"
|
||||
#include "version.h"
|
||||
#include "benchmark.h"
|
||||
#include "outfile_check.h"
|
||||
@ -418,117 +418,7 @@ int sort_by_mtime (const void *p1, const void *p2)
|
||||
// thread
|
||||
static hc_thread_mutex_t mux_dispatcher;
|
||||
static hc_thread_mutex_t mux_counter;
|
||||
static void myabort ()
|
||||
{
|
||||
data.devices_status = STATUS_ABORTED;
|
||||
}
|
||||
static void myquit ()
|
||||
{
|
||||
data.devices_status = STATUS_QUIT;
|
||||
}
|
||||
|
||||
#if defined (_WIN)
|
||||
|
||||
static BOOL WINAPI sigHandler_default (DWORD sig)
|
||||
{
|
||||
switch (sig)
|
||||
{
|
||||
case CTRL_CLOSE_EVENT:
|
||||
|
||||
/*
|
||||
* special case see: https://stackoverflow.com/questions/3640633/c-setconsolectrlhandler-routine-issue/5610042#5610042
|
||||
* if the user interacts w/ the user-interface (GUI/cmd), we need to do the finalization job within this signal handler
|
||||
* function otherwise it is too late (e.g. after returning from this function)
|
||||
*/
|
||||
|
||||
myabort ();
|
||||
|
||||
SetConsoleCtrlHandler (NULL, TRUE);
|
||||
|
||||
hc_sleep (10);
|
||||
|
||||
return TRUE;
|
||||
|
||||
case CTRL_C_EVENT:
|
||||
case CTRL_LOGOFF_EVENT:
|
||||
case CTRL_SHUTDOWN_EVENT:
|
||||
|
||||
myabort ();
|
||||
|
||||
SetConsoleCtrlHandler (NULL, TRUE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOL WINAPI sigHandler_benchmark (DWORD sig)
|
||||
{
|
||||
switch (sig)
|
||||
{
|
||||
case CTRL_CLOSE_EVENT:
|
||||
|
||||
myquit ();
|
||||
|
||||
SetConsoleCtrlHandler (NULL, TRUE);
|
||||
|
||||
hc_sleep (10);
|
||||
|
||||
return TRUE;
|
||||
|
||||
case CTRL_C_EVENT:
|
||||
case CTRL_LOGOFF_EVENT:
|
||||
case CTRL_SHUTDOWN_EVENT:
|
||||
|
||||
myquit ();
|
||||
|
||||
SetConsoleCtrlHandler (NULL, TRUE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void hc_signal (BOOL WINAPI (callback) (DWORD))
|
||||
{
|
||||
if (callback == NULL)
|
||||
{
|
||||
SetConsoleCtrlHandler ((PHANDLER_ROUTINE) callback, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetConsoleCtrlHandler ((PHANDLER_ROUTINE) callback, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void sigHandler_default (int sig)
|
||||
{
|
||||
myabort ();
|
||||
|
||||
signal (sig, NULL);
|
||||
}
|
||||
|
||||
static void sigHandler_benchmark (int sig)
|
||||
{
|
||||
myquit ();
|
||||
|
||||
signal (sig, NULL);
|
||||
}
|
||||
|
||||
static void hc_signal (void (callback) (int))
|
||||
{
|
||||
if (callback == NULL) callback = SIG_DFL;
|
||||
|
||||
signal (SIGINT, callback);
|
||||
signal (SIGTERM, callback);
|
||||
signal (SIGABRT, callback);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// restore
|
||||
static void check_checkpoint ()
|
||||
@ -2474,145 +2364,6 @@ static int run_cracker (hc_device_param_t *device_param, hashconfig_t *hashconfi
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u64 count_words (wl_data_t *wl_data, FILE *fd, const char *dictfile, dictstat_ctx_t *dictstat_ctx)
|
||||
{
|
||||
hc_signal (NULL);
|
||||
|
||||
dictstat_t d;
|
||||
|
||||
d.cnt = 0;
|
||||
|
||||
#if defined (_POSIX)
|
||||
fstat (fileno (fd), &d.stat);
|
||||
#endif
|
||||
|
||||
#if defined (_WIN)
|
||||
_fstat64 (fileno (fd), &d.stat);
|
||||
#endif
|
||||
|
||||
d.stat.st_mode = 0;
|
||||
d.stat.st_nlink = 0;
|
||||
d.stat.st_uid = 0;
|
||||
d.stat.st_gid = 0;
|
||||
d.stat.st_rdev = 0;
|
||||
d.stat.st_atime = 0;
|
||||
|
||||
#if defined (_POSIX)
|
||||
d.stat.st_blksize = 0;
|
||||
d.stat.st_blocks = 0;
|
||||
#endif
|
||||
|
||||
if (d.stat.st_size == 0) return 0;
|
||||
|
||||
const u64 cached_cnt = dictstat_find (dictstat_ctx, &d);
|
||||
|
||||
if (run_rule_engine (data.rule_len_l, data.rule_buf_l) == 0)
|
||||
{
|
||||
if (cached_cnt)
|
||||
{
|
||||
u64 keyspace = cached_cnt;
|
||||
|
||||
if (data.attack_kern == ATTACK_KERN_STRAIGHT)
|
||||
{
|
||||
keyspace *= data.kernel_rules_cnt;
|
||||
}
|
||||
else if (data.attack_kern == ATTACK_KERN_COMBI)
|
||||
{
|
||||
keyspace *= data.combs_cnt;
|
||||
}
|
||||
|
||||
if (data.quiet == 0) log_info ("Cache-hit dictionary stats %s: %" PRIu64 " bytes, %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, d.stat.st_size, cached_cnt, keyspace);
|
||||
if (data.quiet == 0) log_info ("");
|
||||
|
||||
hc_signal (sigHandler_default);
|
||||
|
||||
return (keyspace);
|
||||
}
|
||||
}
|
||||
|
||||
time_t now = 0;
|
||||
time_t prev = 0;
|
||||
|
||||
u64 comp = 0;
|
||||
u64 cnt = 0;
|
||||
u64 cnt2 = 0;
|
||||
|
||||
while (!feof (fd))
|
||||
{
|
||||
load_segment (wl_data, fd);
|
||||
|
||||
comp += wl_data->cnt;
|
||||
|
||||
u32 i = 0;
|
||||
|
||||
while (i < wl_data->cnt)
|
||||
{
|
||||
u32 len;
|
||||
u32 off;
|
||||
|
||||
get_next_word_func (wl_data->buf + i, wl_data->cnt - i, &len, &off);
|
||||
|
||||
if (run_rule_engine (data.rule_len_l, data.rule_buf_l))
|
||||
{
|
||||
char rule_buf_out[BLOCK_SIZE] = { 0 };
|
||||
|
||||
int rule_len_out = -1;
|
||||
|
||||
if (len < BLOCK_SIZE)
|
||||
{
|
||||
rule_len_out = _old_apply_rule (data.rule_buf_l, data.rule_len_l, wl_data->buf + i, len, rule_buf_out);
|
||||
}
|
||||
|
||||
if (rule_len_out < 0)
|
||||
{
|
||||
len = PW_MAX1;
|
||||
}
|
||||
else
|
||||
{
|
||||
len = rule_len_out;
|
||||
}
|
||||
}
|
||||
|
||||
if (len < PW_MAX1)
|
||||
{
|
||||
if (data.attack_kern == ATTACK_KERN_STRAIGHT)
|
||||
{
|
||||
cnt += data.kernel_rules_cnt;
|
||||
}
|
||||
else if (data.attack_kern == ATTACK_KERN_COMBI)
|
||||
{
|
||||
cnt += data.combs_cnt;
|
||||
}
|
||||
|
||||
d.cnt++;
|
||||
}
|
||||
|
||||
i += off;
|
||||
|
||||
cnt2++;
|
||||
}
|
||||
|
||||
time (&now);
|
||||
|
||||
if ((now - prev) == 0) continue;
|
||||
|
||||
double percent = (double) comp / (double) d.stat.st_size;
|
||||
|
||||
if (data.quiet == 0) log_info_nn ("Generating dictionary stats for %s: %" PRIu64 " bytes (%.2f%%), %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, comp, percent * 100, cnt2, cnt);
|
||||
|
||||
time (&prev);
|
||||
}
|
||||
|
||||
if (data.quiet == 0) log_info ("Generated dictionary stats for %s: %" PRIu64 " bytes, %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, comp, cnt2, cnt);
|
||||
if (data.quiet == 0) log_info ("");
|
||||
|
||||
dictstat_append (dictstat_ctx, &d);
|
||||
|
||||
hc_signal (sigHandler_default);
|
||||
|
||||
return (cnt);
|
||||
}
|
||||
|
||||
static void *thread_monitor (void *p)
|
||||
{
|
||||
uint runtime_check = 0;
|
||||
|
134
src/thread.c
134
src/thread.c
@ -4,4 +4,138 @@
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "types_int.h"
|
||||
#include "types.h"
|
||||
#include "timer.h"
|
||||
#include "ext_OpenCL.h"
|
||||
#include "ext_ADL.h"
|
||||
#include "ext_nvapi.h"
|
||||
#include "ext_nvml.h"
|
||||
#include "ext_xnvctrl.h"
|
||||
#include "opencl.h"
|
||||
#include "thread.h"
|
||||
#include "rp_cpu.h"
|
||||
#include "terminal.h"
|
||||
#include "interface.h"
|
||||
#include "hwmon.h"
|
||||
#include "mpsp.h"
|
||||
#include "restore.h"
|
||||
#include "outfile.h"
|
||||
#include "potfile.h"
|
||||
#include "status.h"
|
||||
#include "data.h"
|
||||
|
||||
extern hc_global_data_t data;
|
||||
|
||||
#if defined (_WIN)
|
||||
|
||||
BOOL WINAPI sigHandler_default (DWORD sig)
|
||||
{
|
||||
switch (sig)
|
||||
{
|
||||
case CTRL_CLOSE_EVENT:
|
||||
|
||||
/*
|
||||
* special case see: https://stackoverflow.com/questions/3640633/c-setconsolectrlhandler-routine-issue/5610042#5610042
|
||||
* if the user interacts w/ the user-interface (GUI/cmd), we need to do the finalization job within this signal handler
|
||||
* function otherwise it is too late (e.g. after returning from this function)
|
||||
*/
|
||||
|
||||
myabort ();
|
||||
|
||||
SetConsoleCtrlHandler (NULL, TRUE);
|
||||
|
||||
hc_sleep (10);
|
||||
|
||||
return TRUE;
|
||||
|
||||
case CTRL_C_EVENT:
|
||||
case CTRL_LOGOFF_EVENT:
|
||||
case CTRL_SHUTDOWN_EVENT:
|
||||
|
||||
myabort ();
|
||||
|
||||
SetConsoleCtrlHandler (NULL, TRUE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL WINAPI sigHandler_benchmark (DWORD sig)
|
||||
{
|
||||
switch (sig)
|
||||
{
|
||||
case CTRL_CLOSE_EVENT:
|
||||
|
||||
myquit ();
|
||||
|
||||
SetConsoleCtrlHandler (NULL, TRUE);
|
||||
|
||||
hc_sleep (10);
|
||||
|
||||
return TRUE;
|
||||
|
||||
case CTRL_C_EVENT:
|
||||
case CTRL_LOGOFF_EVENT:
|
||||
case CTRL_SHUTDOWN_EVENT:
|
||||
|
||||
myquit ();
|
||||
|
||||
SetConsoleCtrlHandler (NULL, TRUE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void hc_signal (BOOL WINAPI (callback) (DWORD))
|
||||
{
|
||||
if (callback == NULL)
|
||||
{
|
||||
SetConsoleCtrlHandler ((PHANDLER_ROUTINE) callback, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetConsoleCtrlHandler ((PHANDLER_ROUTINE) callback, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void sigHandler_default (int sig)
|
||||
{
|
||||
myabort ();
|
||||
|
||||
signal (sig, NULL);
|
||||
}
|
||||
|
||||
void sigHandler_benchmark (int sig)
|
||||
{
|
||||
myquit ();
|
||||
|
||||
signal (sig, NULL);
|
||||
}
|
||||
|
||||
void hc_signal (void (callback) (int))
|
||||
{
|
||||
if (callback == NULL) callback = SIG_DFL;
|
||||
|
||||
signal (SIGINT, callback);
|
||||
signal (SIGTERM, callback);
|
||||
signal (SIGABRT, callback);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void myabort ()
|
||||
{
|
||||
data.devices_status = STATUS_ABORTED;
|
||||
}
|
||||
|
||||
void myquit ()
|
||||
{
|
||||
data.devices_status = STATUS_QUIT;
|
||||
}
|
||||
|
141
src/wordlist.c
141
src/wordlist.c
@ -24,6 +24,8 @@
|
||||
#include "interface.h"
|
||||
#include "shared.h"
|
||||
#include "hwmon.h"
|
||||
#include "thread.h"
|
||||
#include "dictstat.h"
|
||||
#include "mpsp.h"
|
||||
#include "restore.h"
|
||||
#include "outfile.h"
|
||||
@ -282,3 +284,142 @@ void pw_add (hc_device_param_t *device_param, const u8 *pw_buf, const int pw_len
|
||||
// return;
|
||||
//}
|
||||
}
|
||||
|
||||
u64 count_words (wl_data_t *wl_data, FILE *fd, const char *dictfile, dictstat_ctx_t *dictstat_ctx)
|
||||
{
|
||||
hc_signal (NULL);
|
||||
|
||||
dictstat_t d;
|
||||
|
||||
d.cnt = 0;
|
||||
|
||||
#if defined (_POSIX)
|
||||
fstat (fileno (fd), &d.stat);
|
||||
#endif
|
||||
|
||||
#if defined (_WIN)
|
||||
_fstat64 (fileno (fd), &d.stat);
|
||||
#endif
|
||||
|
||||
d.stat.st_mode = 0;
|
||||
d.stat.st_nlink = 0;
|
||||
d.stat.st_uid = 0;
|
||||
d.stat.st_gid = 0;
|
||||
d.stat.st_rdev = 0;
|
||||
d.stat.st_atime = 0;
|
||||
|
||||
#if defined (_POSIX)
|
||||
d.stat.st_blksize = 0;
|
||||
d.stat.st_blocks = 0;
|
||||
#endif
|
||||
|
||||
if (d.stat.st_size == 0) return 0;
|
||||
|
||||
const u64 cached_cnt = dictstat_find (dictstat_ctx, &d);
|
||||
|
||||
if (run_rule_engine (data.rule_len_l, data.rule_buf_l) == 0)
|
||||
{
|
||||
if (cached_cnt)
|
||||
{
|
||||
u64 keyspace = cached_cnt;
|
||||
|
||||
if (data.attack_kern == ATTACK_KERN_STRAIGHT)
|
||||
{
|
||||
keyspace *= data.kernel_rules_cnt;
|
||||
}
|
||||
else if (data.attack_kern == ATTACK_KERN_COMBI)
|
||||
{
|
||||
keyspace *= data.combs_cnt;
|
||||
}
|
||||
|
||||
if (data.quiet == 0) log_info ("Cache-hit dictionary stats %s: %" PRIu64 " bytes, %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, d.stat.st_size, cached_cnt, keyspace);
|
||||
if (data.quiet == 0) log_info ("");
|
||||
|
||||
hc_signal (sigHandler_default);
|
||||
|
||||
return (keyspace);
|
||||
}
|
||||
}
|
||||
|
||||
time_t now = 0;
|
||||
time_t prev = 0;
|
||||
|
||||
u64 comp = 0;
|
||||
u64 cnt = 0;
|
||||
u64 cnt2 = 0;
|
||||
|
||||
while (!feof (fd))
|
||||
{
|
||||
load_segment (wl_data, fd);
|
||||
|
||||
comp += wl_data->cnt;
|
||||
|
||||
u32 i = 0;
|
||||
|
||||
while (i < wl_data->cnt)
|
||||
{
|
||||
u32 len;
|
||||
u32 off;
|
||||
|
||||
get_next_word_func (wl_data->buf + i, wl_data->cnt - i, &len, &off);
|
||||
|
||||
if (run_rule_engine (data.rule_len_l, data.rule_buf_l))
|
||||
{
|
||||
char rule_buf_out[BLOCK_SIZE] = { 0 };
|
||||
|
||||
int rule_len_out = -1;
|
||||
|
||||
if (len < BLOCK_SIZE)
|
||||
{
|
||||
rule_len_out = _old_apply_rule (data.rule_buf_l, data.rule_len_l, wl_data->buf + i, len, rule_buf_out);
|
||||
}
|
||||
|
||||
if (rule_len_out < 0)
|
||||
{
|
||||
len = PW_MAX1;
|
||||
}
|
||||
else
|
||||
{
|
||||
len = rule_len_out;
|
||||
}
|
||||
}
|
||||
|
||||
if (len < PW_MAX1)
|
||||
{
|
||||
if (data.attack_kern == ATTACK_KERN_STRAIGHT)
|
||||
{
|
||||
cnt += data.kernel_rules_cnt;
|
||||
}
|
||||
else if (data.attack_kern == ATTACK_KERN_COMBI)
|
||||
{
|
||||
cnt += data.combs_cnt;
|
||||
}
|
||||
|
||||
d.cnt++;
|
||||
}
|
||||
|
||||
i += off;
|
||||
|
||||
cnt2++;
|
||||
}
|
||||
|
||||
time (&now);
|
||||
|
||||
if ((now - prev) == 0) continue;
|
||||
|
||||
double percent = (double) comp / (double) d.stat.st_size;
|
||||
|
||||
if (data.quiet == 0) log_info_nn ("Generating dictionary stats for %s: %" PRIu64 " bytes (%.2f%%), %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, comp, percent * 100, cnt2, cnt);
|
||||
|
||||
time (&prev);
|
||||
}
|
||||
|
||||
if (data.quiet == 0) log_info ("Generated dictionary stats for %s: %" PRIu64 " bytes, %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, comp, cnt2, cnt);
|
||||
if (data.quiet == 0) log_info ("");
|
||||
|
||||
dictstat_append (dictstat_ctx, &d);
|
||||
|
||||
hc_signal (sigHandler_default);
|
||||
|
||||
return (cnt);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user