diff --git a/include/common.h b/include/common.h index d1568fd40..15c1dbfd9 100644 --- a/include/common.h +++ b/include/common.h @@ -48,6 +48,12 @@ #define __stdcall #endif +#if defined (_WIN32) || defined (__WIN32__) || defined (__CYGWIN__) +#define HC_API_CALL __stdcall +#else +#define HC_API_CALL +#endif + #if defined (_WIN) #define WIN32_LEAN_AND_MEAN #endif diff --git a/include/ext_ADL.h b/include/ext_ADL.h index 1dbff1445..3f4f34d6e 100644 --- a/include/ext_ADL.h +++ b/include/ext_ADL.h @@ -356,6 +356,8 @@ typedef hm_adl_lib_t ADL_PTR; int adl_init (ADL_PTR *lib); void adl_close (ADL_PTR *lib); +void *HC_API_CALL ADL_Main_Memory_Alloc (const int iSize); + int hm_ADL_Main_Control_Destroy (ADL_PTR *adl); int hm_ADL_Main_Control_Create (ADL_PTR *adl, ADL_MAIN_MALLOC_CALLBACK callback, int iEnumConnectedAdapters); int hm_ADL_Adapter_NumberOfAdapters_Get (ADL_PTR *adl, int *lpNumAdapters); diff --git a/include/shared.h b/include/shared.h index 80256fe8c..968a520e5 100644 --- a/include/shared.h +++ b/include/shared.h @@ -61,16 +61,14 @@ extern const char *PROMPT; -extern hc_thread_mutex_t mux_display; - - - /* * functions */ +double get_avg_exec_time (hc_device_param_t *device_param, const int last_num_entries); + void *rulefind (const void *key, void *base, int nmemb, size_t size, int (*compar) (const void *, const void *)); int sort_by_u32 (const void *p1, const void *p2); @@ -134,7 +132,7 @@ void naive_escape (char *s, size_t s_max, const u8 key_char, const u8 escape_cha -void check_checkpoint (void); +void check_checkpoint (void); #if defined (_WIN) @@ -150,11 +148,5 @@ void hc_signal (void c (int)); #endif -void *thread_device_watch (void *p); -void *thread_keypress (void *p); -void *thread_runtime (void *p); - -void status_display (void); -void status_display_machine_readable (void); #endif // _SHARED_H diff --git a/include/status.h b/include/status.h new file mode 100644 index 000000000..dd8024e1d --- /dev/null +++ b/include/status.h @@ -0,0 +1,42 @@ +/** + * Author......: Jens Steube + * License.....: MIT + */ + +#ifndef _STATUS_H +#define _STATUS_H + +#include +#include + +#define STATUS 0 +#define STATUS_TIMER 10 + +typedef enum status_rc +{ + STATUS_STARTING = 0, + STATUS_INIT = 1, + STATUS_RUNNING = 2, + STATUS_PAUSED = 3, + STATUS_EXHAUSTED = 4, + STATUS_CRACKED = 5, + STATUS_ABORTED = 6, + STATUS_QUIT = 7, + STATUS_BYPASS = 8, + STATUS_STOP_AT_CHECKPOINT = 9, + STATUS_AUTOTUNE = 10 + +} status_rc_t; + +char *strstatus (const uint devices_status); + +void status_display_machine_readable (); + +void status_display (); + +void status_benchmark_automate (); + +void status_benchmark (); + + +#endif // _STATUS_H diff --git a/include/terminal.h b/include/terminal.h index ebba754aa..91e3fcc1e 100644 --- a/include/terminal.h +++ b/include/terminal.h @@ -24,6 +24,10 @@ #include #endif // _WIN +#if defined (_WIN) +void SetConsoleWindowSize (const int x); +#endif + int tty_break(); int tty_getchar(); int tty_fix(); diff --git a/include/types.h b/include/types.h index 32f6f9189..a859168e7 100644 --- a/include/types.h +++ b/include/types.h @@ -23,6 +23,94 @@ * Outfile formats */ + +typedef enum wl_mode +{ + WL_MODE_STDIN = 1, + WL_MODE_FILE = 2, + WL_MODE_MASK = 3 + +} wl_mode_t; + +typedef enum hl_mode +{ + HL_MODE_FILE = 4, + HL_MODE_ARG = 5 + +} hl_mode_t; + +#define HLFMTS_CNT 11 + +typedef enum hlfmt_name +{ + HLFMT_HASHCAT = 0, + HLFMT_PWDUMP = 1, + HLFMT_PASSWD = 2, + HLFMT_SHADOW = 3, + HLFMT_DCC = 4, + HLFMT_DCC2 = 5, + HLFMT_NETNTLM1 = 7, + HLFMT_NETNTLM2 = 8, + HLFMT_NSLDAP = 9, + HLFMT_NSLDAPS = 10 + +} hlfmt_name_t; + +typedef enum attack_mode +{ + ATTACK_MODE_STRAIGHT = 0, + ATTACK_MODE_COMBI = 1, + ATTACK_MODE_TOGGLE = 2, + ATTACK_MODE_BF = 3, + ATTACK_MODE_PERM = 4, + ATTACK_MODE_TABLE = 5, + ATTACK_MODE_HYBRID1 = 6, + ATTACK_MODE_HYBRID2 = 7, + ATTACK_MODE_NONE = 100 + +} attack_mode_t; + +typedef enum attack_kern +{ + ATTACK_KERN_STRAIGHT = 0, + ATTACK_KERN_COMBI = 1, + ATTACK_KERN_BF = 3, + ATTACK_KERN_NONE = 100 + +} attack_kern_t; + +typedef enum attack_exec +{ + ATTACK_EXEC_OUTSIDE_KERNEL = 10, + ATTACK_EXEC_INSIDE_KERNEL = 11 + +} attack_exec_t; + +typedef enum combinator_mode +{ + COMBINATOR_MODE_BASE_LEFT = 10001, + COMBINATOR_MODE_BASE_RIGHT = 10002 + +} combinator_mode_t; + +typedef enum kern_run +{ + KERN_RUN_1 = 1000, + KERN_RUN_12 = 1500, + KERN_RUN_2 = 2000, + KERN_RUN_23 = 2500, + KERN_RUN_3 = 3000 + +} kern_run_t; + +typedef enum kern_run_mp +{ + KERN_RUN_MP = 101, + KERN_RUN_MP_L = 102, + KERN_RUN_MP_R = 103 + +} kern_run_mp_t; + typedef enum outfile_fmt { OUTFILE_FMT_HASH = (1 << 0), @@ -134,21 +222,7 @@ typedef enum dgst_size * status */ -typedef enum status_rc -{ - STATUS_STARTING = 0, - STATUS_INIT = 1, - STATUS_RUNNING = 2, - STATUS_PAUSED = 3, - STATUS_EXHAUSTED = 4, - STATUS_CRACKED = 5, - STATUS_ABORTED = 6, - STATUS_QUIT = 7, - STATUS_BYPASS = 8, - STATUS_STOP_AT_CHECKPOINT = 9, - STATUS_AUTOTUNE = 10 -} status_rc_t; typedef struct { diff --git a/src/Makefile b/src/Makefile index c1d04c6a1..7cb24b6ec 100644 --- a/src/Makefile +++ b/src/Makefile @@ -166,7 +166,7 @@ LFLAGS_CROSS_WIN := -lpsapi ## Objects ## -NATIVE_OBJS := 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/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/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/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/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/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/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/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/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/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 diff --git a/src/ext_ADL.c b/src/ext_ADL.c index db9537b66..f55c52410 100644 --- a/src/ext_ADL.c +++ b/src/ext_ADL.c @@ -83,6 +83,11 @@ void adl_close (ADL_PTR *adl) } } +void *HC_API_CALL ADL_Main_Memory_Alloc (const int iSize) +{ + return mymalloc (iSize); +} + int hm_ADL_Main_Control_Destroy (ADL_PTR *adl) { if (!adl) return -1; diff --git a/src/hashcat.c b/src/hashcat.c index bbdff0f18..93dcac3fb 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -52,6 +52,7 @@ #include "locking.h" #include "rp_cpu.h" #include "rp_kernel_on_cpu.h" +#include "terminal.h" #include "inc_hash_constants.h" #include "interface.h" #include "shared.h" @@ -62,11 +63,14 @@ #include "affinity.h" #include "bitmap.h" #include "usage.h" +#include "status.h" extern hc_global_data_t data; extern int SUPPRESS_OUTPUT; +extern hc_thread_mutex_t mux_hwmon; +extern hc_thread_mutex_t mux_display; static const char *PROGNAME = "hashcat"; @@ -86,8 +90,6 @@ static double TARGET_MS_PROFILE[4] = { 2, 12, 96, 480 }; #define BENCHMARK 0 #define STDOUT_FLAG 0 -#define STATUS 0 -#define STATUS_TIMER 10 #define MACHINE_READABLE 0 #define LOOPBACK 0 #define WEAK_HASH_THRESHOLD 100 @@ -139,38 +141,6 @@ static double TARGET_MS_PROFILE[4] = { 2, 12, 96, 480 }; #define SCRYPT_TMTO 0 #define OPENCL_VECTOR_WIDTH 0 -typedef enum wl_mode -{ - WL_MODE_STDIN = 1, - WL_MODE_FILE = 2, - WL_MODE_MASK = 3 - -} wl_mode_t; - -typedef enum hl_mode -{ - HL_MODE_FILE = 4, - HL_MODE_ARG = 5 - -} hl_mode_t; - -#define HLFMTS_CNT 11 - -typedef enum hlfmt_name -{ - HLFMT_HASHCAT = 0, - HLFMT_PWDUMP = 1, - HLFMT_PASSWD = 2, - HLFMT_SHADOW = 3, - HLFMT_DCC = 4, - HLFMT_DCC2 = 5, - HLFMT_NETNTLM1 = 7, - HLFMT_NETNTLM2 = 8, - HLFMT_NSLDAP = 9, - HLFMT_NSLDAPS = 10 - -} hlfmt_name_t; - static const char HLFMT_TEXT_HASHCAT[] = "native hashcat"; static const char HLFMT_TEXT_PWDUMP[] = "pwdump"; static const char HLFMT_TEXT_PASSWD[] = "passwd"; @@ -182,61 +152,6 @@ static const char HLFMT_TEXT_NETNTLM2[] = "NetNTLMv2"; static const char HLFMT_TEXT_NSLDAP[] = "nsldap"; static const char HLFMT_TEXT_NSLDAPS[] = "nsldaps"; -typedef enum attack_mode -{ - ATTACK_MODE_STRAIGHT = 0, - ATTACK_MODE_COMBI = 1, - ATTACK_MODE_TOGGLE = 2, - ATTACK_MODE_BF = 3, - ATTACK_MODE_PERM = 4, - ATTACK_MODE_TABLE = 5, - ATTACK_MODE_HYBRID1 = 6, - ATTACK_MODE_HYBRID2 = 7, - ATTACK_MODE_NONE = 100 - -} attack_mode_t; - -typedef enum attack_kern -{ - ATTACK_KERN_STRAIGHT = 0, - ATTACK_KERN_COMBI = 1, - ATTACK_KERN_BF = 3, - ATTACK_KERN_NONE = 100 - -} attack_kern_t; - -typedef enum attack_exec -{ - ATTACK_EXEC_OUTSIDE_KERNEL = 10, - ATTACK_EXEC_INSIDE_KERNEL = 11 - -} attack_exec_t; - -typedef enum combinator_mode -{ - COMBINATOR_MODE_BASE_LEFT = 10001, - COMBINATOR_MODE_BASE_RIGHT = 10002 - -} combinator_mode_t; - -typedef enum kern_run -{ - KERN_RUN_1 = 1000, - KERN_RUN_12 = 1500, - KERN_RUN_2 = 2000, - KERN_RUN_23 = 2500, - KERN_RUN_3 = 3000 - -} kern_run_t; - -typedef enum kern_run_mp -{ - KERN_RUN_MP = 101, - KERN_RUN_MP_L = 102, - KERN_RUN_MP_R = 103 - -} kern_run_mp_t; - static const char OPTI_STR_ZERO_BYTE[] = "Zero-Byte"; static const char OPTI_STR_PRECOMPUTE_INIT[] = "Precompute-Init"; static const char OPTI_STR_PRECOMPUTE_MERKLE[] = "Precompute-Merkle-Demgard"; @@ -257,17 +172,6 @@ static const char OPTI_STR_USES_BITS_16[] = "Uses-16-Bit"; static const char OPTI_STR_USES_BITS_32[] = "Uses-32-Bit"; static const char OPTI_STR_USES_BITS_64[] = "Uses-64-Bit"; -static const char ST_0000[] = "Initializing"; -static const char ST_0001[] = "Starting"; -static const char ST_0002[] = "Running"; -static const char ST_0003[] = "Paused"; -static const char ST_0004[] = "Exhausted"; -static const char ST_0005[] = "Cracked"; -static const char ST_0006[] = "Aborted"; -static const char ST_0007[] = "Quit"; -static const char ST_0008[] = "Bypass"; -static const char ST_0009[] = "Running (stop at checkpoint)"; -static const char ST_0010[] = "Autotuning"; #if defined (_WIN) @@ -296,12 +200,6 @@ static const char ST_0010[] = "Autotuning"; attr = NULL; \ } -#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) -#define HC_API_CALL __stdcall -#else -#define HC_API_CALL -#endif - static uint default_benchmark_algorithms[NUM_DEFAULT_BENCHMARK_ALGORITHMS] = { 900, @@ -466,10 +364,10 @@ static unsigned int full01 = 0x01010101; static unsigned int full80 = 0x80808080; -static hc_thread_mutex_t mux_adl; + static hc_thread_mutex_t mux_counter; static hc_thread_mutex_t mux_dispatcher; - hc_thread_mutex_t mux_display; + const char *PROMPT = "[s]tatus [p]ause [r]esume [b]ypass [c]heckpoint [q]uit => "; @@ -477,25 +375,7 @@ const char *PROMPT = "[s]tatus [p]ause [r]esume [b]ypass [c]heckpoint [q]uit => * hashcat specific functions */ -char *strstatus (const uint devices_status) -{ - switch (devices_status) - { - case STATUS_INIT: return ((char *) ST_0000); - case STATUS_STARTING: return ((char *) ST_0001); - case STATUS_RUNNING: return ((char *) ST_0002); - case STATUS_PAUSED: return ((char *) ST_0003); - case STATUS_EXHAUSTED: return ((char *) ST_0004); - case STATUS_CRACKED: return ((char *) ST_0005); - case STATUS_ABORTED: return ((char *) ST_0006); - case STATUS_QUIT: return ((char *) ST_0007); - case STATUS_BYPASS: return ((char *) ST_0008); - case STATUS_STOP_AT_CHECKPOINT: return ((char *) ST_0009); - case STATUS_AUTOTUNE: return ((char *) ST_0010); - } - return ((char *) "Unknown"); -} char *stroptitype (const uint opti_type) { @@ -525,1143 +405,8 @@ char *stroptitype (const uint opti_type) return (NULL); } -static double get_avg_exec_time (hc_device_param_t *device_param, const int last_num_entries) -{ - int exec_pos = (int) device_param->exec_pos - last_num_entries; - if (exec_pos < 0) exec_pos += EXEC_CACHE; - double exec_ms_sum = 0; - - int exec_ms_cnt = 0; - - for (int i = 0; i < last_num_entries; i++) - { - double exec_ms = device_param->exec_ms[(exec_pos + i) % EXEC_CACHE]; - - if (exec_ms > 0) - { - exec_ms_sum += exec_ms; - - exec_ms_cnt++; - } - } - - if (exec_ms_cnt == 0) return 0; - - return exec_ms_sum / exec_ms_cnt; -} - -void status_display_machine_readable () -{ - FILE *out = stdout; - - fprintf (out, "STATUS\t%u\t", data.devices_status); - - /** - * speed new - */ - - fprintf (out, "SPEED\t"); - - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) - { - hc_device_param_t *device_param = &data.devices_param[device_id]; - - if (device_param->skipped) continue; - - u64 speed_cnt = 0; - double speed_ms = 0; - - for (int i = 0; i < SPEED_CACHE; i++) - { - speed_cnt += device_param->speed_cnt[i]; - speed_ms += device_param->speed_ms[i]; - } - - speed_cnt /= SPEED_CACHE; - speed_ms /= SPEED_CACHE; - - fprintf (out, "%" PRIu64 "\t%f\t", speed_cnt, speed_ms); - } - - /** - * exec time - */ - - fprintf (out, "EXEC_RUNTIME\t"); - - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) - { - hc_device_param_t *device_param = &data.devices_param[device_id]; - - if (device_param->skipped) continue; - - double exec_ms_avg = get_avg_exec_time (device_param, EXEC_CACHE); - - fprintf (out, "%f\t", exec_ms_avg); - } - - /** - * words_cur - */ - - u64 words_cur = get_lowest_words_done (); - - fprintf (out, "CURKU\t%" PRIu64 "\t", words_cur); - - /** - * counter - */ - - u64 progress_total = data.words_cnt * data.salts_cnt; - - u64 all_done = 0; - u64 all_rejected = 0; - u64 all_restored = 0; - - for (uint salt_pos = 0; salt_pos < data.salts_cnt; salt_pos++) - { - all_done += data.words_progress_done[salt_pos]; - all_rejected += data.words_progress_rejected[salt_pos]; - all_restored += data.words_progress_restored[salt_pos]; - } - - u64 progress_cur = all_restored + all_done + all_rejected; - u64 progress_end = progress_total; - - u64 progress_skip = 0; - - if (data.skip) - { - progress_skip = MIN (data.skip, data.words_base) * data.salts_cnt; - - if (data.attack_kern == ATTACK_KERN_STRAIGHT) progress_skip *= data.kernel_rules_cnt; - else if (data.attack_kern == ATTACK_KERN_COMBI) progress_skip *= data.combs_cnt; - else if (data.attack_kern == ATTACK_KERN_BF) progress_skip *= data.bfs_cnt; - } - - if (data.limit) - { - progress_end = MIN (data.limit, data.words_base) * data.salts_cnt; - - if (data.attack_kern == ATTACK_KERN_STRAIGHT) progress_end *= data.kernel_rules_cnt; - else if (data.attack_kern == ATTACK_KERN_COMBI) progress_end *= data.combs_cnt; - else if (data.attack_kern == ATTACK_KERN_BF) progress_end *= data.bfs_cnt; - } - - u64 progress_cur_relative_skip = progress_cur - progress_skip; - u64 progress_end_relative_skip = progress_end - progress_skip; - - fprintf (out, "PROGRESS\t%" PRIu64 "\t%" PRIu64 "\t", progress_cur_relative_skip, progress_end_relative_skip); - - /** - * cracks - */ - - fprintf (out, "RECHASH\t%u\t%u\t", data.digests_done, data.digests_cnt); - fprintf (out, "RECSALT\t%u\t%u\t", data.salts_done, data.salts_cnt); - - /** - * temperature - */ - - #if defined (HAVE_HWMON) - if (data.gpu_temp_disable == 0) - { - fprintf (out, "TEMP\t"); - - hc_thread_mutex_lock (mux_adl); - - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) - { - hc_device_param_t *device_param = &data.devices_param[device_id]; - - if (device_param->skipped) continue; - - int temp = hm_get_temperature_with_device_id (device_id); - - fprintf (out, "%d\t", temp); - } - - hc_thread_mutex_unlock (mux_adl); - } - #endif // HAVE_HWMON - - /** - * flush - */ - - fputs (EOL, out); - fflush (out); -} - -void status_display () -{ - if (data.devices_status == STATUS_INIT) return; - if (data.devices_status == STATUS_STARTING) return; - - // in this case some required buffers are free'd, ascii_digest() would run into segfault - if (data.shutdown_inner == 1) return; - - if (data.machine_readable == 1) - { - status_display_machine_readable (); - - return; - } - - char tmp_buf[1000] = { 0 }; - - uint tmp_len = 0; - - log_info ("Session.Name...: %s", data.session); - - char *status_type = strstatus (data.devices_status); - - uint hash_mode = data.hash_mode; - - char *hash_type = strhashtype (hash_mode); // not a bug - - log_info ("Status.........: %s", status_type); - - /** - * show rules - */ - - if (data.rp_files_cnt) - { - uint i; - - for (i = 0, tmp_len = 0; i < data.rp_files_cnt - 1 && tmp_len < sizeof (tmp_buf); i++) - { - tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, "File (%s), ", data.rp_files[i]); - } - - snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, "File (%s)", data.rp_files[i]); - - log_info ("Rules.Type.....: %s", tmp_buf); - - tmp_len = 0; - } - - if (data.rp_gen) - { - log_info ("Rules.Type.....: Generated (%u)", data.rp_gen); - - if (data.rp_gen_seed) - { - log_info ("Rules.Seed.....: %u", data.rp_gen_seed); - } - } - - /** - * show input - */ - - if (data.attack_mode == ATTACK_MODE_STRAIGHT) - { - if (data.wordlist_mode == WL_MODE_FILE) - { - if (data.dictfile != NULL) log_info ("Input.Mode.....: File (%s)", data.dictfile); - } - else if (data.wordlist_mode == WL_MODE_STDIN) - { - log_info ("Input.Mode.....: Pipe"); - } - } - else if (data.attack_mode == ATTACK_MODE_COMBI) - { - if (data.dictfile != NULL) log_info ("Input.Left.....: File (%s)", data.dictfile); - if (data.dictfile2 != NULL) log_info ("Input.Right....: File (%s)", data.dictfile2); - } - else if (data.attack_mode == ATTACK_MODE_BF) - { - char *mask = data.mask; - - if (mask != NULL) - { - uint mask_len = data.css_cnt; - - tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, "Mask (%s)", mask); - - if (mask_len > 0) - { - if (data.opti_type & OPTI_TYPE_SINGLE_HASH) - { - if (data.opti_type & OPTI_TYPE_APPENDED_SALT) - { - mask_len -= data.salts_buf[0].salt_len; - } - } - - if (data.opts_type & OPTS_TYPE_PT_UNICODE) mask_len /= 2; - - tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, " [%i]", mask_len); - } - - if (data.maskcnt > 1) - { - double mask_percentage = (double) data.maskpos / (double) data.maskcnt; - - tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, " (%.02f%%)", mask_percentage * 100); - } - - log_info ("Input.Mode.....: %s", tmp_buf); - - if (data.custom_charset_1 || data.custom_charset_2 || data.custom_charset_3 || data.custom_charset_4) - { - char *custom_charset_1 = data.custom_charset_1; - char *custom_charset_2 = data.custom_charset_2; - char *custom_charset_3 = data.custom_charset_3; - char *custom_charset_4 = data.custom_charset_4; - - if (custom_charset_1 == NULL) - { - custom_charset_1 = "Undefined"; - } - if (custom_charset_2 == NULL) - { - custom_charset_2 = "Undefined"; - } - if (custom_charset_3 == NULL) - { - custom_charset_3 = "Undefined"; - } - if (custom_charset_4 == NULL) - { - custom_charset_4 = "Undefined"; - } - - log_info ("Custom.Chars...: -1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4); - } - } - - tmp_len = 0; - } - else if (data.attack_mode == ATTACK_MODE_HYBRID1) - { - if (data.dictfile != NULL) log_info ("Input.Left.....: File (%s)", data.dictfile); - if (data.mask != NULL) log_info ("Input.Right....: Mask (%s) [%i]", data.mask, data.css_cnt); - if (data.custom_charset_1 || data.custom_charset_2 || data.custom_charset_3 || data.custom_charset_4) - { - char *custom_charset_1 = data.custom_charset_1; - char *custom_charset_2 = data.custom_charset_2; - char *custom_charset_3 = data.custom_charset_3; - char *custom_charset_4 = data.custom_charset_4; - - if (custom_charset_1 == NULL) - { - custom_charset_1 = "Undefined"; - } - if (custom_charset_2 == NULL) - { - custom_charset_2 = "Undefined"; - } - if (custom_charset_3 == NULL) - { - custom_charset_3 = "Undefined"; - } - if (custom_charset_4 == NULL) - { - custom_charset_4 = "Undefined"; - } - - log_info ("Custom.Chars...: -1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4); - } - } - else if (data.attack_mode == ATTACK_MODE_HYBRID2) - { - if (data.mask != NULL) log_info ("Input.Left.....: Mask (%s) [%i]", data.mask, data.css_cnt); - if (data.dictfile != NULL) log_info ("Input.Right....: File (%s)", data.dictfile); - if (data.custom_charset_1 || data.custom_charset_2 || data.custom_charset_3 || data.custom_charset_4) - { - char *custom_charset_1 = data.custom_charset_1; - char *custom_charset_2 = data.custom_charset_2; - char *custom_charset_3 = data.custom_charset_3; - char *custom_charset_4 = data.custom_charset_4; - - if (custom_charset_1 == NULL) - { - custom_charset_1 = "Undefined"; - } - if (custom_charset_2 == NULL) - { - custom_charset_2 = "Undefined"; - } - if (custom_charset_3 == NULL) - { - custom_charset_3 = "Undefined"; - } - if (custom_charset_4 == NULL) - { - custom_charset_4 = "Undefined"; - } - - log_info ("Custom.Chars...: -1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4); - } - } - - if (data.digests_cnt == 1) - { - if (data.hash_mode == 2500) - { - wpa_t *wpa = (wpa_t *) data.esalts_buf; - - log_info ("Hash.Target....: %s (%02x:%02x:%02x:%02x:%02x:%02x <-> %02x:%02x:%02x:%02x:%02x:%02x)", - (char *) data.salts_buf[0].salt_buf, - wpa->orig_mac1[0], - wpa->orig_mac1[1], - wpa->orig_mac1[2], - wpa->orig_mac1[3], - wpa->orig_mac1[4], - wpa->orig_mac1[5], - wpa->orig_mac2[0], - wpa->orig_mac2[1], - wpa->orig_mac2[2], - wpa->orig_mac2[3], - wpa->orig_mac2[4], - wpa->orig_mac2[5]); - } - else if (data.hash_mode == 5200) - { - log_info ("Hash.Target....: File (%s)", data.hashfile); - } - else if (data.hash_mode == 9000) - { - log_info ("Hash.Target....: File (%s)", data.hashfile); - } - else if ((data.hash_mode >= 6200) && (data.hash_mode <= 6299)) - { - log_info ("Hash.Target....: File (%s)", data.hashfile); - } - else if ((data.hash_mode >= 13700) && (data.hash_mode <= 13799)) - { - log_info ("Hash.Target....: File (%s)", data.hashfile); - } - else - { - char out_buf[HCBUFSIZ] = { 0 }; - - ascii_digest (out_buf, 0, 0); - - // limit length - if (strlen (out_buf) > 40) - { - out_buf[41] = '.'; - out_buf[42] = '.'; - out_buf[43] = '.'; - out_buf[44] = 0; - } - - log_info ("Hash.Target....: %s", out_buf); - } - } - else - { - if (data.hash_mode == 3000) - { - char out_buf1[32] = { 0 }; - char out_buf2[32] = { 0 }; - - ascii_digest (out_buf1, 0, 0); - ascii_digest (out_buf2, 0, 1); - - log_info ("Hash.Target....: %s, %s", out_buf1, out_buf2); - } - else - { - log_info ("Hash.Target....: File (%s)", data.hashfile); - } - } - - log_info ("Hash.Type......: %s", hash_type); - - /** - * speed new - */ - - u64 speed_cnt[DEVICES_MAX] = { 0 }; - double speed_ms[DEVICES_MAX] = { 0 }; - - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) - { - hc_device_param_t *device_param = &data.devices_param[device_id]; - - if (device_param->skipped) continue; - - speed_cnt[device_id] = 0; - speed_ms[device_id] = 0; - - for (int i = 0; i < SPEED_CACHE; i++) - { - speed_cnt[device_id] += device_param->speed_cnt[i]; - speed_ms[device_id] += device_param->speed_ms[i]; - } - - speed_cnt[device_id] /= SPEED_CACHE; - speed_ms[device_id] /= SPEED_CACHE; - } - - double hashes_all_ms = 0; - - double hashes_dev_ms[DEVICES_MAX] = { 0 }; - - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) - { - hc_device_param_t *device_param = &data.devices_param[device_id]; - - if (device_param->skipped) continue; - - hashes_dev_ms[device_id] = 0; - - if (speed_ms[device_id] > 0) - { - hashes_dev_ms[device_id] = (double) speed_cnt[device_id] / speed_ms[device_id]; - - hashes_all_ms += hashes_dev_ms[device_id]; - } - } - - /** - * exec time - */ - - double exec_all_ms[DEVICES_MAX] = { 0 }; - - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) - { - hc_device_param_t *device_param = &data.devices_param[device_id]; - - if (device_param->skipped) continue; - - double exec_ms_avg = get_avg_exec_time (device_param, EXEC_CACHE); - - exec_all_ms[device_id] = exec_ms_avg; - } - - /** - * timers - */ - - double ms_running = 0; - - hc_timer_get (data.timer_running, ms_running); - - double ms_paused = data.ms_paused; - - if (data.devices_status == STATUS_PAUSED) - { - double ms_paused_tmp = 0; - - hc_timer_get (data.timer_paused, ms_paused_tmp); - - ms_paused += ms_paused_tmp; - } - - #if defined (_WIN) - - __time64_t sec_run = (__time64_t) ms_running / 1000; - - #else - - time_t sec_run = (time_t) ms_running / 1000; - - #endif - - if (sec_run) - { - char display_run[32] = { 0 }; - - struct tm tm_run; - - struct tm *tmp = NULL; - - #if defined (_WIN) - - tmp = _gmtime64 (&sec_run); - - #else - - tmp = gmtime (&sec_run); - - #endif - - if (tmp != NULL) - { - memset (&tm_run, 0, sizeof (tm_run)); - - memcpy (&tm_run, tmp, sizeof (tm_run)); - - format_timer_display (&tm_run, display_run, sizeof (tm_run)); - - char *start = ctime (&data.proc_start); - - size_t start_len = strlen (start); - - if (start[start_len - 1] == '\n') start[start_len - 1] = 0; - if (start[start_len - 2] == '\r') start[start_len - 2] = 0; - - log_info ("Time.Started...: %s (%s)", start, display_run); - } - } - else - { - log_info ("Time.Started...: 0 secs"); - } - - /** - * counters - */ - - u64 progress_total = data.words_cnt * data.salts_cnt; - - u64 all_done = 0; - u64 all_rejected = 0; - u64 all_restored = 0; - - u64 progress_noneed = 0; - - for (uint salt_pos = 0; salt_pos < data.salts_cnt; salt_pos++) - { - all_done += data.words_progress_done[salt_pos]; - all_rejected += data.words_progress_rejected[salt_pos]; - all_restored += data.words_progress_restored[salt_pos]; - - // Important for ETA only - - if (data.salts_shown[salt_pos] == 1) - { - const u64 all = data.words_progress_done[salt_pos] - + data.words_progress_rejected[salt_pos] - + data.words_progress_restored[salt_pos]; - - const u64 left = data.words_cnt - all; - - progress_noneed += left; - } - } - - u64 progress_cur = all_restored + all_done + all_rejected; - u64 progress_end = progress_total; - - u64 progress_skip = 0; - - if (data.skip) - { - progress_skip = MIN (data.skip, data.words_base) * data.salts_cnt; - - if (data.attack_kern == ATTACK_KERN_STRAIGHT) progress_skip *= data.kernel_rules_cnt; - else if (data.attack_kern == ATTACK_KERN_COMBI) progress_skip *= data.combs_cnt; - else if (data.attack_kern == ATTACK_KERN_BF) progress_skip *= data.bfs_cnt; - } - - if (data.limit) - { - progress_end = MIN (data.limit, data.words_base) * data.salts_cnt; - - if (data.attack_kern == ATTACK_KERN_STRAIGHT) progress_end *= data.kernel_rules_cnt; - else if (data.attack_kern == ATTACK_KERN_COMBI) progress_end *= data.combs_cnt; - else if (data.attack_kern == ATTACK_KERN_BF) progress_end *= data.bfs_cnt; - } - - u64 progress_cur_relative_skip = progress_cur - progress_skip; - u64 progress_end_relative_skip = progress_end - progress_skip; - - if ((data.wordlist_mode == WL_MODE_FILE) || (data.wordlist_mode == WL_MODE_MASK)) - { - if (data.devices_status != STATUS_CRACKED) - { - #if defined (_WIN) - __time64_t sec_etc = 0; - #else - time_t sec_etc = 0; - #endif - - if (hashes_all_ms > 0) - { - u64 progress_left_relative_skip = progress_end_relative_skip - progress_cur_relative_skip; - - u64 ms_left = (u64) ((progress_left_relative_skip - progress_noneed) / hashes_all_ms); - - sec_etc = ms_left / 1000; - } - - if (sec_etc == 0) - { - //log_info ("Time.Estimated.: 0 secs"); - } - else if ((u64) sec_etc > ETC_MAX) - { - log_info ("Time.Estimated.: > 10 Years"); - } - else - { - char display_etc[32] = { 0 }; - char display_runtime[32] = { 0 }; - - struct tm tm_etc; - struct tm tm_runtime; - - struct tm *tmp = NULL; - - #if defined (_WIN) - tmp = _gmtime64 (&sec_etc); - #else - tmp = gmtime (&sec_etc); - #endif - - if (tmp != NULL) - { - memcpy (&tm_etc, tmp, sizeof (tm_etc)); - - format_timer_display (&tm_etc, display_etc, sizeof (display_etc)); - - time_t now; - - time (&now); - - now += sec_etc; - - char *etc = ctime (&now); - - size_t etc_len = strlen (etc); - - if (etc[etc_len - 1] == '\n') etc[etc_len - 1] = 0; - if (etc[etc_len - 2] == '\r') etc[etc_len - 2] = 0; - - if (data.runtime) - { - time_t runtime_cur; - - time (&runtime_cur); - - #if defined (_WIN) - - __time64_t runtime_left = data.proc_start + data.runtime + data.prepare_time + (ms_paused / 1000) - runtime_cur; - - tmp = _gmtime64 (&runtime_left); - - #else - - time_t runtime_left = data.proc_start + data.runtime + data.prepare_time + (ms_paused / 1000) - runtime_cur; - - tmp = gmtime (&runtime_left); - - #endif - - if ((tmp != NULL) && (runtime_left > 0) && (runtime_left < sec_etc)) - { - memcpy (&tm_runtime, tmp, sizeof (tm_runtime)); - - format_timer_display (&tm_runtime, display_runtime, sizeof (display_runtime)); - - log_info ("Time.Estimated.: %s (%s), but limited (%s)", etc, display_etc, display_runtime); - } - else - { - log_info ("Time.Estimated.: %s (%s), but limit exceeded", etc, display_etc); - } - } - else - { - log_info ("Time.Estimated.: %s (%s)", etc, display_etc); - } - } - } - } - } - - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) - { - hc_device_param_t *device_param = &data.devices_param[device_id]; - - if (device_param->skipped) continue; - - char display_dev_cur[16] = { 0 }; - - strncpy (display_dev_cur, "0.00", 4); - - format_speed_display (hashes_dev_ms[device_id] * 1000, display_dev_cur, sizeof (display_dev_cur)); - - log_info ("Speed.Dev.#%d...: %9sH/s (%0.2fms)", device_id + 1, display_dev_cur, exec_all_ms[device_id]); - } - - char display_all_cur[16] = { 0 }; - - strncpy (display_all_cur, "0.00", 4); - - format_speed_display (hashes_all_ms * 1000, display_all_cur, sizeof (display_all_cur)); - - if (data.devices_active > 1) log_info ("Speed.Dev.#*...: %9sH/s", display_all_cur); - - const double digests_percent = (double) data.digests_done / data.digests_cnt; - const double salts_percent = (double) data.salts_done / data.salts_cnt; - - log_info ("Recovered......: %u/%u (%.2f%%) Digests, %u/%u (%.2f%%) Salts", data.digests_done, data.digests_cnt, digests_percent * 100, data.salts_done, data.salts_cnt, salts_percent * 100); - - // crack-per-time - - if (data.digests_cnt > 100) - { - time_t now = time (NULL); - - int cpt_cur_min = 0; - int cpt_cur_hour = 0; - int cpt_cur_day = 0; - - for (int i = 0; i < CPT_BUF; i++) - { - const uint cracked = data.cpt_buf[i].cracked; - const time_t timestamp = data.cpt_buf[i].timestamp; - - if ((timestamp + 60) > now) - { - cpt_cur_min += cracked; - } - - if ((timestamp + 3600) > now) - { - cpt_cur_hour += cracked; - } - - if ((timestamp + 86400) > now) - { - cpt_cur_day += cracked; - } - } - - double ms_real = ms_running - ms_paused; - - double cpt_avg_min = (double) data.cpt_total / ((ms_real / 1000) / 60); - double cpt_avg_hour = (double) data.cpt_total / ((ms_real / 1000) / 3600); - double cpt_avg_day = (double) data.cpt_total / ((ms_real / 1000) / 86400); - - if ((data.cpt_start + 86400) < now) - { - log_info ("Recovered/Time.: CUR:%" PRIu64 ",%" PRIu64 ",%" PRIu64 " AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", - cpt_cur_min, - cpt_cur_hour, - cpt_cur_day, - cpt_avg_min, - cpt_avg_hour, - cpt_avg_day); - } - else if ((data.cpt_start + 3600) < now) - { - log_info ("Recovered/Time.: CUR:%" PRIu64 ",%" PRIu64 ",N/A AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", - cpt_cur_min, - cpt_cur_hour, - cpt_avg_min, - cpt_avg_hour, - cpt_avg_day); - } - else if ((data.cpt_start + 60) < now) - { - log_info ("Recovered/Time.: CUR:%" PRIu64 ",N/A,N/A AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", - cpt_cur_min, - cpt_avg_min, - cpt_avg_hour, - cpt_avg_day); - } - else - { - log_info ("Recovered/Time.: CUR:N/A,N/A,N/A AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", - cpt_avg_min, - cpt_avg_hour, - cpt_avg_day); - } - } - - // Restore point - - u64 restore_point = get_lowest_words_done (); - - u64 restore_total = data.words_base; - - double percent_restore = 0; - - if (restore_total != 0) percent_restore = (double) restore_point / (double) restore_total; - - if (progress_end_relative_skip) - { - if ((data.wordlist_mode == WL_MODE_FILE) || (data.wordlist_mode == WL_MODE_MASK)) - { - double percent_finished = (double) progress_cur_relative_skip / (double) progress_end_relative_skip; - double percent_rejected = 0.0; - - if (progress_cur) - { - percent_rejected = (double) (all_rejected) / (double) progress_cur; - } - - log_info ("Progress.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", progress_cur_relative_skip, progress_end_relative_skip, percent_finished * 100); - log_info ("Rejected.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", all_rejected, progress_cur_relative_skip, percent_rejected * 100); - - if (data.restore_disable == 0) - { - if (percent_finished != 1) - { - log_info ("Restore.Point..: %" PRIu64 "/%" PRIu64 " (%.02f%%)", restore_point, restore_total, percent_restore * 100); - } - } - } - } - else - { - if ((data.wordlist_mode == WL_MODE_FILE) || (data.wordlist_mode == WL_MODE_MASK)) - { - log_info ("Progress.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); - log_info ("Rejected.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); - - if (data.restore_disable == 0) - { - log_info ("Restore.Point..: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); - } - } - else - { - log_info ("Progress.......: %" PRIu64 "", progress_cur_relative_skip); - log_info ("Rejected.......: %" PRIu64 "", all_rejected); - - // --restore not allowed if stdin is used -- really? why? - - //if (data.restore_disable == 0) - //{ - // log_info ("Restore.Point..: %" PRIu64 "", restore_point); - //} - } - } - - #if defined (HAVE_HWMON) - - if (data.devices_status == STATUS_EXHAUSTED) return; - if (data.devices_status == STATUS_CRACKED) return; - if (data.devices_status == STATUS_ABORTED) return; - if (data.devices_status == STATUS_QUIT) return; - - if (data.gpu_temp_disable == 0) - { - hc_thread_mutex_lock (mux_adl); - - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) - { - hc_device_param_t *device_param = &data.devices_param[device_id]; - - if (device_param->skipped) continue; - - const int num_temperature = hm_get_temperature_with_device_id (device_id); - const int num_fanspeed = hm_get_fanspeed_with_device_id (device_id); - const int num_utilization = hm_get_utilization_with_device_id (device_id); - const int num_corespeed = hm_get_corespeed_with_device_id (device_id); - const int num_memoryspeed = hm_get_memoryspeed_with_device_id (device_id); - const int num_buslanes = hm_get_buslanes_with_device_id (device_id); - const int num_throttle = hm_get_throttle_with_device_id (device_id); - - char output_buf[256] = { 0 }; - - int output_len = 0; - - if (num_temperature >= 0) - { - snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Temp:%3uc", num_temperature); - - output_len = strlen (output_buf); - } - - if (num_fanspeed >= 0) - { - snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Fan:%3u%%", num_fanspeed); - - output_len = strlen (output_buf); - } - - if (num_utilization >= 0) - { - snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Util:%3u%%", num_utilization); - - output_len = strlen (output_buf); - } - - if (num_corespeed >= 0) - { - snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Core:%4uMhz", num_corespeed); - - output_len = strlen (output_buf); - } - - if (num_memoryspeed >= 0) - { - snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Mem:%4uMhz", num_memoryspeed); - - output_len = strlen (output_buf); - } - - if (num_buslanes >= 0) - { - snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Lanes:%u", num_buslanes); - - output_len = strlen (output_buf); - } - - if (num_throttle == 1) - { - snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " *Throttled*"); - - output_len = strlen (output_buf); - } - - if (output_len == 0) - { - snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " N/A"); - - output_len = strlen (output_buf); - } - - log_info ("HWMon.Dev.#%d...:%s", device_id + 1, output_buf); - } - - hc_thread_mutex_unlock (mux_adl); - } - - #endif // HAVE_HWMON -} - -static void status_benchmark_automate () -{ - u64 speed_cnt[DEVICES_MAX] = { 0 }; - double speed_ms[DEVICES_MAX] = { 0 }; - - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) - { - hc_device_param_t *device_param = &data.devices_param[device_id]; - - if (device_param->skipped) continue; - - speed_cnt[device_id] = device_param->speed_cnt[0]; - speed_ms[device_id] = device_param->speed_ms[0]; - } - - double hashes_dev_ms[DEVICES_MAX] = { 0 }; - - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) - { - hc_device_param_t *device_param = &data.devices_param[device_id]; - - if (device_param->skipped) continue; - - hashes_dev_ms[device_id] = 0; - - if (speed_ms[device_id] > 0) - { - hashes_dev_ms[device_id] = (double) speed_cnt[device_id] / speed_ms[device_id]; - } - } - - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) - { - hc_device_param_t *device_param = &data.devices_param[device_id]; - - if (device_param->skipped) continue; - - log_info ("%u:%u:%" PRIu64 "", device_id + 1, data.hash_mode, (hashes_dev_ms[device_id] * 1000)); - } -} - -static void status_benchmark () -{ - if (data.devices_status == STATUS_INIT) return; - if (data.devices_status == STATUS_STARTING) return; - - if (data.shutdown_inner == 1) return; - - if (data.machine_readable == 1) - { - status_benchmark_automate (); - - return; - } - - u64 speed_cnt[DEVICES_MAX] = { 0 }; - double speed_ms[DEVICES_MAX] = { 0 }; - - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) - { - hc_device_param_t *device_param = &data.devices_param[device_id]; - - if (device_param->skipped) continue; - - speed_cnt[device_id] = device_param->speed_cnt[0]; - speed_ms[device_id] = device_param->speed_ms[0]; - } - - double hashes_all_ms = 0; - - double hashes_dev_ms[DEVICES_MAX] = { 0 }; - - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) - { - hc_device_param_t *device_param = &data.devices_param[device_id]; - - if (device_param->skipped) continue; - - hashes_dev_ms[device_id] = 0; - - if (speed_ms[device_id] > 0) - { - hashes_dev_ms[device_id] = (double) speed_cnt[device_id] / speed_ms[device_id]; - - hashes_all_ms += hashes_dev_ms[device_id]; - } - } - - /** - * exec time - */ - - double exec_all_ms[DEVICES_MAX] = { 0 }; - - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) - { - hc_device_param_t *device_param = &data.devices_param[device_id]; - - if (device_param->skipped) continue; - - double exec_ms_avg = get_avg_exec_time (device_param, EXEC_CACHE); - - exec_all_ms[device_id] = exec_ms_avg; - } - - for (uint device_id = 0; device_id < data.devices_cnt; device_id++) - { - hc_device_param_t *device_param = &data.devices_param[device_id]; - - if (device_param->skipped) continue; - - char display_dev_cur[16] = { 0 }; - - strncpy (display_dev_cur, "0.00", 4); - - format_speed_display (hashes_dev_ms[device_id] * 1000, display_dev_cur, sizeof (display_dev_cur)); - - if (data.devices_active >= 10) - { - log_info ("Speed.Dev.#%d: %9sH/s (%0.2fms)", device_id + 1, display_dev_cur, exec_all_ms[device_id]); - } - else - { - log_info ("Speed.Dev.#%d.: %9sH/s (%0.2fms)", device_id + 1, display_dev_cur, exec_all_ms[device_id]); - } - } - - char display_all_cur[16] = { 0 }; - - strncpy (display_all_cur, "0.00", 4); - - format_speed_display (hashes_all_ms * 1000, display_all_cur, sizeof (display_all_cur)); - - if (data.devices_active > 1) log_info ("Speed.Dev.#*.: %9sH/s", display_all_cur); -} /** * hashcat -only- functions @@ -4386,7 +3131,7 @@ static void *thread_monitor (void *p) if (hwmon_check == 1) { - hc_thread_mutex_lock (mux_adl); + hc_thread_mutex_lock (mux_hwmon); for (uint device_id = 0; device_id < data.devices_cnt; device_id++) { @@ -4440,12 +3185,12 @@ static void *thread_monitor (void *p) } } - hc_thread_mutex_unlock (mux_adl); + hc_thread_mutex_unlock (mux_hwmon); } if (hwmon_check == 1) { - hc_thread_mutex_lock (mux_adl); + hc_thread_mutex_lock (mux_hwmon); time_t temp_check_time; @@ -4543,7 +3288,7 @@ static void *thread_monitor (void *p) } } - hc_thread_mutex_unlock (mux_adl); + hc_thread_mutex_unlock (mux_hwmon); } #endif // HAVE_HWMON @@ -5036,6 +3781,79 @@ static uint get_work (hc_device_param_t *device_param, const u64 max) return work; } +static void SuspendThreads () +{ + if (data.devices_status != STATUS_RUNNING) return; + + hc_timer_set (&data.timer_paused); + + data.devices_status = STATUS_PAUSED; + + log_info ("Paused"); +} + +static void ResumeThreads () +{ + if (data.devices_status != STATUS_PAUSED) return; + + double ms_paused; + + hc_timer_get (data.timer_paused, ms_paused); + + data.ms_paused += ms_paused; + + data.devices_status = STATUS_RUNNING; + + log_info ("Resumed"); +} + +static void bypass () +{ + data.devices_status = STATUS_BYPASS; + + log_info ("Next dictionary / mask in queue selected, bypassing current one"); +} + +static void stop_at_checkpoint () +{ + if (data.devices_status != STATUS_STOP_AT_CHECKPOINT) + { + if (data.devices_status != STATUS_RUNNING) return; + } + + // this feature only makes sense if --restore-disable was not specified + + if (data.restore_disable == 1) + { + log_info ("WARNING: This feature is disabled when --restore-disable is specified"); + + return; + } + + // check if monitoring of Restore Point updates should be enabled or disabled + + if (data.devices_status != STATUS_STOP_AT_CHECKPOINT) + { + data.devices_status = STATUS_STOP_AT_CHECKPOINT; + + // save the current restore point value + + data.checkpoint_cur_words = get_lowest_words_done (); + + log_info ("Checkpoint enabled: Will quit at next Restore Point update"); + } + else + { + data.devices_status = STATUS_RUNNING; + + // reset the global value for checkpoint checks + + data.checkpoint_cur_words = 0; + + log_info ("Checkpoint disabled: Restore Point updates will no longer be monitored"); + } +} + static void *thread_autotune (void *p) { hc_device_param_t *device_param = (hc_device_param_t *) p; @@ -5466,6 +4284,120 @@ static void *thread_calc (void *p) return NULL; } +static void *thread_keypress (void *p) +{ + uint quiet = data.quiet; + + tty_break(); + + while (data.shutdown_outer == 0) + { + int ch = tty_getchar(); + + if (ch == -1) break; + + if (ch == 0) continue; + + //https://github.com/hashcat/hashcat/issues/302 + //#if defined (_POSIX) + //if (ch != '\n') + //#endif + + hc_thread_mutex_lock (mux_display); + + log_info (""); + + switch (ch) + { + case 's': + case '\r': + case '\n': + + log_info (""); + + status_display (); + + log_info (""); + + if (quiet == 0) fprintf (stdout, "%s", PROMPT); + if (quiet == 0) fflush (stdout); + + break; + + case 'b': + + log_info (""); + + bypass (); + + log_info (""); + + if (quiet == 0) fprintf (stdout, "%s", PROMPT); + if (quiet == 0) fflush (stdout); + + break; + + case 'p': + + log_info (""); + + SuspendThreads (); + + log_info (""); + + if (quiet == 0) fprintf (stdout, "%s", PROMPT); + if (quiet == 0) fflush (stdout); + + break; + + case 'r': + + log_info (""); + + ResumeThreads (); + + log_info (""); + + if (quiet == 0) fprintf (stdout, "%s", PROMPT); + if (quiet == 0) fflush (stdout); + + break; + + case 'c': + + log_info (""); + + stop_at_checkpoint (); + + log_info (""); + + if (quiet == 0) fprintf (stdout, "%s", PROMPT); + if (quiet == 0) fflush (stdout); + + break; + + case 'q': + + log_info (""); + + myabort (); + + break; + } + + //https://github.com/hashcat/hashcat/issues/302 + //#if defined (_POSIX) + //if (ch != '\n') + //#endif + + hc_thread_mutex_unlock (mux_display); + } + + tty_fix(); + + return (p); +} + static void weak_hash_check (hc_device_param_t *device_param, const uint salt_pos) { if (!device_param) @@ -5899,48 +4831,7 @@ static uint hlfmt_detect (FILE *fp, uint max_check) return hashlist_format; } -/** - * some further helper function - */ -// wrapper around mymalloc for ADL - -#if defined(HAVE_HWMON) -static void *HC_API_CALL ADL_Main_Memory_Alloc (const int iSize) -{ - return mymalloc (iSize); -} -#endif - -/** - * main - */ - -#if defined (_WIN) -static void SetConsoleWindowSize (const int x) -{ - HANDLE h = GetStdHandle (STD_OUTPUT_HANDLE); - - if (h == INVALID_HANDLE_VALUE) return; - - CONSOLE_SCREEN_BUFFER_INFO bufferInfo; - - if (!GetConsoleScreenBufferInfo (h, &bufferInfo)) return; - - SMALL_RECT *sr = &bufferInfo.srWindow; - - sr->Right = MAX (sr->Right, x - 1); - - COORD co; - - co.X = sr->Right + 1; - co.Y = 9999; - - if (!SetConsoleScreenBufferSize (h, co)) return; - - if (!SetConsoleWindowInfo (h, TRUE, sr)) return; -} -#endif int main (int argc, char **argv) { @@ -6023,7 +4914,7 @@ int main (int argc, char **argv) hc_thread_mutex_init (mux_dispatcher); hc_thread_mutex_init (mux_counter); hc_thread_mutex_init (mux_display); - hc_thread_mutex_init (mux_adl); + hc_thread_mutex_init (mux_hwmon); /** * commandline parameters @@ -15211,7 +14102,7 @@ int main (int argc, char **argv) if (num_adl_adapters > 0) { - hc_thread_mutex_lock (mux_adl); + hc_thread_mutex_lock (mux_hwmon); // hm_get_opencl_busid_devid (hm_adapters_adl, devices_all_cnt, devices_all); @@ -15220,7 +14111,7 @@ int main (int argc, char **argv) hm_get_overdrive_version (data.hm_adl, hm_adapters_adl, valid_adl_device_list, num_adl_adapters, lpAdapterInfo); hm_check_fanspeed_control (data.hm_adl, hm_adapters_adl, valid_adl_device_list, num_adl_adapters, lpAdapterInfo); - hc_thread_mutex_unlock (mux_adl); + hc_thread_mutex_unlock (mux_hwmon); } myfree (valid_adl_device_list); @@ -15389,7 +14280,7 @@ int main (int argc, char **argv) if (powertune_enable == 1) { - hc_thread_mutex_lock (mux_adl); + hc_thread_mutex_lock (mux_hwmon); for (uint device_id = 0; device_id < data.devices_cnt; device_id++) { @@ -15573,7 +14464,7 @@ int main (int argc, char **argv) } } - hc_thread_mutex_unlock (mux_adl); + hc_thread_mutex_unlock (mux_hwmon); } #endif // HAVE_HWMON @@ -17538,7 +16429,7 @@ int main (int argc, char **argv) { if (gpu_temp_retain != 0) { - hc_thread_mutex_lock (mux_adl); + hc_thread_mutex_lock (mux_hwmon); if (data.hm_device[device_id].fan_get_supported == 1) { @@ -17586,7 +16477,7 @@ int main (int argc, char **argv) } } - hc_thread_mutex_unlock (mux_adl); + hc_thread_mutex_unlock (mux_hwmon); } } @@ -19814,7 +18705,7 @@ int main (int argc, char **argv) { if (gpu_temp_retain != 0) { - hc_thread_mutex_lock (mux_adl); + hc_thread_mutex_lock (mux_hwmon); for (uint device_id = 0; device_id < data.devices_cnt; device_id++) { @@ -19845,7 +18736,7 @@ int main (int argc, char **argv) } } - hc_thread_mutex_unlock (mux_adl); + hc_thread_mutex_unlock (mux_hwmon); } } @@ -19853,7 +18744,7 @@ int main (int argc, char **argv) if (powertune_enable == 1) { - hc_thread_mutex_lock (mux_adl); + hc_thread_mutex_lock (mux_hwmon); for (uint device_id = 0; device_id < data.devices_cnt; device_id++) { @@ -19921,7 +18812,7 @@ int main (int argc, char **argv) } } - hc_thread_mutex_unlock (mux_adl); + hc_thread_mutex_unlock (mux_hwmon); } if (gpu_temp_disable == 0) @@ -20048,7 +18939,7 @@ int main (int argc, char **argv) hc_thread_mutex_delete (mux_dispatcher); hc_thread_mutex_delete (mux_counter); hc_thread_mutex_delete (mux_display); - hc_thread_mutex_delete (mux_adl); + hc_thread_mutex_delete (mux_hwmon); // free memory diff --git a/src/hwmon.c b/src/hwmon.c index 5da2e7c01..45f2ac0f3 100644 --- a/src/hwmon.c +++ b/src/hwmon.c @@ -21,10 +21,13 @@ #include "rp_cpu.h" #include "restore.h" #include "opencl.h" +#include "thread.h" #include "data.h" #if defined (HAVE_HWMON) +hc_thread_mutex_t mux_hwmon; + extern hc_global_data_t data; int get_adapters_num_adl (void *adl, int *iNumberAdapters) diff --git a/src/shared.c b/src/shared.c index 995311138..740345ab3 100644 --- a/src/shared.c +++ b/src/shared.c @@ -25,16 +25,45 @@ #include "locking.h" #include "thread.h" #include "rp_cpu.h" -#include "terminal.h" #include "hwmon.h" #include "mpsp.h" #include "rp_cpu.h" #include "opencl.h" #include "restore.h" #include "data.h" +#include "status.h" #include "shared.h" extern hc_global_data_t data; +extern hc_thread_mutex_t mux_display; + +double get_avg_exec_time (hc_device_param_t *device_param, const int last_num_entries) +{ + int exec_pos = (int) device_param->exec_pos - last_num_entries; + + if (exec_pos < 0) exec_pos += EXEC_CACHE; + + double exec_ms_sum = 0; + + int exec_ms_cnt = 0; + + for (int i = 0; i < last_num_entries; i++) + { + double exec_ms = device_param->exec_ms[(exec_pos + i) % EXEC_CACHE]; + + if (exec_ms > 0) + { + exec_ms_sum += exec_ms; + + exec_ms_cnt++; + } + } + + if (exec_ms_cnt == 0) return 0; + + return exec_ms_sum / exec_ms_cnt; +} + void *rulefind (const void *key, void *base, int nmemb, size_t size, int (*compar) (const void *, const void *)) { @@ -971,78 +1000,7 @@ void format_speed_display (double val, char *buf, size_t len) -static void SuspendThreads () -{ - if (data.devices_status != STATUS_RUNNING) return; - hc_timer_set (&data.timer_paused); - - data.devices_status = STATUS_PAUSED; - - log_info ("Paused"); -} - -static void ResumeThreads () -{ - if (data.devices_status != STATUS_PAUSED) return; - - double ms_paused; - - hc_timer_get (data.timer_paused, ms_paused); - - data.ms_paused += ms_paused; - - data.devices_status = STATUS_RUNNING; - - log_info ("Resumed"); -} - -static void bypass () -{ - data.devices_status = STATUS_BYPASS; - - log_info ("Next dictionary / mask in queue selected, bypassing current one"); -} - -static void stop_at_checkpoint () -{ - if (data.devices_status != STATUS_STOP_AT_CHECKPOINT) - { - if (data.devices_status != STATUS_RUNNING) return; - } - - // this feature only makes sense if --restore-disable was not specified - - if (data.restore_disable == 1) - { - log_info ("WARNING: This feature is disabled when --restore-disable is specified"); - - return; - } - - // check if monitoring of Restore Point updates should be enabled or disabled - - if (data.devices_status != STATUS_STOP_AT_CHECKPOINT) - { - data.devices_status = STATUS_STOP_AT_CHECKPOINT; - - // save the current restore point value - - data.checkpoint_cur_words = get_lowest_words_done (); - - log_info ("Checkpoint enabled: Will quit at next Restore Point update"); - } - else - { - data.devices_status = STATUS_RUNNING; - - // reset the global value for checkpoint checks - - data.checkpoint_cur_words = 0; - - log_info ("Checkpoint disabled: Restore Point updates will no longer be monitored"); - } -} void myabort () { @@ -1222,118 +1180,3 @@ void hc_signal (void (callback) (int)) #endif -void status_display (); - -void *thread_keypress (void *p) -{ - uint quiet = data.quiet; - - tty_break(); - - while (data.shutdown_outer == 0) - { - int ch = tty_getchar(); - - if (ch == -1) break; - - if (ch == 0) continue; - - //https://github.com/hashcat/hashcat/issues/302 - //#if defined (_POSIX) - //if (ch != '\n') - //#endif - - hc_thread_mutex_lock (mux_display); - - log_info (""); - - switch (ch) - { - case 's': - case '\r': - case '\n': - - log_info (""); - - status_display (); - - log_info (""); - - if (quiet == 0) fprintf (stdout, "%s", PROMPT); - if (quiet == 0) fflush (stdout); - - break; - - case 'b': - - log_info (""); - - bypass (); - - log_info (""); - - if (quiet == 0) fprintf (stdout, "%s", PROMPT); - if (quiet == 0) fflush (stdout); - - break; - - case 'p': - - log_info (""); - - SuspendThreads (); - - log_info (""); - - if (quiet == 0) fprintf (stdout, "%s", PROMPT); - if (quiet == 0) fflush (stdout); - - break; - - case 'r': - - log_info (""); - - ResumeThreads (); - - log_info (""); - - if (quiet == 0) fprintf (stdout, "%s", PROMPT); - if (quiet == 0) fflush (stdout); - - break; - - case 'c': - - log_info (""); - - stop_at_checkpoint (); - - log_info (""); - - if (quiet == 0) fprintf (stdout, "%s", PROMPT); - if (quiet == 0) fflush (stdout); - - break; - - case 'q': - - log_info (""); - - myabort (); - - break; - } - - //https://github.com/hashcat/hashcat/issues/302 - //#if defined (_POSIX) - //if (ch != '\n') - //#endif - - hc_thread_mutex_unlock (mux_display); - } - - tty_fix(); - - return (p); -} diff --git a/src/status.c b/src/status.c new file mode 100644 index 000000000..c3f8d5fb2 --- /dev/null +++ b/src/status.c @@ -0,0 +1,1175 @@ +/** + * Author......: Jens Steube + * License.....: MIT + */ + +#include "common.h" +#include "types_int.h" +#include "types.h" +#include "timer.h" +#include "memory.h" +#include "logging.h" +#include "ext_OpenCL.h" +#include "ext_ADL.h" +#include "ext_nvapi.h" +#include "ext_nvml.h" +#include "ext_xnvctrl.h" +#include "thread.h" +#include "rp_cpu.h" +#include "terminal.h" +#include "hwmon.h" +#include "mpsp.h" +#include "opencl.h" +#include "restore.h" +#include "data.h" +#include "shared.h" +#include "interface.h" +#include "status.h" + +static const char ST_0000[] = "Initializing"; +static const char ST_0001[] = "Starting"; +static const char ST_0002[] = "Running"; +static const char ST_0003[] = "Paused"; +static const char ST_0004[] = "Exhausted"; +static const char ST_0005[] = "Cracked"; +static const char ST_0006[] = "Aborted"; +static const char ST_0007[] = "Quit"; +static const char ST_0008[] = "Bypass"; +static const char ST_0009[] = "Running (stop at checkpoint)"; +static const char ST_0010[] = "Autotuning"; + +extern hc_global_data_t data; +extern hc_thread_mutex_t mux_hwmon; + +hc_thread_mutex_t mux_display; + +char *strstatus (const uint devices_status) +{ + switch (devices_status) + { + case STATUS_INIT: return ((char *) ST_0000); + case STATUS_STARTING: return ((char *) ST_0001); + case STATUS_RUNNING: return ((char *) ST_0002); + case STATUS_PAUSED: return ((char *) ST_0003); + case STATUS_EXHAUSTED: return ((char *) ST_0004); + case STATUS_CRACKED: return ((char *) ST_0005); + case STATUS_ABORTED: return ((char *) ST_0006); + case STATUS_QUIT: return ((char *) ST_0007); + case STATUS_BYPASS: return ((char *) ST_0008); + case STATUS_STOP_AT_CHECKPOINT: return ((char *) ST_0009); + case STATUS_AUTOTUNE: return ((char *) ST_0010); + } + + return ((char *) "Unknown"); +} + +void status_display_machine_readable () +{ + FILE *out = stdout; + + fprintf (out, "STATUS\t%u\t", data.devices_status); + + /** + * speed new + */ + + fprintf (out, "SPEED\t"); + + for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + { + hc_device_param_t *device_param = &data.devices_param[device_id]; + + if (device_param->skipped) continue; + + u64 speed_cnt = 0; + double speed_ms = 0; + + for (int i = 0; i < SPEED_CACHE; i++) + { + speed_cnt += device_param->speed_cnt[i]; + speed_ms += device_param->speed_ms[i]; + } + + speed_cnt /= SPEED_CACHE; + speed_ms /= SPEED_CACHE; + + fprintf (out, "%" PRIu64 "\t%f\t", speed_cnt, speed_ms); + } + + /** + * exec time + */ + + fprintf (out, "EXEC_RUNTIME\t"); + + for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + { + hc_device_param_t *device_param = &data.devices_param[device_id]; + + if (device_param->skipped) continue; + + double exec_ms_avg = get_avg_exec_time (device_param, EXEC_CACHE); + + fprintf (out, "%f\t", exec_ms_avg); + } + + /** + * words_cur + */ + + u64 words_cur = get_lowest_words_done (); + + fprintf (out, "CURKU\t%" PRIu64 "\t", words_cur); + + /** + * counter + */ + + u64 progress_total = data.words_cnt * data.salts_cnt; + + u64 all_done = 0; + u64 all_rejected = 0; + u64 all_restored = 0; + + for (uint salt_pos = 0; salt_pos < data.salts_cnt; salt_pos++) + { + all_done += data.words_progress_done[salt_pos]; + all_rejected += data.words_progress_rejected[salt_pos]; + all_restored += data.words_progress_restored[salt_pos]; + } + + u64 progress_cur = all_restored + all_done + all_rejected; + u64 progress_end = progress_total; + + u64 progress_skip = 0; + + if (data.skip) + { + progress_skip = MIN (data.skip, data.words_base) * data.salts_cnt; + + if (data.attack_kern == ATTACK_KERN_STRAIGHT) progress_skip *= data.kernel_rules_cnt; + else if (data.attack_kern == ATTACK_KERN_COMBI) progress_skip *= data.combs_cnt; + else if (data.attack_kern == ATTACK_KERN_BF) progress_skip *= data.bfs_cnt; + } + + if (data.limit) + { + progress_end = MIN (data.limit, data.words_base) * data.salts_cnt; + + if (data.attack_kern == ATTACK_KERN_STRAIGHT) progress_end *= data.kernel_rules_cnt; + else if (data.attack_kern == ATTACK_KERN_COMBI) progress_end *= data.combs_cnt; + else if (data.attack_kern == ATTACK_KERN_BF) progress_end *= data.bfs_cnt; + } + + u64 progress_cur_relative_skip = progress_cur - progress_skip; + u64 progress_end_relative_skip = progress_end - progress_skip; + + fprintf (out, "PROGRESS\t%" PRIu64 "\t%" PRIu64 "\t", progress_cur_relative_skip, progress_end_relative_skip); + + /** + * cracks + */ + + fprintf (out, "RECHASH\t%u\t%u\t", data.digests_done, data.digests_cnt); + fprintf (out, "RECSALT\t%u\t%u\t", data.salts_done, data.salts_cnt); + + /** + * temperature + */ + + #if defined (HAVE_HWMON) + if (data.gpu_temp_disable == 0) + { + fprintf (out, "TEMP\t"); + + hc_thread_mutex_lock (mux_hwmon); + + for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + { + hc_device_param_t *device_param = &data.devices_param[device_id]; + + if (device_param->skipped) continue; + + int temp = hm_get_temperature_with_device_id (device_id); + + fprintf (out, "%d\t", temp); + } + + hc_thread_mutex_unlock (mux_hwmon); + } + #endif // HAVE_HWMON + + /** + * flush + */ + + fputs (EOL, out); + fflush (out); +} + +void status_display () +{ + if (data.devices_status == STATUS_INIT) return; + if (data.devices_status == STATUS_STARTING) return; + + // in this case some required buffers are free'd, ascii_digest() would run into segfault + if (data.shutdown_inner == 1) return; + + if (data.machine_readable == 1) + { + status_display_machine_readable (); + + return; + } + + char tmp_buf[1000] = { 0 }; + + uint tmp_len = 0; + + log_info ("Session.Name...: %s", data.session); + + char *status_type = strstatus (data.devices_status); + + uint hash_mode = data.hash_mode; + + char *hash_type = strhashtype (hash_mode); // not a bug + + log_info ("Status.........: %s", status_type); + + /** + * show rules + */ + + if (data.rp_files_cnt) + { + uint i; + + for (i = 0, tmp_len = 0; i < data.rp_files_cnt - 1 && tmp_len < sizeof (tmp_buf); i++) + { + tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, "File (%s), ", data.rp_files[i]); + } + + snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, "File (%s)", data.rp_files[i]); + + log_info ("Rules.Type.....: %s", tmp_buf); + + tmp_len = 0; + } + + if (data.rp_gen) + { + log_info ("Rules.Type.....: Generated (%u)", data.rp_gen); + + if (data.rp_gen_seed) + { + log_info ("Rules.Seed.....: %u", data.rp_gen_seed); + } + } + + /** + * show input + */ + + if (data.attack_mode == ATTACK_MODE_STRAIGHT) + { + if (data.wordlist_mode == WL_MODE_FILE) + { + if (data.dictfile != NULL) log_info ("Input.Mode.....: File (%s)", data.dictfile); + } + else if (data.wordlist_mode == WL_MODE_STDIN) + { + log_info ("Input.Mode.....: Pipe"); + } + } + else if (data.attack_mode == ATTACK_MODE_COMBI) + { + if (data.dictfile != NULL) log_info ("Input.Left.....: File (%s)", data.dictfile); + if (data.dictfile2 != NULL) log_info ("Input.Right....: File (%s)", data.dictfile2); + } + else if (data.attack_mode == ATTACK_MODE_BF) + { + char *mask = data.mask; + + if (mask != NULL) + { + uint mask_len = data.css_cnt; + + tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, "Mask (%s)", mask); + + if (mask_len > 0) + { + if (data.opti_type & OPTI_TYPE_SINGLE_HASH) + { + if (data.opti_type & OPTI_TYPE_APPENDED_SALT) + { + mask_len -= data.salts_buf[0].salt_len; + } + } + + if (data.opts_type & OPTS_TYPE_PT_UNICODE) mask_len /= 2; + + tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, " [%i]", mask_len); + } + + if (data.maskcnt > 1) + { + double mask_percentage = (double) data.maskpos / (double) data.maskcnt; + + tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, " (%.02f%%)", mask_percentage * 100); + } + + log_info ("Input.Mode.....: %s", tmp_buf); + + if (data.custom_charset_1 || data.custom_charset_2 || data.custom_charset_3 || data.custom_charset_4) + { + char *custom_charset_1 = data.custom_charset_1; + char *custom_charset_2 = data.custom_charset_2; + char *custom_charset_3 = data.custom_charset_3; + char *custom_charset_4 = data.custom_charset_4; + + if (custom_charset_1 == NULL) + { + custom_charset_1 = "Undefined"; + } + if (custom_charset_2 == NULL) + { + custom_charset_2 = "Undefined"; + } + if (custom_charset_3 == NULL) + { + custom_charset_3 = "Undefined"; + } + if (custom_charset_4 == NULL) + { + custom_charset_4 = "Undefined"; + } + + log_info ("Custom.Chars...: -1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4); + } + } + + tmp_len = 0; + } + else if (data.attack_mode == ATTACK_MODE_HYBRID1) + { + if (data.dictfile != NULL) log_info ("Input.Left.....: File (%s)", data.dictfile); + if (data.mask != NULL) log_info ("Input.Right....: Mask (%s) [%i]", data.mask, data.css_cnt); + if (data.custom_charset_1 || data.custom_charset_2 || data.custom_charset_3 || data.custom_charset_4) + { + char *custom_charset_1 = data.custom_charset_1; + char *custom_charset_2 = data.custom_charset_2; + char *custom_charset_3 = data.custom_charset_3; + char *custom_charset_4 = data.custom_charset_4; + + if (custom_charset_1 == NULL) + { + custom_charset_1 = "Undefined"; + } + if (custom_charset_2 == NULL) + { + custom_charset_2 = "Undefined"; + } + if (custom_charset_3 == NULL) + { + custom_charset_3 = "Undefined"; + } + if (custom_charset_4 == NULL) + { + custom_charset_4 = "Undefined"; + } + + log_info ("Custom.Chars...: -1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4); + } + } + else if (data.attack_mode == ATTACK_MODE_HYBRID2) + { + if (data.mask != NULL) log_info ("Input.Left.....: Mask (%s) [%i]", data.mask, data.css_cnt); + if (data.dictfile != NULL) log_info ("Input.Right....: File (%s)", data.dictfile); + if (data.custom_charset_1 || data.custom_charset_2 || data.custom_charset_3 || data.custom_charset_4) + { + char *custom_charset_1 = data.custom_charset_1; + char *custom_charset_2 = data.custom_charset_2; + char *custom_charset_3 = data.custom_charset_3; + char *custom_charset_4 = data.custom_charset_4; + + if (custom_charset_1 == NULL) + { + custom_charset_1 = "Undefined"; + } + if (custom_charset_2 == NULL) + { + custom_charset_2 = "Undefined"; + } + if (custom_charset_3 == NULL) + { + custom_charset_3 = "Undefined"; + } + if (custom_charset_4 == NULL) + { + custom_charset_4 = "Undefined"; + } + + log_info ("Custom.Chars...: -1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4); + } + } + + if (data.digests_cnt == 1) + { + if (data.hash_mode == 2500) + { + wpa_t *wpa = (wpa_t *) data.esalts_buf; + + log_info ("Hash.Target....: %s (%02x:%02x:%02x:%02x:%02x:%02x <-> %02x:%02x:%02x:%02x:%02x:%02x)", + (char *) data.salts_buf[0].salt_buf, + wpa->orig_mac1[0], + wpa->orig_mac1[1], + wpa->orig_mac1[2], + wpa->orig_mac1[3], + wpa->orig_mac1[4], + wpa->orig_mac1[5], + wpa->orig_mac2[0], + wpa->orig_mac2[1], + wpa->orig_mac2[2], + wpa->orig_mac2[3], + wpa->orig_mac2[4], + wpa->orig_mac2[5]); + } + else if (data.hash_mode == 5200) + { + log_info ("Hash.Target....: File (%s)", data.hashfile); + } + else if (data.hash_mode == 9000) + { + log_info ("Hash.Target....: File (%s)", data.hashfile); + } + else if ((data.hash_mode >= 6200) && (data.hash_mode <= 6299)) + { + log_info ("Hash.Target....: File (%s)", data.hashfile); + } + else if ((data.hash_mode >= 13700) && (data.hash_mode <= 13799)) + { + log_info ("Hash.Target....: File (%s)", data.hashfile); + } + else + { + char out_buf[HCBUFSIZ] = { 0 }; + + ascii_digest (out_buf, 0, 0); + + // limit length + if (strlen (out_buf) > 40) + { + out_buf[41] = '.'; + out_buf[42] = '.'; + out_buf[43] = '.'; + out_buf[44] = 0; + } + + log_info ("Hash.Target....: %s", out_buf); + } + } + else + { + if (data.hash_mode == 3000) + { + char out_buf1[32] = { 0 }; + char out_buf2[32] = { 0 }; + + ascii_digest (out_buf1, 0, 0); + ascii_digest (out_buf2, 0, 1); + + log_info ("Hash.Target....: %s, %s", out_buf1, out_buf2); + } + else + { + log_info ("Hash.Target....: File (%s)", data.hashfile); + } + } + + log_info ("Hash.Type......: %s", hash_type); + + /** + * speed new + */ + + u64 speed_cnt[DEVICES_MAX] = { 0 }; + double speed_ms[DEVICES_MAX] = { 0 }; + + for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + { + hc_device_param_t *device_param = &data.devices_param[device_id]; + + if (device_param->skipped) continue; + + speed_cnt[device_id] = 0; + speed_ms[device_id] = 0; + + for (int i = 0; i < SPEED_CACHE; i++) + { + speed_cnt[device_id] += device_param->speed_cnt[i]; + speed_ms[device_id] += device_param->speed_ms[i]; + } + + speed_cnt[device_id] /= SPEED_CACHE; + speed_ms[device_id] /= SPEED_CACHE; + } + + double hashes_all_ms = 0; + + double hashes_dev_ms[DEVICES_MAX] = { 0 }; + + for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + { + hc_device_param_t *device_param = &data.devices_param[device_id]; + + if (device_param->skipped) continue; + + hashes_dev_ms[device_id] = 0; + + if (speed_ms[device_id] > 0) + { + hashes_dev_ms[device_id] = (double) speed_cnt[device_id] / speed_ms[device_id]; + + hashes_all_ms += hashes_dev_ms[device_id]; + } + } + + /** + * exec time + */ + + double exec_all_ms[DEVICES_MAX] = { 0 }; + + for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + { + hc_device_param_t *device_param = &data.devices_param[device_id]; + + if (device_param->skipped) continue; + + double exec_ms_avg = get_avg_exec_time (device_param, EXEC_CACHE); + + exec_all_ms[device_id] = exec_ms_avg; + } + + /** + * timers + */ + + double ms_running = 0; + + hc_timer_get (data.timer_running, ms_running); + + double ms_paused = data.ms_paused; + + if (data.devices_status == STATUS_PAUSED) + { + double ms_paused_tmp = 0; + + hc_timer_get (data.timer_paused, ms_paused_tmp); + + ms_paused += ms_paused_tmp; + } + + #if defined (_WIN) + + __time64_t sec_run = (__time64_t) ms_running / 1000; + + #else + + time_t sec_run = (time_t) ms_running / 1000; + + #endif + + if (sec_run) + { + char display_run[32] = { 0 }; + + struct tm tm_run; + + struct tm *tmp = NULL; + + #if defined (_WIN) + + tmp = _gmtime64 (&sec_run); + + #else + + tmp = gmtime (&sec_run); + + #endif + + if (tmp != NULL) + { + memset (&tm_run, 0, sizeof (tm_run)); + + memcpy (&tm_run, tmp, sizeof (tm_run)); + + format_timer_display (&tm_run, display_run, sizeof (tm_run)); + + char *start = ctime (&data.proc_start); + + size_t start_len = strlen (start); + + if (start[start_len - 1] == '\n') start[start_len - 1] = 0; + if (start[start_len - 2] == '\r') start[start_len - 2] = 0; + + log_info ("Time.Started...: %s (%s)", start, display_run); + } + } + else + { + log_info ("Time.Started...: 0 secs"); + } + + /** + * counters + */ + + u64 progress_total = data.words_cnt * data.salts_cnt; + + u64 all_done = 0; + u64 all_rejected = 0; + u64 all_restored = 0; + + u64 progress_noneed = 0; + + for (uint salt_pos = 0; salt_pos < data.salts_cnt; salt_pos++) + { + all_done += data.words_progress_done[salt_pos]; + all_rejected += data.words_progress_rejected[salt_pos]; + all_restored += data.words_progress_restored[salt_pos]; + + // Important for ETA only + + if (data.salts_shown[salt_pos] == 1) + { + const u64 all = data.words_progress_done[salt_pos] + + data.words_progress_rejected[salt_pos] + + data.words_progress_restored[salt_pos]; + + const u64 left = data.words_cnt - all; + + progress_noneed += left; + } + } + + u64 progress_cur = all_restored + all_done + all_rejected; + u64 progress_end = progress_total; + + u64 progress_skip = 0; + + if (data.skip) + { + progress_skip = MIN (data.skip, data.words_base) * data.salts_cnt; + + if (data.attack_kern == ATTACK_KERN_STRAIGHT) progress_skip *= data.kernel_rules_cnt; + else if (data.attack_kern == ATTACK_KERN_COMBI) progress_skip *= data.combs_cnt; + else if (data.attack_kern == ATTACK_KERN_BF) progress_skip *= data.bfs_cnt; + } + + if (data.limit) + { + progress_end = MIN (data.limit, data.words_base) * data.salts_cnt; + + if (data.attack_kern == ATTACK_KERN_STRAIGHT) progress_end *= data.kernel_rules_cnt; + else if (data.attack_kern == ATTACK_KERN_COMBI) progress_end *= data.combs_cnt; + else if (data.attack_kern == ATTACK_KERN_BF) progress_end *= data.bfs_cnt; + } + + u64 progress_cur_relative_skip = progress_cur - progress_skip; + u64 progress_end_relative_skip = progress_end - progress_skip; + + if ((data.wordlist_mode == WL_MODE_FILE) || (data.wordlist_mode == WL_MODE_MASK)) + { + if (data.devices_status != STATUS_CRACKED) + { + #if defined (_WIN) + __time64_t sec_etc = 0; + #else + time_t sec_etc = 0; + #endif + + if (hashes_all_ms > 0) + { + u64 progress_left_relative_skip = progress_end_relative_skip - progress_cur_relative_skip; + + u64 ms_left = (u64) ((progress_left_relative_skip - progress_noneed) / hashes_all_ms); + + sec_etc = ms_left / 1000; + } + + if (sec_etc == 0) + { + //log_info ("Time.Estimated.: 0 secs"); + } + else if ((u64) sec_etc > ETC_MAX) + { + log_info ("Time.Estimated.: > 10 Years"); + } + else + { + char display_etc[32] = { 0 }; + char display_runtime[32] = { 0 }; + + struct tm tm_etc; + struct tm tm_runtime; + + struct tm *tmp = NULL; + + #if defined (_WIN) + tmp = _gmtime64 (&sec_etc); + #else + tmp = gmtime (&sec_etc); + #endif + + if (tmp != NULL) + { + memcpy (&tm_etc, tmp, sizeof (tm_etc)); + + format_timer_display (&tm_etc, display_etc, sizeof (display_etc)); + + time_t now; + + time (&now); + + now += sec_etc; + + char *etc = ctime (&now); + + size_t etc_len = strlen (etc); + + if (etc[etc_len - 1] == '\n') etc[etc_len - 1] = 0; + if (etc[etc_len - 2] == '\r') etc[etc_len - 2] = 0; + + if (data.runtime) + { + time_t runtime_cur; + + time (&runtime_cur); + + #if defined (_WIN) + + __time64_t runtime_left = data.proc_start + data.runtime + data.prepare_time + (ms_paused / 1000) - runtime_cur; + + tmp = _gmtime64 (&runtime_left); + + #else + + time_t runtime_left = data.proc_start + data.runtime + data.prepare_time + (ms_paused / 1000) - runtime_cur; + + tmp = gmtime (&runtime_left); + + #endif + + if ((tmp != NULL) && (runtime_left > 0) && (runtime_left < sec_etc)) + { + memcpy (&tm_runtime, tmp, sizeof (tm_runtime)); + + format_timer_display (&tm_runtime, display_runtime, sizeof (display_runtime)); + + log_info ("Time.Estimated.: %s (%s), but limited (%s)", etc, display_etc, display_runtime); + } + else + { + log_info ("Time.Estimated.: %s (%s), but limit exceeded", etc, display_etc); + } + } + else + { + log_info ("Time.Estimated.: %s (%s)", etc, display_etc); + } + } + } + } + } + + for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + { + hc_device_param_t *device_param = &data.devices_param[device_id]; + + if (device_param->skipped) continue; + + char display_dev_cur[16] = { 0 }; + + strncpy (display_dev_cur, "0.00", 4); + + format_speed_display (hashes_dev_ms[device_id] * 1000, display_dev_cur, sizeof (display_dev_cur)); + + log_info ("Speed.Dev.#%d...: %9sH/s (%0.2fms)", device_id + 1, display_dev_cur, exec_all_ms[device_id]); + } + + char display_all_cur[16] = { 0 }; + + strncpy (display_all_cur, "0.00", 4); + + format_speed_display (hashes_all_ms * 1000, display_all_cur, sizeof (display_all_cur)); + + if (data.devices_active > 1) log_info ("Speed.Dev.#*...: %9sH/s", display_all_cur); + + const double digests_percent = (double) data.digests_done / data.digests_cnt; + const double salts_percent = (double) data.salts_done / data.salts_cnt; + + log_info ("Recovered......: %u/%u (%.2f%%) Digests, %u/%u (%.2f%%) Salts", data.digests_done, data.digests_cnt, digests_percent * 100, data.salts_done, data.salts_cnt, salts_percent * 100); + + // crack-per-time + + if (data.digests_cnt > 100) + { + time_t now = time (NULL); + + int cpt_cur_min = 0; + int cpt_cur_hour = 0; + int cpt_cur_day = 0; + + for (int i = 0; i < CPT_BUF; i++) + { + const uint cracked = data.cpt_buf[i].cracked; + const time_t timestamp = data.cpt_buf[i].timestamp; + + if ((timestamp + 60) > now) + { + cpt_cur_min += cracked; + } + + if ((timestamp + 3600) > now) + { + cpt_cur_hour += cracked; + } + + if ((timestamp + 86400) > now) + { + cpt_cur_day += cracked; + } + } + + double ms_real = ms_running - ms_paused; + + double cpt_avg_min = (double) data.cpt_total / ((ms_real / 1000) / 60); + double cpt_avg_hour = (double) data.cpt_total / ((ms_real / 1000) / 3600); + double cpt_avg_day = (double) data.cpt_total / ((ms_real / 1000) / 86400); + + if ((data.cpt_start + 86400) < now) + { + log_info ("Recovered/Time.: CUR:%" PRIu64 ",%" PRIu64 ",%" PRIu64 " AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", + cpt_cur_min, + cpt_cur_hour, + cpt_cur_day, + cpt_avg_min, + cpt_avg_hour, + cpt_avg_day); + } + else if ((data.cpt_start + 3600) < now) + { + log_info ("Recovered/Time.: CUR:%" PRIu64 ",%" PRIu64 ",N/A AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", + cpt_cur_min, + cpt_cur_hour, + cpt_avg_min, + cpt_avg_hour, + cpt_avg_day); + } + else if ((data.cpt_start + 60) < now) + { + log_info ("Recovered/Time.: CUR:%" PRIu64 ",N/A,N/A AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", + cpt_cur_min, + cpt_avg_min, + cpt_avg_hour, + cpt_avg_day); + } + else + { + log_info ("Recovered/Time.: CUR:N/A,N/A,N/A AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", + cpt_avg_min, + cpt_avg_hour, + cpt_avg_day); + } + } + + // Restore point + + u64 restore_point = get_lowest_words_done (); + + u64 restore_total = data.words_base; + + double percent_restore = 0; + + if (restore_total != 0) percent_restore = (double) restore_point / (double) restore_total; + + if (progress_end_relative_skip) + { + if ((data.wordlist_mode == WL_MODE_FILE) || (data.wordlist_mode == WL_MODE_MASK)) + { + double percent_finished = (double) progress_cur_relative_skip / (double) progress_end_relative_skip; + double percent_rejected = 0.0; + + if (progress_cur) + { + percent_rejected = (double) (all_rejected) / (double) progress_cur; + } + + log_info ("Progress.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", progress_cur_relative_skip, progress_end_relative_skip, percent_finished * 100); + log_info ("Rejected.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", all_rejected, progress_cur_relative_skip, percent_rejected * 100); + + if (data.restore_disable == 0) + { + if (percent_finished != 1) + { + log_info ("Restore.Point..: %" PRIu64 "/%" PRIu64 " (%.02f%%)", restore_point, restore_total, percent_restore * 100); + } + } + } + } + else + { + if ((data.wordlist_mode == WL_MODE_FILE) || (data.wordlist_mode == WL_MODE_MASK)) + { + log_info ("Progress.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); + log_info ("Rejected.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); + + if (data.restore_disable == 0) + { + log_info ("Restore.Point..: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); + } + } + else + { + log_info ("Progress.......: %" PRIu64 "", progress_cur_relative_skip); + log_info ("Rejected.......: %" PRIu64 "", all_rejected); + + // --restore not allowed if stdin is used -- really? why? + + //if (data.restore_disable == 0) + //{ + // log_info ("Restore.Point..: %" PRIu64 "", restore_point); + //} + } + } + + #if defined (HAVE_HWMON) + + if (data.devices_status == STATUS_EXHAUSTED) return; + if (data.devices_status == STATUS_CRACKED) return; + if (data.devices_status == STATUS_ABORTED) return; + if (data.devices_status == STATUS_QUIT) return; + + if (data.gpu_temp_disable == 0) + { + hc_thread_mutex_lock (mux_hwmon); + + for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + { + hc_device_param_t *device_param = &data.devices_param[device_id]; + + if (device_param->skipped) continue; + + const int num_temperature = hm_get_temperature_with_device_id (device_id); + const int num_fanspeed = hm_get_fanspeed_with_device_id (device_id); + const int num_utilization = hm_get_utilization_with_device_id (device_id); + const int num_corespeed = hm_get_corespeed_with_device_id (device_id); + const int num_memoryspeed = hm_get_memoryspeed_with_device_id (device_id); + const int num_buslanes = hm_get_buslanes_with_device_id (device_id); + const int num_throttle = hm_get_throttle_with_device_id (device_id); + + char output_buf[256] = { 0 }; + + int output_len = 0; + + if (num_temperature >= 0) + { + snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Temp:%3uc", num_temperature); + + output_len = strlen (output_buf); + } + + if (num_fanspeed >= 0) + { + snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Fan:%3u%%", num_fanspeed); + + output_len = strlen (output_buf); + } + + if (num_utilization >= 0) + { + snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Util:%3u%%", num_utilization); + + output_len = strlen (output_buf); + } + + if (num_corespeed >= 0) + { + snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Core:%4uMhz", num_corespeed); + + output_len = strlen (output_buf); + } + + if (num_memoryspeed >= 0) + { + snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Mem:%4uMhz", num_memoryspeed); + + output_len = strlen (output_buf); + } + + if (num_buslanes >= 0) + { + snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " Lanes:%u", num_buslanes); + + output_len = strlen (output_buf); + } + + if (num_throttle == 1) + { + snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " *Throttled*"); + + output_len = strlen (output_buf); + } + + if (output_len == 0) + { + snprintf (output_buf + output_len, sizeof (output_buf) - output_len, " N/A"); + + output_len = strlen (output_buf); + } + + log_info ("HWMon.Dev.#%d...:%s", device_id + 1, output_buf); + } + + hc_thread_mutex_unlock (mux_hwmon); + } + + #endif // HAVE_HWMON +} + +void status_benchmark_automate () +{ + u64 speed_cnt[DEVICES_MAX] = { 0 }; + double speed_ms[DEVICES_MAX] = { 0 }; + + for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + { + hc_device_param_t *device_param = &data.devices_param[device_id]; + + if (device_param->skipped) continue; + + speed_cnt[device_id] = device_param->speed_cnt[0]; + speed_ms[device_id] = device_param->speed_ms[0]; + } + + double hashes_dev_ms[DEVICES_MAX] = { 0 }; + + for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + { + hc_device_param_t *device_param = &data.devices_param[device_id]; + + if (device_param->skipped) continue; + + hashes_dev_ms[device_id] = 0; + + if (speed_ms[device_id] > 0) + { + hashes_dev_ms[device_id] = (double) speed_cnt[device_id] / speed_ms[device_id]; + } + } + + for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + { + hc_device_param_t *device_param = &data.devices_param[device_id]; + + if (device_param->skipped) continue; + + log_info ("%u:%u:%" PRIu64 "", device_id + 1, data.hash_mode, (hashes_dev_ms[device_id] * 1000)); + } +} + +void status_benchmark () +{ + if (data.devices_status == STATUS_INIT) return; + if (data.devices_status == STATUS_STARTING) return; + + if (data.shutdown_inner == 1) return; + + if (data.machine_readable == 1) + { + status_benchmark_automate (); + + return; + } + + u64 speed_cnt[DEVICES_MAX] = { 0 }; + double speed_ms[DEVICES_MAX] = { 0 }; + + for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + { + hc_device_param_t *device_param = &data.devices_param[device_id]; + + if (device_param->skipped) continue; + + speed_cnt[device_id] = device_param->speed_cnt[0]; + speed_ms[device_id] = device_param->speed_ms[0]; + } + + double hashes_all_ms = 0; + + double hashes_dev_ms[DEVICES_MAX] = { 0 }; + + for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + { + hc_device_param_t *device_param = &data.devices_param[device_id]; + + if (device_param->skipped) continue; + + hashes_dev_ms[device_id] = 0; + + if (speed_ms[device_id] > 0) + { + hashes_dev_ms[device_id] = (double) speed_cnt[device_id] / speed_ms[device_id]; + + hashes_all_ms += hashes_dev_ms[device_id]; + } + } + + /** + * exec time + */ + + double exec_all_ms[DEVICES_MAX] = { 0 }; + + for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + { + hc_device_param_t *device_param = &data.devices_param[device_id]; + + if (device_param->skipped) continue; + + double exec_ms_avg = get_avg_exec_time (device_param, EXEC_CACHE); + + exec_all_ms[device_id] = exec_ms_avg; + } + + for (uint device_id = 0; device_id < data.devices_cnt; device_id++) + { + hc_device_param_t *device_param = &data.devices_param[device_id]; + + if (device_param->skipped) continue; + + char display_dev_cur[16] = { 0 }; + + strncpy (display_dev_cur, "0.00", 4); + + format_speed_display (hashes_dev_ms[device_id] * 1000, display_dev_cur, sizeof (display_dev_cur)); + + if (data.devices_active >= 10) + { + log_info ("Speed.Dev.#%d: %9sH/s (%0.2fms)", device_id + 1, display_dev_cur, exec_all_ms[device_id]); + } + else + { + log_info ("Speed.Dev.#%d.: %9sH/s (%0.2fms)", device_id + 1, display_dev_cur, exec_all_ms[device_id]); + } + } + + char display_all_cur[16] = { 0 }; + + strncpy (display_all_cur, "0.00", 4); + + format_speed_display (hashes_all_ms * 1000, display_all_cur, sizeof (display_all_cur)); + + if (data.devices_active > 1) log_info ("Speed.Dev.#*.: %9sH/s", display_all_cur); +} diff --git a/src/terminal.c b/src/terminal.c index d3d6ef6eb..9b1b2dbd2 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -6,6 +6,32 @@ #include "common.h" #include "terminal.h" +#if defined (_WIN) +void SetConsoleWindowSize (const int x) +{ + HANDLE h = GetStdHandle (STD_OUTPUT_HANDLE); + + if (h == INVALID_HANDLE_VALUE) return; + + CONSOLE_SCREEN_BUFFER_INFO bufferInfo; + + if (!GetConsoleScreenBufferInfo (h, &bufferInfo)) return; + + SMALL_RECT *sr = &bufferInfo.srWindow; + + sr->Right = MAX (sr->Right, x - 1); + + COORD co; + + co.X = sr->Right + 1; + co.Y = 9999; + + if (!SetConsoleScreenBufferSize (h, co)) return; + + if (!SetConsoleWindowInfo (h, TRUE, sr)) return; +} +#endif + #if defined (__linux__) static struct termios savemodes; static int havemodes = 0;