mirror of
https://github.com/hashcat/hashcat
synced 2024-11-13 17:28:58 +01:00
Move wordlist specific functions into their own source file
This commit is contained in:
parent
367473c657
commit
e304eed8c5
@ -93,4 +93,6 @@ int _old_apply_rule (char *rule, int rule_len, char in[BLOCK_SIZE], int in_len,
|
||||
int cpu_rule_to_kernel_rule (char *rule_buf, uint rule_len, kernel_rule_t *rule);
|
||||
int kernel_rule_to_cpu_rule (char *rule_buf, kernel_rule_t *rule);
|
||||
|
||||
int run_rule_engine (const int rule_len, const char *rule_buf);
|
||||
|
||||
#endif // _RP_CPU_H
|
||||
|
@ -331,15 +331,7 @@ typedef struct
|
||||
|
||||
} outfile_data_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *buf;
|
||||
u32 incr;
|
||||
u32 avail;
|
||||
u32 cnt;
|
||||
u32 pos;
|
||||
|
||||
} wl_data_t;
|
||||
|
||||
#define CPT_BUF 0x20000
|
||||
|
||||
|
31
include/wordlist.h
Normal file
31
include/wordlist.h
Normal file
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Author......: Jens Steube <jens.steube@gmail.com>
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#ifndef _WORDLIST_H
|
||||
#define _WORDLIST_H
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *buf;
|
||||
u32 incr;
|
||||
u32 avail;
|
||||
u32 cnt;
|
||||
u32 pos;
|
||||
|
||||
} wl_data_t;
|
||||
|
||||
uint convert_from_hex (char *line_buf, const uint line_len);
|
||||
|
||||
void load_segment (wl_data_t *wl_data, FILE *fd);
|
||||
|
||||
void get_next_word_lm (char *buf, u32 sz, u32 *len, u32 *off);
|
||||
void get_next_word_uc (char *buf, u32 sz, u32 *len, u32 *off);
|
||||
void get_next_word_std (char *buf, u32 sz, u32 *len, u32 *off);
|
||||
|
||||
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);
|
||||
|
||||
#endif // _WORDLIST_H
|
10
src/Makefile
10
src/Makefile
@ -166,7 +166,7 @@ LFLAGS_CROSS_WIN := -lpsapi
|
||||
## Objects
|
||||
##
|
||||
|
||||
NATIVE_OBJS := obj/stdout.NATIVE.o obj/filenames.NATIVE.o obj/hlfmt.NATIVE.o obj/status.NATIVE.o obj/restore.NATIVE.o obj/bitmap.NATIVE.o obj/opencl.NATIVE.o obj/affinity.NATIVE.o obj/filehandling.NATIVE.o obj/tuningdb.NATIVE.o obj/locking.NATIVE.o obj/folder.NATIVE.o obj/bitops.NATIVE.o obj/convert.NATIVE.o obj/cpu_aes.NATIVE.o obj/cpu_crc32.NATIVE.o obj/cpu_des.NATIVE.o obj/cpu_md5.NATIVE.o obj/cpu_sha1.NATIVE.o obj/cpu_sha256.NATIVE.o obj/data.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/hwmon.NATIVE.o obj/interface.NATIVE.o obj/logfile.NATIVE.o obj/logging.NATIVE.o obj/memory.NATIVE.o obj/mpsp.NATIVE.o obj/rp_cpu.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o obj/shared.NATIVE.o obj/terminal.NATIVE.o obj/usage.NATIVE.o
|
||||
NATIVE_OBJS := obj/wordlist.NATIVE.o obj/stdout.NATIVE.o obj/filenames.NATIVE.o obj/hlfmt.NATIVE.o obj/status.NATIVE.o obj/restore.NATIVE.o obj/bitmap.NATIVE.o obj/opencl.NATIVE.o obj/affinity.NATIVE.o obj/filehandling.NATIVE.o obj/tuningdb.NATIVE.o obj/locking.NATIVE.o obj/folder.NATIVE.o obj/bitops.NATIVE.o obj/convert.NATIVE.o obj/cpu_aes.NATIVE.o obj/cpu_crc32.NATIVE.o obj/cpu_des.NATIVE.o obj/cpu_md5.NATIVE.o obj/cpu_sha1.NATIVE.o obj/cpu_sha256.NATIVE.o obj/data.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/hwmon.NATIVE.o obj/interface.NATIVE.o obj/logfile.NATIVE.o obj/logging.NATIVE.o obj/memory.NATIVE.o obj/mpsp.NATIVE.o obj/rp_cpu.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o obj/shared.NATIVE.o obj/terminal.NATIVE.o obj/usage.NATIVE.o
|
||||
|
||||
ifeq ($(UNAME),Linux)
|
||||
NATIVE_OBJS += obj/ext_ADL.NATIVE.o
|
||||
@ -175,8 +175,8 @@ NATIVE_OBJS += obj/ext_nvml.NATIVE.o
|
||||
NATIVE_OBJS += obj/ext_xnvctrl.NATIVE.o
|
||||
endif
|
||||
|
||||
LINUX_32_OBJS := obj/stdout.LINUX.32.o obj/filenames.LINUX.32.o obj/hlfmt.LINUX.32.o obj/status.LINUX.32.o obj/restore.LINUX.32.o obj/bitmap.LINUX.32.o obj/opencl.LINUX.32.o obj/affinity.LINUX.32.o obj/filehandling.LINUX.32.o obj/tuningdb.LINUX.32.o obj/locking.LINUX.32.o obj/folder.LINUX.32.o obj/bitops.LINUX.32.o obj/convert.LINUX.32.o obj/cpu_aes.LINUX.32.o obj/cpu_crc32.LINUX.32.o obj/cpu_des.LINUX.32.o obj/cpu_md5.LINUX.32.o obj/cpu_sha1.LINUX.32.o obj/cpu_sha256.LINUX.32.o obj/data.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o obj/hwmon.LINUX.32.o obj/interface.LINUX.32.o obj/logfile.LINUX.32.o obj/logging.LINUX.32.o obj/memory.LINUX.32.o obj/mpsp.LINUX.32.o obj/rp_cpu.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/shared.LINUX.32.o obj/terminal.LINUX.32.o obj/usage.LINUX.32.o
|
||||
LINUX_64_OBJS := obj/stdout.LINUX.64.o obj/filenames.LINUX.64.o obj/hlfmt.LINUX.64.o obj/status.LINUX.64.o obj/restore.LINUX.64.o obj/bitmap.LINUX.64.o obj/opencl.LINUX.64.o obj/affinity.LINUX.64.o obj/filehandling.LINUX.64.o obj/tuningdb.LINUX.64.o obj/locking.LINUX.64.o obj/folder.LINUX.64.o obj/bitops.LINUX.64.o obj/convert.LINUX.64.o obj/cpu_aes.LINUX.64.o obj/cpu_crc32.LINUX.64.o obj/cpu_des.LINUX.64.o obj/cpu_md5.LINUX.64.o obj/cpu_sha1.LINUX.64.o obj/cpu_sha256.LINUX.64.o obj/data.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o obj/hwmon.LINUX.64.o obj/interface.LINUX.64.o obj/logfile.LINUX.64.o obj/logging.LINUX.64.o obj/memory.LINUX.64.o obj/mpsp.LINUX.64.o obj/rp_cpu.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/shared.LINUX.64.o obj/terminal.LINUX.64.o obj/usage.LINUX.64.o
|
||||
LINUX_32_OBJS := obj/wordlist.LINUX.32.o obj/stdout.LINUX.32.o obj/filenames.LINUX.32.o obj/hlfmt.LINUX.32.o obj/status.LINUX.32.o obj/restore.LINUX.32.o obj/bitmap.LINUX.32.o obj/opencl.LINUX.32.o obj/affinity.LINUX.32.o obj/filehandling.LINUX.32.o obj/tuningdb.LINUX.32.o obj/locking.LINUX.32.o obj/folder.LINUX.32.o obj/bitops.LINUX.32.o obj/convert.LINUX.32.o obj/cpu_aes.LINUX.32.o obj/cpu_crc32.LINUX.32.o obj/cpu_des.LINUX.32.o obj/cpu_md5.LINUX.32.o obj/cpu_sha1.LINUX.32.o obj/cpu_sha256.LINUX.32.o obj/data.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o obj/hwmon.LINUX.32.o obj/interface.LINUX.32.o obj/logfile.LINUX.32.o obj/logging.LINUX.32.o obj/memory.LINUX.32.o obj/mpsp.LINUX.32.o obj/rp_cpu.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/shared.LINUX.32.o obj/terminal.LINUX.32.o obj/usage.LINUX.32.o
|
||||
LINUX_64_OBJS := obj/wordlist.LINUX.64.o obj/stdout.LINUX.64.o obj/filenames.LINUX.64.o obj/hlfmt.LINUX.64.o obj/status.LINUX.64.o obj/restore.LINUX.64.o obj/bitmap.LINUX.64.o obj/opencl.LINUX.64.o obj/affinity.LINUX.64.o obj/filehandling.LINUX.64.o obj/tuningdb.LINUX.64.o obj/locking.LINUX.64.o obj/folder.LINUX.64.o obj/bitops.LINUX.64.o obj/convert.LINUX.64.o obj/cpu_aes.LINUX.64.o obj/cpu_crc32.LINUX.64.o obj/cpu_des.LINUX.64.o obj/cpu_md5.LINUX.64.o obj/cpu_sha1.LINUX.64.o obj/cpu_sha256.LINUX.64.o obj/data.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o obj/hwmon.LINUX.64.o obj/interface.LINUX.64.o obj/logfile.LINUX.64.o obj/logging.LINUX.64.o obj/memory.LINUX.64.o obj/mpsp.LINUX.64.o obj/rp_cpu.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/shared.LINUX.64.o obj/terminal.LINUX.64.o obj/usage.LINUX.64.o
|
||||
|
||||
# Windows CRT file globbing:
|
||||
|
||||
@ -186,8 +186,8 @@ CRT_GLOB_INCLUDE_FOLDER := $(dir $(lastword $(MAKEFILE_LIST)))
|
||||
|
||||
include $(CRT_GLOB_INCLUDE_FOLDER)/win_file_globbing.mk
|
||||
|
||||
WIN_32_OBJS := obj/stdout.WIN.32.o obj/filenames.WIN.32.o obj/hlfmt.WIN.32.o obj/status.WIN.32.o obj/restore.WIN.32.o obj/bitmap.WIN.32.o obj/opencl.WIN.32.o obj/affinity.WIN.32.o obj/filehandling.WIN.32.o obj/tuningdb.WIN.32.o obj/locking.WIN.32.o obj/folder.WIN.32.o obj/bitops.WIN.32.o obj/convert.WIN.32.o obj/cpu_aes.WIN.32.o obj/cpu_crc32.WIN.32.o obj/cpu_des.WIN.32.o obj/cpu_md5.WIN.32.o obj/cpu_sha1.WIN.32.o obj/cpu_sha256.WIN.32.o obj/data.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/ext_xnvctrl.WIN.32.o obj/hwmon.WIN.32.o obj/interface.WIN.32.o obj/logfile.WIN.32.o obj/logging.WIN.32.o obj/memory.WIN.32.o obj/mpsp.WIN.32.o obj/rp_cpu.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/shared.WIN.32.o obj/terminal.WIN.32.o obj/usage.WIN.32.o $(CRT_GLOB_32)
|
||||
WIN_64_OBJS := obj/stdout.WIN.64.o obj/filenames.WIN.64.o obj/hlfmt.WIN.64.o obj/status.WIN.64.o obj/restore.WIN.64.o obj/bitmap.WIN.64.o obj/opencl.WIN.64.o obj/affinity.WIN.64.o obj/filehandling.WIN.64.o obj/tuningdb.WIN.64.o obj/locking.WIN.64.o obj/folder.WIN.64.o obj/bitops.WIN.64.o obj/convert.WIN.64.o obj/cpu_aes.WIN.64.o obj/cpu_crc32.WIN.64.o obj/cpu_des.WIN.64.o obj/cpu_md5.WIN.64.o obj/cpu_sha1.WIN.64.o obj/cpu_sha256.WIN.64.o obj/data.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/ext_xnvctrl.WIN.64.o obj/hwmon.WIN.64.o obj/interface.WIN.64.o obj/logfile.WIN.64.o obj/logging.WIN.64.o obj/memory.WIN.64.o obj/mpsp.WIN.64.o obj/rp_cpu.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/shared.WIN.64.o obj/terminal.WIN.64.o obj/usage.WIN.64.o $(CRT_GLOB_64)
|
||||
WIN_32_OBJS := obj/wordlist.WIN.32.o obj/stdout.WIN.32.o obj/filenames.WIN.32.o obj/hlfmt.WIN.32.o obj/status.WIN.32.o obj/restore.WIN.32.o obj/bitmap.WIN.32.o obj/opencl.WIN.32.o obj/affinity.WIN.32.o obj/filehandling.WIN.32.o obj/tuningdb.WIN.32.o obj/locking.WIN.32.o obj/folder.WIN.32.o obj/bitops.WIN.32.o obj/convert.WIN.32.o obj/cpu_aes.WIN.32.o obj/cpu_crc32.WIN.32.o obj/cpu_des.WIN.32.o obj/cpu_md5.WIN.32.o obj/cpu_sha1.WIN.32.o obj/cpu_sha256.WIN.32.o obj/data.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/ext_xnvctrl.WIN.32.o obj/hwmon.WIN.32.o obj/interface.WIN.32.o obj/logfile.WIN.32.o obj/logging.WIN.32.o obj/memory.WIN.32.o obj/mpsp.WIN.32.o obj/rp_cpu.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/shared.WIN.32.o obj/terminal.WIN.32.o obj/usage.WIN.32.o $(CRT_GLOB_32)
|
||||
WIN_64_OBJS := obj/wordlist.WIN.64.o obj/stdout.WIN.64.o obj/filenames.WIN.64.o obj/hlfmt.WIN.64.o obj/status.WIN.64.o obj/restore.WIN.64.o obj/bitmap.WIN.64.o obj/opencl.WIN.64.o obj/affinity.WIN.64.o obj/filehandling.WIN.64.o obj/tuningdb.WIN.64.o obj/locking.WIN.64.o obj/folder.WIN.64.o obj/bitops.WIN.64.o obj/convert.WIN.64.o obj/cpu_aes.WIN.64.o obj/cpu_crc32.WIN.64.o obj/cpu_des.WIN.64.o obj/cpu_md5.WIN.64.o obj/cpu_sha1.WIN.64.o obj/cpu_sha256.WIN.64.o obj/data.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/ext_xnvctrl.WIN.64.o obj/hwmon.WIN.64.o obj/interface.WIN.64.o obj/logfile.WIN.64.o obj/logging.WIN.64.o obj/memory.WIN.64.o obj/mpsp.WIN.64.o obj/rp_cpu.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/shared.WIN.64.o obj/terminal.WIN.64.o obj/usage.WIN.64.o $(CRT_GLOB_64)
|
||||
|
||||
##
|
||||
## Targets: Global
|
||||
|
263
src/hashcat.c
263
src/hashcat.c
@ -68,6 +68,7 @@
|
||||
#include "hlfmt.h"
|
||||
#include "filenames.h"
|
||||
#include "stdout.h"
|
||||
#include "wordlist.h"
|
||||
|
||||
extern hc_global_data_t data;
|
||||
|
||||
@ -76,6 +77,8 @@ extern int SUPPRESS_OUTPUT;
|
||||
extern hc_thread_mutex_t mux_hwmon;
|
||||
extern hc_thread_mutex_t mux_display;
|
||||
|
||||
extern void (*get_next_word_func) (char *, u32, u32 *, u32 *);
|
||||
|
||||
static const char *PROGNAME = "hashcat";
|
||||
|
||||
static double TARGET_MS_PROFILE[4] = { 2, 12, 96, 480 };
|
||||
@ -359,7 +362,7 @@ static uint default_benchmark_algorithms[NUM_DEFAULT_BENCHMARK_ALGORITHMS] =
|
||||
* types
|
||||
*/
|
||||
|
||||
static void (*get_next_word_func) (char *, u32, u32 *, u32 *);
|
||||
|
||||
|
||||
/**
|
||||
* globals
|
||||
@ -1362,48 +1365,7 @@ static void hc_signal (void (callback) (int))
|
||||
|
||||
|
||||
|
||||
static uint convert_from_hex (char *line_buf, const uint line_len)
|
||||
{
|
||||
if (line_len & 1) return (line_len); // not in hex
|
||||
|
||||
if (data.hex_wordlist == 1)
|
||||
{
|
||||
uint i;
|
||||
uint j;
|
||||
|
||||
for (i = 0, j = 0; j < line_len; i += 1, j += 2)
|
||||
{
|
||||
line_buf[i] = hex_to_u8 ((const u8 *) &line_buf[j]);
|
||||
}
|
||||
|
||||
memset (line_buf + i, 0, line_len - i);
|
||||
|
||||
return (i);
|
||||
}
|
||||
else if (line_len >= 6) // $HEX[] = 6
|
||||
{
|
||||
if (line_buf[0] != '$') return (line_len);
|
||||
if (line_buf[1] != 'H') return (line_len);
|
||||
if (line_buf[2] != 'E') return (line_len);
|
||||
if (line_buf[3] != 'X') return (line_len);
|
||||
if (line_buf[4] != '[') return (line_len);
|
||||
if (line_buf[line_len - 1] != ']') return (line_len);
|
||||
|
||||
uint i;
|
||||
uint j;
|
||||
|
||||
for (i = 0, j = 5; j < line_len - 1; i += 1, j += 2)
|
||||
{
|
||||
line_buf[i] = hex_to_u8 ((const u8 *) &line_buf[j]);
|
||||
}
|
||||
|
||||
memset (line_buf + i, 0, line_len - i);
|
||||
|
||||
return (i);
|
||||
}
|
||||
|
||||
return (line_len);
|
||||
}
|
||||
|
||||
static void clear_prompt ()
|
||||
{
|
||||
@ -2589,19 +2551,6 @@ static int choose_kernel (hc_device_param_t *device_param, const uint attack_exe
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int run_rule_engine (const int rule_len, const char *rule_buf)
|
||||
{
|
||||
if (rule_len == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (rule_len == 1)
|
||||
{
|
||||
if (rule_buf[0] == RULE_OP_MANGLE_NOOP) return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int run_copy (hc_device_param_t *device_param, const uint pws_cnt)
|
||||
{
|
||||
@ -3341,187 +3290,6 @@ static int run_cracker (hc_device_param_t *device_param, const uint pws_cnt)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void load_segment (wl_data_t *wl_data, FILE *fd)
|
||||
{
|
||||
// NOTE: use (never changing) ->incr here instead of ->avail otherwise the buffer gets bigger and bigger
|
||||
|
||||
wl_data->pos = 0;
|
||||
|
||||
wl_data->cnt = fread (wl_data->buf, 1, wl_data->incr - 1000, fd);
|
||||
|
||||
wl_data->buf[wl_data->cnt] = 0;
|
||||
|
||||
if (wl_data->cnt == 0) return;
|
||||
|
||||
if (wl_data->buf[wl_data->cnt - 1] == '\n') return;
|
||||
|
||||
while (!feof (fd))
|
||||
{
|
||||
if (wl_data->cnt == wl_data->avail)
|
||||
{
|
||||
wl_data->buf = (char *) myrealloc (wl_data->buf, wl_data->avail, wl_data->incr);
|
||||
|
||||
wl_data->avail += wl_data->incr;
|
||||
}
|
||||
|
||||
const int c = fgetc (fd);
|
||||
|
||||
if (c == EOF) break;
|
||||
|
||||
wl_data->buf[wl_data->cnt] = (char) c;
|
||||
|
||||
wl_data->cnt++;
|
||||
|
||||
if (c == '\n') break;
|
||||
}
|
||||
|
||||
// ensure stream ends with a newline
|
||||
|
||||
if (wl_data->buf[wl_data->cnt - 1] != '\n')
|
||||
{
|
||||
wl_data->cnt++;
|
||||
|
||||
wl_data->buf[wl_data->cnt - 1] = '\n';
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void get_next_word_lm (char *buf, u32 sz, u32 *len, u32 *off)
|
||||
{
|
||||
char *ptr = buf;
|
||||
|
||||
for (u32 i = 0; i < sz; i++, ptr++)
|
||||
{
|
||||
if (*ptr >= 'a' && *ptr <= 'z') *ptr -= 0x20;
|
||||
|
||||
if (i == 7)
|
||||
{
|
||||
*off = i;
|
||||
*len = i;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (*ptr != '\n') continue;
|
||||
|
||||
*off = i + 1;
|
||||
|
||||
if ((i > 0) && (buf[i - 1] == '\r')) i--;
|
||||
|
||||
*len = i;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
*off = sz;
|
||||
*len = sz;
|
||||
}
|
||||
|
||||
static void get_next_word_uc (char *buf, u32 sz, u32 *len, u32 *off)
|
||||
{
|
||||
char *ptr = buf;
|
||||
|
||||
for (u32 i = 0; i < sz; i++, ptr++)
|
||||
{
|
||||
if (*ptr >= 'a' && *ptr <= 'z') *ptr -= 0x20;
|
||||
|
||||
if (*ptr != '\n') continue;
|
||||
|
||||
*off = i + 1;
|
||||
|
||||
if ((i > 0) && (buf[i - 1] == '\r')) i--;
|
||||
|
||||
*len = i;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
*off = sz;
|
||||
*len = sz;
|
||||
}
|
||||
|
||||
static void get_next_word_std (char *buf, u32 sz, u32 *len, u32 *off)
|
||||
{
|
||||
char *ptr = buf;
|
||||
|
||||
for (u32 i = 0; i < sz; i++, ptr++)
|
||||
{
|
||||
if (*ptr != '\n') continue;
|
||||
|
||||
*off = i + 1;
|
||||
|
||||
if ((i > 0) && (buf[i - 1] == '\r')) i--;
|
||||
|
||||
*len = i;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
*off = sz;
|
||||
*len = sz;
|
||||
}
|
||||
|
||||
static void get_next_word (wl_data_t *wl_data, FILE *fd, char **out_buf, uint *out_len)
|
||||
{
|
||||
while (wl_data->pos < wl_data->cnt)
|
||||
{
|
||||
uint off;
|
||||
uint len;
|
||||
|
||||
char *ptr = wl_data->buf + wl_data->pos;
|
||||
|
||||
get_next_word_func (ptr, wl_data->cnt - wl_data->pos, &len, &off);
|
||||
|
||||
wl_data->pos += 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, ptr, len, rule_buf_out);
|
||||
}
|
||||
|
||||
if (rule_len_out < 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (rule_len_out > PW_MAX)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (len > PW_MAX)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
*out_buf = ptr;
|
||||
*out_len = len;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (feof (fd))
|
||||
{
|
||||
fprintf (stderr, "BUG feof()!!\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
load_segment (wl_data, fd);
|
||||
|
||||
get_next_word (wl_data, fd, out_buf, out_len);
|
||||
}
|
||||
|
||||
#if defined (_POSIX)
|
||||
static u64 count_words (wl_data_t *wl_data, FILE *fd, char *dictfile, dictstat_t *dictstat_base, size_t *dictstat_nmemb)
|
||||
#endif
|
||||
@ -4304,29 +4072,6 @@ static void *thread_outfile_remove (void *p)
|
||||
return (p);
|
||||
}
|
||||
|
||||
static void pw_add (hc_device_param_t *device_param, const u8 *pw_buf, const int pw_len)
|
||||
{
|
||||
//if (device_param->pws_cnt < device_param->kernel_power)
|
||||
//{
|
||||
pw_t *pw = (pw_t *) device_param->pws_buf + device_param->pws_cnt;
|
||||
|
||||
u8 *ptr = (u8 *) pw->i;
|
||||
|
||||
memcpy (ptr, pw_buf, pw_len);
|
||||
|
||||
memset (ptr + pw_len, 0, sizeof (pw->i) - pw_len);
|
||||
|
||||
pw->pw_len = pw_len;
|
||||
|
||||
device_param->pws_cnt++;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// fprintf (stderr, "BUG pw_add()!!\n");
|
||||
//
|
||||
// return;
|
||||
//}
|
||||
}
|
||||
|
||||
static void set_kernel_power_final (const u64 kernel_power_final)
|
||||
{
|
||||
|
15
src/rp_cpu.c
15
src/rp_cpu.c
@ -1494,3 +1494,18 @@ int kernel_rule_to_cpu_rule (char *rule_buf, kernel_rule_t *rule)
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int run_rule_engine (const int rule_len, const char *rule_buf)
|
||||
{
|
||||
if (rule_len == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (rule_len == 1)
|
||||
{
|
||||
if (rule_buf[0] == RULE_OP_MANGLE_NOOP) return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
282
src/wordlist.c
Normal file
282
src/wordlist.c
Normal file
@ -0,0 +1,282 @@
|
||||
/**
|
||||
* Author......: Jens Steube <jens.steube@gmail.com>
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
#include "types_int.h"
|
||||
#include "types.h"
|
||||
#include "timer.h"
|
||||
#include "memory.h"
|
||||
#include "convert.h"
|
||||
#include "logging.h"
|
||||
#include "logfile.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 "locking.h"
|
||||
#include "rp_cpu.h"
|
||||
#include "rp_kernel_on_cpu.h"
|
||||
#include "interface.h"
|
||||
#include "shared.h"
|
||||
#include "hwmon.h"
|
||||
#include "mpsp.h"
|
||||
#include "restore.h"
|
||||
#include "data.h"
|
||||
#include "wordlist.h"
|
||||
|
||||
extern hc_global_data_t data;
|
||||
|
||||
void (*get_next_word_func) (char *, u32, u32 *, u32 *);
|
||||
|
||||
uint convert_from_hex (char *line_buf, const uint line_len)
|
||||
{
|
||||
if (line_len & 1) return (line_len); // not in hex
|
||||
|
||||
if (data.hex_wordlist == 1)
|
||||
{
|
||||
uint i;
|
||||
uint j;
|
||||
|
||||
for (i = 0, j = 0; j < line_len; i += 1, j += 2)
|
||||
{
|
||||
line_buf[i] = hex_to_u8 ((const u8 *) &line_buf[j]);
|
||||
}
|
||||
|
||||
memset (line_buf + i, 0, line_len - i);
|
||||
|
||||
return (i);
|
||||
}
|
||||
else if (line_len >= 6) // $HEX[] = 6
|
||||
{
|
||||
if (line_buf[0] != '$') return (line_len);
|
||||
if (line_buf[1] != 'H') return (line_len);
|
||||
if (line_buf[2] != 'E') return (line_len);
|
||||
if (line_buf[3] != 'X') return (line_len);
|
||||
if (line_buf[4] != '[') return (line_len);
|
||||
if (line_buf[line_len - 1] != ']') return (line_len);
|
||||
|
||||
uint i;
|
||||
uint j;
|
||||
|
||||
for (i = 0, j = 5; j < line_len - 1; i += 1, j += 2)
|
||||
{
|
||||
line_buf[i] = hex_to_u8 ((const u8 *) &line_buf[j]);
|
||||
}
|
||||
|
||||
memset (line_buf + i, 0, line_len - i);
|
||||
|
||||
return (i);
|
||||
}
|
||||
|
||||
return (line_len);
|
||||
}
|
||||
|
||||
void load_segment (wl_data_t *wl_data, FILE *fd)
|
||||
{
|
||||
// NOTE: use (never changing) ->incr here instead of ->avail otherwise the buffer gets bigger and bigger
|
||||
|
||||
wl_data->pos = 0;
|
||||
|
||||
wl_data->cnt = fread (wl_data->buf, 1, wl_data->incr - 1000, fd);
|
||||
|
||||
wl_data->buf[wl_data->cnt] = 0;
|
||||
|
||||
if (wl_data->cnt == 0) return;
|
||||
|
||||
if (wl_data->buf[wl_data->cnt - 1] == '\n') return;
|
||||
|
||||
while (!feof (fd))
|
||||
{
|
||||
if (wl_data->cnt == wl_data->avail)
|
||||
{
|
||||
wl_data->buf = (char *) myrealloc (wl_data->buf, wl_data->avail, wl_data->incr);
|
||||
|
||||
wl_data->avail += wl_data->incr;
|
||||
}
|
||||
|
||||
const int c = fgetc (fd);
|
||||
|
||||
if (c == EOF) break;
|
||||
|
||||
wl_data->buf[wl_data->cnt] = (char) c;
|
||||
|
||||
wl_data->cnt++;
|
||||
|
||||
if (c == '\n') break;
|
||||
}
|
||||
|
||||
// ensure stream ends with a newline
|
||||
|
||||
if (wl_data->buf[wl_data->cnt - 1] != '\n')
|
||||
{
|
||||
wl_data->cnt++;
|
||||
|
||||
wl_data->buf[wl_data->cnt - 1] = '\n';
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void get_next_word_lm (char *buf, u32 sz, u32 *len, u32 *off)
|
||||
{
|
||||
char *ptr = buf;
|
||||
|
||||
for (u32 i = 0; i < sz; i++, ptr++)
|
||||
{
|
||||
if (*ptr >= 'a' && *ptr <= 'z') *ptr -= 0x20;
|
||||
|
||||
if (i == 7)
|
||||
{
|
||||
*off = i;
|
||||
*len = i;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (*ptr != '\n') continue;
|
||||
|
||||
*off = i + 1;
|
||||
|
||||
if ((i > 0) && (buf[i - 1] == '\r')) i--;
|
||||
|
||||
*len = i;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
*off = sz;
|
||||
*len = sz;
|
||||
}
|
||||
|
||||
void get_next_word_uc (char *buf, u32 sz, u32 *len, u32 *off)
|
||||
{
|
||||
char *ptr = buf;
|
||||
|
||||
for (u32 i = 0; i < sz; i++, ptr++)
|
||||
{
|
||||
if (*ptr >= 'a' && *ptr <= 'z') *ptr -= 0x20;
|
||||
|
||||
if (*ptr != '\n') continue;
|
||||
|
||||
*off = i + 1;
|
||||
|
||||
if ((i > 0) && (buf[i - 1] == '\r')) i--;
|
||||
|
||||
*len = i;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
*off = sz;
|
||||
*len = sz;
|
||||
}
|
||||
|
||||
void get_next_word_std (char *buf, u32 sz, u32 *len, u32 *off)
|
||||
{
|
||||
char *ptr = buf;
|
||||
|
||||
for (u32 i = 0; i < sz; i++, ptr++)
|
||||
{
|
||||
if (*ptr != '\n') continue;
|
||||
|
||||
*off = i + 1;
|
||||
|
||||
if ((i > 0) && (buf[i - 1] == '\r')) i--;
|
||||
|
||||
*len = i;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
*off = sz;
|
||||
*len = sz;
|
||||
}
|
||||
|
||||
void get_next_word (wl_data_t *wl_data, FILE *fd, char **out_buf, uint *out_len)
|
||||
{
|
||||
while (wl_data->pos < wl_data->cnt)
|
||||
{
|
||||
uint off;
|
||||
uint len;
|
||||
|
||||
char *ptr = wl_data->buf + wl_data->pos;
|
||||
|
||||
get_next_word_func (ptr, wl_data->cnt - wl_data->pos, &len, &off);
|
||||
|
||||
wl_data->pos += 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, ptr, len, rule_buf_out);
|
||||
}
|
||||
|
||||
if (rule_len_out < 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (rule_len_out > PW_MAX)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (len > PW_MAX)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
*out_buf = ptr;
|
||||
*out_len = len;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (feof (fd))
|
||||
{
|
||||
fprintf (stderr, "BUG feof()!!\n");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
load_segment (wl_data, fd);
|
||||
|
||||
get_next_word (wl_data, fd, out_buf, out_len);
|
||||
}
|
||||
|
||||
void pw_add (hc_device_param_t *device_param, const u8 *pw_buf, const int pw_len)
|
||||
{
|
||||
//if (device_param->pws_cnt < device_param->kernel_power)
|
||||
//{
|
||||
pw_t *pw = (pw_t *) device_param->pws_buf + device_param->pws_cnt;
|
||||
|
||||
u8 *ptr = (u8 *) pw->i;
|
||||
|
||||
memcpy (ptr, pw_buf, pw_len);
|
||||
|
||||
memset (ptr + pw_len, 0, sizeof (pw->i) - pw_len);
|
||||
|
||||
pw->pw_len = pw_len;
|
||||
|
||||
device_param->pws_cnt++;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// fprintf (stderr, "BUG pw_add()!!\n");
|
||||
//
|
||||
// return;
|
||||
//}
|
||||
}
|
Loading…
Reference in New Issue
Block a user