diff --git a/OpenCL/inc_vendor.cl b/OpenCL/inc_vendor.cl index 8469c0661..14bcbebed 100644 --- a/OpenCL/inc_vendor.cl +++ b/OpenCL/inc_vendor.cl @@ -89,9 +89,15 @@ #if KERN_TYPE == 6223 #undef _unroll #endif +#if KERN_TYPE == 6400 +#undef _unroll +#endif #if KERN_TYPE == 6500 #undef _unroll #endif +#if KERN_TYPE == 6800 +#undef _unroll +#endif #if KERN_TYPE == 7100 #undef _unroll #endif @@ -104,6 +110,9 @@ #if KERN_TYPE == 8200 #undef _unroll #endif +#if KERN_TYPE == 8900 +#undef _unroll +#endif #if KERN_TYPE == 10400 #undef _unroll #endif @@ -113,12 +122,18 @@ #if KERN_TYPE == 10700 #undef _unroll #endif +#if KERN_TYPE == 10900 +#undef _unroll +#endif #if KERN_TYPE == 12300 #undef _unroll #endif #if KERN_TYPE == 12400 #undef _unroll #endif +#if KERN_TYPE == 12900 +#undef _unroll +#endif #if KERN_TYPE == 13721 #undef _unroll #endif @@ -128,6 +143,15 @@ #if KERN_TYPE == 13723 #undef _unroll #endif +#if KERN_TYPE == 13751 +#undef _unroll +#endif +#if KERN_TYPE == 13752 +#undef _unroll +#endif +#if KERN_TYPE == 13753 +#undef _unroll +#endif #if KERN_TYPE == 14000 #undef _unroll #endif diff --git a/OpenCL/m01800.cl b/OpenCL/m01800.cl index e295e70be..985844971 100644 --- a/OpenCL/m01800.cl +++ b/OpenCL/m01800.cl @@ -58,7 +58,7 @@ __constant u64 k_sha512[80] = SHA512C4c, SHA512C4d, SHA512C4e, SHA512C4f, }; -void sha512_transform (const u64 w[16], u64 digest[8]) +void sha512_transform (const u64 *w, u64 *digest) { u64 w0_t = w[ 0]; u64 w1_t = w[ 1]; diff --git a/OpenCL/m10700.cl b/OpenCL/m10700.cl index 5eaa72f8f..2219ed466 100644 --- a/OpenCL/m10700.cl +++ b/OpenCL/m10700.cl @@ -54,7 +54,7 @@ __constant u32 k_sha256[64] = SHA256C3c, SHA256C3d, SHA256C3e, SHA256C3f, }; -void sha256_transform (const u32 w0[4], const u32 w1[4], const u32 w2[4], const u32 w3[4], u32 digest[8]) +void sha256_transform (const u32 *w0, const u32 *w1, const u32 *w2, const u32 *w3, u32 *digest) { u32 a = digest[0]; u32 b = digest[1]; @@ -166,7 +166,7 @@ __constant u64 k_sha384[80] = SHA384C4c, SHA384C4d, SHA384C4e, SHA384C4f, }; -void sha384_transform (const u64 w0[4], const u64 w1[4], const u64 w2[4], const u64 w3[4], u64 digest[8]) +void sha384_transform (const u32 *w0, const u32 *w1, const u32 *w2, const u32 *w3, u32 *digest) { u64 a = digest[0]; u64 b = digest[1]; @@ -278,7 +278,7 @@ __constant u64 k_sha512[80] = SHA384C4c, SHA384C4d, SHA384C4e, SHA384C4f, }; -void sha512_transform (const u64 w0[4], const u64 w1[4], const u64 w2[4], const u64 w3[4], u64 digest[8]) +void sha512_transform (const u32 *w0, const u32 *w1, const u32 *w2, const u32 *w3, u32 *digest) { u64 a = digest[0]; u64 b = digest[1]; diff --git a/docs/changes.txt b/docs/changes.txt index ee36109cb..2e0ee1824 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -4,6 +4,7 @@ ## Improvements ## +- Added support for --speed-only: quickly shows expected speed per device based on the users hash(es) and option selected - Added the current first and last password candidate test queued for execution per device on status view - Use .gitmodules to handle OpenCL headers depency - Allow loading of bcrypt hashes with signature $2b$ (February 2014) @@ -13,6 +14,8 @@ - Added docs/team.txt - Allow words of length > 32 in wordlists for -a 0 for slow hashes if no rules are in use or a : rule is in the rulefile - Reduce max. number of allowed function calls per rule from 256 to 32 to save GPU memory +- Status display shows what's the base and modifier keyspace currently in use +- Added a workaround for some OpenCL kernel to compile with amd-gpu-pro ## ## Algorithms diff --git a/extra/tab_completion/hashcat.sh b/extra/tab_completion/hashcat.sh index 979a04856..3b027b72a 100644 --- a/extra/tab_completion/hashcat.sh +++ b/extra/tab_completion/hashcat.sh @@ -188,7 +188,7 @@ _hashcat () local BUILD_IN_CHARSETS='?l ?u ?d ?a ?b ?s' local SHORT_OPTS="-m -a -V -v -h -b -t -o -p -c -d -w -n -u -j -k -r -g -1 -2 -3 -4 -i -I -s -l" - local LONG_OPTS="--hash-type --attack-mode --version --help --eula --quiet --benchmark --benchmark-repeats --hex-salt --hex-wordlist --hex-charset --force --status --status-timer --machine-readable --loopback --weak-hash-threshold --markov-hcstat --markov-disable --markov-classic --markov-threshold --runtime --session --restore --restore-disable --outfile --outfile-format --outfile-autohex-disable --outfile-check-timer --outfile-check-dir --separator --show --left --username --remove --remove-timer --potfile-disable --potfile-path --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --opencl-info --opencl-devices --opencl-platforms --opencl-device-types --opencl-vector-width --workload-profile --kernel-accel --kernel-loops --nvidia-spin-damp --gpu-temp-disable --gpu-temp-abort --gpu-temp-retain --powertune-enable --skip --limit --keyspace --rule-left --rule-right --rules-file --generate-rules --generate-rules-func-min --generate-rules-func-max --generate-rules-seed --rules-cleanup --custom-charset1 --custom-charset2 --custom-charset3 --custom-charset4 --increment --increment-min --increment-max --logfile-disable --scrypt-tmto --truecrypt-keyfiles" + local LONG_OPTS="--hash-type --attack-mode --version --help --eula --quiet --benchmark --benchmark-repeats --hex-salt --hex-wordlist --hex-charset --force --status --status-timer --machine-readable --loopback --weak-hash-threshold --markov-hcstat --markov-disable --markov-classic --markov-threshold --runtime --session --speed-only --restore --restore-disable --outfile --outfile-format --outfile-autohex-disable --outfile-check-timer --outfile-check-dir --separator --show --left --username --remove --remove-timer --potfile-disable --potfile-path --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --opencl-info --opencl-devices --opencl-platforms --opencl-device-types --opencl-vector-width --workload-profile --kernel-accel --kernel-loops --nvidia-spin-damp --gpu-temp-disable --gpu-temp-abort --gpu-temp-retain --powertune-enable --skip --limit --keyspace --rule-left --rule-right --rules-file --generate-rules --generate-rules-func-min --generate-rules-func-max --generate-rules-seed --rules-cleanup --custom-charset1 --custom-charset2 --custom-charset3 --custom-charset4 --increment --increment-min --increment-max --logfile-disable --scrypt-tmto --truecrypt-keyfiles" local OPTIONS="-m -a -t -o -p -c -d -w -n -u -j -k -r -g -1 -2 -3 -4 -s -l --hash-type --attack-mode --benchmark-repeats --status-timer --weak-hash-threshold --markov-hcstat --markov-threshold --runtime --session --timer --outfile --outfile-format --outfile-check-timer --outfile-check-dir --separator --remove-timer --potfile-path --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --opencl-devices --opencl-platforms --opencl-device-types --opencl-vector-width --workload-profile --kernel-accel --kernel-loops --nvidia-spin-damp --gpu-temp-abort --gpu-temp-retain -disable --skip --limit --rule-left --rule-right --rules-file --generate-rules --generate-rules-func-min --generate-rules-func-max --generate-rules-seed --custom-charset1 --custom-charset2 --custom-charset3 --custom-charset4 --increment-min --increment-max --scrypt-tmto --truecrypt-keyfiles" COMPREPLY=() diff --git a/include/affinity.h b/include/affinity.h index 742fc8fb8..ff88f85a3 100644 --- a/include/affinity.h +++ b/include/affinity.h @@ -17,12 +17,13 @@ #if defined (__APPLE__) #include #include +#include #endif // __APPLE__ #if defined (_WIN) #include #endif // _WIN -void set_cpu_affinity (char *cpu_affinity); +int set_cpu_affinity (hashcat_ctx_t *hashcat_ctx); #endif // _AFFINITY_H diff --git a/include/bitmap.h b/include/bitmap.h index 18b07f329..c12b6889a 100644 --- a/include/bitmap.h +++ b/include/bitmap.h @@ -8,7 +8,7 @@ #include -void bitmap_ctx_init (hashcat_ctx_t *hashcat_ctx); +int bitmap_ctx_init (hashcat_ctx_t *hashcat_ctx); void bitmap_ctx_destroy (hashcat_ctx_t *hashcat_ctx); #endif // _BITMAP_H diff --git a/include/common.h b/include/common.h index 0777826f7..cfe5c2d15 100644 --- a/include/common.h +++ b/include/common.h @@ -87,4 +87,6 @@ but this is nededed for VS compiler which doesn't have inline keyword but has __ #define EOL "\n" #endif +#define MAYBE_UNUSED __attribute__((unused)) + #endif // _COMMON_H diff --git a/include/cpu_crc32.h b/include/cpu_crc32.h index 50e4e23b8..a1d86f19e 100644 --- a/include/cpu_crc32.h +++ b/include/cpu_crc32.h @@ -9,6 +9,6 @@ #include #include -void cpu_crc32 (const char *filename, u8 keytab[64]); +int cpu_crc32 (hashcat_ctx_t *hashcat_ctx, const char *filename, u8 keytab[64]); #endif // _CPU_CRC32_H diff --git a/include/dynloader.h b/include/dynloader.h index d2c35005c..534883afd 100644 --- a/include/dynloader.h +++ b/include/dynloader.h @@ -34,11 +34,11 @@ void *hc_dlsym (void *module, const char *symbol); if (noerr != -1) { \ if (!ptr->name) { \ if (noerr == 1) { \ - log_error ("ERROR: %s is missing from %s shared library.", #name, #libname); \ - exit (-1); \ - } else { \ - log_info ("WARNING: %s is missing from %s shared library.", #name, #libname); \ + event_log_error (hashcat_ctx, "%s is missing from %s shared library.", #name, #libname); \ return -1; \ + } else { \ + event_log_warning (hashcat_ctx, "%s is missing from %s shared library.", #name, #libname); \ + return 0; \ } \ } \ } @@ -48,11 +48,11 @@ void *hc_dlsym (void *module, const char *symbol); if (noerr != -1) { \ if (!ptr->name) { \ if (noerr == 1) { \ - log_error ("ERROR: %s is missing from %s shared library.", #name, #libname); \ - exit (-1); \ - } else { \ - log_info ("WARNING: %s is missing from %s shared library.", #name, #libname); \ + event_log_error (hashcat_ctx, "%s is missing from %s shared library.", #name, #libname); \ return -1; \ + } else { \ + event_log_warning (hashcat_ctx, "%s is missing from %s shared library.", #name, #libname); \ + return 0; \ } \ } \ } @@ -61,13 +61,12 @@ void *hc_dlsym (void *module, const char *symbol); ptr->name = (type) (*ptr->func) (addr); \ if (!ptr->name) { \ if (noerr == 1) { \ - log_error ("ERROR: %s at address %08x is missing from %s shared library.", #name, addr, #libname); \ - exit (-1); \ - } else { \ - log_error ("WARNING: %s at address %08x is missing from %s shared library.", #name, addr, #libname); \ + event_log_error (hashcat_ctx, "%s at address %08x is missing from %s shared library.", #name, addr, #libname); \ return -1; \ + } else { \ + event_log_warning (hashcat_ctx, "%s at address %08x is missing from %s shared library.", #name, addr, #libname); \ + return 0; \ } \ } #endif // _DYNALOADER_H - diff --git a/include/event.h b/include/event.h new file mode 100644 index 000000000..cac3d15e1 --- /dev/null +++ b/include/event.h @@ -0,0 +1,28 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#ifndef _EVENT_H +#define _EVENT_H + +#include +#include + +void event_call (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len); + +#define EVENT(id) event_call ((id), hashcat_ctx, NULL, 0) +#define EVENT_DATA(id,buf,len) event_call ((id), hashcat_ctx, (buf), (len)) + +size_t event_log_info_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); +size_t event_log_warning_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); +size_t event_log_error_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); + +size_t event_log_info (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); +size_t event_log_warning (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); +size_t event_log_error (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...); + +int event_ctx_init (hashcat_ctx_t *hashcat_ctx); +void event_ctx_destroy (hashcat_ctx_t *hashcat_ctx); + +#endif // _EVENT_H diff --git a/include/ext_ADL.h b/include/ext_ADL.h index f2f446a4b..9a3322fe0 100644 --- a/include/ext_ADL.h +++ b/include/ext_ADL.h @@ -7,6 +7,11 @@ #define _EXT_ADL_H #include +#include + +#if defined (_WIN) +#include +#endif // _WIN /** * Declarations from adl_sdk.h and subheaders @@ -352,44 +357,6 @@ typedef struct hm_adl_lib 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); -int hm_ADL_Adapter_AdapterInfo_Get (ADL_PTR *adl, LPAdapterInfo lpInfo, int iInputSize); -int hm_ADL_Display_DisplayInfo_Get (ADL_PTR *adl, int iAdapterIndex, int *iNumDisplays, ADLDisplayInfo **lppInfo, int iForceDetect); -int hm_ADL_Overdrive5_Temperature_Get (ADL_PTR *adl, int iAdapterIndex, int iThermalControllerIndex, ADLTemperature *lpTemperature); -int hm_ADL_Overdrive6_Temperature_Get (ADL_PTR *adl, int iAdapterIndex, int *iTemperature); -int hm_ADL_Overdrive_CurrentActivity_Get (ADL_PTR *adl, int iAdapterIndex, ADLPMActivity *lpActivity); -int hm_ADL_Overdrive_ThermalDevices_Enum (ADL_PTR *adl, int iAdapterIndex, int iThermalControllerIndex, ADLThermalControllerInfo *lpThermalControllerInfo); -int hm_ADL_Adapter_ID_Get (ADL_PTR *adl, int iAdapterIndex, int *lpAdapterID); -int hm_ADL_Adapter_VideoBiosInfo_Get (ADL_PTR *adl, int iAdapterIndex, ADLBiosInfo *lpBiosInfo); -int hm_ADL_Overdrive5_FanSpeedInfo_Get (ADL_PTR *adl, int iAdapterIndex, int iThermalControllerIndex, ADLFanSpeedInfo *lpFanSpeedInfo); -int hm_ADL_Overdrive5_FanSpeed_Get (ADL_PTR *adl, int iAdapterIndex, int iThermalControllerIndex, ADLFanSpeedValue *lpFanSpeedValue); -int hm_ADL_Overdrive6_FanSpeed_Get (ADL_PTR *adl, int iAdapterIndex, ADLOD6FanSpeedInfo *lpFanSpeedInfo); -int hm_ADL_Overdrive5_FanSpeed_Set (ADL_PTR *adl, int iAdapterIndex, int iThermalControllerIndex, ADLFanSpeedValue *lpFanSpeedValue); -int hm_ADL_Overdrive6_FanSpeed_Set (ADL_PTR *adl, int iAdapterIndex, ADLOD6FanSpeedValue *lpFanSpeedValue); -int hm_ADL_Overdrive5_FanSpeedToDefault_Set (ADL_PTR *adl, int iAdapterIndex, int iThermalControllerIndex); -int hm_ADL_Overdrive_ODParameters_Get (ADL_PTR *adl, int iAdapterIndex, ADLODParameters *lpOdParameters); -int hm_ADL_Overdrive_ODPerformanceLevels_Get (ADL_PTR *adl, int iAdapterIndex, int iDefault, ADLODPerformanceLevels *lpOdPerformanceLevels); -int hm_ADL_Overdrive_ODPerformanceLevels_Set (ADL_PTR *adl, int iAdapterIndex, ADLODPerformanceLevels *lpOdPerformanceLevels); -int hm_ADL_Overdrive_PowerControlInfo_Get (ADL_PTR *adl, int iAdapterIndex, ADLOD6PowerControlInfo *); -int hm_ADL_Overdrive_PowerControl_Get (ADL_PTR *adl, int iAdapterIndex, int *level); -int hm_ADL_Overdrive_PowerControl_Set (ADL_PTR *adl, int iAdapterIndex, int level); -int hm_ADL_Adapter_Active_Get (ADL_PTR *adl, int iAdapterIndex, int *lpStatus); -//int hm_ADL_DisplayEnable_Set (ADL_PTR *adl, int iAdapterIndex, int *lpDisplayIndexList, int iDisplayListSize, int bPersistOnly); -int hm_ADL_Overdrive_Caps (ADL_PTR *adl, int iAdapterIndex, int *od_supported, int *od_enabled, int *od_version); -int hm_ADL_Overdrive_CurrentStatus_Get (ADL_PTR *adl, int iAdapterIndex, ADLOD6CurrentStatus *status); -int hm_ADL_Overdrive_StateInfo_Get (ADL_PTR *adl, int iAdapterIndex, int type, ADLOD6MemClockState *state); -int hm_ADL_Overdrive_Capabilities_Get (ADL_PTR *adl, int iAdapterIndex, ADLOD6Capabilities *caps); -int hm_ADL_Overdrive_State_Set (ADL_PTR *adl, int iAdapterIndex, int type, ADLOD6StateInfo *state); -int hm_ADL_Overdrive6_PowerControl_Caps (ADL_PTR *adl, int iAdapterIndex, int *lpSupported); -int hm_ADL_Overdrive6_TargetTemperatureData_Get (ADL_PTR *adl, int iAdapterIndex, int *cur_temp, int *default_temp); -int hm_ADL_Overdrive6_TargetTemperatureRangeInfo_Get (ADL_PTR *adl, int iAdapterIndex, ADLOD6ParameterRange *lpTargetTemperatureInfo); -int hm_ADL_Overdrive6_FanSpeed_Reset (ADL_PTR *adl, int iAdapterIndex); - #endif // _EXT_ADL_H diff --git a/include/ext_OpenCL.h b/include/ext_OpenCL.h index 9b56dbaf2..ea288b166 100644 --- a/include/ext_OpenCL.h +++ b/include/ext_OpenCL.h @@ -109,40 +109,4 @@ typedef hc_opencl_lib_t OCL_PTR; const char *val2cstr_cl (cl_int CL_err); -int ocl_init (OCL_PTR *ocl); -void ocl_close (OCL_PTR *ocl); - -cl_int hc_clBuildProgram (OCL_PTR *ocl, cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, void (CL_CALLBACK *pfn_notify) (cl_program program, void *user_data), void *user_data); -cl_int hc_clCreateBuffer (OCL_PTR *ocl, cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_mem *mem); -cl_int hc_clCreateCommandQueue (OCL_PTR *ocl, cl_context context, cl_device_id device, cl_command_queue_properties properties, cl_command_queue *command_queue); -cl_int hc_clCreateContext (OCL_PTR *ocl, cl_context_properties *properties, cl_uint num_devices, const cl_device_id *devices, void (CL_CALLBACK *pfn_notify) (const char *, const void *, size_t, void *), void *user_data, cl_context *context); -cl_int hc_clCreateKernel (OCL_PTR *ocl, cl_program program, const char *kernel_name, cl_kernel *kernel); -cl_int hc_clCreateProgramWithBinary (OCL_PTR *ocl, cl_context context, cl_uint num_devices, const cl_device_id *device_list, const size_t *lengths, const unsigned char **binaries, cl_int *binary_status, cl_program *program); -cl_int hc_clCreateProgramWithSource (OCL_PTR *ocl, cl_context context, cl_uint count, const char **strings, const size_t *lengths, cl_program *program); -cl_int hc_clEnqueueCopyBuffer (OCL_PTR *ocl, cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer, size_t src_offset, size_t dst_offset, size_t cb, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event); -cl_int hc_clEnqueueMapBuffer (OCL_PTR *ocl, cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_map, cl_map_flags map_flags, size_t offset, size_t cb, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event, void **buf); -cl_int hc_clEnqueueNDRangeKernel (OCL_PTR *ocl, cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim, const size_t *global_work_offset, const size_t *global_work_size, const size_t *local_work_size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event); -cl_int hc_clEnqueueReadBuffer (OCL_PTR *ocl, cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, size_t offset, size_t cb, void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event); -cl_int hc_clEnqueueUnmapMemObject (OCL_PTR *ocl, cl_command_queue command_queue, cl_mem memobj, void *mapped_ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event); -cl_int hc_clEnqueueWriteBuffer (OCL_PTR *ocl, cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, size_t offset, size_t cb, const void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event); -cl_int hc_clFinish (OCL_PTR *ocl, cl_command_queue command_queue); -cl_int hc_clFlush (OCL_PTR *ocl, cl_command_queue command_queue); -cl_int hc_clGetDeviceIDs (OCL_PTR *ocl, cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, cl_device_id *devices, cl_uint *num_devices); -cl_int hc_clGetDeviceInfo (OCL_PTR *ocl, cl_device_id device, cl_device_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret); -cl_int hc_clGetEventInfo (OCL_PTR *ocl, cl_event event, cl_event_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret); -cl_int hc_clGetEventProfilingInfo (OCL_PTR *ocl, cl_event event, cl_profiling_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret); -cl_int hc_clGetKernelWorkGroupInfo (OCL_PTR *ocl, cl_kernel kernel, cl_device_id device, cl_kernel_work_group_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret); -cl_int hc_clGetPlatformIDs (OCL_PTR *ocl, cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms); -cl_int hc_clGetPlatformInfo (OCL_PTR *ocl, cl_platform_id platform, cl_platform_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret); -cl_int hc_clGetProgramBuildInfo (OCL_PTR *ocl, cl_program program, cl_device_id device, cl_program_build_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret); -cl_int hc_clGetProgramInfo (OCL_PTR *ocl, cl_program program, cl_program_info param_name, size_t param_value_size, void *param_value, size_t * param_value_size_ret); -cl_int hc_clReleaseCommandQueue (OCL_PTR *ocl, cl_command_queue command_queue); -cl_int hc_clReleaseContext (OCL_PTR *ocl, cl_context context); -cl_int hc_clReleaseEvent (OCL_PTR *ocl, cl_event event); -cl_int hc_clReleaseKernel (OCL_PTR *ocl, cl_kernel kernel); -cl_int hc_clReleaseMemObject (OCL_PTR *ocl, cl_mem mem); -cl_int hc_clReleaseProgram (OCL_PTR *ocl, cl_program program); -cl_int hc_clSetKernelArg (OCL_PTR *ocl, cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value); -cl_int hc_clWaitForEvents (OCL_PTR *ocl, cl_uint num_events, const cl_event *event_list); - #endif // _EXT_OPENCL_H diff --git a/include/ext_nvapi.h b/include/ext_nvapi.h index 3a5c68162..f2883d65a 100644 --- a/include/ext_nvapi.h +++ b/include/ext_nvapi.h @@ -255,18 +255,4 @@ typedef struct hm_nvapi_lib typedef hm_nvapi_lib_t NVAPI_PTR; -int nvapi_init (NVAPI_PTR *nvapi); -void nvapi_close (NVAPI_PTR *nvapi); - -int hm_NvAPI_QueryInterface (NVAPI_PTR *nvapi, unsigned int offset); -int hm_NvAPI_GetErrorMessage (NVAPI_PTR *nvapi, NvAPI_Status nr, NvAPI_ShortString szDesc); - -NvAPI_Status hm_NvAPI_Initialize (NVAPI_PTR *nvapi); -NvAPI_Status hm_NvAPI_Unload (NVAPI_PTR *nvapi); -NvAPI_Status hm_NvAPI_EnumPhysicalGPUs (NVAPI_PTR *nvapi, NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount); -NvAPI_Status hm_NvAPI_GPU_GetPerfPoliciesInfo (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 *perfPolicies_info); -NvAPI_Status hm_NvAPI_GPU_GetPerfPoliciesStatus (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 *perfPolicies_status); -NvAPI_Status hm_NvAPI_GPU_SetCoolerLevels (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NvU32 coolerIndex, NV_GPU_COOLER_LEVELS *pCoolerLevels); -NvAPI_Status hm_NvAPI_GPU_RestoreCoolerSettings (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NvU32 coolerIndex); - #endif // _EXT_NVAPI_H diff --git a/include/ext_nvml.h b/include/ext_nvml.h index ce7df5993..9342b4e6e 100644 --- a/include/ext_nvml.h +++ b/include/ext_nvml.h @@ -168,6 +168,7 @@ typedef nvmlDevice_t HM_ADAPTER_NVML; typedef const char * (*NVML_API_CALL NVML_ERROR_STRING) (nvmlReturn_t); typedef int (*NVML_API_CALL NVML_INIT) (void); typedef int (*NVML_API_CALL NVML_SHUTDOWN) (void); +typedef nvmlReturn_t (*NVML_API_CALL NVML_DEVICE_GET_COUNT) (unsigned int *); typedef nvmlReturn_t (*NVML_API_CALL NVML_DEVICE_GET_NAME) (nvmlDevice_t, char *, unsigned int); typedef nvmlReturn_t (*NVML_API_CALL NVML_DEVICE_GET_HANDLE_BY_INDEX) (unsigned int, nvmlDevice_t *); typedef nvmlReturn_t (*NVML_API_CALL NVML_DEVICE_GET_TEMPERATURE) (nvmlDevice_t, nvmlTemperatureSensors_t, unsigned int *); @@ -199,6 +200,7 @@ typedef struct hm_nvml_lib NVML_ERROR_STRING nvmlErrorString; NVML_INIT nvmlInit; NVML_SHUTDOWN nvmlShutdown; + NVML_DEVICE_GET_COUNT nvmlDeviceGetCount; NVML_DEVICE_GET_NAME nvmlDeviceGetName; NVML_DEVICE_GET_HANDLE_BY_INDEX nvmlDeviceGetHandleByIndex; NVML_DEVICE_GET_TEMPERATURE nvmlDeviceGetTemperature; @@ -221,28 +223,4 @@ typedef struct hm_nvml_lib typedef hm_nvml_lib_t NVML_PTR; -int nvml_init (NVML_PTR *lib); -void nvml_close (NVML_PTR *lib); - -const char * hm_NVML_nvmlErrorString (NVML_PTR *nvml, nvmlReturn_t nvml_rc); -nvmlReturn_t hm_NVML_nvmlInit (NVML_PTR *nvml); -nvmlReturn_t hm_NVML_nvmlShutdown (NVML_PTR *nvml); -nvmlReturn_t hm_NVML_nvmlDeviceGetName (NVML_PTR *nvml, int, nvmlDevice_t device, char *name, unsigned int length); -nvmlReturn_t hm_NVML_nvmlDeviceGetHandleByIndex (NVML_PTR *nvml, int, unsigned int index, nvmlDevice_t *device); -nvmlReturn_t hm_NVML_nvmlDeviceGetTemperature (NVML_PTR *nvml, int, nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int *temp); -nvmlReturn_t hm_NVML_nvmlDeviceGetFanSpeed (NVML_PTR *nvml, int, nvmlDevice_t device, unsigned int *speed); -nvmlReturn_t hm_NVML_nvmlDeviceGetPowerUsage (NVML_PTR *nvml, int, nvmlDevice_t device, unsigned int *power); -nvmlReturn_t hm_NVML_nvmlDeviceGetUtilizationRates (NVML_PTR *nvml, int, nvmlDevice_t device, nvmlUtilization_t *utilization); -nvmlReturn_t hm_NVML_nvmlDeviceGetClockInfo (NVML_PTR *nvml, int, nvmlDevice_t device, nvmlClockType_t type, unsigned int *clock); -nvmlReturn_t hm_NVML_nvmlDeviceGetTemperatureThreshold (NVML_PTR *nvml, int, nvmlDevice_t device, nvmlTemperatureThresholds_t thresholdType, unsigned int *temp); -nvmlReturn_t hm_NVML_nvmlDeviceGetCurrPcieLinkGeneration (NVML_PTR *nvml, int, nvmlDevice_t device, unsigned int *currLinkGen); -nvmlReturn_t hm_NVML_nvmlDeviceGetCurrPcieLinkWidth (NVML_PTR *nvml, int, nvmlDevice_t device, unsigned int *currLinkWidth); -nvmlReturn_t hm_NVML_nvmlDeviceGetCurrentClocksThrottleReasons (NVML_PTR *nvml, int, nvmlDevice_t device, unsigned long long *clocksThrottleReasons); -nvmlReturn_t hm_NVML_nvmlDeviceGetSupportedClocksThrottleReasons (NVML_PTR *nvml, int, nvmlDevice_t device, unsigned long long *supportedClocksThrottleReasons); -nvmlReturn_t hm_NVML_nvmlDeviceSetComputeMode (NVML_PTR *nvml, int, nvmlDevice_t device, nvmlComputeMode_t mode); -nvmlReturn_t hm_NVML_nvmlDeviceSetGpuOperationMode (NVML_PTR *nvml, int, nvmlDevice_t device, nvmlGpuOperationMode_t mode); -nvmlReturn_t hm_NVML_nvmlDeviceGetPowerManagementLimitConstraints (NVML_PTR *nvml, int, nvmlDevice_t device, unsigned int *minLimit, unsigned int *maxLimit); -nvmlReturn_t hm_NVML_nvmlDeviceSetPowerManagementLimit (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, unsigned int limit); -nvmlReturn_t hm_NVML_nvmlDeviceGetPowerManagementLimit (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, unsigned int *limit); - #endif // _NVML_H diff --git a/include/ext_xnvctrl.h b/include/ext_xnvctrl.h index 6ff1e3caf..1ae36dfcf 100644 --- a/include/ext_xnvctrl.h +++ b/include/ext_xnvctrl.h @@ -72,19 +72,4 @@ typedef struct hm_xnvctrl_lib typedef hm_xnvctrl_lib_t XNVCTRL_PTR; -int xnvctrl_init (XNVCTRL_PTR *xnvctrl); -void xnvctrl_close (XNVCTRL_PTR *xnvctrl); - -int hm_XNVCTRL_XOpenDisplay (XNVCTRL_PTR *xnvctrl); -void hm_XNVCTRL_XCloseDisplay (XNVCTRL_PTR *xnvctrl); - -int get_core_threshold (XNVCTRL_PTR *xnvctrl, int gpu, int *val); - -int get_fan_control (XNVCTRL_PTR *xnvctrl, int gpu, int *val); -int set_fan_control (XNVCTRL_PTR *xnvctrl, int gpu, int val); - -int get_fan_speed_current (XNVCTRL_PTR *xnvctrl, int gpu, int *val); -int get_fan_speed_target (XNVCTRL_PTR *xnvctrl, int gpu, int *val); -int set_fan_speed_target (XNVCTRL_PTR *xnvctrl, int gpu, int val); - #endif // _EXT_XNVCTRL_H diff --git a/include/filehandling.h b/include/filehandling.h index 582599453..b8f70d40c 100644 --- a/include/filehandling.h +++ b/include/filehandling.h @@ -10,7 +10,7 @@ #include #include -u64 count_lines (FILE *fd); +u64 count_lines (hashcat_ctx_t *hashcat_ctx, FILE *fd); int fgetl (FILE *fp, char *line_buf); diff --git a/include/folder.h b/include/folder.h index f850ec276..d4ddc212b 100644 --- a/include/folder.h +++ b/include/folder.h @@ -29,16 +29,11 @@ int sort_by_stringptr (const void *p1, const void *p2); -char *get_exec_path (void); -char *get_install_dir (const char *progname); -char *get_profile_dir (const char *homedir); -char *get_session_dir (const char *profile_dir); - int count_dictionaries (char **dictionary_files); -char **scan_directory (const char *path); +char **scan_directory (hashcat_ctx_t *hashcat_ctx, const char *path); -int folder_config_init (hashcat_ctx_t *hashcat_ctx, const char *install_folder, const char *shared_folder); +int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *install_folder, MAYBE_UNUSED const char *shared_folder); void folder_config_destroy (hashcat_ctx_t *hashcat_ctx); -int hc_mkdir (const char *name, int mode); +int hc_mkdir (const char *name, MAYBE_UNUSED const int mode); diff --git a/include/hashcat.h b/include/hashcat.h index 8b3b3f9fb..51302b567 100644 --- a/include/hashcat.h +++ b/include/hashcat.h @@ -6,9 +6,17 @@ #ifndef _HASHCAT_H #define _HASHCAT_H -int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_folder, int argc, char **argv, const int comptime); +int hashcat_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t)); +void hashcat_destroy (hashcat_ctx_t *hashcat_ctx); -void hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx); -void hashcat_ctx_destroy (hashcat_ctx_t *hashcat_ctx); +int hashcat_session_run (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_folder, int argc, char **argv, const int comptime); +int hashcat_session_pause (hashcat_ctx_t *hashcat_ctx); +int hashcat_session_resume (hashcat_ctx_t *hashcat_ctx); +int hashcat_session_bypass (hashcat_ctx_t *hashcat_ctx); +int hashcat_session_checkpoint (hashcat_ctx_t *hashcat_ctx); +int hashcat_session_quit (hashcat_ctx_t *hashcat_ctx); + +char *hashcat_get_log (hashcat_ctx_t *hashcat_ctx); +int hashcat_get_status (hashcat_ctx_t *hashcat_ctx, hashcat_status_t *hashcat_status); #endif // _HASHCAT_H diff --git a/include/hashes.h b/include/hashes.h index 561e7d0cf..2c0564aa2 100644 --- a/include/hashes.h +++ b/include/hashes.h @@ -11,7 +11,7 @@ int sort_by_salt (const void *v1, const void *v2); int sort_by_hash (const void *v1, const void *v2, void *v3); int sort_by_hash_no_salt (const void *v1, const void *v2, void *v3); -void save_hash (hashcat_ctx_t *hashcat_ctx); +int save_hash (hashcat_ctx_t *hashcat_ctx); void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain); @@ -20,6 +20,7 @@ int check_cracked (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx); int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx); int hashes_init_stage3 (hashcat_ctx_t *hashcat_ctx); +int hashes_init_stage4 (hashcat_ctx_t *hashcat_ctx); void hashes_destroy (hashcat_ctx_t *hashcat_ctx); diff --git a/include/interface.h b/include/interface.h index 39d7d1e91..6300c2872 100644 --- a/include/interface.h +++ b/include/interface.h @@ -1340,162 +1340,162 @@ typedef enum rounds_count * input functions */ -int bcrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int cisco4_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int dcc_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int dcc2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int descrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int des_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int episerver_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int ipb2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int joomla_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int postgresql_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int netscreen_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int keccak_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int lm_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int md4_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int md4s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int md5s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int md5half_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int md5md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int md5pix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int md5asa_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int md5apr1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int md5crypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int mssql2000_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int mssql2005_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int netntlmv1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int netntlmv2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int oracleh_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int oracles_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int oraclet_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int osc_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int arubaos_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int osx1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int osx512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int phpass_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha1b64_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha1b64s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha1s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha256s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha384_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha512s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha512crypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int smf_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int vb3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int vb30_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int wpa_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int psafe2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int psafe3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int ikepsk_md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int ikepsk_sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int androidpin_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int ripemd160_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int whirlpool_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int truecrypt_parse_hash_1k (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int truecrypt_parse_hash_2k (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int md5aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha256aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha512aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int agilekey_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha1aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int lastpass_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int gost_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha256crypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int mssql2012_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha512osx_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int episerver4_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha512grub_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha512b64s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int hmacsha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int hmacsha256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int hmacsha512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int hmacmd5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int krb5pa_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int krb5tgs_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sapb_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sapg_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int drupal7_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sybasease_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int mysql323_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int rakp_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int netscaler_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int chap_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int cloudkey_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int nsec3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int wbb3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int racf_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int lotus5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int lotus6_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int lotus8_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int hmailserver_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int phps_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int mediawiki_b_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int peoplesoft_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int skype_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int androidfde_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int scrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int juniper_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int cisco8_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int cisco9_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int office2007_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int office2010_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int office2013_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int oldoffice01_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int oldoffice01cm1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int oldoffice01cm2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int oldoffice34_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int oldoffice34cm1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int oldoffice34cm2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int radmin2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int djangosha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int djangopbkdf2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int siphash_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int crammd5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int saph_sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int redmine_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int pdf11_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int pdf11cm1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int pdf11cm2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int pdf14_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int pdf17l3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int pdf17l8_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int pbkdf2_sha256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int prestashop_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int postgresql_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int mysql_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int bitcoin_wallet_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sip_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int crc32_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int seven_zip_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int gost2012sbog_256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int gost2012sbog_512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int pbkdf2_md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int pbkdf2_sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int pbkdf2_sha512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int ecryptfs_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int bsdicrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int rar3hp_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int rar5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int cf10_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int mywallet_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int ms_drsr_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int androidfde_samsung_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int axcrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int sha1axcrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int keepass_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int pstoken_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int zip2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int veracrypt_parse_hash_200000 (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int veracrypt_parse_hash_500000 (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int veracrypt_parse_hash_327661 (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int veracrypt_parse_hash_655331 (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int win8phone_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); -int opencart_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig); +int bcrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int cisco4_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int dcc_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int dcc2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int descrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int des_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int episerver_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int ipb2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int joomla_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int postgresql_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int netscreen_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int keccak_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int lm_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int md4_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int md4s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int md5s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int md5half_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int md5md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int md5pix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int md5asa_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int md5apr1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int md5crypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int mssql2000_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int mssql2005_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int netntlmv1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int netntlmv2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int oracleh_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int oracles_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int oraclet_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int osc_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int arubaos_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int osx1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int osx512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int phpass_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha1b64_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha1b64s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha1s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha256s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha384_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha512s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha512crypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int smf_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int vb3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int vb30_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int wpa_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int psafe2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int psafe3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int ikepsk_md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int ikepsk_sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int androidpin_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int ripemd160_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int whirlpool_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int truecrypt_parse_hash_1k (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int truecrypt_parse_hash_2k (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int md5aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha256aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha512aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int agilekey_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha1aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int lastpass_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int gost_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha256crypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int mssql2012_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha512osx_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int episerver4_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha512grub_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha512b64s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int hmacsha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int hmacsha256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int hmacsha512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int hmacmd5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int krb5pa_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int krb5tgs_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sapb_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sapg_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int drupal7_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sybasease_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int mysql323_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int rakp_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int netscaler_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int chap_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int cloudkey_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int nsec3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int wbb3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int racf_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int lotus5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int lotus6_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int lotus8_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int hmailserver_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int phps_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int mediawiki_b_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int peoplesoft_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int skype_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int androidfde_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int scrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int juniper_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int cisco8_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int cisco9_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int office2007_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int office2010_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int office2013_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int oldoffice01_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int oldoffice01cm1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int oldoffice01cm2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int oldoffice34_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int oldoffice34cm1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int oldoffice34cm2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int radmin2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int djangosha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int djangopbkdf2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int siphash_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int crammd5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int saph_sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int redmine_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int pdf11_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int pdf11cm1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int pdf11cm2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int pdf14_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int pdf17l3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int pdf17l8_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int pbkdf2_sha256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int prestashop_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int postgresql_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int mysql_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int bitcoin_wallet_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sip_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int crc32_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int seven_zip_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int gost2012sbog_256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int gost2012sbog_512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int pbkdf2_md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int pbkdf2_sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int pbkdf2_sha512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int ecryptfs_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int bsdicrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int rar3hp_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int rar5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int cf10_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int mywallet_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int ms_drsr_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int androidfde_samsung_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int axcrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int sha1axcrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int keepass_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int pstoken_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int zip2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int veracrypt_parse_hash_200000 (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int veracrypt_parse_hash_500000 (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int veracrypt_parse_hash_327661 (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int veracrypt_parse_hash_655331 (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int win8phone_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); +int opencart_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig); /** * output functions @@ -1505,15 +1505,15 @@ char *stroptitype (const u32 opti_type); char *strhashtype (const u32 hash_mode); char *strparser (const u32 parser_status); -void to_hccap_t (hccap_t *hccap, const u32 salt_pos, const u32 digest_pos, const hashconfig_t *hashconfig, const hashes_t *hashes); +void to_hccap_t (hashcat_ctx_t *hashcat_ctx, hccap_t *hccap, const u32 salt_pos, const u32 digest_pos); -void ascii_digest (char *out_buf, const u32 salt_pos, const u32 digest_pos, const hashconfig_t *hashconfig, const hashes_t *hashes); +int ascii_digest (hashcat_ctx_t *hashcat_ctx, char *out_buf, const u32 salt_pos, const u32 digest_pos); int hashconfig_init (hashcat_ctx_t *hashcat_ctx); void hashconfig_destroy (hashcat_ctx_t *hashcat_ctx); u32 hashconfig_enforce_kernel_threads (hashcat_ctx_t *hashcat_ctx, const hc_device_param_t *device_param); u32 hashconfig_enforce_kernel_loops (hashcat_ctx_t *hashcat_ctx); -void hashconfig_general_defaults (hashcat_ctx_t *hashcat_ctx); +int hashconfig_general_defaults (hashcat_ctx_t *hashcat_ctx); void hashconfig_benchmark_defaults (hashcat_ctx_t *hashcat_ctx, salt_t *salt, void *esalt); char *hashconfig_benchmark_mask (hashcat_ctx_t *hashcat_ctx); diff --git a/include/locking.h b/include/locking.h index 9d4a1d68a..c36745c9d 100644 --- a/include/locking.h +++ b/include/locking.h @@ -15,13 +15,13 @@ #if defined (F_SETLKW) -void lock_file (FILE *fp); +int lock_file (FILE *fp); void unlock_file (FILE *fp); #else -#define lock_file(dummy) {} -#define unlock_file(dummy) {} +#define lock_file(dummy) 0 +#define unlock_file(dummy) #endif diff --git a/include/logging.h b/include/logging.h deleted file mode 100644 index 01ee26014..000000000 --- a/include/logging.h +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Author......: See docs/credits.txt - * License.....: MIT - */ - -#ifndef _LOGGING_H -#define _LOGGING_H - -#include -#include - -int log_out_nn (FILE *fp, const char *fmt, ...); -int log_info_nn (const char *fmt, ...); -int log_error_nn (const char *fmt, ...); - -int log_out (FILE *fp, const char *fmt, ...); -int log_info (const char *fmt, ...); -int log_error (const char *fmt, ...); - -#endif // _LOGGING_H diff --git a/include/memory.h b/include/memory.h index ca59cd756..c1193d78c 100644 --- a/include/memory.h +++ b/include/memory.h @@ -6,15 +6,18 @@ #ifndef _MEMORY_H #define _MEMORY_H +#include #include #include #define MSG_ENOMEM "Insufficient memory available" -void *mycalloc (size_t nmemb, size_t size); -void myfree (void *ptr); -void *mymalloc (size_t size); -void *myrealloc (void *ptr, size_t oldsz, size_t add); -char *mystrdup (const char *s); +#define VERIFY_PTR(v) if ((v) == NULL) return -1; + +void *hccalloc (hashcat_ctx_t *hashcat_ctx, const size_t nmemb, const size_t sz); +void *hcmalloc (hashcat_ctx_t *hashcat_ctx, const size_t sz); +void *hcrealloc (hashcat_ctx_t *hashcat_ctx, void *ptr, const size_t oldsz, const size_t addsz); +char *hcstrdup (hashcat_ctx_t *hashcat_ctx, const char *s); +void hcfree (void *ptr); #endif // _MEMORY_H diff --git a/include/monitor.h b/include/monitor.h index ac0d67acb..2f6da11ab 100644 --- a/include/monitor.h +++ b/include/monitor.h @@ -6,6 +6,8 @@ #ifndef _MONITOR_H #define _MONITOR_H +int get_runtime_left (const hashcat_ctx_t *hashcat_ctx); + void *thread_monitor (void *p); #endif // _MONITOR_H diff --git a/include/mpsp.h b/include/mpsp.h index 54fa909b0..5840704eb 100644 --- a/include/mpsp.h +++ b/include/mpsp.h @@ -20,26 +20,7 @@ #define INCR_MASKS 1000 -void mp_css_split_cnt (const mask_ctx_t *mask_ctx, const hashconfig_t *hashconfig, const u32 css_cnt_orig, u32 css_cnt_rl[2]); -void mp_css_append_salt (mask_ctx_t *mask_ctx, salt_t *salt_buf); -void mp_css_unicode_expand (mask_ctx_t *mask_ctx); -void mp_css_to_uniq_tbl (u32 css_cnt, cs_t *css, u32 uniq_tbls[SP_PW_MAX][CHARSIZ]); -void mp_cut_at (char *mask, u32 max); -u32 mp_get_length (char *mask); -void mp_exec (u64 val, char *buf, cs_t *css, int css_cnt); -cs_t *mp_gen_css (char *mask_buf, size_t mask_len, cs_t *mp_sys, cs_t *mp_usr, u32 *css_cnt, const hashconfig_t *hashconfig, const user_options_t *user_options); -u64 mp_get_sum (u32 css_cnt, cs_t *css); -void mp_setup_sys (cs_t *mp_sys); -void mp_setup_usr (cs_t *mp_sys, cs_t *mp_usr, char *buf, u32 index, const hashconfig_t *hashconfig, const user_options_t *user_options); -void mp_reset_usr (cs_t *mp_usr, u32 index); - -u64 sp_get_sum (u32 start, u32 stop, cs_t *root_css_buf); void sp_exec (u64 ctx, char *pw_buf, cs_t *root_css_buf, cs_t *markov_css_buf, u32 start, u32 stop); -int sp_comp_val (const void *p1, const void *p2); -void sp_setup_tbl (const char *install_dir, char *hcstat, u32 disable, u32 classic, hcstat_table_t *root_table_buf, hcstat_table_t *markov_table_buf); -void sp_tbl_to_css (hcstat_table_t *root_table_buf, hcstat_table_t *markov_table_buf, cs_t *root_css_buf, cs_t *markov_css_buf, u32 threshold, u32 uniq_tbls[SP_PW_MAX][CHARSIZ]); -void sp_stretch_markov (hcstat_table_t *in, hcstat_table_t *out); -void sp_stretch_root (hcstat_table_t *in, hcstat_table_t *out); int mask_ctx_update_loop (hashcat_ctx_t *hashcat_ctx); int mask_ctx_init (hashcat_ctx_t *hashcat_ctx); diff --git a/include/opencl.h b/include/opencl.h index dae899ee3..16304eac3 100644 --- a/include/opencl.h +++ b/include/opencl.h @@ -18,6 +18,42 @@ static const char CL_VENDOR_MESA[] = "Mesa"; static const char CL_VENDOR_NV[] = "NVIDIA Corporation"; static const char CL_VENDOR_POCL[] = "The pocl project"; +int ocl_init (hashcat_ctx_t *hashcat_ctx); +void ocl_close (hashcat_ctx_t *hashcat_ctx); + +int hc_clBuildProgram (hashcat_ctx_t *hashcat_ctx, cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, void (CL_CALLBACK *pfn_notify) (cl_program program, void *user_data), void *user_data); +int hc_clCreateBuffer (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_mem *mem); +int hc_clCreateCommandQueue (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_device_id device, cl_command_queue_properties properties, cl_command_queue *command_queue); +int hc_clCreateContext (hashcat_ctx_t *hashcat_ctx, cl_context_properties *properties, cl_uint num_devices, const cl_device_id *devices, void (CL_CALLBACK *pfn_notify) (const char *, const void *, size_t, void *), void *user_data, cl_context *context); +int hc_clCreateKernel (hashcat_ctx_t *hashcat_ctx, cl_program program, const char *kernel_name, cl_kernel *kernel); +int hc_clCreateProgramWithBinary (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_uint num_devices, const cl_device_id *device_list, const size_t *lengths, const unsigned char **binaries, cl_int *binary_status, cl_program *program); +int hc_clCreateProgramWithSource (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_uint count, const char **strings, const size_t *lengths, cl_program *program); +int hc_clEnqueueCopyBuffer (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer, size_t src_offset, size_t dst_offset, size_t cb, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event); +int hc_clEnqueueMapBuffer (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_map, cl_map_flags map_flags, size_t offset, size_t cb, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event, void **buf); +int hc_clEnqueueNDRangeKernel (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim, const size_t *global_work_offset, const size_t *global_work_size, const size_t *local_work_size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event); +int hc_clEnqueueReadBuffer (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, size_t offset, size_t cb, void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event); +int hc_clEnqueueUnmapMemObject (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_mem memobj, void *mapped_ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event); +int hc_clEnqueueWriteBuffer (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, size_t offset, size_t cb, const void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event); +int hc_clFinish (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue); +int hc_clFlush (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue); +int hc_clGetDeviceIDs (hashcat_ctx_t *hashcat_ctx, cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, cl_device_id *devices, cl_uint *num_devices); +int hc_clGetDeviceInfo (hashcat_ctx_t *hashcat_ctx, cl_device_id device, cl_device_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret); +int hc_clGetEventInfo (hashcat_ctx_t *hashcat_ctx, cl_event event, cl_event_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret); +int hc_clGetEventProfilingInfo (hashcat_ctx_t *hashcat_ctx, cl_event event, cl_profiling_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret); +int hc_clGetKernelWorkGroupInfo (hashcat_ctx_t *hashcat_ctx, cl_kernel kernel, cl_device_id device, cl_kernel_work_group_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret); +int hc_clGetPlatformIDs (hashcat_ctx_t *hashcat_ctx, cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms); +int hc_clGetPlatformInfo (hashcat_ctx_t *hashcat_ctx, cl_platform_id platform, cl_platform_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret); +int hc_clGetProgramBuildInfo (hashcat_ctx_t *hashcat_ctx, cl_program program, cl_device_id device, cl_program_build_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret); +int hc_clGetProgramInfo (hashcat_ctx_t *hashcat_ctx, cl_program program, cl_program_info param_name, size_t param_value_size, void *param_value, size_t * param_value_size_ret); +int hc_clReleaseCommandQueue (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue); +int hc_clReleaseContext (hashcat_ctx_t *hashcat_ctx, cl_context context); +int hc_clReleaseEvent (hashcat_ctx_t *hashcat_ctx, cl_event event); +int hc_clReleaseKernel (hashcat_ctx_t *hashcat_ctx, cl_kernel kernel); +int hc_clReleaseMemObject (hashcat_ctx_t *hashcat_ctx, cl_mem mem); +int hc_clReleaseProgram (hashcat_ctx_t *hashcat_ctx, cl_program program); +int hc_clSetKernelArg (hashcat_ctx_t *hashcat_ctx, cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value); +int hc_clWaitForEvents (hashcat_ctx_t *hashcat_ctx, cl_uint num_events, const cl_event *event_list); + int gidd_to_pw_t (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u64 gidd, pw_t *pw); int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 highest_pw_len, const u32 pws_cnt, const u32 fast_iteration, const u32 salt_pos); int run_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 kern_run, const u32 num, const u32 event_update, const u32 iteration); diff --git a/include/outfile.h b/include/outfile.h index af88cb4fc..ef4b6b267 100644 --- a/include/outfile.h +++ b/include/outfile.h @@ -10,15 +10,15 @@ #include #include -void build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u32 *plain_buf, int *out_len); -void build_crackpos (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u64 *out_pos); -void build_debugdata (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u8 *debug_rule_buf, int *debug_rule_len, u8 *debug_plain_ptr, int *debug_plain_len); +int build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u32 *plain_buf, int *out_len); +int build_crackpos (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u64 *out_pos); +int build_debugdata (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u8 *debug_rule_buf, int *debug_rule_len, u8 *debug_plain_ptr, int *debug_plain_len); int outfile_init (hashcat_ctx_t *hashcat_ctx); void outfile_destroy (hashcat_ctx_t *hashcat_ctx); int outfile_write_open (hashcat_ctx_t *hashcat_ctx); void outfile_write_close (hashcat_ctx_t *hashcat_ctx); -void outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const unsigned char *plain_ptr, const u32 plain_len, const u64 crackpos, const unsigned char *username, const u32 user_len); +int outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const unsigned char *plain_ptr, const u32 plain_len, const u64 crackpos, const unsigned char *username, const u32 user_len, char tmp_buf[HCBUFSIZ_LARGE]); int outfile_and_hashfile (hashcat_ctx_t *hashcat_ctx); #endif // _OUTFILE_H diff --git a/include/potfile.h b/include/potfile.h index 9b552214e..72c54d805 100644 --- a/include/potfile.h +++ b/include/potfile.h @@ -12,8 +12,8 @@ #define INCR_POT 1000 -int sort_by_pot (const void *v1, const void *v2, void *v3); -int sort_by_salt_buf (const void *v1, const void *v2, void *v3); +int sort_by_pot (const void *v1, const void *v2, MAYBE_UNUSED void *v3); +int sort_by_salt_buf (const void *v1, const void *v2, MAYBE_UNUSED void *v3); int sort_by_hash_t_salt (const void *v1, const void *v2); int sort_by_hash_t_salt_hccap (const void *v1, const void *v2); @@ -22,18 +22,13 @@ void *hc_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size int potfile_init (hashcat_ctx_t *hashcat_ctx); int potfile_read_open (hashcat_ctx_t *hashcat_ctx); -void potfile_read_parse (hashcat_ctx_t *hashcat_ctx); void potfile_read_close (hashcat_ctx_t *hashcat_ctx); int potfile_write_open (hashcat_ctx_t *hashcat_ctx); void potfile_write_close (hashcat_ctx_t *hashcat_ctx); void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, u8 *plain_ptr, unsigned int plain_len); -void potfile_hash_alloc (hashcat_ctx_t *hashcat_ctx, const u32 num); -void potfile_hash_free (hashcat_ctx_t *hashcat_ctx); -void potfile_show_request (hashcat_ctx_t *hashcat_ctx, char *input_buf, int input_len, hash_t *hashes_buf, int (*sort_by_pot) (const void *, const void *, void *)); -void potfile_left_request (hashcat_ctx_t *hashcat_ctx, char *input_buf, int input_len, hash_t *hashes_buf, int (*sort_by_pot) (const void *, const void *, void *)); -void potfile_show_request_lm (hashcat_ctx_t *hashcat_ctx, char *input_buf, int input_len, hash_t *hash_left, hash_t *hash_right, int (*sort_by_pot) (const void *, const void *, void *)); -void potfile_left_request_lm (hashcat_ctx_t *hashcat_ctx, char *input_buf, int input_len, hash_t *hash_left, hash_t *hash_right, int (*sort_by_pot) (const void *, const void *, void *)); int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx); void potfile_destroy (hashcat_ctx_t *hashcat_ctx); +int potfile_handle_show (hashcat_ctx_t *hashcat_ctx); +int potfile_handle_left (hashcat_ctx_t *hashcat_ctx); #endif // _POTFILE_H diff --git a/include/restore.h b/include/restore.h index 72a06955c..28623f8fb 100644 --- a/include/restore.h +++ b/include/restore.h @@ -23,20 +23,10 @@ #define RESTORE_VERSION_MIN 320 #define RESTORE_VERSION_CUR 320 -u64 get_lowest_words_done (hashcat_ctx_t *hashcat_ctx); - -void init_restore (hashcat_ctx_t *hashcat_ctx); - -void read_restore (hashcat_ctx_t *hashcat_ctx); - -void write_restore (hashcat_ctx_t *hashcat_ctx); - -void cycle_restore (hashcat_ctx_t *hashcat_ctx); +int cycle_restore (hashcat_ctx_t *hashcat_ctx); void unlink_restore (hashcat_ctx_t *hashcat_ctx); -void stop_at_checkpoint (hashcat_ctx_t *hashcat_ctx); - int restore_ctx_init (hashcat_ctx_t *hashcat_ctx, int argc, char **argv); void restore_ctx_destroy (hashcat_ctx_t *hashcat_ctx); diff --git a/include/shared.h b/include/shared.h index 9971466f1..1fa73fcf3 100644 --- a/include/shared.h +++ b/include/shared.h @@ -24,8 +24,8 @@ char *filename_from_filepath (char *filepath); void naive_replace (char *s, const char key_char, const char replace_char); void naive_escape (char *s, size_t s_max, const char key_char, const char escape_char); -void hc_sleep_ms (const u32 msec); -void hc_sleep (const u32 sec); +void hc_sleep_msec (const u32 msec); +void hc_sleep (const u32 sec); void setup_environment_variables (); void setup_umask (); diff --git a/include/status.h b/include/status.h index 2799f5def..60f8dc16e 100644 --- a/include/status.h +++ b/include/status.h @@ -12,16 +12,72 @@ double get_avg_exec_time (hc_device_param_t *device_param, const int last_num_entries); -void status_display_machine_readable (hashcat_ctx_t *hashcat_ctx); -void status_display (hashcat_ctx_t *hashcat_ctx); -void status_benchmark_automate (hashcat_ctx_t *hashcat_ctx); -void status_benchmark (hashcat_ctx_t *hashcat_ctx); +// should be static after refactoring +void format_timer_display (struct tm *tm, char *buf, size_t len); +void format_speed_display (double val, char *buf, size_t len); -int status_progress_init (hashcat_ctx_t *hashcat_ctx); -void status_progress_destroy (hashcat_ctx_t *hashcat_ctx); -void status_progress_reset (hashcat_ctx_t *hashcat_ctx); +int status_get_device_info_cnt (const hashcat_ctx_t *hashcat_ctx); +int status_get_device_info_active (const hashcat_ctx_t *hashcat_ctx); +bool status_get_skipped_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id); +char *status_get_session (const hashcat_ctx_t *hashcat_ctx); +char *status_get_status_string (const hashcat_ctx_t *hashcat_ctx); +int status_get_status_number (const hashcat_ctx_t *hashcat_ctx); +int status_get_input_mode (const hashcat_ctx_t *hashcat_ctx); +char *status_get_input_base (const hashcat_ctx_t *hashcat_ctx); +char *status_get_input_mod (const hashcat_ctx_t *hashcat_ctx); +char *status_get_input_charset (const hashcat_ctx_t *hashcat_ctx); +char *status_get_input_candidates_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id); +char *status_get_hash_type (const hashcat_ctx_t *hashcat_ctx); +char *status_get_hash_target (const hashcat_ctx_t *hashcat_ctx); +int status_get_digests_done (const hashcat_ctx_t *hashcat_ctx); +int status_get_digests_cnt (const hashcat_ctx_t *hashcat_ctx); +double status_get_digests_percent (const hashcat_ctx_t *hashcat_ctx); +int status_get_salts_done (const hashcat_ctx_t *hashcat_ctx); +int status_get_salts_cnt (const hashcat_ctx_t *hashcat_ctx); +double status_get_salts_percent (const hashcat_ctx_t *hashcat_ctx); +double status_get_msec_running (const hashcat_ctx_t *hashcat_ctx); +double status_get_msec_paused (const hashcat_ctx_t *hashcat_ctx); +double status_get_msec_real (const hashcat_ctx_t *hashcat_ctx); +char *status_get_time_started_absolute (const hashcat_ctx_t *hashcat_ctx); +char *status_get_time_started_relative (const hashcat_ctx_t *hashcat_ctx); +char *status_get_time_estimated_absolute (const hashcat_ctx_t *hashcat_ctx); +char *status_get_time_estimated_relative (const hashcat_ctx_t *hashcat_ctx); +u64 status_get_restore_point (const hashcat_ctx_t *hashcat_ctx); +u64 status_get_restore_total (const hashcat_ctx_t *hashcat_ctx); +double status_get_restore_percent (const hashcat_ctx_t *hashcat_ctx); +int status_get_progress_mode (const hashcat_ctx_t *hashcat_ctx); +double status_get_progress_finished_percent (const hashcat_ctx_t *hashcat_ctx); +u64 status_get_progress_done (const hashcat_ctx_t *hashcat_ctx); +u64 status_get_progress_rejected (const hashcat_ctx_t *hashcat_ctx); +double status_get_progress_rejected_percent (const hashcat_ctx_t *hashcat_ctx); +u64 status_get_progress_restored (const hashcat_ctx_t *hashcat_ctx); +u64 status_get_progress_cur (const hashcat_ctx_t *hashcat_ctx); +u64 status_get_progress_end (const hashcat_ctx_t *hashcat_ctx); +u64 status_get_progress_ignore (const hashcat_ctx_t *hashcat_ctx); +u64 status_get_progress_skip (const hashcat_ctx_t *hashcat_ctx); +u64 status_get_progress_cur_relative_skip (const hashcat_ctx_t *hashcat_ctx); +u64 status_get_progress_end_relative_skip (const hashcat_ctx_t *hashcat_ctx); +double status_get_hashes_msec_all (const hashcat_ctx_t *hashcat_ctx); +double status_get_hashes_msec_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id); +double status_get_hashes_msec_dev_benchmark (const hashcat_ctx_t *hashcat_ctx, const int device_id); +double status_get_exec_msec_all (const hashcat_ctx_t *hashcat_ctx); +double status_get_exec_msec_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id); +char *status_get_speed_sec_all (const hashcat_ctx_t *hashcat_ctx); +char *status_get_speed_sec_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id); +int status_get_cpt_cur_min (const hashcat_ctx_t *hashcat_ctx); +int status_get_cpt_cur_hour (const hashcat_ctx_t *hashcat_ctx); +int status_get_cpt_cur_day (const hashcat_ctx_t *hashcat_ctx); +double status_get_cpt_avg_min (const hashcat_ctx_t *hashcat_ctx); +double status_get_cpt_avg_hour (const hashcat_ctx_t *hashcat_ctx); +double status_get_cpt_avg_day (const hashcat_ctx_t *hashcat_ctx); +char *status_get_cpt (const hashcat_ctx_t *hashcat_ctx); +char *status_get_hwmon_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id); -int status_ctx_init (hashcat_ctx_t *hashcat_ctx); -void status_ctx_destroy (hashcat_ctx_t *hashcat_ctx); +int status_progress_init (hashcat_ctx_t *hashcat_ctx); +void status_progress_destroy (hashcat_ctx_t *hashcat_ctx); +void status_progress_reset (hashcat_ctx_t *hashcat_ctx); + +int status_ctx_init (hashcat_ctx_t *hashcat_ctx); +void status_ctx_destroy (hashcat_ctx_t *hashcat_ctx); #endif // _STATUS_H diff --git a/include/stdout.h b/include/stdout.h index a40fdb91a..910b9e69c 100644 --- a/include/stdout.h +++ b/include/stdout.h @@ -20,6 +20,6 @@ #include #endif // _POSIX -void process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 pws_cnt); +int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 pws_cnt); #endif // _STDOUT_H diff --git a/include/terminal.h b/include/terminal.h index 6c73e1890..284411387 100644 --- a/include/terminal.h +++ b/include/terminal.h @@ -26,7 +26,7 @@ void welcome_screen (hashcat_ctx_t *hashcat_ctx, const time_t proc_start, const char *version_tag); void goodbye_screen (hashcat_ctx_t *hashcat_ctx, const time_t proc_start, const time_t proc_stop); -int setup_console (); +int setup_console (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx); void send_prompt (); void clear_prompt (); @@ -42,3 +42,8 @@ int tty_getchar(); int tty_fix(); #endif // _TERMINAL_H + +void status_display_machine_readable (hashcat_ctx_t *hashcat_ctx); +void status_display (hashcat_ctx_t *hashcat_ctx); +void status_benchmark_automate (hashcat_ctx_t *hashcat_ctx); +void status_benchmark (hashcat_ctx_t *hashcat_ctx); diff --git a/include/thread.h b/include/thread.h index b73796af3..713fe9064 100644 --- a/include/thread.h +++ b/include/thread.h @@ -56,12 +56,12 @@ void hc_signal (void (callback) (int)); #endif */ -void mycracked (status_ctx_t *status_ctx); -void myabort (status_ctx_t *status_ctx); -void myquit (status_ctx_t *status_ctx); -void bypass (status_ctx_t *status_ctx); - -void SuspendThreads (status_ctx_t *status_ctx); -void ResumeThreads (status_ctx_t *status_ctx); +int mycracked (hashcat_ctx_t *hashcat_ctx); +int myabort (hashcat_ctx_t *hashcat_ctx); +int myquit (hashcat_ctx_t *hashcat_ctx); +int bypass (hashcat_ctx_t *hashcat_ctx); +int SuspendThreads (hashcat_ctx_t *hashcat_ctx); +int ResumeThreads (hashcat_ctx_t *hashcat_ctx); +int stop_at_checkpoint (hashcat_ctx_t *hashcat_ctx); #endif // _THREAD_H diff --git a/include/types.h b/include/types.h index cf6edf9ae..600377b34 100644 --- a/include/types.h +++ b/include/types.h @@ -37,12 +37,6 @@ typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; -#include "ext_OpenCL.h" -#include "ext_ADL.h" -#include "ext_nvapi.h" -#include "ext_nvml.h" -#include "ext_xnvctrl.h" - // timer #if defined (_WIN) @@ -81,6 +75,58 @@ typedef struct stat64 hc_stat; // enums +typedef enum loglevel +{ + LOGLEVEL_INFO = 0, + LOGLEVEL_WARNING = 1, + LOGLEVEL_ERROR = 2, + +} loglevel_t; + +typedef enum event_identifier +{ + EVENT_LOG_INFO = 0x00000001, + EVENT_LOG_WARNING = 0x00000002, + EVENT_LOG_ERROR = 0x00000003, + EVENT_WELCOME_SCREEN = 0x00000011, + EVENT_GOODBYE_SCREEN = 0x00000012, + EVENT_OUTERLOOP_STARTING = 0x00000031, + EVENT_OUTERLOOP_MAINSCREEN = 0x00000032, + EVENT_OUTERLOOP_FINISHED = 0x00000033, + EVENT_INNERLOOP1_STARTING = 0x00000041, + EVENT_INNERLOOP1_FINISHED = 0x00000042, + EVENT_INNERLOOP2_STARTING = 0x00000051, + EVENT_INNERLOOP2_FINISHED = 0x00000052, + EVENT_CALCULATED_WORDS_BASE = 0x00000059, + EVENT_AUTOTUNE_STARTING = 0x00000053, + EVENT_AUTOTUNE_FINISHED = 0x00000054, + EVENT_CRACKER_STARTING = 0x00000055, + EVENT_CRACKER_FINISHED = 0x00000056, + EVENT_CRACKER_HASH_CRACKED = 0x00000058, + EVENT_POTFILE_REMOVE_PARSE_PRE = 0x00000061, + EVENT_POTFILE_REMOVE_PARSE_POST = 0x00000062, + EVENT_POTFILE_NUM_CRACKED = 0x00000063, + EVENT_POTFILE_ALL_CRACKED = 0x00000064, + EVENT_POTFILE_HASH_SHOW = 0x00000065, + EVENT_POTFILE_HASH_LEFT = 0x00000066, + EVENT_OPENCL_SESSION_PRE = 0x00000071, + EVENT_OPENCL_SESSION_POST = 0x00000072, + EVENT_BITMAP_INIT_PRE = 0x00000081, + EVENT_BITMAP_INIT_POST = 0x00000082, + EVENT_WEAK_HASH_PRE = 0x00000091, + EVENT_WEAK_HASH_POST = 0x00000092, + EVENT_SET_KERNEL_POWER_FINAL = 0x000000a1, + EVENT_MONITOR_THROTTLE1 = 0x000000b1, + EVENT_MONITOR_THROTTLE2 = 0x000000b2, + EVENT_MONITOR_THROTTLE3 = 0x000000b3, + EVENT_MONITOR_TEMP_ABORT = 0x000000c1, + EVENT_MONITOR_RUNTIME_LIMIT = 0x000000d1, + EVENT_MONITOR_STATUS_REFRESH = 0x000000e1, + + // there will be much more event types soon + +} event_identifier_t; + typedef enum amplifier_count { KERNEL_BFS = 1024, @@ -378,6 +424,7 @@ typedef enum parser_rc PARSER_TC_FILE_SIZE = -15, PARSER_VC_FILE_SIZE = -16, PARSER_SIP_AUTH_DIRECTIVE = -17, + PARSER_HASH_FILE = -18, PARSER_UNKNOWN_ERROR = -255 } parser_rc_t; @@ -430,6 +477,8 @@ typedef struct hash void *esalt; int cracked; hashinfo_t *hash_info; + char *pw_buf; + int pw_len; } hash_t; @@ -474,6 +523,7 @@ typedef struct hashes void *esalts_buf; + u32 hashes_cnt_orig; u32 hashes_cnt; hash_t *hashes_buf; @@ -572,6 +622,8 @@ typedef struct wordr } wordr_t; +#include "ext_OpenCL.h" + typedef struct hc_device_param { cl_device_id device; @@ -637,7 +689,7 @@ typedef struct hc_device_param u32 innerloop_left; u32 exec_pos; - double exec_ms[EXEC_CACHE]; + double exec_msec[EXEC_CACHE]; // workaround cpu spinning @@ -649,7 +701,7 @@ typedef struct hc_device_param u32 speed_pos; u64 speed_cnt[SPEED_CACHE]; - double speed_ms[SPEED_CACHE]; + double speed_msec[SPEED_CACHE]; hc_timer_t timer_speed; @@ -776,17 +828,53 @@ typedef struct opencl_ctx u32 devices_filter; cl_device_type device_types_filter; - double target_ms; + double target_msec; - int need_adl; - int need_nvml; - int need_nvapi; - int need_xnvctrl; + bool need_adl; + bool need_nvml; + bool need_nvapi; + bool need_xnvctrl; int force_jit_compilation; } opencl_ctx_t; +#include "ext_ADL.h" +#include "ext_nvapi.h" +#include "ext_nvml.h" +#include "ext_xnvctrl.h" + +typedef struct hm_attrs +{ + HM_ADAPTER_ADL adl; + HM_ADAPTER_NVML nvml; + HM_ADAPTER_NVAPI nvapi; + HM_ADAPTER_XNVCTRL xnvctrl; + + int od_version; + + bool fan_get_supported; + bool fan_set_supported; + +} hm_attrs_t; + +typedef struct hwmon_ctx +{ + bool enabled; + + void *hm_adl; + void *hm_nvml; + void *hm_nvapi; + void *hm_xnvctrl; + + hm_attrs_t *hm_device; + + ADLOD6MemClockState *od_clock_mem_status; + int *od_power_control_status; + unsigned int *nvml_power_limit; + +} hwmon_ctx_t; + #if defined (__APPLE__) typedef struct cpu_set { @@ -847,20 +935,6 @@ typedef struct dictstat_ctx } dictstat_ctx_t; -typedef struct hm_attrs -{ - HM_ADAPTER_ADL adl; - HM_ADAPTER_NVML nvml; - HM_ADAPTER_NVAPI nvapi; - HM_ADAPTER_XNVCTRL xnvctrl; - - int od_version; - - bool fan_get_supported; - bool fan_set_supported; - -} hm_attrs_t; - typedef struct loopback_ctx { bool enabled; @@ -918,12 +992,6 @@ typedef struct potfile_ctx FILE *fp; char *filename; - pot_t *pot; - - u32 pot_cnt; - u32 pot_avail; - u32 pot_hashes_avail; - } potfile_ctx_t; typedef struct restore_data @@ -1026,87 +1094,10 @@ typedef struct wl_data typedef struct user_options { - bool usage; - bool version; - bool quiet; - bool benchmark; - bool stdout_flag; - bool show; - bool left; - bool username; - bool remove; - u32 remove_timer; - u64 skip; - u64 limit; - bool force; - bool keyspace; - bool potfile_disable; - char *potfile_path; - u32 debug_mode; - char *debug_file; - char *induction_dir; - char *outfile_check_dir; - u32 runtime; - u32 hash_mode; - u32 attack_mode; - char *outfile; - u32 outfile_format; - bool outfile_autohex; - u32 outfile_check_timer; - bool restore; - u32 restore_timer; - bool restore_disable; - bool status; - u32 status_timer; - bool machine_readable; - bool loopback; - u32 weak_hash_threshold; - char *session; - bool hex_charset; - bool hex_salt; - bool hex_wordlist; - u32 rp_gen; - u32 rp_gen_func_min; - u32 rp_gen_func_max; - u32 rp_gen_seed; - char *rule_buf_l; - char *rule_buf_r; - bool increment; - u32 increment_min; - u32 increment_max; - char *cpu_affinity; - bool opencl_info; - char *opencl_devices; - char *opencl_platforms; - char *opencl_device_types; - u32 opencl_vector_width; - char *truecrypt_keyfiles; - char *veracrypt_keyfiles; - u32 veracrypt_pim; - u32 workload_profile; - u32 kernel_accel; - u32 kernel_loops; - u32 nvidia_spin_damp; - bool gpu_temp_disable; - u32 gpu_temp_abort; - u32 gpu_temp_retain; - bool powertune_enable; - bool logfile_disable; - u32 segment_size; - u32 scrypt_tmto; - char separator; - u32 bitmap_min; - u32 bitmap_max; - bool markov_disable; - bool markov_classic; - u32 markov_threshold; - char *markov_hcstat; - char *custom_charset_1; - char *custom_charset_2; - char *custom_charset_3; - char *custom_charset_4; - u32 rp_files_cnt; - char **rp_files; + char *hc_bin; + + int hc_argc; + char **hc_argv; bool attack_mode_chgd; bool hash_mode_chgd; @@ -1123,10 +1114,88 @@ typedef struct user_options bool workload_profile_chgd; bool segment_size_chgd; - char *hc_bin; - - int hc_argc; - char **hc_argv; + bool benchmark; + bool force; + bool gpu_temp_disable; + bool hex_charset; + bool hex_salt; + bool hex_wordlist; + bool increment; + bool keyspace; + bool left; + bool logfile_disable; + bool loopback; + bool machine_readable; + bool markov_classic; + bool markov_disable; + bool opencl_info; + bool outfile_autohex; + bool potfile_disable; + bool powertune_enable; + bool quiet; + bool remove; + bool restore; + bool restore_disable; + bool show; + bool status; + bool stdout_flag; + bool speed_only; + bool usage; + bool username; + bool version; + char *cpu_affinity; + char *custom_charset_1; + char *custom_charset_2; + char *custom_charset_3; + char *custom_charset_4; + char *debug_file; + char *induction_dir; + char *markov_hcstat; + char *opencl_devices; + char *opencl_device_types; + char *opencl_platforms; + char *outfile; + char *outfile_check_dir; + char *potfile_path; + char **rp_files; + char *rule_buf_l; + char *rule_buf_r; + char separator; + char *session; + char *truecrypt_keyfiles; + char *veracrypt_keyfiles; + u32 attack_mode; + u32 bitmap_max; + u32 bitmap_min; + u32 debug_mode; + u32 gpu_temp_abort; + u32 gpu_temp_retain; + u32 hash_mode; + u32 increment_max; + u32 increment_min; + u32 kernel_accel; + u32 kernel_loops; + u32 markov_threshold; + u32 nvidia_spin_damp; + u32 opencl_vector_width; + u32 outfile_check_timer; + u32 outfile_format; + u32 remove_timer; + u32 restore_timer; + u32 rp_files_cnt; + u32 rp_gen; + u32 rp_gen_func_max; + u32 rp_gen_func_min; + u32 rp_gen_seed; + u32 runtime; + u32 scrypt_tmto; + u32 segment_size; + u32 status_timer; + u32 veracrypt_pim; + u32 weak_hash_threshold; + u32 workload_profile; + u64 limit; + u64 skip; } user_options_t; @@ -1260,23 +1329,6 @@ typedef struct mask_ctx } mask_ctx_t; -typedef struct hwmon_ctx -{ - bool enabled; - - void *hm_adl; - void *hm_nvml; - void *hm_nvapi; - void *hm_xnvctrl; - - hm_attrs_t *hm_device; - - ADLOD6MemClockState *od_clock_mem_status; - int *od_power_control_status; - unsigned int *nvml_power_limit; - -} hwmon_ctx_t; - typedef struct cpt_ctx { bool enabled; @@ -1318,9 +1370,11 @@ typedef struct status_ctx * workload */ - u64 words_cnt; - u64 words_cur; - u64 words_base; + u64 words_off; // used by dispatcher; get_work () as offset; attention: needs to be redone on in restore case! + u64 words_cur; // used by dispatcher; the different to words_cur_next is that this counter guarantees that the work from zero to this counter has been actually computed + // has been finished actually, can be used for restore point therefore + u64 words_base; // the unamplified max keyspace + u64 words_cnt; // the amplified max keyspace /** * progress @@ -1346,10 +1400,31 @@ typedef struct status_ctx hc_timer_t timer_running; // timer on current dict hc_timer_t timer_paused; // timer on current dict - double ms_paused; // timer on current dict + double msec_paused; // timer on current dict } status_ctx_t; +typedef struct hashcat_user +{ + // use this for context specific data + + int outer_threads_cnt; + hc_thread_t *outer_threads; + +} hashcat_user_t; + +typedef struct event_ctx +{ + char msg_buf[HCBUFSIZ_TINY]; + int msg_len; + bool msg_newline; + + int prev_len; + + hc_thread_mutex_t mux_event; + +} event_ctx_t; + typedef struct hashcat_ctx { bitmap_ctx_t *bitmap_ctx; @@ -1357,7 +1432,9 @@ typedef struct hashcat_ctx cpt_ctx_t *cpt_ctx; debugfile_ctx_t *debugfile_ctx; dictstat_ctx_t *dictstat_ctx; + event_ctx_t *event_ctx; folder_config_t *folder_config; + hashcat_user_t *hashcat_user; hashconfig_t *hashconfig; hashes_t *hashes; hwmon_ctx_t *hwmon_ctx; @@ -1377,8 +1454,107 @@ typedef struct hashcat_ctx user_options_t *user_options; wl_data_t *wl_data; + void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t); + } hashcat_ctx_t; +typedef enum input_mode +{ + INPUT_MODE_NONE = 0, + INPUT_MODE_STRAIGHT_FILE = 1, + INPUT_MODE_STRAIGHT_FILE_RULES_FILE = 2, + INPUT_MODE_STRAIGHT_FILE_RULES_GEN = 3, + INPUT_MODE_STRAIGHT_STDIN = 4, + INPUT_MODE_STRAIGHT_STDIN_RULES_FILE = 5, + INPUT_MODE_STRAIGHT_STDIN_RULES_GEN = 6, + INPUT_MODE_COMBINATOR_BASE_LEFT = 7, + INPUT_MODE_COMBINATOR_BASE_RIGHT = 8, + INPUT_MODE_MASK = 9, + INPUT_MODE_MASK_CS = 10, + INPUT_MODE_HYBRID1 = 11, + INPUT_MODE_HYBRID1_CS = 12, + INPUT_MODE_HYBRID2 = 13, + INPUT_MODE_HYBRID2_CS = 14, + +} input_mode_t; + +typedef enum progress_mode +{ + PROGRESS_MODE_NONE = 0, + PROGRESS_MODE_KEYSPACE_KNOWN = 1, + PROGRESS_MODE_KEYSPACE_UNKNOWN = 2, + +} progress_mode_t; + +typedef struct +{ + bool skipped_dev; + double hashes_msec_dev; + double hashes_msec_dev_benchmark; + double exec_msec_dev; + char *speed_sec_dev; + char *input_candidates_dev; + char *hwmon_dev; + +} device_info_t; + +typedef struct +{ + char *hash_target; + char *hash_type; + char *input_base; + char *input_charset; + char *input_mod; + char *session; + char *status_string; + int status_number; + char *time_estimated_absolute; + char *time_estimated_relative; + char *time_started_absolute; + char *time_started_relative; + double msec_paused; + double msec_running; + double msec_real; + int digests_cnt; + int digests_done; + double digests_percent; + int input_mode; + int salts_cnt; + int salts_done; + double salts_percent; + int progress_mode; + double progress_finished_percent; + u64 progress_cur; + u64 progress_cur_relative_skip; + u64 progress_done; + u64 progress_end; + u64 progress_end_relative_skip; + u64 progress_ignore; + u64 progress_rejected; + double progress_rejected_percent; + u64 progress_restored; + u64 progress_skip; + u64 restore_point; + u64 restore_total; + double restore_percent; + int cpt_cur_min; + int cpt_cur_hour; + int cpt_cur_day; + double cpt_avg_min; + double cpt_avg_hour; + double cpt_avg_day; + char *cpt; + + device_info_t device_info_buf[DEVICES_MAX]; + int device_info_cnt; + int device_info_active; + + double hashes_msec_all; + double exec_msec_all; + char *speed_sec_all; + +} hashcat_status_t; + typedef struct thread_param { u32 tid; diff --git a/include/usage.h b/include/usage.h index e0cd5a575..6a1b88543 100644 --- a/include/usage.h +++ b/include/usage.h @@ -6,6 +6,8 @@ #ifndef _USAGE_H #define _USAGE_H +#include + void usage_mini_print (const char *progname); void usage_big_print (const char *progname); diff --git a/include/user_options.h b/include/user_options.h index da54d7d49..ba5fd8719 100644 --- a/include/user_options.h +++ b/include/user_options.h @@ -10,45 +10,45 @@ typedef enum user_options_defaults { - ATTACK_MODE = 0, - BENCHMARK = 0, + ATTACK_MODE = ATTACK_MODE_STRAIGHT, + BENCHMARK = false, BITMAP_MAX = 24, BITMAP_MIN = 16, DEBUG_MODE = 0, - FORCE = 0, + FORCE = false, GPU_TEMP_ABORT = 90, - GPU_TEMP_DISABLE = 0, + GPU_TEMP_DISABLE = false, GPU_TEMP_RETAIN = 75, HASH_MODE = 0, - HEX_CHARSET = 0, - HEX_SALT = 0, - HEX_WORDLIST = 0, - INCREMENT = 0, + HEX_CHARSET = false, + HEX_SALT = false, + HEX_WORDLIST = false, + INCREMENT = false, INCREMENT_MAX = PW_MAX, INCREMENT_MIN = 1, KERNEL_ACCEL = 0, KERNEL_LOOPS = 0, - KEYSPACE = 0, - LEFT = 0, + KEYSPACE = false, + LEFT = false, LIMIT = 0, - LOGFILE_DISABLE = 0, - LOOPBACK = 0, - MACHINE_READABLE = 0, - MARKOV_CLASSIC = 0, - MARKOV_DISABLE = 0, + LOGFILE_DISABLE = false, + LOOPBACK = false, + MACHINE_READABLE = false, + MARKOV_CLASSIC = false, + MARKOV_DISABLE = false, MARKOV_THRESHOLD = 0, NVIDIA_SPIN_DAMP = 100, OPENCL_VECTOR_WIDTH = 0, - OUTFILE_AUTOHEX = 1, + OUTFILE_AUTOHEX = true, OUTFILE_CHECK_TIMER = 5, OUTFILE_FORMAT = 3, - POTFILE_DISABLE = 0, - POWERTUNE_ENABLE = 0, - QUIET = 0, - REMOVE = 0, + POTFILE_DISABLE = false, + POWERTUNE_ENABLE = false, + QUIET = false, + REMOVE = false, REMOVE_TIMER = 60, - RESTORE = 0, - RESTORE_DISABLE = 0, + RESTORE = false, + RESTORE_DISABLE = false, RESTORE_TIMER = 60, RP_GEN = 0, RP_GEN_FUNC_MAX = 4, @@ -58,14 +58,15 @@ typedef enum user_options_defaults SCRYPT_TMTO = 0, SEGMENT_SIZE = 33554432, SEPARATOR = ':', - SHOW = 0, + SHOW = false, SKIP = 0, - STATUS = 0, + STATUS = false, STATUS_TIMER = 10, - STDOUT_FLAG = 0, - USAGE = 0, - USERNAME = 0, - VERSION = 0, + STDOUT_FLAG = false, + SPEED_ONLY = false, + USAGE = false, + USERNAME = false, + VERSION = false, WEAK_HASH_THRESHOLD = 100, WORKLOAD_PROFILE = 2, @@ -145,18 +146,19 @@ typedef enum user_options_map IDX_STATUS = 0xff2d, IDX_STATUS_TIMER = 0xff2e, IDX_STDOUT_FLAG = 0xff2f, - IDX_TRUECRYPT_KEYFILES = 0xff30, - IDX_USERNAME = 0xff31, - IDX_VERACRYPT_KEYFILES = 0xff32, - IDX_VERACRYPT_PIM = 0xff33, + IDX_SPEED_ONLY = 0xff30, + IDX_TRUECRYPT_KEYFILES = 0xff31, + IDX_USERNAME = 0xff32, + IDX_VERACRYPT_KEYFILES = 0xff33, + IDX_VERACRYPT_PIM = 0xff34, IDX_VERSION_LOWER = 'v', IDX_VERSION = 'V', - IDX_WEAK_HASH_THRESHOLD = 0xff34, + IDX_WEAK_HASH_THRESHOLD = 0xff35, IDX_WORKLOAD_PROFILE = 'w' } user_options_map_t; -void user_options_init (hashcat_ctx_t *hashcat_ctx); +int user_options_init (hashcat_ctx_t *hashcat_ctx); void user_options_destroy (hashcat_ctx_t *hashcat_ctx); diff --git a/include/weak_hash.h b/include/weak_hash.h index aad4a9f3c..a2d0dfc44 100644 --- a/include/weak_hash.h +++ b/include/weak_hash.h @@ -6,6 +6,6 @@ #ifndef _WEAK_HASH_H #define _WEAK_HASH_H -void weak_hash_check (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 salt_pos); +int weak_hash_check (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 salt_pos); #endif // _WEAK_HASH_H diff --git a/include/wordlist.h b/include/wordlist.h index fa68bf83c..0efa2221e 100644 --- a/include/wordlist.h +++ b/include/wordlist.h @@ -18,9 +18,9 @@ void get_next_word_uc (char *buf, u64 sz, u64 *len, u64 *off); void get_next_word_std (char *buf, u64 sz, u64 *len, u64 *off); void get_next_word (hashcat_ctx_t *hashcat_ctx, FILE *fd, char **out_buf, u32 *out_len); -void load_segment (hashcat_ctx_t *hashcat_ctx, FILE *fd); +int load_segment (hashcat_ctx_t *hashcat_ctx, FILE *fd); u64 count_words (hashcat_ctx_t *hashcat_ctx, FILE *fd, const char *dictfile); -void wl_data_init (hashcat_ctx_t *hashcat_ctx); +int wl_data_init (hashcat_ctx_t *hashcat_ctx); void wl_data_destroy (hashcat_ctx_t *hashcat_ctx); #endif // _WORDLIST_H diff --git a/src/Makefile b/src/Makefile index f1dcfc06c..8c9f2d698 100644 --- a/src/Makefile +++ b/src/Makefile @@ -12,9 +12,12 @@ PROG_NAME := hashcat UNAME := $(shell uname -s) # we need to strip the windows version number to be able to build hashcat on cygwin hosts -UNAME := $(patsubst CYGWIN_NT-%,CYGWIN_NT-,$(UNAME)) +UNAME := $(patsubst CYGWIN_NT-%,CYGWIN,$(UNAME)) +UNAME := $(patsubst MSYS_NT-%,MSYS2,$(UNAME)) +UNAME := $(patsubst MINGW32_NT-%,MSYS2,$(UNAME)) +UNAME := $(patsubst MINGW64_NT-%,MSYS2,$(UNAME)) -ifeq (,$(filter $(UNAME),Linux Darwin CYGWIN_NT- FreeBSD)) +ifeq (,$(filter $(UNAME),Linux Darwin CYGWIN MSYS2 FreeBSD)) $(error "! Your Operating System ($(UNAME)) is not supported by $(PROG_NAME) Makefile") endif @@ -91,7 +94,9 @@ VERSION_TAG := $(shell test -d .git && git describe --tags --dirty= ## Compiler flags ## -CFLAGS += -pipe -W -Wall -std=c99 -Iinclude/ -IOpenCL/ -I$(OPENCL_HEADERS_KHRONOS)/ +INCLUDE_PATHS := -Iinclude/ -IOpenCL/ -I$(OPENCL_HEADERS_KHRONOS)/ + +CFLAGS += -pipe -W -Wall -std=c99 ifndef DEBUG CFLAGS += -O2 @@ -102,6 +107,14 @@ CFLAGS += -fsanitize=address -fno-omit-frame-pointer endif endif +## +## Linker flags +## + +ifndef DEBUG +LDFLAGS += -s +endif + ## ## Native compilation target ## @@ -118,12 +131,9 @@ endif # darwin ifeq ($(UNAME),Linux) CFLAGS_NATIVE := -ifndef DEBUG -CFLAGS_NATIVE += -s -endif CFLAGS_NATIVE += $(CFLAGS) -LFLAGS_NATIVE := -lpthread -ldl CFLAGS_NATIVE += -DWITH_HWMON +LFLAGS_NATIVE := -lpthread -ldl LFLAGS_NATIVE += $(LDFLAGS) endif # linux @@ -134,38 +144,45 @@ LFLAGS_NATIVE := -lpthread LFLAGS_NATIVE += $(LDFLAGS) endif # freebsd +CFLAGS_NATIVE_SHARED := +CFLAGS_NATIVE_SHARED += $(CFLAGS) +CFLAGS_NATIVE_SHARED += -DWITH_HWMON -fpic +LFLAGS_NATIVE_SHARED := -L. -lhashcat +LFLAGS_NATIVE_SHARED += -Wl,-rpath=. +LFLAGS_NATIVE_SHARED += -lpthread -ldl +LFLAGS_NATIVE_SHARED += $(LDFLAGS) + ## ## Cross compilation target ## CFLAGS_CROSS_LINUX := -ifndef DEBUG -CFLAGS_CROSS_LINUX += -s -endif CFLAGS_CROSS_LINUX += $(CFLAGS) CFLAGS_CROSS_LINUX += -DWITH_HWMON -#CFLAGS_CROSS_WIN := -D_WIN -DWIN -D__MSVCRT__ -D__USE_MINGW_ANSI_STDIO=1 CFLAGS_CROSS_WIN := -ifndef DEBUG -CFLAGS_CROSS_WIN += -s -endif CFLAGS_CROSS_WIN += $(filter-out -fsanitize=address,$(CFLAGS)) CFLAGS_CROSS_WIN += -DWITH_HWMON CFLAGS_CROSS_32 := -m32 CFLAGS_CROSS_64 := -m64 -LFLAGS_CROSS_LINUX := -lpthread -ldl -LFLAGS_CROSS_WIN := -lpsapi +LFLAGS_CROSS_LINUX := +LFLAGS_CROSS_LINUX += $(LDFLAGS) +LFLAGS_CROSS_LINUX += -lpthread -ldl + +LFLAGS_CROSS_WIN := +LFLAGS_CROSS_WIN += $(LDFLAGS) +LFLAGS_CROSS_WIN += -lpsapi -Wl,--dynamicbase -Wl,--nxcompat ## ## Objects ## -OBJS_ALL := affinity autotune benchmark bitmap bitops combinator common convert cpt cpu_aes cpu_crc32 cpu_des cpu_md5 cpu_sha1 cpu_sha256 debugfile dictstat dispatch dynloader ext_ADL ext_nvapi ext_nvml ext_OpenCL ext_xnvctrl filehandling folder hashcat hashes hlfmt hwmon induct interface locking logfile logging loopback memory monitor mpsp opencl outfile_check outfile potfile restore rp rp_cpu rp_kernel_on_cpu shared status stdout straight terminal thread timer tuningdb usage user_options weak_hash wordlist +OBJS_ALL := affinity autotune benchmark bitmap bitops combinator common convert cpt cpu_aes cpu_crc32 cpu_des cpu_md5 cpu_sha1 cpu_sha256 debugfile dictstat dispatch dynloader event ext_ADL ext_nvapi ext_nvml ext_OpenCL ext_xnvctrl filehandling folder hashcat hashes hlfmt hwmon induct interface locking logfile loopback memory monitor mpsp opencl outfile_check outfile potfile restore rp rp_cpu rp_kernel_on_cpu shared status stdout straight terminal thread timer tuningdb usage user_options weak_hash wordlist NATIVE_OBJS := $(foreach OBJ,$(OBJS_ALL),obj/$(OBJ).NATIVE.o) +NATIVE_SHARED_OBJS := $(foreach OBJ,$(OBJS_ALL),obj/$(OBJ).NATIVE.SHARED.o) LINUX_32_OBJS := $(foreach OBJ,$(OBJS_ALL),obj/$(OBJ).LINUX.32.o) LINUX_64_OBJS := $(foreach OBJ,$(OBJS_ALL),obj/$(OBJ).LINUX.64.o) @@ -190,7 +207,7 @@ native: hashcat binaries: linux32 linux64 win32 win64 clean: - $(RM) -f obj/*.o *.bin *.exe *.restore *.out *.pot *.log hashcat core + $(RM) -f obj/*.o *.bin *.exe *.restore *.out *.pot *.log hashcat hashcat_shared libhashcat.so core $(RM) -rf *.induct $(RM) -rf *.outfiles $(RM) -rf *.dSYM @@ -254,36 +271,49 @@ uninstall: ## native compiled hashcat ## -obj/%.NATIVE.o: src/%.c - $(CC) $(CFLAGS_NATIVE) -c -o $@ $< +obj/%.NATIVE.o: src/%.c + $(CC) -c $(CFLAGS_NATIVE) $(INCLUDE_PATHS) -o $@ $^ -$(BINARY_NATIVE): src/main.c $(NATIVE_OBJS) - $(CC) $(CFLAGS_NATIVE) -o $(BINARY_NATIVE) $^ $(LFLAGS_NATIVE) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\" +$(BINARY_NATIVE): $(NATIVE_OBJS) src/main.c + $(CC) $(CFLAGS_NATIVE) $(INCLUDE_PATHS) -o $@ $^ -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\" $(LFLAGS_NATIVE) + +## +## native compiled hashcat (shared) +## + +obj/%.NATIVE.SHARED.o: src/%.c + $(CC) -c $(CFLAGS_NATIVE_SHARED) $(INCLUDE_PATHS) -o $@ $^ + +lib$(BINARY_NATIVE).so: $(NATIVE_SHARED_OBJS) + $(CC) -o $@ $^ -shared + +$(BINARY_NATIVE)_shared: lib$(BINARY_NATIVE).so src/main_shared.c + $(CC) $(CFLAGS_NATIVE_SHARED) $(INCLUDE_PATHS) -o $@ $^ -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\" $(LFLAGS_NATIVE_SHARED) ## ## cross compiled hashcat for binary release version ## obj/%.LINUX.32.o: src/%.c - $(CC_LINUX_32) $(CFLAGS_CROSS_LINUX) $(CFLAGS_CROSS_32) -c -o $@ $< + $(CC_LINUX_32) $(CFLAGS_CROSS_LINUX) $(CFLAGS_CROSS_32) $(INCLUDE_PATHS) -c -o $@ $< obj/%.LINUX.64.o: src/%.c - $(CC_LINUX_64) $(CFLAGS_CROSS_LINUX) $(CFLAGS_CROSS_64) -c -o $@ $< + $(CC_LINUX_64) $(CFLAGS_CROSS_LINUX) $(CFLAGS_CROSS_64) $(INCLUDE_PATHS) -c -o $@ $< obj/%.WIN.32.o: src/%.c - $(CC_WIN_32) $(CFLAGS_CROSS_WIN) $(CFLAGS_CROSS_32) -c -o $@ $< + $(CC_WIN_32) $(CFLAGS_CROSS_WIN) $(CFLAGS_CROSS_32) $(INCLUDE_PATHS) -c -o $@ $< obj/%.WIN.64.o: src/%.c - $(CC_WIN_64) $(CFLAGS_CROSS_WIN) $(CFLAGS_CROSS_64) -c -o $@ $< + $(CC_WIN_64) $(CFLAGS_CROSS_WIN) $(CFLAGS_CROSS_64) $(INCLUDE_PATHS) -c -o $@ $< hashcat32.bin: src/main.c $(LINUX_32_OBJS) - $(CC_LINUX_32) $(CFLAGS_CROSS_LINUX) $(CFLAGS_CROSS_32) -o $@ $^ $(LFLAGS_CROSS_LINUX) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\" + $(CC_LINUX_32) $(CFLAGS_CROSS_LINUX) $(CFLAGS_CROSS_32) $(INCLUDE_PATHS) -o $@ $^ $(LFLAGS_CROSS_LINUX) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\" hashcat64.bin: src/main.c $(LINUX_64_OBJS) - $(CC_LINUX_64) $(CFLAGS_CROSS_LINUX) $(CFLAGS_CROSS_64) -o $@ $^ $(LFLAGS_CROSS_LINUX) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\" + $(CC_LINUX_64) $(CFLAGS_CROSS_LINUX) $(CFLAGS_CROSS_64) $(INCLUDE_PATHS) -o $@ $^ $(LFLAGS_CROSS_LINUX) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" -DINSTALL_FOLDER=\"$(INSTALL_FOLDER)\" -DSHARED_FOLDER=\"$(SHARED_FOLDER)\" -DDOCUMENT_FOLDER=\"$(DOCUMENT_FOLDER)\" hashcat32.exe: src/main.c $(WIN_32_OBJS) - $(CC_WIN_32) $(CFLAGS_CROSS_WIN) $(CFLAGS_CROSS_32) -o $@ $^ $(LFLAGS_CROSS_WIN) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" + $(CC_WIN_32) $(CFLAGS_CROSS_WIN) $(CFLAGS_CROSS_32) $(INCLUDE_PATHS) -o $@ $^ $(LFLAGS_CROSS_WIN) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" hashcat64.exe: src/main.c $(WIN_64_OBJS) - $(CC_WIN_64) $(CFLAGS_CROSS_WIN) $(CFLAGS_CROSS_64) -o $@ $^ $(LFLAGS_CROSS_WIN) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" + $(CC_WIN_64) $(CFLAGS_CROSS_WIN) $(CFLAGS_CROSS_64) $(INCLUDE_PATHS) -o $@ $^ $(LFLAGS_CROSS_WIN) -DCOMPTIME=$(COMPTIME) -DVERSION_TAG=\"$(VERSION_TAG)\" diff --git a/src/affinity.c b/src/affinity.c index b408fb058..7f141a4f3 100644 --- a/src/affinity.c +++ b/src/affinity.c @@ -10,7 +10,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "affinity.h" #if defined (__APPLE__) @@ -40,78 +40,86 @@ static int pthread_setaffinity_np (pthread_t thread, size_t cpu_size, cpu_set_t thread_affinity_policy_data_t policy = { core }; - const int rc = thread_policy_set (pthread_mach_thread_np (thread), THREAD_AFFINITY_POLICY, (thread_policy_t) &policy, 1); - - if (rc != KERN_SUCCESS) - { - log_error ("ERROR: %s : %d", "thread_policy_set()", rc); - - exit (-1); - } - - return rc; + return thread_policy_set (pthread_mach_thread_np (thread), THREAD_AFFINITY_POLICY, (thread_policy_t) &policy, 1); } #endif -void set_cpu_affinity (char *cpu_affinity) +#if defined (__FreeBSD__) +typedef cpuset_t cpu_set_t; +#endif + +int set_cpu_affinity (hashcat_ctx_t *hashcat_ctx) { - #if defined(_WIN) + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->cpu_affinity == NULL) return 0; + + #if defined (_WIN) DWORD_PTR aff_mask = 0; - #elif defined(__FreeBSD__) - cpuset_t cpuset; - CPU_ZERO (&cpuset); - #elif defined(_POSIX) + #else cpu_set_t cpuset; CPU_ZERO (&cpuset); #endif - if (cpu_affinity) + char *devices = hcstrdup (hashcat_ctx, user_options->cpu_affinity); + + char *next = strtok (devices, ","); + + do { - char *devices = mystrdup (cpu_affinity); + int cpu_id = atoi (next); - char *next = strtok (devices, ","); - - do + if (cpu_id == 0) { - int cpu_id = atoi (next); - - if (cpu_id == 0) - { - #if defined (_WIN) - aff_mask = 0; - #elif defined (_POSIX) - CPU_ZERO (&cpuset); - #endif - - break; - } - - if (cpu_id > 32) - { - log_error ("ERROR: Invalid cpu_id %u specified", cpu_id); - - exit (-1); - } - #if defined (_WIN) - aff_mask |= 1u << (cpu_id - 1); - #elif defined (_POSIX) - CPU_SET ((cpu_id - 1), &cpuset); + aff_mask = 0; + #else + CPU_ZERO (&cpuset); #endif - } while ((next = strtok (NULL, ",")) != NULL); + break; + } - myfree (devices); + if (cpu_id > 32) + { + event_log_error (hashcat_ctx, "Invalid cpu_id %u specified", cpu_id); + + return (-1); + } + + #if defined (_WIN) + aff_mask |= 1u << (cpu_id - 1); + #else + CPU_SET ((cpu_id - 1), &cpuset); + #endif + + } while ((next = strtok (NULL, ",")) != NULL); + + hcfree (devices); + + #if defined (_WIN) + + SetProcessAffinityMask (GetCurrentProcess (), aff_mask); + + if (SetThreadAffinityMask (GetCurrentThread (), aff_mask) == 0) + { + event_log_error (hashcat_ctx, "%s", "SetThreadAffinityMask()"); + + return -1; } - #if defined( _WIN) - SetProcessAffinityMask (GetCurrentProcess (), aff_mask); - SetThreadAffinityMask (GetCurrentThread (), aff_mask); - #elif defined(__FreeBSD__) + #else + pthread_t thread = pthread_self (); - pthread_setaffinity_np (thread, sizeof (cpuset_t), &cpuset); - #elif defined(_POSIX) - pthread_t thread = pthread_self (); - pthread_setaffinity_np (thread, sizeof (cpu_set_t), &cpuset); + + if (pthread_setaffinity_np (thread, sizeof (cpu_set_t), &cpuset) == -1) + { + event_log_error (hashcat_ctx, "%s", "pthread_setaffinity_np()"); + + return -1; + } + #endif + + return 0; } diff --git a/src/autotune.c b/src/autotune.c index 40df5266f..4219617ff 100644 --- a/src/autotune.c +++ b/src/autotune.c @@ -5,10 +5,9 @@ #include "common.h" #include "types.h" -#include "logging.h" +#include "event.h" #include "opencl.h" #include "status.h" -#include "terminal.h" #include "autotune.h" static double try_run (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 kernel_accel, const u32 kernel_loops) @@ -30,9 +29,9 @@ static double try_run (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_par run_kernel (hashcat_ctx, device_param, KERN_RUN_2, kernel_power_try, true, 0); } - const double exec_ms_prev = get_avg_exec_time (device_param, 1); + const double exec_msec_prev = get_avg_exec_time (device_param, 1); - return exec_ms_prev; + return exec_msec_prev; } static int autotune (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) @@ -42,7 +41,7 @@ static int autotune (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; - const double target_ms = opencl_ctx->target_ms; + const double target_msec = opencl_ctx->target_msec; const u32 kernel_accel_min = device_param->kernel_accel_min; const u32 kernel_accel_max = device_param->kernel_accel_max; @@ -82,9 +81,13 @@ static int autotune (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param const u32 kernel_power_max = device_param->device_processors * device_param->kernel_threads * kernel_accel_max; + int CL_rc; + if (user_options_extra->attack_kern == ATTACK_KERN_BF) { - run_kernel_memset (hashcat_ctx, device_param, device_param->d_pws_buf, 7, kernel_power_max * sizeof (pw_t)); + CL_rc = run_kernel_memset (hashcat_ctx, device_param, device_param->d_pws_buf, 7, kernel_power_max * sizeof (pw_t)); + + if (CL_rc == -1) return -1; } else { @@ -95,53 +98,45 @@ static int autotune (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param device_param->pws_buf[i].pw_len = 7 + (i & 7); } - cl_int CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, kernel_power_max * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, kernel_power_max * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL) { if (straight_ctx->kernel_rules_cnt > 1) { - cl_int CL_err = hc_clEnqueueCopyBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_rules, device_param->d_rules_c, 0, 0, MIN (kernel_loops_max, KERNEL_RULES) * sizeof (kernel_rule_t), 0, NULL, NULL); + CL_rc = hc_clEnqueueCopyBuffer (hashcat_ctx, device_param->command_queue, device_param->d_rules, device_param->d_rules_c, 0, 0, MIN (kernel_loops_max, KERNEL_RULES) * sizeof (kernel_rule_t), 0, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueCopyBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } } else { - run_kernel_amp (hashcat_ctx, device_param, kernel_power_max); + CL_rc = run_kernel_amp (hashcat_ctx, device_param, kernel_power_max); + + if (CL_rc == -1) return -1; } #define VERIFIER_CNT 1 - // first find out highest kernel-loops that stays below target_ms + // first find out highest kernel-loops that stays below target_msec if (kernel_loops_min < kernel_loops_max) { for (kernel_loops = kernel_loops_max; kernel_loops > kernel_loops_min; kernel_loops >>= 1) { - double exec_ms = try_run (hashcat_ctx, device_param, kernel_accel_min, kernel_loops); + double exec_msec = try_run (hashcat_ctx, device_param, kernel_accel_min, kernel_loops); for (int i = 0; i < VERIFIER_CNT; i++) { - double exec_ms_v = try_run (hashcat_ctx, device_param, kernel_accel_min, kernel_loops); + double exec_msec_v = try_run (hashcat_ctx, device_param, kernel_accel_min, kernel_loops); - exec_ms = MIN (exec_ms, exec_ms_v); + exec_msec = MIN (exec_msec, exec_msec_v); } - if (exec_ms < target_ms) break; + if (exec_msec < target_msec) break; } } @@ -158,16 +153,16 @@ static int autotune (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param if (kernel_accel_try < kernel_accel_min) continue; if (kernel_accel_try > kernel_accel_max) break; - double exec_ms = try_run (hashcat_ctx, device_param, kernel_accel_try, kernel_loops); + double exec_msec = try_run (hashcat_ctx, device_param, kernel_accel_try, kernel_loops); for (int i = 0; i < VERIFIER_CNT; i++) { - double exec_ms_v = try_run (hashcat_ctx, device_param, kernel_accel_try, kernel_loops); + double exec_msec_v = try_run (hashcat_ctx, device_param, kernel_accel_try, kernel_loops); - exec_ms = MIN (exec_ms, exec_ms_v); + exec_msec = MIN (exec_msec, exec_msec_v); } - if (exec_ms > target_ms) break; + if (exec_msec > target_msec) break; kernel_accel = kernel_accel_try; } @@ -177,17 +172,17 @@ static int autotune (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param // we need a reference for the balancing loop following up, and this // the balancing loop can have an effect that the creates a new opportunity, for example: // if the target is 95 ms and the current runtime is 48ms the above loop - // stopped the execution because the previous exec_ms was > 95ms + // stopped the execution because the previous exec_msec was > 95ms // due to the rebalance it's possible that the runtime reduces from 48ms to 47ms // and this creates the possibility to double the workload -> 47 * 2 = 95ms, which is < 96ms - double exec_ms_pre_final = try_run (hashcat_ctx, device_param, kernel_accel, kernel_loops); + double exec_msec_pre_final = try_run (hashcat_ctx, device_param, kernel_accel, kernel_loops); for (int i = 0; i < VERIFIER_CNT; i++) { - double exec_ms_pre_final_v = try_run (hashcat_ctx, device_param, kernel_accel, kernel_loops); + double exec_msec_pre_final_v = try_run (hashcat_ctx, device_param, kernel_accel, kernel_loops); - exec_ms_pre_final = MIN (exec_ms_pre_final, exec_ms_pre_final_v); + exec_msec_pre_final = MIN (exec_msec_pre_final, exec_msec_pre_final_v); } u32 diff = kernel_loops - kernel_accel; @@ -211,18 +206,18 @@ static int autotune (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param diff_new = diff; - double exec_ms = try_run (hashcat_ctx, device_param, kernel_accel_try, kernel_loops_try); + double exec_msec = try_run (hashcat_ctx, device_param, kernel_accel_try, kernel_loops_try); for (int i = 0; i < VERIFIER_CNT; i++) { - double exec_ms_v = try_run (hashcat_ctx, device_param, kernel_accel_try, kernel_loops_try); + double exec_msec_v = try_run (hashcat_ctx, device_param, kernel_accel_try, kernel_loops_try); - exec_ms = MIN (exec_ms, exec_ms_v); + exec_msec = MIN (exec_msec, exec_msec_v); } - if (exec_ms < exec_ms_pre_final) + if (exec_msec < exec_msec_pre_final) { - exec_ms_pre_final = exec_ms; + exec_msec_pre_final = exec_msec; kernel_accel = kernel_accel_try; kernel_loops = kernel_loops_try; @@ -230,7 +225,7 @@ static int autotune (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param } } - const double exec_left = target_ms / exec_ms_pre_final; + const double exec_left = target_msec / exec_msec_pre_final; const double accel_left = kernel_accel_max / kernel_accel; @@ -248,22 +243,26 @@ static int autotune (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param /* memset (device_param->pws_buf, 0, kernel_power_max * sizeof (pw_t)); - hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, kernel_power_max * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); - hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_pws_amp_buf, CL_TRUE, 0, kernel_power_max * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); + hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, kernel_power_max * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); + hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_pws_amp_buf, CL_TRUE, 0, kernel_power_max * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); */ - run_kernel_memset (hashcat_ctx, device_param, device_param->d_pws_buf, 0, kernel_power_max * sizeof (pw_t)); + CL_rc = run_kernel_memset (hashcat_ctx, device_param, device_param->d_pws_buf, 0, kernel_power_max * sizeof (pw_t)); + + if (CL_rc == -1) return -1; if (hashconfig->attack_exec == ATTACK_EXEC_OUTSIDE_KERNEL) { - run_kernel_memset (hashcat_ctx, device_param, device_param->d_pws_amp_buf, 0, kernel_power_max * sizeof (pw_t)); + CL_rc = run_kernel_memset (hashcat_ctx, device_param, device_param->d_pws_amp_buf, 0, kernel_power_max * sizeof (pw_t)); + + if (CL_rc == -1) return -1; } // reset timer device_param->exec_pos = 0; - memset (device_param->exec_ms, 0, EXEC_CACHE * sizeof (double)); + memset (device_param->exec_msec, 0, EXEC_CACHE * sizeof (double)); memset (device_param->exec_us_prev1, 0, EXPECTED_ITERATIONS * sizeof (double)); memset (device_param->exec_us_prev2, 0, EXPECTED_ITERATIONS * sizeof (double)); @@ -280,14 +279,19 @@ static int autotune (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param #if defined (DEBUG) + user_options_t *user_options = hashcat_ctx->user_options; + if (user_options->quiet == false) { clear_prompt (); - log_info ("- Device #%u: autotuned kernel-accel to %u\n" - "- Device #%u: autotuned kernel-loops to %u\n", - device_param->device_id + 1, kernel_accel, - device_param->device_id + 1, kernel_loops); + printf + ( + "- Device #%u: autotuned kernel-accel to %u\n" + "- Device #%u: autotuned kernel-loops to %u\n", + device_param->device_id + 1, kernel_accel, + device_param->device_id + 1, kernel_loops + ); send_prompt (); } @@ -309,9 +313,14 @@ void *thread_autotune (void *p) hc_device_param_t *device_param = opencl_ctx->devices_param + thread_param->tid; - if (device_param->skipped) return NULL; + if (device_param->skipped == true) return NULL; - autotune (hashcat_ctx, device_param); + const int rc_autotune = autotune (hashcat_ctx, device_param); + + if (rc_autotune == -1) + { + // we should do something here, tell hashcat main that autotune failed to abort + } return NULL; } diff --git a/src/bitmap.c b/src/bitmap.c index abb5c9c1a..82f65e677 100644 --- a/src/bitmap.c +++ b/src/bitmap.c @@ -6,7 +6,6 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" #include "bitmap.h" static u32 generate_bitmaps (const u32 digests_cnt, const u32 dgst_size, const u32 dgst_shifts, char *digests_buf_ptr, const u32 dgst_pos0, const u32 dgst_pos1, const u32 dgst_pos2, const u32 dgst_pos3, const u32 bitmap_mask, const u32 bitmap_size, u32 *bitmap_a, u32 *bitmap_b, u32 *bitmap_c, u32 *bitmap_d, const u64 collisions_max) @@ -50,7 +49,7 @@ static u32 generate_bitmaps (const u32 digests_cnt, const u32 dgst_size, const u return collisions; } -void bitmap_ctx_init (hashcat_ctx_t *hashcat_ctx) +int bitmap_ctx_init (hashcat_ctx_t *hashcat_ctx) { bitmap_ctx_t *bitmap_ctx = hashcat_ctx->bitmap_ctx; hashconfig_t *hashconfig = hashcat_ctx->hashconfig; @@ -59,12 +58,12 @@ void bitmap_ctx_init (hashcat_ctx_t *hashcat_ctx) bitmap_ctx->enabled = false; - if (user_options->keyspace == true) return; - if (user_options->left == true) return; - if (user_options->opencl_info == true) return; - if (user_options->show == true) return; - if (user_options->usage == true) return; - if (user_options->version == true) return; + if (user_options->keyspace == true) return 0; + if (user_options->left == true) return 0; + if (user_options->opencl_info == true) return 0; + if (user_options->show == true) return 0; + if (user_options->usage == true) return 0; + if (user_options->version == true) return 0; bitmap_ctx->enabled = true; @@ -78,14 +77,14 @@ void bitmap_ctx_init (hashcat_ctx_t *hashcat_ctx) const u32 bitmap_min = user_options->bitmap_min; const u32 bitmap_max = user_options->bitmap_max; - u32 *bitmap_s1_a = (u32 *) mymalloc ((1u << bitmap_max) * sizeof (u32)); - u32 *bitmap_s1_b = (u32 *) mymalloc ((1u << bitmap_max) * sizeof (u32)); - u32 *bitmap_s1_c = (u32 *) mymalloc ((1u << bitmap_max) * sizeof (u32)); - u32 *bitmap_s1_d = (u32 *) mymalloc ((1u << bitmap_max) * sizeof (u32)); - u32 *bitmap_s2_a = (u32 *) mymalloc ((1u << bitmap_max) * sizeof (u32)); - u32 *bitmap_s2_b = (u32 *) mymalloc ((1u << bitmap_max) * sizeof (u32)); - u32 *bitmap_s2_c = (u32 *) mymalloc ((1u << bitmap_max) * sizeof (u32)); - u32 *bitmap_s2_d = (u32 *) mymalloc ((1u << bitmap_max) * sizeof (u32)); + u32 *bitmap_s1_a = (u32 *) hcmalloc (hashcat_ctx, (1u << bitmap_max) * sizeof (u32)); VERIFY_PTR (bitmap_s1_a); + u32 *bitmap_s1_b = (u32 *) hcmalloc (hashcat_ctx, (1u << bitmap_max) * sizeof (u32)); VERIFY_PTR (bitmap_s1_b); + u32 *bitmap_s1_c = (u32 *) hcmalloc (hashcat_ctx, (1u << bitmap_max) * sizeof (u32)); VERIFY_PTR (bitmap_s1_c); + u32 *bitmap_s1_d = (u32 *) hcmalloc (hashcat_ctx, (1u << bitmap_max) * sizeof (u32)); VERIFY_PTR (bitmap_s1_d); + u32 *bitmap_s2_a = (u32 *) hcmalloc (hashcat_ctx, (1u << bitmap_max) * sizeof (u32)); VERIFY_PTR (bitmap_s2_a); + u32 *bitmap_s2_b = (u32 *) hcmalloc (hashcat_ctx, (1u << bitmap_max) * sizeof (u32)); VERIFY_PTR (bitmap_s2_b); + u32 *bitmap_s2_c = (u32 *) hcmalloc (hashcat_ctx, (1u << bitmap_max) * sizeof (u32)); VERIFY_PTR (bitmap_s2_c); + u32 *bitmap_s2_d = (u32 *) hcmalloc (hashcat_ctx, (1u << bitmap_max) * sizeof (u32)); VERIFY_PTR (bitmap_s2_d); u32 bitmap_bits; u32 bitmap_nums; @@ -94,8 +93,6 @@ void bitmap_ctx_init (hashcat_ctx_t *hashcat_ctx) for (bitmap_bits = bitmap_min; bitmap_bits < bitmap_max; bitmap_bits++) { - if (user_options->quiet == false) log_info_nn ("Generating bitmap tables with %u bits...", bitmap_bits); - bitmap_nums = 1u << bitmap_bits; bitmap_mask = bitmap_nums - 1; @@ -134,6 +131,8 @@ void bitmap_ctx_init (hashcat_ctx_t *hashcat_ctx) bitmap_ctx->bitmap_s2_b = bitmap_s2_b; bitmap_ctx->bitmap_s2_c = bitmap_s2_c; bitmap_ctx->bitmap_s2_d = bitmap_s2_d; + + return 0; } void bitmap_ctx_destroy (hashcat_ctx_t *hashcat_ctx) @@ -142,14 +141,14 @@ void bitmap_ctx_destroy (hashcat_ctx_t *hashcat_ctx) if (bitmap_ctx->enabled == false) return; - myfree (bitmap_ctx->bitmap_s1_a); - myfree (bitmap_ctx->bitmap_s1_b); - myfree (bitmap_ctx->bitmap_s1_c); - myfree (bitmap_ctx->bitmap_s1_d); - myfree (bitmap_ctx->bitmap_s2_a); - myfree (bitmap_ctx->bitmap_s2_b); - myfree (bitmap_ctx->bitmap_s2_c); - myfree (bitmap_ctx->bitmap_s2_d); + hcfree (bitmap_ctx->bitmap_s1_a); + hcfree (bitmap_ctx->bitmap_s1_b); + hcfree (bitmap_ctx->bitmap_s1_c); + hcfree (bitmap_ctx->bitmap_s1_d); + hcfree (bitmap_ctx->bitmap_s2_a); + hcfree (bitmap_ctx->bitmap_s2_b); + hcfree (bitmap_ctx->bitmap_s2_c); + hcfree (bitmap_ctx->bitmap_s2_d); memset (bitmap_ctx, 0, sizeof (bitmap_ctx_t)); } diff --git a/src/combinator.c b/src/combinator.c index 66ddf0479..e498e7869 100644 --- a/src/combinator.c +++ b/src/combinator.c @@ -5,8 +5,8 @@ #include "common.h" #include "types.h" +#include "event.h" #include "memory.h" -#include "logging.h" #include "combinator.h" #include "wordlist.h" @@ -30,7 +30,7 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) combinator_ctx->enabled = true; - combinator_ctx->scratch_buf = (char *) mymalloc (HCBUFSIZ_LARGE); + combinator_ctx->scratch_buf = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (combinator_ctx->scratch_buf); if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) { @@ -52,14 +52,14 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) if ((fp1 = fopen (dictfile1, "rb")) == NULL) { - log_error ("ERROR: %s: %s", dictfile1, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", dictfile1, strerror (errno)); return -1; } if (stat (dictfile1, &tmp_stat) == -1) { - log_error ("ERROR: %s: %s", dictfile1, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", dictfile1, strerror (errno)); fclose (fp1); @@ -68,7 +68,7 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) if (S_ISDIR (tmp_stat.st_mode)) { - log_error ("ERROR: %s must be a regular file", dictfile1, strerror (errno)); + event_log_error (hashcat_ctx, "%s must be a regular file", dictfile1, strerror (errno)); fclose (fp1); @@ -77,7 +77,7 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) if ((fp2 = fopen (dictfile2, "rb")) == NULL) { - log_error ("ERROR: %s: %s", dictfile2, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", dictfile2, strerror (errno)); fclose (fp1); @@ -86,7 +86,7 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) if (stat (dictfile2, &tmp_stat) == -1) { - log_error ("ERROR: %s: %s", dictfile2, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", dictfile2, strerror (errno)); fclose (fp1); fclose (fp2); @@ -96,7 +96,7 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) if (S_ISDIR (tmp_stat.st_mode)) { - log_error ("ERROR: %s must be a regular file", dictfile2, strerror (errno)); + event_log_error (hashcat_ctx, "%s must be a regular file", dictfile2, strerror (errno)); fclose (fp1); fclose (fp2); @@ -110,7 +110,7 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) if (words1_cnt == 0) { - log_error ("ERROR: %s: empty file", dictfile1); + event_log_error (hashcat_ctx, "%s: empty file", dictfile1); fclose (fp1); fclose (fp2); @@ -124,7 +124,7 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) if (words2_cnt == 0) { - log_error ("ERROR: %s: empty file", dictfile2); + event_log_error (hashcat_ctx, "%s: empty file", dictfile2); fclose (fp1); fclose (fp2); @@ -183,7 +183,7 @@ void combinator_ctx_destroy (hashcat_ctx_t *hashcat_ctx) if (combinator_ctx->enabled == false) return; - myfree (combinator_ctx->scratch_buf); + hcfree (combinator_ctx->scratch_buf); memset (combinator_ctx, 0, sizeof (combinator_ctx_t)); } diff --git a/src/common.c b/src/common.c index 324a1237d..211427cd4 100644 --- a/src/common.c +++ b/src/common.c @@ -4,4 +4,3 @@ */ #include "common.h" - diff --git a/src/cpt.c b/src/cpt.c index 58938b528..9386b5d64 100644 --- a/src/cpt.c +++ b/src/cpt.c @@ -6,7 +6,6 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" #include "cpt.h" int cpt_ctx_init (hashcat_ctx_t *hashcat_ctx) @@ -26,7 +25,7 @@ int cpt_ctx_init (hashcat_ctx_t *hashcat_ctx) cpt_ctx->enabled = true; - cpt_ctx->cpt_buf = (cpt_t *) mycalloc (CPT_BUF, sizeof (cpt_t)); + cpt_ctx->cpt_buf = (cpt_t *) hccalloc (hashcat_ctx, CPT_BUF, sizeof (cpt_t)); VERIFY_PTR (cpt_ctx->cpt_buf); cpt_ctx->cpt_total = 0; cpt_ctx->cpt_pos = 0; @@ -41,7 +40,7 @@ void cpt_ctx_destroy (hashcat_ctx_t *hashcat_ctx) if (cpt_ctx->enabled == false) return; - myfree (cpt_ctx->cpt_buf); + hcfree (cpt_ctx->cpt_buf); memset (cpt_ctx, 0, sizeof (cpt_ctx_t)); } diff --git a/src/cpu_crc32.c b/src/cpu_crc32.c index 282a3ef28..36a62919d 100644 --- a/src/cpu_crc32.c +++ b/src/cpu_crc32.c @@ -6,7 +6,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "cpu_crc32.h" static const u32 crc32tab[256] = @@ -77,7 +77,7 @@ static const u32 crc32tab[256] = 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; -void cpu_crc32 (const char *filename, u8 keytab[64]) +int cpu_crc32 (hashcat_ctx_t *hashcat_ctx, const char *filename, u8 keytab[64]) { u32 crc = ~0u; @@ -85,14 +85,14 @@ void cpu_crc32 (const char *filename, u8 keytab[64]) if (fd == NULL) { - log_error ("%s: %s", filename, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", filename, strerror (errno)); - exit (-1); + return (-1); } #define MAX_KEY_SIZE (1024 * 1024) - u8 *buf = (u8 *) mymalloc (MAX_KEY_SIZE + 1); + u8 *buf = (u8 *) hcmalloc (hashcat_ctx, MAX_KEY_SIZE + 1); VERIFY_PTR (buf); int nread = fread (buf, sizeof (u8), MAX_KEY_SIZE, fd); @@ -112,5 +112,7 @@ void cpu_crc32 (const char *filename, u8 keytab[64]) if (kpos >= 64) kpos = 0; } - myfree (buf); + hcfree (buf); + + return 0; } diff --git a/src/debugfile.c b/src/debugfile.c index 36f114b3a..9e8c0941a 100644 --- a/src/debugfile.c +++ b/src/debugfile.c @@ -6,7 +6,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "debugfile.h" static void debugfile_format_plain (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ptr, const u32 plain_len) @@ -91,6 +91,7 @@ int debugfile_init (hashcat_ctx_t *hashcat_ctx) if (user_options->opencl_info == true) return 0; if (user_options->show == true) return 0; if (user_options->stdout_flag == true) return 0; + if (user_options->speed_only == true) return 0; if (user_options->usage == true) return 0; if (user_options->version == true) return 0; if (user_options->debug_mode == 0) return 0; @@ -107,7 +108,7 @@ int debugfile_init (hashcat_ctx_t *hashcat_ctx) if (debugfile_ctx->fp == NULL) { - log_error ("ERROR: Could not open debug-file for writing"); + event_log_error (hashcat_ctx, "Could not open debug-file for writing"); return -1; } diff --git a/src/dictstat.c b/src/dictstat.c index c6e8827a6..b240da726 100644 --- a/src/dictstat.c +++ b/src/dictstat.c @@ -6,7 +6,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "dictstat.h" int sort_by_dictstat (const void *s1, const void *s2) @@ -42,17 +42,17 @@ int dictstat_init (hashcat_ctx_t *hashcat_ctx) if (user_options->attack_mode == ATTACK_MODE_BF) return 0; dictstat_ctx->enabled = true; - dictstat_ctx->filename = (char *) mymalloc (HCBUFSIZ_TINY); - dictstat_ctx->base = (dictstat_t *) mycalloc (MAX_DICTSTAT, sizeof (dictstat_t)); + dictstat_ctx->filename = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (dictstat_ctx->filename); + dictstat_ctx->base = (dictstat_t *) hccalloc (hashcat_ctx, MAX_DICTSTAT, sizeof (dictstat_t)); VERIFY_PTR (dictstat_ctx->base); dictstat_ctx->cnt = 0; snprintf (dictstat_ctx->filename, HCBUFSIZ_TINY - 1, "%s/hashcat.dictstat", folder_config->profile_dir); - FILE *fp = fopen (dictstat_ctx->filename, "wb"); + FILE *fp = fopen (dictstat_ctx->filename, "ab"); if (fp == NULL) { - log_error ("ERROR: %s: %s", dictstat_ctx->filename, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", dictstat_ctx->filename, strerror (errno)); return -1; } @@ -68,8 +68,8 @@ void dictstat_destroy (hashcat_ctx_t *hashcat_ctx) if (dictstat_ctx->enabled == false) return; - myfree (dictstat_ctx->filename); - myfree (dictstat_ctx->base); + hcfree (dictstat_ctx->filename); + hcfree (dictstat_ctx->base); memset (dictstat_ctx, 0, sizeof (dictstat_ctx_t)); } @@ -101,7 +101,7 @@ void dictstat_read (hashcat_ctx_t *hashcat_ctx) if (dictstat_ctx->cnt == MAX_DICTSTAT) { - log_error ("ERROR: There are too many entries in the %s database. You have to remove/rename it.", dictstat_ctx->filename); + event_log_error (hashcat_ctx, "There are too many entries in the %s database. You have to remove/rename it.", dictstat_ctx->filename); break; } @@ -120,7 +120,7 @@ int dictstat_write (hashcat_ctx_t *hashcat_ctx) if (fp == NULL) { - log_error ("ERROR: %s: %s", dictstat_ctx->filename, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", dictstat_ctx->filename, strerror (errno)); return -1; } @@ -153,7 +153,7 @@ void dictstat_append (hashcat_ctx_t *hashcat_ctx, dictstat_t *d) if (dictstat_ctx->cnt == MAX_DICTSTAT) { - log_error ("ERROR: There are too many entries in the %s database. You have to remove/rename it.", dictstat_ctx->filename); + event_log_error (hashcat_ctx, "There are too many entries in the %s database. You have to remove/rename it.", dictstat_ctx->filename); return; } diff --git a/src/dispatch.c b/src/dispatch.c index b38dd84a7..206ae6481 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -9,7 +9,6 @@ #include "filehandling.h" #include "interface.h" #include "timer.h" -#include "logging.h" #include "ext_OpenCL.h" #include "ext_ADL.h" #include "ext_nvapi.h" @@ -22,7 +21,6 @@ #include "restore.h" #include "hashes.h" #include "rp_cpu.h" -#include "terminal.h" #include "mpsp.h" #include "outfile.h" #include "potfile.h" @@ -33,23 +31,45 @@ #include "wordlist.h" #include "status.h" #include "shared.h" +#include "event.h" #include "dispatch.h" -static void set_kernel_power_final (opencl_ctx_t *opencl_ctx, const user_options_t *user_options, const u64 kernel_power_final) +static u64 get_lowest_words_done (const hashcat_ctx_t *hashcat_ctx) { - if (user_options->quiet == false) + const opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + u64 words_cur = 0xffffffffffffffff; + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - clear_prompt (); + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - //log_info (""); + if (device_param->skipped) continue; - log_info ("INFO: approaching final keyspace, workload adjusted"); - log_info (""); + const u64 words_done = device_param->words_done; - send_prompt (); + if (words_done < words_cur) words_cur = words_done; } + // It's possible that a device's workload isn't finished right after a restore-case. + // In that case, this function would return 0 and overwrite the real restore point + + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + if (words_cur < status_ctx->words_cur) words_cur = status_ctx->words_cur; + + return words_cur; +} + +static int set_kernel_power_final (hashcat_ctx_t *hashcat_ctx, const u32 kernel_power_final) +{ + EVENT (EVENT_SET_KERNEL_POWER_FINAL); + + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + opencl_ctx->kernel_power_final = kernel_power_final; + + return 0; } static u32 get_power (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param) @@ -72,24 +92,28 @@ static u32 get_power (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param) return device_param->kernel_power; } -static u32 get_work (opencl_ctx_t *opencl_ctx, status_ctx_t *status_ctx, const user_options_t *user_options, hc_device_param_t *device_param, const u64 max) +static u32 get_work (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 max) { + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + user_options_t *user_options = hashcat_ctx->user_options; + hc_thread_mutex_lock (status_ctx->mux_dispatcher); - const u64 words_cur = status_ctx->words_cur; + const u64 words_off = status_ctx->words_off; const u64 words_base = (user_options->limit == 0) ? status_ctx->words_base : MIN (user_options->limit, status_ctx->words_base); - device_param->words_off = words_cur; + device_param->words_off = words_off; const u64 kernel_power_all = opencl_ctx->kernel_power_all; - const u64 words_left = words_base - words_cur; + const u64 words_left = words_base - words_off; if (words_left < kernel_power_all) { if (opencl_ctx->kernel_power_final == 0) { - set_kernel_power_final (opencl_ctx, user_options, words_left); + set_kernel_power_final (hashcat_ctx, words_left); } } @@ -99,14 +123,14 @@ static u32 get_work (opencl_ctx_t *opencl_ctx, status_ctx_t *status_ctx, const u work = MIN (work, max); - status_ctx->words_cur += work; + status_ctx->words_off += work; hc_thread_mutex_unlock (status_ctx->mux_dispatcher); return work; } -static void calc_stdin (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) +static int calc_stdin (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) { user_options_t *user_options = hashcat_ctx->user_options; user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; @@ -115,7 +139,7 @@ static void calc_stdin (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_pa straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - char *buf = (char *) mymalloc (HCBUFSIZ_LARGE); + char *buf = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (buf); const u32 attack_kern = user_options_extra->attack_kern; @@ -130,9 +154,9 @@ static void calc_stdin (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_pa break; } - u32 words_cur = 0; + u32 words_buffered = 0; - while (words_cur < device_param->kernel_power) + while (words_buffered < device_param->kernel_power) { char *line_buf = fgets (buf, HCBUFSIZ_LARGE - 1, stdin); @@ -187,7 +211,7 @@ static void calc_stdin (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_pa pw_add (device_param, (u8 *) line_buf, (int) line_len); - words_cur++; + words_buffered++; while (status_ctx->run_thread_level1 == false) break; } @@ -202,9 +226,15 @@ static void calc_stdin (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_pa if (pws_cnt) { - run_copy (hashcat_ctx, device_param, pws_cnt); + int CL_rc; - run_cracker (hashcat_ctx, device_param, pws_cnt); + CL_rc = run_copy (hashcat_ctx, device_param, pws_cnt); + + if (CL_rc == -1) return -1; + + CL_rc = run_cracker (hashcat_ctx, device_param, pws_cnt); + + if (CL_rc == -1) return -1; device_param->pws_cnt = 0; @@ -212,20 +242,30 @@ static void calc_stdin (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_pa still required? if (attack_kern == ATTACK_KERN_STRAIGHT) { - run_kernel_bzero (opencl_ctx, device_param, device_param->d_rules_c, device_param->size_rules_c); + CL_rc = run_kernel_bzero (opencl_ctx, device_param, device_param->d_rules_c, device_param->size_rules_c); + + if (CL_rc == -1) return -1; } else if (attack_kern == ATTACK_KERN_COMBI) { - run_kernel_bzero (opencl_ctx, device_param, device_param->d_combs_c, device_param->size_combs); + rCL_rc = un_kernel_bzero (opencl_ctx, device_param, device_param->d_combs_c, device_param->size_combs); + + if (CL_rc == -1) return -1; } */ } + + if (status_ctx->run_thread_level1 == false) break; + + if (user_options->speed_only == true) break; } device_param->kernel_accel = 0; device_param->kernel_loops = 0; - myfree (buf); + hcfree (buf); + + return 0; } void *thread_calc_stdin (void *p) @@ -242,12 +282,12 @@ void *thread_calc_stdin (void *p) if (device_param->skipped) return NULL; - calc_stdin (hashcat_ctx, device_param); + calc_stdin (hashcat_ctx, device_param); // we should check the RC here return NULL; } -static void calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) +static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) { user_options_t *user_options = hashcat_ctx->user_options; user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; @@ -255,7 +295,6 @@ static void calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) hashes_t *hashes = hashcat_ctx->hashes; straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; status_ctx_t *status_ctx = hashcat_ctx->status_ctx; const u32 attack_mode = user_options->attack_mode; @@ -265,7 +304,7 @@ static void calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) { while (status_ctx->run_thread_level1 == true) { - const u32 work = get_work (opencl_ctx, status_ctx, user_options, device_param, -1u); + const u32 work = get_work (hashcat_ctx, device_param, -1u); if (work == 0) break; @@ -278,23 +317,29 @@ static void calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (pws_cnt) { - run_copy (hashcat_ctx, device_param, pws_cnt); + int CL_rc; - run_cracker (hashcat_ctx, device_param, pws_cnt); + CL_rc = run_copy (hashcat_ctx, device_param, pws_cnt); + + if (CL_rc == -1) return -1; + + CL_rc = run_cracker (hashcat_ctx, device_param, pws_cnt); + + if (CL_rc == -1) return -1; device_param->pws_cnt = 0; + } - /* - still required? - run_kernel_bzero (device_param, device_param->d_bfs_c, device_param->size_bfs); - */ + if (user_options->speed_only == true) break; + + if (status_ctx->run_thread_level2 == true) + { + device_param->words_done = words_fin; + + status_ctx->words_cur = get_lowest_words_done (hashcat_ctx); } if (status_ctx->run_thread_level1 == false) break; - - if (user_options->benchmark == true) break; - - device_param->words_done = words_fin; } } else @@ -317,9 +362,9 @@ static void calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (fd == NULL) { - log_error ("ERROR: %s: %s", dictfile, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", dictfile, strerror (errno)); - return; + return -1; } if (attack_mode == ATTACK_MODE_COMBI) @@ -334,11 +379,11 @@ static void calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (combs_fp == NULL) { - log_error ("ERROR: %s: %s", combinator_ctx->dict2, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", combinator_ctx->dict2, strerror (errno)); fclose (fd); - return; + return -1; } device_param->combs_fp = combs_fp; @@ -351,18 +396,18 @@ static void calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (combs_fp == NULL) { - log_error ("ERROR: %s: %s", dictfilec, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", dictfilec, strerror (errno)); fclose (fd); - return; + return -1; } device_param->combs_fp = combs_fp; } } - hashcat_ctx_t *hashcat_ctx_tmp = (hashcat_ctx_t *) mymalloc (sizeof (hashcat_ctx_t)); + hashcat_ctx_t *hashcat_ctx_tmp = (hashcat_ctx_t *) hcmalloc (hashcat_ctx, sizeof (hashcat_ctx_t)); VERIFY_PTR (hashcat_ctx_tmp); /* hashcat_ctx_tmp->bitmap_ctx = hashcat_ctx->bitmap_ctx; @@ -392,9 +437,11 @@ static void calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) memcpy (hashcat_ctx_tmp, hashcat_ctx, sizeof (hashcat_ctx_t)); // yes we actually want to copy these pointers - hashcat_ctx_tmp->wl_data = (wl_data_t *) mymalloc (sizeof (wl_data_t)); + hashcat_ctx_tmp->wl_data = (wl_data_t *) hcmalloc (hashcat_ctx, sizeof (wl_data_t)); VERIFY_PTR (hashcat_ctx_tmp->wl_data); - wl_data_init (hashcat_ctx_tmp); + const int rc_wl_data_init = wl_data_init (hashcat_ctx_tmp); + + if (rc_wl_data_init == -1) return -1; u64 words_cur = 0; @@ -403,15 +450,15 @@ static void calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) u64 words_off = 0; u64 words_fin = 0; - u64 max = -1llu; + u32 words_extra = -1u; - while (max) + while (words_extra) { - const u32 work = get_work (opencl_ctx, status_ctx, user_options, device_param, max); + const u32 work = get_work (hashcat_ctx, device_param, words_extra); if (work == 0) break; - max = 0; + words_extra = 0; words_off = device_param->words_off; words_fin = words_off + work; @@ -450,7 +497,7 @@ static void calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) { if ((line_len < hashconfig->pw_min) || (line_len > hashconfig->pw_max)) { - max++; + words_extra++; hc_thread_mutex_lock (status_ctx->mux_counter); @@ -471,7 +518,7 @@ static void calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (line_len > hashconfig->pw_max) { - max++; + words_extra++; hc_thread_mutex_lock (status_ctx->mux_counter); @@ -504,9 +551,15 @@ static void calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (pws_cnt) { - run_copy (hashcat_ctx, device_param, pws_cnt); + int CL_rc; - run_cracker (hashcat_ctx, device_param, pws_cnt); + CL_rc = run_copy (hashcat_ctx, device_param, pws_cnt); + + if (CL_rc == -1) return -1; + + CL_rc = run_cracker (hashcat_ctx, device_param, pws_cnt); + + if (CL_rc == -1) return -1; device_param->pws_cnt = 0; @@ -514,20 +567,31 @@ static void calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) still required? if (attack_kern == ATTACK_KERN_STRAIGHT) { - run_kernel_bzero (device_param, device_param->d_rules_c, device_param->size_rules_c); + CL_rc = run_kernel_bzero (device_param, device_param->d_rules_c, device_param->size_rules_c); + + if (CL_rc == -1) return -1; } else if (attack_kern == ATTACK_KERN_COMBI) { - run_kernel_bzero (device_param, device_param->d_combs_c, device_param->size_combs); + CL_rc = run_kernel_bzero (device_param, device_param->d_combs_c, device_param->size_combs); + + if (CL_rc == -1) return -1; } */ } + if (user_options->speed_only == true) break; + + if (status_ctx->run_thread_level2 == true) + { + device_param->words_done = words_fin; + + status_ctx->words_cur = get_lowest_words_done (hashcat_ctx); + } + if (status_ctx->run_thread_level1 == false) break; if (words_fin == 0) break; - - device_param->words_done = words_fin; } if (attack_mode == ATTACK_MODE_COMBI) @@ -537,15 +601,17 @@ static void calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) wl_data_destroy (hashcat_ctx_tmp); - myfree (hashcat_ctx_tmp->wl_data); + hcfree (hashcat_ctx_tmp->wl_data); - myfree (hashcat_ctx_tmp); + hcfree (hashcat_ctx_tmp); fclose (fd); } device_param->kernel_accel = 0; device_param->kernel_loops = 0; + + return 0; } void *thread_calc (void *p) @@ -562,7 +628,7 @@ void *thread_calc (void *p) if (device_param->skipped) return NULL; - calc (hashcat_ctx, device_param); + calc (hashcat_ctx, device_param); // we should check the RC here return NULL; } diff --git a/src/event.c b/src/event.c new file mode 100644 index 000000000..8a1f339bf --- /dev/null +++ b/src/event.c @@ -0,0 +1,188 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#include "common.h" +#include "types.h" +#include "thread.h" +#include "event.h" + +void event_call (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len) +{ + bool need_mux = true; + + switch (id) + { + case EVENT_LOG_INFO: need_mux = false; + case EVENT_LOG_WARNING: need_mux = false; + case EVENT_LOG_ERROR: need_mux = false; + } + + if (need_mux == true) + { + event_ctx_t *event_ctx = hashcat_ctx->event_ctx; + + hc_thread_mutex_lock (event_ctx->mux_event); + } + + hashcat_ctx->event (id, hashcat_ctx, buf, len); + + if (need_mux == true) + { + event_ctx_t *event_ctx = hashcat_ctx->event_ctx; + + hc_thread_mutex_unlock (event_ctx->mux_event); + } +} + +static int event_log (const char *fmt, va_list ap, char *s, const size_t sz) +{ + return vsnprintf (s, sz, fmt, ap); +} + +size_t event_log_info_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...) +{ + va_list ap; + + va_start (ap, fmt); + + event_ctx_t *event_ctx = hashcat_ctx->event_ctx; + + event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1); + + event_ctx->msg_buf[event_ctx->msg_len] = 0; + + va_end (ap); + + event_ctx->msg_newline = false; + + event_call (EVENT_LOG_INFO, hashcat_ctx, NULL, 0); + + return event_ctx->msg_len; +} + +size_t event_log_warning_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...) +{ + va_list ap; + + va_start (ap, fmt); + + event_ctx_t *event_ctx = hashcat_ctx->event_ctx; + + event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1); + + event_ctx->msg_buf[event_ctx->msg_len] = 0; + + va_end (ap); + + event_ctx->msg_newline = false; + + event_call (EVENT_LOG_WARNING, hashcat_ctx, NULL, 0); + + return event_ctx->msg_len; +} + +size_t event_log_error_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...) +{ + va_list ap; + + va_start (ap, fmt); + + event_ctx_t *event_ctx = hashcat_ctx->event_ctx; + + event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1); + + event_ctx->msg_buf[event_ctx->msg_len] = 0; + + va_end (ap); + + event_ctx->msg_newline = false; + + event_call (EVENT_LOG_ERROR, hashcat_ctx, NULL, 0); + + return event_ctx->msg_len; +} + +size_t event_log_info (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...) +{ + va_list ap; + + va_start (ap, fmt); + + event_ctx_t *event_ctx = hashcat_ctx->event_ctx; + + event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1); + + event_ctx->msg_buf[event_ctx->msg_len] = 0; + + va_end (ap); + + event_ctx->msg_newline = true; + + event_call (EVENT_LOG_INFO, hashcat_ctx, NULL, 0); + + return event_ctx->msg_len; +} + +size_t event_log_warning (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...) +{ + va_list ap; + + va_start (ap, fmt); + + event_ctx_t *event_ctx = hashcat_ctx->event_ctx; + + event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1); + + event_ctx->msg_buf[event_ctx->msg_len] = 0; + + va_end (ap); + + event_ctx->msg_newline = true; + + event_call (EVENT_LOG_WARNING, hashcat_ctx, NULL, 0); + + return event_ctx->msg_len; +} + +size_t event_log_error (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...) +{ + va_list ap; + + va_start (ap, fmt); + + event_ctx_t *event_ctx = hashcat_ctx->event_ctx; + + event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1); + + event_ctx->msg_buf[event_ctx->msg_len] = 0; + + va_end (ap); + + event_ctx->msg_newline = true; + + event_call (EVENT_LOG_ERROR, hashcat_ctx, NULL, 0); + + return event_ctx->msg_len; +} + +int event_ctx_init (hashcat_ctx_t *hashcat_ctx) +{ + event_ctx_t *event_ctx = hashcat_ctx->event_ctx; + + hc_thread_mutex_init (event_ctx->mux_event); + + event_ctx->msg_len = 0; + + return 0; +} + +void event_ctx_destroy (hashcat_ctx_t *hashcat_ctx) +{ + event_ctx_t *event_ctx = hashcat_ctx->event_ctx; + + hc_thread_mutex_delete (event_ctx->mux_event); + + event_ctx->msg_len = 0; +} diff --git a/src/ext_ADL.c b/src/ext_ADL.c index 374673566..ad4de4bd7 100644 --- a/src/ext_ADL.c +++ b/src/ext_ADL.c @@ -4,612 +4,9 @@ */ #include "common.h" -#include "logging.h" -#include "memory.h" -#include "dynloader.h" #include "ext_ADL.h" -int adl_init (ADL_PTR *adl) -{ - if (!adl) return -1; - - memset (adl, 0, sizeof (ADL_PTR)); - - #if defined (_WIN) - adl->lib = hc_dlopen ("atiadlxx.dll"); - - if (!adl->lib) - { - adl->lib = hc_dlopen ("atiadlxy.dll"); - } - #elif defined (_POSIX) - adl->lib = hc_dlopen ("libatiadlxx.so", RTLD_NOW); - #endif - - if (!adl->lib) - { - //if (user_options->quiet == false) - // log_info ("WARNING: load ADL library failed, proceed without ADL HWMon enabled."); - - return -1; - } - - HC_LOAD_FUNC(adl, ADL_Main_Control_Destroy, ADL_MAIN_CONTROL_DESTROY, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Main_Control_Create, ADL_MAIN_CONTROL_CREATE, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Adapter_NumberOfAdapters_Get, ADL_ADAPTER_NUMBEROFADAPTERS_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Adapter_AdapterInfo_Get, ADL_ADAPTER_ADAPTERINFO_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Display_DisplayInfo_Get, ADL_DISPLAY_DISPLAYINFO_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Adapter_ID_Get, ADL_ADAPTER_ID_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Adapter_VideoBiosInfo_Get, ADL_ADAPTER_VIDEOBIOSINFO_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive5_ThermalDevices_Enum, ADL_OVERDRIVE5_THERMALDEVICES_ENUM, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive5_Temperature_Get, ADL_OVERDRIVE5_TEMPERATURE_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive6_Temperature_Get, ADL_OVERDRIVE6_TEMPERATURE_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive5_CurrentActivity_Get, ADL_OVERDRIVE5_CURRENTACTIVITY_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive5_FanSpeedInfo_Get, ADL_OVERDRIVE5_FANSPEEDINFO_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive5_FanSpeed_Get, ADL_OVERDRIVE5_FANSPEED_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive6_FanSpeed_Get, ADL_OVERDRIVE6_FANSPEED_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive5_FanSpeed_Set, ADL_OVERDRIVE5_FANSPEED_SET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive6_FanSpeed_Set, ADL_OVERDRIVE6_FANSPEED_SET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive5_FanSpeedToDefault_Set, ADL_OVERDRIVE5_FANSPEEDTODEFAULT_SET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive5_ODParameters_Get, ADL_OVERDRIVE5_ODPARAMETERS_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive5_ODPerformanceLevels_Get, ADL_OVERDRIVE5_ODPERFORMANCELEVELS_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive5_ODPerformanceLevels_Set, ADL_OVERDRIVE5_ODPERFORMANCELEVELS_SET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive6_PowerControlInfo_Get, ADL_OVERDRIVE6_POWERCONTROLINFO_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive6_PowerControl_Get, ADL_OVERDRIVE6_POWERCONTROL_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive6_PowerControl_Set, ADL_OVERDRIVE6_POWERCONTROL_SET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Adapter_Active_Get, ADL_ADAPTER_ACTIVE_GET, ADL, 0) - //HC_LOAD_FUNC(adl, ADL_DisplayEnable_Set, ADL_DISPLAYENABLE_SET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive_Caps, ADL_OVERDRIVE_CAPS, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive6_PowerControl_Caps, ADL_OVERDRIVE6_POWERCONTROL_CAPS, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive6_Capabilities_Get, ADL_OVERDRIVE6_CAPABILITIES_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive6_StateInfo_Get, ADL_OVERDRIVE6_STATEINFO_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive6_CurrentStatus_Get, ADL_OVERDRIVE6_CURRENTSTATUS_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive6_State_Set, ADL_OVERDRIVE6_STATE_SET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive6_TargetTemperatureData_Get, ADL_OVERDRIVE6_TARGETTEMPERATUREDATA_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive6_TargetTemperatureRangeInfo_Get, ADL_OVERDRIVE6_TARGETTEMPERATURERANGEINFO_GET, ADL, 0) - HC_LOAD_FUNC(adl, ADL_Overdrive6_FanSpeed_Reset, ADL_OVERDRIVE6_FANSPEED_RESET, ADL, 0) - - return 0; -} - -void adl_close (ADL_PTR *adl) -{ - if (adl) - { - if (adl->lib) - hc_dlclose (adl->lib); - - myfree (adl); - } -} - void *HC_API_CALL ADL_Main_Memory_Alloc (const int iSize) { - return mymalloc ((size_t) iSize); -} - -int hm_ADL_Main_Control_Destroy (ADL_PTR *adl) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Main_Control_Destroy (); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_Main_Control_Destroy()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Main_Control_Create (ADL_PTR *adl, ADL_MAIN_MALLOC_CALLBACK callback, int iEnumConnectedAdapters) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Main_Control_Create (callback, iEnumConnectedAdapters); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_Main_Control_Create()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Adapter_NumberOfAdapters_Get (ADL_PTR *adl, int *lpNumAdapters) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Adapter_NumberOfAdapters_Get (lpNumAdapters); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_Adapter_NumberOfAdapters_Get()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Adapter_AdapterInfo_Get (ADL_PTR *adl, LPAdapterInfo lpInfo, int iInputSize) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Adapter_AdapterInfo_Get (lpInfo, iInputSize); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_Adapter_AdapterInfo_Get()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Display_DisplayInfo_Get (ADL_PTR *adl, int iAdapterIndex, int *iNumDisplays, ADLDisplayInfo **lppInfo, int iForceDetect) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Display_DisplayInfo_Get (iAdapterIndex, iNumDisplays, lppInfo, iForceDetect); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_Display_DisplayInfo_Get()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Adapter_ID_Get (ADL_PTR *adl, int iAdapterIndex, int *lpAdapterID) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Adapter_ID_Get (iAdapterIndex, lpAdapterID); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_Adapter_ID_Get()", ADL_rc); - } - - return ADL_rc; -} - -int hm_ADL_Adapter_VideoBiosInfo_Get (ADL_PTR *adl, int iAdapterIndex, ADLBiosInfo *lpBiosInfo) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Adapter_VideoBiosInfo_Get (iAdapterIndex, lpBiosInfo); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_Adapter_VideoBiosInfo_Get()", ADL_rc); - } - - return ADL_rc; -} - -int hm_ADL_Overdrive_ThermalDevices_Enum (ADL_PTR *adl, int iAdapterIndex, int iThermalControllerIndex, ADLThermalControllerInfo *lpThermalControllerInfo) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive5_ThermalDevices_Enum (iAdapterIndex, iThermalControllerIndex, lpThermalControllerInfo); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_Overdrive5_ThermalDevices_Enum()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Overdrive5_Temperature_Get (ADL_PTR *adl, int iAdapterIndex, int iThermalControllerIndex, ADLTemperature *lpTemperature) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive5_Temperature_Get (iAdapterIndex, iThermalControllerIndex, lpTemperature); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_Overdrive5_Temperature_Get()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Overdrive6_Temperature_Get (ADL_PTR *adl, int iAdapterIndex, int *iTemperature) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive6_Temperature_Get (iAdapterIndex, iTemperature); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_Overdrive6_Temperature_Get()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Overdrive_CurrentActivity_Get (ADL_PTR *adl, int iAdapterIndex, ADLPMActivity *lpActivity) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive5_CurrentActivity_Get (iAdapterIndex, lpActivity); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_Overdrive5_CurrentActivity_Get()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Overdrive5_FanSpeedInfo_Get (ADL_PTR *adl, int iAdapterIndex, int iThermalControllerIndex, ADLFanSpeedInfo *lpFanSpeedInfo) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive5_FanSpeedInfo_Get (iAdapterIndex, iThermalControllerIndex, lpFanSpeedInfo); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_Overdrive5_FanSpeedInfo_Get()", ADL_rc); - } - - return ADL_rc; -} - -int hm_ADL_Overdrive5_FanSpeed_Get (ADL_PTR *adl, int iAdapterIndex, int iThermalControllerIndex, ADLFanSpeedValue *lpFanSpeedValue) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive5_FanSpeed_Get (iAdapterIndex, iThermalControllerIndex, lpFanSpeedValue); - - if ((ADL_rc != ADL_OK) && (ADL_rc != ADL_ERR_NOT_SUPPORTED)) // exception allowed only here - { - log_info ("WARN: %s: %d\n", "ADL_Overdrive5_FanSpeed_Get()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Overdrive6_FanSpeed_Get (ADL_PTR *adl, int iAdapterIndex, ADLOD6FanSpeedInfo *lpFanSpeedInfo) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive6_FanSpeed_Get (iAdapterIndex, lpFanSpeedInfo); - - if ((ADL_rc != ADL_OK) && (ADL_rc != ADL_ERR_NOT_SUPPORTED)) // exception allowed only here - { - log_info ("WARN: %s: %d\n", "ADL_Overdrive6_FanSpeed_Get()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Overdrive5_FanSpeed_Set (ADL_PTR *adl, int iAdapterIndex, int iThermalControllerIndex, ADLFanSpeedValue *lpFanSpeedValue) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive5_FanSpeed_Set (iAdapterIndex, iThermalControllerIndex, lpFanSpeedValue); - - if ((ADL_rc != ADL_OK) && (ADL_rc != ADL_ERR_NOT_SUPPORTED)) // exception allowed only here - { - log_info ("WARN: %s: %d\n", "ADL_Overdrive5_FanSpeed_Set()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Overdrive6_FanSpeed_Set (ADL_PTR *adl, int iAdapterIndex, ADLOD6FanSpeedValue *lpFanSpeedValue) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive6_FanSpeed_Set (iAdapterIndex, lpFanSpeedValue); - - if ((ADL_rc != ADL_OK) && (ADL_rc != ADL_ERR_NOT_SUPPORTED)) // exception allowed only here - { - log_info ("WARN: %s: %d\n", "ADL_Overdrive6_FanSpeed_Set()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Overdrive5_FanSpeedToDefault_Set (ADL_PTR *adl, int iAdapterIndex, int iThermalControllerIndex) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive5_FanSpeedToDefault_Set (iAdapterIndex, iThermalControllerIndex); - - if ((ADL_rc != ADL_OK) && (ADL_rc != ADL_ERR_NOT_SUPPORTED)) // exception allowed only here - { - log_info ("WARN: %s: %d\n", "ADL_Overdrive5_FanSpeedToDefault_Set()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Overdrive_ODParameters_Get (ADL_PTR *adl, int iAdapterIndex, ADLODParameters *lpOdParameters) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive5_ODParameters_Get (iAdapterIndex, lpOdParameters); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_Overdrive5_ODParameters_Get()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Overdrive_ODPerformanceLevels_Get (ADL_PTR *adl, int iAdapterIndex, int iDefault, ADLODPerformanceLevels *lpOdPerformanceLevels) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive5_ODPerformanceLevels_Get (iAdapterIndex, iDefault, lpOdPerformanceLevels); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_Overdrive5_ODPerformanceLevels_Get()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Overdrive_ODPerformanceLevels_Set (ADL_PTR *adl, int iAdapterIndex, ADLODPerformanceLevels *lpOdPerformanceLevels) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive5_ODPerformanceLevels_Set (iAdapterIndex, lpOdPerformanceLevels); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_Overdrive5_ODPerformanceLevels_Set()", ADL_rc); - } - - return (ADL_rc); -} - -int hm_ADL_Overdrive_PowerControlInfo_Get (ADL_PTR *adl, int iAdapterIndex, ADLOD6PowerControlInfo *powertune) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive6_PowerControlInfo_Get (iAdapterIndex, powertune); - - return (ADL_rc); -} - -int hm_ADL_Overdrive_PowerControl_Get (ADL_PTR *adl, int iAdapterIndex, int *iCurrentValue) -{ - if (!adl) return -1; - - int default_value = 0; - - int ADL_rc = adl->ADL_Overdrive6_PowerControl_Get (iAdapterIndex, iCurrentValue, &default_value); - - return (ADL_rc); -} - -int hm_ADL_Overdrive_PowerControl_Set (ADL_PTR *adl, int iAdapterIndex, int level) -{ - if (!adl) return -1; - - int ADL_rc = ADL_ERR; - - ADLOD6PowerControlInfo powertune = {0, 0, 0, 0, 0}; - - if ((ADL_rc = hm_ADL_Overdrive_PowerControlInfo_Get (adl, iAdapterIndex, &powertune)) != ADL_OK) - { - log_info ("WARN: %s\n", "ADL_Overdrive6_PowerControl_Get", ADL_rc); - } - else - { - int min = powertune.iMinValue; - int max = powertune.iMaxValue; - int step = powertune.iStepValue; - - if (level < min || level > max) - { - log_info ("WARN: ADL PowerControl level invalid"); - - return ADL_ERR; - } - if (level % step != 0) - { - log_info ("WARN: ADL PowerControl step invalid"); - - return ADL_ERR; - } - - ADL_rc = adl->ADL_Overdrive6_PowerControl_Set (iAdapterIndex, level); - } - - return (ADL_rc); -} - -int hm_ADL_Adapter_Active_Get (ADL_PTR *adl, int iAdapterIndex, int *lpStatus) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Adapter_Active_Get (iAdapterIndex, lpStatus); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_Adapter_Active_Get()", ADL_rc); - } - - return (ADL_rc); -} - -/* -int hm_ADL_DisplayEnable_Set (ADL_PTR *adl, int iAdapterIndex, int *lpDisplayIndexList, int iDisplayListSize, int bPersistOnly) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_DisplayEnable_Set (iAdapterIndex, lpDisplayIndexList, iDisplayListSize, bPersistOnly); - - if (ADL_rc != ADL_OK) - { - log_info ("WARN: %s: %d\n", "ADL_DisplayEnable_Set()", ADL_rc); - } - - return (ADL_rc); -} -*/ - -int hm_ADL_Overdrive_Caps (ADL_PTR *adl, int iAdapterIndex, int *od_supported, int *od_enabled, int *od_version) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive_Caps (iAdapterIndex, od_supported, od_enabled, od_version); - - return (ADL_rc); -} - -int hm_ADL_Overdrive6_PowerControl_Caps (ADL_PTR *adl, int iAdapterIndex, int *lpSupported) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive6_PowerControl_Caps (iAdapterIndex, lpSupported); - - return (ADL_rc); -} - -int hm_ADL_Overdrive_Capabilities_Get (ADL_PTR *adl, int iAdapterIndex, ADLOD6Capabilities *caps) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive6_Capabilities_Get (iAdapterIndex, caps); - - return (ADL_rc); -} - -int hm_ADL_Overdrive_StateInfo_Get (ADL_PTR *adl, int iAdapterIndex, int type, ADLOD6MemClockState *state) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive6_StateInfo_Get (iAdapterIndex, type, state); - - if (ADL_rc == ADL_OK) - { - // check if clocks are okay with step sizes - // if not run a little hack: adjust the clocks to nearest clock size (clock down just a little bit) - - ADLOD6Capabilities caps; - - if ((hm_ADL_Overdrive_Capabilities_Get (adl, iAdapterIndex, &caps)) != ADL_OK) - { - log_info ("ERROR: failed to get ADL device capabilities"); - - exit (1); - } - - if (state->state.aLevels[0].iEngineClock % caps.sEngineClockRange.iStep != 0) - { - log_info ("WARN: ADL engine step size invalid for performance level 1"); - state->state.aLevels[0].iEngineClock -= state->state.aLevels[0].iEngineClock % caps.sEngineClockRange.iStep; - } - - if (state->state.aLevels[1].iEngineClock % caps.sEngineClockRange.iStep != 0) - { - log_info ("WARN: ADL engine step size invalid for performance level 2"); - state->state.aLevels[1].iEngineClock -= state->state.aLevels[1].iEngineClock % caps.sEngineClockRange.iStep; - } - - if (state->state.aLevels[0].iMemoryClock % caps.sMemoryClockRange.iStep != 0) - { - log_info ("WARN: ADL memory step size invalid for performance level 1"); - state->state.aLevels[0].iMemoryClock -= state->state.aLevels[0].iMemoryClock % caps.sMemoryClockRange.iStep; - } - - if (state->state.aLevels[1].iMemoryClock % caps.sMemoryClockRange.iStep != 0) - { - log_info ("WARN: ADL memory step size invalid for performance level 2"); - state->state.aLevels[1].iMemoryClock -= state->state.aLevels[1].iMemoryClock % caps.sMemoryClockRange.iStep; - } - } - - return (ADL_rc); -} - -int hm_ADL_Overdrive_CurrentStatus_Get (ADL_PTR *adl, int iAdapterIndex, ADLOD6CurrentStatus *status) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive6_CurrentStatus_Get (iAdapterIndex, status); - - return (ADL_rc); -} - -int hm_ADL_Overdrive_State_Set (ADL_PTR *adl, int iAdapterIndex, int type, ADLOD6StateInfo *state) -{ - if (!adl) return -1; - - // sanity checks - - ADLOD6Capabilities caps; - - if ((hm_ADL_Overdrive_Capabilities_Get (adl, iAdapterIndex, &caps)) != ADL_OK) - { - log_info ("ERROR: failed to get ADL device capabilities"); - - exit (1); - } - - if (state->aLevels[0].iEngineClock < caps.sEngineClockRange.iMin || state->aLevels[1].iEngineClock > caps.sEngineClockRange.iMax) - { - log_info ("WARN: ADL engine clock outside valid range"); - - return ADL_ERR; - } - - if (state->aLevels[1].iEngineClock % caps.sEngineClockRange.iStep != 0) - { - log_info ("WARN: ADL engine step size invalid"); - - return ADL_ERR; - } - - if (state->aLevels[0].iMemoryClock < caps.sMemoryClockRange.iMin || state->aLevels[1].iMemoryClock > caps.sMemoryClockRange.iMax) - { - log_info ("WARN: ADL memory clock outside valid range"); - - return ADL_ERR; - } - - if (state->aLevels[1].iMemoryClock % caps.sMemoryClockRange.iStep != 0) - { - log_info ("WARN: ADL memory step size invalid"); - - return ADL_ERR; - } - - int ADL_rc = adl->ADL_Overdrive6_State_Set (iAdapterIndex, type, state); - - return (ADL_rc); -} - -int hm_ADL_Overdrive6_TargetTemperatureData_Get (ADL_PTR *adl, int iAdapterIndex, int *cur_temp, int *default_temp) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive6_TargetTemperatureData_Get (iAdapterIndex, cur_temp, default_temp); - - return (ADL_rc); -} - -int hm_ADL_Overdrive6_TargetTemperatureRangeInfo_Get (ADL_PTR *adl, int iAdapterIndex, ADLOD6ParameterRange *lpTargetTemperatureInfo) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive6_TargetTemperatureRangeInfo_Get (iAdapterIndex, lpTargetTemperatureInfo); - - return (ADL_rc); -} - -int hm_ADL_Overdrive6_FanSpeed_Reset (ADL_PTR *adl, int iAdapterIndex) -{ - if (!adl) return -1; - - int ADL_rc = adl->ADL_Overdrive6_FanSpeed_Reset (iAdapterIndex); - - return (ADL_rc); + return malloc ((size_t) iSize); } diff --git a/src/ext_OpenCL.c b/src/ext_OpenCL.c index dd81a2e5f..89b291c6c 100644 --- a/src/ext_OpenCL.c +++ b/src/ext_OpenCL.c @@ -6,8 +6,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" -#include "dynloader.h" +#include "event.h" #include "ext_OpenCL.h" const char *val2cstr_cl (cl_int CL_err) @@ -58,279 +57,3 @@ const char *val2cstr_cl (cl_int CL_err) return "CL_UNKNOWN_ERROR"; } - -int ocl_init (OCL_PTR *ocl) -{ - if (!ocl) - { - log_error ("ERROR: OpenCL library pointer is null"); - - exit (-1); - } - - memset (ocl, 0, sizeof (hc_opencl_lib_t)); - - #if defined(_WIN) - ocl->lib = hc_dlopen ("OpenCL"); - #elif defined(__APPLE__) - ocl->lib = hc_dlopen ("/System/Library/Frameworks/OpenCL.framework/OpenCL", RTLD_NOW); - #else - ocl->lib = hc_dlopen ("libOpenCL.so", RTLD_NOW); - - if (ocl->lib == NULL) ocl->lib = hc_dlopen ("libOpenCL.so.1", RTLD_NOW); - #endif - - if (ocl->lib == NULL) - { - log_info (""); - log_info ("ATTENTION! Can't find OpenCL ICD loader library"); - log_info (""); - #if defined (__linux__) - log_info ("You're probably missing the \"ocl-icd-libopencl1\" package (Debian/Ubuntu)"); - log_info (" sudo apt-get install ocl-icd-libopencl1"); - log_info (""); - #elif defined (_WIN) - log_info ("You're probably missing the OpenCL runtime installation"); - log_info (" AMD users require AMD drivers 14.9 or later (recommended 15.12 or later)"); - log_info (" Intel users require Intel OpenCL Runtime 14.2 or later (recommended 15.1 or later)"); - log_info (" NVidia users require NVidia drivers 346.59 or later (recommended 361.x or later)"); - log_info (""); - #endif - - exit (-1); - } - - HC_LOAD_FUNC(ocl, clBuildProgram, OCL_CLBUILDPROGRAM, OpenCL, 1) - HC_LOAD_FUNC(ocl, clCreateBuffer, OCL_CLCREATEBUFFER, OpenCL, 1) - HC_LOAD_FUNC(ocl, clCreateCommandQueue, OCL_CLCREATECOMMANDQUEUE, OpenCL, 1) - HC_LOAD_FUNC(ocl, clCreateContext, OCL_CLCREATECONTEXT, OpenCL, 1) - HC_LOAD_FUNC(ocl, clCreateKernel, OCL_CLCREATEKERNEL, OpenCL, 1) - HC_LOAD_FUNC(ocl, clCreateProgramWithBinary, OCL_CLCREATEPROGRAMWITHBINARY, OpenCL, 1) - HC_LOAD_FUNC(ocl, clCreateProgramWithSource, OCL_CLCREATEPROGRAMWITHSOURCE, OpenCL, 1) - HC_LOAD_FUNC(ocl, clEnqueueCopyBuffer, OCL_CLENQUEUECOPYBUFFER, OpenCL, 1) - HC_LOAD_FUNC(ocl, clEnqueueMapBuffer, OCL_CLENQUEUEMAPBUFFER, OpenCL, 1) - HC_LOAD_FUNC(ocl, clEnqueueNDRangeKernel, OCL_CLENQUEUENDRANGEKERNEL, OpenCL, 1) - HC_LOAD_FUNC(ocl, clEnqueueReadBuffer, OCL_CLENQUEUEREADBUFFER, OpenCL, 1) - HC_LOAD_FUNC(ocl, clEnqueueUnmapMemObject, OCL_CLENQUEUEUNMAPMEMOBJECT, OpenCL, 1) - HC_LOAD_FUNC(ocl, clEnqueueWriteBuffer, OCL_CLENQUEUEWRITEBUFFER, OpenCL, 1) - HC_LOAD_FUNC(ocl, clFinish, OCL_CLFINISH, OpenCL, 1) - HC_LOAD_FUNC(ocl, clFlush, OCL_CLFLUSH, OpenCL, 1) - HC_LOAD_FUNC(ocl, clGetDeviceIDs, OCL_CLGETDEVICEIDS, OpenCL, 1) - HC_LOAD_FUNC(ocl, clGetDeviceInfo, OCL_CLGETDEVICEINFO, OpenCL, 1) - HC_LOAD_FUNC(ocl, clGetEventInfo, OCL_CLGETEVENTINFO, OpenCL, 1) - HC_LOAD_FUNC(ocl, clGetKernelWorkGroupInfo, OCL_CLGETKERNELWORKGROUPINFO, OpenCL, 1) - HC_LOAD_FUNC(ocl, clGetPlatformIDs, OCL_CLGETPLATFORMIDS, OpenCL, 1) - HC_LOAD_FUNC(ocl, clGetPlatformInfo, OCL_CLGETPLATFORMINFO, OpenCL, 1) - HC_LOAD_FUNC(ocl, clGetProgramBuildInfo, OCL_CLGETPROGRAMBUILDINFO, OpenCL, 1) - HC_LOAD_FUNC(ocl, clGetProgramInfo, OCL_CLGETPROGRAMINFO, OpenCL, 1) - HC_LOAD_FUNC(ocl, clReleaseCommandQueue, OCL_CLRELEASECOMMANDQUEUE, OpenCL, 1) - HC_LOAD_FUNC(ocl, clReleaseContext, OCL_CLRELEASECONTEXT, OpenCL, 1) - HC_LOAD_FUNC(ocl, clReleaseKernel, OCL_CLRELEASEKERNEL, OpenCL, 1) - HC_LOAD_FUNC(ocl, clReleaseMemObject, OCL_CLRELEASEMEMOBJECT, OpenCL, 1) - HC_LOAD_FUNC(ocl, clReleaseProgram, OCL_CLRELEASEPROGRAM, OpenCL, 1) - HC_LOAD_FUNC(ocl, clSetKernelArg, OCL_CLSETKERNELARG, OpenCL, 1) - HC_LOAD_FUNC(ocl, clWaitForEvents, OCL_CLWAITFOREVENTS, OpenCL, 1) - HC_LOAD_FUNC(ocl, clGetEventProfilingInfo, OCL_CLGETEVENTPROFILINGINFO, OpenCL, 1) - HC_LOAD_FUNC(ocl, clReleaseEvent, OCL_CLRELEASEEVENT, OpenCL, 1) - - return 0; -} - -void ocl_close (OCL_PTR *ocl) -{ - if (ocl) - { - if (ocl->lib) - { - hc_dlclose (ocl->lib); - } - } -} - -cl_int hc_clEnqueueNDRangeKernel (OCL_PTR *ocl, cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim, const size_t *global_work_offset, const size_t *global_work_size, const size_t *local_work_size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) -{ - return ocl->clEnqueueNDRangeKernel (command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size, num_events_in_wait_list, event_wait_list, event); -} - -cl_int hc_clGetEventInfo (OCL_PTR *ocl, cl_event event, cl_event_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) -{ - return ocl->clGetEventInfo (event, param_name, param_value_size, param_value, param_value_size_ret); -} - -cl_int hc_clFlush (OCL_PTR *ocl, cl_command_queue command_queue) -{ - return ocl->clFlush (command_queue); -} - -cl_int hc_clFinish (OCL_PTR *ocl, cl_command_queue command_queue) -{ - return ocl->clFinish (command_queue); -} - -cl_int hc_clSetKernelArg (OCL_PTR *ocl, cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value) -{ - return ocl->clSetKernelArg (kernel, arg_index, arg_size, arg_value); -} - -cl_int hc_clEnqueueWriteBuffer (OCL_PTR *ocl, cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, size_t offset, size_t cb, const void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) -{ - return ocl->clEnqueueWriteBuffer (command_queue, buffer, blocking_write, offset, cb, ptr, num_events_in_wait_list, event_wait_list, event); -} - -cl_int hc_clEnqueueCopyBuffer (OCL_PTR *ocl, cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer, size_t src_offset, size_t dst_offset, size_t cb, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) -{ - return ocl->clEnqueueCopyBuffer (command_queue, src_buffer, dst_buffer, src_offset, dst_offset, cb, num_events_in_wait_list, event_wait_list, event); -} - -cl_int hc_clEnqueueReadBuffer (OCL_PTR *ocl, cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, size_t offset, size_t cb, void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) -{ - return ocl->clEnqueueReadBuffer (command_queue, buffer, blocking_read, offset, cb, ptr, num_events_in_wait_list, event_wait_list, event); -} - -cl_int hc_clGetPlatformIDs (OCL_PTR *ocl, cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms) -{ - return ocl->clGetPlatformIDs (num_entries, platforms, num_platforms); -} - -cl_int hc_clGetPlatformInfo (OCL_PTR *ocl, cl_platform_id platform, cl_platform_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) -{ - return ocl->clGetPlatformInfo (platform, param_name, param_value_size, param_value, param_value_size_ret); -} - -cl_int hc_clGetDeviceIDs (OCL_PTR *ocl, cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, cl_device_id *devices, cl_uint *num_devices) -{ - return ocl->clGetDeviceIDs (platform, device_type, num_entries, devices, num_devices); -} - -cl_int hc_clGetDeviceInfo (OCL_PTR *ocl, cl_device_id device, cl_device_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) -{ - return ocl->clGetDeviceInfo (device, param_name, param_value_size, param_value, param_value_size_ret); -} - -cl_int hc_clCreateContext (OCL_PTR *ocl, cl_context_properties *properties, cl_uint num_devices, const cl_device_id *devices, void (CL_CALLBACK *pfn_notify) (const char *, const void *, size_t, void *), void *user_data, cl_context *context) -{ - cl_int CL_err; - - *context = ocl->clCreateContext (properties, num_devices, devices, pfn_notify, user_data, &CL_err); - - return CL_err; -} - -cl_int hc_clCreateCommandQueue (OCL_PTR *ocl, cl_context context, cl_device_id device, cl_command_queue_properties properties, cl_command_queue *command_queue) -{ - cl_int CL_err; - - *command_queue = ocl->clCreateCommandQueue (context, device, properties, &CL_err); - - return CL_err; -} - -cl_int hc_clCreateBuffer (OCL_PTR *ocl, cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_mem *mem) -{ - cl_int CL_err; - - *mem = ocl->clCreateBuffer (context, flags, size, host_ptr, &CL_err); - - return CL_err; -} - -cl_int hc_clCreateProgramWithSource (OCL_PTR *ocl, cl_context context, cl_uint count, const char **strings, const size_t *lengths, cl_program *program) -{ - cl_int CL_err; - - *program = ocl->clCreateProgramWithSource (context, count, strings, lengths, &CL_err); - - return CL_err; -} - -cl_int hc_clCreateProgramWithBinary (OCL_PTR *ocl, cl_context context, cl_uint num_devices, const cl_device_id *device_list, const size_t *lengths, const unsigned char **binaries, cl_int *binary_status, cl_program *program) -{ - cl_int CL_err; - - *program = ocl->clCreateProgramWithBinary (context, num_devices, device_list, lengths, binaries, binary_status, &CL_err); - - return CL_err; -} - -cl_int hc_clBuildProgram (OCL_PTR *ocl, cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, void (CL_CALLBACK *pfn_notify) (cl_program program, void *user_data), void *user_data) -{ - return ocl->clBuildProgram (program, num_devices, device_list, options, pfn_notify, user_data); -} - -cl_int hc_clCreateKernel (OCL_PTR *ocl, cl_program program, const char *kernel_name, cl_kernel *kernel) -{ - cl_int CL_err; - - *kernel = ocl->clCreateKernel (program, kernel_name, &CL_err); - - return CL_err; -} - -cl_int hc_clReleaseMemObject (OCL_PTR *ocl, cl_mem mem) -{ - return ocl->clReleaseMemObject (mem); -} - -cl_int hc_clReleaseKernel (OCL_PTR *ocl, cl_kernel kernel) -{ - return ocl->clReleaseKernel (kernel); -} - -cl_int hc_clReleaseProgram (OCL_PTR *ocl, cl_program program) -{ - return ocl->clReleaseProgram (program); -} - -cl_int hc_clReleaseCommandQueue (OCL_PTR *ocl, cl_command_queue command_queue) -{ - return ocl->clReleaseCommandQueue (command_queue); -} - -cl_int hc_clReleaseContext (OCL_PTR *ocl, cl_context context) -{ - return ocl->clReleaseContext (context); -} - -cl_int hc_clEnqueueMapBuffer (OCL_PTR *ocl, cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, cl_map_flags map_flags, size_t offset, size_t cb, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event, void **buf) -{ - cl_int CL_err; - - *buf = ocl->clEnqueueMapBuffer (command_queue, buffer, blocking_read, map_flags, offset, cb, num_events_in_wait_list, event_wait_list, event, &CL_err); - - return CL_err; -} - -cl_int hc_clEnqueueUnmapMemObject (OCL_PTR *ocl, cl_command_queue command_queue, cl_mem memobj, void *mapped_ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) -{ - return ocl->clEnqueueUnmapMemObject (command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event); -} - -cl_int hc_clGetKernelWorkGroupInfo (OCL_PTR *ocl, cl_kernel kernel, cl_device_id device, cl_kernel_work_group_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) -{ - return ocl->clGetKernelWorkGroupInfo (kernel, device, param_name, param_value_size, param_value, param_value_size_ret); -} - -cl_int hc_clGetProgramBuildInfo (OCL_PTR *ocl, cl_program program, cl_device_id device, cl_program_build_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) -{ - return ocl->clGetProgramBuildInfo (program, device, param_name, param_value_size, param_value, param_value_size_ret); -} - -cl_int hc_clGetProgramInfo (OCL_PTR *ocl, cl_program program, cl_program_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) -{ - return ocl->clGetProgramInfo (program, param_name, param_value_size, param_value, param_value_size_ret); -} - -cl_int hc_clWaitForEvents (OCL_PTR *ocl, cl_uint num_events, const cl_event *event_list) -{ - return ocl->clWaitForEvents (num_events, event_list); -} - -cl_int hc_clGetEventProfilingInfo (OCL_PTR *ocl, cl_event event, cl_profiling_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) -{ - return ocl->clGetEventProfilingInfo (event, param_name, param_value_size, param_value, param_value_size_ret); -} - -cl_int hc_clReleaseEvent (OCL_PTR *ocl, cl_event event) -{ - return ocl->clReleaseEvent (event); -} diff --git a/src/ext_nvapi.c b/src/ext_nvapi.c index b50f08ec4..f366372d4 100644 --- a/src/ext_nvapi.c +++ b/src/ext_nvapi.c @@ -4,203 +4,7 @@ */ #include "common.h" -#include "logging.h" +#include "types.h" +#include "event.h" #include "memory.h" -#include "dynloader.h" #include "ext_nvapi.h" - -int nvapi_init (NVAPI_PTR *nvapi) -{ - if (!nvapi) return -1; - - memset (nvapi, 0, sizeof (NVAPI_PTR)); - - #if defined (_WIN) - #if defined (WIN64) - nvapi->lib = hc_dlopen ("nvapi64.dll"); - #elif defined (WIN32) - nvapi->lib = hc_dlopen ("nvapi.dll"); - #endif - #else - nvapi->lib = hc_dlopen ("nvapi.so", RTLD_NOW); // uhm yes, but .. yeah - #endif - - if (!nvapi->lib) - { - //if (user_options->quiet == false) - // log_info ("WARNING: load NVAPI library failed, proceed without NVAPI HWMon enabled."); - - return -1; - } - - HC_LOAD_FUNC(nvapi, nvapi_QueryInterface, NVAPI_QUERYINTERFACE, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_Initialize, NVAPI_INITIALIZE, nvapi_QueryInterface, 0x0150E828, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_Unload, NVAPI_UNLOAD, nvapi_QueryInterface, 0xD22BDD7E, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_GetErrorMessage, NVAPI_GETERRORMESSAGE, nvapi_QueryInterface, 0x6C2D048C, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_EnumPhysicalGPUs, NVAPI_ENUMPHYSICALGPUS, nvapi_QueryInterface, 0xE5AC921F, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfPoliciesInfo, NVAPI_GPU_GETPERFPOLICIESINFO, nvapi_QueryInterface, 0x409D9841, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfPoliciesStatus, NVAPI_GPU_GETPERFPOLICIESSTATUS, nvapi_QueryInterface, 0x3D358A0C, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_GPU_SetCoolerLevels, NVAPI_GPU_SETCOOLERLEVELS, nvapi_QueryInterface, 0x891FA0AE, NVAPI, 0) - HC_LOAD_ADDR(nvapi, NvAPI_GPU_RestoreCoolerSettings, NVAPI_GPU_RESTORECOOLERSETTINGS, nvapi_QueryInterface, 0x8F6ED0FB, NVAPI, 0) - - return 0; -} - -void nvapi_close (NVAPI_PTR *nvapi) -{ - if (nvapi) - { - if (nvapi->lib) - hc_dlclose (nvapi->lib); - - myfree (nvapi); - } -} - -int hm_NvAPI_GetErrorMessage (NVAPI_PTR *nvapi, NvAPI_Status NvAPI_rc, NvAPI_ShortString string) -{ - if (!nvapi) return -1; - - return nvapi->NvAPI_GetErrorMessage (NvAPI_rc, string); -} - -NvAPI_Status hm_NvAPI_Initialize (NVAPI_PTR *nvapi) -{ - if (!nvapi) return (NvAPI_Status) -1; - - NvAPI_Status NvAPI_rc = nvapi->NvAPI_Initialize (); - - if (NvAPI_rc == NVAPI_LIBRARY_NOT_FOUND) NvAPI_rc = NVAPI_OK; // not a bug - - if (NvAPI_rc != NVAPI_OK) - { - NvAPI_ShortString string = { 0 }; - - hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string); - - log_info ("WARN: %s %d %s\n", "NvAPI_Initialize()", NvAPI_rc, string); - } - - return NvAPI_rc; -} - -NvAPI_Status hm_NvAPI_Unload (NVAPI_PTR *nvapi) -{ - if (!nvapi) return (NvAPI_Status) -1; - - NvAPI_Status NvAPI_rc = nvapi->NvAPI_Unload (); - - if (NvAPI_rc != NVAPI_OK) - { - NvAPI_ShortString string = { 0 }; - - hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string); - - log_info ("WARN: %s %d %s\n", "NvAPI_Unload()", NvAPI_rc, string); - } - - return NvAPI_rc; -} - -NvAPI_Status hm_NvAPI_EnumPhysicalGPUs (NVAPI_PTR *nvapi, NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount) -{ - if (!nvapi) return (NvAPI_Status) -1; - - NvAPI_Status NvAPI_rc = nvapi->NvAPI_EnumPhysicalGPUs (nvGPUHandle, pGpuCount); - - if (NvAPI_rc != NVAPI_OK) - { - NvAPI_ShortString string = { 0 }; - - hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string); - - log_info ("WARN: %s %d %s\n", "NvAPI_EnumPhysicalGPUs()", NvAPI_rc, string); - } - - return NvAPI_rc; -} - -NvAPI_Status hm_NvAPI_GPU_GetPerfPoliciesInfo (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 *perfPolicies_info) -{ - if (!nvapi) return (NvAPI_Status) -1; - - NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_GetPerfPoliciesInfo (hPhysicalGpu, perfPolicies_info); - - if (NvAPI_rc != NVAPI_OK) - { - NvAPI_ShortString string = { 0 }; - - hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string); - - log_info ("WARN: %s %d %s\n", "NvAPI_GPU_GetPerfPoliciesInfo()", NvAPI_rc, string); - } - - return NvAPI_rc; -} - -NvAPI_Status hm_NvAPI_GPU_GetPerfPoliciesStatus (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 *perfPolicies_status) -{ - if (!nvapi) return (NvAPI_Status) -1; - - NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_GetPerfPoliciesStatus (hPhysicalGpu, perfPolicies_status); - - if (NvAPI_rc != NVAPI_OK) - { - NvAPI_ShortString string = { 0 }; - - hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string); - - log_info ("WARN: %s %d %s\n", "NvAPI_GPU_GetPerfPoliciesStatus()", NvAPI_rc, string); - } - - return NvAPI_rc; -} - -NvAPI_Status hm_NvAPI_GPU_SetCoolerLevels (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NvU32 coolerIndex, NV_GPU_COOLER_LEVELS *pCoolerLevels) -{ - if (!nvapi) return (NvAPI_Status) -1; - - NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_SetCoolerLevels (hPhysicalGpu, coolerIndex, pCoolerLevels); - - if (NvAPI_rc != NVAPI_OK) - { - NvAPI_ShortString string = { 0 }; - - hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string); - - log_info ("WARN: %s %d %s\n", "NvAPI_GPU_SetCoolerLevels()", NvAPI_rc, string); - } - - return NvAPI_rc; -} - -NvAPI_Status hm_NvAPI_GPU_RestoreCoolerSettings (NVAPI_PTR *nvapi, NvPhysicalGpuHandle hPhysicalGpu, NvU32 coolerIndex) -{ - if (!nvapi) return (NvAPI_Status) -1; - - NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_RestoreCoolerSettings (hPhysicalGpu, coolerIndex); - - if (NvAPI_rc != NVAPI_OK) - { - NvAPI_ShortString string = { 0 }; - - hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string); - - log_info ("WARN: %s %d %s\n", "NvAPI_GPU_RestoreCoolerSettings()", NvAPI_rc, string); - } - - return NvAPI_rc; -} - -#if defined (__MINGW64__) - -void __security_check_cookie (uintptr_t _StackCookie) -{ - (void) _StackCookie; -} - -void __GSHandlerCheck () -{ -} - -#endif diff --git a/src/ext_nvml.c b/src/ext_nvml.c index 9d76f2aba..36e906e28 100644 --- a/src/ext_nvml.c +++ b/src/ext_nvml.c @@ -4,466 +4,8 @@ */ #include "common.h" -#include "logging.h" +#include "types.h" +#include "event.h" #include "memory.h" #include "dynloader.h" #include "ext_nvml.h" - -int nvml_init (NVML_PTR *nvml) -{ - if (!nvml) return -1; - - memset (nvml, 0, sizeof (NVML_PTR)); - - #if defined (_WIN) - nvml->lib = hc_dlopen ("nvml.dll"); - - if (!nvml->lib) - { - DWORD BufferSize = 1024; - - DWORD Type = REG_SZ; - - char *Buffer = (char *) mymalloc (BufferSize + 1); - - HKEY hKey = 0; - - if (RegOpenKeyExA (HKEY_LOCAL_MACHINE, "SOFTWARE\\NVIDIA Corporation\\Global\\NVSMI", 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) - { - if (RegQueryValueExA (hKey, "NVSMIPATH", NULL, &Type, (LPBYTE)Buffer, &BufferSize) == ERROR_SUCCESS) - { - Buffer[BufferSize] = 0; - } - else - { - //if (user_options->quiet == false) - // log_info ("WARNING: NVML library load failed, proceed without NVML HWMon enabled."); - - return -1; - } - - RegCloseKey (hKey); - } - else - { - //if (user_options->quiet == false) - // log_info ("WARNING: NVML library load failed, proceed without NVML HWMon enabled."); - - return -1; - } - - strcat (Buffer, "\\nvml.dll"); - - nvml->lib = hc_dlopen (Buffer); - - myfree (Buffer); - } - - #elif defined (_POSIX) - nvml->lib = hc_dlopen ("libnvidia-ml.so", RTLD_NOW); - #endif - - if (!nvml->lib) - { - //if (user_options->quiet == false) - // log_info ("WARNING: NVML library load failed, proceed without NVML HWMon enabled."); - - return -1; - } - - HC_LOAD_FUNC(nvml, nvmlErrorString, NVML_ERROR_STRING, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlInit, NVML_INIT, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlShutdown, NVML_SHUTDOWN, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceGetName, NVML_DEVICE_GET_NAME, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceGetHandleByIndex, NVML_DEVICE_GET_HANDLE_BY_INDEX, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceGetTemperature, NVML_DEVICE_GET_TEMPERATURE, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceGetFanSpeed, NVML_DEVICE_GET_FAN_SPEED, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceGetPowerUsage, NVML_DEVICE_GET_POWER_USAGE, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceGetUtilizationRates, NVML_DEVICE_GET_UTILIZATION_RATES, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceGetClockInfo, NVML_DEVICE_GET_CLOCKINFO, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceGetTemperatureThreshold, NVML_DEVICE_GET_THRESHOLD, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceGetCurrPcieLinkGeneration, NVML_DEVICE_GET_CURRPCIELINKGENERATION, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceGetCurrPcieLinkWidth, NVML_DEVICE_GET_CURRPCIELINKWIDTH, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceGetCurrentClocksThrottleReasons, NVML_DEVICE_GET_CURRENTCLOCKSTHROTTLEREASONS, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceGetSupportedClocksThrottleReasons, NVML_DEVICE_GET_SUPPORTEDCLOCKSTHROTTLEREASONS, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceSetComputeMode, NVML_DEVICE_SET_COMPUTEMODE, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceSetGpuOperationMode, NVML_DEVICE_SET_OPERATIONMODE, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceGetPowerManagementLimitConstraints, NVML_DEVICE_GET_POWERMANAGEMENTLIMITCONSTRAINTS, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceSetPowerManagementLimit, NVML_DEVICE_SET_POWERMANAGEMENTLIMIT, NVML, 0) - HC_LOAD_FUNC(nvml, nvmlDeviceGetPowerManagementLimit, NVML_DEVICE_GET_POWERMANAGEMENTLIMIT, NVML, 0) - - return 0; -} - -void nvml_close (NVML_PTR *nvml) -{ - if (nvml) - { - if (nvml->lib) - hc_dlclose (nvml->lib); - - myfree (nvml); - } -} - -const char *hm_NVML_nvmlErrorString (NVML_PTR *nvml, nvmlReturn_t nvml_rc) -{ - if (!nvml) return NULL; - - return nvml->nvmlErrorString (nvml_rc); -} - -nvmlReturn_t hm_NVML_nvmlInit (NVML_PTR *nvml) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = (nvmlReturn_t)nvml->nvmlInit (); - - if (nvml_rc != NVML_SUCCESS) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlInit()", nvml_rc, string); - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlShutdown (NVML_PTR *nvml) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = (nvmlReturn_t)nvml->nvmlShutdown (); - - if (nvml_rc != NVML_SUCCESS) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlShutdown()", nvml_rc, string); - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceGetName (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, char *name, unsigned int length) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetName (device, name, length); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceGetName()", nvml_rc, string); - } - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceGetHandleByIndex (NVML_PTR *nvml, int skip_warnings, unsigned int index, nvmlDevice_t *device) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetHandleByIndex (index, device); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceGetHandleByIndex()", nvml_rc, string); - } - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceGetTemperature (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int *temp) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetTemperature (device, sensorType, temp); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceGetTemperature()", nvml_rc, string); - } - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceGetFanSpeed (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, unsigned int *speed) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetFanSpeed (device, speed); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceGetFanSpeed()", nvml_rc, string); - } - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceGetPowerUsage (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, unsigned int *power) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetPowerUsage (device, power); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerUsage()", nvml_rc, string); - } - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceGetUtilizationRates (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, nvmlUtilization_t *utilization) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetUtilizationRates (device, utilization); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string); - } - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceGetClockInfo (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, nvmlClockType_t type, unsigned int *clock) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetClockInfo (device, type, clock); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceGetClockInfo()", nvml_rc, string); - } - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceGetTemperatureThreshold (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, nvmlTemperatureThresholds_t thresholdType, unsigned int *temp) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetTemperatureThreshold (device, thresholdType, temp); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceGetTemperatureThreshold()", nvml_rc, string); - } - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceGetCurrPcieLinkGeneration (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, unsigned int *currLinkGen) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetCurrPcieLinkGeneration (device, currLinkGen); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceGetCurrPcieLinkGeneration()", nvml_rc, string); - } - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceGetCurrPcieLinkWidth (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, unsigned int *currLinkWidth) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetCurrPcieLinkWidth (device, currLinkWidth); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceGetCurrPcieLinkWidth()", nvml_rc, string); - } - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceGetCurrentClocksThrottleReasons (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, unsigned long long *clocksThrottleReasons) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetCurrentClocksThrottleReasons (device, clocksThrottleReasons); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceGetCurrentClocksThrottleReasons()", nvml_rc, string); - } - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceGetSupportedClocksThrottleReasons (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, unsigned long long *supportedClocksThrottleReasons) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetSupportedClocksThrottleReasons (device, supportedClocksThrottleReasons); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceGetSupportedClocksThrottleReasons()", nvml_rc, string); - } - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceSetComputeMode (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, nvmlComputeMode_t mode) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceSetComputeMode (device, mode); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceSetComputeMode()", nvml_rc, string); - } - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceSetGpuOperationMode (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, nvmlGpuOperationMode_t mode) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceSetGpuOperationMode (device, mode); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceSetGpuOperationMode()", nvml_rc, string); - } - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceGetPowerManagementLimitConstraints (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, unsigned int *minLimit, unsigned int *maxLimit) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetPowerManagementLimitConstraints (device, minLimit, maxLimit); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerManagementLimitConstraints()", nvml_rc, string); - } - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceSetPowerManagementLimit (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, unsigned int limit) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceSetPowerManagementLimit (device, limit); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceSetPowerManagementLimit()", nvml_rc, string); - } - } - - return nvml_rc; -} - -nvmlReturn_t hm_NVML_nvmlDeviceGetPowerManagementLimit (NVML_PTR *nvml, int skip_warnings, nvmlDevice_t device, unsigned int *limit) -{ - if (!nvml) return (nvmlReturn_t) -1; - - nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetPowerManagementLimit (device, limit); - - if (nvml_rc != NVML_SUCCESS) - { - if (skip_warnings == 0) - { - const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); - - log_info ("WARN: %s %d %s\n", "nvmlDeviceGetPowerManagementLimit()", nvml_rc, string); - } - } - - return nvml_rc; -} diff --git a/src/ext_xnvctrl.c b/src/ext_xnvctrl.c index b63cd90a2..d3e06a904 100644 --- a/src/ext_xnvctrl.c +++ b/src/ext_xnvctrl.c @@ -4,216 +4,7 @@ */ #include "common.h" -#include "logging.h" +#include "types.h" +#include "event.h" #include "memory.h" -#include "dynloader.h" #include "ext_xnvctrl.h" - -int xnvctrl_init (XNVCTRL_PTR *xnvctrl) -{ - if (!xnvctrl) return -1; - - memset (xnvctrl, 0, sizeof (XNVCTRL_PTR)); - - #if defined (_WIN) - - // unsupport platform? - return -1; - - #elif defined (_POSIX) - - xnvctrl->lib_x11 = dlopen ("libX11.so", RTLD_LAZY); - - if (xnvctrl->lib_x11 == NULL) - { - //if (user_options->quiet == false) log_info ("WARNING: Failed loading the X11 library: %s", dlerror()); - //if (user_options->quiet == false) log_info (" Please install libx11-dev package."); - //if (user_options->quiet == false) log_info (""); - - return -1; - } - - xnvctrl->lib_xnvctrl = dlopen ("libXNVCtrl.so", RTLD_LAZY); - - if (xnvctrl->lib_xnvctrl == NULL) - { - //if (user_options->quiet == false) log_info ("WARNING: Failed loading the XNVCTRL library: %s", dlerror()); - //if (user_options->quiet == false) log_info (" Please install libxnvctrl-dev package."); - //if (user_options->quiet == false) log_info (""); - - return -1; - } - - HC_LOAD_FUNC2 (xnvctrl, XOpenDisplay, XOPENDISPLAY, lib_x11, X11, 0); - HC_LOAD_FUNC2 (xnvctrl, XCloseDisplay, XCLOSEDISPLAY, lib_x11, X11, 0); - - HC_LOAD_FUNC2 (xnvctrl, XNVCTRLQueryTargetAttribute, XNVCTRLQUERYTARGETATTRIBUTE, lib_xnvctrl, XNVCTRL, 0); - HC_LOAD_FUNC2 (xnvctrl, XNVCTRLSetTargetAttribute, XNVCTRLSETTARGETATTRIBUTE, lib_xnvctrl, XNVCTRL, 0); - - #endif - - return 0; -} - -void xnvctrl_close (XNVCTRL_PTR *xnvctrl) -{ - if (xnvctrl) - { - #if defined (_POSIX) - - if (xnvctrl->lib_x11) - { - dlclose (xnvctrl->lib_x11); - } - - if (xnvctrl->lib_xnvctrl) - { - dlclose (xnvctrl->lib_xnvctrl); - } - - #endif - - myfree (xnvctrl); - } -} - -int hm_XNVCTRL_XOpenDisplay (XNVCTRL_PTR *xnvctrl) -{ - if (xnvctrl == NULL) return -1; - - if (xnvctrl->XOpenDisplay == NULL) return -1; - - void *dpy = xnvctrl->XOpenDisplay (NULL); - - if (dpy == NULL) - { - xnvctrl->dpy = NULL; - - return -1; - } - - xnvctrl->dpy = dpy; - - return 0; -} - -void hm_XNVCTRL_XCloseDisplay (XNVCTRL_PTR *xnvctrl) -{ - if (xnvctrl == NULL) return; - - if (xnvctrl->XCloseDisplay == NULL) return; - - if (xnvctrl->dpy == NULL) return; - - xnvctrl->XCloseDisplay (xnvctrl->dpy); -} - -int get_fan_control (XNVCTRL_PTR *xnvctrl, int gpu, int *val) -{ - if (xnvctrl == NULL) return -1; - - if (xnvctrl->XNVCTRLQueryTargetAttribute == NULL) return -1; - - if (xnvctrl->dpy == NULL) return -1; - - int rc = xnvctrl->XNVCTRLQueryTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_GPU, gpu, 0, NV_CTRL_GPU_COOLER_MANUAL_CONTROL, val); - - if (!rc) return -1; - - return 0; -} - -int set_fan_control (XNVCTRL_PTR *xnvctrl, int gpu, int val) -{ - if (xnvctrl == NULL) return -1; - - if (xnvctrl->XNVCTRLSetTargetAttribute == NULL) return -1; - - if (xnvctrl->dpy == NULL) return -1; - - int cur; - - int rc = get_fan_control (xnvctrl, gpu, &cur); - - if (rc == -1) return -1; - - xnvctrl->XNVCTRLSetTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_GPU, gpu, 0, NV_CTRL_GPU_COOLER_MANUAL_CONTROL, val); - - rc = get_fan_control (xnvctrl, gpu, &cur); - - if (rc == -1) return -1; - - if (cur != val) return -1; - - return 0; -} - -int get_core_threshold (XNVCTRL_PTR *xnvctrl, int gpu, int *val) -{ - if (xnvctrl == NULL) return -1; - - if (xnvctrl->XNVCTRLQueryTargetAttribute == NULL) return -1; - - if (xnvctrl->dpy == NULL) return -1; - - int rc = xnvctrl->XNVCTRLQueryTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_GPU, gpu, 0, NV_CTRL_GPU_CORE_THRESHOLD, val); - - if (!rc) return -1; - - return 0; -} - -int get_fan_speed_current (XNVCTRL_PTR *xnvctrl, int gpu, int *val) -{ - if (xnvctrl == NULL) return -1; - - if (xnvctrl->XNVCTRLQueryTargetAttribute == NULL) return -1; - - if (xnvctrl->dpy == NULL) return -1; - - int rc = xnvctrl->XNVCTRLQueryTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_COOLER, gpu, 0, NV_CTRL_THERMAL_COOLER_CURRENT_LEVEL, val); - - if (!rc) return -1; - - return 0; -} - -int get_fan_speed_target (XNVCTRL_PTR *xnvctrl, int gpu, int *val) -{ - if (xnvctrl == NULL) return -1; - - if (xnvctrl->XNVCTRLQueryTargetAttribute == NULL) return -1; - - if (xnvctrl->dpy == NULL) return -1; - - int rc = xnvctrl->XNVCTRLQueryTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_COOLER, gpu, 0, NV_CTRL_THERMAL_COOLER_LEVEL, val); - - if (!rc) return -1; - - return 0; -} - -int set_fan_speed_target (XNVCTRL_PTR *xnvctrl, int gpu, int val) -{ - if (xnvctrl == NULL) return -1; - - if (xnvctrl->XNVCTRLSetTargetAttribute == NULL) return -1; - - if (xnvctrl->dpy == NULL) return -1; - - int cur; - - int rc = get_fan_speed_target (xnvctrl, gpu, &cur); - - if (rc == -1) return -1; - - xnvctrl->XNVCTRLSetTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_COOLER, gpu, 0, NV_CTRL_THERMAL_COOLER_LEVEL, val); - - rc = get_fan_speed_target (xnvctrl, gpu, &cur); - - if (rc == -1) return -1; - - if (cur != val) return -1; - - return 0; -} diff --git a/src/filehandling.c b/src/filehandling.c index f4225489c..67218dba2 100644 --- a/src/filehandling.c +++ b/src/filehandling.c @@ -8,11 +8,11 @@ #include "memory.h" #include "filehandling.h" -u64 count_lines (FILE *fd) +u64 count_lines (hashcat_ctx_t *hashcat_ctx, FILE *fd) { u64 cnt = 0; - char *buf = (char *) mymalloc (HCBUFSIZ_LARGE + 1); + char *buf = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE + 1); VERIFY_PTR (buf); char prev = '\n'; @@ -32,7 +32,7 @@ u64 count_lines (FILE *fd) } } - myfree (buf); + hcfree (buf); return cnt; } diff --git a/src/folder.c b/src/folder.c index 368df70c8..4fe097936 100644 --- a/src/folder.c +++ b/src/folder.c @@ -10,12 +10,12 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "shared.h" #include "folder.h" #if defined (__APPLE__) -#include "logging.h" +#include "event.h" #endif int sort_by_stringptr (const void *p1, const void *p2) @@ -26,34 +26,25 @@ int sort_by_stringptr (const void *p1, const void *p2) return strcmp (*s1, *s2); } -char *get_exec_path () +static int get_exec_path (char *exec_path, const size_t exec_path_sz) { - size_t exec_path_len = 1024; - - char *exec_path = (char *) mymalloc (exec_path_len); - #if defined (__linux__) char tmp[32] = { 0 }; snprintf (tmp, sizeof (tmp) - 1, "/proc/%d/exe", getpid ()); - const int len = readlink (tmp, exec_path, exec_path_len - 1); + const int len = readlink (tmp, exec_path, exec_path_sz - 1); #elif defined (_WIN) - const int len = GetModuleFileName (NULL, exec_path, exec_path_len - 1); + const int len = GetModuleFileName (NULL, exec_path, exec_path_sz - 1); #elif defined (__APPLE__) - u32 size = (u32) exec_path_len; + u32 size = (u32) exec_path_sz; - if (_NSGetExecutablePath (exec_path, &size) != 0) - { - log_error("! executable path buffer too small\n"); - - exit (-1); - } + if (_NSGetExecutablePath (exec_path, &size) != 0) return -1; const size_t len = strlen (exec_path); @@ -68,11 +59,11 @@ char *get_exec_path () char tmp[32] = { 0 }; - size_t size = exec_path_len; + size_t size = exec_path_sz; sysctl (mib, 4, exec_path, &size, NULL, 0); - const int len = readlink (tmp, exec_path, exec_path_len - 1); + const int len = readlink (tmp, exec_path, exec_path_sz - 1); #else #error Your Operating System is not supported or detected @@ -80,13 +71,14 @@ char *get_exec_path () exec_path[len] = 0; - return exec_path; + return 0; } -char *get_install_dir (const char *progname) +void get_install_dir (char *install_dir, const char *exec_path) { - char *install_dir = mystrdup (progname); - char *last_slash = NULL; + strncpy (install_dir, exec_path, HCBUFSIZ_TINY - 1); + + char *last_slash = NULL; if ((last_slash = strrchr (install_dir, '/')) != NULL) { @@ -101,26 +93,16 @@ char *get_install_dir (const char *progname) install_dir[0] = '.'; install_dir[1] = 0; } - - return (install_dir); } -char *get_profile_dir (const char *homedir) +void get_profile_dir (char *profile_dir, const char *home_dir) { - char *profile_dir = (char *) mymalloc (HCBUFSIZ_TINY + 1); - - snprintf (profile_dir, HCBUFSIZ_TINY - 1, "%s/%s", homedir, DOT_HASHCAT); - - return profile_dir; + snprintf (profile_dir, HCBUFSIZ_TINY - 1, "%s/%s", home_dir, DOT_HASHCAT); } -char *get_session_dir (const char *profile_dir) +void get_session_dir (char *session_dir, const char *profile_dir) { - char *session_dir = (char *) mymalloc (HCBUFSIZ_TINY); - snprintf (session_dir, HCBUFSIZ_TINY - 1, "%s/%s", profile_dir, SESSIONS_FOLDER); - - return session_dir; } int count_dictionaries (char **dictionary_files) @@ -137,9 +119,9 @@ int count_dictionaries (char **dictionary_files) return (cnt); } -char **scan_directory (const char *path) +char **scan_directory (hashcat_ctx_t *hashcat_ctx, const char *path) { - char *tmp_path = mystrdup (path); + char *tmp_path = hcstrdup (hashcat_ctx, path); size_t tmp_path_len = strlen (tmp_path); @@ -152,7 +134,7 @@ char **scan_directory (const char *path) char **files = NULL; - int num_files = 0; + size_t num_files = 0; DIR *d = NULL; @@ -168,12 +150,7 @@ char **scan_directory (const char *path) struct dirent *de = NULL; - if (readdir_r (d, &e, &de) != 0) - { - log_error ("ERROR: readdir_r() failed"); - - break; - } + if (readdir_r (d, &e, &de) != 0) break; if (de == NULL) break; @@ -188,13 +165,9 @@ char **scan_directory (const char *path) if ((strcmp (de->d_name, ".") == 0) || (strcmp (de->d_name, "..") == 0)) continue; - size_t path_size = strlen (tmp_path) + 1 + strlen (de->d_name); + char *path_file = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); - char *path_file = (char *) mymalloc (path_size + 1); - - snprintf (path_file, path_size + 1, "%s/%s", tmp_path, de->d_name); - - path_file[path_size] = 0; + snprintf (path_file, HCBUFSIZ_TINY - 1, "%s/%s", tmp_path, de->d_name); DIR *d_test; @@ -202,15 +175,15 @@ char **scan_directory (const char *path) { closedir (d_test); - myfree (path_file); + hcfree (path_file); } else { - files = (char **) myrealloc (files, (size_t) num_files * sizeof (char *), sizeof (char *)); + files = (char **) hcrealloc (hashcat_ctx, files, (num_files + 1) * sizeof (char *), sizeof (char *)); + + files[num_files] = path_file; num_files++; - - files[num_files - 1] = path_file; } } @@ -218,25 +191,25 @@ char **scan_directory (const char *path) } else if (errno == ENOTDIR) { - files = (char **) myrealloc (files, (size_t) num_files * sizeof (char *), sizeof (char *)); + files = (char **) hcrealloc (hashcat_ctx, files, (num_files + 1) * sizeof (char *), sizeof (char *)); + + files[num_files] = hcstrdup (hashcat_ctx, path); num_files++; - - files[num_files - 1] = mystrdup (path); } - files = (char **) myrealloc (files, (size_t) num_files * sizeof (char *), sizeof (char *)); + files = (char **) hcrealloc (hashcat_ctx, files, (num_files + 1) * sizeof (char *), sizeof (char *)); + + files[num_files] = NULL; num_files++; - files[num_files - 1] = NULL; - - myfree (tmp_path); + hcfree (tmp_path); return (files); } -int folder_config_init (hashcat_ctx_t *hashcat_ctx, const char *install_folder, const char *shared_folder) +int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *install_folder, MAYBE_UNUSED const char *shared_folder) { folder_config_t *folder_config = hashcat_ctx->folder_config; @@ -247,11 +220,11 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, const char *install_folder, * then chdir() back to where we came from so we need to save it first */ - char *cwd = (char *) mymalloc (HCBUFSIZ_TINY); + char *cwd = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (cwd); if (getcwd (cwd, HCBUFSIZ_TINY - 1) == NULL) { - log_error ("ERROR: getcwd(): %s", strerror (errno)); + event_log_error (hashcat_ctx, "getcwd(): %s", strerror (errno)); return -1; } @@ -260,7 +233,18 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, const char *install_folder, * folders, as discussed on https://github.com/hashcat/hashcat/issues/20 */ - char *exec_path = get_exec_path (); + const size_t exec_path_sz = 1024; + + char *exec_path = (char *) hcmalloc (hashcat_ctx, exec_path_sz); VERIFY_PTR (exec_path); + + const int rc = get_exec_path (exec_path, exec_path_sz); + + if (rc == -1) + { + event_log_error (hashcat_ctx, "get_exec_path() failed"); + + return -1; + } #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) @@ -271,19 +255,22 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, const char *install_folder, if (resolved_install_folder == NULL) { - log_error ("ERROR: %s: %s", resolved_install_folder, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", resolved_install_folder, strerror (errno)); return -1; } if (resolved_exec_path == NULL) { - log_error ("ERROR: %s: %s", resolved_exec_path, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", resolved_exec_path, strerror (errno)); return -1; } - char *install_dir = get_install_dir (resolved_exec_path); + char *install_dir = hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (install_dir); + + get_install_dir (install_dir, resolved_exec_path); + char *profile_dir = NULL; char *session_dir = NULL; char *shared_dir = NULL; @@ -292,11 +279,15 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, const char *install_folder, { struct passwd *pw = getpwuid (getuid ()); - const char *homedir = pw->pw_dir; + const char *home_dir = pw->pw_dir; - profile_dir = get_profile_dir (homedir); - session_dir = get_session_dir (profile_dir); - shared_dir = mystrdup (shared_folder); + profile_dir = hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (profile_dir); + session_dir = hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (session_dir); + + get_profile_dir (profile_dir, home_dir); + get_session_dir (session_dir, profile_dir); + + shared_dir = hcstrdup (hashcat_ctx, shared_folder); hc_mkdir (profile_dir, 0700); hc_mkdir (session_dir, 0700); @@ -308,22 +299,22 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, const char *install_folder, shared_dir = install_dir; } - myfree (resolved_install_folder); - myfree (resolved_exec_path); + hcfree (resolved_install_folder); + hcfree (resolved_exec_path); #else - if (install_folder == NULL) install_folder = NULL; // make compiler happy - if (shared_folder == NULL) shared_folder = NULL; // make compiler happy + char *install_dir = hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (install_dir); + + get_install_dir (install_dir, exec_path); - char *install_dir = get_install_dir (exec_path); char *profile_dir = install_dir; char *session_dir = install_dir; char *shared_dir = install_dir; #endif - myfree (exec_path); + hcfree (exec_path); /** * There's alot of problem related to bad support -I parameters when building the kernel. @@ -332,17 +323,17 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, const char *install_folder, * The best workaround found so far is to modify the TMP variable (only inside hashcat process) before the runtime is load */ - char *cpath = (char *) mymalloc (HCBUFSIZ_TINY); + char *cpath = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (cpath); #if defined (_WIN) snprintf (cpath, HCBUFSIZ_TINY - 1, "%s\\OpenCL\\", shared_dir); - char *cpath_real = (char *) mymalloc (HCBUFSIZ_TINY); + char *cpath_real = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (cpath_real); if (GetFullPathName (cpath, HCBUFSIZ_TINY - 1, cpath_real, NULL) == 0) { - log_error ("ERROR: %s: %s", cpath, "GetFullPathName()"); + event_log_error (hashcat_ctx, "%s: %s", cpath, "GetFullPathName()"); return -1; } @@ -351,18 +342,18 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, const char *install_folder, snprintf (cpath, HCBUFSIZ_TINY - 1, "%s/OpenCL/", shared_dir); - char *cpath_real = (char *) mymalloc (PATH_MAX); + char *cpath_real = (char *) hcmalloc (hashcat_ctx, PATH_MAX); VERIFY_PTR (cpath_real); if (realpath (cpath, cpath_real) == NULL) { - log_error ("ERROR: %s: %s", cpath, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", cpath, strerror (errno)); return -1; } #endif - myfree (cpath); + hcfree (cpath); //if (getenv ("TMP") == NULL) if (1) @@ -391,13 +382,13 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, const char *install_folder, * kernel cache, we need to make sure folder exist */ - char *kernels_folder = (char *) mymalloc (HCBUFSIZ_TINY); + char *kernels_folder = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (kernels_folder); snprintf (kernels_folder, HCBUFSIZ_TINY - 1, "%s/kernels", profile_dir); hc_mkdir (kernels_folder, 0700); - myfree (kernels_folder); + hcfree (kernels_folder); /** * store for later use @@ -417,17 +408,16 @@ void folder_config_destroy (hashcat_ctx_t *hashcat_ctx) { folder_config_t *folder_config = hashcat_ctx->folder_config; - myfree (folder_config->cpath_real); - myfree (folder_config->cwd); - myfree (folder_config->install_dir); + hcfree (folder_config->cpath_real); + hcfree (folder_config->cwd); + hcfree (folder_config->install_dir); memset (folder_config, 0, sizeof (folder_config_t)); } -int hc_mkdir (const char *name, int mode) +int hc_mkdir (const char *name, MAYBE_UNUSED const int mode) { #if defined (_WIN) - if (mode == 0) mode = 0; // makes compiler happy return _mkdir (name); #else return mkdir (name, mode); diff --git a/src/hashcat.c b/src/hashcat.c index a792c1bb7..a1f184ab1 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -14,7 +14,6 @@ #include "types.h" #include "folder.h" #include "locking.h" -#include "logging.h" #include "memory.h" #include "shared.h" #include "thread.h" @@ -30,6 +29,7 @@ #include "debugfile.h" #include "dictstat.h" #include "dispatch.h" +#include "event.h" #include "hashes.h" #include "hwmon.h" #include "induct.h" @@ -46,7 +46,6 @@ #include "rp.h" #include "status.h" #include "straight.h" -#include "terminal.h" #include "tuningdb.h" #include "usage.h" #include "user_options.h" @@ -56,64 +55,6 @@ extern const u32 DEFAULT_BENCHMARK_ALGORITHMS_CNT; extern const u32 DEFAULT_BENCHMARK_ALGORITHMS_BUF[]; -void hashcat_ctx_init (hashcat_ctx_t *hashcat_ctx) -{ - hashcat_ctx->bitmap_ctx = (bitmap_ctx_t *) mymalloc (sizeof (bitmap_ctx_t)); - hashcat_ctx->combinator_ctx = (combinator_ctx_t *) mymalloc (sizeof (combinator_ctx_t)); - hashcat_ctx->cpt_ctx = (cpt_ctx_t *) mymalloc (sizeof (cpt_ctx_t)); - hashcat_ctx->debugfile_ctx = (debugfile_ctx_t *) mymalloc (sizeof (debugfile_ctx_t)); - hashcat_ctx->dictstat_ctx = (dictstat_ctx_t *) mymalloc (sizeof (dictstat_ctx_t)); - hashcat_ctx->folder_config = (folder_config_t *) mymalloc (sizeof (folder_config_t)); - hashcat_ctx->hashconfig = (hashconfig_t *) mymalloc (sizeof (hashconfig_t)); - hashcat_ctx->hashes = (hashes_t *) mymalloc (sizeof (hashes_t)); - hashcat_ctx->hwmon_ctx = (hwmon_ctx_t *) mymalloc (sizeof (hwmon_ctx_t)); - hashcat_ctx->induct_ctx = (induct_ctx_t *) mymalloc (sizeof (induct_ctx_t)); - hashcat_ctx->logfile_ctx = (logfile_ctx_t *) mymalloc (sizeof (logfile_ctx_t)); - hashcat_ctx->loopback_ctx = (loopback_ctx_t *) mymalloc (sizeof (loopback_ctx_t)); - hashcat_ctx->mask_ctx = (mask_ctx_t *) mymalloc (sizeof (mask_ctx_t)); - hashcat_ctx->opencl_ctx = (opencl_ctx_t *) mymalloc (sizeof (opencl_ctx_t)); - hashcat_ctx->outcheck_ctx = (outcheck_ctx_t *) mymalloc (sizeof (outcheck_ctx_t)); - hashcat_ctx->outfile_ctx = (outfile_ctx_t *) mymalloc (sizeof (outfile_ctx_t)); - hashcat_ctx->potfile_ctx = (potfile_ctx_t *) mymalloc (sizeof (potfile_ctx_t)); - hashcat_ctx->restore_ctx = (restore_ctx_t *) mymalloc (sizeof (restore_ctx_t)); - hashcat_ctx->status_ctx = (status_ctx_t *) mymalloc (sizeof (status_ctx_t)); - hashcat_ctx->straight_ctx = (straight_ctx_t *) mymalloc (sizeof (straight_ctx_t)); - hashcat_ctx->tuning_db = (tuning_db_t *) mymalloc (sizeof (tuning_db_t)); - hashcat_ctx->user_options_extra = (user_options_extra_t *) mymalloc (sizeof (user_options_extra_t)); - hashcat_ctx->user_options = (user_options_t *) mymalloc (sizeof (user_options_t)); - hashcat_ctx->wl_data = (wl_data_t *) mymalloc (sizeof (wl_data_t)); -} - -void hashcat_ctx_destroy (hashcat_ctx_t *hashcat_ctx) -{ - myfree (hashcat_ctx->bitmap_ctx); - myfree (hashcat_ctx->combinator_ctx); - myfree (hashcat_ctx->cpt_ctx); - myfree (hashcat_ctx->debugfile_ctx); - myfree (hashcat_ctx->dictstat_ctx); - myfree (hashcat_ctx->folder_config); - myfree (hashcat_ctx->hashconfig); - myfree (hashcat_ctx->hashes); - myfree (hashcat_ctx->hwmon_ctx); - myfree (hashcat_ctx->induct_ctx); - myfree (hashcat_ctx->logfile_ctx); - myfree (hashcat_ctx->loopback_ctx); - myfree (hashcat_ctx->mask_ctx); - myfree (hashcat_ctx->opencl_ctx); - myfree (hashcat_ctx->outcheck_ctx); - myfree (hashcat_ctx->outfile_ctx); - myfree (hashcat_ctx->potfile_ctx); - myfree (hashcat_ctx->restore_ctx); - myfree (hashcat_ctx->status_ctx); - myfree (hashcat_ctx->straight_ctx); - myfree (hashcat_ctx->tuning_db); - myfree (hashcat_ctx->user_options_extra); - myfree (hashcat_ctx->user_options); - myfree (hashcat_ctx->wl_data); - - memset (hashcat_ctx, 0, sizeof (hashcat_ctx_t)); -} - // inner2_loop iterates through wordlists, then calls kernel execution static int inner2_loop (hashcat_ctx_t *hashcat_ctx) @@ -141,25 +82,33 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx) status_progress_reset (hashcat_ctx); + status_ctx->words_off = 0; status_ctx->words_cur = 0; - restore_data_t *rd = restore_ctx->rd; - - if (rd->words_cur) + if (restore_ctx->rd) { - status_ctx->words_cur = rd->words_cur; + restore_data_t *rd = restore_ctx->rd; + + if (rd->words_cur > 0) + { + status_ctx->words_off = rd->words_cur; + status_ctx->words_cur = status_ctx->words_off; + + rd->words_cur = 0; + + user_options->skip = 0; + } + } + + if (user_options->skip > 0) + { + status_ctx->words_off = user_options->skip; + status_ctx->words_cur = status_ctx->words_off; user_options->skip = 0; } - if (user_options->skip) - { - status_ctx->words_cur = user_options->skip; - - user_options->skip = 0; - } - - status_ctx->ms_paused = 0; + status_ctx->msec_paused = 0; opencl_session_reset (hashcat_ctx); @@ -179,32 +128,28 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx) // words base - status_ctx->words_base = status_ctx->words_cnt / user_options_extra_amplifier (hashcat_ctx); + const u64 amplifier_cnt = user_options_extra_amplifier (hashcat_ctx); - if (user_options->keyspace == true) + status_ctx->words_base = status_ctx->words_cnt / amplifier_cnt; + + EVENT (EVENT_CALCULATED_WORDS_BASE); + + if (user_options->keyspace == true) return 0; + + // restore stuff + + if (status_ctx->words_off > status_ctx->words_base) { - log_info ("%" PRIu64 "", status_ctx->words_base); - - return 0; - } - - if (status_ctx->words_cur > status_ctx->words_base) - { - log_error ("ERROR: Restore value greater keyspace"); + event_log_error (hashcat_ctx, "Restore value greater keyspace"); return -1; } - // restore progress + const u64 progress_restored = status_ctx->words_off * amplifier_cnt; - if (status_ctx->words_cur) + for (u32 i = 0; i < hashes->salts_cnt; i++) { - const u64 progress_restored = status_ctx->words_cur * user_options_extra_amplifier (hashcat_ctx); - - for (u32 i = 0; i < hashes->salts_cnt; i++) - { - status_ctx->words_progress_restored[i] = progress_restored; - } + status_ctx->words_progress_restored[i] = progress_restored; } /** @@ -219,9 +164,11 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx) * create autotune threads */ - thread_param_t *threads_param = (thread_param_t *) mycalloc (opencl_ctx->devices_cnt, sizeof (thread_param_t)); + EVENT (EVENT_AUTOTUNE_STARTING); - hc_thread_t *c_threads = (hc_thread_t *) mycalloc (opencl_ctx->devices_cnt, sizeof (hc_thread_t)); + thread_param_t *threads_param = (thread_param_t *) hccalloc (hashcat_ctx, opencl_ctx->devices_cnt, sizeof (thread_param_t)); VERIFY_PTR (threads_param); + + hc_thread_t *c_threads = (hc_thread_t *) hccalloc (hashcat_ctx, opencl_ctx->devices_cnt, sizeof (hc_thread_t)); VERIFY_PTR (c_threads); status_ctx->devices_status = STATUS_AUTOTUNE; @@ -237,6 +184,8 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx) hc_thread_wait (opencl_ctx->devices_cnt, c_threads); + EVENT (EVENT_AUTOTUNE_FINISHED); + /** * autotune modified kernel_accel, which modifies opencl_ctx->kernel_power_all */ @@ -252,23 +201,6 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx) loopback_write_open (hashcat_ctx); } - /** - * Tell user we're about to start - */ - - if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) - { - if ((user_options->quiet == false) && (user_options->status == false) && (user_options->benchmark == false)) - { - if (user_options->quiet == false) send_prompt (); - } - } - else if (user_options_extra->wordlist_mode == WL_MODE_STDIN) - { - if (user_options->quiet == false) log_info ("Starting attack in stdin mode..."); - if (user_options->quiet == false) log_info (""); - } - /** * Prepare cracking stats */ @@ -287,6 +219,8 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx) * create cracker threads */ + EVENT (EVENT_CRACKER_STARTING); + status_ctx->devices_status = STATUS_RUNNING; for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) @@ -308,11 +242,9 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx) hc_thread_wait (opencl_ctx->devices_cnt, c_threads); - myfree (c_threads); + hcfree (c_threads); - myfree (threads_param); - - // calculate final status + hcfree (threads_param); if ((status_ctx->devices_status != STATUS_CRACKED) && (status_ctx->devices_status != STATUS_ABORTED) @@ -322,8 +254,6 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx) status_ctx->devices_status = STATUS_EXHAUSTED; } - logfile_sub_var_uint ("status-after-work", status_ctx->devices_status); - // update some timer time_t runtime_stop; @@ -337,15 +267,14 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx) time (&status_ctx->prepare_start); + EVENT (EVENT_CRACKER_FINISHED); + + // mark sub logfile + + logfile_sub_var_uint ("status-after-work", status_ctx->devices_status); + logfile_sub_msg ("STOP"); - // no more skip and restore from here - - if (status_ctx->devices_status == STATUS_EXHAUSTED) - { - rd->words_cur = 0; - } - // stop loopback recording if (user_options->loopback == true) @@ -353,41 +282,7 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx) loopback_write_close (hashcat_ctx); } - // print final status - - if (user_options->benchmark == true) - { - status_benchmark (hashcat_ctx); - - if (user_options->machine_readable == false) - { - log_info (""); - } - } - else - { - if (user_options->quiet == false) - { - clear_prompt (); - - if (hashes->digests_saved != hashes->digests_done) log_info (""); - - status_display (hashcat_ctx); - - log_info (""); - } - else - { - if (user_options->status == true) - { - status_display (hashcat_ctx); - - log_info (""); - } - } - } - - // New induction folder check + // New induction folder check, which is a controlled recursion if (induct_ctx->induction_dictionaries_cnt == 0) { @@ -399,14 +294,14 @@ static int inner2_loop (hashcat_ctx_t *hashcat_ctx) { const int rc_inner2_loop = inner2_loop (hashcat_ctx); - if (rc_inner2_loop == -1) return -1; + if (rc_inner2_loop == -1) myabort (hashcat_ctx); if (status_ctx->run_main_level3 == false) break; unlink (induct_ctx->induction_dictionaries[induct_ctx->induction_dictionaries_pos]); } - myfree (induct_ctx->induction_dictionaries); + hcfree (induct_ctx->induction_dictionaries); induct_ctx_scan (hashcat_ctx); } @@ -433,30 +328,44 @@ static int inner1_loop (hashcat_ctx_t *hashcat_ctx) * loop through wordlists */ - restore_data_t *rd = restore_ctx->rd; + EVENT (EVENT_INNERLOOP2_STARTING); + + if (restore_ctx->rd) + { + restore_data_t *rd = restore_ctx->rd; + + if (rd->dicts_pos > 0) + { + straight_ctx->dicts_pos = rd->dicts_pos; + + rd->dicts_pos = 0; + } + } if (straight_ctx->dicts_cnt) { - for (u32 dicts_pos = rd->dicts_pos; dicts_pos < straight_ctx->dicts_cnt; dicts_pos++) + for (u32 dicts_pos = straight_ctx->dicts_pos; dicts_pos < straight_ctx->dicts_cnt; dicts_pos++) { - rd->dicts_pos = dicts_pos; - straight_ctx->dicts_pos = dicts_pos; const int rc_inner2_loop = inner2_loop (hashcat_ctx); - if (rc_inner2_loop == -1) return -1; + if (rc_inner2_loop == -1) myabort (hashcat_ctx); if (status_ctx->run_main_level3 == false) break; } + + if (straight_ctx->dicts_pos == straight_ctx->dicts_cnt) straight_ctx->dicts_pos = 0; } else { const int rc_inner2_loop = inner2_loop (hashcat_ctx); - if (rc_inner2_loop == -1) return -1; + if (rc_inner2_loop == -1) myabort (hashcat_ctx); } + EVENT (EVENT_INNERLOOP2_FINISHED); + return 0; } @@ -465,17 +374,14 @@ static int inner1_loop (hashcat_ctx_t *hashcat_ctx) static int outer_loop (hashcat_ctx_t *hashcat_ctx) { - bitmap_ctx_t *bitmap_ctx = hashcat_ctx->bitmap_ctx; - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - hashes_t *hashes = hashcat_ctx->hashes; - hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; - mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - outcheck_ctx_t *outcheck_ctx = hashcat_ctx->outcheck_ctx; - restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; - user_options_t *user_options = hashcat_ctx->user_options; + hashes_t *hashes = hashcat_ctx->hashes; + mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + outcheck_ctx_t *outcheck_ctx = hashcat_ctx->outcheck_ctx; + restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; + user_options_t *user_options = hashcat_ctx->user_options; status_ctx->devices_status = STATUS_INIT; @@ -499,19 +405,6 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) if (rc_hashconfig == -1) return -1; - /** - * potfile show/left depends on hash_mode, so it's called here first time - */ - - if (user_options->show == true || user_options->left == true) - { - outfile_write_open (hashcat_ctx); - - potfile_read_open (hashcat_ctx); - potfile_read_parse (hashcat_ctx); - potfile_read_close (hashcat_ctx); - } - /** * load hashes, stage 1 */ @@ -524,86 +417,108 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) { if (hashes->hashes_cnt == 0) { - log_error ("ERROR: No hashes loaded"); + event_log_error (hashcat_ctx, "No hashes loaded"); return -1; } } - /** - * potfile show/left final - */ - - if (user_options->show == true || user_options->left == true) - { - outfile_write_close (hashcat_ctx); - - potfile_hash_free (hashcat_ctx); - - return 0; - } - - /** - * Potfile removes - */ - - int potfile_remove_cracks = 0; - - if (user_options->potfile_disable == 0) - { - if (user_options->quiet == false) log_info_nn ("Comparing hashes with potfile entries..."); - - potfile_remove_cracks = potfile_remove_parse (hashcat_ctx); - } - /** * load hashes, stage 2, remove duplicates, build base structure */ - const u32 hashes_cnt_orig = hashes->hashes_cnt; + hashes->hashes_cnt_orig = hashes->hashes_cnt; const int rc_hashes_init_stage2 = hashes_init_stage2 (hashcat_ctx); if (rc_hashes_init_stage2 == -1) return -1; /** - * load hashes, stage 2: at this point we can check for all hashes cracked (by potfile) + * potfile removes */ - if (status_ctx->devices_status == STATUS_CRACKED) + if (user_options->potfile_disable == false) { - if (user_options->quiet == false) - { - log_info ("INFO: All hashes found in potfile! You can use --show to display them."); - log_info (""); - log_info ("INFO: No more hashes left to crack, exiting..."); - log_info (""); - } + EVENT (EVENT_POTFILE_REMOVE_PARSE_PRE); - hashes_destroy (hashcat_ctx); + potfile_remove_parse (hashcat_ctx); - hashconfig_destroy (hashcat_ctx); - - potfile_destroy (hashcat_ctx); - - return 0; + EVENT (EVENT_POTFILE_REMOVE_PARSE_POST); } /** - * load hashes, stage 3, automatic Optimizers + * load hashes, stage 3, update cracked results from potfile */ const int rc_hashes_init_stage3 = hashes_init_stage3 (hashcat_ctx); if (rc_hashes_init_stage3 == -1) return -1; + /** + * potfile show/left handling + */ + + if (user_options->show == true) + { + outfile_write_open (hashcat_ctx); + + const int rc = potfile_handle_show (hashcat_ctx); + + if (rc == -1) return -1; + + outfile_write_close (hashcat_ctx); + + return 0; + } + else if (user_options->left == true) + { + outfile_write_open (hashcat_ctx); + + const int rc = potfile_handle_left (hashcat_ctx); + + if (rc == -1) return -1; + + outfile_write_close (hashcat_ctx); + + return 0; + } + + /** + * maybe all hashes were cracked, we can exit here + */ + + if (status_ctx->devices_status == STATUS_CRACKED) + { + EVENT (EVENT_POTFILE_ALL_CRACKED); + + return 0; + } + + /** + * load hashes, stage 4, automatic Optimizers + */ + + const int rc_hashes_init_stage4 = hashes_init_stage4 (hashcat_ctx); + + if (rc_hashes_init_stage4 == -1) return -1; + + /** + * Done loading hashes, log results + */ + hashes_logger (hashcat_ctx); /** * bitmaps */ - bitmap_ctx_init (hashcat_ctx); + EVENT (EVENT_BITMAP_INIT_PRE); + + const int rc_bitmap_init = bitmap_ctx_init (hashcat_ctx); + + if (rc_bitmap_init == -1) return -1; + + EVENT (EVENT_BITMAP_INIT_POST); /** * cracks-per-time allocate buffer @@ -615,7 +530,9 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) * Wordlist allocate buffer */ - wl_data_init (hashcat_ctx); + const int rc_wl_data_init = wl_data_init (hashcat_ctx); + + if (rc_wl_data_init == -1) return -1; /** * straight mode init @@ -649,7 +566,7 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) { if ((mask_ctx->masks_cnt > 1) || (straight_ctx->dicts_cnt > 1)) { - log_error ("ERROR: --skip/--limit are not supported with --increment or mask files"); + event_log_error (hashcat_ctx, "--skip/--limit are not supported with --increment or mask files"); return -1; } @@ -663,7 +580,7 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) { if ((mask_ctx->masks_cnt > 1) || (straight_ctx->dicts_cnt > 1)) { - log_error ("ERROR: --keyspace is not supported with --increment or mask files"); + event_log_error (hashcat_ctx, "--keyspace is not supported with --increment or mask files"); return -1; } @@ -678,107 +595,22 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) if (rc_status_init == -1) return -1; /** - * enable custom signal handler(s) - * currently disabled, because man page says: - * The effects of signal() in a multithreaded process are unspecified. + * main screen */ - /* - if (user_options->benchmark == false) - { - hc_signal (sigHandler_default); - } - else - { - hc_signal (sigHandler_benchmark); - } - */ + EVENT (EVENT_OUTERLOOP_MAINSCREEN); /** * inform the user */ - if (user_options->quiet == false) - { - log_info ("Hashes: %u digests; %u unique digests, %u unique salts", hashes_cnt_orig, hashes->digests_cnt, hashes->salts_cnt); + EVENT (EVENT_OPENCL_SESSION_PRE); - log_info ("Bitmaps: %u bits, %u entries, 0x%08x mask, %u bytes, %u/%u rotates", bitmap_ctx->bitmap_bits, bitmap_ctx->bitmap_nums, bitmap_ctx->bitmap_mask, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_shift1, bitmap_ctx->bitmap_shift2); + const int rc_session_begin = opencl_session_begin (hashcat_ctx); - if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) - { - log_info ("Rules: %u", straight_ctx->kernel_rules_cnt); - } + if (rc_session_begin == -1) return -1; - if (user_options->quiet == false) log_info (""); - - if (hashconfig->opti_type) - { - log_info ("Applicable Optimizers:"); - - for (u32 i = 0; i < 32; i++) - { - const u32 opti_bit = 1u << i; - - if (hashconfig->opti_type & opti_bit) log_info ("* %s", stroptitype (opti_bit)); - } - } - - if (user_options->quiet == false) log_info (""); - - /** - * Watchdog and Temperature balance - */ - - if (hwmon_ctx->enabled == false && user_options->gpu_temp_disable == false) - { - log_info ("Watchdog: Hardware Monitoring Interface not found on your system"); - } - - if (hwmon_ctx->enabled == true && user_options->gpu_temp_abort > 0) - { - log_info ("Watchdog: Temperature abort trigger set to %uc", user_options->gpu_temp_abort); - } - else - { - log_info ("Watchdog: Temperature abort trigger disabled"); - } - - if (hwmon_ctx->enabled == true && user_options->gpu_temp_retain > 0) - { - log_info ("Watchdog: Temperature retain trigger set to %uc", user_options->gpu_temp_retain); - } - else - { - log_info ("Watchdog: Temperature retain trigger disabled"); - } - - if (user_options->quiet == false) log_info (""); - } - - #if defined (DEBUG) - if (user_options->benchmark == true) log_info ("Hashmode: %d", hashconfig->hash_mode); - #endif - - if (user_options->quiet == false) log_info_nn ("Initializing device kernels and memory..."); - - opencl_session_begin (hashcat_ctx); - - if (user_options->quiet == false) log_info_nn (""); - - /** - * In benchmark-mode, inform user which algorithm is checked - */ - - if (user_options->benchmark == true) - { - if (user_options->machine_readable == false) - { - char *hash_type = strhashtype (hashconfig->hash_mode); // not a bug - - log_info ("Hashtype: %s", hash_type); - log_info (""); - } - } + EVENT (EVENT_OPENCL_SESSION_POST); /** * weak hash check is the first to write to potfile, so open it for writing from here @@ -805,12 +637,16 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) break; } - if (user_options->quiet == false) log_info_nn ("Checking for weak hashes..."); + EVENT (EVENT_WEAK_HASH_PRE); for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) { - weak_hash_check (hashcat_ctx, device_param, salt_pos); + const int CL_rc = weak_hash_check (hashcat_ctx, device_param, salt_pos); + + if (CL_rc == -1) return -1; } + + EVENT (EVENT_WEAK_HASH_POST); } /** @@ -819,7 +655,7 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) int inner_threads_cnt = 0; - hc_thread_t *inner_threads = (hc_thread_t *) mycalloc (10, sizeof (hc_thread_t)); + hc_thread_t *inner_threads = (hc_thread_t *) hccalloc (hashcat_ctx, 10, sizeof (hc_thread_t)); VERIFY_PTR (inner_threads); status_ctx->shutdown_inner = false; @@ -827,7 +663,7 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) * Outfile remove */ - if (user_options->keyspace == false && user_options->benchmark == false && user_options->stdout_flag == false) + if (user_options->keyspace == false && user_options->benchmark == false && user_options->stdout_flag == false && user_options->speed_only == false) { hc_thread_create (inner_threads[inner_threads_cnt], thread_monitor, hashcat_ctx); @@ -845,52 +681,44 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) * Tell user about cracked hashes by potfile */ - if (user_options->quiet == false) - { - if (potfile_remove_cracks > 0) - { - if (potfile_remove_cracks == 1) - { - log_info ("INFO: Removed 1 hash found in potfile"); - log_info (""); - } - else - { - log_info ("INFO: Removed %d hashes found in potfile", potfile_remove_cracks); - log_info (""); - } - } - } + EVENT (EVENT_POTFILE_NUM_CRACKED); // main call - if (mask_ctx->masks_cnt) + if (restore_ctx->rd) { restore_data_t *rd = restore_ctx->rd; - for (u32 masks_pos = rd->masks_pos; masks_pos < mask_ctx->masks_cnt; masks_pos++) + if (rd->masks_pos > 0) { - if (masks_pos > rd->masks_pos) - { - rd->dicts_pos = 0; - } + mask_ctx->masks_pos = rd->masks_pos; - rd->masks_pos = masks_pos; + rd->masks_pos = 0; + } + } + EVENT (EVENT_INNERLOOP1_STARTING); + + if (mask_ctx->masks_cnt) + { + for (u32 masks_pos = mask_ctx->masks_pos; masks_pos < mask_ctx->masks_cnt; masks_pos++) + { mask_ctx->masks_pos = masks_pos; const int rc_inner1_loop = inner1_loop (hashcat_ctx); - if (rc_inner1_loop == -1) return -1; + if (rc_inner1_loop == -1) myabort (hashcat_ctx); if (status_ctx->run_main_level2 == false) break; } + + if (mask_ctx->masks_pos == mask_ctx->masks_cnt) mask_ctx->masks_pos = 0; } else { const int rc_inner1_loop = inner1_loop (hashcat_ctx); - if (rc_inner1_loop == -1) return -1; + if (rc_inner1_loop == -1) myabort (hashcat_ctx); } // wait for inner threads @@ -902,57 +730,118 @@ static int outer_loop (hashcat_ctx_t *hashcat_ctx) hc_thread_wait (1, &inner_threads[thread_idx]); } - myfree (inner_threads); + hcfree (inner_threads); + + EVENT (EVENT_INNERLOOP1_FINISHED); // finalize potfile potfile_write_close (hashcat_ctx); - // finalize session + // finalize opencl session opencl_session_destroy (hashcat_ctx); // clean up + bitmap_ctx_destroy (hashcat_ctx); + combinator_ctx_destroy (hashcat_ctx); + cpt_ctx_destroy (hashcat_ctx); + hashconfig_destroy (hashcat_ctx); + hashes_destroy (hashcat_ctx); + mask_ctx_destroy (hashcat_ctx); status_progress_destroy (hashcat_ctx); - - bitmap_ctx_destroy (hashcat_ctx); - - mask_ctx_destroy (hashcat_ctx); - - combinator_ctx_destroy (hashcat_ctx); - - straight_ctx_destroy (hashcat_ctx); - - hashes_destroy (hashcat_ctx); - - hashconfig_destroy (hashcat_ctx); - - wl_data_destroy (hashcat_ctx); - - cpt_ctx_destroy (hashcat_ctx); + straight_ctx_destroy (hashcat_ctx); + wl_data_destroy (hashcat_ctx); return 0; } -int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_folder, int argc, char **argv, const int comptime) +int hashcat_init (hashcat_ctx_t *hashcat_ctx, void (*event) (const u32, struct hashcat_ctx *, const void *, const size_t)) { - /** - * To help users a bit - */ + if (event == NULL) + { + fprintf (stderr, "Event callback function is mandatory\n"); - setup_environment_variables (); + return -1; + } - setup_umask (); + hashcat_ctx->event = event; + + hashcat_ctx->bitmap_ctx = (bitmap_ctx_t *) hcmalloc (hashcat_ctx, sizeof (bitmap_ctx_t)); VERIFY_PTR (hashcat_ctx->bitmap_ctx); + hashcat_ctx->combinator_ctx = (combinator_ctx_t *) hcmalloc (hashcat_ctx, sizeof (combinator_ctx_t)); VERIFY_PTR (hashcat_ctx->combinator_ctx); + hashcat_ctx->cpt_ctx = (cpt_ctx_t *) hcmalloc (hashcat_ctx, sizeof (cpt_ctx_t)); VERIFY_PTR (hashcat_ctx->cpt_ctx); + hashcat_ctx->debugfile_ctx = (debugfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (debugfile_ctx_t)); VERIFY_PTR (hashcat_ctx->debugfile_ctx); + hashcat_ctx->dictstat_ctx = (dictstat_ctx_t *) hcmalloc (hashcat_ctx, sizeof (dictstat_ctx_t)); VERIFY_PTR (hashcat_ctx->dictstat_ctx); + hashcat_ctx->event_ctx = (event_ctx_t *) hcmalloc (hashcat_ctx, sizeof (event_ctx_t)); VERIFY_PTR (hashcat_ctx->event_ctx); + hashcat_ctx->folder_config = (folder_config_t *) hcmalloc (hashcat_ctx, sizeof (folder_config_t)); VERIFY_PTR (hashcat_ctx->folder_config); + hashcat_ctx->hashcat_user = (hashcat_user_t *) hcmalloc (hashcat_ctx, sizeof (hashcat_user_t)); VERIFY_PTR (hashcat_ctx->hashcat_user); + hashcat_ctx->hashconfig = (hashconfig_t *) hcmalloc (hashcat_ctx, sizeof (hashconfig_t)); VERIFY_PTR (hashcat_ctx->hashconfig); + hashcat_ctx->hashes = (hashes_t *) hcmalloc (hashcat_ctx, sizeof (hashes_t)); VERIFY_PTR (hashcat_ctx->hashes); + hashcat_ctx->hwmon_ctx = (hwmon_ctx_t *) hcmalloc (hashcat_ctx, sizeof (hwmon_ctx_t)); VERIFY_PTR (hashcat_ctx->hwmon_ctx); + hashcat_ctx->induct_ctx = (induct_ctx_t *) hcmalloc (hashcat_ctx, sizeof (induct_ctx_t)); VERIFY_PTR (hashcat_ctx->induct_ctx); + hashcat_ctx->logfile_ctx = (logfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (logfile_ctx_t)); VERIFY_PTR (hashcat_ctx->logfile_ctx); + hashcat_ctx->loopback_ctx = (loopback_ctx_t *) hcmalloc (hashcat_ctx, sizeof (loopback_ctx_t)); VERIFY_PTR (hashcat_ctx->loopback_ctx); + hashcat_ctx->mask_ctx = (mask_ctx_t *) hcmalloc (hashcat_ctx, sizeof (mask_ctx_t)); VERIFY_PTR (hashcat_ctx->mask_ctx); + hashcat_ctx->opencl_ctx = (opencl_ctx_t *) hcmalloc (hashcat_ctx, sizeof (opencl_ctx_t)); VERIFY_PTR (hashcat_ctx->opencl_ctx); + hashcat_ctx->outcheck_ctx = (outcheck_ctx_t *) hcmalloc (hashcat_ctx, sizeof (outcheck_ctx_t)); VERIFY_PTR (hashcat_ctx->outcheck_ctx); + hashcat_ctx->outfile_ctx = (outfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (outfile_ctx_t)); VERIFY_PTR (hashcat_ctx->outfile_ctx); + hashcat_ctx->potfile_ctx = (potfile_ctx_t *) hcmalloc (hashcat_ctx, sizeof (potfile_ctx_t)); VERIFY_PTR (hashcat_ctx->potfile_ctx); + hashcat_ctx->restore_ctx = (restore_ctx_t *) hcmalloc (hashcat_ctx, sizeof (restore_ctx_t)); VERIFY_PTR (hashcat_ctx->restore_ctx); + hashcat_ctx->status_ctx = (status_ctx_t *) hcmalloc (hashcat_ctx, sizeof (status_ctx_t)); VERIFY_PTR (hashcat_ctx->status_ctx); + hashcat_ctx->straight_ctx = (straight_ctx_t *) hcmalloc (hashcat_ctx, sizeof (straight_ctx_t)); VERIFY_PTR (hashcat_ctx->straight_ctx); + hashcat_ctx->tuning_db = (tuning_db_t *) hcmalloc (hashcat_ctx, sizeof (tuning_db_t)); VERIFY_PTR (hashcat_ctx->tuning_db); + hashcat_ctx->user_options_extra = (user_options_extra_t *) hcmalloc (hashcat_ctx, sizeof (user_options_extra_t)); VERIFY_PTR (hashcat_ctx->user_options_extra); + hashcat_ctx->user_options = (user_options_t *) hcmalloc (hashcat_ctx, sizeof (user_options_t)); VERIFY_PTR (hashcat_ctx->user_options); + hashcat_ctx->wl_data = (wl_data_t *) hcmalloc (hashcat_ctx, sizeof (wl_data_t)); VERIFY_PTR (hashcat_ctx->wl_data); + + return 0; +} + +void hashcat_destroy (hashcat_ctx_t *hashcat_ctx) +{ + hcfree (hashcat_ctx->bitmap_ctx); + hcfree (hashcat_ctx->combinator_ctx); + hcfree (hashcat_ctx->cpt_ctx); + hcfree (hashcat_ctx->debugfile_ctx); + hcfree (hashcat_ctx->dictstat_ctx); + hcfree (hashcat_ctx->event_ctx); + hcfree (hashcat_ctx->folder_config); + hcfree (hashcat_ctx->hashconfig); + hcfree (hashcat_ctx->hashes); + hcfree (hashcat_ctx->hwmon_ctx); + hcfree (hashcat_ctx->induct_ctx); + hcfree (hashcat_ctx->logfile_ctx); + hcfree (hashcat_ctx->loopback_ctx); + hcfree (hashcat_ctx->mask_ctx); + hcfree (hashcat_ctx->opencl_ctx); + hcfree (hashcat_ctx->outcheck_ctx); + hcfree (hashcat_ctx->outfile_ctx); + hcfree (hashcat_ctx->potfile_ctx); + hcfree (hashcat_ctx->restore_ctx); + hcfree (hashcat_ctx->status_ctx); + hcfree (hashcat_ctx->straight_ctx); + hcfree (hashcat_ctx->tuning_db); + hcfree (hashcat_ctx->user_options_extra); + hcfree (hashcat_ctx->user_options); + hcfree (hashcat_ctx->wl_data); + + memset (hashcat_ctx, 0, sizeof (hashcat_ctx_t)); +} + +int hashcat_session_run (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_folder, int argc, char **argv, const int comptime) +{ + logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + user_options_t *user_options = hashcat_ctx->user_options; /** - * main init + * event init (needed for logging so should be first) */ - logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; - user_options_t *user_options = hashcat_ctx->user_options; + const int rc_event_init = event_ctx_init (hashcat_ctx); + + if (rc_event_init == -1) return -1; /** * status init @@ -962,6 +851,8 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold if (rc_status_init == -1) return -1; + EVENT (EVENT_WELCOME_SCREEN); + /** * folder */ @@ -987,13 +878,7 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold user_options_extra_init (hashcat_ctx); /** - * prepare seeding for random number generator, required by logfile and rules generator - */ - - setup_seeding (user_options->rp_gen_seed_chgd, user_options->rp_gen_seed); - - /** - * logfile init + * logfile */ const int rc_logfile_init = logfile_init (hashcat_ctx); @@ -1004,8 +889,32 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold logfile_top_msg ("START"); + // add all user options to logfile in case we want to debug some user session + user_options_logger (hashcat_ctx); + /** + * cpu affinity + */ + + const int rc_affinity = set_cpu_affinity (hashcat_ctx); + + if (rc_affinity == -1) return -1; + + /** + * prepare seeding for random number generator, required by logfile and rules generator + */ + + setup_seeding (user_options->rp_gen_seed_chgd, user_options->rp_gen_seed); + + /** + * To help users a bit + */ + + setup_environment_variables (); + + setup_umask (); + /** * tuning db */ @@ -1055,6 +964,7 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold const int rc_potfile_init = potfile_init (hashcat_ctx); if (rc_potfile_init == -1) return -1; + /** * dictstat init */ @@ -1081,15 +991,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold if (rc_debugfile_init == -1) return -1; - /** - * cpu affinity - */ - - if (user_options->cpu_affinity) - { - set_cpu_affinity (user_options->cpu_affinity); - } - /** * Init OpenCL library loader */ @@ -1105,6 +1006,7 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold const int rc_devices_init = opencl_ctx_devices_init (hashcat_ctx, comptime); if (rc_devices_init == -1) return -1; + /** * HM devices: init */ @@ -1113,39 +1015,23 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold if (rc_hwmon_init == -1) return -1; - /** - * keypress thread - */ - - int outer_threads_cnt = 0; - - hc_thread_t *outer_threads = (hc_thread_t *) mycalloc (10, sizeof (hc_thread_t)); - - status_ctx->shutdown_outer = false; - - if (user_options->keyspace == false && user_options->benchmark == false && user_options->stdout_flag == false) - { - if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) - { - hc_thread_create (outer_threads[outer_threads_cnt], thread_keypress, hashcat_ctx); - - outer_threads_cnt++; - } - } - /** * outer loop */ + EVENT (EVENT_OUTERLOOP_STARTING); + + int rc_final = -1; + if (user_options->benchmark == true) { user_options->quiet = true; if (user_options->hash_mode_chgd == true) { - const int rc = outer_loop (hashcat_ctx); + rc_final = outer_loop (hashcat_ctx); - if (rc == -1) return -1; + if (rc_final == -1) myabort (hashcat_ctx); } else { @@ -1153,36 +1039,28 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold { user_options->hash_mode = DEFAULT_BENCHMARK_ALGORITHMS_BUF[algorithm_pos]; - const int rc = outer_loop (hashcat_ctx); + rc_final = outer_loop (hashcat_ctx); - if (rc == -1) return -1; + if (rc_final == -1) myabort (hashcat_ctx); if (status_ctx->run_main_level1 == false) break; } } + + user_options->quiet = false; } else { - const int rc = outer_loop (hashcat_ctx); + if (user_options->speed_only == true) user_options->quiet = true; - if (rc == -1) return -1; + rc_final = outer_loop (hashcat_ctx); + + if (rc_final == -1) myabort (hashcat_ctx); + + if (user_options->speed_only == true) user_options->quiet = false; } - // wait for outer threads - - status_ctx->shutdown_outer = true; - - for (int thread_idx = 0; thread_idx < outer_threads_cnt; thread_idx++) - { - hc_thread_wait (1, &outer_threads[thread_idx]); - } - - myfree (outer_threads); - - if (user_options->benchmark == true) - { - user_options->quiet = false; - } + EVENT (EVENT_OUTERLOOP_FINISHED); // if exhausted or cracked, unlink the restore file @@ -1192,33 +1070,7 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold dictstat_write (hashcat_ctx); - // free memory - - debugfile_destroy (hashcat_ctx); - - tuning_db_destroy (hashcat_ctx); - - loopback_destroy (hashcat_ctx); - - dictstat_destroy (hashcat_ctx); - - potfile_destroy (hashcat_ctx); - - induct_ctx_destroy (hashcat_ctx); - - outfile_destroy (hashcat_ctx); - - outcheck_ctx_destroy (hashcat_ctx); - - folder_config_destroy (hashcat_ctx); - - hwmon_ctx_destroy (hashcat_ctx); - - opencl_ctx_devices_destroy (hashcat_ctx); - - opencl_ctx_destroy (hashcat_ctx); - - restore_ctx_destroy (hashcat_ctx); + // final logfile entry time (&status_ctx->proc_stop); @@ -1227,20 +1079,171 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold logfile_top_msg ("STOP"); - logfile_destroy (hashcat_ctx); + // free memory + EVENT (EVENT_GOODBYE_SCREEN); + + debugfile_destroy (hashcat_ctx); + dictstat_destroy (hashcat_ctx); + folder_config_destroy (hashcat_ctx); + hwmon_ctx_destroy (hashcat_ctx); + induct_ctx_destroy (hashcat_ctx); + logfile_destroy (hashcat_ctx); + loopback_destroy (hashcat_ctx); + opencl_ctx_destroy (hashcat_ctx); + opencl_ctx_devices_destroy (hashcat_ctx); + outcheck_ctx_destroy (hashcat_ctx); + outfile_destroy (hashcat_ctx); + potfile_destroy (hashcat_ctx); + restore_ctx_destroy (hashcat_ctx); + tuning_db_destroy (hashcat_ctx); + user_options_destroy (hashcat_ctx); user_options_extra_destroy (hashcat_ctx); - user_options_destroy (hashcat_ctx); + if (rc_final == 0) + { + if (status_ctx->devices_status == STATUS_ABORTED) rc_final = 2; + if (status_ctx->devices_status == STATUS_QUIT) rc_final = 2; + if (status_ctx->devices_status == STATUS_EXHAUSTED) rc_final = 1; + if (status_ctx->devices_status == STATUS_CRACKED) rc_final = 0; + } - int rc_final = -1; + // do not clear status and event so we can access them from main.c after hashcat_session_run() finishes + //status_ctx_destroy (hashcat_ctx); + //event_ctx_destroy (hashcat_ctx); - if (status_ctx->devices_status == STATUS_ABORTED) rc_final = 2; - if (status_ctx->devices_status == STATUS_QUIT) rc_final = 2; - if (status_ctx->devices_status == STATUS_EXHAUSTED) rc_final = 1; - if (status_ctx->devices_status == STATUS_CRACKED) rc_final = 0; - - status_ctx_destroy (hashcat_ctx); + // done return rc_final; } + +int hashcat_session_pause (hashcat_ctx_t *hashcat_ctx) +{ + return SuspendThreads (hashcat_ctx); +} + +int hashcat_session_resume (hashcat_ctx_t *hashcat_ctx) +{ + return ResumeThreads (hashcat_ctx); +} + +int hashcat_session_bypass (hashcat_ctx_t *hashcat_ctx) +{ + return bypass (hashcat_ctx); +} + +int hashcat_session_checkpoint (hashcat_ctx_t *hashcat_ctx) +{ + return stop_at_checkpoint (hashcat_ctx); +} + +int hashcat_session_quit (hashcat_ctx_t *hashcat_ctx) +{ + return myabort (hashcat_ctx); +} + +char *hashcat_get_log (hashcat_ctx_t *hashcat_ctx) +{ + event_ctx_t *event_ctx = hashcat_ctx->event_ctx; + + return event_ctx->msg_buf; +} + +int hashcat_get_status (hashcat_ctx_t *hashcat_ctx, hashcat_status_t *hashcat_status) +{ + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + if (status_ctx->devices_status == STATUS_INIT) + { + event_log_error (hashcat_ctx, "Status view is not available during initialization phase"); + + return -1; + } + + if (status_ctx->devices_status == STATUS_AUTOTUNE) + { + event_log_error (hashcat_ctx, "Status view is not available during autotune phase"); + + return -1; + } + + if (status_ctx->shutdown_inner == true) + { + // in this case some required buffers are free'd, ascii_digest() would run into segfault + + event_log_error (hashcat_ctx, "Status view is not available during shutdown phase"); + + return -1; + } + + memset (hashcat_status, 0, sizeof (hashcat_status_t)); + + hashcat_status->digests_cnt = status_get_digests_cnt (hashcat_ctx); + hashcat_status->digests_done = status_get_digests_done (hashcat_ctx); + hashcat_status->digests_percent = status_get_digests_percent (hashcat_ctx); + hashcat_status->hash_target = status_get_hash_target (hashcat_ctx); + hashcat_status->hash_type = status_get_hash_type (hashcat_ctx); + hashcat_status->input_base = status_get_input_base (hashcat_ctx); + hashcat_status->input_charset = status_get_input_charset (hashcat_ctx); + hashcat_status->input_mode = status_get_input_mode (hashcat_ctx); + hashcat_status->input_mod = status_get_input_mod (hashcat_ctx); + hashcat_status->msec_paused = status_get_msec_paused (hashcat_ctx); + hashcat_status->msec_running = status_get_msec_running (hashcat_ctx); + hashcat_status->msec_real = status_get_msec_real (hashcat_ctx); + hashcat_status->progress_mode = status_get_progress_mode (hashcat_ctx); + hashcat_status->progress_finished_percent = status_get_progress_finished_percent (hashcat_ctx); + hashcat_status->progress_cur_relative_skip = status_get_progress_cur_relative_skip (hashcat_ctx); + hashcat_status->progress_cur = status_get_progress_cur (hashcat_ctx); + hashcat_status->progress_done = status_get_progress_done (hashcat_ctx); + hashcat_status->progress_end_relative_skip = status_get_progress_end_relative_skip (hashcat_ctx); + hashcat_status->progress_end = status_get_progress_end (hashcat_ctx); + hashcat_status->progress_ignore = status_get_progress_ignore (hashcat_ctx); + hashcat_status->progress_rejected = status_get_progress_rejected (hashcat_ctx); + hashcat_status->progress_rejected_percent = status_get_progress_rejected_percent (hashcat_ctx); + hashcat_status->progress_restored = status_get_progress_restored (hashcat_ctx); + hashcat_status->progress_skip = status_get_progress_skip (hashcat_ctx); + hashcat_status->restore_point = status_get_restore_point (hashcat_ctx); + hashcat_status->restore_total = status_get_restore_total (hashcat_ctx); + hashcat_status->restore_percent = status_get_restore_percent (hashcat_ctx); + hashcat_status->salts_cnt = status_get_salts_cnt (hashcat_ctx); + hashcat_status->salts_done = status_get_salts_done (hashcat_ctx); + hashcat_status->salts_percent = status_get_salts_percent (hashcat_ctx); + hashcat_status->session = status_get_session (hashcat_ctx); + hashcat_status->status_string = status_get_status_string (hashcat_ctx); + hashcat_status->status_number = status_get_status_number (hashcat_ctx); + hashcat_status->time_estimated_absolute = status_get_time_estimated_absolute (hashcat_ctx); + hashcat_status->time_estimated_relative = status_get_time_estimated_relative (hashcat_ctx); + hashcat_status->time_started_absolute = status_get_time_started_absolute (hashcat_ctx); + hashcat_status->time_started_relative = status_get_time_started_relative (hashcat_ctx); + hashcat_status->cpt_cur_min = status_get_cpt_cur_min (hashcat_ctx); + hashcat_status->cpt_cur_hour = status_get_cpt_cur_hour (hashcat_ctx); + hashcat_status->cpt_cur_day = status_get_cpt_cur_day (hashcat_ctx); + hashcat_status->cpt_avg_min = status_get_cpt_avg_min (hashcat_ctx); + hashcat_status->cpt_avg_hour = status_get_cpt_avg_hour (hashcat_ctx); + hashcat_status->cpt_avg_day = status_get_cpt_avg_day (hashcat_ctx); + hashcat_status->cpt = status_get_cpt (hashcat_ctx); + + // multiple devices + + hashcat_status->device_info_cnt = status_get_device_info_cnt (hashcat_ctx); + hashcat_status->device_info_active = status_get_device_info_active (hashcat_ctx); + + for (int device_id = 0; device_id < hashcat_status->device_info_cnt; device_id++) + { + device_info_t *device_info = hashcat_status->device_info_buf + device_id; + + device_info->skipped_dev = status_get_skipped_dev (hashcat_ctx, device_id); + device_info->hashes_msec_dev = status_get_hashes_msec_dev (hashcat_ctx, device_id); + device_info->hashes_msec_dev_benchmark = status_get_hashes_msec_dev_benchmark (hashcat_ctx, device_id); + device_info->exec_msec_dev = status_get_exec_msec_dev (hashcat_ctx, device_id); + device_info->speed_sec_dev = status_get_speed_sec_dev (hashcat_ctx, device_id); + device_info->input_candidates_dev = status_get_input_candidates_dev (hashcat_ctx, device_id); + device_info->hwmon_dev = status_get_hwmon_dev (hashcat_ctx, device_id); + } + + hashcat_status->hashes_msec_all = status_get_hashes_msec_all (hashcat_ctx); + hashcat_status->exec_msec_all = status_get_exec_msec_all (hashcat_ctx); + hashcat_status->speed_sec_all = status_get_speed_sec_all (hashcat_ctx); + + return 0; +} diff --git a/src/hashes.c b/src/hashes.c index 8a8531353..3ff91e0de 100644 --- a/src/hashes.c +++ b/src/hashes.c @@ -6,7 +6,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "hashes.h" #include "debugfile.h" @@ -21,7 +21,6 @@ #include "potfile.h" #include "rp.h" #include "rp_kernel_on_cpu.h" -#include "terminal.h" #include "thread.h" #include "timer.h" @@ -117,7 +116,7 @@ int sort_by_hash_no_salt (const void *v1, const void *v2, void *v3) return sort_by_digest_p0p1 (d1, d2, v3); } -void save_hash (hashcat_ctx_t *hashcat_ctx) +int save_hash (hashcat_ctx_t *hashcat_ctx) { hashes_t *hashes = hashcat_ctx->hashes; hashconfig_t *hashconfig = hashcat_ctx->hashconfig; @@ -139,9 +138,9 @@ void save_hash (hashcat_ctx_t *hashcat_ctx) if (fp == NULL) { - log_error ("ERROR: %s: %s", new_hashfile, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", new_hashfile, strerror (errno)); - exit (-1); + return -1; } for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) @@ -158,7 +157,7 @@ void save_hash (hashcat_ctx_t *hashcat_ctx) if (hashconfig->hash_mode != 2500) { - if (user_options->username == 1) + if (user_options->username == true) { user_t *user = hashes->hash_info[idx]->user; @@ -173,7 +172,7 @@ void save_hash (hashcat_ctx_t *hashcat_ctx) out_buf[0] = 0; - ascii_digest (out_buf, salt_pos, digest_pos, hashconfig, hashes); + ascii_digest (hashcat_ctx, out_buf, salt_pos, digest_pos); fputs (out_buf, fp); @@ -183,7 +182,7 @@ void save_hash (hashcat_ctx_t *hashcat_ctx) { hccap_t hccap; - to_hccap_t (&hccap, salt_pos, digest_pos, hashconfig, hashes); + to_hccap_t (hashcat_ctx, &hccap, salt_pos, digest_pos); fwrite (&hccap, sizeof (hccap_t), 1, fp); } @@ -198,42 +197,40 @@ void save_hash (hashcat_ctx_t *hashcat_ctx) if (rename (hashfile, old_hashfile) != 0) { - log_error ("ERROR: Rename file '%s' to '%s': %s", hashfile, old_hashfile, strerror (errno)); + event_log_error (hashcat_ctx, "Rename file '%s' to '%s': %s", hashfile, old_hashfile, strerror (errno)); - exit (-1); + return -1; } unlink (hashfile); if (rename (new_hashfile, hashfile) != 0) { - log_error ("ERROR: Rename file '%s' to '%s': %s", new_hashfile, hashfile, strerror (errno)); + event_log_error (hashcat_ctx, "Rename file '%s' to '%s': %s", new_hashfile, hashfile, strerror (errno)); - exit (-1); + return -1; } unlink (old_hashfile); + + return 0; } void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain) { - debugfile_ctx_t *debugfile_ctx = hashcat_ctx->debugfile_ctx; - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - hashes_t *hashes = hashcat_ctx->hashes; - loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx; - outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - user_options_t *user_options = hashcat_ctx->user_options; - user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + debugfile_ctx_t *debugfile_ctx = hashcat_ctx->debugfile_ctx; + loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx; const u32 salt_pos = plain->salt_pos; const u32 digest_pos = plain->digest_pos; // relative // hash - char out_buf[HCBUFSIZ_LARGE] = { 0 }; + char out_buf[HCBUFSIZ_LARGE]; - ascii_digest (out_buf, salt_pos, digest_pos, hashconfig, hashes); + out_buf[0] = 0; + + ascii_digest (hashcat_ctx, out_buf, salt_pos, digest_pos); // plain @@ -270,23 +267,16 @@ void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, pl outfile_write_open (hashcat_ctx); - if (outfile_ctx->filename == NULL) if (user_options->quiet == false) clear_prompt (); + char tmp_buf[HCBUFSIZ_LARGE]; - outfile_write (hashcat_ctx, out_buf, plain_ptr, plain_len, crackpos, NULL, 0); + const int tmp_len = outfile_write (hashcat_ctx, out_buf, plain_ptr, plain_len, crackpos, NULL, 0, tmp_buf); outfile_write_close (hashcat_ctx); - if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) - { - if ((status_ctx->devices_status != STATUS_CRACKED) && (user_options->status != true)) - { - if (outfile_ctx->filename == NULL) if (user_options->quiet == false) send_prompt (); - } - } + EVENT_DATA (EVENT_CRACKER_HASH_CRACKED, tmp_buf, tmp_len); // if enabled, update also the loopback file - if (loopback_ctx->fp != NULL) { loopback_write_append (hashcat_ctx, plain_ptr, plain_len); @@ -309,11 +299,10 @@ void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, pl int check_cracked (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 salt_pos) { - cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - hashes_t *hashes = hashcat_ctx->hashes; - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; + hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + hashes_t *hashes = hashcat_ctx->hashes; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; salt_t *salt_buf = &hashes->salts_buf[salt_pos]; @@ -321,11 +310,11 @@ int check_cracked (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, cl_int CL_err; - CL_err = hc_clEnqueueReadBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_result, CL_TRUE, 0, sizeof (u32), &num_cracked, 0, NULL, NULL); + CL_err = hc_clEnqueueReadBuffer (hashcat_ctx, device_param->command_queue, device_param->d_result, CL_TRUE, 0, sizeof (u32), &num_cracked, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { - log_error ("ERROR: clEnqueueReadBuffer(): %s\n", val2cstr_cl (CL_err)); + event_log_error (hashcat_ctx, "clEnqueueReadBuffer(): %s", val2cstr_cl (CL_err)); return -1; } @@ -334,15 +323,15 @@ int check_cracked (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, { // display hack (for weak hashes etc, it could be that there is still something to clear on the current line) - log_info_nn (""); + event_log_info_nn (hashcat_ctx, ""); - plain_t *cracked = (plain_t *) mycalloc (num_cracked, sizeof (plain_t)); + plain_t *cracked = (plain_t *) hccalloc (hashcat_ctx, num_cracked, sizeof (plain_t)); VERIFY_PTR (cracked); - CL_err = hc_clEnqueueReadBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_plain_bufs, CL_TRUE, 0, num_cracked * sizeof (plain_t), cracked, 0, NULL, NULL); + CL_err = hc_clEnqueueReadBuffer (hashcat_ctx, device_param->command_queue, device_param->d_plain_bufs, CL_TRUE, 0, num_cracked * sizeof (plain_t), cracked, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { - log_error ("ERROR: clEnqueueReadBuffer(): %s\n", val2cstr_cl (CL_err)); + event_log_error (hashcat_ctx, "clEnqueueReadBuffer(): %s", val2cstr_cl (CL_err)); return -1; } @@ -375,14 +364,14 @@ int check_cracked (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, } } - if (hashes->salts_done == hashes->salts_cnt) mycracked (status_ctx); + if (hashes->salts_done == hashes->salts_cnt) mycracked (hashcat_ctx); check_hash (hashcat_ctx, device_param, &cracked[i]); } hc_thread_mutex_unlock (status_ctx->mux_display); - myfree (cracked); + hcfree (cracked); if (cpt_cracked > 0) { @@ -408,11 +397,11 @@ int check_cracked (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, memset (hashes->digests_shown_tmp, 0, salt_buf->digests_cnt * sizeof (u32)); - CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_digests_shown, CL_TRUE, salt_buf->digests_offset * sizeof (u32), salt_buf->digests_cnt * sizeof (u32), &hashes->digests_shown_tmp[salt_buf->digests_offset], 0, NULL, NULL); + CL_err = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_digests_shown, CL_TRUE, salt_buf->digests_offset * sizeof (u32), salt_buf->digests_cnt * sizeof (u32), &hashes->digests_shown_tmp[salt_buf->digests_offset], 0, NULL, NULL); if (CL_err != CL_SUCCESS) { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); + event_log_error (hashcat_ctx, "clEnqueueWriteBuffer(): %s", val2cstr_cl (CL_err)); return -1; } @@ -420,11 +409,11 @@ int check_cracked (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, num_cracked = 0; - CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_result, CL_TRUE, 0, sizeof (u32), &num_cracked, 0, NULL, NULL); + CL_err = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_result, CL_TRUE, 0, sizeof (u32), &num_cracked, 0, NULL, NULL); if (CL_err != CL_SUCCESS) { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); + event_log_error (hashcat_ctx, "clEnqueueWriteBuffer(): %s", val2cstr_cl (CL_err)); return -1; } @@ -478,7 +467,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) if (stat (hashes->hashfile, &st) == -1) { - log_error ("ERROR: %s: %s", hashes->hashfile, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", hashes->hashfile, strerror (errno)); return -1; } @@ -500,20 +489,20 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) if ((fp = fopen (hashfile, "rb")) == NULL) { - log_error ("ERROR: %s: %s", hashfile, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", hashfile, strerror (errno)); return -1; } - if (user_options->quiet == false) log_info_nn ("Counting lines in %s", hashfile); + if (user_options->quiet == false) event_log_info_nn (hashcat_ctx, "Counting lines in %s", hashfile); - hashes_avail = count_lines (fp); + hashes_avail = count_lines (hashcat_ctx, fp); rewind (fp); if (hashes_avail == 0) { - log_error ("ERROR: hashfile is empty or corrupt"); + event_log_error (hashcat_ctx, "hashfile is empty or corrupt"); fclose (fp); @@ -524,7 +513,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) if ((user_options->remove == 1) && (hashlist_format != HLFMT_HASHCAT)) { - log_error ("ERROR: remove not supported in native hashfile-format mode"); + event_log_error (hashcat_ctx, "remove not supported in native hashfile-format mode"); fclose (fp); @@ -555,44 +544,44 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) salt_t *salts_buf = NULL; void *esalts_buf = NULL; - hashes_buf = (hash_t *) mycalloc (hashes_avail, sizeof (hash_t)); + hashes_buf = (hash_t *) hccalloc (hashcat_ctx, hashes_avail, sizeof (hash_t)); VERIFY_PTR (hashes_buf); - digests_buf = (void *) mycalloc (hashes_avail, hashconfig->dgst_size); + digests_buf = (void *) hccalloc (hashcat_ctx, hashes_avail, hashconfig->dgst_size); VERIFY_PTR (digests_buf); - if ((user_options->username && (user_options->remove || user_options->show)) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) + if ((user_options->username == true) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) { u32 hash_pos; for (hash_pos = 0; hash_pos < hashes_avail; hash_pos++) { - hashinfo_t *hash_info = (hashinfo_t *) mymalloc (sizeof (hashinfo_t)); + hashinfo_t *hash_info = (hashinfo_t *) hcmalloc (hashcat_ctx, sizeof (hashinfo_t)); VERIFY_PTR (hash_info); hashes_buf[hash_pos].hash_info = hash_info; - if (user_options->username && (user_options->remove || user_options->show || user_options->left)) + if (user_options->username == true) { - hash_info->user = (user_t*) mymalloc (sizeof (user_t)); + hash_info->user = (user_t*) hcmalloc (hashcat_ctx, sizeof (user_t)); VERIFY_PTR (hash_info->user); } - if (user_options->benchmark) + if (user_options->benchmark == true) { - hash_info->orighash = (char *) mymalloc (256); + hash_info->orighash = (char *) hcmalloc (hashcat_ctx, 256); VERIFY_PTR (hash_info->orighash); } } } if (hashconfig->is_salted) { - salts_buf = (salt_t *) mycalloc (hashes_avail, sizeof (salt_t)); + salts_buf = (salt_t *) hccalloc (hashcat_ctx, hashes_avail, sizeof (salt_t)); VERIFY_PTR (salts_buf); if (hashconfig->esalt_size) { - esalts_buf = (void *) mycalloc (hashes_avail, hashconfig->esalt_size); + esalts_buf = (void *) hccalloc (hashcat_ctx, hashes_avail, hashconfig->esalt_size); VERIFY_PTR (esalts_buf); } } else { - salts_buf = (salt_t *) mycalloc (1, sizeof (salt_t)); + salts_buf = (salt_t *) hccalloc (hashcat_ctx, 1, sizeof (salt_t)); VERIFY_PTR (salts_buf); } for (u32 hash_pos = 0; hash_pos < hashes_avail; hash_pos++) @@ -666,7 +655,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) if (hash_fmt_error) { - log_info ("WARNING: Failed to parse hashes using the '%s' format", strhlfmt (hashlist_format)); + event_log_warning (hashcat_ctx, "Failed to parse hashes using the '%s' format", strhlfmt (hashlist_format)); } else { @@ -674,7 +663,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) { hashinfo_t *hash_info_tmp = hashes_buf[hashes_cnt].hash_info; - hash_info_tmp->orighash = mystrdup (hash_buf); + hash_info_tmp->orighash = hcstrdup (hashcat_ctx, hash_buf); } if (hashconfig->is_salted) @@ -688,7 +677,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) { if (hash_len == 0) { - log_error ("ERROR: hccap file not specified"); + event_log_error (hashcat_ctx, "hccap file not specified"); return -1; } @@ -701,14 +690,14 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) if (fp == NULL) { - log_error ("ERROR: %s: %s", hash_buf, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", hash_buf, strerror (errno)); return -1; } if (hashes_avail < 1) { - log_error ("ERROR: hccap file is empty or corrupt"); + event_log_error (hashcat_ctx, "hccap file is empty or corrupt"); fclose (fp); @@ -717,7 +706,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) u32 hccap_size = sizeof (hccap_t); - char *in = (char *) mymalloc (hccap_size); + char *in = (char *) hcmalloc (hashcat_ctx, hccap_size); VERIFY_PTR (in); while (!feof (fp)) { @@ -734,61 +723,17 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) if (parser_status != PARSER_OK) { - log_info ("WARNING: Hash '%s': %s", hash_buf, strparser (parser_status)); + event_log_warning (hashcat_ctx, "Hash '%s': %s", hash_buf, strparser (parser_status)); continue; } - // hack: append MAC1 and MAC2 s.t. in --show and --left the line matches with the .pot file format (i.e. ESSID:MAC1:MAC2) - - if ((user_options->show == true) || (user_options->left == true)) - { - salt_t *tmp_salt = hashes_buf[hashes_cnt].salt; - - char *salt_ptr = (char *) tmp_salt->salt_buf; - - int cur_pos = tmp_salt->salt_len; - int rem_len = sizeof (hashes_buf[hashes_cnt].salt->salt_buf) - cur_pos; - - wpa_t *wpa = (wpa_t *) hashes_buf[hashes_cnt].esalt; - - // do the appending task - - snprintf (salt_ptr + cur_pos, - rem_len, - ":%02x%02x%02x%02x%02x%02x:%02x%02x%02x%02x%02x%02x", - 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]); - - // memset () the remaining part of the salt - - cur_pos = tmp_salt->salt_len + 1 + 12 + 1 + 12; - rem_len = sizeof (hashes_buf[hashes_cnt].salt->salt_buf) - cur_pos; - - if (rem_len > 0) memset (salt_ptr + cur_pos, 0, rem_len); - - tmp_salt->salt_len += 1 + 12 + 1 + 12; - } - - if (user_options->show == true) potfile_show_request (hashcat_ctx, (char *) hashes_buf[hashes_cnt].salt->salt_buf, hashes_buf[hashes_cnt].salt->salt_len, &hashes_buf[hashes_cnt], sort_by_salt_buf); - if (user_options->left == true) potfile_left_request (hashcat_ctx, (char *) hashes_buf[hashes_cnt].salt->salt_buf, hashes_buf[hashes_cnt].salt->salt_len, &hashes_buf[hashes_cnt], sort_by_salt_buf); - hashes_cnt++; } fclose (fp); - myfree (in); + hcfree (in); } else if (hashconfig->hash_mode == 3000) { @@ -796,59 +741,37 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) { parser_status = hashconfig->parse_func (hash_buf, 16, &hashes_buf[hashes_cnt], hashconfig); - hash_t *lm_hash_left = NULL; - if (parser_status == PARSER_OK) { - lm_hash_left = &hashes_buf[hashes_cnt]; - hashes_cnt++; } else { - log_info ("WARNING: Hash '%s': %s", input_buf, strparser (parser_status)); + event_log_warning (hashcat_ctx, "Hash '%s': %s", input_buf, strparser (parser_status)); } parser_status = hashconfig->parse_func (hash_buf + 16, 16, &hashes_buf[hashes_cnt], hashconfig); - hash_t *lm_hash_right = NULL; - if (parser_status == PARSER_OK) { - lm_hash_right = &hashes_buf[hashes_cnt]; - hashes_cnt++; } else { - log_info ("WARNING: Hash '%s': %s", input_buf, strparser (parser_status)); - } - - // show / left - - if ((lm_hash_left != NULL) && (lm_hash_right != NULL)) - { - if (user_options->show == true) potfile_show_request_lm (hashcat_ctx, input_buf, input_len, lm_hash_left, lm_hash_right, sort_by_pot); - if (user_options->left == true) potfile_left_request_lm (hashcat_ctx, input_buf, input_len, lm_hash_left, lm_hash_right, sort_by_pot); + event_log_warning (hashcat_ctx, "Hash '%s': %s", input_buf, strparser (parser_status)); } } else { parser_status = hashconfig->parse_func (hash_buf, hash_len, &hashes_buf[hashes_cnt], hashconfig); - if (parser_status == PARSER_OK) - { - if (user_options->show == true) potfile_show_request (hashcat_ctx, input_buf, input_len, &hashes_buf[hashes_cnt], sort_by_pot); - if (user_options->left == true) potfile_left_request (hashcat_ctx, input_buf, input_len, &hashes_buf[hashes_cnt], sort_by_pot); - } - if (parser_status == PARSER_OK) { hashes_cnt++; } else { - log_info ("WARNING: Hash '%s': %s", input_buf, strparser (parser_status)); + event_log_warning (hashcat_ctx, "Hash '%s': %s", input_buf, strparser (parser_status)); } } } @@ -856,19 +779,13 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) { parser_status = hashconfig->parse_func (hash_buf, hash_len, &hashes_buf[hashes_cnt], hashconfig); - if (parser_status == PARSER_OK) - { - if (user_options->show == true) potfile_show_request (hashcat_ctx, input_buf, input_len, &hashes_buf[hashes_cnt], sort_by_pot); - if (user_options->left == true) potfile_left_request (hashcat_ctx, input_buf, input_len, &hashes_buf[hashes_cnt], sort_by_pot); - } - if (parser_status == PARSER_OK) { hashes_cnt++; } else { - log_info ("WARNING: Hash '%s': %s", input_buf, strparser (parser_status)); + event_log_warning (hashcat_ctx, "Hash '%s': %s", input_buf, strparser (parser_status)); } } } @@ -881,14 +798,14 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) if ((fp = fopen (hashfile, "rb")) == NULL) { - log_error ("ERROR: %s: %s", hashfile, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", hashfile, strerror (errno)); return -1; } u32 line_num = 0; - char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE); + char *line_buf = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (line_buf); while (!feof (fp)) { @@ -910,44 +827,41 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) if (hash_fmt_error) { - log_info ("WARNING: failed to parse hashes using the '%s' format", strhlfmt (hashlist_format)); + event_log_warning (hashcat_ctx, "failed to parse hashes using the '%s' format", strhlfmt (hashlist_format)); continue; } - if (user_options->username) + if (user_options->username == true) { char *user_buf = NULL; int user_len = 0; hlfmt_user (hashcat_ctx, hashlist_format, line_buf, line_len, &user_buf, &user_len); - if (user_options->remove || user_options->show) + user_t **user = &hashes_buf[hashes_cnt].hash_info->user; + + *user = (user_t *) hcmalloc (hashcat_ctx, sizeof (user_t)); VERIFY_PTR (*user); + + user_t *user_ptr = *user; + + if (user_buf != NULL) { - user_t **user = &hashes_buf[hashes_cnt].hash_info->user; - - *user = (user_t *) mymalloc (sizeof (user_t)); - - user_t *user_ptr = *user; - - if (user_buf != NULL) - { - user_ptr->user_name = mystrdup (user_buf); - } - else - { - user_ptr->user_name = mystrdup (""); - } - - user_ptr->user_len = user_len; + user_ptr->user_name = hcstrdup (hashcat_ctx, user_buf); } + else + { + user_ptr->user_name = hcstrdup (hashcat_ctx, ""); + } + + user_ptr->user_len = user_len; } if (hashconfig->opts_type & OPTS_TYPE_HASH_COPY) { hashinfo_t *hash_info_tmp = hashes_buf[hashes_cnt].hash_info; - hash_info_tmp->orighash = mystrdup (hash_buf); + hash_info_tmp->orighash = hcstrdup (hashcat_ctx, hash_buf); } if (hashconfig->is_salted) @@ -963,34 +877,25 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) if (parser_status < PARSER_GLOBAL_ZERO) { - log_info ("WARNING: Hashfile '%s' on line %u (%s): %s", hashes->hashfile, line_num, line_buf, strparser (parser_status)); + event_log_warning (hashcat_ctx, "Hashfile '%s' on line %u (%s): %s", hashes->hashfile, line_num, line_buf, strparser (parser_status)); continue; } - hash_t *lm_hash_left = &hashes_buf[hashes_cnt]; - hashes_cnt++; parser_status = hashconfig->parse_func (hash_buf + 16, 16, &hashes_buf[hashes_cnt], hashconfig); if (parser_status < PARSER_GLOBAL_ZERO) { - log_info ("WARNING: Hashfile '%s' on line %u (%s): %s", hashes->hashfile, line_num, line_buf, strparser (parser_status)); + event_log_warning (hashcat_ctx, "Hashfile '%s' on line %u (%s): %s", hashes->hashfile, line_num, line_buf, strparser (parser_status)); continue; } - hash_t *lm_hash_right = &hashes_buf[hashes_cnt]; - - if (user_options->quiet == false) if ((hashes_cnt % 0x20000) == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((double) hashes_cnt / hashes_avail) * 100); + if (user_options->quiet == false) if ((hashes_cnt % 0x20000) == 0) event_log_info_nn (hashcat_ctx, "Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((double) hashes_cnt / hashes_avail) * 100); hashes_cnt++; - - // show / left - - if (user_options->show == true) potfile_show_request_lm (hashcat_ctx, line_buf, line_len, lm_hash_left, lm_hash_right, sort_by_pot); - if (user_options->left == true) potfile_left_request_lm (hashcat_ctx, line_buf, line_len, lm_hash_left, lm_hash_right, sort_by_pot); } else { @@ -998,15 +903,12 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) if (parser_status < PARSER_GLOBAL_ZERO) { - log_info ("WARNING: Hashfile '%s' on line %u (%s): %s", hashes->hashfile, line_num, line_buf, strparser (parser_status)); + event_log_warning (hashcat_ctx, "Hashfile '%s' on line %u (%s): %s", hashes->hashfile, line_num, line_buf, strparser (parser_status)); continue; } - if (user_options->quiet == false) if ((hashes_cnt % 0x20000) == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((double) hashes_cnt / hashes_avail) * 100); - - if (user_options->show == true) potfile_show_request (hashcat_ctx, line_buf, line_len, &hashes_buf[hashes_cnt], sort_by_pot); - if (user_options->left == true) potfile_left_request (hashcat_ctx, line_buf, line_len, &hashes_buf[hashes_cnt], sort_by_pot); + if (user_options->quiet == false) if ((hashes_cnt % 0x20000) == 0) event_log_info_nn (hashcat_ctx, "Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((double) hashes_cnt / hashes_avail) * 100); hashes_cnt++; } @@ -1017,25 +919,22 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) if (parser_status < PARSER_GLOBAL_ZERO) { - log_info ("WARNING: Hashfile '%s' on line %u (%s): %s", hashes->hashfile, line_num, line_buf, strparser (parser_status)); + event_log_warning (hashcat_ctx, "Hashfile '%s' on line %u (%s): %s", hashes->hashfile, line_num, line_buf, strparser (parser_status)); continue; } - if (user_options->quiet == false) if ((hashes_cnt % 0x20000) == 0) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((double) hashes_cnt / hashes_avail) * 100); - - if (user_options->show == true) potfile_show_request (hashcat_ctx, line_buf, line_len, &hashes_buf[hashes_cnt], sort_by_pot); - if (user_options->left == true) potfile_left_request (hashcat_ctx, line_buf, line_len, &hashes_buf[hashes_cnt], sort_by_pot); + if (user_options->quiet == false) if ((hashes_cnt % 0x20000) == 0) event_log_info_nn (hashcat_ctx, "Parsed Hashes: %u/%u (%0.2f%%)", hashes_cnt, hashes_avail, ((double) hashes_cnt / hashes_avail) * 100); hashes_cnt++; } } - myfree (line_buf); + hcfree (line_buf); fclose (fp); - if (user_options->quiet == false) log_info_nn ("Parsed Hashes: %u/%u (%0.2f%%)", hashes_avail, hashes_avail, 100.00); + if (user_options->quiet == false) event_log_info_nn (hashcat_ctx, "Parsed Hashes: %u/%u (%0.2f%%)", hashes_avail, hashes_avail, 100.00); } } @@ -1043,7 +942,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) if (hashes_cnt) { - if (user_options->quiet == false) log_info_nn ("Sorting Hashes..."); + if (user_options->quiet == false) event_log_info_nn (hashcat_ctx, "Sorting Hashes..."); if (hashconfig->is_salted) { @@ -1053,6 +952,8 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) { hc_qsort_r (hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash_no_salt, (void *) hashconfig); } + + if (user_options->quiet == false) event_log_info_nn (hashcat_ctx, "Sorted Hashes..."); } return 0; @@ -1062,7 +963,6 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx) { hashconfig_t *hashconfig = hashcat_ctx->hashconfig; hashes_t *hashes = hashcat_ctx->hashes; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; user_options_t *user_options = hashcat_ctx->user_options; hash_t *hashes_buf = hashes->hashes_buf; @@ -1072,11 +972,11 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx) * Remove duplicates */ - if (user_options->quiet == false) log_info_nn ("Removing duplicate hashes..."); + if (user_options->quiet == false) event_log_info_nn (hashcat_ctx, "Removing duplicate hashes..."); - hashes_cnt = 1; + u32 hashes_cnt_new = 1; - for (u32 hashes_pos = 1; hashes_pos < hashes->hashes_cnt; hashes_pos++) + for (u32 hashes_pos = 1; hashes_pos < hashes_cnt; hashes_pos++) { if (hashconfig->is_salted) { @@ -1090,69 +990,77 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx) if (sort_by_digest_p0p1 (hashes_buf[hashes_pos].digest, hashes_buf[hashes_pos - 1].digest, (void *) hashconfig) == 0) continue; } - if (hashes_pos > hashes_cnt) - { - memcpy (&hashes_buf[hashes_cnt], &hashes_buf[hashes_pos], sizeof (hash_t)); - } + hash_t tmp; - hashes_cnt++; + memcpy (&tmp, &hashes_buf[hashes_pos], sizeof (hash_t)); + + memcpy (&hashes_buf[hashes_cnt_new], &tmp, sizeof (hash_t)); + + hashes_cnt_new++; } + for (u32 i = hashes_cnt_new; i < hashes->hashes_cnt; i++) + { + memset (&hashes_buf[i], 0, sizeof (hash_t)); + } + + hashes_cnt = hashes_cnt_new; + hashes->hashes_cnt = hashes_cnt; /** * Now generate all the buffers required for later */ - void *digests_buf_new = (void *) mycalloc (hashes_cnt, hashconfig->dgst_size); + void *digests_buf_new = (void *) hccalloc (hashcat_ctx, hashes_cnt, hashconfig->dgst_size); VERIFY_PTR (digests_buf_new); salt_t *salts_buf_new = NULL; void *esalts_buf_new = NULL; if (hashconfig->is_salted) { - salts_buf_new = (salt_t *) mycalloc (hashes_cnt, sizeof (salt_t)); + salts_buf_new = (salt_t *) hccalloc (hashcat_ctx, hashes_cnt, sizeof (salt_t)); VERIFY_PTR (salts_buf_new); if (hashconfig->esalt_size) { - esalts_buf_new = (void *) mycalloc (hashes_cnt, hashconfig->esalt_size); + esalts_buf_new = (void *) hccalloc (hashcat_ctx, hashes_cnt, hashconfig->esalt_size); VERIFY_PTR (esalts_buf_new); } } else { - salts_buf_new = (salt_t *) mycalloc (1, sizeof (salt_t)); + salts_buf_new = (salt_t *) hccalloc (hashcat_ctx, 1, sizeof (salt_t)); VERIFY_PTR (salts_buf_new); } - if (user_options->quiet == false) log_info_nn ("Structuring salts for cracking task..."); + if (user_options->quiet == false) event_log_info_nn (hashcat_ctx, "Structuring salts for cracking task..."); u32 digests_cnt = hashes_cnt; u32 digests_done = 0; - u32 *digests_shown = (u32 *) mycalloc (digests_cnt, sizeof (u32)); - u32 *digests_shown_tmp = (u32 *) mycalloc (digests_cnt, sizeof (u32)); + u32 *digests_shown = (u32 *) hccalloc (hashcat_ctx, digests_cnt, sizeof (u32)); VERIFY_PTR (digests_shown); + u32 *digests_shown_tmp = (u32 *) hccalloc (hashcat_ctx, digests_cnt, sizeof (u32)); VERIFY_PTR (digests_shown_tmp); u32 salts_cnt = 0; u32 salts_done = 0; hashinfo_t **hash_info = NULL; - if ((user_options->username && (user_options->remove || user_options->show)) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) + if ((user_options->username == true) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) { - hash_info = (hashinfo_t **) mycalloc (hashes_cnt, sizeof (hashinfo_t *)); + hash_info = (hashinfo_t **) hccalloc (hashcat_ctx, hashes_cnt, sizeof (hashinfo_t *)); VERIFY_PTR (hash_info); - if (user_options->username && (user_options->remove || user_options->show)) + if (user_options->username == true) { u32 user_pos; for (user_pos = 0; user_pos < hashes_cnt; user_pos++) { - hash_info[user_pos] = (hashinfo_t *) mycalloc (hashes_cnt, sizeof (hashinfo_t)); + hash_info[user_pos] = (hashinfo_t *) hcmalloc (hashcat_ctx, sizeof (hashinfo_t)); VERIFY_PTR (hash_info[user_pos]); - hash_info[user_pos]->user = (user_t *) mymalloc (sizeof (user_t)); + hash_info[user_pos]->user = (user_t *) hcmalloc (hashcat_ctx, sizeof (user_t)); VERIFY_PTR (hash_info[user_pos]->user); } } } - u32 *salts_shown = (u32 *) mycalloc (digests_cnt, sizeof (u32)); + u32 *salts_shown = (u32 *) hccalloc (hashcat_ctx, digests_cnt, sizeof (u32)); VERIFY_PTR (salts_shown); salt_t *salt_buf; @@ -1163,9 +1071,15 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx) memcpy (salt_buf, hashes_buf[0].salt, sizeof (salt_t)); + hashes_buf[0].salt = salt_buf; + if (hashconfig->esalt_size) { - memcpy (((char *) esalts_buf_new) + (salts_cnt * hashconfig->esalt_size), hashes_buf[0].esalt, hashconfig->esalt_size); + char *esalts_buf_new_ptr = ((char *) esalts_buf_new) + (salts_cnt * hashconfig->esalt_size); + + memcpy (esalts_buf_new_ptr, hashes_buf[0].esalt, hashconfig->esalt_size); + + hashes_buf[0].esalt = esalts_buf_new_ptr; } salt_buf->digests_cnt = 0; @@ -1175,20 +1089,15 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx) salts_cnt++; } - if (hashes_buf[0].cracked == 1) - { - digests_shown[0] = 1; - - digests_done++; - - salt_buf->digests_done++; - } - salt_buf->digests_cnt++; - memcpy (((char *) digests_buf_new) + (0 * hashconfig->dgst_size), hashes_buf[0].digest, hashconfig->dgst_size); + char *digests_buf_new_ptr = ((char *) digests_buf_new) + (0 * hashconfig->dgst_size); - if ((user_options->username && (user_options->remove || user_options->show)) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) + memcpy (digests_buf_new_ptr, hashes_buf[0].digest, hashconfig->dgst_size); + + hashes_buf[0].digest = digests_buf_new_ptr; + + if ((user_options->username == true) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) { hash_info[0] = hashes_buf[0].hash_info; } @@ -1205,9 +1114,15 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx) memcpy (salt_buf, hashes_buf[hashes_pos].salt, sizeof (salt_t)); + hashes_buf[hashes_pos].salt = salt_buf; + if (hashconfig->esalt_size) { - memcpy (((char *) esalts_buf_new) + (salts_cnt * hashconfig->esalt_size), hashes_buf[hashes_pos].esalt, hashconfig->esalt_size); + char *esalts_buf_new_ptr = ((char *) esalts_buf_new) + (salts_cnt * hashconfig->esalt_size); + + memcpy (esalts_buf_new_ptr, hashes_buf[hashes_pos].esalt, hashconfig->esalt_size); + + hashes_buf[hashes_pos].esalt = esalts_buf_new_ptr; } salt_buf->digests_cnt = 0; @@ -1218,43 +1133,23 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx) } } - if (hashes_buf[hashes_pos].cracked == 1) - { - digests_shown[hashes_pos] = 1; - - digests_done++; - - salt_buf->digests_done++; - } - salt_buf->digests_cnt++; - memcpy (((char *) digests_buf_new) + (hashes_pos * hashconfig->dgst_size), hashes_buf[hashes_pos].digest, hashconfig->dgst_size); + digests_buf_new_ptr = ((char *) digests_buf_new) + (hashes_pos * hashconfig->dgst_size); - if ((user_options->username && (user_options->remove || user_options->show)) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) + memcpy (digests_buf_new_ptr, hashes_buf[hashes_pos].digest, hashconfig->dgst_size); + + hashes_buf[hashes_pos].digest = digests_buf_new_ptr; + + if ((user_options->username == true) || (hashconfig->opts_type & OPTS_TYPE_HASH_COPY)) { hash_info[hashes_pos] = hashes_buf[hashes_pos].hash_info; } } - for (u32 salt_pos = 0; salt_pos < salts_cnt; salt_pos++) - { - salt_t *salt_buf = &salts_buf_new[salt_pos]; - - if (salt_buf->digests_done == salt_buf->digests_cnt) - { - salts_shown[salt_pos] = 1; - - salts_done++; - } - - if (salts_done == salts_cnt) mycracked (status_ctx); - } - - myfree (hashes->digests_buf); - myfree (hashes->salts_buf); - myfree (hashes->esalts_buf); - myfree (hashes->hashes_buf); + hcfree (hashes->digests_buf); + hcfree (hashes->salts_buf); + hcfree (hashes->esalts_buf); hashes->digests_cnt = digests_cnt; hashes->digests_done = digests_done; @@ -1269,21 +1164,73 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx) hashes->esalts_buf = esalts_buf_new; - hashes->hashes_cnt = 0; - hashes->hashes_buf = NULL; - hashes->hash_info = hash_info; return 0; } int hashes_init_stage3 (hashcat_ctx_t *hashcat_ctx) +{ + hashes_t *hashes = hashcat_ctx->hashes; + + u32 digests_done = hashes->digests_done; + u32 *digests_shown = hashes->digests_shown; + + u32 salts_cnt = hashes->salts_cnt; + u32 salts_done = hashes->salts_done; + u32 *salts_shown = hashes->salts_shown; + + hash_t *hashes_buf = hashes->hashes_buf; + + salt_t *salts_buf = hashes->salts_buf; + + for (u32 salt_idx = 0; salt_idx < salts_cnt; salt_idx++) + { + salt_t *salt_buf = salts_buf + salt_idx; + + u32 digests_cnt = salt_buf->digests_cnt; + + for (u32 digest_idx = 0; digest_idx < digests_cnt; digest_idx++) + { + const u32 hashes_idx = salt_buf->digests_offset + digest_idx; + + if (hashes_buf[hashes_idx].cracked == 1) + { + digests_shown[hashes_idx] = 1; + + digests_done++; + + salt_buf->digests_done++; + } + } + + if (salt_buf->digests_done == salt_buf->digests_cnt) + { + salts_shown[salt_idx] = 1; + + salts_done++; + } + + if (salts_done == salts_cnt) mycracked (hashcat_ctx); + } + + hashes->digests_done = digests_done; + + hashes->salts_cnt = salts_cnt; + hashes->salts_done = salts_done; + + return 0; +} + +int hashes_init_stage4 (hashcat_ctx_t *hashcat_ctx) { hashconfig_t *hashconfig = hashcat_ctx->hashconfig; hashes_t *hashes = hashcat_ctx->hashes; user_options_t *user_options = hashcat_ctx->user_options; - hashconfig_general_defaults (hashcat_ctx); + const int rc_defaults = hashconfig_general_defaults (hashcat_ctx); + + if (rc_defaults == -1) return -1; if (hashes->salts_cnt == 1) hashconfig->opti_type |= OPTI_TYPE_SINGLE_SALT; @@ -1324,6 +1271,15 @@ int hashes_init_stage3 (hashcat_ctx_t *hashcat_ctx) } } + // at this point we no longer need hash_t* structure + + hash_t *hashes_buf = hashes->hashes_buf; + + hcfree (hashes_buf); + + hashes->hashes_cnt = 0; + hashes->hashes_buf = NULL; + return 0; } @@ -1331,16 +1287,16 @@ void hashes_destroy (hashcat_ctx_t *hashcat_ctx) { hashes_t *hashes = hashcat_ctx->hashes; - myfree (hashes->digests_buf); - myfree (hashes->digests_shown); - myfree (hashes->digests_shown_tmp); + hcfree (hashes->digests_buf); + hcfree (hashes->digests_shown); + hcfree (hashes->digests_shown_tmp); - myfree (hashes->salts_buf); - myfree (hashes->salts_shown); + hcfree (hashes->salts_buf); + hcfree (hashes->salts_shown); - myfree (hashes->esalts_buf); + hcfree (hashes->esalts_buf); - myfree (hashes->hash_info); + hcfree (hashes->hash_info); memset (hashes, 0, sizeof (hashes_t)); } diff --git a/src/hlfmt.c b/src/hlfmt.c index c1a026b0e..835092eda 100644 --- a/src/hlfmt.c +++ b/src/hlfmt.c @@ -22,7 +22,7 @@ static const char HLFMT_TEXT_NSLDAPS[] = "nsldaps"; // hlfmt hashcat -static void hlfmt_hash_hashcat (hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len) +static void hlfmt_hash_hashcat (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len) { const user_options_t *user_options = hashcat_ctx->user_options; const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; @@ -54,7 +54,7 @@ static void hlfmt_hash_hashcat (hashcat_ctx_t *hashcat_ctx, char *line_buf, int } } -static void hlfmt_user_hashcat (hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len) +static void hlfmt_user_hashcat (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len) { const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; @@ -86,10 +86,8 @@ static void hlfmt_user_hashcat (hashcat_ctx_t *hashcat_ctx, char *line_buf, int // hlfmt pwdump -static int hlfmt_detect_pwdump (hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len) +static int hlfmt_detect_pwdump (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len) { - if (hashcat_ctx == NULL) hashcat_ctx = NULL; // makes GCC happy - int sep_cnt = 0; int sep2_len = 0; @@ -113,7 +111,7 @@ static int hlfmt_detect_pwdump (hashcat_ctx_t *hashcat_ctx, char *line_buf, int return 0; } -static void hlfmt_hash_pwdump (hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len) +static void hlfmt_hash_pwdump (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len) { const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; @@ -155,10 +153,8 @@ static void hlfmt_hash_pwdump (hashcat_ctx_t *hashcat_ctx, char *line_buf, int l *hashbuf_len = len; } -static void hlfmt_user_pwdump (hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len) +static void hlfmt_user_pwdump (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len) { - if (hashcat_ctx == NULL) hashcat_ctx = NULL; // makes GCC happy - char *pos = NULL; int len = 0; @@ -187,10 +183,8 @@ static void hlfmt_user_pwdump (hashcat_ctx_t *hashcat_ctx, char *line_buf, int l // hlfmt passwd -static int hlfmt_detect_passwd (hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len) +static int hlfmt_detect_passwd (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len) { - if (hashcat_ctx == NULL) hashcat_ctx = NULL; // makes GCC happy - int sep_cnt = 0; char sep5_first = 0; @@ -214,10 +208,8 @@ static int hlfmt_detect_passwd (hashcat_ctx_t *hashcat_ctx, char *line_buf, int return 0; } -static void hlfmt_hash_passwd (hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len) +static void hlfmt_hash_passwd (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len) { - if (hashcat_ctx == NULL) hashcat_ctx = NULL; // makes GCC happy - char *pos = NULL; int len = 0; @@ -244,10 +236,8 @@ static void hlfmt_hash_passwd (hashcat_ctx_t *hashcat_ctx, char *line_buf, int l *hashbuf_len = len; } -static void hlfmt_user_passwd (hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len) +static void hlfmt_user_passwd (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len) { - if (hashcat_ctx == NULL) hashcat_ctx = NULL; // makes GCC happy - char *pos = NULL; int len = 0; @@ -276,10 +266,8 @@ static void hlfmt_user_passwd (hashcat_ctx_t *hashcat_ctx, char *line_buf, int l // hlfmt shadow -static int hlfmt_detect_shadow (hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len) +static int hlfmt_detect_shadow (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len) { - if (hashcat_ctx == NULL) hashcat_ctx = NULL; // makes GCC happy - int sep_cnt = 0; for (int i = 0; i < line_len; i++) @@ -292,12 +280,12 @@ static int hlfmt_detect_shadow (hashcat_ctx_t *hashcat_ctx, char *line_buf, int return 0; } -static void hlfmt_hash_shadow (hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len) +static void hlfmt_hash_shadow (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len) { hlfmt_hash_passwd (hashcat_ctx, line_buf, line_len, hashbuf_pos, hashbuf_len); } -static void hlfmt_user_shadow (hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len) +static void hlfmt_user_shadow (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len) { hlfmt_user_passwd (hashcat_ctx, line_buf, line_len, userbuf_pos, userbuf_len); } @@ -354,11 +342,11 @@ u32 hlfmt_detect (hashcat_ctx_t *hashcat_ctx, FILE *fp, u32 max_check) if (hashconfig->hash_mode == 5300) return HLFMT_HASHCAT; if (hashconfig->hash_mode == 5400) return HLFMT_HASHCAT; - u32 *formats_cnt = (u32 *) mycalloc (HLFMTS_CNT, sizeof (u32)); + u32 *formats_cnt = (u32 *) hccalloc (hashcat_ctx, HLFMTS_CNT, sizeof (u32)); VERIFY_PTR (formats_cnt); u32 num_check = 0; - char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE); + char *line_buf = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (line_buf); while (!feof (fp)) { @@ -375,7 +363,7 @@ u32 hlfmt_detect (hashcat_ctx_t *hashcat_ctx, FILE *fp, u32 max_check) num_check++; } - myfree (line_buf); + hcfree (line_buf); u32 hashlist_format = HLFMT_HASHCAT; diff --git a/src/hwmon.c b/src/hwmon.c index e0fc636d1..e53ea223f 100644 --- a/src/hwmon.c +++ b/src/hwmon.c @@ -6,16 +6,134 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" +#include "dynloader.h" #include "hwmon.h" -static int get_adapters_num_adl (ADL_PTR *adl, int *iNumberAdapters) -{ - if (hm_ADL_Adapter_NumberOfAdapters_Get (adl, iNumberAdapters) != ADL_OK) return -1; +// nvml functions - if (iNumberAdapters == 0) +static int nvml_init (hashcat_ctx_t *hashcat_ctx) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + memset (nvml, 0, sizeof (NVML_PTR)); + + #if defined (_WIN) + nvml->lib = hc_dlopen ("nvml.dll"); + + if (!nvml->lib) { - log_info ("WARN: No ADL adapters found."); + DWORD BufferSize = 1024; + + DWORD Type = REG_SZ; + + char *Buffer = (char *) hcmalloc (hashcat_ctx, BufferSize + 1); VERIFY_PTR (Buffer); + + HKEY hKey = 0; + + if (RegOpenKeyExA (HKEY_LOCAL_MACHINE, "SOFTWARE\\NVIDIA Corporation\\Global\\NVSMI", 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) + { + if (RegQueryValueExA (hKey, "NVSMIPATH", NULL, &Type, (LPBYTE)Buffer, &BufferSize) == ERROR_SUCCESS) + { + Buffer[BufferSize] = 0; + } + else + { + //if (user_options->quiet == false) + // event_log_error (hashcat_ctx, "NVML library load failed, proceed without NVML HWMon enabled"); + + return -1; + } + + RegCloseKey (hKey); + } + else + { + //if (user_options->quiet == false) + // event_log_error (hashcat_ctx, "NVML library load failed, proceed without NVML HWMon enabled"); + + return -1; + } + + strcat (Buffer, "\\nvml.dll"); + + nvml->lib = hc_dlopen (Buffer); + + hcfree (Buffer); + } + + #elif defined (_POSIX) + nvml->lib = hc_dlopen ("libnvidia-ml.so", RTLD_NOW); + #endif + + if (!nvml->lib) + { + //if (user_options->quiet == false) + // event_log_error (hashcat_ctx, "NVML library load failed, proceed without NVML HWMon enabled"); + + return -1; + } + + HC_LOAD_FUNC(nvml, nvmlErrorString, NVML_ERROR_STRING, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlInit, NVML_INIT, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlShutdown, NVML_SHUTDOWN, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceGetCount, NVML_DEVICE_GET_COUNT, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceGetName, NVML_DEVICE_GET_NAME, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceGetHandleByIndex, NVML_DEVICE_GET_HANDLE_BY_INDEX, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceGetTemperature, NVML_DEVICE_GET_TEMPERATURE, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceGetFanSpeed, NVML_DEVICE_GET_FAN_SPEED, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceGetPowerUsage, NVML_DEVICE_GET_POWER_USAGE, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceGetUtilizationRates, NVML_DEVICE_GET_UTILIZATION_RATES, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceGetClockInfo, NVML_DEVICE_GET_CLOCKINFO, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceGetTemperatureThreshold, NVML_DEVICE_GET_THRESHOLD, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceGetCurrPcieLinkGeneration, NVML_DEVICE_GET_CURRPCIELINKGENERATION, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceGetCurrPcieLinkWidth, NVML_DEVICE_GET_CURRPCIELINKWIDTH, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceGetCurrentClocksThrottleReasons, NVML_DEVICE_GET_CURRENTCLOCKSTHROTTLEREASONS, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceGetSupportedClocksThrottleReasons, NVML_DEVICE_GET_SUPPORTEDCLOCKSTHROTTLEREASONS, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceSetComputeMode, NVML_DEVICE_SET_COMPUTEMODE, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceSetGpuOperationMode, NVML_DEVICE_SET_OPERATIONMODE, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceGetPowerManagementLimitConstraints, NVML_DEVICE_GET_POWERMANAGEMENTLIMITCONSTRAINTS, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceSetPowerManagementLimit, NVML_DEVICE_SET_POWERMANAGEMENTLIMIT, NVML, 0) + HC_LOAD_FUNC(nvml, nvmlDeviceGetPowerManagementLimit, NVML_DEVICE_GET_POWERMANAGEMENTLIMIT, NVML, 0) + + return 0; +} + +static void nvml_close (hashcat_ctx_t *hashcat_ctx) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + if (nvml) + { + if (nvml->lib) + hc_dlclose (nvml->lib); + + hcfree (nvml); + } +} + +static const char *hm_NVML_nvmlErrorString (NVML_PTR *nvml, const nvmlReturn_t nvml_rc) +{ + return nvml->nvmlErrorString (nvml_rc); +} + +static int hm_NVML_nvmlInit (hashcat_ctx_t *hashcat_ctx) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlInit (); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlInit(): %s", string); return -1; } @@ -23,26 +141,1740 @@ static int get_adapters_num_adl (ADL_PTR *adl, int *iNumberAdapters) return 0; } -static LPAdapterInfo hm_get_adapter_info_adl (ADL_PTR *adl, int iNumberAdapters) +static int hm_NVML_nvmlShutdown (hashcat_ctx_t *hashcat_ctx) { - size_t AdapterInfoSize = iNumberAdapters * sizeof (AdapterInfo); + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; - LPAdapterInfo lpAdapterInfo = (LPAdapterInfo) mymalloc (AdapterInfoSize); + NVML_PTR *nvml = hwmon_ctx->hm_nvml; - if (hm_ADL_Adapter_AdapterInfo_Get (adl, lpAdapterInfo, AdapterInfoSize) != ADL_OK) return NULL; + const nvmlReturn_t nvml_rc = nvml->nvmlShutdown (); - return lpAdapterInfo; + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlShutdown(): %s", string); + + return -1; + } + + return 0; } -static int hm_get_adapter_index_nvapi (const hwmon_ctx_t *hwmon_ctx, HM_ADAPTER_NVAPI *nvapiGPUHandle) +static int hm_NVML_nvmlDeviceGetCount (hashcat_ctx_t *hashcat_ctx, unsigned int *deviceCount) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetCount (deviceCount); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceGetCount(): %s", string); + + return -1; + } + + return 0; +} + +static int hm_NVML_nvmlDeviceGetHandleByIndex (hashcat_ctx_t *hashcat_ctx, unsigned int index, nvmlDevice_t *device) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetHandleByIndex (index, device); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceGetHandleByIndex(): %s", string); + + return -1; + } + + return 0; +} + +/* +static int hm_NVML_nvmlDeviceGetName (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, char *name, unsigned int length) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetName (device, name, length); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceGetName(): %s", string); + + return -1; + } + + return 0; +} +*/ + +static int hm_NVML_nvmlDeviceGetTemperature (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int *temp) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetTemperature (device, sensorType, temp); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceGetTemperature(): %s", string); + + return -1; + } + + return 0; +} + +static int hm_NVML_nvmlDeviceGetFanSpeed (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned int *speed) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetFanSpeed (device, speed); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceGetFanSpeed(): %s", string); + + return -1; + } + + return 0; +} + +/* +static int hm_NVML_nvmlDeviceGetPowerUsage (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned int *power) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetPowerUsage (device, power); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceGetPowerUsage(): %s", string); + + return -1; + } + + return 0; +} +*/ + +static int hm_NVML_nvmlDeviceGetUtilizationRates (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, nvmlUtilization_t *utilization) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetUtilizationRates (device, utilization); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceGetUtilizationRates(): %s", string); + + return -1; + } + + return 0; +} + +static int hm_NVML_nvmlDeviceGetClockInfo (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, nvmlClockType_t type, unsigned int *clock) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetClockInfo (device, type, clock); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceGetClockInfo(): %s", string); + + return -1; + } + + return 0; +} + +static int hm_NVML_nvmlDeviceGetTemperatureThreshold (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, nvmlTemperatureThresholds_t thresholdType, unsigned int *temp) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetTemperatureThreshold (device, thresholdType, temp); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceGetTemperatureThreshold(): %s", string); + + return -1; + } + + return 0; +} + +/* +static int hm_NVML_nvmlDeviceGetCurrPcieLinkGeneration (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned int *currLinkGen) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetCurrPcieLinkGeneration (device, currLinkGen); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceGetCurrPcieLinkGeneration(): %s", string); + + return -1; + } + + return 0; +} +*/ + +static int hm_NVML_nvmlDeviceGetCurrPcieLinkWidth (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned int *currLinkWidth) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetCurrPcieLinkWidth (device, currLinkWidth); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceGetCurrPcieLinkWidth(): %s", string); + + return -1; + } + + return 0; +} + +/* +static int hm_NVML_nvmlDeviceGetCurrentClocksThrottleReasons (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned long long *clocksThrottleReasons) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetCurrentClocksThrottleReasons (device, clocksThrottleReasons); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceGetCurrentClocksThrottleReasons(): %s", string); + + return -1; + } + + return 0; +} +*/ + +/* +static int hm_NVML_nvmlDeviceGetSupportedClocksThrottleReasons (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned long long *supportedClocksThrottleReasons) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetSupportedClocksThrottleReasons (device, supportedClocksThrottleReasons); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceGetSupportedClocksThrottleReasons(): %s", string); + + return -1; + } + + return 0; +} +*/ + +/* +static int hm_NVML_nvmlDeviceSetComputeMode (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, nvmlComputeMode_t mode) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceSetComputeMode (device, mode); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceSetComputeMode(): %s", string); + + return -1; + } + + return 0; +} +*/ + +/* +static int hm_NVML_nvmlDeviceSetGpuOperationMode (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, nvmlGpuOperationMode_t mode) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceSetGpuOperationMode (device, mode); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceSetGpuOperationMode(): %s", string); + + return -1; + } + + return 0; +} +*/ + +static int hm_NVML_nvmlDeviceGetPowerManagementLimitConstraints (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned int *minLimit, unsigned int *maxLimit) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetPowerManagementLimitConstraints (device, minLimit, maxLimit); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceGetPowerManagementLimitConstraints(): %s", string); + + return -1; + } + + return 0; +} + +static int hm_NVML_nvmlDeviceSetPowerManagementLimit (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned int limit) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceSetPowerManagementLimit (device, limit); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceSetPowerManagementLimit(): %s", string); + + return -1; + } + + return 0; +} + +static int hm_NVML_nvmlDeviceGetPowerManagementLimit (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned int *limit) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVML_PTR *nvml = hwmon_ctx->hm_nvml; + + const nvmlReturn_t nvml_rc = nvml->nvmlDeviceGetPowerManagementLimit (device, limit); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "nvmlDeviceGetPowerManagementLimit(): %s", string); + + return -1; + } + + return 0; +} + +// nvapi functions + +static int nvapi_init (hashcat_ctx_t *hashcat_ctx) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVAPI_PTR *nvapi = hwmon_ctx->hm_nvapi; + + memset (nvapi, 0, sizeof (NVAPI_PTR)); + + #if defined (_WIN) + #if defined (WIN64) + nvapi->lib = hc_dlopen ("nvapi64.dll"); + #elif defined (WIN32) + nvapi->lib = hc_dlopen ("nvapi.dll"); + #endif + #else + nvapi->lib = hc_dlopen ("nvapi.so", RTLD_NOW); // uhm yes, but .. yeah + #endif + + if (!nvapi->lib) + { + //if (user_options->quiet == false) + // event_log_error (hashcat_ctx, "load NVAPI library failed, proceed without NVAPI HWMon enabled"); + + return -1; + } + + HC_LOAD_FUNC(nvapi, nvapi_QueryInterface, NVAPI_QUERYINTERFACE, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_Initialize, NVAPI_INITIALIZE, nvapi_QueryInterface, 0x0150E828, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_Unload, NVAPI_UNLOAD, nvapi_QueryInterface, 0xD22BDD7E, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_GetErrorMessage, NVAPI_GETERRORMESSAGE, nvapi_QueryInterface, 0x6C2D048C, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_EnumPhysicalGPUs, NVAPI_ENUMPHYSICALGPUS, nvapi_QueryInterface, 0xE5AC921F, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfPoliciesInfo, NVAPI_GPU_GETPERFPOLICIESINFO, nvapi_QueryInterface, 0x409D9841, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_GPU_GetPerfPoliciesStatus, NVAPI_GPU_GETPERFPOLICIESSTATUS, nvapi_QueryInterface, 0x3D358A0C, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_GPU_SetCoolerLevels, NVAPI_GPU_SETCOOLERLEVELS, nvapi_QueryInterface, 0x891FA0AE, NVAPI, 0) + HC_LOAD_ADDR(nvapi, NvAPI_GPU_RestoreCoolerSettings, NVAPI_GPU_RESTORECOOLERSETTINGS, nvapi_QueryInterface, 0x8F6ED0FB, NVAPI, 0) + + return 0; +} + +static void nvapi_close (hashcat_ctx_t *hashcat_ctx) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVAPI_PTR *nvapi = hwmon_ctx->hm_nvapi; + + if (nvapi) + { + if (nvapi->lib) + hc_dlclose (nvapi->lib); + + hcfree (nvapi); + } +} + +static void hm_NvAPI_GetErrorMessage (NVAPI_PTR *nvapi, const NvAPI_Status NvAPI_rc, NvAPI_ShortString string) +{ + nvapi->NvAPI_GetErrorMessage (NvAPI_rc, string); +} + +static int hm_NvAPI_Initialize (hashcat_ctx_t *hashcat_ctx) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVAPI_PTR *nvapi = hwmon_ctx->hm_nvapi; + + const NvAPI_Status NvAPI_rc = nvapi->NvAPI_Initialize (); + + if (NvAPI_rc == NVAPI_LIBRARY_NOT_FOUND) return -1; + + if (NvAPI_rc != NVAPI_OK) + { + NvAPI_ShortString string = { 0 }; + + hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string); + + event_log_error (hashcat_ctx, "NvAPI_Initialize(): %s", string); + + return -1; + } + + return 0; +} + +static int hm_NvAPI_Unload (hashcat_ctx_t *hashcat_ctx) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVAPI_PTR *nvapi = hwmon_ctx->hm_nvapi; + + const NvAPI_Status NvAPI_rc = nvapi->NvAPI_Unload (); + + if (NvAPI_rc != NVAPI_OK) + { + NvAPI_ShortString string = { 0 }; + + hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string); + + event_log_error (hashcat_ctx, "NvAPI_Unload(): %s", string); + + return -1; + } + + return 0; +} + +static int hm_NvAPI_EnumPhysicalGPUs (hashcat_ctx_t *hashcat_ctx, NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVAPI_PTR *nvapi = hwmon_ctx->hm_nvapi; + + const NvAPI_Status NvAPI_rc = nvapi->NvAPI_EnumPhysicalGPUs (nvGPUHandle, pGpuCount); + + if (NvAPI_rc != NVAPI_OK) + { + NvAPI_ShortString string = { 0 }; + + hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string); + + event_log_error (hashcat_ctx, "NvAPI_EnumPhysicalGPUs(): %s", string); + + return -1; + } + + return 0; +} + +static int hm_NvAPI_GPU_GetPerfPoliciesInfo (hashcat_ctx_t *hashcat_ctx, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 *perfPolicies_info) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVAPI_PTR *nvapi = hwmon_ctx->hm_nvapi; + + const NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_GetPerfPoliciesInfo (hPhysicalGpu, perfPolicies_info); + + if (NvAPI_rc != NVAPI_OK) + { + NvAPI_ShortString string = { 0 }; + + hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string); + + event_log_error (hashcat_ctx, "NvAPI_GPU_GetPerfPoliciesInfo(): %s", string); + + return -1; + } + + return 0; +} + +static int hm_NvAPI_GPU_GetPerfPoliciesStatus (hashcat_ctx_t *hashcat_ctx, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 *perfPolicies_status) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVAPI_PTR *nvapi = hwmon_ctx->hm_nvapi; + + const NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_GetPerfPoliciesStatus (hPhysicalGpu, perfPolicies_status); + + if (NvAPI_rc != NVAPI_OK) + { + NvAPI_ShortString string = { 0 }; + + hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string); + + event_log_error (hashcat_ctx, "NvAPI_GPU_GetPerfPoliciesStatus(): %s", string); + + return -1; + } + + return 0; +} + +static int hm_NvAPI_GPU_SetCoolerLevels (hashcat_ctx_t *hashcat_ctx, NvPhysicalGpuHandle hPhysicalGpu, NvU32 coolerIndex, NV_GPU_COOLER_LEVELS *pCoolerLevels) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVAPI_PTR *nvapi = hwmon_ctx->hm_nvapi; + + const NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_SetCoolerLevels (hPhysicalGpu, coolerIndex, pCoolerLevels); + + if (NvAPI_rc != NVAPI_OK) + { + NvAPI_ShortString string = { 0 }; + + hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string); + + event_log_error (hashcat_ctx, "NvAPI_GPU_SetCoolerLevels(): %s", string); + + return -1; + } + + return 0; +} + +static int hm_NvAPI_GPU_RestoreCoolerSettings (hashcat_ctx_t *hashcat_ctx, NvPhysicalGpuHandle hPhysicalGpu, NvU32 coolerIndex) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + NVAPI_PTR *nvapi = hwmon_ctx->hm_nvapi; + + const NvAPI_Status NvAPI_rc = nvapi->NvAPI_GPU_RestoreCoolerSettings (hPhysicalGpu, coolerIndex); + + if (NvAPI_rc != NVAPI_OK) + { + NvAPI_ShortString string = { 0 }; + + hm_NvAPI_GetErrorMessage (nvapi, NvAPI_rc, string); + + event_log_error (hashcat_ctx, "NvAPI_GPU_RestoreCoolerSettings(): %s", string); + + return -1; + } + + return 0; +} + +#if defined (__MINGW64__) + +void __security_check_cookie (uintptr_t _StackCookie) +{ + (void) _StackCookie; +} + +void __GSHandlerCheck () +{ +} + +#endif + +// xnvctrl functions + +static int xnvctrl_init (hashcat_ctx_t *hashcat_ctx) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + XNVCTRL_PTR *xnvctrl = hwmon_ctx->hm_xnvctrl; + + memset (xnvctrl, 0, sizeof (XNVCTRL_PTR)); + + #if defined (_WIN) + + // unsupport platform? + return -1; + + #elif defined (_POSIX) + + xnvctrl->lib_x11 = dlopen ("libX11.so", RTLD_LAZY); + + if (xnvctrl->lib_x11 == NULL) + { + //event_log_error (hashcat_ctx, "Failed loading the X11 library: %s", dlerror()); + //event_log_error (hashcat_ctx, "Please install libx11-dev package"); + + return -1; + } + + xnvctrl->lib_xnvctrl = dlopen ("libXNVCtrl.so", RTLD_LAZY); + + if (xnvctrl->lib_xnvctrl == NULL) + { + //event_log_error (hashcat_ctx, "Failed loading the XNVCTRL library: %s", dlerror()); + //event_log_error (hashcat_ctx, "Please install libxnvctrl-dev package"); + + return -1; + } + + HC_LOAD_FUNC2 (xnvctrl, XOpenDisplay, XOPENDISPLAY, lib_x11, X11, 0); + HC_LOAD_FUNC2 (xnvctrl, XCloseDisplay, XCLOSEDISPLAY, lib_x11, X11, 0); + + HC_LOAD_FUNC2 (xnvctrl, XNVCTRLQueryTargetAttribute, XNVCTRLQUERYTARGETATTRIBUTE, lib_xnvctrl, XNVCTRL, 0); + HC_LOAD_FUNC2 (xnvctrl, XNVCTRLSetTargetAttribute, XNVCTRLSETTARGETATTRIBUTE, lib_xnvctrl, XNVCTRL, 0); + + #endif + + return 0; +} + +static void xnvctrl_close (hashcat_ctx_t *hashcat_ctx) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + XNVCTRL_PTR *xnvctrl = hwmon_ctx->hm_xnvctrl; + + if (xnvctrl) + { + #if defined (_POSIX) + + if (xnvctrl->lib_x11) + { + dlclose (xnvctrl->lib_x11); + } + + if (xnvctrl->lib_xnvctrl) + { + dlclose (xnvctrl->lib_xnvctrl); + } + + #endif + + hcfree (xnvctrl); + } +} + +static int hm_XNVCTRL_XOpenDisplay (hashcat_ctx_t *hashcat_ctx) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + XNVCTRL_PTR *xnvctrl = hwmon_ctx->hm_xnvctrl; + + if (xnvctrl->XOpenDisplay == NULL) return -1; + + void *dpy = xnvctrl->XOpenDisplay (NULL); + + if (dpy == NULL) + { + event_log_error (hashcat_ctx, "XOpenDisplay() failed"); + + return -1; + } + + xnvctrl->dpy = dpy; + + return 0; +} + +static void hm_XNVCTRL_XCloseDisplay (hashcat_ctx_t *hashcat_ctx) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + XNVCTRL_PTR *xnvctrl = hwmon_ctx->hm_xnvctrl; + + if (xnvctrl->XCloseDisplay == NULL) return; + + if (xnvctrl->dpy == NULL) return; + + xnvctrl->XCloseDisplay (xnvctrl->dpy); +} + +static int hm_XNVCTRL_get_fan_control (hashcat_ctx_t *hashcat_ctx, const int gpu, int *val) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + XNVCTRL_PTR *xnvctrl = hwmon_ctx->hm_xnvctrl; + + if (xnvctrl->XNVCTRLQueryTargetAttribute == NULL) return -1; + + if (xnvctrl->dpy == NULL) return -1; + + const bool rc = xnvctrl->XNVCTRLQueryTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_GPU, gpu, 0, NV_CTRL_GPU_COOLER_MANUAL_CONTROL, val); + + if (rc == false) + { + event_log_error (hashcat_ctx, "XNVCTRLQueryTargetAttribute(NV_CTRL_GPU_COOLER_MANUAL_CONTROL) failed"); + + return -1; + } + + return 0; +} + +static int hm_XNVCTRL_set_fan_control (hashcat_ctx_t *hashcat_ctx, const int gpu, int val) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + XNVCTRL_PTR *xnvctrl = hwmon_ctx->hm_xnvctrl; + + if (xnvctrl->XNVCTRLSetTargetAttribute == NULL) return -1; + + if (xnvctrl->dpy == NULL) return -1; + + int cur; + + int rc = hm_XNVCTRL_get_fan_control (hashcat_ctx, gpu, &cur); + + if (rc == -1) return -1; + + xnvctrl->XNVCTRLSetTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_GPU, gpu, 0, NV_CTRL_GPU_COOLER_MANUAL_CONTROL, val); + + rc = hm_XNVCTRL_get_fan_control (hashcat_ctx, gpu, &cur); + + if (rc == -1) return -1; + + if (cur != val) return -1; + + return 0; +} + +/* +static int hm_XNVCTRL_get_core_threshold (hashcat_ctx_t *hashcat_ctx, const int gpu, int *val) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + XNVCTRL_PTR *xnvctrl = hwmon_ctx->hm_xnvctrl; + + if (xnvctrl->XNVCTRLQueryTargetAttribute == NULL) return -1; + + if (xnvctrl->dpy == NULL) return -1; + + const bool rc = xnvctrl->XNVCTRLQueryTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_GPU, gpu, 0, NV_CTRL_GPU_CORE_THRESHOLD, val); + + if (rc == false) + { + event_log_error (hashcat_ctx, "XNVCTRLQueryTargetAttribute(NV_CTRL_GPU_CORE_THRESHOLD) failed"); + + return -1; + } + + return 0; +} +*/ + +static int hm_XNVCTRL_get_fan_speed_current (hashcat_ctx_t *hashcat_ctx, const int gpu, int *val) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + XNVCTRL_PTR *xnvctrl = hwmon_ctx->hm_xnvctrl; + + if (xnvctrl->XNVCTRLQueryTargetAttribute == NULL) return -1; + + if (xnvctrl->dpy == NULL) return -1; + + const bool rc = xnvctrl->XNVCTRLQueryTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_COOLER, gpu, 0, NV_CTRL_THERMAL_COOLER_CURRENT_LEVEL, val); + + if (rc == false) + { + event_log_error (hashcat_ctx, "XNVCTRLQueryTargetAttribute(NV_CTRL_THERMAL_COOLER_CURRENT_LEVEL) failed"); + + return -1; + } + + return 0; +} + +static int hm_XNVCTRL_get_fan_speed_target (hashcat_ctx_t *hashcat_ctx, const int gpu, int *val) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + XNVCTRL_PTR *xnvctrl = hwmon_ctx->hm_xnvctrl; + + if (xnvctrl->XNVCTRLQueryTargetAttribute == NULL) return -1; + + if (xnvctrl->dpy == NULL) return -1; + + const int rc = xnvctrl->XNVCTRLQueryTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_COOLER, gpu, 0, NV_CTRL_THERMAL_COOLER_LEVEL, val); + + if (rc == false) + { + event_log_error (hashcat_ctx, "%s", "XNVCTRLQueryTargetAttribute(NV_CTRL_THERMAL_COOLER_LEVEL) failed"); + + return -1; + } + + return 0; +} + +static int hm_XNVCTRL_set_fan_speed_target (hashcat_ctx_t *hashcat_ctx, const int gpu, int val) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + XNVCTRL_PTR *xnvctrl = hwmon_ctx->hm_xnvctrl; + + if (xnvctrl->XNVCTRLSetTargetAttribute == NULL) return -1; + + if (xnvctrl->dpy == NULL) return -1; + + int cur; + + int rc = hm_XNVCTRL_get_fan_speed_target (hashcat_ctx, gpu, &cur); + + if (rc == -1) return -1; + + xnvctrl->XNVCTRLSetTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_COOLER, gpu, 0, NV_CTRL_THERMAL_COOLER_LEVEL, val); + + rc = hm_XNVCTRL_get_fan_speed_target (hashcat_ctx, gpu, &cur); + + if (rc == -1) return -1; + + if (cur != val) return -1; + + return 0; +} + +// ADL functions + +static int adl_init (hashcat_ctx_t *hashcat_ctx) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + memset (adl, 0, sizeof (ADL_PTR)); + + #if defined (_WIN) + adl->lib = hc_dlopen ("atiadlxx.dll"); + + if (!adl->lib) + { + adl->lib = hc_dlopen ("atiadlxy.dll"); + } + #elif defined (_POSIX) + adl->lib = hc_dlopen ("libatiadlxx.so", RTLD_NOW); + #endif + + if (!adl->lib) + { + //if (user_options->quiet == false) + // event_log_error (hashcat_ctx, "load ADL library failed, proceed without ADL HWMon enabled"); + + return -1; + } + + HC_LOAD_FUNC(adl, ADL_Main_Control_Destroy, ADL_MAIN_CONTROL_DESTROY, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Main_Control_Create, ADL_MAIN_CONTROL_CREATE, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Adapter_NumberOfAdapters_Get, ADL_ADAPTER_NUMBEROFADAPTERS_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Adapter_AdapterInfo_Get, ADL_ADAPTER_ADAPTERINFO_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Display_DisplayInfo_Get, ADL_DISPLAY_DISPLAYINFO_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Adapter_ID_Get, ADL_ADAPTER_ID_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Adapter_VideoBiosInfo_Get, ADL_ADAPTER_VIDEOBIOSINFO_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive5_ThermalDevices_Enum, ADL_OVERDRIVE5_THERMALDEVICES_ENUM, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive5_Temperature_Get, ADL_OVERDRIVE5_TEMPERATURE_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive6_Temperature_Get, ADL_OVERDRIVE6_TEMPERATURE_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive5_CurrentActivity_Get, ADL_OVERDRIVE5_CURRENTACTIVITY_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive5_FanSpeedInfo_Get, ADL_OVERDRIVE5_FANSPEEDINFO_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive5_FanSpeed_Get, ADL_OVERDRIVE5_FANSPEED_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive6_FanSpeed_Get, ADL_OVERDRIVE6_FANSPEED_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive5_FanSpeed_Set, ADL_OVERDRIVE5_FANSPEED_SET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive6_FanSpeed_Set, ADL_OVERDRIVE6_FANSPEED_SET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive5_FanSpeedToDefault_Set, ADL_OVERDRIVE5_FANSPEEDTODEFAULT_SET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive5_ODParameters_Get, ADL_OVERDRIVE5_ODPARAMETERS_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive5_ODPerformanceLevels_Get, ADL_OVERDRIVE5_ODPERFORMANCELEVELS_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive5_ODPerformanceLevels_Set, ADL_OVERDRIVE5_ODPERFORMANCELEVELS_SET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive6_PowerControlInfo_Get, ADL_OVERDRIVE6_POWERCONTROLINFO_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive6_PowerControl_Get, ADL_OVERDRIVE6_POWERCONTROL_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive6_PowerControl_Set, ADL_OVERDRIVE6_POWERCONTROL_SET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Adapter_Active_Get, ADL_ADAPTER_ACTIVE_GET, ADL, 0) + //HC_LOAD_FUNC(adl, ADL_DisplayEnable_Set, ADL_DISPLAYENABLE_SET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive_Caps, ADL_OVERDRIVE_CAPS, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive6_PowerControl_Caps, ADL_OVERDRIVE6_POWERCONTROL_CAPS, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive6_Capabilities_Get, ADL_OVERDRIVE6_CAPABILITIES_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive6_StateInfo_Get, ADL_OVERDRIVE6_STATEINFO_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive6_CurrentStatus_Get, ADL_OVERDRIVE6_CURRENTSTATUS_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive6_State_Set, ADL_OVERDRIVE6_STATE_SET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive6_TargetTemperatureData_Get, ADL_OVERDRIVE6_TARGETTEMPERATUREDATA_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive6_TargetTemperatureRangeInfo_Get, ADL_OVERDRIVE6_TARGETTEMPERATURERANGEINFO_GET, ADL, 0) + HC_LOAD_FUNC(adl, ADL_Overdrive6_FanSpeed_Reset, ADL_OVERDRIVE6_FANSPEED_RESET, ADL, 0) + + return 0; +} + +static void adl_close (hashcat_ctx_t *hashcat_ctx) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + if (adl) + { + if (adl->lib) + hc_dlclose (adl->lib); + + hcfree (adl); + } +} + +static int hm_ADL_Main_Control_Destroy (hashcat_ctx_t *hashcat_ctx) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Main_Control_Destroy (); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Main_Control_Destroy(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +static int hm_ADL_Main_Control_Create (hashcat_ctx_t *hashcat_ctx, ADL_MAIN_MALLOC_CALLBACK callback, int iEnumConnectedAdapters) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Main_Control_Create (callback, iEnumConnectedAdapters); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Main_Control_Create(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +static int hm_ADL_Adapter_NumberOfAdapters_Get (hashcat_ctx_t *hashcat_ctx, int *lpNumAdapters) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Adapter_NumberOfAdapters_Get (lpNumAdapters); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Adapter_NumberOfAdapters_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +static int hm_ADL_Adapter_AdapterInfo_Get (hashcat_ctx_t *hashcat_ctx, LPAdapterInfo lpInfo, int iInputSize) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Adapter_AdapterInfo_Get (lpInfo, iInputSize); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Adapter_AdapterInfo_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +/* +static int hm_ADL_Display_DisplayInfo_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *iNumDisplays, ADLDisplayInfo **lppInfo, int iForceDetect) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Display_DisplayInfo_Get (iAdapterIndex, iNumDisplays, lppInfo, iForceDetect); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Display_DisplayInfo_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} +*/ + +/* +static int hm_ADL_Adapter_ID_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *lpAdapterID) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Adapter_ID_Get (iAdapterIndex, lpAdapterID); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Adapter_ID_Get(): %d", ADL_rc); + + return -1; + } + + return ADL_rc; +} +*/ + +/* +static int hm_ADL_Adapter_VideoBiosInfo_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLBiosInfo *lpBiosInfo) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Adapter_VideoBiosInfo_Get (iAdapterIndex, lpBiosInfo); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Adapter_VideoBiosInfo_Get(): %d", ADL_rc); + + return -1; + } + + return ADL_rc; +} +*/ + +/* +static int hm_ADL_Overdrive_ThermalDevices_Enum (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int iThermalControllerIndex, ADLThermalControllerInfo *lpThermalControllerInfo) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive5_ThermalDevices_Enum (iAdapterIndex, iThermalControllerIndex, lpThermalControllerInfo); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive5_ThermalDevices_Enum(): %d", ADL_rc); + + return -1; + } + + return 0; +} +*/ + +static int hm_ADL_Overdrive5_Temperature_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int iThermalControllerIndex, ADLTemperature *lpTemperature) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive5_Temperature_Get (iAdapterIndex, iThermalControllerIndex, lpTemperature); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive5_Temperature_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +static int hm_ADL_Overdrive6_Temperature_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *iTemperature) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive6_Temperature_Get (iAdapterIndex, iTemperature); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive6_Temperature_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +static int hm_ADL_Overdrive_CurrentActivity_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLPMActivity *lpActivity) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive5_CurrentActivity_Get (iAdapterIndex, lpActivity); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive5_CurrentActivity_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +static int hm_ADL_Overdrive5_FanSpeedInfo_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int iThermalControllerIndex, ADLFanSpeedInfo *lpFanSpeedInfo) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive5_FanSpeedInfo_Get (iAdapterIndex, iThermalControllerIndex, lpFanSpeedInfo); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive5_FanSpeedInfo_Get(): %d", ADL_rc); + + return -1; + } + + return ADL_rc; +} + +static int hm_ADL_Overdrive5_FanSpeed_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int iThermalControllerIndex, ADLFanSpeedValue *lpFanSpeedValue) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive5_FanSpeed_Get (iAdapterIndex, iThermalControllerIndex, lpFanSpeedValue); + + if ((ADL_rc != ADL_OK) && (ADL_rc != ADL_ERR_NOT_SUPPORTED)) // exception allowed only here + { + event_log_error (hashcat_ctx, "ADL_Overdrive5_FanSpeed_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +static int hm_ADL_Overdrive6_FanSpeed_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLOD6FanSpeedInfo *lpFanSpeedInfo) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive6_FanSpeed_Get (iAdapterIndex, lpFanSpeedInfo); + + if ((ADL_rc != ADL_OK) && (ADL_rc != ADL_ERR_NOT_SUPPORTED)) // exception allowed only here + { + event_log_error (hashcat_ctx, "ADL_Overdrive6_FanSpeed_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +static int hm_ADL_Overdrive5_FanSpeed_Set (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int iThermalControllerIndex, ADLFanSpeedValue *lpFanSpeedValue) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive5_FanSpeed_Set (iAdapterIndex, iThermalControllerIndex, lpFanSpeedValue); + + if ((ADL_rc != ADL_OK) && (ADL_rc != ADL_ERR_NOT_SUPPORTED)) // exception allowed only here + { + event_log_error (hashcat_ctx, "ADL_Overdrive5_FanSpeed_Set(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +static int hm_ADL_Overdrive6_FanSpeed_Set (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLOD6FanSpeedValue *lpFanSpeedValue) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive6_FanSpeed_Set (iAdapterIndex, lpFanSpeedValue); + + if ((ADL_rc != ADL_OK) && (ADL_rc != ADL_ERR_NOT_SUPPORTED)) // exception allowed only here + { + event_log_error (hashcat_ctx, "ADL_Overdrive6_FanSpeed_Set(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +static int hm_ADL_Overdrive5_FanSpeedToDefault_Set (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int iThermalControllerIndex) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive5_FanSpeedToDefault_Set (iAdapterIndex, iThermalControllerIndex); + + if ((ADL_rc != ADL_OK) && (ADL_rc != ADL_ERR_NOT_SUPPORTED)) // exception allowed only here + { + event_log_error (hashcat_ctx, "ADL_Overdrive5_FanSpeedToDefault_Set(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +/* +static int hm_ADL_Overdrive_ODParameters_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLODParameters *lpOdParameters) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive5_ODParameters_Get (iAdapterIndex, lpOdParameters); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive5_ODParameters_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} +*/ + +/* +static int hm_ADL_Overdrive_ODPerformanceLevels_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int iDefault, ADLODPerformanceLevels *lpOdPerformanceLevels) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive5_ODPerformanceLevels_Get (iAdapterIndex, iDefault, lpOdPerformanceLevels); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive5_ODPerformanceLevels_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} +*/ + +/* +static int hm_ADL_Overdrive_ODPerformanceLevels_Set (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLODPerformanceLevels *lpOdPerformanceLevels) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive5_ODPerformanceLevels_Set (iAdapterIndex, lpOdPerformanceLevels); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive5_ODPerformanceLevels_Set(): %d", ADL_rc); + + return -1; + } + + return 0; +} +*/ + +static int hm_ADL_Overdrive_PowerControlInfo_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLOD6PowerControlInfo *powertune) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive6_PowerControlInfo_Get (iAdapterIndex, powertune); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive6_PowerControlInfo_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +static int hm_ADL_Overdrive_PowerControl_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *iCurrentValue) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + int default_value = 0; + + const int ADL_rc = adl->ADL_Overdrive6_PowerControl_Get (iAdapterIndex, iCurrentValue, &default_value); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive6_PowerControl_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +static int hm_ADL_Overdrive_PowerControl_Set (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int level) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + ADLOD6PowerControlInfo powertune = {0, 0, 0, 0, 0}; + + const int hm_rc = hm_ADL_Overdrive_PowerControlInfo_Get (hashcat_ctx, iAdapterIndex, &powertune); + + if (hm_rc == -1) return -1; + + int min = powertune.iMinValue; + int max = powertune.iMaxValue; + int step = powertune.iStepValue; + + if (level < min || level > max) + { + event_log_error (hashcat_ctx, "ADL PowerControl level invalid"); + + return -1; + } + + if (level % step != 0) + { + event_log_error (hashcat_ctx, "ADL PowerControl step invalid"); + + return -1; + } + + const int ADL_rc = adl->ADL_Overdrive6_PowerControl_Set (iAdapterIndex, level); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive6_PowerControl_Set(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +/* +static int hm_ADL_Adapter_Active_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *lpStatus) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Adapter_Active_Get (iAdapterIndex, lpStatus); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Adapter_Active_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} +*/ + +/* +static int hm_ADL_DisplayEnable_Set (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *lpDisplayIndexList, int iDisplayListSize, int bPersistOnly) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_DisplayEnable_Set (iAdapterIndex, lpDisplayIndexList, iDisplayListSize, bPersistOnly); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_DisplayEnable_Set(): %d", ADL_rc); + + return -1; + } + + return 0; +} +*/ + +static int hm_ADL_Overdrive_Caps (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *od_supported, int *od_enabled, int *od_version) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive_Caps (iAdapterIndex, od_supported, od_enabled, od_version); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive_Caps(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +static int hm_ADL_Overdrive6_PowerControl_Caps (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *lpSupported) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive6_PowerControl_Caps (iAdapterIndex, lpSupported); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive6_PowerControl_Caps(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +static int hm_ADL_Overdrive_Capabilities_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLOD6Capabilities *caps) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive6_Capabilities_Get (iAdapterIndex, caps); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive6_Capabilities_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +static int hm_ADL_Overdrive_StateInfo_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int type, ADLOD6MemClockState *state) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive6_StateInfo_Get (iAdapterIndex, type, state); + + if (ADL_rc == ADL_OK) + { + // check if clocks are okay with step sizes + // if not run a little hack: adjust the clocks to nearest clock size (clock down just a little bit) + + ADLOD6Capabilities caps; + + const int hm_rc = hm_ADL_Overdrive_Capabilities_Get (hashcat_ctx, iAdapterIndex, &caps); + + if (hm_rc == -1) return -1; + + if (state->state.aLevels[0].iEngineClock % caps.sEngineClockRange.iStep != 0) + { + event_log_error (hashcat_ctx, "ADL engine step size invalid for performance level 1"); + + //state->state.aLevels[0].iEngineClock -= state->state.aLevels[0].iEngineClock % caps.sEngineClockRange.iStep; + + return -1; + } + + if (state->state.aLevels[1].iEngineClock % caps.sEngineClockRange.iStep != 0) + { + event_log_error (hashcat_ctx, "ADL engine step size invalid for performance level 2"); + + //state->state.aLevels[1].iEngineClock -= state->state.aLevels[1].iEngineClock % caps.sEngineClockRange.iStep; + + return -1; + } + + if (state->state.aLevels[0].iMemoryClock % caps.sMemoryClockRange.iStep != 0) + { + event_log_error (hashcat_ctx, "ADL memory step size invalid for performance level 1"); + + //state->state.aLevels[0].iMemoryClock -= state->state.aLevels[0].iMemoryClock % caps.sMemoryClockRange.iStep; + + return -1; + } + + if (state->state.aLevels[1].iMemoryClock % caps.sMemoryClockRange.iStep != 0) + { + event_log_error (hashcat_ctx, "ADL memory step size invalid for performance level 2"); + + //state->state.aLevels[1].iMemoryClock -= state->state.aLevels[1].iMemoryClock % caps.sMemoryClockRange.iStep; + + return -1; + } + } + else + { + event_log_error (hashcat_ctx, "ADL_Overdrive6_StateInfo_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +/* +static int hm_ADL_Overdrive_CurrentStatus_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLOD6CurrentStatus *status) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive6_CurrentStatus_Get (iAdapterIndex, status); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive6_CurrentStatus_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} +*/ + +static int hm_ADL_Overdrive_State_Set (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int type, ADLOD6StateInfo *state) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + // sanity checks + + ADLOD6Capabilities caps; + + const int hm_rc = hm_ADL_Overdrive_Capabilities_Get (hashcat_ctx, iAdapterIndex, &caps); + + if (hm_rc == -1) return -1; + + if (state->aLevels[0].iEngineClock < caps.sEngineClockRange.iMin || state->aLevels[1].iEngineClock > caps.sEngineClockRange.iMax) + { + event_log_error (hashcat_ctx, "ADL engine clock outside valid range"); + + return -1; + } + + if (state->aLevels[1].iEngineClock % caps.sEngineClockRange.iStep != 0) + { + event_log_error (hashcat_ctx, "ADL engine step size invalid"); + + return -1; + } + + if (state->aLevels[0].iMemoryClock < caps.sMemoryClockRange.iMin || state->aLevels[1].iMemoryClock > caps.sMemoryClockRange.iMax) + { + event_log_error (hashcat_ctx, "ADL memory clock outside valid range"); + + return -1; + } + + if (state->aLevels[1].iMemoryClock % caps.sMemoryClockRange.iStep != 0) + { + event_log_error (hashcat_ctx, "ADL memory step size invalid"); + + return -1; + } + + const int ADL_rc = adl->ADL_Overdrive6_State_Set (iAdapterIndex, type, state); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive6_State_Set(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +static int hm_ADL_Overdrive6_TargetTemperatureData_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *cur_temp, int *default_temp) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive6_TargetTemperatureData_Get (iAdapterIndex, cur_temp, default_temp); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive6_TargetTemperatureData_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +/* +static int hm_ADL_Overdrive6_TargetTemperatureRangeInfo_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLOD6ParameterRange *lpTargetTemperatureInfo) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive6_TargetTemperatureRangeInfo_Get (iAdapterIndex, lpTargetTemperatureInfo); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive6_TargetTemperatureRangeInfo_Get(): %d", ADL_rc); + + return -1; + } + + return 0; +} +*/ + +static int hm_ADL_Overdrive6_FanSpeed_Reset (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + ADL_PTR *adl = hwmon_ctx->hm_adl; + + const int ADL_rc = adl->ADL_Overdrive6_FanSpeed_Reset (iAdapterIndex); + + if (ADL_rc != ADL_OK) + { + event_log_error (hashcat_ctx, "ADL_Overdrive6_FanSpeed_Reset(): %d", ADL_rc); + + return -1; + } + + return 0; +} + +// general functions + +static int get_adapters_num_adl (hashcat_ctx_t *hashcat_ctx, int *iNumberAdapters) +{ + const int hm_rc = hm_ADL_Adapter_NumberOfAdapters_Get (hashcat_ctx, iNumberAdapters); + + if (hm_rc == -1) return -1; + + if (iNumberAdapters == 0) + { + event_log_error (hashcat_ctx, "No ADL adapters found"); + + return -1; + } + + return 0; +} + +static int hm_get_adapter_info_adl (hashcat_ctx_t *hashcat_ctx, LPAdapterInfo lpAdapterInfo, const size_t AdapterInfoSize) +{ + return hm_ADL_Adapter_AdapterInfo_Get (hashcat_ctx, lpAdapterInfo, AdapterInfoSize); +} + +static int hm_get_adapter_index_nvapi (hashcat_ctx_t *hashcat_ctx, HM_ADAPTER_NVAPI *nvapiGPUHandle) { NvU32 pGpuCount; - if (hm_NvAPI_EnumPhysicalGPUs (hwmon_ctx->hm_nvapi, nvapiGPUHandle, &pGpuCount) != NVAPI_OK) return 0; + if (hm_NvAPI_EnumPhysicalGPUs (hashcat_ctx, nvapiGPUHandle, &pGpuCount) != NVAPI_OK) return 0; if (pGpuCount == 0) { - log_info ("WARN: No NvAPI adapters found"); + event_log_error (hashcat_ctx, "No NvAPI adapters found"); return 0; } @@ -50,29 +1882,29 @@ static int hm_get_adapter_index_nvapi (const hwmon_ctx_t *hwmon_ctx, HM_ADAPTER_ return (pGpuCount); } -static int hm_get_adapter_index_nvml (const hwmon_ctx_t *hwmon_ctx, HM_ADAPTER_NVML *nvmlGPUHandle) +static int hm_get_adapter_index_nvml (hashcat_ctx_t *hashcat_ctx, HM_ADAPTER_NVML *nvmlGPUHandle) { - int pGpuCount = 0; + unsigned int deviceCount = 0; - for (u32 i = 0; i < DEVICES_MAX; i++) + hm_NVML_nvmlDeviceGetCount (hashcat_ctx, &deviceCount); + + if (deviceCount == 0) { - if (hm_NVML_nvmlDeviceGetHandleByIndex (hwmon_ctx->hm_nvml, 1, i, &nvmlGPUHandle[i]) != NVML_SUCCESS) break; - - // can be used to determine if the device by index matches the cuda device by index - // char name[100]; memset (name, 0, sizeof (name)); - // hm_NVML_nvmlDeviceGetName (hwmon_ctx->hm_nvml, nvGPUHandle[i], name, sizeof (name) - 1); - - pGpuCount++; - } - - if (pGpuCount == 0) - { - log_info ("WARN: No NVML adapters found"); + event_log_error (hashcat_ctx, "No NVML adapters found"); return 0; } - return (pGpuCount); + for (u32 i = 0; i < deviceCount; i++) + { + if (hm_NVML_nvmlDeviceGetHandleByIndex (hashcat_ctx, i, &nvmlGPUHandle[i]) == -1) break; + + // can be used to determine if the device by index matches the cuda device by index + // char name[100]; memset (name, 0, sizeof (name)); + // hm_NVML_nvmlDeviceGetName (hashcat_ctx, nvGPUHandle[i], name, sizeof (name) - 1); + } + + return (deviceCount); } static void hm_sort_adl_adapters_by_busid_devid (u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo) @@ -124,7 +1956,7 @@ static void hm_sort_adl_adapters_by_busid_devid (u32 *valid_adl_device_list, int } } -static u32 *hm_get_list_valid_adl_adapters (int iNumberAdapters, int *num_adl_adapters, LPAdapterInfo lpAdapterInfo) +static u32 *hm_get_list_valid_adl_adapters (hashcat_ctx_t *hashcat_ctx, int iNumberAdapters, int *num_adl_adapters, LPAdapterInfo lpAdapterInfo) { *num_adl_adapters = 0; @@ -163,14 +1995,14 @@ static u32 *hm_get_list_valid_adl_adapters (int iNumberAdapters, int *num_adl_ad // add it to the list - adl_adapters = (u32 *) myrealloc (adl_adapters, (*num_adl_adapters) * sizeof (int), sizeof (int)); + adl_adapters = (u32 *) hcrealloc (hashcat_ctx, adl_adapters, (*num_adl_adapters) * sizeof (int), sizeof (int)); // need check adl_adapters[*num_adl_adapters] = i; // rest is just bookkeeping - bus_numbers = (int*) myrealloc (bus_numbers, (*num_adl_adapters) * sizeof (int), sizeof (int)); - device_numbers = (int*) myrealloc (device_numbers, (*num_adl_adapters) * sizeof (int), sizeof (int)); + bus_numbers = (int*) hcrealloc (hashcat_ctx, bus_numbers, (*num_adl_adapters) * sizeof (int), sizeof (int)); // need check + device_numbers = (int*) hcrealloc (hashcat_ctx, device_numbers, (*num_adl_adapters) * sizeof (int), sizeof (int)); // need check bus_numbers[*num_adl_adapters] = info.iBusNumber; device_numbers[*num_adl_adapters] = info.iDeviceNumber; @@ -178,8 +2010,8 @@ static u32 *hm_get_list_valid_adl_adapters (int iNumberAdapters, int *num_adl_ad (*num_adl_adapters)++; } - myfree (bus_numbers); - myfree (device_numbers); + hcfree (bus_numbers); + hcfree (device_numbers); // sort the list by increasing bus id, device id number @@ -188,7 +2020,7 @@ static u32 *hm_get_list_valid_adl_adapters (int iNumberAdapters, int *num_adl_ad return adl_adapters; } -static int hm_check_fanspeed_control (ADL_PTR *adl, hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo) +static int hm_check_fanspeed_control (hashcat_ctx_t *hashcat_ctx, hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo) { // loop through all valid devices @@ -218,7 +2050,7 @@ static int hm_check_fanspeed_control (ADL_PTR *adl, hm_attrs_t *hm_device, u32 * FanSpeedInfo.iSize = sizeof (ADLFanSpeedInfo); - if (hm_ADL_Overdrive5_FanSpeedInfo_Get (adl, info.iAdapterIndex, 0, &FanSpeedInfo) != ADL_OK) return -1; + if (hm_ADL_Overdrive5_FanSpeedInfo_Get (hashcat_ctx, info.iAdapterIndex, 0, &FanSpeedInfo) == -1) return -1; // check read and write capability in fanspeedinfo @@ -238,7 +2070,7 @@ static int hm_check_fanspeed_control (ADL_PTR *adl, hm_attrs_t *hm_device, u32 * memset (&faninfo, 0, sizeof (faninfo)); - if (hm_ADL_Overdrive6_FanSpeed_Get (adl, info.iAdapterIndex, &faninfo) != ADL_OK) return -1; + if (hm_ADL_Overdrive6_FanSpeed_Get (hashcat_ctx, info.iAdapterIndex, &faninfo) == -1) return -1; // check read capability in fanspeedinfo @@ -256,7 +2088,7 @@ static int hm_check_fanspeed_control (ADL_PTR *adl, hm_attrs_t *hm_device, u32 * return 0; } -static int hm_get_overdrive_version (ADL_PTR *adl, hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo) +static int hm_get_overdrive_version (hashcat_ctx_t *hashcat_ctx, hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo) { for (int i = 0; i < num_adl_adapters; i++) { @@ -272,7 +2104,7 @@ static int hm_get_overdrive_version (ADL_PTR *adl, hm_attrs_t *hm_device, u32 *v int od_enabled = 0; int od_version = 0; - if (hm_ADL_Overdrive_Caps (adl, info.iAdapterIndex, &od_supported, &od_enabled, &od_version) != ADL_OK) return -1; + if (hm_ADL_Overdrive_Caps (hashcat_ctx, info.iAdapterIndex, &od_supported, &od_enabled, &od_version) == -1) return -1; // store the overdrive version in hm_device @@ -288,11 +2120,15 @@ static int hm_get_overdrive_version (ADL_PTR *adl, hm_attrs_t *hm_device, u32 *v return 0; } -static int hm_get_adapter_index_adl (hm_attrs_t *hm_device, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo) +static int hm_get_adapter_index_adl (hashcat_ctx_t *hashcat_ctx, u32 *valid_adl_device_list, int num_adl_adapters, LPAdapterInfo lpAdapterInfo) { + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + hm_attrs_t *hm_device = hwmon_ctx->hm_device; + for (int i = 0; i < num_adl_adapters; i++) { - u32 adapter_index = valid_adl_device_list[i]; + const u32 adapter_index = valid_adl_device_list[i]; // get AdapterInfo @@ -334,7 +2170,7 @@ int hm_get_threshold_slowdown_with_device_id (hashcat_ctx_t *hashcat_ctx, const int CurrentValue = 0; int DefaultValue = 0; - if (hm_ADL_Overdrive6_TargetTemperatureData_Get (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, &CurrentValue, &DefaultValue) != ADL_OK) return -1; + if (hm_ADL_Overdrive6_TargetTemperatureData_Get (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, &CurrentValue, &DefaultValue) == -1) return -1; // the return value has never been tested since hm_ADL_Overdrive6_TargetTemperatureData_Get() never worked on any system. expect problems. @@ -347,7 +2183,7 @@ int hm_get_threshold_slowdown_with_device_id (hashcat_ctx_t *hashcat_ctx, const { int target = 0; - if (hm_NVML_nvmlDeviceGetTemperatureThreshold (hwmon_ctx->hm_nvml, 1, hwmon_ctx->hm_device[device_id].nvml, NVML_TEMPERATURE_THRESHOLD_SLOWDOWN, (unsigned int *) &target) != NVML_SUCCESS) return -1; + if (hm_NVML_nvmlDeviceGetTemperatureThreshold (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvml, NVML_TEMPERATURE_THRESHOLD_SLOWDOWN, (unsigned int *) &target) == -1) return -1; return target; } @@ -383,7 +2219,7 @@ int hm_get_threshold_shutdown_with_device_id (hashcat_ctx_t *hashcat_ctx, const { int target = 0; - if (hm_NVML_nvmlDeviceGetTemperatureThreshold (hwmon_ctx->hm_nvml, 1, hwmon_ctx->hm_device[device_id].nvml, NVML_TEMPERATURE_THRESHOLD_SHUTDOWN, (unsigned int *) &target) != NVML_SUCCESS) return -1; + if (hm_NVML_nvmlDeviceGetTemperatureThreshold (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvml, NVML_TEMPERATURE_THRESHOLD_SHUTDOWN, (unsigned int *) &target) == -1) return -1; return target; } @@ -410,7 +2246,7 @@ int hm_get_temperature_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 dev Temperature.iSize = sizeof (ADLTemperature); - if (hm_ADL_Overdrive5_Temperature_Get (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, 0, &Temperature) != ADL_OK) return -1; + if (hm_ADL_Overdrive5_Temperature_Get (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, 0, &Temperature) == -1) return -1; return Temperature.iTemperature / 1000; } @@ -418,7 +2254,7 @@ int hm_get_temperature_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 dev { int Temperature = 0; - if (hm_ADL_Overdrive6_Temperature_Get (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, &Temperature) != ADL_OK) return -1; + if (hm_ADL_Overdrive6_Temperature_Get (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, &Temperature) == -1) return -1; return Temperature / 1000; } @@ -429,7 +2265,7 @@ int hm_get_temperature_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 dev { int temperature = 0; - if (hm_NVML_nvmlDeviceGetTemperature (hwmon_ctx->hm_nvml, 1, hwmon_ctx->hm_device[device_id].nvml, NVML_TEMPERATURE_GPU, (u32 *) &temperature) != NVML_SUCCESS) return -1; + if (hm_NVML_nvmlDeviceGetTemperature (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvml, NVML_TEMPERATURE_GPU, (u32 *) &temperature) == -1) return -1; return temperature; } @@ -461,7 +2297,7 @@ int hm_get_fanpolicy_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 devic lpFanSpeedValue.iSize = sizeof (lpFanSpeedValue); lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT; - if (hm_ADL_Overdrive5_FanSpeed_Get (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, 0, &lpFanSpeedValue) != ADL_OK) return -1; + if (hm_ADL_Overdrive5_FanSpeed_Get (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, 0, &lpFanSpeedValue) == -1) return -1; return (lpFanSpeedValue.iFanSpeed & ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED) ? 0 : 1; } @@ -506,7 +2342,7 @@ int hm_get_fanspeed_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 device lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT; lpFanSpeedValue.iFlags = ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED; - if (hm_ADL_Overdrive5_FanSpeed_Get (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, 0, &lpFanSpeedValue) != ADL_OK) return -1; + if (hm_ADL_Overdrive5_FanSpeed_Get (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, 0, &lpFanSpeedValue) == -1) return -1; return lpFanSpeedValue.iFanSpeed; } @@ -516,7 +2352,7 @@ int hm_get_fanspeed_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 device memset (&faninfo, 0, sizeof (faninfo)); - if (hm_ADL_Overdrive6_FanSpeed_Get (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, &faninfo) != ADL_OK) return -1; + if (hm_ADL_Overdrive6_FanSpeed_Get (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, &faninfo) == -1) return -1; return faninfo.iFanSpeedPercent; } @@ -527,7 +2363,7 @@ int hm_get_fanspeed_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 device { int speed = 0; - if (hm_NVML_nvmlDeviceGetFanSpeed (hwmon_ctx->hm_nvml, 0, hwmon_ctx->hm_device[device_id].nvml, (u32 *) &speed) != NVML_SUCCESS) return -1; + if (hm_NVML_nvmlDeviceGetFanSpeed (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvml, (u32 *) &speed) == -1) return -1; return speed; } @@ -553,7 +2389,7 @@ int hm_get_buslanes_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 device PMActivity.iSize = sizeof (ADLPMActivity); - if (hm_ADL_Overdrive_CurrentActivity_Get (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, &PMActivity) != ADL_OK) return -1; + if (hm_ADL_Overdrive_CurrentActivity_Get (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, &PMActivity) == -1) return -1; return PMActivity.iCurrentBusLanes; } @@ -563,7 +2399,7 @@ int hm_get_buslanes_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 device { unsigned int currLinkWidth; - if (hm_NVML_nvmlDeviceGetCurrPcieLinkWidth (hwmon_ctx->hm_nvml, 1, hwmon_ctx->hm_device[device_id].nvml, &currLinkWidth) != NVML_SUCCESS) return -1; + if (hm_NVML_nvmlDeviceGetCurrPcieLinkWidth (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvml, &currLinkWidth) == -1) return -1; return currLinkWidth; } @@ -588,7 +2424,7 @@ int hm_get_utilization_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 dev PMActivity.iSize = sizeof (ADLPMActivity); - if (hm_ADL_Overdrive_CurrentActivity_Get (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, &PMActivity) != ADL_OK) return -1; + if (hm_ADL_Overdrive_CurrentActivity_Get (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, &PMActivity) == -1) return -1; return PMActivity.iActivityPercent; } @@ -598,7 +2434,7 @@ int hm_get_utilization_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 dev { nvmlUtilization_t utilization; - if (hm_NVML_nvmlDeviceGetUtilizationRates (hwmon_ctx->hm_nvml, 1, hwmon_ctx->hm_device[device_id].nvml, &utilization) != NVML_SUCCESS) return -1; + if (hm_NVML_nvmlDeviceGetUtilizationRates (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvml, &utilization) == -1) return -1; return utilization.gpu; } @@ -623,7 +2459,7 @@ int hm_get_memoryspeed_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 dev PMActivity.iSize = sizeof (ADLPMActivity); - if (hm_ADL_Overdrive_CurrentActivity_Get (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, &PMActivity) != ADL_OK) return -1; + if (hm_ADL_Overdrive_CurrentActivity_Get (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, &PMActivity) == -1) return -1; return PMActivity.iMemoryClock / 100; } @@ -633,7 +2469,7 @@ int hm_get_memoryspeed_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 dev { unsigned int clock; - if (hm_NVML_nvmlDeviceGetClockInfo (hwmon_ctx->hm_nvml, 1, hwmon_ctx->hm_device[device_id].nvml, NVML_CLOCK_MEM, &clock) != NVML_SUCCESS) return -1; + if (hm_NVML_nvmlDeviceGetClockInfo (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvml, NVML_CLOCK_MEM, &clock) == -1) return -1; return clock; } @@ -658,7 +2494,7 @@ int hm_get_corespeed_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 devic PMActivity.iSize = sizeof (ADLPMActivity); - if (hm_ADL_Overdrive_CurrentActivity_Get (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, &PMActivity) != ADL_OK) return -1; + if (hm_ADL_Overdrive_CurrentActivity_Get (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, &PMActivity) == -1) return -1; return PMActivity.iEngineClock / 100; } @@ -668,7 +2504,7 @@ int hm_get_corespeed_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 devic { unsigned int clock; - if (hm_NVML_nvmlDeviceGetClockInfo (hwmon_ctx->hm_nvml, 1, hwmon_ctx->hm_device[device_id].nvml, NVML_CLOCK_SM, &clock) != NVML_SUCCESS) return -1; + if (hm_NVML_nvmlDeviceGetClockInfo (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvml, NVML_CLOCK_SM, &clock) == -1) return -1; return clock; } @@ -692,11 +2528,12 @@ int hm_get_throttle_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 device if (opencl_ctx->devices_param[device_id].device_vendor_id == VENDOR_ID_NV) { + /* this is triggered by mask generator, too. therefore useless unsigned long long clocksThrottleReasons = 0; unsigned long long supportedThrottleReasons = 0; - if (hm_NVML_nvmlDeviceGetCurrentClocksThrottleReasons (hwmon_ctx->hm_nvml, 1, hwmon_ctx->hm_device[device_id].nvml, &clocksThrottleReasons) != NVML_SUCCESS) return -1; - if (hm_NVML_nvmlDeviceGetSupportedClocksThrottleReasons (hwmon_ctx->hm_nvml, 1, hwmon_ctx->hm_device[device_id].nvml, &supportedThrottleReasons) != NVML_SUCCESS) return -1; + if (hm_NVML_nvmlDeviceGetCurrentClocksThrottleReasons (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvml, &clocksThrottleReasons) == -1) return -1; + if (hm_NVML_nvmlDeviceGetSupportedClocksThrottleReasons (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvml, &supportedThrottleReasons) == -1) return -1; clocksThrottleReasons &= supportedThrottleReasons; clocksThrottleReasons &= ~nvmlClocksThrottleReasonGpuIdle; @@ -709,6 +2546,27 @@ int hm_get_throttle_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 device } return (clocksThrottleReasons != nvmlClocksThrottleReasonNone); + */ + + if (hwmon_ctx->hm_nvapi) + { + NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 perfPolicies_info; + NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 perfPolicies_status; + + memset (&perfPolicies_info, 0, sizeof (NV_GPU_PERF_POLICIES_INFO_PARAMS_V1)); + memset (&perfPolicies_status, 0, sizeof (NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1)); + + perfPolicies_info.version = MAKE_NVAPI_VERSION (NV_GPU_PERF_POLICIES_INFO_PARAMS_V1, 1); + perfPolicies_status.version = MAKE_NVAPI_VERSION (NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1, 1); + + hm_NvAPI_GPU_GetPerfPoliciesInfo (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvapi, &perfPolicies_info); + + perfPolicies_status.info_value = perfPolicies_info.info_value; + + hm_NvAPI_GPU_GetPerfPoliciesStatus (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvapi, &perfPolicies_status); + + return perfPolicies_status.throttle & 2; + } } return -1; @@ -737,7 +2595,7 @@ int hm_set_fanspeed_with_device_id_adl (hashcat_ctx_t *hashcat_ctx, const u32 de lpFanSpeedValue.iFlags = ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED; lpFanSpeedValue.iFanSpeed = fanspeed; - if (hm_ADL_Overdrive5_FanSpeed_Set (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, 0, &lpFanSpeedValue) != ADL_OK) return -1; + if (hm_ADL_Overdrive5_FanSpeed_Set (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, 0, &lpFanSpeedValue) == -1) return -1; return 0; } @@ -750,7 +2608,7 @@ int hm_set_fanspeed_with_device_id_adl (hashcat_ctx_t *hashcat_ctx, const u32 de fan_speed_value.iSpeedType = ADL_OD6_FANSPEED_TYPE_PERCENT; fan_speed_value.iFanSpeed = fanspeed; - if (hm_ADL_Overdrive6_FanSpeed_Set (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, &fan_speed_value) != ADL_OK) return -1; + if (hm_ADL_Overdrive6_FanSpeed_Set (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, &fan_speed_value) == -1) return -1; return 0; } @@ -759,13 +2617,13 @@ int hm_set_fanspeed_with_device_id_adl (hashcat_ctx_t *hashcat_ctx, const u32 de { if (hwmon_ctx->hm_device[device_id].od_version == 5) { - if (hm_ADL_Overdrive5_FanSpeedToDefault_Set (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, 0) != ADL_OK) return -1; + if (hm_ADL_Overdrive5_FanSpeedToDefault_Set (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, 0) == -1) return -1; return 0; } else // od_version == 6 { - if (hm_ADL_Overdrive6_FanSpeed_Reset (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl) != ADL_OK) return -1; + if (hm_ADL_Overdrive6_FanSpeed_Reset (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl) == -1) return -1; return 0; } @@ -797,13 +2655,13 @@ int hm_set_fanspeed_with_device_id_nvapi (hashcat_ctx_t *hashcat_ctx, const u32 CoolerLevels.Levels[0].Level = fanspeed; CoolerLevels.Levels[0].Policy = 1; - if (hm_NvAPI_GPU_SetCoolerLevels (hwmon_ctx->hm_nvapi, hwmon_ctx->hm_device[device_id].nvapi, 0, &CoolerLevels) != NVAPI_OK) return -1; + if (hm_NvAPI_GPU_SetCoolerLevels (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvapi, 0, &CoolerLevels) != NVAPI_OK) return -1; return 0; } else { - if (hm_NvAPI_GPU_RestoreCoolerSettings (hwmon_ctx->hm_nvapi, hwmon_ctx->hm_device[device_id].nvapi, 0) != NVAPI_OK) return -1; + if (hm_NvAPI_GPU_RestoreCoolerSettings (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvapi, 0) != NVAPI_OK) return -1; return 0; } @@ -823,7 +2681,26 @@ int hm_set_fanspeed_with_device_id_xnvctrl (hashcat_ctx_t *hashcat_ctx, const u3 { if (hwmon_ctx->hm_xnvctrl) { - if (set_fan_speed_target (hwmon_ctx->hm_xnvctrl, hwmon_ctx->hm_device[device_id].xnvctrl, fanspeed) != 0) return -1; + if (hm_XNVCTRL_set_fan_speed_target (hashcat_ctx, hwmon_ctx->hm_device[device_id].xnvctrl, fanspeed) == -1) return -1; + + return 0; + } + } + + return -1; +} + +int hm_set_fanctrl_with_device_id_xnvctrl (hashcat_ctx_t *hashcat_ctx, const u32 device_id, const int val) +{ + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + + if (hwmon_ctx->enabled == false) return -1; + + if (hwmon_ctx->hm_device[device_id].fan_set_supported == true) + { + if (hwmon_ctx->hm_xnvctrl) + { + if (hm_XNVCTRL_set_fan_control (hashcat_ctx, hwmon_ctx->hm_device[device_id].xnvctrl, val) == -1) return -1; return 0; } @@ -849,39 +2726,77 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) if (user_options->version == true) return 0; if (user_options->gpu_temp_disable == true) return 0; - hwmon_ctx->hm_device = (hm_attrs_t *) mycalloc (DEVICES_MAX, sizeof (hm_attrs_t)); + hwmon_ctx->hm_device = (hm_attrs_t *) hccalloc (hashcat_ctx, DEVICES_MAX, sizeof (hm_attrs_t)); VERIFY_PTR (hwmon_ctx->hm_device); /** * Initialize shared libraries */ - ADL_PTR *adl = (ADL_PTR *) mymalloc (sizeof (ADL_PTR)); - NVAPI_PTR *nvapi = (NVAPI_PTR *) mymalloc (sizeof (NVAPI_PTR)); - NVML_PTR *nvml = (NVML_PTR *) mymalloc (sizeof (NVML_PTR)); - XNVCTRL_PTR *xnvctrl = (XNVCTRL_PTR *) mymalloc (sizeof (XNVCTRL_PTR)); + ADL_PTR *adl = (ADL_PTR *) hcmalloc (hashcat_ctx, sizeof (ADL_PTR)); + NVAPI_PTR *nvapi = (NVAPI_PTR *) hcmalloc (hashcat_ctx, sizeof (NVAPI_PTR)); + NVML_PTR *nvml = (NVML_PTR *) hcmalloc (hashcat_ctx, sizeof (NVML_PTR)); + XNVCTRL_PTR *xnvctrl = (XNVCTRL_PTR *) hcmalloc (hashcat_ctx, sizeof (XNVCTRL_PTR)); - hwmon_ctx->hm_adl = NULL; - hwmon_ctx->hm_nvapi = NULL; - hwmon_ctx->hm_nvml = NULL; - hwmon_ctx->hm_xnvctrl = NULL; + hm_attrs_t *hm_adapters_adl = (hm_attrs_t *) hccalloc (hashcat_ctx, DEVICES_MAX, sizeof (hm_attrs_t)); VERIFY_PTR (hm_adapters_adl); + hm_attrs_t *hm_adapters_nvapi = (hm_attrs_t *) hccalloc (hashcat_ctx, DEVICES_MAX, sizeof (hm_attrs_t)); VERIFY_PTR (hm_adapters_nvapi); + hm_attrs_t *hm_adapters_nvml = (hm_attrs_t *) hccalloc (hashcat_ctx, DEVICES_MAX, sizeof (hm_attrs_t)); VERIFY_PTR (hm_adapters_nvml); + hm_attrs_t *hm_adapters_xnvctrl = (hm_attrs_t *) hccalloc (hashcat_ctx, DEVICES_MAX, sizeof (hm_attrs_t)); VERIFY_PTR (hm_adapters_xnvctrl); - hm_attrs_t *hm_adapters_adl = (hm_attrs_t *) mycalloc (DEVICES_MAX, sizeof (hm_attrs_t)); - hm_attrs_t *hm_adapters_nvapi = (hm_attrs_t *) mycalloc (DEVICES_MAX, sizeof (hm_attrs_t)); - hm_attrs_t *hm_adapters_nvml = (hm_attrs_t *) mycalloc (DEVICES_MAX, sizeof (hm_attrs_t)); - hm_attrs_t *hm_adapters_xnvctrl = (hm_attrs_t *) mycalloc (DEVICES_MAX, sizeof (hm_attrs_t)); - - if ((opencl_ctx->need_nvml == true) && (nvml_init (nvml) == 0)) + if (opencl_ctx->need_nvml == true) { hwmon_ctx->hm_nvml = nvml; + + if (nvml_init (hashcat_ctx) == -1) + { + hcfree (hwmon_ctx->hm_nvml); + + hwmon_ctx->hm_nvml = NULL; + } + } + + if (opencl_ctx->need_nvapi == true) + { + hwmon_ctx->hm_nvapi = nvapi; + + if (nvapi_init (hashcat_ctx) == -1) + { + hcfree (hwmon_ctx->hm_nvapi); + + hwmon_ctx->hm_nvapi = NULL; + } + } + + if (opencl_ctx->need_xnvctrl == true) + { + hwmon_ctx->hm_xnvctrl = xnvctrl; + + if (xnvctrl_init (hashcat_ctx) == -1) + { + hcfree (hwmon_ctx->hm_xnvctrl); + + hwmon_ctx->hm_xnvctrl = NULL; + } + } + + if (opencl_ctx->need_adl == true) + { + hwmon_ctx->hm_adl = adl; + + if (adl_init (hashcat_ctx) == -1) + { + hcfree (hwmon_ctx->hm_adl); + + hwmon_ctx->hm_adl = NULL; + } } if (hwmon_ctx->hm_nvml) { - if (hm_NVML_nvmlInit (hwmon_ctx->hm_nvml) == NVML_SUCCESS) + if (hm_NVML_nvmlInit (hashcat_ctx) == 0) { - HM_ADAPTER_NVML *nvmlGPUHandle = (HM_ADAPTER_NVML *) mycalloc (DEVICES_MAX, sizeof (HM_ADAPTER_NVML)); + HM_ADAPTER_NVML *nvmlGPUHandle = (HM_ADAPTER_NVML *) hccalloc (hashcat_ctx, DEVICES_MAX, sizeof (HM_ADAPTER_NVML)); VERIFY_PTR (nvmlGPUHandle); - int tmp_in = hm_get_adapter_index_nvml (hwmon_ctx, nvmlGPUHandle); + int tmp_in = hm_get_adapter_index_nvml (hashcat_ctx, nvmlGPUHandle); int tmp_out = 0; @@ -894,29 +2809,24 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) { unsigned int speed; - if (hm_NVML_nvmlDeviceGetFanSpeed (hwmon_ctx->hm_nvml, 0, hm_adapters_nvml[i].nvml, &speed) == NVML_SUCCESS) hm_adapters_nvml[i].fan_get_supported = true; + if (hm_NVML_nvmlDeviceGetFanSpeed (hashcat_ctx, hm_adapters_nvml[i].nvml, &speed) == 0) hm_adapters_nvml[i].fan_get_supported = true; // doesn't seem to create any advantages - //hm_NVML_nvmlDeviceSetComputeMode (hwmon_ctx->hm_nvml, 1, hm_adapters_nvml[i].nvml, NVML_COMPUTEMODE_EXCLUSIVE_PROCESS); - //hm_NVML_nvmlDeviceSetGpuOperationMode (hwmon_ctx->hm_nvml, 1, hm_adapters_nvml[i].nvml, NVML_GOM_ALL_ON); + //hm_NVML_nvmlDeviceSetComputeMode (hashcat_ctx, hm_adapters_nvml[i].nvml, NVML_COMPUTEMODE_EXCLUSIVE_PROCESS); + //hm_NVML_nvmlDeviceSetGpuOperationMode (hashcat_ctx, hm_adapters_nvml[i].nvml, NVML_GOM_ALL_ON); } - myfree (nvmlGPUHandle); + hcfree (nvmlGPUHandle); } } - if ((opencl_ctx->need_nvapi == true) && (nvapi_init (nvapi) == 0)) - { - hwmon_ctx->hm_nvapi = nvapi; - } - if (hwmon_ctx->hm_nvapi) { - if (hm_NvAPI_Initialize (hwmon_ctx->hm_nvapi) == NVAPI_OK) + if (hm_NvAPI_Initialize (hashcat_ctx) == 0) { - HM_ADAPTER_NVAPI *nvGPUHandle = (HM_ADAPTER_NVAPI *) mycalloc (DEVICES_MAX, sizeof (HM_ADAPTER_NVAPI)); + HM_ADAPTER_NVAPI *nvGPUHandle = (HM_ADAPTER_NVAPI *) hccalloc (hashcat_ctx, DEVICES_MAX, sizeof (HM_ADAPTER_NVAPI)); VERIFY_PTR (nvGPUHandle); - int tmp_in = hm_get_adapter_index_nvapi (hwmon_ctx, nvGPUHandle); + int tmp_in = hm_get_adapter_index_nvapi (hashcat_ctx, nvGPUHandle); int tmp_out = 0; @@ -925,18 +2835,13 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) hm_adapters_nvapi[tmp_out++].nvapi = nvGPUHandle[i]; } - myfree (nvGPUHandle); + hcfree (nvGPUHandle); } } - if ((opencl_ctx->need_xnvctrl == true) && (xnvctrl_init (xnvctrl) == 0)) - { - hwmon_ctx->hm_xnvctrl = xnvctrl; - } - if (hwmon_ctx->hm_xnvctrl) { - if (hm_XNVCTRL_XOpenDisplay (hwmon_ctx->hm_xnvctrl) == 0) + if (hm_XNVCTRL_XOpenDisplay (hashcat_ctx) == 0) { for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { @@ -948,50 +2853,47 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) int speed = 0; - if (get_fan_speed_current (hwmon_ctx->hm_xnvctrl, device_id, &speed) == 0) hm_adapters_xnvctrl[device_id].fan_get_supported = true; + if (hm_XNVCTRL_get_fan_speed_current (hashcat_ctx, device_id, &speed) == 0) hm_adapters_xnvctrl[device_id].fan_get_supported = true; } } } - if ((opencl_ctx->need_adl == true) && (adl_init (adl) == 0)) - { - hwmon_ctx->hm_adl = adl; - } - if (hwmon_ctx->hm_adl) { - if (hm_ADL_Main_Control_Create (hwmon_ctx->hm_adl, ADL_Main_Memory_Alloc, 0) == ADL_OK) + if (hm_ADL_Main_Control_Create (hashcat_ctx, ADL_Main_Memory_Alloc, 0) == 0) { // total number of adapters int hm_adapters_num; - if (get_adapters_num_adl (hwmon_ctx->hm_adl, &hm_adapters_num) != 0) return -1; + if (get_adapters_num_adl (hashcat_ctx, &hm_adapters_num) == -1) return -1; // adapter info - LPAdapterInfo lpAdapterInfo = hm_get_adapter_info_adl (hwmon_ctx->hm_adl, hm_adapters_num); + LPAdapterInfo lpAdapterInfo = (LPAdapterInfo) hccalloc (hashcat_ctx, hm_adapters_num, sizeof (AdapterInfo)); VERIFY_PTR (lpAdapterInfo); - if (lpAdapterInfo == NULL) return -1; + const int rc_adapter_info_adl = hm_get_adapter_info_adl (hashcat_ctx, lpAdapterInfo, hm_adapters_num * sizeof (AdapterInfo)); + + if (rc_adapter_info_adl == -1) return -1; // get a list (of ids of) valid/usable adapters int num_adl_adapters = 0; - u32 *valid_adl_device_list = hm_get_list_valid_adl_adapters (hm_adapters_num, &num_adl_adapters, lpAdapterInfo); + u32 *valid_adl_device_list = hm_get_list_valid_adl_adapters (hashcat_ctx, hm_adapters_num, &num_adl_adapters, lpAdapterInfo); if (num_adl_adapters > 0) { - hm_get_adapter_index_adl (hm_adapters_adl, valid_adl_device_list, num_adl_adapters, lpAdapterInfo); + hm_get_adapter_index_adl (hashcat_ctx, valid_adl_device_list, num_adl_adapters, lpAdapterInfo); - hm_get_overdrive_version (hwmon_ctx->hm_adl, hm_adapters_adl, valid_adl_device_list, num_adl_adapters, lpAdapterInfo); + hm_get_overdrive_version (hashcat_ctx, hm_adapters_adl, valid_adl_device_list, num_adl_adapters, lpAdapterInfo); - hm_check_fanspeed_control (hwmon_ctx->hm_adl, hm_adapters_adl, valid_adl_device_list, num_adl_adapters, lpAdapterInfo); + hm_check_fanspeed_control (hashcat_ctx, hm_adapters_adl, valid_adl_device_list, num_adl_adapters, lpAdapterInfo); } - myfree (valid_adl_device_list); + hcfree (valid_adl_device_list); - myfree (lpAdapterInfo); + hcfree (lpAdapterInfo); } } @@ -1010,11 +2912,11 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) * save buffer required for later restores */ - hwmon_ctx->od_clock_mem_status = (ADLOD6MemClockState *) mycalloc (opencl_ctx->devices_cnt, sizeof (ADLOD6MemClockState)); + hwmon_ctx->od_clock_mem_status = (ADLOD6MemClockState *) hccalloc (hashcat_ctx, opencl_ctx->devices_cnt, sizeof (ADLOD6MemClockState)); VERIFY_PTR (hwmon_ctx->od_clock_mem_status); - hwmon_ctx->od_power_control_status = (int *) mycalloc (opencl_ctx->devices_cnt, sizeof (int)); + hwmon_ctx->od_power_control_status = (int *) hccalloc (hashcat_ctx, opencl_ctx->devices_cnt, sizeof (int)); VERIFY_PTR (hwmon_ctx->od_power_control_status); - hwmon_ctx->nvml_power_limit = (unsigned int *) mycalloc (opencl_ctx->devices_cnt, sizeof (unsigned int)); + hwmon_ctx->nvml_power_limit = (unsigned int *) hccalloc (hashcat_ctx, opencl_ctx->devices_cnt, sizeof (unsigned int)); VERIFY_PTR (hwmon_ctx->nvml_power_limit); /** * HM devices: copy @@ -1053,10 +2955,10 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) } } - myfree (hm_adapters_adl); - myfree (hm_adapters_nvapi); - myfree (hm_adapters_nvml); - myfree (hm_adapters_xnvctrl); + hcfree (hm_adapters_adl); + hcfree (hm_adapters_nvapi); + hcfree (hm_adapters_nvml); + hcfree (hm_adapters_xnvctrl); /** * powertune on user request @@ -1086,9 +2988,9 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) int powertune_supported = 0; - if ((ADL_rc = hm_ADL_Overdrive6_PowerControl_Caps (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, &powertune_supported)) != ADL_OK) + if ((ADL_rc = hm_ADL_Overdrive6_PowerControl_Caps (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, &powertune_supported)) == -1) { - log_error ("ERROR: Failed to get ADL PowerControl Capabilities"); + event_log_error (hashcat_ctx, "Failed to get ADL PowerControl Capabilities"); return -1; } @@ -1101,21 +3003,21 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) ADLOD6PowerControlInfo powertune = {0, 0, 0, 0, 0}; - if ((ADL_rc = hm_ADL_Overdrive_PowerControlInfo_Get (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, &powertune)) == ADL_OK) + if ((ADL_rc = hm_ADL_Overdrive_PowerControlInfo_Get (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, &powertune)) == ADL_OK) { - ADL_rc = hm_ADL_Overdrive_PowerControl_Get (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, &hwmon_ctx->od_power_control_status[device_id]); + ADL_rc = hm_ADL_Overdrive_PowerControl_Get (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, &hwmon_ctx->od_power_control_status[device_id]); } - if (ADL_rc != ADL_OK) + if (ADL_rc == -1) { - log_error ("ERROR: Failed to get current ADL PowerControl settings"); + event_log_error (hashcat_ctx, "Failed to get current ADL PowerControl settings"); return -1; } - if ((ADL_rc = hm_ADL_Overdrive_PowerControl_Set (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, powertune.iMaxValue)) != ADL_OK) + if ((ADL_rc = hm_ADL_Overdrive_PowerControl_Set (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, powertune.iMaxValue)) == -1) { - log_error ("ERROR: Failed to set new ADL PowerControl values"); + event_log_error (hashcat_ctx, "Failed to set new ADL PowerControl values"); return -1; } @@ -1126,9 +3028,9 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) hwmon_ctx->od_clock_mem_status[device_id].state.iNumberOfPerformanceLevels = 2; - if ((ADL_rc = hm_ADL_Overdrive_StateInfo_Get (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, ADL_OD6_GETSTATEINFO_CUSTOM_PERFORMANCE, &hwmon_ctx->od_clock_mem_status[device_id])) != ADL_OK) + if ((ADL_rc = hm_ADL_Overdrive_StateInfo_Get (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, ADL_OD6_GETSTATEINFO_CUSTOM_PERFORMANCE, &hwmon_ctx->od_clock_mem_status[device_id])) == -1) { - log_error ("ERROR: Failed to get ADL memory and engine clock frequency"); + event_log_error (hashcat_ctx, "Failed to get ADL memory and engine clock frequency"); return -1; } @@ -1137,9 +3039,9 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) ADLOD6Capabilities caps = {0, 0, 0, {0, 0, 0}, {0, 0, 0}, 0, 0}; - if ((ADL_rc = hm_ADL_Overdrive_Capabilities_Get (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, &caps)) != ADL_OK) + if ((ADL_rc = hm_ADL_Overdrive_Capabilities_Get (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, &caps)) == -1) { - log_error ("ERROR: Failed to get ADL device capabilities"); + event_log_error (hashcat_ctx, "Failed to get ADL device capabilities"); return -1; } @@ -1157,15 +3059,15 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) if ((engine_clock_max - engine_clock_profile_max) > warning_trigger_engine) { - log_info ("WARN: The custom profile seems to have too low maximum engine clock values. You therefore may not reach full performance"); + event_log_error (hashcat_ctx, "The custom profile seems to have too low maximum engine clock values. You therefore may not reach full performance"); } if ((memory_clock_max - memory_clock_profile_max) > warning_trigger_memory) { - log_info ("WARN: The custom profile seems to have too low maximum memory clock values. You therefore may not reach full performance"); + event_log_error (hashcat_ctx, "The custom profile seems to have too low maximum memory clock values. You therefore may not reach full performance"); } - ADLOD6StateInfo *performance_state = (ADLOD6StateInfo*) mycalloc (1, sizeof (ADLOD6StateInfo) + sizeof (ADLOD6PerformanceLevel)); + ADLOD6StateInfo *performance_state = (ADLOD6StateInfo*) hccalloc (hashcat_ctx, 1, sizeof (ADLOD6StateInfo) + sizeof (ADLOD6PerformanceLevel)); VERIFY_PTR (performance_state); performance_state->iNumberOfPerformanceLevels = 2; @@ -1174,14 +3076,14 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) performance_state->aLevels[0].iMemoryClock = memory_clock_profile_max; performance_state->aLevels[1].iMemoryClock = memory_clock_profile_max; - if ((ADL_rc = hm_ADL_Overdrive_State_Set (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, ADL_OD6_SETSTATE_PERFORMANCE, performance_state)) != ADL_OK) + if ((ADL_rc = hm_ADL_Overdrive_State_Set (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, ADL_OD6_SETSTATE_PERFORMANCE, performance_state)) == -1) { - log_info ("ERROR: Failed to set ADL performance state"); + event_log_error (hashcat_ctx, "Failed to set ADL performance state"); return -1; } - myfree (performance_state); + hcfree (performance_state); } // set powertune value only @@ -1191,16 +3093,16 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) // powertune set ADLOD6PowerControlInfo powertune = {0, 0, 0, 0, 0}; - if ((ADL_rc = hm_ADL_Overdrive_PowerControlInfo_Get (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, &powertune)) != ADL_OK) + if ((ADL_rc = hm_ADL_Overdrive_PowerControlInfo_Get (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, &powertune)) == -1) { - log_error ("ERROR: Failed to get current ADL PowerControl settings"); + event_log_error (hashcat_ctx, "Failed to get current ADL PowerControl settings"); return -1; } - if ((ADL_rc = hm_ADL_Overdrive_PowerControl_Set (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, powertune.iMaxValue)) != ADL_OK) + if ((ADL_rc = hm_ADL_Overdrive_PowerControl_Set (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, powertune.iMaxValue)) == -1) { - log_error ("ERROR: Failed to set new ADL PowerControl values"); + event_log_error (hashcat_ctx, "Failed to set new ADL PowerControl values"); return -1; } @@ -1216,7 +3118,7 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) bool powertune_supported = false; - if (hm_NVML_nvmlDeviceGetPowerManagementLimit (hwmon_ctx->hm_nvml, 0, hwmon_ctx->hm_device[device_id].nvml, &limit) == NVML_SUCCESS) + if (hm_NVML_nvmlDeviceGetPowerManagementLimit (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvml, &limit) == NVML_SUCCESS) { powertune_supported = true; } @@ -1228,11 +3130,11 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) unsigned int minLimit; unsigned int maxLimit; - if (hm_NVML_nvmlDeviceGetPowerManagementLimitConstraints (hwmon_ctx->hm_nvml, 0, hwmon_ctx->hm_device[device_id].nvml, &minLimit, &maxLimit) == NVML_SUCCESS) + if (hm_NVML_nvmlDeviceGetPowerManagementLimitConstraints (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvml, &minLimit, &maxLimit) == NVML_SUCCESS) { if (maxLimit > 0) { - if (hm_NVML_nvmlDeviceSetPowerManagementLimit (hwmon_ctx->hm_nvml, 0, hwmon_ctx->hm_device[device_id].nvml, maxLimit) == NVML_SUCCESS) + if (hm_NVML_nvmlDeviceSetPowerManagementLimit (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvml, maxLimit) == NVML_SUCCESS) { // now we can be sure we need to reset later @@ -1276,13 +3178,15 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) } else if (device_param->device_vendor_id == VENDOR_ID_NV) { - #if defined (__linux__) - rc = set_fan_control (hwmon_ctx->hm_xnvctrl, hwmon_ctx->hm_device[device_id].xnvctrl, NV_CTRL_GPU_COOLER_MANUAL_CONTROL_TRUE); - #endif + if (hwmon_ctx->hm_xnvctrl) + { + rc = hm_set_fanctrl_with_device_id_xnvctrl (hashcat_ctx, device_id, NV_CTRL_GPU_COOLER_MANUAL_CONTROL_TRUE); + } - #if defined (_WIN) - rc = hm_set_fanspeed_with_device_id_nvapi (hashcat_ctx, device_id, fanspeed, 1); - #endif + if (hwmon_ctx->hm_nvapi) + { + rc = hm_set_fanspeed_with_device_id_nvapi (hashcat_ctx, device_id, fanspeed, 1); + } } if (rc == 0) @@ -1291,7 +3195,7 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) } else { - log_info ("WARNING: Failed to set initial fan speed for device #%u", device_id + 1); + //event_log_error (hashcat_ctx, "Failed to set initial fan speed for device #%u", device_id + 1); hwmon_ctx->hm_device[device_id].fan_set_supported = false; } @@ -1335,16 +3239,18 @@ void hwmon_ctx_destroy (hashcat_ctx_t *hashcat_ctx) } else if (device_param->device_vendor_id == VENDOR_ID_NV) { - #if defined (__linux__) - rc = set_fan_control (hwmon_ctx->hm_xnvctrl, hwmon_ctx->hm_device[device_id].xnvctrl, NV_CTRL_GPU_COOLER_MANUAL_CONTROL_FALSE); - #endif + if (hwmon_ctx->hm_xnvctrl) + { + rc = hm_set_fanctrl_with_device_id_xnvctrl (hashcat_ctx, device_id, NV_CTRL_GPU_COOLER_MANUAL_CONTROL_FALSE); + } - #if defined (_WIN) - rc = hm_set_fanspeed_with_device_id_nvapi (hashcat_ctx, device_id, 100, 0); - #endif + if (hwmon_ctx->hm_nvapi) + { + rc = hm_set_fanspeed_with_device_id_nvapi (hashcat_ctx, device_id, 100, 0); + } } - if (rc == -1) log_info ("WARNING: Failed to restore default fan speed and policy for device #%", device_id + 1); + if (rc == -1) event_log_error (hashcat_ctx, "Failed to restore default fan speed and policy for device #%", device_id + 1); } } } @@ -1365,9 +3271,9 @@ void hwmon_ctx_destroy (hashcat_ctx_t *hashcat_ctx) int powertune_supported = 0; - if ((hm_ADL_Overdrive6_PowerControl_Caps (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, &powertune_supported)) != ADL_OK) + if ((hm_ADL_Overdrive6_PowerControl_Caps (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, &powertune_supported)) == -1) { - log_error ("ERROR: Failed to get ADL PowerControl Capabilities"); + //event_log_error (hashcat_ctx, "Failed to get ADL PowerControl Capabilities"); continue; } @@ -1376,16 +3282,16 @@ void hwmon_ctx_destroy (hashcat_ctx_t *hashcat_ctx) { // powercontrol settings - if ((hm_ADL_Overdrive_PowerControl_Set (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, hwmon_ctx->od_power_control_status[device_id])) != ADL_OK) + if ((hm_ADL_Overdrive_PowerControl_Set (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, hwmon_ctx->od_power_control_status[device_id])) == -1) { - log_info ("ERROR: Failed to restore the ADL PowerControl values"); + //event_log_error (hashcat_ctx, "Failed to restore the ADL PowerControl values"); continue; } // clocks - ADLOD6StateInfo *performance_state = (ADLOD6StateInfo*) mycalloc (1, sizeof (ADLOD6StateInfo) + sizeof (ADLOD6PerformanceLevel)); + ADLOD6StateInfo *performance_state = (ADLOD6StateInfo*) hccalloc (hashcat_ctx, 1, sizeof (ADLOD6StateInfo) + sizeof (ADLOD6PerformanceLevel)); performance_state->iNumberOfPerformanceLevels = 2; @@ -1394,14 +3300,14 @@ void hwmon_ctx_destroy (hashcat_ctx_t *hashcat_ctx) performance_state->aLevels[0].iMemoryClock = hwmon_ctx->od_clock_mem_status[device_id].state.aLevels[0].iMemoryClock; performance_state->aLevels[1].iMemoryClock = hwmon_ctx->od_clock_mem_status[device_id].state.aLevels[1].iMemoryClock; - if ((hm_ADL_Overdrive_State_Set (hwmon_ctx->hm_adl, hwmon_ctx->hm_device[device_id].adl, ADL_OD6_SETSTATE_PERFORMANCE, performance_state)) != ADL_OK) + if ((hm_ADL_Overdrive_State_Set (hashcat_ctx, hwmon_ctx->hm_device[device_id].adl, ADL_OD6_SETSTATE_PERFORMANCE, performance_state)) == -1) { - log_info ("ERROR: Failed to restore ADL performance state"); + //event_log_info (hashcat_ctx, "Failed to restore ADL performance state"); continue; } - myfree (performance_state); + hcfree (performance_state); } } } @@ -1412,7 +3318,7 @@ void hwmon_ctx_destroy (hashcat_ctx_t *hashcat_ctx) if (power_limit > 0) { - hm_NVML_nvmlDeviceSetPowerManagementLimit (hwmon_ctx->hm_nvml, 0, hwmon_ctx->hm_device[device_id].nvml, power_limit); + hm_NVML_nvmlDeviceSetPowerManagementLimit (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvml, power_limit); } } } @@ -1421,39 +3327,39 @@ void hwmon_ctx_destroy (hashcat_ctx_t *hashcat_ctx) if (hwmon_ctx->hm_nvml) { - hm_NVML_nvmlShutdown (hwmon_ctx->hm_nvml); + hm_NVML_nvmlShutdown (hashcat_ctx); - nvml_close (hwmon_ctx->hm_nvml); + nvml_close (hashcat_ctx); } if (hwmon_ctx->hm_nvapi) { - hm_NvAPI_Unload (hwmon_ctx->hm_nvapi); + hm_NvAPI_Unload (hashcat_ctx); - nvapi_close (hwmon_ctx->hm_nvapi); + nvapi_close (hashcat_ctx); } if (hwmon_ctx->hm_xnvctrl) { - hm_XNVCTRL_XCloseDisplay (hwmon_ctx->hm_xnvctrl); + hm_XNVCTRL_XCloseDisplay (hashcat_ctx); - xnvctrl_close (hwmon_ctx->hm_xnvctrl); + xnvctrl_close (hashcat_ctx); } if (hwmon_ctx->hm_adl) { - hm_ADL_Main_Control_Destroy (hwmon_ctx->hm_adl); + hm_ADL_Main_Control_Destroy (hashcat_ctx); - adl_close (hwmon_ctx->hm_adl); + adl_close (hashcat_ctx); } // free memory - myfree (hwmon_ctx->nvml_power_limit); - myfree (hwmon_ctx->od_power_control_status); - myfree (hwmon_ctx->od_clock_mem_status); + hcfree (hwmon_ctx->nvml_power_limit); + hcfree (hwmon_ctx->od_power_control_status); + hcfree (hwmon_ctx->od_clock_mem_status); - myfree (hwmon_ctx->hm_device); + hcfree (hwmon_ctx->hm_device); memset (hwmon_ctx, 0, sizeof (hwmon_ctx_t)); } diff --git a/src/induct.c b/src/induct.c index 61a0f454e..757157419 100644 --- a/src/induct.c +++ b/src/induct.c @@ -6,7 +6,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "folder.h" #include "induct.h" @@ -36,6 +36,7 @@ int induct_ctx_init (hashcat_ctx_t *hashcat_ctx) if (user_options->opencl_info == true) return 0; if (user_options->show == true) return 0; if (user_options->stdout_flag == true) return 0; + if (user_options->speed_only == true) return 0; if (user_options->usage == true) return 0; if (user_options->version == true) return 0; @@ -46,7 +47,7 @@ int induct_ctx_init (hashcat_ctx_t *hashcat_ctx) if (user_options->induction_dir == NULL) { - char *root_directory = (char *) mymalloc (HCBUFSIZ_TINY); + char *root_directory = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (root_directory); snprintf (root_directory, HCBUFSIZ_TINY - 1, "%s/%s.%s", folder_config->session_dir, user_options->session, INDUCT_DIR); @@ -58,20 +59,20 @@ int induct_ctx_init (hashcat_ctx_t *hashcat_ctx) } else if (errno == ENOTEMPTY) { - char *root_directory_mv = (char *) mymalloc (HCBUFSIZ_TINY); + char *root_directory_mv = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (root_directory_mv); snprintf (root_directory_mv, HCBUFSIZ_TINY - 1, "%s/%s.induct.%d", folder_config->session_dir, user_options->session, (int) status_ctx->proc_start); if (rename (root_directory, root_directory_mv) != 0) { - log_error ("ERROR: Rename directory %s to %s: %s", root_directory, root_directory_mv, strerror (errno)); + event_log_error (hashcat_ctx, "Rename directory %s to %s: %s", root_directory, root_directory_mv, strerror (errno)); return -1; } } else { - log_error ("ERROR: %s: %s", root_directory, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", root_directory, strerror (errno)); return -1; } @@ -79,7 +80,7 @@ int induct_ctx_init (hashcat_ctx_t *hashcat_ctx) if (hc_mkdir (root_directory, 0700) == -1) { - log_error ("ERROR: %s: %s", root_directory, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", root_directory, strerror (errno)); return -1; } @@ -88,7 +89,7 @@ int induct_ctx_init (hashcat_ctx_t *hashcat_ctx) } else { - induct_ctx->root_directory = mystrdup (user_options->induction_dir); + induct_ctx->root_directory = hcstrdup (hashcat_ctx, user_options->induction_dir); } return 0; @@ -100,7 +101,7 @@ void induct_ctx_scan (hashcat_ctx_t *hashcat_ctx) if (induct_ctx->enabled == false) return; - induct_ctx->induction_dictionaries = scan_directory (induct_ctx->root_directory); + induct_ctx->induction_dictionaries = scan_directory (hashcat_ctx, induct_ctx->root_directory); induct_ctx->induction_dictionaries_cnt = count_dictionaries (induct_ctx->induction_dictionaries); @@ -142,13 +143,13 @@ void induct_ctx_destroy (hashcat_ctx_t *hashcat_ctx) } else { - log_error ("ERROR: %s: %s", induct_ctx->root_directory, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", induct_ctx->root_directory, strerror (errno)); //return -1; } } - myfree (induct_ctx->root_directory); + hcfree (induct_ctx->root_directory); memset (induct_ctx, 0, sizeof (induct_ctx_t)); } diff --git a/src/interface.c b/src/interface.c index f74199071..4f5782968 100644 --- a/src/interface.c +++ b/src/interface.c @@ -12,7 +12,7 @@ #include "bitops.h" #include "memory.h" #include "convert.h" -#include "logging.h" +#include "event.h" #include "inc_hash_constants.h" #include "cpu_aes.h" #include "cpu_crc32.h" @@ -59,7 +59,8 @@ static const char PA_013[] = "Invalid psafe2 filesize"; static const char PA_014[] = "Invalid psafe3 filesize"; static const char PA_015[] = "Invalid truecrypt filesize"; static const char PA_016[] = "Invalid veracrypt filesize"; -//static const char PA_017[] = "Invalid SIP directive, only MD5 is supported"; +static const char PA_017[] = "Invalid SIP directive, only MD5 is supported"; +static const char PA_018[] = "Hash-file exception"; static const char PA_255[] = "Unknown error"; static const char HT_00000[] = "MD5"; @@ -1999,7 +2000,7 @@ static void drupal7_encode (u8 digest[64], u8 buf[43]) * parser */ -static u32 parse_and_store_salt (char *out, char *in, u32 salt_len, const hashconfig_t *hashconfig) +static u32 parse_and_store_salt (char *out, char *in, u32 salt_len, MAYBE_UNUSED const hashconfig_t *hashconfig) { u8 tmp[256] = { 0 }; @@ -2114,10 +2115,7 @@ static u32 parse_and_store_salt (char *out, char *in, u32 salt_len, const hashco return (salt_len); } -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" - -int bcrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int bcrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_3200) || (input_len > DISPLAY_LEN_MAX_3200)) return (PARSER_GLOBAL_LENGTH); @@ -2176,7 +2174,7 @@ int bcrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int cisco4_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int cisco4_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_5700) || (input_len > DISPLAY_LEN_MAX_5700)) return (PARSER_GLOBAL_LENGTH); @@ -2209,7 +2207,7 @@ int cisco4_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int lm_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int lm_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_3000) || (input_len > DISPLAY_LEN_MAX_3000)) return (PARSER_GLOBAL_LENGTH); @@ -2233,7 +2231,7 @@ int lm_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashc return (PARSER_OK); } -int arubaos_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int arubaos_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_125) || (input_len > DISPLAY_LEN_MAX_125)) return (PARSER_GLOBAL_LENGTH); @@ -2270,7 +2268,7 @@ int arubaos_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int osx1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int osx1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_122) || (input_len > DISPLAY_LEN_MAX_122)) return (PARSER_GLOBAL_LENGTH); @@ -2305,7 +2303,7 @@ int osx1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int osx512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int osx512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_1722) || (input_len > DISPLAY_LEN_MAX_1722)) return (PARSER_GLOBAL_LENGTH); @@ -2346,7 +2344,7 @@ int osx512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int osc_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int osc_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -2393,7 +2391,7 @@ int osc_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hash return (PARSER_OK); } -int netscreen_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int netscreen_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -2509,7 +2507,7 @@ int netscreen_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int smf_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int smf_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -2553,7 +2551,7 @@ int smf_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hash return (PARSER_OK); } -int dcc2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int dcc2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -2611,7 +2609,7 @@ int dcc2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int wpa_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int wpa_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { u32 *digest = (u32 *) hash_buf->digest; @@ -2638,12 +2636,7 @@ int wpa_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hash u32 salt_len = strlen (in.essid); - if (salt_len > 36) - { - log_info ("WARNING: The ESSID length is too long, the hccap file may be invalid or corrupted"); - - return (PARSER_SALT_LENGTH); - } + if (salt_len > 36) return (PARSER_SALT_LENGTH); memcpy (salt->salt_buf, in.essid, salt_len); @@ -2691,11 +2684,12 @@ int wpa_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hash if (wpa->keyver > 255) { - log_info ("ATTENTION!"); - log_info (" The WPA/WPA2 key version in your .hccap file is invalid!"); - log_info (" This could be due to a recent aircrack-ng bug."); - log_info (" The key version was automatically reset to a reasonable value."); - log_info (""); + // not sure yet how to transport this message + //event_log_warning (hashcat_ctx, "ATTENTION!"); + //event_log_warning (hashcat_ctx, " The WPA/WPA2 key version in your .hccap file is invalid!"); + //event_log_warning (hashcat_ctx, " This could be due to a recent aircrack-ng bug."); + //event_log_warning (hashcat_ctx, " The key version was automatically reset to a reasonable value."); + //event_log_warning (hashcat_ctx, ""); wpa->keyver &= 0xff; } @@ -2740,27 +2734,17 @@ int wpa_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hash return (PARSER_OK); } -int psafe2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int psafe2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { u32 *digest = (u32 *) hash_buf->digest; salt_t *salt = hash_buf->salt; - if (input_len == 0) - { - log_error ("Password Safe v2 container not specified"); - - exit (-1); - } + if (input_len == 0) return (PARSER_HASH_LENGTH); FILE *fp = fopen (input_buf, "rb"); - if (fp == NULL) - { - log_error ("%s: %s", input_buf, strerror (errno)); - - exit (-1); - } + if (fp == NULL) return (PARSER_HASH_FILE); psafe2_hdr buf; @@ -2787,27 +2771,17 @@ int psafe2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int psafe3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int psafe3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { u32 *digest = (u32 *) hash_buf->digest; salt_t *salt = hash_buf->salt; - if (input_len == 0) - { - log_error (".psafe3 not specified"); - - exit (-1); - } + if (input_len == 0) return (PARSER_HASH_LENGTH); FILE *fp = fopen (input_buf, "rb"); - if (fp == NULL) - { - log_error ("%s: %s", input_buf, strerror (errno)); - - exit (-1); - } + if (fp == NULL) return (PARSER_HASH_FILE); psafe3_t in; @@ -2853,7 +2827,7 @@ int psafe3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int phpass_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int phpass_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_400) || (input_len > DISPLAY_LEN_MAX_400)) return (PARSER_GLOBAL_LENGTH); @@ -2888,7 +2862,7 @@ int phpass_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int md5crypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int md5crypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (input_len < DISPLAY_LEN_MIN_500) return (PARSER_GLOBAL_LENGTH); @@ -2949,7 +2923,7 @@ int md5crypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int md5apr1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int md5apr1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (memcmp (SIGNATURE_MD5APR1, input_buf, 6)) return (PARSER_SIGNATURE_UNMATCHED); @@ -3004,7 +2978,7 @@ int md5apr1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int episerver_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int episerver_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_141) || (input_len > DISPLAY_LEN_MAX_141)) return (PARSER_GLOBAL_LENGTH); @@ -3053,7 +3027,7 @@ int episerver_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int descrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int descrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_1500) || (input_len > DISPLAY_LEN_MAX_1500)) return (PARSER_GLOBAL_LENGTH); @@ -3090,7 +3064,7 @@ int descrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int md4_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int md4_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_900) || (input_len > DISPLAY_LEN_MAX_900)) return (PARSER_GLOBAL_LENGTH); @@ -3114,7 +3088,7 @@ int md4_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hash return (PARSER_OK); } -int md4s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int md4s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -3161,7 +3135,7 @@ int md4s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_0) || (input_len > DISPLAY_LEN_MAX_0)) return (PARSER_GLOBAL_LENGTH); @@ -3185,7 +3159,7 @@ int md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hash return (PARSER_OK); } -int md5half_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int md5half_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_5100) || (input_len > DISPLAY_LEN_MAX_5100)) return (PARSER_GLOBAL_LENGTH); @@ -3202,7 +3176,7 @@ int md5half_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int md5s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int md5s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -3249,7 +3223,7 @@ int md5s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int md5pix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int md5pix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_2400) || (input_len > DISPLAY_LEN_MAX_2400)) return (PARSER_GLOBAL_LENGTH); @@ -3285,7 +3259,7 @@ int md5pix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int md5asa_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int md5asa_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -3365,7 +3339,7 @@ static void transform_netntlmv1_key (const u8 *nthash, u8 *key) key[7] |= 0x01; } -int netntlmv1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int netntlmv1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_5500) || (input_len > DISPLAY_LEN_MAX_5500)) return (PARSER_GLOBAL_LENGTH); @@ -3601,7 +3575,7 @@ int netntlmv1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int netntlmv2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int netntlmv2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_5600) || (input_len > DISPLAY_LEN_MAX_5600)) return (PARSER_GLOBAL_LENGTH); @@ -3779,7 +3753,7 @@ int netntlmv2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int joomla_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int joomla_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -3826,7 +3800,7 @@ int joomla_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int postgresql_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int postgresql_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -3873,7 +3847,7 @@ int postgresql_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int md5md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int md5md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_2600) || (input_len > DISPLAY_LEN_MAX_2600)) return (PARSER_GLOBAL_LENGTH); @@ -3913,7 +3887,7 @@ int md5md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int vb3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int vb3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -3960,7 +3934,7 @@ int vb3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hash return (PARSER_OK); } -int vb30_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int vb30_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -4002,7 +3976,7 @@ int vb30_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int dcc_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int dcc_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -4049,7 +4023,7 @@ int dcc_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hash return (PARSER_OK); } -int ipb2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int ipb2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -4117,7 +4091,7 @@ int ipb2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_100) || (input_len > DISPLAY_LEN_MAX_100)) return (PARSER_GLOBAL_LENGTH); @@ -4138,7 +4112,7 @@ int sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int sha1axcrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha1axcrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_13300) || (input_len > DISPLAY_LEN_MAX_13300)) return (PARSER_GLOBAL_LENGTH); @@ -4157,7 +4131,7 @@ int sha1axcrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, co return (PARSER_OK); } -int sha1s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha1s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -4201,7 +4175,7 @@ int sha1s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const ha return (PARSER_OK); } -int pstoken_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int pstoken_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_13500) || (input_len > DISPLAY_LEN_MAX_13500)) return (PARSER_GLOBAL_LENGTH); @@ -4287,7 +4261,7 @@ int pstoken_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int sha1b64_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha1b64_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_101) || (input_len > DISPLAY_LEN_MAX_101)) return (PARSER_GLOBAL_LENGTH); @@ -4316,7 +4290,7 @@ int sha1b64_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int sha1b64s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha1b64s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_111) || (input_len > DISPLAY_LEN_MAX_111)) return (PARSER_GLOBAL_LENGTH); @@ -4364,7 +4338,7 @@ int sha1b64s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int mssql2000_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int mssql2000_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_131) || (input_len > DISPLAY_LEN_MAX_131)) return (PARSER_GLOBAL_LENGTH); @@ -4403,7 +4377,7 @@ int mssql2000_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int mssql2005_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int mssql2005_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_132) || (input_len > DISPLAY_LEN_MAX_132)) return (PARSER_GLOBAL_LENGTH); @@ -4442,7 +4416,7 @@ int mssql2005_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int mssql2012_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int mssql2012_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_1731) || (input_len > DISPLAY_LEN_MAX_1731)) return (PARSER_GLOBAL_LENGTH); @@ -4487,7 +4461,7 @@ int mssql2012_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int oracleh_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int oracleh_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -4527,7 +4501,7 @@ int oracleh_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int oracles_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int oracles_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_112) || (input_len > DISPLAY_LEN_MAX_112)) return (PARSER_GLOBAL_LENGTH); @@ -4564,7 +4538,7 @@ int oracles_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int oraclet_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int oraclet_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_12300) || (input_len > DISPLAY_LEN_MAX_12300)) return (PARSER_GLOBAL_LENGTH); @@ -4604,7 +4578,7 @@ int oraclet_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int sha256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_1400) || (input_len > DISPLAY_LEN_MAX_1400)) return (PARSER_GLOBAL_LENGTH); @@ -4631,7 +4605,7 @@ int sha256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int sha256s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha256s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -4681,7 +4655,7 @@ int sha256s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int sha384_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha384_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_10800) || (input_len > DISPLAY_LEN_MAX_10800)) return (PARSER_GLOBAL_LENGTH); @@ -4708,7 +4682,7 @@ int sha384_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int sha512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_1700) || (input_len > DISPLAY_LEN_MAX_1700)) return (PARSER_GLOBAL_LENGTH); @@ -4735,7 +4709,7 @@ int sha512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int sha512s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha512s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -4785,7 +4759,7 @@ int sha512s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int sha512crypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha512crypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (memcmp (SIGNATURE_SHA512CRYPT, input_buf, 3)) return (PARSER_SIGNATURE_UNMATCHED); @@ -4840,7 +4814,7 @@ int sha512crypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, co return (PARSER_OK); } -int keccak_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int keccak_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_5000) || (input_len > DISPLAY_LEN_MAX_5000)) return (PARSER_GLOBAL_LENGTH); @@ -4864,7 +4838,7 @@ int keccak_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int ikepsk_md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int ikepsk_md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_5300) || (input_len > DISPLAY_LEN_MAX_5300)) return (PARSER_GLOBAL_LENGTH); @@ -4951,7 +4925,7 @@ int ikepsk_md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int ikepsk_sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int ikepsk_sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_5400) || (input_len > DISPLAY_LEN_MAX_5400)) return (PARSER_GLOBAL_LENGTH); @@ -5034,7 +5008,7 @@ int ikepsk_sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, co return (PARSER_OK); } -int ripemd160_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int ripemd160_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_6000) || (input_len > DISPLAY_LEN_MAX_6000)) return (PARSER_GLOBAL_LENGTH); @@ -5055,7 +5029,7 @@ int ripemd160_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int whirlpool_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int whirlpool_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_6100) || (input_len > DISPLAY_LEN_MAX_6100)) return (PARSER_GLOBAL_LENGTH); @@ -5081,7 +5055,7 @@ int whirlpool_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int androidpin_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int androidpin_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_5800) || (input_len > DISPLAY_LEN_MAX_5800)) return (PARSER_GLOBAL_LENGTH); @@ -5114,7 +5088,7 @@ int androidpin_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int truecrypt_parse_hash_1k (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int truecrypt_parse_hash_1k (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { u32 *digest = (u32 *) hash_buf->digest; @@ -5122,21 +5096,11 @@ int truecrypt_parse_hash_1k (char *input_buf, u32 input_len, hash_t *hash_buf, c tc_t *tc = (tc_t *) hash_buf->esalt; - if (input_len == 0) - { - log_error ("TrueCrypt container not specified"); - - exit (-1); - } + if (input_len == 0) return (PARSER_HASH_LENGTH); FILE *fp = fopen (input_buf, "rb"); - if (fp == NULL) - { - log_error ("%s: %s", input_buf, strerror (errno)); - - exit (-1); - } + if (fp == NULL) return (PARSER_HASH_FILE); char buf[512] = { 0 }; @@ -5163,7 +5127,7 @@ int truecrypt_parse_hash_1k (char *input_buf, u32 input_len, hash_t *hash_buf, c return (PARSER_OK); } -int truecrypt_parse_hash_2k (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int truecrypt_parse_hash_2k (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { u32 *digest = (u32 *) hash_buf->digest; @@ -5171,21 +5135,11 @@ int truecrypt_parse_hash_2k (char *input_buf, u32 input_len, hash_t *hash_buf, c tc_t *tc = (tc_t *) hash_buf->esalt; - if (input_len == 0) - { - log_error ("TrueCrypt container not specified"); - - exit (-1); - } + if (input_len == 0) return (PARSER_HASH_LENGTH); FILE *fp = fopen (input_buf, "rb"); - if (fp == NULL) - { - log_error ("%s: %s", input_buf, strerror (errno)); - - exit (-1); - } + if (fp == NULL) return (PARSER_HASH_FILE); char buf[512] = { 0 }; @@ -5212,7 +5166,7 @@ int truecrypt_parse_hash_2k (char *input_buf, u32 input_len, hash_t *hash_buf, c return (PARSER_OK); } -int veracrypt_parse_hash_200000 (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int veracrypt_parse_hash_200000 (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { u32 *digest = (u32 *) hash_buf->digest; @@ -5220,21 +5174,11 @@ int veracrypt_parse_hash_200000 (char *input_buf, u32 input_len, hash_t *hash_bu tc_t *tc = (tc_t *) hash_buf->esalt; - if (input_len == 0) - { - log_error ("VeraCrypt container not specified"); - - exit (-1); - } + if (input_len == 0) return (PARSER_HASH_LENGTH); FILE *fp = fopen (input_buf, "rb"); - if (fp == NULL) - { - log_error ("%s: %s", input_buf, strerror (errno)); - - exit (-1); - } + if (fp == NULL) return (PARSER_HASH_FILE); char buf[512] = { 0 }; @@ -5261,7 +5205,7 @@ int veracrypt_parse_hash_200000 (char *input_buf, u32 input_len, hash_t *hash_bu return (PARSER_OK); } -int veracrypt_parse_hash_500000 (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int veracrypt_parse_hash_500000 (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { u32 *digest = (u32 *) hash_buf->digest; @@ -5269,21 +5213,11 @@ int veracrypt_parse_hash_500000 (char *input_buf, u32 input_len, hash_t *hash_bu tc_t *tc = (tc_t *) hash_buf->esalt; - if (input_len == 0) - { - log_error ("VeraCrypt container not specified"); - - exit (-1); - } + if (input_len == 0) return (PARSER_HASH_LENGTH); FILE *fp = fopen (input_buf, "rb"); - if (fp == NULL) - { - log_error ("%s: %s", input_buf, strerror (errno)); - - exit (-1); - } + if (fp == NULL) return (PARSER_HASH_FILE); char buf[512] = { 0 }; @@ -5310,7 +5244,7 @@ int veracrypt_parse_hash_500000 (char *input_buf, u32 input_len, hash_t *hash_bu return (PARSER_OK); } -int veracrypt_parse_hash_327661 (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int veracrypt_parse_hash_327661 (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { u32 *digest = (u32 *) hash_buf->digest; @@ -5318,21 +5252,11 @@ int veracrypt_parse_hash_327661 (char *input_buf, u32 input_len, hash_t *hash_bu tc_t *tc = (tc_t *) hash_buf->esalt; - if (input_len == 0) - { - log_error ("VeraCrypt container not specified"); - - exit (-1); - } + if (input_len == 0) return (PARSER_HASH_LENGTH); FILE *fp = fopen (input_buf, "rb"); - if (fp == NULL) - { - log_error ("%s: %s", input_buf, strerror (errno)); - - exit (-1); - } + if (fp == NULL) return (PARSER_HASH_FILE); char buf[512] = { 0 }; @@ -5359,7 +5283,7 @@ int veracrypt_parse_hash_327661 (char *input_buf, u32 input_len, hash_t *hash_bu return (PARSER_OK); } -int veracrypt_parse_hash_655331 (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int veracrypt_parse_hash_655331 (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { u32 *digest = (u32 *) hash_buf->digest; @@ -5367,21 +5291,11 @@ int veracrypt_parse_hash_655331 (char *input_buf, u32 input_len, hash_t *hash_bu tc_t *tc = (tc_t *) hash_buf->esalt; - if (input_len == 0) - { - log_error ("VeraCrypt container not specified"); - - exit (-1); - } + if (input_len == 0) return (PARSER_HASH_LENGTH); FILE *fp = fopen (input_buf, "rb"); - if (fp == NULL) - { - log_error ("%s: %s", input_buf, strerror (errno)); - - exit (-1); - } + if (fp == NULL) return (PARSER_HASH_FILE); char buf[512] = { 0 }; @@ -5408,7 +5322,7 @@ int veracrypt_parse_hash_655331 (char *input_buf, u32 input_len, hash_t *hash_bu return (PARSER_OK); } -int md5aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int md5aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_6300) || (input_len > DISPLAY_LEN_MAX_6300)) return (PARSER_GLOBAL_LENGTH); @@ -5441,7 +5355,7 @@ int md5aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int sha1aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha1aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_6700) || (input_len > DISPLAY_LEN_MAX_6700)) return (PARSER_GLOBAL_LENGTH); @@ -5490,7 +5404,7 @@ int sha1aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int sha256aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha256aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_6400) || (input_len > DISPLAY_LEN_MAX_6400)) return (PARSER_GLOBAL_LENGTH); @@ -5542,7 +5456,7 @@ int sha256aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int sha512aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha512aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_6500) || (input_len > DISPLAY_LEN_MAX_6500)) return (PARSER_GLOBAL_LENGTH); @@ -5594,7 +5508,7 @@ int sha512aix_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int agilekey_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int agilekey_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_6600) || (input_len > DISPLAY_LEN_MAX_6600)) return (PARSER_GLOBAL_LENGTH); @@ -5661,7 +5575,7 @@ int agilekey_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const * handle cipher encoding */ - u32 *tmp = (u32 *) mymalloc (32); + u32 tmp[32]; char *cipherbuf_ptr = (char *) tmp; @@ -5687,8 +5601,6 @@ int agilekey_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const salt->salt_buf[10] = byte_swap_32 (tmp[6]); salt->salt_buf[11] = byte_swap_32 (tmp[7]); - myfree (tmp); - for (u32 i = 0, j = 0; i < 1040; i += 1, j += 2) { const char p0 = cipherbuf_pos[j + 0]; @@ -5710,7 +5622,7 @@ int agilekey_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int lastpass_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int lastpass_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_6800) || (input_len > DISPLAY_LEN_MAX_6800)) return (PARSER_GLOBAL_LENGTH); @@ -5760,7 +5672,7 @@ int lastpass_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int gost_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int gost_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_6900) || (input_len > DISPLAY_LEN_MAX_6900)) return (PARSER_GLOBAL_LENGTH); @@ -5787,7 +5699,7 @@ int gost_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int sha256crypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha256crypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (memcmp (SIGNATURE_SHA256CRYPT, input_buf, 3)) return (PARSER_SIGNATURE_UNMATCHED); @@ -5842,7 +5754,7 @@ int sha256crypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, co return (PARSER_OK); } -int sha512osx_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha512osx_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { u32 max_len = DISPLAY_LEN_MAX_7100 + (2 * 128); @@ -5914,7 +5826,7 @@ int sha512osx_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int episerver4_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int episerver4_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_1441) || (input_len > DISPLAY_LEN_MAX_1441)) return (PARSER_GLOBAL_LENGTH); @@ -5969,7 +5881,7 @@ int episerver4_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int sha512grub_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha512grub_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { u32 max_len = DISPLAY_LEN_MAX_7200 + (8 * 128); @@ -6033,7 +5945,7 @@ int sha512grub_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int sha512b64s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sha512b64s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_1711) || (input_len > DISPLAY_LEN_MAX_1711)) return (PARSER_GLOBAL_LENGTH); @@ -6087,7 +5999,7 @@ int sha512b64s_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int hmacmd5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int hmacmd5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -6129,7 +6041,7 @@ int hmacmd5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int hmacsha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int hmacsha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -6167,7 +6079,7 @@ int hmacsha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int hmacsha256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int hmacsha256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -6208,7 +6120,7 @@ int hmacsha256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int hmacsha512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int hmacsha512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (hashconfig->opts_type & OPTS_TYPE_ST_HEX) { @@ -6249,7 +6161,7 @@ int hmacsha512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int krb5pa_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int krb5pa_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_7500) || (input_len > DISPLAY_LEN_MAX_7500)) return (PARSER_GLOBAL_LENGTH); @@ -6355,7 +6267,7 @@ int krb5pa_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int sapb_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sapb_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_7700) || (input_len > DISPLAY_LEN_MAX_7700)) return (PARSER_GLOBAL_LENGTH); @@ -6425,7 +6337,7 @@ int sapb_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int sapg_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sapg_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_7800) || (input_len > DISPLAY_LEN_MAX_7800)) return (PARSER_GLOBAL_LENGTH); @@ -6497,7 +6409,7 @@ int sapg_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int drupal7_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int drupal7_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_7900) || (input_len > DISPLAY_LEN_MAX_7900)) return (PARSER_GLOBAL_LENGTH); @@ -6549,7 +6461,7 @@ int drupal7_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int sybasease_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sybasease_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_8000) || (input_len > DISPLAY_LEN_MAX_8000)) return (PARSER_GLOBAL_LENGTH); @@ -6585,7 +6497,7 @@ int sybasease_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int mysql323_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int mysql323_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_200) || (input_len > DISPLAY_LEN_MAX_200)) return (PARSER_GLOBAL_LENGTH); @@ -6599,7 +6511,7 @@ int mysql323_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int rakp_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int rakp_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_7300) || (input_len > DISPLAY_LEN_MAX_7300)) return (PARSER_GLOBAL_LENGTH); @@ -6668,7 +6580,7 @@ int rakp_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int netscaler_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int netscaler_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_8100) || (input_len > DISPLAY_LEN_MAX_8100)) return (PARSER_GLOBAL_LENGTH); @@ -6704,7 +6616,7 @@ int netscaler_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int chap_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int chap_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_4800) || (input_len > DISPLAY_LEN_MAX_4800)) return (PARSER_GLOBAL_LENGTH); @@ -6754,7 +6666,7 @@ int chap_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int cloudkey_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int cloudkey_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_8200) || (input_len > DISPLAY_LEN_MAX_8200)) return (PARSER_GLOBAL_LENGTH); @@ -6864,7 +6776,7 @@ int cloudkey_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int nsec3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int nsec3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_8300) || (input_len > DISPLAY_LEN_MAX_8300)) return (PARSER_GLOBAL_LENGTH); @@ -6978,7 +6890,7 @@ int nsec3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const ha return (PARSER_OK); } -int wbb3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int wbb3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_8400) || (input_len > DISPLAY_LEN_MAX_8400)) return (PARSER_GLOBAL_LENGTH); @@ -7009,7 +6921,7 @@ int wbb3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int opencart_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int opencart_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_13900) || (input_len > DISPLAY_LEN_MAX_13900)) return (PARSER_GLOBAL_LENGTH); @@ -7040,7 +6952,7 @@ int opencart_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int racf_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int racf_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { const u8 ascii_to_ebcdic[] = { @@ -7127,7 +7039,7 @@ int racf_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int des_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int des_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_14000) || (input_len > DISPLAY_LEN_MAX_14000)) return (PARSER_GLOBAL_LENGTH); @@ -7182,7 +7094,7 @@ int des_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hash return (PARSER_OK); } -int lotus5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int lotus5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_8600) || (input_len > DISPLAY_LEN_MAX_8600)) return (PARSER_GLOBAL_LENGTH); @@ -7201,7 +7113,7 @@ int lotus5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int lotus6_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int lotus6_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_8700) || (input_len > DISPLAY_LEN_MAX_8700)) return (PARSER_GLOBAL_LENGTH); @@ -7230,7 +7142,7 @@ int lotus6_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int lotus8_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int lotus8_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_9100) || (input_len > DISPLAY_LEN_MAX_9100)) return (PARSER_GLOBAL_LENGTH); @@ -7286,7 +7198,7 @@ int lotus8_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int hmailserver_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int hmailserver_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_1421) || (input_len > DISPLAY_LEN_MAX_1421)) return (PARSER_GLOBAL_LENGTH); @@ -7327,7 +7239,7 @@ int hmailserver_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, co return (PARSER_OK); } -int phps_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int phps_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_2612) || (input_len > DISPLAY_LEN_MAX_2612)) return (PARSER_GLOBAL_LENGTH); @@ -7373,7 +7285,7 @@ int phps_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int mediawiki_b_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int mediawiki_b_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_3711) || (input_len > DISPLAY_LEN_MAX_3711)) return (PARSER_GLOBAL_LENGTH); @@ -7421,7 +7333,7 @@ int mediawiki_b_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, co return (PARSER_OK); } -int peoplesoft_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int peoplesoft_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_133) || (input_len > DISPLAY_LEN_MAX_133)) return (PARSER_GLOBAL_LENGTH); @@ -7454,7 +7366,7 @@ int peoplesoft_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int skype_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int skype_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_23) || (input_len > DISPLAY_LEN_MAX_23)) return (PARSER_GLOBAL_LENGTH); @@ -7502,7 +7414,7 @@ int skype_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const ha return (PARSER_OK); } -int androidfde_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int androidfde_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_8800) || (input_len > DISPLAY_LEN_MAX_8800)) return (PARSER_GLOBAL_LENGTH); @@ -7594,7 +7506,7 @@ int androidfde_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int scrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int scrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_8900) || (input_len > DISPLAY_LEN_MAX_8900)) return (PARSER_GLOBAL_LENGTH); @@ -7684,7 +7596,7 @@ int scrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int juniper_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int juniper_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_501) || (input_len > DISPLAY_LEN_MAX_501)) return (PARSER_GLOBAL_LENGTH); @@ -7721,7 +7633,7 @@ int juniper_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int cisco8_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int cisco8_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_9200) || (input_len > DISPLAY_LEN_MAX_9200)) return (PARSER_GLOBAL_LENGTH); @@ -7792,7 +7704,7 @@ int cisco8_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int cisco9_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int cisco9_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_9300) || (input_len > DISPLAY_LEN_MAX_9300)) return (PARSER_GLOBAL_LENGTH); @@ -7847,7 +7759,7 @@ int cisco9_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int office2007_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int office2007_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_9400) || (input_len > DISPLAY_LEN_MAX_9400)) return (PARSER_GLOBAL_LENGTH); @@ -7986,7 +7898,7 @@ int office2007_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int office2010_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int office2010_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_9500) || (input_len > DISPLAY_LEN_MAX_9500)) return (PARSER_GLOBAL_LENGTH); @@ -8126,7 +8038,7 @@ int office2010_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int office2013_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int office2013_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_9600) || (input_len > DISPLAY_LEN_MAX_9600)) return (PARSER_GLOBAL_LENGTH); @@ -8266,7 +8178,7 @@ int office2013_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int oldoffice01_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int oldoffice01_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_9700) || (input_len > DISPLAY_LEN_MAX_9700)) return (PARSER_GLOBAL_LENGTH); @@ -8389,12 +8301,12 @@ int oldoffice01_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, co return (PARSER_OK); } -int oldoffice01cm1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int oldoffice01cm1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { return oldoffice01_parse_hash (input_buf, input_len, hash_buf, hashconfig); } -int oldoffice01cm2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int oldoffice01cm2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_9720) || (input_len > DISPLAY_LEN_MAX_9720)) return (PARSER_GLOBAL_LENGTH); @@ -8544,7 +8456,7 @@ int oldoffice01cm2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, return (PARSER_OK); } -int oldoffice34_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int oldoffice34_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_9800) || (input_len > DISPLAY_LEN_MAX_9800)) return (PARSER_GLOBAL_LENGTH); @@ -8664,14 +8576,14 @@ int oldoffice34_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, co return (PARSER_OK); } -int oldoffice34cm1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int oldoffice34cm1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if (memcmp (SIGNATURE_OLDOFFICE3, input_buf, 12)) return (PARSER_SIGNATURE_UNMATCHED); return oldoffice34_parse_hash (input_buf, input_len, hash_buf, hashconfig); } -int oldoffice34cm2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int oldoffice34cm2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_9820) || (input_len > DISPLAY_LEN_MAX_9820)) return (PARSER_GLOBAL_LENGTH); @@ -8818,7 +8730,7 @@ int oldoffice34cm2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, return (PARSER_OK); } -int radmin2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int radmin2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_9900) || (input_len > DISPLAY_LEN_MAX_9900)) return (PARSER_GLOBAL_LENGTH); @@ -8837,7 +8749,7 @@ int radmin2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int djangosha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int djangosha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_124) || (input_len > DISPLAY_LEN_MAX_124)) return (PARSER_GLOBAL_LENGTH); @@ -8894,7 +8806,7 @@ int djangosha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int djangopbkdf2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int djangopbkdf2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_10000) || (input_len > DISPLAY_LEN_MAX_10000)) return (PARSER_GLOBAL_LENGTH); @@ -8973,7 +8885,7 @@ int djangopbkdf2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, c return (PARSER_OK); } -int siphash_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int siphash_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_10100) || (input_len > DISPLAY_LEN_MAX_10100)) return (PARSER_GLOBAL_LENGTH); @@ -9017,7 +8929,7 @@ int siphash_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int crammd5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int crammd5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_10200) || (input_len > DISPLAY_LEN_MAX_10200)) return (PARSER_GLOBAL_LENGTH); @@ -9091,7 +9003,7 @@ int crammd5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int saph_sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int saph_sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_10300) || (input_len > DISPLAY_LEN_MAX_10300)) return (PARSER_GLOBAL_LENGTH); @@ -9160,7 +9072,7 @@ int saph_sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int redmine_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int redmine_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_7600) || (input_len > DISPLAY_LEN_MAX_7600)) return (PARSER_GLOBAL_LENGTH); @@ -9191,7 +9103,7 @@ int redmine_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int pdf11_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int pdf11_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_10400) || (input_len > DISPLAY_LEN_MAX_10400)) return (PARSER_GLOBAL_LENGTH); @@ -9395,12 +9307,12 @@ int pdf11_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const ha return (PARSER_OK); } -int pdf11cm1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int pdf11cm1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { return pdf11_parse_hash (input_buf, input_len, hash_buf, hashconfig); } -int pdf11cm2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int pdf11cm2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_10420) || (input_len > DISPLAY_LEN_MAX_10420)) return (PARSER_GLOBAL_LENGTH); @@ -9635,7 +9547,7 @@ int pdf11cm2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int pdf14_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int pdf14_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_10500) || (input_len > DISPLAY_LEN_MAX_10500)) return (PARSER_GLOBAL_LENGTH); @@ -9900,7 +9812,7 @@ int pdf14_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const ha return (PARSER_OK); } -int pdf17l3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int pdf17l3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { int ret = pdf17l8_parse_hash (input_buf, input_len, hash_buf, hashconfig); @@ -9927,7 +9839,7 @@ int pdf17l3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int pdf17l8_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int pdf17l8_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_10600) || (input_len > DISPLAY_LEN_MAX_10600)) return (PARSER_GLOBAL_LENGTH); @@ -10098,7 +10010,7 @@ int pdf17l8_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int pbkdf2_sha256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int pbkdf2_sha256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_10900) || (input_len > DISPLAY_LEN_MAX_10900)) return (PARSER_GLOBAL_LENGTH); @@ -10185,7 +10097,7 @@ int pbkdf2_sha256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, return (PARSER_OK); } -int prestashop_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int prestashop_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_11000) || (input_len > DISPLAY_LEN_MAX_11000)) return (PARSER_GLOBAL_LENGTH); @@ -10220,7 +10132,7 @@ int prestashop_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int postgresql_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int postgresql_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_11100) || (input_len > DISPLAY_LEN_MAX_11100)) return (PARSER_GLOBAL_LENGTH); @@ -10293,7 +10205,7 @@ int postgresql_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf return (PARSER_OK); } -int mysql_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int mysql_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_11200) || (input_len > DISPLAY_LEN_MAX_11200)) return (PARSER_GLOBAL_LENGTH); @@ -10342,7 +10254,7 @@ int mysql_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int bitcoin_wallet_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int bitcoin_wallet_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_11300) || (input_len > DISPLAY_LEN_MAX_11300)) return (PARSER_GLOBAL_LENGTH); @@ -10489,7 +10401,7 @@ int bitcoin_wallet_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, return (PARSER_OK); } -int sip_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int sip_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_11400) || (input_len > DISPLAY_LEN_MAX_11400)) return (PARSER_GLOBAL_LENGTH); @@ -10502,320 +10414,182 @@ int sip_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const sip_t *sip = (sip_t *) hash_buf->esalt; // work with a temporary copy of input_buf (s.t. we can manipulate it directly) - - char *temp_input_buf = (char *) mymalloc (input_len + 1); - - memcpy (temp_input_buf, input_buf, input_len); + // why? should be fine to use original buffer + //char *temp_input_buf = (char *) hcmalloc (hashcat_ctx, input_len + 1); + //memcpy (temp_input_buf, input_buf, input_len); // URI_server: - char *URI_server_pos = temp_input_buf + 6; + char *URI_server_pos = input_buf + 6; char *URI_client_pos = strchr (URI_server_pos, '*'); - if (URI_client_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } + if (URI_client_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); URI_client_pos[0] = 0; URI_client_pos++; u32 URI_server_len = strlen (URI_server_pos); - if (URI_server_len > 512) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } + if (URI_server_len > 512) return (PARSER_SALT_LENGTH); // URI_client: char *user_pos = strchr (URI_client_pos, '*'); - if (user_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } + if (user_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); user_pos[0] = 0; user_pos++; u32 URI_client_len = strlen (URI_client_pos); - if (URI_client_len > 512) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } + if (URI_client_len > 512) return (PARSER_SALT_LENGTH); // user: char *realm_pos = strchr (user_pos, '*'); - if (realm_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } + if (realm_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); realm_pos[0] = 0; realm_pos++; u32 user_len = strlen (user_pos); - if (user_len > 116) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } + if (user_len > 116) return (PARSER_SALT_LENGTH); // realm: char *method_pos = strchr (realm_pos, '*'); - if (method_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } + if (method_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); method_pos[0] = 0; method_pos++; u32 realm_len = strlen (realm_pos); - if (realm_len > 116) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } + if (realm_len > 116) return (PARSER_SALT_LENGTH); // method: char *URI_prefix_pos = strchr (method_pos, '*'); - if (URI_prefix_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } + if (URI_prefix_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); URI_prefix_pos[0] = 0; URI_prefix_pos++; u32 method_len = strlen (method_pos); - if (method_len > 246) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } + if (method_len > 246) return (PARSER_SALT_LENGTH); // URI_prefix: char *URI_resource_pos = strchr (URI_prefix_pos, '*'); - if (URI_resource_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } + if (URI_resource_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); URI_resource_pos[0] = 0; URI_resource_pos++; u32 URI_prefix_len = strlen (URI_prefix_pos); - if (URI_prefix_len > 245) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } + if (URI_prefix_len > 245) return (PARSER_SALT_LENGTH); // URI_resource: char *URI_suffix_pos = strchr (URI_resource_pos, '*'); - if (URI_suffix_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } + if (URI_suffix_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); URI_suffix_pos[0] = 0; URI_suffix_pos++; u32 URI_resource_len = strlen (URI_resource_pos); - if (URI_resource_len < 1 || URI_resource_len > 246) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } + if (URI_resource_len < 1 || URI_resource_len > 246) return (PARSER_SALT_LENGTH); // URI_suffix: char *nonce_pos = strchr (URI_suffix_pos, '*'); - if (nonce_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } + if (nonce_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); nonce_pos[0] = 0; nonce_pos++; u32 URI_suffix_len = strlen (URI_suffix_pos); - if (URI_suffix_len > 245) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } + if (URI_suffix_len > 245) return (PARSER_SALT_LENGTH); // nonce: char *nonce_client_pos = strchr (nonce_pos, '*'); - if (nonce_client_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } + if (nonce_client_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); nonce_client_pos[0] = 0; nonce_client_pos++; u32 nonce_len = strlen (nonce_pos); - if (nonce_len < 1 || nonce_len > 50) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } + if (nonce_len < 1 || nonce_len > 50) return (PARSER_SALT_LENGTH); // nonce_client: char *nonce_count_pos = strchr (nonce_client_pos, '*'); - if (nonce_count_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } + if (nonce_count_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); nonce_count_pos[0] = 0; nonce_count_pos++; u32 nonce_client_len = strlen (nonce_client_pos); - if (nonce_client_len > 50) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } + if (nonce_client_len > 50) return (PARSER_SALT_LENGTH); // nonce_count: char *qop_pos = strchr (nonce_count_pos, '*'); - if (qop_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } + if (qop_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); qop_pos[0] = 0; qop_pos++; u32 nonce_count_len = strlen (nonce_count_pos); - if (nonce_count_len > 50) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } + if (nonce_count_len > 50) return (PARSER_SALT_LENGTH); // qop: char *directive_pos = strchr (qop_pos, '*'); - if (directive_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } + if (directive_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); directive_pos[0] = 0; directive_pos++; u32 qop_len = strlen (qop_pos); - if (qop_len > 50) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } + if (qop_len > 50) return (PARSER_SALT_LENGTH); // directive char *digest_pos = strchr (directive_pos, '*'); - if (digest_pos == NULL) - { - myfree (temp_input_buf); - - return (PARSER_SEPARATOR_UNMATCHED); - } + if (digest_pos == NULL) return (PARSER_SEPARATOR_UNMATCHED); digest_pos[0] = 0; digest_pos++; u32 directive_len = strlen (directive_pos); - if (directive_len != 3) - { - myfree (temp_input_buf); + if (directive_len != 3) return (PARSER_SALT_LENGTH); - return (PARSER_SALT_LENGTH); - } - - if (memcmp (directive_pos, "MD5", 3)) - { - log_info ("ERROR: Only the MD5 directive is currently supported\n"); - - myfree (temp_input_buf); - - return (PARSER_SIP_AUTH_DIRECTIVE); - } + if (memcmp (directive_pos, "MD5", 3)) return (PARSER_SIP_AUTH_DIRECTIVE); /* * first (pre-)compute: HA2 = md5 ($method . ":" . $uri) @@ -10887,12 +10661,7 @@ int sip_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const { esalt_len = 1 + nonce_len + 1 + nonce_count_len + 1 + nonce_client_len + 1 + qop_len + 1 + 32; - if (esalt_len > max_esalt_len) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } + if (esalt_len > max_esalt_len) return (PARSER_SALT_LENGTH); snprintf (esalt_buf_ptr, max_esalt_len, ":%s:%s:%s:%s:%08x%08x%08x%08x", nonce_pos, @@ -10908,12 +10677,7 @@ int sip_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const { esalt_len = 1 + nonce_len + 1 + 32; - if (esalt_len > max_esalt_len) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } + if (esalt_len > max_esalt_len) return (PARSER_SALT_LENGTH); snprintf (esalt_buf_ptr, max_esalt_len, ":%s:%08x%08x%08x%08x", nonce_pos, @@ -10939,12 +10703,7 @@ int sip_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const u32 max_salt_len = 119; - if (salt_len > max_salt_len) - { - myfree (temp_input_buf); - - return (PARSER_SALT_LENGTH); - } + if (salt_len > max_salt_len) return (PARSER_SALT_LENGTH); snprintf (sip_salt_ptr, max_salt_len + 1, "%s:%s:", user_pos, realm_pos); @@ -10983,12 +10742,10 @@ int sip_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const digest[2] = byte_swap_32 (digest[2]); digest[3] = byte_swap_32 (digest[3]); - myfree (temp_input_buf); - return (PARSER_OK); } -int crc32_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int crc32_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_11500) || (input_len > DISPLAY_LEN_MAX_11500)) return (PARSER_GLOBAL_LENGTH); @@ -11024,7 +10781,7 @@ int crc32_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const ha return (PARSER_OK); } -int seven_zip_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int seven_zip_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_11600) || (input_len > DISPLAY_LEN_MAX_11600)) return (PARSER_GLOBAL_LENGTH); @@ -11190,7 +10947,7 @@ int seven_zip_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int gost2012sbog_256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int gost2012sbog_256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_11700) || (input_len > DISPLAY_LEN_MAX_11700)) return (PARSER_GLOBAL_LENGTH); @@ -11217,7 +10974,7 @@ int gost2012sbog_256_parse_hash (char *input_buf, u32 input_len, hash_t *hash_bu return (PARSER_OK); } -int gost2012sbog_512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int gost2012sbog_512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_11800) || (input_len > DISPLAY_LEN_MAX_11800)) return (PARSER_GLOBAL_LENGTH); @@ -11260,7 +11017,7 @@ int gost2012sbog_512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_bu return (PARSER_OK); } -int pbkdf2_md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int pbkdf2_md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_11900) || (input_len > DISPLAY_LEN_MAX_11900)) return (PARSER_GLOBAL_LENGTH); @@ -11342,7 +11099,7 @@ int pbkdf2_md5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, con return (PARSER_OK); } -int pbkdf2_sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int pbkdf2_sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_12000) || (input_len > DISPLAY_LEN_MAX_12000)) return (PARSER_GLOBAL_LENGTH); @@ -11429,7 +11186,7 @@ int pbkdf2_sha1_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, co return (PARSER_OK); } -int pbkdf2_sha512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int pbkdf2_sha512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_12100) || (input_len > DISPLAY_LEN_MAX_12100)) return (PARSER_GLOBAL_LENGTH); @@ -11520,7 +11277,7 @@ int pbkdf2_sha512_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, return (PARSER_OK); } -int ecryptfs_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int ecryptfs_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_12200) || (input_len > DISPLAY_LEN_MAX_12200)) return (PARSER_GLOBAL_LENGTH); @@ -11580,7 +11337,7 @@ int ecryptfs_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int bsdicrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int bsdicrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_12400) || (input_len > DISPLAY_LEN_MAX_12400)) return (PARSER_GLOBAL_LENGTH); @@ -11628,7 +11385,7 @@ int bsdicrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, cons return (PARSER_OK); } -int rar3hp_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int rar3hp_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_12500) || (input_len > DISPLAY_LEN_MAX_12500)) return (PARSER_GLOBAL_LENGTH); @@ -11697,7 +11454,7 @@ int rar3hp_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h return (PARSER_OK); } -int rar5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int rar5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_13000) || (input_len > DISPLAY_LEN_MAX_13000)) return (PARSER_GLOBAL_LENGTH); @@ -11809,7 +11566,7 @@ int rar5_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int krb5tgs_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int krb5tgs_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_13100) || (input_len > DISPLAY_LEN_MAX_13100)) return (PARSER_GLOBAL_LENGTH); @@ -11908,7 +11665,7 @@ int krb5tgs_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int axcrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int axcrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_13200) || (input_len > DISPLAY_LEN_MAX_13200)) return (PARSER_GLOBAL_LENGTH); @@ -11983,7 +11740,7 @@ int axcrypt_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int keepass_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int keepass_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_13400) || (input_len > DISPLAY_LEN_MAX_13400)) return (PARSER_GLOBAL_LENGTH); @@ -12285,7 +12042,7 @@ int keepass_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int cf10_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int cf10_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_12600) || (input_len > DISPLAY_LEN_MAX_12600)) return (PARSER_GLOBAL_LENGTH); @@ -12364,7 +12121,7 @@ int cf10_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int mywallet_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int mywallet_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_12700) || (input_len > DISPLAY_LEN_MAX_12700)) return (PARSER_GLOBAL_LENGTH); @@ -12435,7 +12192,7 @@ int mywallet_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int ms_drsr_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int ms_drsr_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_12800) || (input_len > DISPLAY_LEN_MAX_12800)) return (PARSER_GLOBAL_LENGTH); @@ -12509,7 +12266,7 @@ int ms_drsr_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const return (PARSER_OK); } -int androidfde_samsung_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int androidfde_samsung_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_12900) || (input_len > DISPLAY_LEN_MAX_12900)) return (PARSER_GLOBAL_LENGTH); @@ -12564,7 +12321,7 @@ int androidfde_samsung_parse_hash (char *input_buf, u32 input_len, hash_t *hash_ return (PARSER_OK); } -int zip2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int zip2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_13600) || (input_len > DISPLAY_LEN_MAX_13600)) return (PARSER_GLOBAL_LENGTH); @@ -12792,7 +12549,7 @@ int zip2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const has return (PARSER_OK); } -int win8phone_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const hashconfig_t *hashconfig) +int win8phone_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSED const hashconfig_t *hashconfig) { if ((input_len < DISPLAY_LEN_MIN_13800) || (input_len > DISPLAY_LEN_MAX_13800)) return (PARSER_GLOBAL_LENGTH); @@ -13103,14 +12860,19 @@ char *strparser (const u32 parser_status) case PARSER_PSAFE2_FILE_SIZE: return ((char *) PA_013); case PARSER_PSAFE3_FILE_SIZE: return ((char *) PA_014); case PARSER_TC_FILE_SIZE: return ((char *) PA_015); - case PARSER_SIP_AUTH_DIRECTIVE: return ((char *) PA_016); + case PARSER_VC_FILE_SIZE: return ((char *) PA_016); + case PARSER_SIP_AUTH_DIRECTIVE: return ((char *) PA_017); + case PARSER_HASH_FILE: return ((char *) PA_018); } return ((char *) PA_255); } -void to_hccap_t (hccap_t *hccap, const u32 salt_pos, const u32 digest_pos, const hashconfig_t *hashconfig, const hashes_t *hashes) +void to_hccap_t (hashcat_ctx_t *hashcat_ctx, hccap_t *hccap, const u32 salt_pos, const u32 digest_pos) { + const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + const hashes_t *hashes = hashcat_ctx->hashes; + const void *digests_buf = hashes->digests_buf; const salt_t *salts_buf = hashes->salts_buf; const void *esalts_buf = hashes->esalts_buf; @@ -13172,8 +12934,11 @@ void to_hccap_t (hccap_t *hccap, const u32 salt_pos, const u32 digest_pos, const } } -void ascii_digest (char *out_buf, const u32 salt_pos, const u32 digest_pos, const hashconfig_t *hashconfig, const hashes_t *hashes) +int ascii_digest (hashcat_ctx_t *hashcat_ctx, char *out_buf, const u32 salt_pos, const u32 digest_pos) { + const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + const hashes_t *hashes = hashcat_ctx->hashes; + void *digests_buf = hashes->digests_buf; salt_t *salts_buf = hashes->salts_buf; void *esalts_buf = hashes->esalts_buf; @@ -15274,9 +15039,9 @@ void ascii_digest (char *out_buf, const u32 salt_pos, const u32 digest_pos, cons const u32 ckey_len = bitcoin_wallet->ckey_len; const u32 public_key_len = bitcoin_wallet->public_key_len; - char *cry_master_buf = (char *) mymalloc ((cry_master_len * 2) + 1); - char *ckey_buf = (char *) mymalloc ((ckey_len * 2) + 1); - char *public_key_buf = (char *) mymalloc ((public_key_len * 2) + 1); + char *cry_master_buf = (char *) hcmalloc (hashcat_ctx, (cry_master_len * 2) + 1); VERIFY_PTR (cry_master_buf); + char *ckey_buf = (char *) hcmalloc (hashcat_ctx, (ckey_len * 2) + 1); VERIFY_PTR (ckey_buf); + char *public_key_buf = (char *) hcmalloc (hashcat_ctx, (public_key_len * 2) + 1); VERIFY_PTR (public_key_buf); for (u32 i = 0, j = 0; i < cry_master_len; i += 1, j += 2) { @@ -15312,9 +15077,9 @@ void ascii_digest (char *out_buf, const u32 salt_pos, const u32 digest_pos, cons public_key_buf ); - myfree (cry_master_buf); - myfree (ckey_buf); - myfree (public_key_buf); + hcfree (cry_master_buf); + hcfree (ckey_buf); + hcfree (public_key_buf); } else if (hash_mode == 11400) { @@ -15333,7 +15098,7 @@ void ascii_digest (char *out_buf, const u32 salt_pos, const u32 digest_pos, cons const u32 data_len = seven_zip->data_len; - char *data_buf = (char *) mymalloc ((data_len * 2) + 1); + char *data_buf = (char *) hcmalloc (hashcat_ctx, (data_len * 2) + 1); VERIFY_PTR (data_buf); for (u32 i = 0, j = 0; i < data_len; i += 1, j += 2) { @@ -15358,7 +15123,7 @@ void ascii_digest (char *out_buf, const u32 salt_pos, const u32 digest_pos, cons seven_zip->unpack_size, data_buf); - myfree (data_buf); + hcfree (data_buf); } else if (hash_mode == 11700) { @@ -16154,9 +15919,9 @@ void ascii_digest (char *out_buf, const u32 salt_pos, const u32 digest_pos, cons out_buf[pos + 1 + salt.salt_len] = 0; } -} -#pragma GCC diagnostic pop + return 0; +} int hashconfig_init (hashcat_ctx_t *hashcat_ctx) { @@ -19814,7 +19579,7 @@ int hashconfig_init (hashcat_ctx_t *hashcat_ctx) hashconfig->dgst_pos3 = 3; break; - default: log_error ("ERROR: Unknown hash-type '%u' selected", hashconfig->hash_mode); + default: event_log_error (hashcat_ctx, "Unknown hash-type '%u' selected", hashconfig->hash_mode); return -1; } @@ -19826,7 +19591,7 @@ int hashconfig_init (hashcat_ctx_t *hashcat_ctx) } else { - log_error ("ERROR: Parameter hex-salt not valid for hash-type %u", hashconfig->hash_mode); + event_log_error (hashcat_ctx, "Parameter hex-salt not valid for hash-type %u", hashconfig->hash_mode); return -1; } @@ -20190,7 +19955,7 @@ u32 hashconfig_enforce_kernel_loops (hashcat_ctx_t *hashcat_ctx) return kernel_loops_fixed; } -void hashconfig_general_defaults (hashcat_ctx_t *hashcat_ctx) +int hashconfig_general_defaults (hashcat_ctx_t *hashcat_ctx) { hashconfig_t *hashconfig = hashcat_ctx->hashconfig; hashes_t *hashes = hashcat_ctx->hashes; @@ -20251,18 +20016,22 @@ void hashconfig_general_defaults (hashcat_ctx_t *hashcat_ctx) u32 *keyfile_buf = ((tc_t *) esalts_buf)->keyfile_buf; - char *keyfiles = mystrdup (tcvc_keyfiles); + char *keyfiles = hcstrdup (hashcat_ctx, tcvc_keyfiles); char *keyfile = strtok (keyfiles, ","); do { - cpu_crc32 (keyfile, (u8 *) keyfile_buf); + const int rc_crc32 = cpu_crc32 (hashcat_ctx, keyfile, (u8 *) keyfile_buf); + + if (rc_crc32 == -1) return -1; } while ((keyfile = strtok (NULL, ",")) != NULL); free (keyfiles); } + + return 0; } void hashconfig_benchmark_defaults (hashcat_ctx_t *hashcat_ctx, salt_t *salt, void *esalt) @@ -20277,6 +20046,8 @@ void hashconfig_benchmark_defaults (hashcat_ctx_t *hashcat_ctx, salt_t *salt, vo switch (hashconfig->hash_mode) { + case 22: salt->salt_len = 30; + break; case 1500: salt->salt_len = 2; salt->salt_buf[0] = 388; // pure magic break; diff --git a/src/locking.c b/src/locking.c index cece6b4c7..f2b80b57e 100644 --- a/src/locking.c +++ b/src/locking.c @@ -4,12 +4,13 @@ */ #include "common.h" -#include "logging.h" +#include "types.h" +#include "event.h" #include "locking.h" #if defined (F_SETLKW) -void lock_file (FILE *fp) +int lock_file (FILE *fp) { struct flock lock; @@ -17,15 +18,9 @@ void lock_file (FILE *fp) lock.l_type = F_WRLCK; - while (fcntl (fileno (fp), F_SETLKW, &lock)) - { - if (errno != EINTR) - { - log_error ("ERROR: Failed acquiring write lock: %s", strerror (errno)); + if (fcntl (fileno (fp), F_SETLKW, &lock)) return -1; - exit (-1); - } - } + return 0; } void unlock_file (FILE *fp) diff --git a/src/logfile.c b/src/logfile.c index abec9dd3b..51514ab45 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -10,7 +10,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "logfile.h" static int logfile_generate_id () @@ -77,20 +77,20 @@ int logfile_init (hashcat_ctx_t *hashcat_ctx) if (user_options->logfile_disable == true) return 0; - logfile_ctx->logfile = (char *) mymalloc (HCBUFSIZ_TINY); + logfile_ctx->logfile = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (logfile_ctx->logfile); snprintf (logfile_ctx->logfile, HCBUFSIZ_TINY - 1, "%s/%s.log", folder_config->session_dir, user_options->session); - logfile_ctx->subid = (char *) mymalloc (HCBUFSIZ_TINY); - logfile_ctx->topid = (char *) mymalloc (HCBUFSIZ_TINY); + logfile_ctx->subid = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (logfile_ctx->subid); + logfile_ctx->topid = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (logfile_ctx->topid); logfile_ctx->enabled = true; - FILE *fp = fopen (logfile_ctx->logfile, "wb"); + FILE *fp = fopen (logfile_ctx->logfile, "ab"); if (fp == NULL) { - log_error ("ERROR: %s: %s", logfile_ctx->logfile, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", logfile_ctx->logfile, strerror (errno)); return -1; } @@ -106,9 +106,9 @@ void logfile_destroy (hashcat_ctx_t *hashcat_ctx) if (logfile_ctx->enabled == false) return; - myfree (logfile_ctx->logfile); - myfree (logfile_ctx->topid); - myfree (logfile_ctx->subid); + hcfree (logfile_ctx->logfile); + hcfree (logfile_ctx->topid); + hcfree (logfile_ctx->subid); memset (logfile_ctx, 0, sizeof (logfile_ctx_t)); } diff --git a/src/logging.c b/src/logging.c deleted file mode 100644 index 6bfcbd3b0..000000000 --- a/src/logging.c +++ /dev/null @@ -1,138 +0,0 @@ -/** - * Author......: See docs/credits.txt - * License.....: MIT - */ - -#if defined (__APPLE__) -#include -#endif - -#include "common.h" -#include "logging.h" - -static int last_len = 0; - -static int log_final (FILE *fp, const char *fmt, va_list ap) -{ - if (last_len) - { - fputc ('\r', fp); - - for (int i = 0; i < last_len; i++) - { - fputc (' ', fp); - } - - fputc ('\r', fp); - } - - char s[4096] = { 0 }; - - const size_t max_len = sizeof (s); - - const int len = vsnprintf (s, max_len, fmt, ap); - - //if (len > max_len) len = max_len; - - fwrite (s, (size_t) len, 1, fp); - - fflush (fp); - - last_len = len; - - return last_len; -} - -int log_out_nn (FILE *fp, const char *fmt, ...) -{ - va_list ap; - - va_start (ap, fmt); - - const int len = log_final (fp, fmt, ap); - - va_end (ap); - - return len; -} - -int log_info_nn (const char *fmt, ...) -{ - va_list ap; - - va_start (ap, fmt); - - const int len = log_final (stdout, fmt, ap); - - va_end (ap); - - return len; -} - -int log_error_nn (const char *fmt, ...) -{ - va_list ap; - - va_start (ap, fmt); - - const int len = log_final (stderr, fmt, ap); - - va_end (ap); - - return len; -} - -int log_out (FILE *fp, const char *fmt, ...) -{ - va_list ap; - - va_start (ap, fmt); - - const int len = log_final (fp, fmt, ap); - - va_end (ap); - - fputc ('\n', fp); - - last_len = 0; - - return len; -} - -int log_info (const char *fmt, ...) -{ - va_list ap; - - va_start (ap, fmt); - - const int len = log_final (stdout, fmt, ap); - - va_end (ap); - - fputc ('\n', stdout); - - last_len = 0; - - return len; -} - -int log_error (const char *fmt, ...) -{ - fputc ('\n', stderr); - fputc ('\n', stderr); - - va_list ap; - - va_start (ap, fmt); - - const int len = log_final (stderr, fmt, ap); - - va_end (ap); - - fputc ('\n', stderr); - fputc ('\n', stderr); - - last_len = 0; - - return len; -} diff --git a/src/loopback.c b/src/loopback.c index 79646f84f..973bcf8ca 100644 --- a/src/loopback.c +++ b/src/loopback.c @@ -6,7 +6,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "shared.h" #include "loopback.h" @@ -65,12 +65,13 @@ int loopback_init (hashcat_ctx_t *hashcat_ctx) if (user_options->opencl_info == true) return 0; if (user_options->show == true) return 0; if (user_options->stdout_flag == true) return 0; + if (user_options->speed_only == true) return 0; if (user_options->usage == true) return 0; if (user_options->version == true) return 0; loopback_ctx->enabled = true; loopback_ctx->fp = NULL; - loopback_ctx->filename = (char *) mymalloc (HCBUFSIZ_TINY); + loopback_ctx->filename = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (loopback_ctx->filename); return 0; } @@ -105,7 +106,7 @@ int loopback_write_open (hashcat_ctx_t *hashcat_ctx) if (loopback_ctx->fp == NULL) { - log_error ("ERROR: %s: %s", loopback_ctx->filename, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", loopback_ctx->filename, strerror (errno)); return -1; } diff --git a/src/main.c b/src/main.c index f9666d699..efc470753 100644 --- a/src/main.c +++ b/src/main.c @@ -10,135 +10,781 @@ #include "common.h" #include "types.h" #include "user_options.h" +#include "usage.h" +#include "memory.h" #include "hashcat.h" -#include "terminal.h" // commandline only -#include "usage.h" // commandline only +#include "terminal.h" +#include "thread.h" +#include "status.h" +#include "interface.h" +#include "event.h" -#define RUN_AS_COMMANDLINE true +static void main_log_clear_line (MAYBE_UNUSED const int prev_len, MAYBE_UNUSED FILE *fp) +{ + #if defined (_WIN) + + fputc ('\r', fp); + + for (int i = 0; i < prev_len; i++) + { + fputc (' ', fp); + } + + fputc ('\r', fp); + + #else + + printf ("\033[2K\r"); + + #endif +} + +static void main_log (hashcat_ctx_t *hashcat_ctx, FILE *fp, const int loglevel) +{ + event_ctx_t *event_ctx = hashcat_ctx->event_ctx; + + const char *msg_buf = event_ctx->msg_buf; + const int msg_len = event_ctx->msg_len; + const bool msg_newline = event_ctx->msg_newline; + + // handle last_len + + const int prev_len = event_ctx->prev_len; + + if (prev_len) + { + main_log_clear_line (prev_len, fp); + } + + if (msg_newline == true) + { + event_ctx->prev_len = 0; + } + else + { + event_ctx->prev_len = msg_len; + } + + // color stuff pre + + #if defined (_WIN) + HANDLE hConsole = GetStdHandle (STD_OUTPUT_HANDLE); + + CONSOLE_SCREEN_BUFFER_INFO con_info; + + GetConsoleScreenBufferInfo (hConsole, &con_info); + + const int orig = con_info.wAttributes; + + switch (loglevel) + { + case LOGLEVEL_INFO: break; + case LOGLEVEL_WARNING: SetConsoleTextAttribute (hConsole, 6); break; + case LOGLEVEL_ERROR: SetConsoleTextAttribute (hConsole, FOREGROUND_RED); break; + } + + #else + switch (loglevel) + { + case LOGLEVEL_INFO: break; + case LOGLEVEL_WARNING: fwrite ("\033[33m", 5, 1, fp); break; + case LOGLEVEL_ERROR: fwrite ("\033[31m", 5, 1, fp); break; + } + #endif + + // finally, print + + fwrite (msg_buf, msg_len, 1, fp); + + // color stuff post + + #if defined (_WIN) + switch (loglevel) + { + case LOGLEVEL_INFO: break; + case LOGLEVEL_WARNING: SetConsoleTextAttribute (hConsole, orig); break; + case LOGLEVEL_ERROR: SetConsoleTextAttribute (hConsole, orig); break; + } + #else + switch (loglevel) + { + case LOGLEVEL_INFO: break; + case LOGLEVEL_WARNING: fwrite ("\033[0m", 4, 1, fp); break; + case LOGLEVEL_ERROR: fwrite ("\033[0m", 4, 1, fp); break; + } + #endif + + // eventual newline + + if (msg_newline == true) + { + fwrite (EOL, strlen (EOL), 1, fp); + + // on error, add another newline + + if (loglevel == LOGLEVEL_ERROR) + { + fwrite (EOL, strlen (EOL), 1, fp); + } + } + + fflush (fp); +} + +static void main_log_info (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + main_log (hashcat_ctx, stdout, LOGLEVEL_INFO); +} + +static void main_log_warning (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + main_log (hashcat_ctx, stdout, LOGLEVEL_WARNING); +} + +static void main_log_error (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + main_log (hashcat_ctx, stderr, LOGLEVEL_ERROR); +} + +static void main_welcome_screen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + // sets dos window size (windows only) + + setup_console (hashcat_ctx); + + // Inform user things getting started + + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + //const user_options_t *user_options = hashcat_ctx->user_options; + + //if (user_options->machine_readable == true) return; + + welcome_screen (hashcat_ctx, status_ctx->proc_start, VERSION_TAG); +} + +static void main_goodbye_screen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + // Inform user we're done + + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->machine_readable == true) return; + + goodbye_screen (hashcat_ctx, status_ctx->proc_start, status_ctx->proc_stop); +} + +static void main_outerloop_starting (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + + hashcat_user_t *hashcat_user = hashcat_ctx->hashcat_user; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + /** + * keypress thread + */ + + hashcat_user->outer_threads_cnt = 0; + + hashcat_user->outer_threads = (hc_thread_t *) hccalloc (hashcat_ctx, 2, sizeof (hc_thread_t)); if (hashcat_user->outer_threads == NULL) return; + + status_ctx->shutdown_outer = false; + + if (user_options->keyspace == false && user_options->benchmark == false && user_options->stdout_flag == false && user_options->opencl_info == false && user_options->speed_only == false) + { + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + // see thread_keypress() how to access status information + + hc_thread_create (hashcat_user->outer_threads[hashcat_user->outer_threads_cnt], thread_keypress, hashcat_ctx); + + hashcat_user->outer_threads_cnt++; + } + } +} + +static void main_outerloop_finished (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + hashcat_user_t *hashcat_user = hashcat_ctx->hashcat_user; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + // wait for outer threads + + status_ctx->shutdown_outer = true; + + for (int thread_idx = 0; thread_idx < hashcat_user->outer_threads_cnt; thread_idx++) + { + hc_thread_wait (1, &hashcat_user->outer_threads[thread_idx]); + } + + hcfree (hashcat_user->outer_threads); + + hashcat_user->outer_threads_cnt = 0; +} + +static void main_cracker_starting (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + + if (user_options->quiet == true) return; + + // Tell the user we're about to start + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + if ((user_options->quiet == false) && (user_options->benchmark == false) && (user_options->speed_only == false)) + { + event_log_info_nn (hashcat_ctx, ""); + + send_prompt (); + } + } + else if (user_options_extra->wordlist_mode == WL_MODE_STDIN) + { + event_log_info (hashcat_ctx, "Starting attack in stdin mode..."); + event_log_info (hashcat_ctx, ""); + } +} + +static void main_cracker_finished (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const hashes_t *hashes = hashcat_ctx->hashes; + const user_options_t *user_options = hashcat_ctx->user_options; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + + if (user_options->keyspace == true) return; + if (user_options->opencl_info == true) return; + if (user_options->stdout_flag == true) return; + + // if we had a prompt, clear it + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + if ((user_options->benchmark == false) && (user_options->speed_only == false)) + { + clear_prompt (); + } + } + + // print final status + + if ((user_options->benchmark == true) || (user_options->speed_only == true)) + { + status_benchmark (hashcat_ctx); + + if (user_options->machine_readable == false) + { + event_log_info (hashcat_ctx, ""); + } + } + else + { + if (user_options->quiet == false) + { + if (hashes->digests_saved != hashes->digests_done) event_log_info (hashcat_ctx, ""); + + status_display (hashcat_ctx); + + event_log_info (hashcat_ctx, ""); + } + } +} + +static void main_cracker_hash_cracked (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + user_options_t *user_options = hashcat_ctx->user_options; + user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + + if (outfile_ctx->fp != NULL) return; // cracked hash was not written to an outfile + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + if (outfile_ctx->filename == NULL) if (user_options->quiet == false) clear_prompt (); + } + + fwrite (buf, len, 1, stdout); + fwrite (EOL, strlen (EOL), 1, stdout); + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + if (status_ctx->devices_status != STATUS_CRACKED) + { + if (outfile_ctx->filename == NULL) if (user_options->quiet == false) send_prompt (); + } + } +} + +static void main_calculated_words_base (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->keyspace == false) return; + + event_log_info (hashcat_ctx, "%" PRIu64 "", status_ctx->words_base); +} + +static void main_potfile_remove_parse_pre (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->quiet == true) return; + + event_log_info_nn (hashcat_ctx, "Comparing hashes with potfile entries..."); +} + +static void main_potfile_remove_parse_post (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->quiet == true) return; + + event_log_info_nn (hashcat_ctx, "Compared hashes with potfile entries..."); +} + +static void main_potfile_hash_show (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; + + if (outfile_ctx->fp != NULL) return; // cracked hash was not written to an outfile + + fwrite (buf, len, 1, stdout); + fwrite (EOL, strlen (EOL), 1, stdout); +} + +static void main_potfile_hash_left (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; + + if (outfile_ctx->fp != NULL) return; // cracked hash was not written to an outfile + + fwrite (buf, len, 1, stdout); + fwrite (EOL, strlen (EOL), 1, stdout); +} + +static void main_potfile_num_cracked (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + const hashes_t *hashes = hashcat_ctx->hashes; + + if (user_options->quiet == true) return; + + const int potfile_remove_cracks = hashes->digests_done; + + if (potfile_remove_cracks > 0) + { + if (potfile_remove_cracks == 1) + { + event_log_info (hashcat_ctx, "INFO: Removed 1 hash found in potfile"); + event_log_info (hashcat_ctx, ""); + } + else + { + event_log_info (hashcat_ctx, "INFO: Removed %d hashes found in potfile", potfile_remove_cracks); + event_log_info (hashcat_ctx, ""); + } + } +} + +static void main_potfile_all_cracked (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->quiet == true) return; + + event_log_info (hashcat_ctx, "INFO: All hashes found in potfile! You can use --show to display them."); + event_log_info (hashcat_ctx, ""); +} + +static void main_outerloop_mainscreen (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const bitmap_ctx_t *bitmap_ctx = hashcat_ctx->bitmap_ctx; + const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + const hashes_t *hashes = hashcat_ctx->hashes; + const hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; + const user_options_t *user_options = hashcat_ctx->user_options; + + /** + * In benchmark-mode, inform user which algorithm is checked + */ + + if (user_options->benchmark == true) + { + if (user_options->machine_readable == false) + { + char *hash_type = strhashtype (hashconfig->hash_mode); // not a bug + + event_log_info (hashcat_ctx, "Hashtype: %s", hash_type); + event_log_info (hashcat_ctx, ""); + } + } + + if (user_options->quiet == true) return; + + event_log_info (hashcat_ctx, "Hashes: %u digests; %u unique digests, %u unique salts", hashes->hashes_cnt_orig, hashes->digests_cnt, hashes->salts_cnt); + event_log_info (hashcat_ctx, "Bitmaps: %u bits, %u entries, 0x%08x mask, %u bytes, %u/%u rotates", bitmap_ctx->bitmap_bits, bitmap_ctx->bitmap_nums, bitmap_ctx->bitmap_mask, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_shift1, bitmap_ctx->bitmap_shift2); + + if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) + { + event_log_info (hashcat_ctx, "Rules: %u", straight_ctx->kernel_rules_cnt); + } + + if (user_options->quiet == false) event_log_info (hashcat_ctx, ""); + + if (hashconfig->opti_type) + { + event_log_info (hashcat_ctx, "Applicable Optimizers:"); + + for (u32 i = 0; i < 32; i++) + { + const u32 opti_bit = 1u << i; + + if (hashconfig->opti_type & opti_bit) event_log_info (hashcat_ctx, "* %s", stroptitype (opti_bit)); + } + } + + event_log_info (hashcat_ctx, ""); + + /** + * Watchdog and Temperature balance + */ + + if (hwmon_ctx->enabled == false && user_options->gpu_temp_disable == false) + { + event_log_info (hashcat_ctx, "Watchdog: Hardware Monitoring Interface not found on your system"); + } + + if (hwmon_ctx->enabled == true && user_options->gpu_temp_abort > 0) + { + event_log_info (hashcat_ctx, "Watchdog: Temperature abort trigger set to %uc", user_options->gpu_temp_abort); + } + else + { + event_log_info (hashcat_ctx, "Watchdog: Temperature abort trigger disabled"); + } + + if (hwmon_ctx->enabled == true && user_options->gpu_temp_retain > 0) + { + event_log_info (hashcat_ctx, "Watchdog: Temperature retain trigger set to %uc", user_options->gpu_temp_retain); + } + else + { + event_log_info (hashcat_ctx, "Watchdog: Temperature retain trigger disabled"); + } + + event_log_info (hashcat_ctx, ""); + + #if defined (DEBUG) + if (user_options->benchmark == true) event_log_info (hashcat_ctx, "Hashmode: %d", hashconfig->hash_mode); + #endif +} + +static void main_opencl_session_pre (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->quiet == true) return; + + event_log_info_nn (hashcat_ctx, "Initializing device kernels and memory..."); +} + +static void main_opencl_session_post (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->quiet == true) return; + + event_log_info_nn (hashcat_ctx, "Initialized device kernels and memory..."); +} + +static void main_weak_hash_pre (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->quiet == true) return; + + event_log_info_nn (hashcat_ctx, "Checking for weak hashes..."); +} + +static void main_weak_hash_post (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->quiet == true) return; + + event_log_info_nn (hashcat_ctx, "Checked for weak hashes..."); +} + +static void main_bitmap_init_pre (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->quiet == true) return; + + event_log_info_nn (hashcat_ctx, "Generating bitmap tables..."); +} + +static void main_bitmap_init_post (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->quiet == true) return; + + event_log_info_nn (hashcat_ctx, "Generated bitmap tables..."); +} + +static void main_set_kernel_power_final (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->quiet == true) return; + + clear_prompt (); + + event_log_info (hashcat_ctx, "INFO: approaching final keyspace, workload adjusted"); + event_log_info (hashcat_ctx, ""); + + send_prompt (); +} + +static void main_monitor_throttle1 (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + + if (user_options->quiet == true) return; + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + clear_prompt (); + } + + u32 *device_id = (u32 *) buf; + + event_log_warning (hashcat_ctx, "Drivers temperature threshold hit on GPU #%d, expect performance to drop...", *device_id + 1); + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + send_prompt (); + } +} + +static void main_monitor_throttle2 (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + + if (user_options->quiet == true) return; + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + clear_prompt (); + } + + u32 *device_id = (u32 *) buf; + + event_log_warning (hashcat_ctx, "Drivers temperature threshold hit on GPU #%d, expect performance to drop...", *device_id + 1); + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + send_prompt (); + } +} + +static void main_monitor_throttle3 (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + + if (user_options->quiet == true) return; + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + clear_prompt (); + } + + u32 *device_id = (u32 *) buf; + + event_log_warning (hashcat_ctx, "Drivers temperature threshold hit on GPU #%d, expect performance to drop...", *device_id + 1); + event_log_warning (hashcat_ctx, ""); + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + send_prompt (); + } +} + +static void main_monitor_temp_abort (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + + if (user_options->quiet == true) return; + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + clear_prompt (); + } + + u32 *device_id = (u32 *) buf; + + event_log_error (hashcat_ctx, "Temperature limit on GPU #%u reached, aborting...", *device_id + 1); +} + +static void main_monitor_runtime_limit (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + + if (user_options->quiet == true) return; + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + clear_prompt (); + } + + event_log_warning (hashcat_ctx, "Runtime limit reached, aborting..."); +} + +static void main_monitor_status_refresh (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + if (user_options->quiet == false) + { + //clear_prompt (); + + event_log_info (hashcat_ctx, ""); + event_log_info (hashcat_ctx, ""); + } + } + + status_display (hashcat_ctx); + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + if (user_options->quiet == false) + { + event_log_info (hashcat_ctx, ""); + + send_prompt (); + } + } +} + +void event (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len) +{ + switch (id) + { + case EVENT_LOG_INFO: main_log_info (hashcat_ctx, buf, len); break; + case EVENT_LOG_WARNING: main_log_warning (hashcat_ctx, buf, len); break; + case EVENT_LOG_ERROR: main_log_error (hashcat_ctx, buf, len); break; + case EVENT_WELCOME_SCREEN: main_welcome_screen (hashcat_ctx, buf, len); break; + case EVENT_GOODBYE_SCREEN: main_goodbye_screen (hashcat_ctx, buf, len); break; + case EVENT_OUTERLOOP_STARTING: main_outerloop_starting (hashcat_ctx, buf, len); break; + case EVENT_OUTERLOOP_FINISHED: main_outerloop_finished (hashcat_ctx, buf, len); break; + case EVENT_OUTERLOOP_MAINSCREEN: main_outerloop_mainscreen (hashcat_ctx, buf, len); break; + case EVENT_CRACKER_STARTING: main_cracker_starting (hashcat_ctx, buf, len); break; + case EVENT_CRACKER_FINISHED: main_cracker_finished (hashcat_ctx, buf, len); break; + case EVENT_CRACKER_HASH_CRACKED: main_cracker_hash_cracked (hashcat_ctx, buf, len); break; + case EVENT_CALCULATED_WORDS_BASE: main_calculated_words_base (hashcat_ctx, buf, len); break; + case EVENT_POTFILE_REMOVE_PARSE_PRE: main_potfile_remove_parse_pre (hashcat_ctx, buf, len); break; + case EVENT_POTFILE_REMOVE_PARSE_POST: main_potfile_remove_parse_post (hashcat_ctx, buf, len); break; + case EVENT_POTFILE_HASH_SHOW: main_potfile_hash_show (hashcat_ctx, buf, len); break; + case EVENT_POTFILE_HASH_LEFT: main_potfile_hash_left (hashcat_ctx, buf, len); break; + case EVENT_POTFILE_NUM_CRACKED: main_potfile_num_cracked (hashcat_ctx, buf, len); break; + case EVENT_POTFILE_ALL_CRACKED: main_potfile_all_cracked (hashcat_ctx, buf, len); break; + case EVENT_OPENCL_SESSION_PRE: main_opencl_session_pre (hashcat_ctx, buf, len); break; + case EVENT_OPENCL_SESSION_POST: main_opencl_session_post (hashcat_ctx, buf, len); break; + case EVENT_BITMAP_INIT_PRE: main_bitmap_init_pre (hashcat_ctx, buf, len); break; + case EVENT_BITMAP_INIT_POST: main_bitmap_init_post (hashcat_ctx, buf, len); break; + case EVENT_WEAK_HASH_PRE: main_weak_hash_pre (hashcat_ctx, buf, len); break; + case EVENT_WEAK_HASH_POST: main_weak_hash_post (hashcat_ctx, buf, len); break; + case EVENT_SET_KERNEL_POWER_FINAL: main_set_kernel_power_final (hashcat_ctx, buf, len); break; + case EVENT_MONITOR_THROTTLE1: main_monitor_throttle1 (hashcat_ctx, buf, len); break; + case EVENT_MONITOR_THROTTLE2: main_monitor_throttle2 (hashcat_ctx, buf, len); break; + case EVENT_MONITOR_THROTTLE3: main_monitor_throttle3 (hashcat_ctx, buf, len); break; + case EVENT_MONITOR_TEMP_ABORT: main_monitor_temp_abort (hashcat_ctx, buf, len); break; + case EVENT_MONITOR_RUNTIME_LIMIT: main_monitor_runtime_limit (hashcat_ctx, buf, len); break; + case EVENT_MONITOR_STATUS_REFRESH: main_monitor_status_refresh (hashcat_ctx, buf, len); break; + } +} int main (int argc, char **argv) { // hashcat main context - hashcat_ctx_t *hashcat_ctx = (hashcat_ctx_t *) malloc (sizeof (hashcat_ctx_t)); + hashcat_ctx_t *hashcat_ctx = (hashcat_ctx_t *) malloc (sizeof (hashcat_ctx_t)); VERIFY_PTR (hashcat_ctx); - hashcat_ctx_init (hashcat_ctx); + const int rc_hashcat_init = hashcat_init (hashcat_ctx, event); - // initialize the session via getops for commandline use or - // alternatively you can set the user_options directly + if (rc_hashcat_init == -1) return -1; - int rc_hashcat = 0; + // install and shared folder need to be set to recognize "make install" use - bool run_as_commandline = RUN_AS_COMMANDLINE; + char *install_folder = NULL; + char *shared_folder = NULL; - if (run_as_commandline == true) + #if defined (INSTALL_FOLDER) + install_folder = INSTALL_FOLDER; + #endif + + #if defined (SHARED_FOLDER) + shared_folder = SHARED_FOLDER; + #endif + + // initialize the user options with some defaults (you can override them later) + + const int rc_options_init = user_options_init (hashcat_ctx); + + if (rc_options_init == -1) return -1; + + // parse commandline parameters and check them + + const int rc_options_getopt = user_options_getopt (hashcat_ctx, argc, argv); + + if (rc_options_getopt == -1) return -1; + + const int rc_options_sanity = user_options_sanity (hashcat_ctx); + + if (rc_options_sanity == -1) return -1; + + // some early exits + + user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->version == true) { - // install and shared folder need to be set to recognize "make install" use + printf ("%s\n", VERSION_TAG); - char *install_folder = NULL; - char *shared_folder = NULL; - - #if defined (INSTALL_FOLDER) - install_folder = INSTALL_FOLDER; - #endif - - #if defined (SHARED_FOLDER) - shared_folder = SHARED_FOLDER; - #endif - - // sets dos window size (windows only) - - const int rc_console = setup_console (); - - if (rc_console == -1) return -1; - - // initialize the user options with some defaults (you can override them later) - - user_options_init (hashcat_ctx); - - // parse commandline parameters and check them - - const int rc_options_getopt = user_options_getopt (hashcat_ctx, argc, argv); - - if (rc_options_getopt == -1) return -1; - - const int rc_options_sanity = user_options_sanity (hashcat_ctx); - - if (rc_options_sanity == -1) return -1; - - // some early exits - - user_options_t *user_options = hashcat_ctx->user_options; - - if (user_options->version == true) - { - printf ("%s\n", VERSION_TAG); - - return 0; - } - - if (user_options->usage == true) - { - usage_big_print (PROGNAME); - - return 0; - } - - // Inform user things getting started - - time_t proc_start; - - time (&proc_start); - - welcome_screen (hashcat_ctx, proc_start, VERSION_TAG); - - // now run hashcat - - rc_hashcat = hashcat (hashcat_ctx, install_folder, shared_folder, argc, argv, COMPTIME); - - // Inform user we're done - - time_t proc_stop; - - time (&proc_stop); - - goodbye_screen (hashcat_ctx, proc_start, proc_stop); + return 0; } - else + + if (user_options->usage == true) { - // this is a bit ugly, but it's the example you're looking for + usage_big_print (PROGNAME); - char *hash = "8743b52063cd84097a65d1633f5c74f5"; - char *mask = "?l?l?l?l?l?l?l"; - - char *hc_argv[] = { hash, mask, NULL }; - - // initialize the user options with some defaults (you can override them later) - - user_options_init (hashcat_ctx); - - // your own stuff - - user_options_t *user_options = hashcat_ctx->user_options; - - user_options->hc_argv = hc_argv; - user_options->hc_argc = 2; - user_options->quiet = true; - user_options->potfile_disable = true; - user_options->attack_mode = ATTACK_MODE_BF; // this is -a 3 - user_options->hash_mode = 0; // MD5 - user_options->workload_profile = 3; - - // now run hashcat - - rc_hashcat = hashcat (hashcat_ctx, NULL, NULL, 0, NULL, 0); + return 0; } + // now run hashcat + + const int rc_hashcat = hashcat_session_run (hashcat_ctx, install_folder, shared_folder, argc, argv, COMPTIME); + // finished with hashcat, clean up - hashcat_ctx_destroy (hashcat_ctx); + hashcat_destroy (hashcat_ctx); free (hashcat_ctx); return rc_hashcat; -} \ No newline at end of file +} diff --git a/src/main_shared.c b/src/main_shared.c new file mode 100644 index 000000000..986aee4ec --- /dev/null +++ b/src/main_shared.c @@ -0,0 +1,102 @@ +/** + * Author......: See docs/credits.txt + * License.....: MIT + */ + +#include +#include + +#include "common.h" +#include "types.h" +#include "memory.h" +#include "user_options.h" +#include "hashcat.h" + +static void main_cracker_hash_cracked (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) +{ + outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; + + if (outfile_ctx->fp != NULL) return; // cracked hash was not written to an outfile + + fwrite (buf, len, 1, stdout); + fwrite (EOL, strlen (EOL), 1, stdout); +} + +void event (const u32 id, hashcat_ctx_t *hashcat_ctx, const void *buf, const size_t len) +{ + switch (id) + { + case EVENT_CRACKER_HASH_CRACKED: main_cracker_hash_cracked (hashcat_ctx, buf, len); break; + } +} + +int main () +{ + // hashcat main context + + hashcat_ctx_t *hashcat_ctx = (hashcat_ctx_t *) malloc (sizeof (hashcat_ctx_t)); + + assert (hashcat_ctx); + + const int rc_hashcat_init = hashcat_init (hashcat_ctx, event); + + if (rc_hashcat_init == -1) return -1; + + // this is a bit ugly, but it's the example you're looking for + + char *hash = "8743b52063cd84097a65d1633f5c74f5"; + char *mask = "?l?l?l?l?l?l?l"; + + char *hc_argv[] = { hash, mask, NULL }; + + // initialize the user options with some defaults (you can override them later) + + const int rc_options_init = user_options_init (hashcat_ctx); + + if (rc_options_init == -1) return -1; + + // your own stuff + + user_options_t *user_options = hashcat_ctx->user_options; + + user_options->hc_argv = hc_argv; + user_options->hc_argc = 2; + user_options->quiet = true; + user_options->potfile_disable = true; + user_options->attack_mode = ATTACK_MODE_BF; // this is -a 3 + user_options->hash_mode = 0; // MD5 + user_options->workload_profile = 3; + + // now run hashcat + + const int rc_hashcat = hashcat_session_run (hashcat_ctx, NULL, NULL, 0, NULL, 0); + + if (rc_hashcat == 0) + { + hashcat_status_t hashcat_status; + + const int rc = hashcat_get_status (hashcat_ctx, &hashcat_status); + + printf ("Session: %s\n", hashcat_status.session); + printf ("Status: %s\n", hashcat_status.status_string); + + if (rc == 0) + { + printf ("%d\n", hashcat_status.device_info_cnt); + + } + + } + else if (rc_hashcat == -1) + { + char *msg = hashcat_get_log (hashcat_ctx); + + fprintf (stderr, "%s\n", msg); + } + + hashcat_destroy (hashcat_ctx); + + free (hashcat_ctx); + + return 0; +} diff --git a/src/memory.c b/src/memory.c index 506e331a3..a566914b2 100644 --- a/src/memory.c +++ b/src/memory.c @@ -4,69 +4,74 @@ */ #include "common.h" -#include "logging.h" +#include "types.h" +#include "event.h" #include "memory.h" -void *mycalloc (size_t nmemb, size_t size) +void *hccalloc (hashcat_ctx_t *hashcat_ctx, const size_t nmemb, const size_t sz) { - void *p = calloc (nmemb, size); + void *p = calloc (nmemb, sz); if (p == NULL) { - log_error ("ERROR: %s", MSG_ENOMEM); + event_log_error (hashcat_ctx, "%s", MSG_ENOMEM); - exit (-1); + return (NULL); } return (p); } -void *mymalloc (size_t size) +void *hcmalloc (hashcat_ctx_t *hashcat_ctx, const size_t sz) { - void *p = malloc (size); + void *p = malloc (sz); if (p == NULL) { - log_error ("ERROR: %s", MSG_ENOMEM); + event_log_error (hashcat_ctx, "%s", MSG_ENOMEM); - exit (-1); + return (NULL); } - memset (p, 0, size); + memset (p, 0, sz); return (p); } -void myfree (void *ptr) +void *hcrealloc (hashcat_ctx_t *hashcat_ctx, void *ptr, const size_t oldsz, const size_t addsz) +{ + void *p = realloc (ptr, oldsz + addsz); + + if (p == NULL) + { + event_log_error (hashcat_ctx, "%s", MSG_ENOMEM); + + return (NULL); + } + + memset ((char *) p + oldsz, 0, addsz); + + return (p); +} + +char *hcstrdup (hashcat_ctx_t *hashcat_ctx, const char *s) +{ + const size_t len = strlen (s); + + char *b = (char *) hcmalloc (hashcat_ctx, len + 1); + + if (b == NULL) return (NULL); + + memcpy (b, s, len); + + b[len] = 0; + + return (b); +} + +void hcfree (void *ptr) { if (ptr == NULL) return; free (ptr); } - -void *myrealloc (void *ptr, size_t oldsz, size_t add) -{ - void *p = realloc (ptr, oldsz + add); - - if (p == NULL) - { - log_error ("ERROR: %s", MSG_ENOMEM); - - exit (-1); - } - - memset ((char *) p + oldsz, 0, add); - - return (p); -} - -char *mystrdup (const char *s) -{ - const size_t len = strlen (s); - - char *b = (char *) mymalloc (len + 1); - - memcpy (b, s, len); - - return (b); -} diff --git a/src/monitor.c b/src/monitor.c index b268d6289..1fe99ca73 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -5,26 +5,47 @@ #include "common.h" #include "types.h" -#include "logging.h" +#include "event.h" #include "memory.h" #include "hwmon.h" #include "timer.h" #include "hashes.h" #include "thread.h" #include "restore.h" -#include "terminal.h" -#include "status.h" #include "shared.h" #include "monitor.h" -static void monitor (hashcat_ctx_t *hashcat_ctx) +int get_runtime_left (const hashcat_ctx_t *hashcat_ctx) { - hashes_t *hashes = hashcat_ctx->hashes; - hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - user_options_t *user_options = hashcat_ctx->user_options; + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + const user_options_t *user_options = hashcat_ctx->user_options; + + double msec_paused = status_ctx->msec_paused; + + if (status_ctx->devices_status == STATUS_PAUSED) + { + double msec_paused_tmp = hc_timer_get (status_ctx->timer_paused); + + msec_paused += msec_paused_tmp; + } + + time_t runtime_cur; + + time (&runtime_cur); + + const int runtime_left = status_ctx->proc_start + user_options->runtime + status_ctx->prepare_time + (msec_paused / 1000) - runtime_cur; + + return runtime_left; +} + +static int monitor (hashcat_ctx_t *hashcat_ctx) +{ + hashes_t *hashes = hashcat_ctx->hashes; + hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + user_options_t *user_options = hashcat_ctx->user_options; bool runtime_check = false; bool remove_check = false; @@ -64,17 +85,17 @@ static void monitor (hashcat_ctx_t *hashcat_ctx) if ((runtime_check == false) && (remove_check == false) && (status_check == false) && (restore_check == false) && (hwmon_check == false)) { - return; + return 0; } // these variables are mainly used for fan control - int *fan_speed_chgd = (int *) mycalloc (opencl_ctx->devices_cnt, sizeof (int)); + int *fan_speed_chgd = (int *) hccalloc (hashcat_ctx, opencl_ctx->devices_cnt, sizeof (int)); VERIFY_PTR (fan_speed_chgd); // temperature controller "loopback" values - int *temp_diff_old = (int *) mycalloc (opencl_ctx->devices_cnt, sizeof (int)); - int *temp_diff_sum = (int *) mycalloc (opencl_ctx->devices_cnt, sizeof (int)); + int *temp_diff_old = (int *) hccalloc (hashcat_ctx, opencl_ctx->devices_cnt, sizeof (int)); VERIFY_PTR (temp_diff_old); + int *temp_diff_sum = (int *) hccalloc (hashcat_ctx, opencl_ctx->devices_cnt, sizeof (int)); VERIFY_PTR (temp_diff_sum); time_t last_temp_check_time; @@ -102,48 +123,21 @@ static void monitor (hashcat_ctx_t *hashcat_ctx) if (device_param->skipped) continue; - if (device_param->device_vendor_id == VENDOR_ID_NV) + const int rc_throttle = hm_get_throttle_with_device_id (hashcat_ctx, device_id); + + if (rc_throttle == -1) continue; + + if (rc_throttle > 0) { - if (hwmon_ctx->hm_nvapi) - { - NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 perfPolicies_info; - NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 perfPolicies_status; + slowdown_warnings++; - memset (&perfPolicies_info, 0, sizeof (NV_GPU_PERF_POLICIES_INFO_PARAMS_V1)); - memset (&perfPolicies_status, 0, sizeof (NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1)); - - perfPolicies_info.version = MAKE_NVAPI_VERSION (NV_GPU_PERF_POLICIES_INFO_PARAMS_V1, 1); - perfPolicies_status.version = MAKE_NVAPI_VERSION (NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1, 1); - - hm_NvAPI_GPU_GetPerfPoliciesInfo (hwmon_ctx->hm_nvapi, hwmon_ctx->hm_device[device_id].nvapi, &perfPolicies_info); - - perfPolicies_status.info_value = perfPolicies_info.info_value; - - hm_NvAPI_GPU_GetPerfPoliciesStatus (hwmon_ctx->hm_nvapi, hwmon_ctx->hm_device[device_id].nvapi, &perfPolicies_status); - - if (perfPolicies_status.throttle & 2) - { - if (slowdown_warnings < 3) - { - if (user_options->quiet == false) clear_prompt (); - - log_info ("WARNING: Drivers temperature threshold hit on GPU #%d, expect performance to drop...", device_id + 1); - - if (slowdown_warnings == 2) - { - log_info (""); - } - - if (user_options->quiet == false) send_prompt (); - - slowdown_warnings++; - } - } - else - { - slowdown_warnings = 0; - } - } + if (slowdown_warnings == 1) EVENT_DATA (EVENT_MONITOR_THROTTLE1, &device_id, sizeof (u32)); + if (slowdown_warnings == 2) EVENT_DATA (EVENT_MONITOR_THROTTLE2, &device_id, sizeof (u32)); + if (slowdown_warnings == 3) EVENT_DATA (EVENT_MONITOR_THROTTLE3, &device_id, sizeof (u32)); + } + else + { + slowdown_warnings = 0; } } @@ -174,11 +168,9 @@ static void monitor (hashcat_ctx_t *hashcat_ctx) if (temperature > (int) user_options->gpu_temp_abort) { - log_error ("ERROR: Temperature limit on GPU %d reached, aborting...", device_id + 1); + EVENT_DATA (EVENT_MONITOR_TEMP_ABORT, &device_id, sizeof (u32)); - myabort (status_ctx); - - break; + myabort (hashcat_ctx); } const u32 gpu_temp_retain = user_options->gpu_temp_retain; @@ -259,7 +251,9 @@ static void monitor (hashcat_ctx_t *hashcat_ctx) if (restore_left == 0) { - cycle_restore (hashcat_ctx); + const int rc = cycle_restore (hashcat_ctx); + + if (rc == -1) return -1; restore_left = user_options->restore_timer; } @@ -267,29 +261,13 @@ static void monitor (hashcat_ctx_t *hashcat_ctx) if ((runtime_check == true) && (status_ctx->runtime_start > 0)) { - double ms_paused = status_ctx->ms_paused; - - if (status_ctx->devices_status == STATUS_PAUSED) - { - double ms_paused_tmp = hc_timer_get (status_ctx->timer_paused); - - ms_paused += ms_paused_tmp; - } - - time_t runtime_cur; - - time (&runtime_cur); - - int runtime_left = status_ctx->proc_start + user_options->runtime + status_ctx->prepare_time + (ms_paused / 1000) - runtime_cur; + const int runtime_left = get_runtime_left (hashcat_ctx); if (runtime_left <= 0) { - if (user_options->benchmark == false) - { - if (user_options->quiet == false) log_info ("\nNOTE: Runtime limit reached, aborting...\n"); - } + EVENT_DATA (EVENT_MONITOR_RUNTIME_LIMIT, NULL, 0); - myabort (status_ctx); + myabort (hashcat_ctx); } } @@ -303,7 +281,9 @@ static void monitor (hashcat_ctx_t *hashcat_ctx) { hashes->digests_saved = hashes->digests_done; - save_hash (hashcat_ctx); + const int rc = save_hash (hashcat_ctx); + + if (rc == -1) return -1; } remove_left = user_options->remove_timer; @@ -318,13 +298,7 @@ static void monitor (hashcat_ctx_t *hashcat_ctx) { hc_thread_mutex_lock (status_ctx->mux_display); - if (user_options->quiet == false) clear_prompt (); - - if (user_options->quiet == false) log_info (""); - - status_display (hashcat_ctx); - - if (user_options->quiet == false) log_info (""); + EVENT_DATA (EVENT_MONITOR_STATUS_REFRESH, NULL, 0); hc_thread_mutex_unlock (status_ctx->mux_display); @@ -339,7 +313,9 @@ static void monitor (hashcat_ctx_t *hashcat_ctx) { if (hashes->digests_saved != hashes->digests_done) { - save_hash (hashcat_ctx); + const int rc = save_hash (hashcat_ctx); + + if (rc == -1) return -1; } } @@ -347,20 +323,24 @@ static void monitor (hashcat_ctx_t *hashcat_ctx) if (restore_check == true) { - cycle_restore (hashcat_ctx); + const int rc = cycle_restore (hashcat_ctx); + + if (rc == -1) return -1; } - myfree (fan_speed_chgd); + hcfree (fan_speed_chgd); - myfree (temp_diff_old); - myfree (temp_diff_sum); + hcfree (temp_diff_old); + hcfree (temp_diff_sum); + + return 0; } void *thread_monitor (void *p) { hashcat_ctx_t *hashcat_ctx = (hashcat_ctx_t *) p; - monitor (hashcat_ctx); + monitor (hashcat_ctx); // we should give back some useful returncode return NULL; } diff --git a/src/mpsp.c b/src/mpsp.c index 432ba01aa..7bb31973f 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -10,7 +10,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "logfile.h" #include "convert.h" #include "filehandling.h" @@ -22,8 +22,35 @@ static const char DEF_MASK[] = "?1?2?2?2?2?2?2?3?3?3?3?d?d?d?d"; #define MAX_MFS 5 // 4*charset, 1*mask -void mp_css_split_cnt (const mask_ctx_t *mask_ctx, const hashconfig_t *hashconfig, const u32 css_cnt_orig, u32 css_cnt_lr[2]) +static int sp_comp_val (const void *p1, const void *p2) { + hcstat_table_t *b1 = (hcstat_table_t *) p1; + hcstat_table_t *b2 = (hcstat_table_t *) p2; + + return b2->val - b1->val; +} + +static u32 mp_get_length (char *mask) +{ + u32 len = 0; + + u32 mask_len = strlen (mask); + + for (u32 i = 0; i < mask_len; i++) + { + if (mask[i] == '?') i++; + + len++; + } + + return len; +} + +static void mp_css_split_cnt (hashcat_ctx_t *hashcat_ctx, const u32 css_cnt_orig, u32 css_cnt_lr[2]) +{ + const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + u32 css_cnt_l = mask_ctx->css_cnt; u32 css_cnt_r; @@ -87,14 +114,16 @@ void mp_css_split_cnt (const mask_ctx_t *mask_ctx, const hashconfig_t *hashconfi css_cnt_lr[1] = css_cnt_r; } -void mp_css_append_salt (mask_ctx_t *mask_ctx, salt_t *salt_buf) +static int mp_css_append_salt (hashcat_ctx_t *hashcat_ctx, salt_t *salt_buf) { + mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + u32 salt_len = (u32) salt_buf->salt_len; u8 *salt_buf_ptr = (u8 *) salt_buf->salt_buf; u32 css_cnt_salt = mask_ctx->css_cnt + salt_len; - cs_t *css_buf_salt = (cs_t *) mycalloc (css_cnt_salt, sizeof (cs_t)); + cs_t *css_buf_salt = (cs_t *) hccalloc (hashcat_ctx, css_cnt_salt, sizeof (cs_t)); VERIFY_PTR (css_buf_salt); memcpy (css_buf_salt, mask_ctx->css_buf, mask_ctx->css_cnt * sizeof (cs_t)); @@ -104,17 +133,21 @@ void mp_css_append_salt (mask_ctx_t *mask_ctx, salt_t *salt_buf) css_buf_salt[j].cs_len = 1; } - myfree (mask_ctx->css_buf); + hcfree (mask_ctx->css_buf); mask_ctx->css_buf = css_buf_salt; mask_ctx->css_cnt = css_cnt_salt; + + return 0; } -void mp_css_unicode_expand (mask_ctx_t *mask_ctx) +static int mp_css_unicode_expand (hashcat_ctx_t *hashcat_ctx) { + mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + u32 css_cnt_unicode = mask_ctx->css_cnt * 2; - cs_t *css_buf_unicode = (cs_t *) mycalloc (css_cnt_unicode, sizeof (cs_t)); + cs_t *css_buf_unicode = (cs_t *) hccalloc (hashcat_ctx, css_cnt_unicode, sizeof (cs_t)); VERIFY_PTR (css_buf_unicode); for (u32 i = 0, j = 0; i < mask_ctx->css_cnt; i += 1, j += 2) { @@ -124,21 +157,23 @@ void mp_css_unicode_expand (mask_ctx_t *mask_ctx) css_buf_unicode[j + 1].cs_len = 1; } - myfree (mask_ctx->css_buf); + hcfree (mask_ctx->css_buf); mask_ctx->css_buf = css_buf_unicode; mask_ctx->css_cnt = css_cnt_unicode; + + return 0; } -void mp_css_to_uniq_tbl (u32 css_cnt, cs_t *css, u32 uniq_tbls[SP_PW_MAX][CHARSIZ]) +static int mp_css_to_uniq_tbl (hashcat_ctx_t *hashcat_ctx, u32 css_cnt, cs_t *css, u32 uniq_tbls[SP_PW_MAX][CHARSIZ]) { /* generates a lookup table where key is the char itself for fastest possible lookup performance */ if (css_cnt > SP_PW_MAX) { - log_error ("ERROR: Mask length is too long"); + event_log_error (hashcat_ctx, "Mask length is too long"); - exit (-1); + return -1; } for (u32 css_pos = 0; css_pos < css_cnt; css_pos++) @@ -155,15 +190,19 @@ void mp_css_to_uniq_tbl (u32 css_cnt, cs_t *css, u32 uniq_tbls[SP_PW_MAX][CHARSI uniq_tbl[c] = 1; } } + + return 0; } -static void mp_add_cs_buf (u32 *in_buf, size_t in_len, cs_t *css, u32 css_cnt, const hashconfig_t *hashconfig) +static int mp_add_cs_buf (hashcat_ctx_t *hashcat_ctx, u32 *in_buf, size_t in_len, cs_t *css, u32 css_cnt) { + const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + cs_t *cs = &css[css_cnt]; size_t css_uniq_sz = CHARSIZ * sizeof (u32); - u32 *css_uniq = (u32 *) mymalloc (css_uniq_sz); + u32 *css_uniq = (u32 *) hcmalloc (hashcat_ctx, css_uniq_sz); VERIFY_PTR (css_uniq); size_t i; @@ -189,11 +228,15 @@ static void mp_add_cs_buf (u32 *in_buf, size_t in_len, cs_t *css, u32 css_cnt, c cs->cs_len++; } - myfree (css_uniq); + hcfree (css_uniq); + + return 0; } -static void mp_expand (char *in_buf, size_t in_len, cs_t *mp_sys, cs_t *mp_usr, u32 mp_usr_offset, int interpret, const hashconfig_t *hashconfig, const user_options_t *user_options) +static int mp_expand (hashcat_ctx_t *hashcat_ctx, char *in_buf, size_t in_len, cs_t *mp_sys, cs_t *mp_usr, u32 mp_usr_offset, int interpret) { + const user_options_t *user_options = hashcat_ctx->user_options; + size_t in_pos; for (in_pos = 0; in_pos < in_len; in_pos++) @@ -208,37 +251,41 @@ static void mp_expand (char *in_buf, size_t in_len, cs_t *mp_sys, cs_t *mp_usr, u32 p1 = in_buf[in_pos] & 0xff; + int rc = 0; + switch (p1) { - case 'l': mp_add_cs_buf (mp_sys[0].cs_buf, mp_sys[0].cs_len, mp_usr, mp_usr_offset, hashconfig); + case 'l': rc = mp_add_cs_buf (hashcat_ctx, mp_sys[0].cs_buf, mp_sys[0].cs_len, mp_usr, mp_usr_offset); break; - case 'u': mp_add_cs_buf (mp_sys[1].cs_buf, mp_sys[1].cs_len, mp_usr, mp_usr_offset, hashconfig); + case 'u': rc = mp_add_cs_buf (hashcat_ctx, mp_sys[1].cs_buf, mp_sys[1].cs_len, mp_usr, mp_usr_offset); break; - case 'd': mp_add_cs_buf (mp_sys[2].cs_buf, mp_sys[2].cs_len, mp_usr, mp_usr_offset, hashconfig); + case 'd': rc = mp_add_cs_buf (hashcat_ctx, mp_sys[2].cs_buf, mp_sys[2].cs_len, mp_usr, mp_usr_offset); break; - case 's': mp_add_cs_buf (mp_sys[3].cs_buf, mp_sys[3].cs_len, mp_usr, mp_usr_offset, hashconfig); + case 's': rc = mp_add_cs_buf (hashcat_ctx, mp_sys[3].cs_buf, mp_sys[3].cs_len, mp_usr, mp_usr_offset); break; - case 'a': mp_add_cs_buf (mp_sys[4].cs_buf, mp_sys[4].cs_len, mp_usr, mp_usr_offset, hashconfig); + case 'a': rc = mp_add_cs_buf (hashcat_ctx, mp_sys[4].cs_buf, mp_sys[4].cs_len, mp_usr, mp_usr_offset); break; - case 'b': mp_add_cs_buf (mp_sys[5].cs_buf, mp_sys[5].cs_len, mp_usr, mp_usr_offset, hashconfig); + case 'b': rc = mp_add_cs_buf (hashcat_ctx, mp_sys[5].cs_buf, mp_sys[5].cs_len, mp_usr, mp_usr_offset); break; - case '1': if (mp_usr[0].cs_len == 0) { log_error ("ERROR: Custom-charset 1 is undefined\n"); exit (-1); } - mp_add_cs_buf (mp_usr[0].cs_buf, mp_usr[0].cs_len, mp_usr, mp_usr_offset, hashconfig); + case '1': if (mp_usr[0].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 1 is undefined"); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[0].cs_buf, mp_usr[0].cs_len, mp_usr, mp_usr_offset); break; - case '2': if (mp_usr[1].cs_len == 0) { log_error ("ERROR: Custom-charset 2 is undefined\n"); exit (-1); } - mp_add_cs_buf (mp_usr[1].cs_buf, mp_usr[1].cs_len, mp_usr, mp_usr_offset, hashconfig); + case '2': if (mp_usr[1].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 2 is undefined"); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[1].cs_buf, mp_usr[1].cs_len, mp_usr, mp_usr_offset); break; - case '3': if (mp_usr[2].cs_len == 0) { log_error ("ERROR: Custom-charset 3 is undefined\n"); exit (-1); } - mp_add_cs_buf (mp_usr[2].cs_buf, mp_usr[2].cs_len, mp_usr, mp_usr_offset, hashconfig); + case '3': if (mp_usr[2].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 3 is undefined"); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[2].cs_buf, mp_usr[2].cs_len, mp_usr, mp_usr_offset); break; - case '4': if (mp_usr[3].cs_len == 0) { log_error ("ERROR: Custom-charset 4 is undefined\n"); exit (-1); } - mp_add_cs_buf (mp_usr[3].cs_buf, mp_usr[3].cs_len, mp_usr, mp_usr_offset, hashconfig); + case '4': if (mp_usr[3].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 4 is undefined"); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[3].cs_buf, mp_usr[3].cs_len, mp_usr, mp_usr_offset); break; - case '?': mp_add_cs_buf (&p0, 1, mp_usr, mp_usr_offset, hashconfig); + case '?': rc = mp_add_cs_buf (hashcat_ctx, &p0, 1, mp_usr, mp_usr_offset); break; - default: log_error ("Syntax error: %s", in_buf); - exit (-1); + default: event_log_error (hashcat_ctx, "Syntax error: %s", in_buf); + return -1; } + + if (rc == -1) return -1; } else { @@ -248,18 +295,18 @@ static void mp_expand (char *in_buf, size_t in_len, cs_t *mp_sys, cs_t *mp_usr, if (in_pos == in_len) { - log_error ("ERROR: The hex-charset option always expects couples of exactly 2 hexadecimal chars, failed mask: %s", in_buf); + event_log_error (hashcat_ctx, "The hex-charset option always expects couples of exactly 2 hexadecimal chars, failed mask: %s", in_buf); - exit (-1); + return -1; } u32 p1 = in_buf[in_pos] & 0xff; if ((is_valid_hex_char ((u8) p0) == false) || (is_valid_hex_char ((u8) p1) == false)) { - log_error ("ERROR: Invalid hex character detected in mask %s", in_buf); + event_log_error (hashcat_ctx, "Invalid hex character detected in mask %s", in_buf); - exit (-1); + return -1; } u32 chr = 0; @@ -267,33 +314,27 @@ static void mp_expand (char *in_buf, size_t in_len, cs_t *mp_sys, cs_t *mp_usr, chr = (u32) hex_convert ((u8) p1) << 0; chr |= (u32) hex_convert ((u8) p0) << 4; - mp_add_cs_buf (&chr, 1, mp_usr, mp_usr_offset, hashconfig); + const int rc = mp_add_cs_buf (hashcat_ctx, &chr, 1, mp_usr, mp_usr_offset); + + if (rc == -1) return -1; } else { u32 chr = p0; - mp_add_cs_buf (&chr, 1, mp_usr, mp_usr_offset, hashconfig); + const int rc = mp_add_cs_buf (hashcat_ctx, &chr, 1, mp_usr, mp_usr_offset); + + if (rc == -1) return -1; } } } + + return 0; } -u64 mp_get_sum (u32 css_cnt, cs_t *css) +static int mp_gen_css (hashcat_ctx_t *hashcat_ctx, char *mask_buf, size_t mask_len, cs_t *mp_sys, cs_t *mp_usr, cs_t *css_buf, u32 *css_cnt) { - u64 sum = 1; - - for (u32 css_pos = 0; css_pos < css_cnt; css_pos++) - { - sum *= css[css_pos].cs_len; - } - - return (sum); -} - -cs_t *mp_gen_css (char *mask_buf, size_t mask_len, cs_t *mp_sys, cs_t *mp_usr, u32 *css_cnt, const hashconfig_t *hashconfig, const user_options_t *user_options) -{ - cs_t *css = (cs_t *) mycalloc (256, sizeof (cs_t)); + const user_options_t *user_options = hashcat_ctx->user_options; u32 mask_pos; u32 css_pos; @@ -312,37 +353,41 @@ cs_t *mp_gen_css (char *mask_buf, size_t mask_len, cs_t *mp_sys, cs_t *mp_usr, u u32 chr = (u32) p1; + int rc = 0; + switch (p1) { - case 'l': mp_add_cs_buf (mp_sys[0].cs_buf, mp_sys[0].cs_len, css, css_pos, hashconfig); + case 'l': rc = mp_add_cs_buf (hashcat_ctx, mp_sys[0].cs_buf, mp_sys[0].cs_len, css_buf, css_pos); break; - case 'u': mp_add_cs_buf (mp_sys[1].cs_buf, mp_sys[1].cs_len, css, css_pos, hashconfig); + case 'u': rc = mp_add_cs_buf (hashcat_ctx, mp_sys[1].cs_buf, mp_sys[1].cs_len, css_buf, css_pos); break; - case 'd': mp_add_cs_buf (mp_sys[2].cs_buf, mp_sys[2].cs_len, css, css_pos, hashconfig); + case 'd': rc = mp_add_cs_buf (hashcat_ctx, mp_sys[2].cs_buf, mp_sys[2].cs_len, css_buf, css_pos); break; - case 's': mp_add_cs_buf (mp_sys[3].cs_buf, mp_sys[3].cs_len, css, css_pos, hashconfig); + case 's': rc = mp_add_cs_buf (hashcat_ctx, mp_sys[3].cs_buf, mp_sys[3].cs_len, css_buf, css_pos); break; - case 'a': mp_add_cs_buf (mp_sys[4].cs_buf, mp_sys[4].cs_len, css, css_pos, hashconfig); + case 'a': rc = mp_add_cs_buf (hashcat_ctx, mp_sys[4].cs_buf, mp_sys[4].cs_len, css_buf, css_pos); break; - case 'b': mp_add_cs_buf (mp_sys[5].cs_buf, mp_sys[5].cs_len, css, css_pos, hashconfig); + case 'b': rc = mp_add_cs_buf (hashcat_ctx, mp_sys[5].cs_buf, mp_sys[5].cs_len, css_buf, css_pos); break; - case '1': if (mp_usr[0].cs_len == 0) { log_error ("ERROR: Custom-charset 1 is undefined\n"); exit (-1); } - mp_add_cs_buf (mp_usr[0].cs_buf, mp_usr[0].cs_len, css, css_pos, hashconfig); + case '1': if (mp_usr[0].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 1 is undefined"); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[0].cs_buf, mp_usr[0].cs_len, css_buf, css_pos); break; - case '2': if (mp_usr[1].cs_len == 0) { log_error ("ERROR: Custom-charset 2 is undefined\n"); exit (-1); } - mp_add_cs_buf (mp_usr[1].cs_buf, mp_usr[1].cs_len, css, css_pos, hashconfig); + case '2': if (mp_usr[1].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 2 is undefined"); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[1].cs_buf, mp_usr[1].cs_len, css_buf, css_pos); break; - case '3': if (mp_usr[2].cs_len == 0) { log_error ("ERROR: Custom-charset 3 is undefined\n"); exit (-1); } - mp_add_cs_buf (mp_usr[2].cs_buf, mp_usr[2].cs_len, css, css_pos, hashconfig); + case '3': if (mp_usr[2].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 3 is undefined"); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[2].cs_buf, mp_usr[2].cs_len, css_buf, css_pos); break; - case '4': if (mp_usr[3].cs_len == 0) { log_error ("ERROR: Custom-charset 4 is undefined\n"); exit (-1); } - mp_add_cs_buf (mp_usr[3].cs_buf, mp_usr[3].cs_len, css, css_pos, hashconfig); + case '4': if (mp_usr[3].cs_len == 0) { event_log_error (hashcat_ctx, "Custom-charset 4 is undefined"); return -1; } + rc = mp_add_cs_buf (hashcat_ctx, mp_usr[3].cs_buf, mp_usr[3].cs_len, css_buf, css_pos); break; - case '?': mp_add_cs_buf (&chr, 1, css, css_pos, hashconfig); + case '?': rc = mp_add_cs_buf (hashcat_ctx, &chr, 1, css_buf, css_pos); break; - default: log_error ("ERROR: Syntax error: %s", mask_buf); - exit (-1); + default: event_log_error (hashcat_ctx, "Syntax error: %s", mask_buf); + return -1; } + + if (rc == -1) return -1; } else { @@ -354,9 +399,9 @@ cs_t *mp_gen_css (char *mask_buf, size_t mask_len, cs_t *mp_sys, cs_t *mp_usr, u if (mask_pos == mask_len) { - log_error ("ERROR: The hex-charset option always expects couples of exactly 2 hexadecimal chars, failed mask: %s", mask_buf); + event_log_error (hashcat_ctx, "The hex-charset option always expects couples of exactly 2 hexadecimal chars, failed mask: %s", mask_buf); - exit (-1); + return -1; } char p1 = mask_buf[mask_pos]; @@ -365,9 +410,9 @@ cs_t *mp_gen_css (char *mask_buf, size_t mask_len, cs_t *mp_sys, cs_t *mp_usr, u if ((is_valid_hex_char ((u8) p0) == false) || (is_valid_hex_char ((u8) p1) == false)) { - log_error ("ERROR: Invalid hex character detected in mask %s", mask_buf); + event_log_error (hashcat_ctx, "Invalid hex character detected in mask %s", mask_buf); - exit (-1); + return -1; } u32 chr = 0; @@ -375,141 +420,36 @@ cs_t *mp_gen_css (char *mask_buf, size_t mask_len, cs_t *mp_sys, cs_t *mp_usr, u chr |= (u32) hex_convert ((u8) p1) << 0; chr |= (u32) hex_convert ((u8) p0) << 4; - mp_add_cs_buf (&chr, 1, css, css_pos, hashconfig); + const int rc = mp_add_cs_buf (hashcat_ctx, &chr, 1, css_buf, css_pos); + + if (rc == -1) return -1; } else { u32 chr = (u32) p0; - mp_add_cs_buf (&chr, 1, css, css_pos, hashconfig); + const int rc = mp_add_cs_buf (hashcat_ctx, &chr, 1, css_buf, css_pos); + + if (rc == -1) return -1; } } } if (css_pos == 0) { - log_error ("ERROR: Invalid mask length (0)"); + event_log_error (hashcat_ctx, "Invalid mask length (0)"); - exit (-1); + return -1; } *css_cnt = css_pos; - return (css); + return 0; } -void mp_exec (u64 val, char *buf, cs_t *css, int css_cnt) +static int mp_get_truncated_mask (hashcat_ctx_t *hashcat_ctx, const char *mask_buf, const size_t mask_len, const u32 len, char *new_mask_buf) { - for (int i = 0; i < css_cnt; i++) - { - u32 len = css[i].cs_len; - u64 next = val / len; - u32 pos = val % len; - buf[i] = (char) (css[i].cs_buf[pos] & 0xff); - val = next; - } -} - -u32 mp_get_length (char *mask) -{ - u32 len = 0; - - u32 mask_len = strlen (mask); - - for (u32 i = 0; i < mask_len; i++) - { - if (mask[i] == '?') i++; - - len++; - } - - return len; -} - -void mp_cut_at (char *mask, u32 max) -{ - u32 i; - u32 j; - u32 mask_len = strlen (mask); - - for (i = 0, j = 0; i < mask_len && j < max; i++, j++) - { - if (mask[i] == '?') i++; - } - - mask[i] = 0; -} - -void mp_setup_sys (cs_t *mp_sys) -{ - u32 pos; - u32 chr; - u32 donec[CHARSIZ] = { 0 }; - - for (pos = 0, chr = 'a'; chr <= 'z'; chr++) { donec[chr] = 1; - mp_sys[0].cs_buf[pos++] = chr; - mp_sys[0].cs_len = pos; } - - for (pos = 0, chr = 'A'; chr <= 'Z'; chr++) { donec[chr] = 1; - mp_sys[1].cs_buf[pos++] = chr; - mp_sys[1].cs_len = pos; } - - for (pos = 0, chr = '0'; chr <= '9'; chr++) { donec[chr] = 1; - mp_sys[2].cs_buf[pos++] = chr; - mp_sys[2].cs_len = pos; } - - for (pos = 0, chr = 0x20; chr <= 0x7e; chr++) { if (donec[chr]) continue; - mp_sys[3].cs_buf[pos++] = chr; - mp_sys[3].cs_len = pos; } - - for (pos = 0, chr = 0x20; chr <= 0x7e; chr++) { mp_sys[4].cs_buf[pos++] = chr; - mp_sys[4].cs_len = pos; } - - for (pos = 0, chr = 0x00; chr <= 0xff; chr++) { mp_sys[5].cs_buf[pos++] = chr; - mp_sys[5].cs_len = pos; } -} - -void mp_setup_usr (cs_t *mp_sys, cs_t *mp_usr, char *buf, u32 index, const hashconfig_t *hashconfig, const user_options_t *user_options) -{ - FILE *fp = fopen (buf, "rb"); - - if (fp == NULL || feof (fp)) // feof() in case if file is empty - { - mp_expand (buf, strlen (buf), mp_sys, mp_usr, index, 1, hashconfig, user_options); - } - else - { - char mp_file[1024] = { 0 }; - - int len = (int) fread (mp_file, 1, sizeof (mp_file) - 1, fp); - - fclose (fp); - - len = in_superchop (mp_file); - - if (len == 0) - { - log_info ("WARNING: Charset file corrupted"); - - mp_expand (buf, strlen (buf), mp_sys, mp_usr, index, 1, hashconfig, user_options); - } - else - { - mp_expand (mp_file, (size_t) len, mp_sys, mp_usr, index, 0, hashconfig, user_options); - } - } -} - -void mp_reset_usr (cs_t *mp_usr, u32 index) -{ - mp_usr[index].cs_len = 0; - - memset (mp_usr[index].cs_buf, 0, sizeof (mp_usr[index].cs_buf)); -} - -static char *mp_get_truncated_mask (const char *mask_buf, const size_t mask_len, const u32 len, const user_options_t *user_options) -{ - char *new_mask_buf = (char *) mymalloc (256); + const user_options_t *user_options = hashcat_ctx->user_options; u32 mask_pos; @@ -539,9 +479,9 @@ static char *mp_get_truncated_mask (const char *mask_buf, const size_t mask_len, if (mask_pos == mask_len) { - log_error ("ERROR: The hex-charset option always expects couples of exactly 2 hexadecimal chars, failed mask: %s", mask_buf); + event_log_error (hashcat_ctx, "The hex-charset option always expects couples of exactly 2 hexadecimal chars, failed mask: %s", mask_buf); - exit (-1); + return -1; } char p1 = mask_buf[mask_pos]; @@ -550,9 +490,9 @@ static char *mp_get_truncated_mask (const char *mask_buf, const size_t mask_len, if ((is_valid_hex_char ((u8) p0) == false) || (is_valid_hex_char ((u8) p1) == false)) { - log_error ("ERROR: Invalid hex character detected in mask: %s", mask_buf); + event_log_error (hashcat_ctx, "Invalid hex character detected in mask: %s", mask_buf); - exit (-1); + return -1; } new_mask_buf[mask_pos] = p1; @@ -560,60 +500,99 @@ static char *mp_get_truncated_mask (const char *mask_buf, const size_t mask_len, } } - if (css_pos == len) return (new_mask_buf); - - myfree (new_mask_buf); - - return (NULL); + return 0; } -u64 sp_get_sum (u32 start, u32 stop, cs_t *root_css_buf) +static void mp_setup_sys (cs_t *mp_sys) { - u64 sum = 1; + u32 pos; + u32 chr; + u32 donec[CHARSIZ] = { 0 }; - u32 i; + for (pos = 0, chr = 'a'; chr <= 'z'; chr++) { donec[chr] = 1; + mp_sys[0].cs_buf[pos++] = chr; + mp_sys[0].cs_len = pos; } - for (i = start; i < stop; i++) + for (pos = 0, chr = 'A'; chr <= 'Z'; chr++) { donec[chr] = 1; + mp_sys[1].cs_buf[pos++] = chr; + mp_sys[1].cs_len = pos; } + + for (pos = 0, chr = '0'; chr <= '9'; chr++) { donec[chr] = 1; + mp_sys[2].cs_buf[pos++] = chr; + mp_sys[2].cs_len = pos; } + + for (pos = 0, chr = 0x20; chr <= 0x7e; chr++) { if (donec[chr]) continue; + mp_sys[3].cs_buf[pos++] = chr; + mp_sys[3].cs_len = pos; } + + for (pos = 0, chr = 0x20; chr <= 0x7e; chr++) { mp_sys[4].cs_buf[pos++] = chr; + mp_sys[4].cs_len = pos; } + + for (pos = 0, chr = 0x00; chr <= 0xff; chr++) { mp_sys[5].cs_buf[pos++] = chr; + mp_sys[5].cs_len = pos; } +} + +static int mp_setup_usr (hashcat_ctx_t *hashcat_ctx, cs_t *mp_sys, cs_t *mp_usr, char *buf, u32 index) +{ + FILE *fp = fopen (buf, "rb"); + + if (fp == NULL || feof (fp)) // feof() in case if file is empty { - sum *= root_css_buf[i].cs_len; + const int rc = mp_expand (hashcat_ctx, buf, strlen (buf), mp_sys, mp_usr, index, 1); + + if (rc == -1) return -1; + } + else + { + char mp_file[1024] = { 0 }; + + int len = (int) fread (mp_file, 1, sizeof (mp_file) - 1, fp); + + fclose (fp); + + len = in_superchop (mp_file); + + if (len == 0) + { + event_log_warning (hashcat_ctx, "Charset file corrupted"); + + const int rc = mp_expand (hashcat_ctx, buf, strlen (buf), mp_sys, mp_usr, index, 1); + + if (rc == -1) return -1; + } + else + { + const int rc = mp_expand (hashcat_ctx, mp_file, (size_t) len, mp_sys, mp_usr, index, 0); + + if (rc == -1) return -1; + } } - return (sum); + return 0; } -void sp_exec (u64 ctx, char *pw_buf, cs_t *root_css_buf, cs_t *markov_css_buf, u32 start, u32 stop) +static void mp_reset_usr (cs_t *mp_usr, u32 index) { - u64 v = ctx; + mp_usr[index].cs_len = 0; - cs_t *cs = &root_css_buf[start]; - - u32 i; - - for (i = start; i < stop; i++) - { - const u64 m = v % cs->cs_len; - const u64 d = v / cs->cs_len; - - v = d; - - const u32 k = cs->cs_buf[m]; - - pw_buf[i - start] = (char) k; - - cs = &markov_css_buf[(i * CHARSIZ) + k]; - } + memset (mp_usr[index].cs_buf, 0, sizeof (mp_usr[index].cs_buf)); } -int sp_comp_val (const void *p1, const void *p2) +static int sp_setup_tbl (hashcat_ctx_t *hashcat_ctx) { - hcstat_table_t *b1 = (hcstat_table_t *) p1; - hcstat_table_t *b2 = (hcstat_table_t *) p2; + folder_config_t *folder_config = hashcat_ctx->folder_config; + mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + user_options_t *user_options = hashcat_ctx->user_options; - return b2->val - b1->val; -} + char *shared_dir = folder_config->shared_dir; + + char *hcstat = user_options->markov_hcstat; + u32 disable = user_options->markov_disable; + u32 classic = user_options->markov_classic; + + hcstat_table_t *root_table_buf = mask_ctx->root_table_buf; + hcstat_table_t *markov_table_buf = mask_ctx->markov_table_buf; -void sp_setup_tbl (const char *shared_dir, char *hcstat, u32 disable, u32 classic, hcstat_table_t *root_table_buf, hcstat_table_t *markov_table_buf) -{ u32 i; u32 j; u32 k; @@ -622,7 +601,7 @@ void sp_setup_tbl (const char *shared_dir, char *hcstat, u32 disable, u32 classi * Initialize hcstats */ - u64 *root_stats_buf = (u64 *) mycalloc (SP_ROOT_CNT, sizeof (u64)); + u64 *root_stats_buf = (u64 *) hccalloc (hashcat_ctx, SP_ROOT_CNT, sizeof (u64)); VERIFY_PTR (root_stats_buf); u64 *root_stats_ptr = root_stats_buf; @@ -635,7 +614,7 @@ void sp_setup_tbl (const char *shared_dir, char *hcstat, u32 disable, u32 classi root_stats_ptr += CHARSIZ; } - u64 *markov_stats_buf = (u64 *) mycalloc (SP_MARKOV_CNT, sizeof (u64)); + u64 *markov_stats_buf = (u64 *) hccalloc (hashcat_ctx, SP_MARKOV_CNT, sizeof (u64)); VERIFY_PTR (markov_stats_buf); u64 *markov_stats_ptr = markov_stats_buf; @@ -668,27 +647,27 @@ void sp_setup_tbl (const char *shared_dir, char *hcstat, u32 disable, u32 classi if (fd == NULL) { - log_error ("%s: %s", hcstat, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", hcstat, strerror (errno)); - exit (-1); + return -1; } if (fread (root_stats_buf, sizeof (u64), SP_ROOT_CNT, fd) != SP_ROOT_CNT) { - log_error ("%s: Could not load data", hcstat); + event_log_error (hashcat_ctx, "%s: Could not load data", hcstat); fclose (fd); - exit (-1); + return -1; } if (fread (markov_stats_buf, sizeof (u64), SP_MARKOV_CNT, fd) != SP_MARKOV_CNT) { - log_error ("%s: Could not load data", hcstat); + event_log_error (hashcat_ctx, "%s: Could not load data", hcstat); fclose (fd); - exit (-1); + return -1; } fclose (fd); @@ -794,8 +773,8 @@ void sp_setup_tbl (const char *shared_dir, char *hcstat, u32 disable, u32 classi markov_table_buf[i].val = markov_stats_buf[i]; } - myfree (root_stats_buf); - myfree (markov_stats_buf); + hcfree (root_stats_buf); + hcfree (markov_stats_buf); /** * Finally sort them @@ -813,9 +792,25 @@ void sp_setup_tbl (const char *shared_dir, char *hcstat, u32 disable, u32 classi qsort (markov_table_buf_by_key[i][j], CHARSIZ, sizeof (hcstat_table_t), sp_comp_val); } } + + return 0; } -void sp_tbl_to_css (hcstat_table_t *root_table_buf, hcstat_table_t *markov_table_buf, cs_t *root_css_buf, cs_t *markov_css_buf, u32 threshold, u32 uniq_tbls[SP_PW_MAX][CHARSIZ]) +static u64 sp_get_sum (u32 start, u32 stop, cs_t *root_css_buf) +{ + u64 sum = 1; + + u32 i; + + for (i = start; i < stop; i++) + { + sum *= root_css_buf[i].cs_len; + } + + return (sum); +} + +static void sp_tbl_to_css (hcstat_table_t *root_table_buf, hcstat_table_t *markov_table_buf, cs_t *root_css_buf, cs_t *markov_css_buf, u32 threshold, u32 uniq_tbls[SP_PW_MAX][CHARSIZ]) { memset (root_css_buf, 0, SP_PW_MAX * sizeof (cs_t)); memset (markov_css_buf, 0, SP_PW_MAX * CHARSIZ * sizeof (cs_t)); @@ -882,88 +877,74 @@ void sp_tbl_to_css (hcstat_table_t *root_table_buf, hcstat_table_t *markov_table */ } -void sp_stretch_root (hcstat_table_t *in, hcstat_table_t *out) +void sp_exec (u64 ctx, char *pw_buf, cs_t *root_css_buf, cs_t *markov_css_buf, u32 start, u32 stop) { - for (u32 i = 0; i < SP_PW_MAX; i += 2) + u64 v = ctx; + + cs_t *cs = &root_css_buf[start]; + + u32 i; + + for (i = start; i < stop; i++) { - memcpy (out, in, CHARSIZ * sizeof (hcstat_table_t)); + const u64 m = v % cs->cs_len; + const u64 d = v / cs->cs_len; - out += CHARSIZ; - in += CHARSIZ; + v = d; - out->key = 0; - out->val = 1; + const u32 k = cs->cs_buf[m]; - out++; + pw_buf[i - start] = (char) k; - for (u32 j = 1; j < CHARSIZ; j++) - { - out->key = j; - out->val = 0; - - out++; - } + cs = &markov_css_buf[(i * CHARSIZ) + k]; } } -void sp_stretch_markov (hcstat_table_t *in, hcstat_table_t *out) +static int mask_append_final (hashcat_ctx_t *hashcat_ctx, const char *mask) { - for (u32 i = 0; i < SP_PW_MAX; i += 2) - { - memcpy (out, in, CHARSIZ * CHARSIZ * sizeof (hcstat_table_t)); + mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; - out += CHARSIZ * CHARSIZ; - in += CHARSIZ * CHARSIZ; - - for (u32 j = 0; j < CHARSIZ; j++) - { - out->key = 0; - out->val = 1; - - out++; - - for (u32 k = 1; k < CHARSIZ; k++) - { - out->key = k; - out->val = 0; - - out++; - } - } - } -} - -static void mask_append_final (mask_ctx_t *mask_ctx, const char *mask) -{ if (mask_ctx->masks_avail == mask_ctx->masks_cnt) { - mask_ctx->masks = (char **) myrealloc (mask_ctx->masks, mask_ctx->masks_avail * sizeof (char *), INCR_MASKS * sizeof (char *)); + mask_ctx->masks = (char **) hcrealloc (hashcat_ctx, mask_ctx->masks, mask_ctx->masks_avail * sizeof (char *), INCR_MASKS * sizeof (char *)); VERIFY_PTR (mask_ctx->masks); mask_ctx->masks_avail += INCR_MASKS; } - mask_ctx->masks[mask_ctx->masks_cnt] = mystrdup (mask); + mask_ctx->masks[mask_ctx->masks_cnt] = hcstrdup (hashcat_ctx, mask); mask_ctx->masks_cnt++; + + return 0; } -static void mask_append (mask_ctx_t *mask_ctx, const user_options_t *user_options, const char *mask) +static int mask_append (hashcat_ctx_t *hashcat_ctx, const char *mask) { + user_options_t *user_options = hashcat_ctx->user_options; + if (user_options->increment == true) { - for (u32 mask_len = user_options->increment_min; mask_len <= user_options->increment_max; mask_len++) + for (u32 increment_len = user_options->increment_min; increment_len <= user_options->increment_max; increment_len++) { - char *mask_truncated = mp_get_truncated_mask (mask, strlen (mask), mask_len, user_options); + char *mask_truncated = (char *) hcmalloc (hashcat_ctx, 256); VERIFY_PTR (mask_truncated); - if (mask_truncated == NULL) break; + const int rc_truncated_mask = mp_get_truncated_mask (hashcat_ctx, mask, strlen (mask), increment_len, mask_truncated); - mask_append_final (mask_ctx, mask_truncated); + if (rc_truncated_mask == -1) break; + + const int rc = mask_append_final (hashcat_ctx, mask_truncated); + + if (rc == -1) return -1; } } else { - mask_append_final (mask_ctx, mask); + const int rc = mask_append_final (hashcat_ctx, mask); + + if (rc == -1) return -1; } + + return 0; } int mask_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) @@ -991,11 +972,15 @@ int mask_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) if (rc_mask_file == -1) return -1; - mask_ctx->css_buf = mp_gen_css (mask_ctx->mask, strlen (mask_ctx->mask), mask_ctx->mp_sys, mask_ctx->mp_usr, &mask_ctx->css_cnt, hashconfig, user_options); + mask_ctx->css_buf = (cs_t *) hccalloc (hashcat_ctx, 256, sizeof (cs_t)); VERIFY_PTR (mask_ctx->css_buf); + + const int rc_gen_css = mp_gen_css (hashcat_ctx, mask_ctx->mask, strlen (mask_ctx->mask), mask_ctx->mp_sys, mask_ctx->mp_usr, mask_ctx->css_buf, &mask_ctx->css_cnt); + + if (rc_gen_css == -1) return -1; u32 uniq_tbls[SP_PW_MAX][CHARSIZ] = { { 0 } }; - mp_css_to_uniq_tbl (mask_ctx->css_cnt, mask_ctx->css_buf, uniq_tbls); + mp_css_to_uniq_tbl (hashcat_ctx, mask_ctx->css_cnt, mask_ctx->css_buf, uniq_tbls); sp_tbl_to_css (mask_ctx->root_table_buf, mask_ctx->markov_table_buf, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, user_options->markov_threshold, uniq_tbls); @@ -1020,7 +1005,11 @@ int mask_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) if (user_options->attack_mode == ATTACK_MODE_BF) // always true { - mask_ctx->css_buf = mp_gen_css (mask_ctx->mask, strlen (mask_ctx->mask), mask_ctx->mp_sys, mask_ctx->mp_usr, &mask_ctx->css_cnt, hashconfig, user_options); + mask_ctx->css_buf = (cs_t *) hccalloc (hashcat_ctx, 256, sizeof (cs_t)); VERIFY_PTR (mask_ctx->css_buf); + + const int rc_gen_css = mp_gen_css (hashcat_ctx, mask_ctx->mask, strlen (mask_ctx->mask), mask_ctx->mp_sys, mask_ctx->mp_usr, mask_ctx->css_buf, &mask_ctx->css_cnt); + + if (rc_gen_css == -1) return -1; // special case for benchmark @@ -1045,12 +1034,12 @@ int mask_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) { if (mask_ctx->css_cnt < mask_min) { - log_info ("WARNING: Skipping mask '%s' because it is smaller than the minimum password length", mask_ctx->mask); + event_log_warning (hashcat_ctx, "Skipping mask '%s' because it is smaller than the minimum password length", mask_ctx->mask); } if (mask_ctx->css_cnt > mask_max) { - log_info ("WARNING: Skipping mask '%s' because it is larger than the maximum password length", mask_ctx->mask); + event_log_warning (hashcat_ctx, "Skipping mask '%s' because it is larger than the maximum password length", mask_ctx->mask); } // skip to next mask @@ -1068,7 +1057,9 @@ int mask_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) if (hashconfig->opts_type & OPTS_TYPE_PT_UNICODE) { - mp_css_unicode_expand (mask_ctx); + const int rc = mp_css_unicode_expand (hashcat_ctx); + + if (rc == -1) return -1; } u32 css_cnt_orig = mask_ctx->css_cnt; @@ -1077,13 +1068,15 @@ int mask_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) { if (hashconfig->opti_type & OPTI_TYPE_APPENDED_SALT) { - mp_css_append_salt (mask_ctx, &hashes->salts_buf[0]); + const int rc = mp_css_append_salt (hashcat_ctx, &hashes->salts_buf[0]); + + if (rc == -1) return -1; } } u32 uniq_tbls[SP_PW_MAX][CHARSIZ] = { { 0 } }; - mp_css_to_uniq_tbl (mask_ctx->css_cnt, mask_ctx->css_buf, uniq_tbls); + mp_css_to_uniq_tbl (hashcat_ctx, mask_ctx->css_cnt, mask_ctx->css_buf, uniq_tbls); sp_tbl_to_css (mask_ctx->root_table_buf, mask_ctx->markov_table_buf, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, user_options->markov_threshold, uniq_tbls); @@ -1093,7 +1086,7 @@ int mask_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) u32 css_cnt_lr[2]; - mp_css_split_cnt (mask_ctx, hashconfig, css_cnt_orig, css_cnt_lr); + mp_css_split_cnt (hashcat_ctx, css_cnt_orig, css_cnt_lr); mask_ctx->bfs_cnt = sp_get_sum (0, css_cnt_lr[1], mask_ctx->root_css_buf); @@ -1108,8 +1101,6 @@ int mask_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) { - folder_config_t *folder_config = hashcat_ctx->folder_config; - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; user_options_t *user_options = hashcat_ctx->user_options; @@ -1127,13 +1118,13 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) mask_ctx->enabled = true; - mask_ctx->root_table_buf = (hcstat_table_t *) mycalloc (SP_ROOT_CNT, sizeof (hcstat_table_t)); - mask_ctx->markov_table_buf = (hcstat_table_t *) mycalloc (SP_MARKOV_CNT, sizeof (hcstat_table_t)); + mask_ctx->root_table_buf = (hcstat_table_t *) hccalloc (hashcat_ctx, SP_ROOT_CNT, sizeof (hcstat_table_t)); VERIFY_PTR (mask_ctx->root_table_buf); + mask_ctx->markov_table_buf = (hcstat_table_t *) hccalloc (hashcat_ctx, SP_MARKOV_CNT, sizeof (hcstat_table_t)); VERIFY_PTR (mask_ctx->markov_table_buf); - sp_setup_tbl (folder_config->shared_dir, user_options->markov_hcstat, user_options->markov_disable, user_options->markov_classic, mask_ctx->root_table_buf, mask_ctx->markov_table_buf); + sp_setup_tbl (hashcat_ctx); - mask_ctx->root_css_buf = (cs_t *) mycalloc (SP_PW_MAX, sizeof (cs_t)); - mask_ctx->markov_css_buf = (cs_t *) mycalloc (SP_PW_MAX * CHARSIZ, sizeof (cs_t)); + mask_ctx->root_css_buf = (cs_t *) hccalloc (hashcat_ctx, SP_PW_MAX, sizeof (cs_t)); VERIFY_PTR (mask_ctx->root_css_buf); + mask_ctx->markov_css_buf = (cs_t *) hccalloc (hashcat_ctx, SP_PW_MAX * CHARSIZ, sizeof (cs_t)); VERIFY_PTR (mask_ctx->markov_css_buf); mask_ctx->css_cnt = 0; mask_ctx->css_buf = NULL; @@ -1144,14 +1135,14 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) mask_ctx->masks_pos = 0; mask_ctx->masks_cnt = 0; - mask_ctx->mfs = (mf_t *) mycalloc (MAX_MFS, sizeof (mf_t)); + mask_ctx->mfs = (mf_t *) hccalloc (hashcat_ctx, MAX_MFS, sizeof (mf_t)); VERIFY_PTR (mask_ctx->mfs); mp_setup_sys (mask_ctx->mp_sys); - if (user_options->custom_charset_1) mp_setup_usr (mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_1, 0, hashconfig, user_options); - if (user_options->custom_charset_2) mp_setup_usr (mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_2, 1, hashconfig, user_options); - if (user_options->custom_charset_3) mp_setup_usr (mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_3, 2, hashconfig, user_options); - if (user_options->custom_charset_4) mp_setup_usr (mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_4, 3, hashconfig, user_options); + if (user_options->custom_charset_1) mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_1, 0); + if (user_options->custom_charset_2) mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_2, 1); + if (user_options->custom_charset_3) mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_3, 2); + if (user_options->custom_charset_4) mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_4, 3); if (user_options->attack_mode == ATTACK_MODE_BF) { @@ -1165,7 +1156,9 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (stat (arg, &file_stat) == -1) { - mask_append (mask_ctx, user_options, arg); + const int rc = mask_append (hashcat_ctx, arg); + + if (rc == -1) return -1; } else { @@ -1177,7 +1170,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (stat (arg, &file_stat) == -1) { - log_error ("ERROR: %s: %s", arg, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", arg, strerror (errno)); return -1; } @@ -1188,12 +1181,12 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (mask_fp == NULL) { - log_error ("ERROR: %s: %s", arg, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", arg, strerror (errno)); return -1; } - char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE); + char *line_buf = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (line_buf); while (!feof (mask_fp)) { @@ -1203,16 +1196,18 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (line_buf[0] == '#') continue; - mask_append (mask_ctx, user_options, line_buf); + const int rc = mask_append (hashcat_ctx, line_buf); + + if (rc == -1) return -1; } - myfree (line_buf); + hcfree (line_buf); fclose (mask_fp); } else { - log_error ("ERROR: %s: unsupported file-type", arg); + event_log_error (hashcat_ctx, "%s: unsupported file-type", arg); return -1; } @@ -1223,14 +1218,18 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) { const char *mask = DEF_MASK; - mask_append (mask_ctx, user_options, mask); + const int rc = mask_append (hashcat_ctx, mask); + + if (rc == -1) return -1; } } else { const char *mask = hashconfig_benchmark_mask (hashcat_ctx); - mask_append (mask_ctx, user_options, mask); + const int rc = mask_append (hashcat_ctx, mask); + + if (rc == -1) return -1; } } else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) @@ -1245,7 +1244,9 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (stat (arg, &file_stat) == -1) { - mask_append (mask_ctx, user_options, arg); + const int rc = mask_append (hashcat_ctx, arg); + + if (rc == -1) return -1; } else { @@ -1257,12 +1258,12 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (mask_fp == NULL) { - log_error ("ERROR: %s: %s", arg, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", arg, strerror (errno)); return -1; } - char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE); + char *line_buf = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (line_buf); while (!feof (mask_fp)) { @@ -1272,16 +1273,18 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (line_buf[0] == '#') continue; - mask_append (mask_ctx, user_options, line_buf); + const int rc = mask_append (hashcat_ctx, line_buf); + + if (rc == -1) return -1; } - myfree (line_buf); + hcfree (line_buf); fclose (mask_fp); } else { - log_error ("ERROR: %s: unsupported file-type", arg); + event_log_error (hashcat_ctx, "%s: unsupported file-type", arg); return -1; } @@ -1299,7 +1302,9 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (stat (arg, &file_stat) == -1) { - mask_append (mask_ctx, user_options, arg); + const int rc = mask_append (hashcat_ctx, arg); + + if (rc == -1) return -1; } else { @@ -1311,12 +1316,12 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (mask_fp == NULL) { - log_error ("ERROR: %s: %s", arg, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", arg, strerror (errno)); return -1; } - char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE); + char *line_buf = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (line_buf); while (!feof (mask_fp)) { @@ -1326,16 +1331,18 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (line_buf[0] == '#') continue; - mask_append (mask_ctx, user_options, line_buf); + const int rc = mask_append (hashcat_ctx, line_buf); + + if (rc == -1) return -1; } - myfree (line_buf); + hcfree (line_buf); fclose (mask_fp); } else { - log_error ("ERROR: %s: unsupported file-type", arg); + event_log_error (hashcat_ctx, "%s: unsupported file-type", arg); return -1; } @@ -1344,7 +1351,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (mask_ctx->masks_cnt == 0) { - log_error ("ERROR: Invalid mask"); + event_log_error (hashcat_ctx, "Invalid mask"); return -1; } @@ -1360,29 +1367,28 @@ void mask_ctx_destroy (hashcat_ctx_t *hashcat_ctx) if (mask_ctx->enabled == false) return; - myfree (mask_ctx->css_buf); + hcfree (mask_ctx->css_buf); - myfree (mask_ctx->root_css_buf); - myfree (mask_ctx->markov_css_buf); + hcfree (mask_ctx->root_css_buf); + hcfree (mask_ctx->markov_css_buf); - myfree (mask_ctx->root_table_buf); - myfree (mask_ctx->markov_table_buf); + hcfree (mask_ctx->root_table_buf); + hcfree (mask_ctx->markov_table_buf); for (u32 mask_pos = 0; mask_pos < mask_ctx->masks_cnt; mask_pos++) { - myfree (mask_ctx->masks[mask_pos]); + hcfree (mask_ctx->masks[mask_pos]); } - myfree (mask_ctx->masks); + hcfree (mask_ctx->masks); - myfree (mask_ctx->mfs); + hcfree (mask_ctx->mfs); memset (mask_ctx, 0, sizeof (mask_ctx_t)); } int mask_ctx_parse_maskfile (hashcat_ctx_t *hashcat_ctx) { - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; user_options_t *user_options = hashcat_ctx->user_options; @@ -1432,7 +1438,7 @@ int mask_ctx_parse_maskfile (hashcat_ctx_t *hashcat_ctx) if (mf_cnt >= MAX_MFS) { - log_error ("ERROR: Invalid line '%s' in maskfile", mask_buf); + event_log_error (hashcat_ctx, "Invalid line '%s' in maskfile", mask_buf); return -1; } @@ -1457,25 +1463,25 @@ int mask_ctx_parse_maskfile (hashcat_ctx_t *hashcat_ctx) case 0: user_options->custom_charset_1 = mfs[0].mf_buf; mp_reset_usr (mask_ctx->mp_usr, 0); - mp_setup_usr (mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_1, 0, hashconfig, user_options); + mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_1, 0); break; case 1: user_options->custom_charset_2 = mfs[1].mf_buf; mp_reset_usr (mask_ctx->mp_usr, 1); - mp_setup_usr (mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_2, 1, hashconfig, user_options); + mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_2, 1); break; case 2: user_options->custom_charset_3 = mfs[2].mf_buf; mp_reset_usr (mask_ctx->mp_usr, 2); - mp_setup_usr (mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_3, 2, hashconfig, user_options); + mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_3, 2); break; case 3: user_options->custom_charset_4 = mfs[3].mf_buf; mp_reset_usr (mask_ctx->mp_usr, 3); - mp_setup_usr (mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_4, 3, hashconfig, user_options); + mp_setup_usr (hashcat_ctx, mask_ctx->mp_sys, mask_ctx->mp_usr, user_options->custom_charset_4, 3); break; } } diff --git a/src/opencl.c b/src/opencl.c index 94e127480..c77e3d9b2 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -6,13 +6,11 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" #include "locking.h" #include "thread.h" #include "timer.h" #include "tuningdb.h" #include "rp_cpu.h" -#include "terminal.h" #include "mpsp.h" #include "straight.h" #include "combinator.h" @@ -24,12 +22,14 @@ #include "shared.h" #include "hashes.h" #include "cpu_md5.h" +#include "event.h" +#include "dynloader.h" #include "opencl.h" static const u32 full01 = 0x01010101; static const u32 full80 = 0x80808080; -static double TARGET_MS_PROFILE[4] = { 2, 12, 96, 480 }; +static double TARGET_MSEC_PROFILE[4] = { 2, 12, 96, 480 }; static void generate_source_kernel_filename (const u32 attack_exec, const u32 attack_kern, const u32 kern_type, char *shared_dir, char *source_file) { @@ -97,13 +97,13 @@ static void generate_cached_kernel_amp_filename (const u32 attack_kern, char *pr snprintf (cached_file, 255, "%s/kernels/amp_a%d.%s.kernel", profile_dir, attack_kern, device_name_chksum); } -static u32 setup_opencl_platforms_filter (const char *opencl_platforms) +static int setup_opencl_platforms_filter (hashcat_ctx_t *hashcat_ctx, const char *opencl_platforms, u32 *out) { u32 opencl_platforms_filter = 0; if (opencl_platforms) { - char *platforms = mystrdup (opencl_platforms); + char *platforms = hcstrdup (hashcat_ctx, opencl_platforms); char *next = strtok (platforms, ","); @@ -113,32 +113,34 @@ static u32 setup_opencl_platforms_filter (const char *opencl_platforms) if (platform < 1 || platform > 32) { - log_error ("ERROR: Invalid OpenCL platform %u specified", platform); + event_log_error (hashcat_ctx, "Invalid OpenCL platform %u specified", platform); - exit (-1); + return -1; } opencl_platforms_filter |= 1u << (platform - 1); } while ((next = strtok (NULL, ",")) != NULL); - myfree (platforms); + hcfree (platforms); } else { opencl_platforms_filter = -1u; } - return opencl_platforms_filter; + *out = opencl_platforms_filter; + + return 0; } -static u32 setup_devices_filter (const char *opencl_devices) +static int setup_devices_filter (hashcat_ctx_t *hashcat_ctx, const char *opencl_devices, u32 *out) { u32 devices_filter = 0; if (opencl_devices) { - char *devices = mystrdup (opencl_devices); + char *devices = hcstrdup (hashcat_ctx, opencl_devices); char *next = strtok (devices, ","); @@ -148,32 +150,34 @@ static u32 setup_devices_filter (const char *opencl_devices) if (device_id < 1 || device_id > 32) { - log_error ("ERROR: Invalid device_id %u specified", device_id); + event_log_error (hashcat_ctx, "Invalid device_id %u specified", device_id); - exit (-1); + return -1; } devices_filter |= 1u << (device_id - 1); } while ((next = strtok (NULL, ",")) != NULL); - myfree (devices); + hcfree (devices); } else { devices_filter = -1u; } - return devices_filter; + *out = devices_filter; + + return 0; } -static cl_device_type setup_device_types_filter (const char *opencl_device_types) +static int setup_device_types_filter (hashcat_ctx_t *hashcat_ctx, const char *opencl_device_types, cl_device_type *out) { cl_device_type device_types_filter = 0; if (opencl_device_types) { - char *device_types = mystrdup (opencl_device_types); + char *device_types = hcstrdup (hashcat_ctx, opencl_device_types); char *next = strtok (device_types, ","); @@ -183,16 +187,16 @@ static cl_device_type setup_device_types_filter (const char *opencl_device_types if (device_type < 1 || device_type > 3) { - log_error ("ERROR: Invalid device_type %u specified", device_type); + event_log_error (hashcat_ctx, "Invalid device_type %u specified", device_type); - exit (-1); + return -1; } device_types_filter |= 1u << device_type; } while ((next = strtok (NULL, ",")) != NULL); - myfree (device_types); + hcfree (device_types); } else { @@ -202,10 +206,12 @@ static cl_device_type setup_device_types_filter (const char *opencl_device_types device_types_filter = CL_DEVICE_TYPE_ALL & ~CL_DEVICE_TYPE_CPU; } - return device_types_filter; + *out = device_types_filter; + + return 0; } -static void read_kernel_binary (const char *kernel_file, int num_devices, size_t *kernel_lengths, char **kernel_sources) +static int read_kernel_binary (hashcat_ctx_t *hashcat_ctx, const char *kernel_file, int num_devices, size_t *kernel_lengths, char **kernel_sources) { FILE *fp = fopen (kernel_file, "rb"); @@ -217,15 +223,15 @@ static void read_kernel_binary (const char *kernel_file, int num_devices, size_t stat (kernel_file, &st); - char *buf = (char *) mymalloc (st.st_size + 1); + char *buf = (char *) hcmalloc (hashcat_ctx, st.st_size + 1); VERIFY_PTR (buf); size_t num_read = fread (buf, sizeof (char), st.st_size, fp); if (num_read != (size_t) st.st_size) { - log_error ("ERROR: %s: %s", kernel_file, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", kernel_file, strerror (errno)); - exit (-1); + return -1; } fclose (fp); @@ -241,40 +247,726 @@ static void read_kernel_binary (const char *kernel_file, int num_devices, size_t } else { - log_error ("ERROR: %s: %s", kernel_file, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", kernel_file, strerror (errno)); - exit (-1); + return -1; } - return; + return 0; } -static void write_kernel_binary (char *dst, char *binary, size_t binary_size) +static int write_kernel_binary (hashcat_ctx_t *hashcat_ctx, char *kernel_file, char *binary, size_t binary_size) { if (binary_size > 0) { - FILE *fp = fopen (dst, "wb"); + FILE *fp = fopen (kernel_file, "wb"); + + if (fp == NULL) + { + event_log_error (hashcat_ctx, "%s: %s", kernel_file, strerror (errno)); + + return -1; + } + + const int rc = lock_file (fp); + + if (rc == -1) return -1; - lock_file (fp); fwrite (binary, sizeof (char), binary_size, fp); - fflush (fp); fclose (fp); + + unlock_file (fp); } + + return 0; +} + +int ocl_init (hashcat_ctx_t *hashcat_ctx) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + memset (ocl, 0, sizeof (OCL_PTR)); + + #if defined(_WIN) + ocl->lib = hc_dlopen ("OpenCL"); + #elif defined(__APPLE__) + ocl->lib = hc_dlopen ("/System/Library/Frameworks/OpenCL.framework/OpenCL", RTLD_NOW); + #else + ocl->lib = hc_dlopen ("libOpenCL.so", RTLD_NOW); + + if (ocl->lib == NULL) ocl->lib = hc_dlopen ("libOpenCL.so.1", RTLD_NOW); + #endif + + if (ocl->lib == NULL) + { + event_log_error (hashcat_ctx, + "Can't find an OpenCL ICD loader library" EOL + "" EOL + #if defined (__linux__) + "You're probably missing the \"ocl-icd-libopencl1\" package (Debian/Ubuntu)" EOL + "Run: sudo apt-get install ocl-icd-libopencl1" EOL + "" EOL + #elif defined (_WIN) + "You're probably missing the OpenCL runtime installation" EOL + "* AMD users require AMD drivers 14.9 or later (recommended 15.12 exact)" EOL + "* Intel users require Intel OpenCL Runtime 14.2 or later (recommended 16.1 or later)" EOL + "* NVidia users require NVidia drivers 346.59 or later (recommended 367.27 or later)" EOL + "" EOL + #endif + ); + + return -1; + } + + HC_LOAD_FUNC(ocl, clBuildProgram, OCL_CLBUILDPROGRAM, OpenCL, 1) + HC_LOAD_FUNC(ocl, clCreateBuffer, OCL_CLCREATEBUFFER, OpenCL, 1) + HC_LOAD_FUNC(ocl, clCreateCommandQueue, OCL_CLCREATECOMMANDQUEUE, OpenCL, 1) + HC_LOAD_FUNC(ocl, clCreateContext, OCL_CLCREATECONTEXT, OpenCL, 1) + HC_LOAD_FUNC(ocl, clCreateKernel, OCL_CLCREATEKERNEL, OpenCL, 1) + HC_LOAD_FUNC(ocl, clCreateProgramWithBinary, OCL_CLCREATEPROGRAMWITHBINARY, OpenCL, 1) + HC_LOAD_FUNC(ocl, clCreateProgramWithSource, OCL_CLCREATEPROGRAMWITHSOURCE, OpenCL, 1) + HC_LOAD_FUNC(ocl, clEnqueueCopyBuffer, OCL_CLENQUEUECOPYBUFFER, OpenCL, 1) + HC_LOAD_FUNC(ocl, clEnqueueMapBuffer, OCL_CLENQUEUEMAPBUFFER, OpenCL, 1) + HC_LOAD_FUNC(ocl, clEnqueueNDRangeKernel, OCL_CLENQUEUENDRANGEKERNEL, OpenCL, 1) + HC_LOAD_FUNC(ocl, clEnqueueReadBuffer, OCL_CLENQUEUEREADBUFFER, OpenCL, 1) + HC_LOAD_FUNC(ocl, clEnqueueUnmapMemObject, OCL_CLENQUEUEUNMAPMEMOBJECT, OpenCL, 1) + HC_LOAD_FUNC(ocl, clEnqueueWriteBuffer, OCL_CLENQUEUEWRITEBUFFER, OpenCL, 1) + HC_LOAD_FUNC(ocl, clFinish, OCL_CLFINISH, OpenCL, 1) + HC_LOAD_FUNC(ocl, clFlush, OCL_CLFLUSH, OpenCL, 1) + HC_LOAD_FUNC(ocl, clGetDeviceIDs, OCL_CLGETDEVICEIDS, OpenCL, 1) + HC_LOAD_FUNC(ocl, clGetDeviceInfo, OCL_CLGETDEVICEINFO, OpenCL, 1) + HC_LOAD_FUNC(ocl, clGetEventInfo, OCL_CLGETEVENTINFO, OpenCL, 1) + HC_LOAD_FUNC(ocl, clGetKernelWorkGroupInfo, OCL_CLGETKERNELWORKGROUPINFO, OpenCL, 1) + HC_LOAD_FUNC(ocl, clGetPlatformIDs, OCL_CLGETPLATFORMIDS, OpenCL, 1) + HC_LOAD_FUNC(ocl, clGetPlatformInfo, OCL_CLGETPLATFORMINFO, OpenCL, 1) + HC_LOAD_FUNC(ocl, clGetProgramBuildInfo, OCL_CLGETPROGRAMBUILDINFO, OpenCL, 1) + HC_LOAD_FUNC(ocl, clGetProgramInfo, OCL_CLGETPROGRAMINFO, OpenCL, 1) + HC_LOAD_FUNC(ocl, clReleaseCommandQueue, OCL_CLRELEASECOMMANDQUEUE, OpenCL, 1) + HC_LOAD_FUNC(ocl, clReleaseContext, OCL_CLRELEASECONTEXT, OpenCL, 1) + HC_LOAD_FUNC(ocl, clReleaseKernel, OCL_CLRELEASEKERNEL, OpenCL, 1) + HC_LOAD_FUNC(ocl, clReleaseMemObject, OCL_CLRELEASEMEMOBJECT, OpenCL, 1) + HC_LOAD_FUNC(ocl, clReleaseProgram, OCL_CLRELEASEPROGRAM, OpenCL, 1) + HC_LOAD_FUNC(ocl, clSetKernelArg, OCL_CLSETKERNELARG, OpenCL, 1) + HC_LOAD_FUNC(ocl, clWaitForEvents, OCL_CLWAITFOREVENTS, OpenCL, 1) + HC_LOAD_FUNC(ocl, clGetEventProfilingInfo, OCL_CLGETEVENTPROFILINGINFO, OpenCL, 1) + HC_LOAD_FUNC(ocl, clReleaseEvent, OCL_CLRELEASEEVENT, OpenCL, 1) + + return 0; +} + +void ocl_close (hashcat_ctx_t *hashcat_ctx) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + if (ocl) + { + if (ocl->lib) + { + hc_dlclose (ocl->lib); + } + } +} + +int hc_clEnqueueNDRangeKernel (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_kernel kernel, cl_uint work_dim, const size_t *global_work_offset, const size_t *global_work_size, const size_t *local_work_size, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clEnqueueNDRangeKernel (command_queue, kernel, work_dim, global_work_offset, global_work_size, local_work_size, num_events_in_wait_list, event_wait_list, event); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clEnqueueNDRangeKernel(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clGetEventInfo (hashcat_ctx_t *hashcat_ctx, cl_event event, cl_event_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clGetEventInfo (event, param_name, param_value_size, param_value, param_value_size_ret); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clGetEventInfo(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clFlush (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clFlush (command_queue); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clFlush(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clFinish (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clFinish (command_queue); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clFinish(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clSetKernelArg (hashcat_ctx_t *hashcat_ctx, cl_kernel kernel, cl_uint arg_index, size_t arg_size, const void *arg_value) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clSetKernelArg (kernel, arg_index, arg_size, arg_value); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clSetKernelArg(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clEnqueueWriteBuffer (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_write, size_t offset, size_t cb, const void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clEnqueueWriteBuffer (command_queue, buffer, blocking_write, offset, cb, ptr, num_events_in_wait_list, event_wait_list, event); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clEnqueueWriteBuffer(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clEnqueueCopyBuffer (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_mem src_buffer, cl_mem dst_buffer, size_t src_offset, size_t dst_offset, size_t cb, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clEnqueueCopyBuffer (command_queue, src_buffer, dst_buffer, src_offset, dst_offset, cb, num_events_in_wait_list, event_wait_list, event); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clEnqueueCopyBuffer(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clEnqueueReadBuffer (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, size_t offset, size_t cb, void *ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clEnqueueReadBuffer (command_queue, buffer, blocking_read, offset, cb, ptr, num_events_in_wait_list, event_wait_list, event); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clEnqueueReadBuffer(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clGetPlatformIDs (hashcat_ctx_t *hashcat_ctx, cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clGetPlatformIDs (num_entries, platforms, num_platforms); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clGetPlatformIDs(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clGetPlatformInfo (hashcat_ctx_t *hashcat_ctx, cl_platform_id platform, cl_platform_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clGetPlatformInfo (platform, param_name, param_value_size, param_value, param_value_size_ret); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clGetPlatformInfo(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clGetDeviceIDs (hashcat_ctx_t *hashcat_ctx, cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, cl_device_id *devices, cl_uint *num_devices) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clGetDeviceIDs (platform, device_type, num_entries, devices, num_devices); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clGetDeviceIDs(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clGetDeviceInfo (hashcat_ctx_t *hashcat_ctx, cl_device_id device, cl_device_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clGetDeviceInfo (device, param_name, param_value_size, param_value, param_value_size_ret); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clGetDeviceInfo(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clCreateContext (hashcat_ctx_t *hashcat_ctx, cl_context_properties *properties, cl_uint num_devices, const cl_device_id *devices, void (CL_CALLBACK *pfn_notify) (const char *, const void *, size_t, void *), void *user_data, cl_context *context) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + cl_int CL_err; + + *context = ocl->clCreateContext (properties, num_devices, devices, pfn_notify, user_data, &CL_err); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clCreateContext(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clCreateCommandQueue (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_device_id device, cl_command_queue_properties properties, cl_command_queue *command_queue) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + cl_int CL_err; + + *command_queue = ocl->clCreateCommandQueue (context, device, properties, &CL_err); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clCreateCommandQueue(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clCreateBuffer (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_mem_flags flags, size_t size, void *host_ptr, cl_mem *mem) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + cl_int CL_err; + + *mem = ocl->clCreateBuffer (context, flags, size, host_ptr, &CL_err); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clCreateBuffer(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clCreateProgramWithSource (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_uint count, const char **strings, const size_t *lengths, cl_program *program) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + cl_int CL_err; + + *program = ocl->clCreateProgramWithSource (context, count, strings, lengths, &CL_err); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clCreateProgramWithSource(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clCreateProgramWithBinary (hashcat_ctx_t *hashcat_ctx, cl_context context, cl_uint num_devices, const cl_device_id *device_list, const size_t *lengths, const unsigned char **binaries, cl_int *binary_status, cl_program *program) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + cl_int CL_err; + + *program = ocl->clCreateProgramWithBinary (context, num_devices, device_list, lengths, binaries, binary_status, &CL_err); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clCreateProgramWithBinary(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clBuildProgram (hashcat_ctx_t *hashcat_ctx, cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, void (CL_CALLBACK *pfn_notify) (cl_program program, void *user_data), void *user_data) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clBuildProgram (program, num_devices, device_list, options, pfn_notify, user_data); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clBuildProgram(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clCreateKernel (hashcat_ctx_t *hashcat_ctx, cl_program program, const char *kernel_name, cl_kernel *kernel) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + cl_int CL_err; + + *kernel = ocl->clCreateKernel (program, kernel_name, &CL_err); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clCreateKernel(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clReleaseMemObject (hashcat_ctx_t *hashcat_ctx, cl_mem mem) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clReleaseMemObject (mem); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clReleaseMemObject(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clReleaseKernel (hashcat_ctx_t *hashcat_ctx, cl_kernel kernel) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clReleaseKernel (kernel); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clReleaseKernel(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clReleaseProgram (hashcat_ctx_t *hashcat_ctx, cl_program program) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clReleaseProgram (program); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clReleaseProgram(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clReleaseCommandQueue (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clReleaseCommandQueue (command_queue); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clReleaseCommandQueue(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clReleaseContext (hashcat_ctx_t *hashcat_ctx, cl_context context) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clReleaseContext (context); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clReleaseContext(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clEnqueueMapBuffer (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_mem buffer, cl_bool blocking_read, cl_map_flags map_flags, size_t offset, size_t cb, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event, void **buf) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + cl_int CL_err; + + *buf = ocl->clEnqueueMapBuffer (command_queue, buffer, blocking_read, map_flags, offset, cb, num_events_in_wait_list, event_wait_list, event, &CL_err); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clEnqueueMapBuffer(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clEnqueueUnmapMemObject (hashcat_ctx_t *hashcat_ctx, cl_command_queue command_queue, cl_mem memobj, void *mapped_ptr, cl_uint num_events_in_wait_list, const cl_event *event_wait_list, cl_event *event) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clEnqueueUnmapMemObject (command_queue, memobj, mapped_ptr, num_events_in_wait_list, event_wait_list, event); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clEnqueueUnmapMemObject(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clGetKernelWorkGroupInfo (hashcat_ctx_t *hashcat_ctx, cl_kernel kernel, cl_device_id device, cl_kernel_work_group_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clGetKernelWorkGroupInfo (kernel, device, param_name, param_value_size, param_value, param_value_size_ret); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clGetKernelWorkGroupInfo(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clGetProgramBuildInfo (hashcat_ctx_t *hashcat_ctx, cl_program program, cl_device_id device, cl_program_build_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clGetProgramBuildInfo (program, device, param_name, param_value_size, param_value, param_value_size_ret); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clGetProgramBuildInfo(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clGetProgramInfo (hashcat_ctx_t *hashcat_ctx, cl_program program, cl_program_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clGetProgramInfo (program, param_name, param_value_size, param_value, param_value_size_ret); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clGetProgramInfo(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clWaitForEvents (hashcat_ctx_t *hashcat_ctx, cl_uint num_events, const cl_event *event_list) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clWaitForEvents (num_events, event_list); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clWaitForEvents(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clGetEventProfilingInfo (hashcat_ctx_t *hashcat_ctx, cl_event event, cl_profiling_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clGetEventProfilingInfo (event, param_name, param_value_size, param_value, param_value_size_ret); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clGetEventProfilingInfo(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; +} + +int hc_clReleaseEvent (hashcat_ctx_t *hashcat_ctx, cl_event event) +{ + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clReleaseEvent (event); + + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "clReleaseEvent(): %s", val2cstr_cl (CL_err)); + + return -1; + } + + return 0; } int gidd_to_pw_t (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u64 gidd, pw_t *pw) { - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + int CL_rc = hc_clEnqueueReadBuffer (hashcat_ctx, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, gidd * sizeof (pw_t), sizeof (pw_t), pw, 0, NULL, NULL); - cl_int CL_err = hc_clEnqueueReadBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, gidd * sizeof (pw_t), sizeof (pw_t), pw, 0, NULL, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueReadBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; return 0; } @@ -283,19 +975,16 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, { hashconfig_t *hashconfig = hashcat_ctx->hashconfig; hashes_t *hashes = hashcat_ctx->hashes; - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; status_ctx_t *status_ctx = hashcat_ctx->status_ctx; user_options_t *user_options = hashcat_ctx->user_options; - cl_int CL_err = CL_SUCCESS; - if (hashconfig->hash_mode == 2000) { - process_stdout (hashcat_ctx, device_param, pws_cnt); - - return 0; + return process_stdout (hashcat_ctx, device_param, pws_cnt); } + int CL_rc; + if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL) { if (user_options->attack_mode == ATTACK_MODE_BF) @@ -304,63 +993,64 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, { const u32 size_tm = 32 * sizeof (bs_word_t); - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_tm_c, size_tm); + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_tm_c, size_tm); - run_kernel_tm (hashcat_ctx, device_param); + if (CL_rc == -1) return -1; - CL_err = hc_clEnqueueCopyBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_tm_c, device_param->d_bfs_c, 0, 0, size_tm, 0, NULL, NULL); + CL_rc = run_kernel_tm (hashcat_ctx, device_param); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueCopyBuffer(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + CL_rc = hc_clEnqueueCopyBuffer (hashcat_ctx, device_param->command_queue, device_param->d_tm_c, device_param->d_bfs_c, 0, 0, size_tm, 0, NULL, NULL); + + if (CL_rc == -1) return -1; } } if (highest_pw_len < 16) { - run_kernel (hashcat_ctx, device_param, KERN_RUN_1, pws_cnt, true, fast_iteration); + CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_1, pws_cnt, true, fast_iteration); + + if (CL_rc == -1) return -1; } else if (highest_pw_len < 32) { - run_kernel (hashcat_ctx, device_param, KERN_RUN_2, pws_cnt, true, fast_iteration); + CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_2, pws_cnt, true, fast_iteration); + + if (CL_rc == -1) return -1; } else { - run_kernel (hashcat_ctx, device_param, KERN_RUN_3,pws_cnt, true, fast_iteration); + CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_3,pws_cnt, true, fast_iteration); + + if (CL_rc == -1) return -1; } } else { - run_kernel_amp (hashcat_ctx, device_param, pws_cnt); + CL_rc = run_kernel_amp (hashcat_ctx, device_param, pws_cnt); - run_kernel (hashcat_ctx, device_param, KERN_RUN_1, pws_cnt, false, 0); + if (CL_rc == -1) return -1; + + CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_1, pws_cnt, false, 0); + + if (CL_rc == -1) return -1; if (hashconfig->opts_type & OPTS_TYPE_HOOK12) { - run_kernel (hashcat_ctx, device_param, KERN_RUN_12, pws_cnt, false, 0); + CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_12, pws_cnt, false, 0); - CL_err = hc_clEnqueueReadBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL); + if (CL_rc == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueReadBuffer(): %s\n", val2cstr_cl (CL_err)); + CL_rc = hc_clEnqueueReadBuffer (hashcat_ctx, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL); - return -1; - } + if (CL_rc == -1) return -1; // do something with data - CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL); + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } u32 iter = hashes->salts_buf[salt_pos].salt_iter; @@ -376,7 +1066,9 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, device_param->kernel_params_buf32[28] = loop_pos; device_param->kernel_params_buf32[29] = loop_left; - run_kernel (hashcat_ctx, device_param, KERN_RUN_2, pws_cnt, true, slow_iteration); + CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_2, pws_cnt, true, slow_iteration); + + if (CL_rc == -1) return -1; while (status_ctx->run_thread_level2 == false) break; @@ -388,46 +1080,40 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u64 perf_sum_all = (u64) (pws_cnt * iter_part); - double speed_ms = hc_timer_get (device_param->timer_speed); + double speed_msec = hc_timer_get (device_param->timer_speed); const u32 speed_pos = device_param->speed_pos; device_param->speed_cnt[speed_pos] = perf_sum_all; - device_param->speed_ms[speed_pos] = speed_ms; + device_param->speed_msec[speed_pos] = speed_msec; - if (user_options->benchmark == true) + if (user_options->speed_only == true) { - if (speed_ms > 4096) return -1; + if (speed_msec > 4096) return 0; } } if (hashconfig->opts_type & OPTS_TYPE_HOOK23) { - run_kernel (hashcat_ctx, device_param, KERN_RUN_23, pws_cnt, false, 0); + CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_23, pws_cnt, false, 0); - CL_err = hc_clEnqueueReadBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL); + if (CL_rc == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueReadBuffer(): %s\n", val2cstr_cl (CL_err)); + CL_rc = hc_clEnqueueReadBuffer (hashcat_ctx, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL); - return -1; - } + if (CL_rc == -1) return -1; // do something with data - CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL); + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_hooks, CL_TRUE, 0, device_param->size_hooks, device_param->hooks_buf, 0, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } - run_kernel (hashcat_ctx, device_param, KERN_RUN_3, pws_cnt, false, 0); + CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_3, pws_cnt, false, 0); + + if (CL_rc == -1) return -1; } return 0; @@ -436,12 +1122,9 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, int run_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 kern_run, const u32 num, const u32 event_update, const u32 iteration) { hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; status_ctx_t *status_ctx = hashcat_ctx->status_ctx; user_options_t *user_options = hashcat_ctx->user_options; - cl_int CL_err = CL_SUCCESS; - u32 num_elements = num; device_param->kernel_params_buf32[34] = num; @@ -461,24 +1144,19 @@ int run_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, con case KERN_RUN_3: kernel = device_param->kernel3; break; } - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 24, sizeof (cl_uint), device_param->kernel_params[24]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 25, sizeof (cl_uint), device_param->kernel_params[25]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 26, sizeof (cl_uint), device_param->kernel_params[26]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 27, sizeof (cl_uint), device_param->kernel_params[27]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 28, sizeof (cl_uint), device_param->kernel_params[28]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 29, sizeof (cl_uint), device_param->kernel_params[29]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 30, sizeof (cl_uint), device_param->kernel_params[30]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 31, sizeof (cl_uint), device_param->kernel_params[31]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 32, sizeof (cl_uint), device_param->kernel_params[32]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 33, sizeof (cl_uint), device_param->kernel_params[33]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 34, sizeof (cl_uint), device_param->kernel_params[34]); + int CL_rc; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 24, sizeof (cl_uint), device_param->kernel_params[24]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 25, sizeof (cl_uint), device_param->kernel_params[25]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 26, sizeof (cl_uint), device_param->kernel_params[26]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 27, sizeof (cl_uint), device_param->kernel_params[27]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 28, sizeof (cl_uint), device_param->kernel_params[28]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 29, sizeof (cl_uint), device_param->kernel_params[29]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 30, sizeof (cl_uint), device_param->kernel_params[30]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 31, sizeof (cl_uint), device_param->kernel_params[31]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 32, sizeof (cl_uint), device_param->kernel_params[32]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 34, sizeof (cl_uint), device_param->kernel_params[34]); if (CL_rc == -1) return -1; cl_event event; @@ -487,14 +1165,9 @@ int run_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, con const size_t global_work_size[3] = { num_elements, 32, 1 }; const size_t local_work_size[3] = { kernel_threads / 32, 32, 1 }; - CL_err = hc_clEnqueueNDRangeKernel (opencl_ctx->ocl, device_param->command_queue, kernel, 2, NULL, global_work_size, local_work_size, 0, NULL, &event); + CL_rc = hc_clEnqueueNDRangeKernel (hashcat_ctx, device_param->command_queue, kernel, 2, NULL, global_work_size, local_work_size, 0, NULL, &event); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueNDRangeKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } else { @@ -511,24 +1184,14 @@ int run_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, con const size_t global_work_size[3] = { num_elements, 1, 1 }; const size_t local_work_size[3] = { kernel_threads, 1, 1 }; - CL_err = hc_clEnqueueNDRangeKernel (opencl_ctx->ocl, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, &event); + CL_rc = hc_clEnqueueNDRangeKernel (hashcat_ctx, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, &event); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueNDRangeKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } - CL_err = hc_clFlush (opencl_ctx->ocl, device_param->command_queue); + CL_rc = hc_clFlush (hashcat_ctx, device_param->command_queue); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clFlush(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; if (device_param->nvidia_spin_damp > 0) { @@ -546,27 +1209,15 @@ int run_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, con } } - CL_err = hc_clWaitForEvents (opencl_ctx->ocl, 1, &event); + CL_rc = hc_clWaitForEvents (hashcat_ctx, 1, &event); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clWaitForEvents(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; cl_ulong time_start; cl_ulong time_end; - CL_err |= hc_clGetEventProfilingInfo (opencl_ctx->ocl, event, CL_PROFILING_COMMAND_START, sizeof (time_start), &time_start, NULL); - CL_err |= hc_clGetEventProfilingInfo (opencl_ctx->ocl, event, CL_PROFILING_COMMAND_END, sizeof (time_end), &time_end, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetEventProfilingInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_rc = hc_clGetEventProfilingInfo (hashcat_ctx, event, CL_PROFILING_COMMAND_START, sizeof (time_start), &time_start, NULL); if (CL_rc == -1) return -1; + CL_rc = hc_clGetEventProfilingInfo (hashcat_ctx, event, CL_PROFILING_COMMAND_END, sizeof (time_end), &time_end, NULL); if (CL_rc == -1) return -1; const double exec_us = (double) (time_end - time_start) / 1000; @@ -587,7 +1238,7 @@ int run_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, con { u32 exec_pos = device_param->exec_pos; - device_param->exec_ms[exec_pos] = exec_us / 1000; + device_param->exec_msec[exec_pos] = exec_us / 1000; exec_pos++; @@ -599,32 +1250,20 @@ int run_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, con device_param->exec_pos = exec_pos; } - CL_err = hc_clReleaseEvent (opencl_ctx->ocl, event); + CL_rc = hc_clReleaseEvent (hashcat_ctx, event); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clReleaseEvent(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + CL_rc = hc_clFinish (hashcat_ctx, device_param->command_queue); - CL_err = hc_clFinish (opencl_ctx->ocl, device_param->command_queue); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clFinish(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; return 0; } int run_kernel_mp (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 kern_run, const u32 num) { - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - - cl_int CL_err = CL_SUCCESS; + int CL_rc = CL_SUCCESS; u32 num_elements = num; @@ -653,75 +1292,51 @@ int run_kernel_mp (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, switch (kern_run) { - case KERN_RUN_MP: CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp[3]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp[4]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp[5]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp[6]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp[7]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 8, sizeof (cl_uint), device_param->kernel_params_mp[8]); + case KERN_RUN_MP: CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp[3]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp[4]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp[5]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp[6]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp[7]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 8, sizeof (cl_uint), device_param->kernel_params_mp[8]); if (CL_rc == -1) return -1; break; - case KERN_RUN_MP_R: CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp_r[3]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp_r[4]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp_r[5]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp_r[6]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp_r[7]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 8, sizeof (cl_uint), device_param->kernel_params_mp_r[8]); + case KERN_RUN_MP_R: CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp_r[3]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp_r[4]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp_r[5]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp_r[6]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp_r[7]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 8, sizeof (cl_uint), device_param->kernel_params_mp_r[8]); if (CL_rc == -1) return -1; break; - case KERN_RUN_MP_L: CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp_l[3]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp_l[4]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp_l[5]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp_l[6]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp_l[7]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 8, sizeof (cl_uint), device_param->kernel_params_mp_l[8]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 9, sizeof (cl_uint), device_param->kernel_params_mp_l[9]); + case KERN_RUN_MP_L: CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp_l[3]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp_l[4]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp_l[5]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp_l[6]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp_l[7]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 8, sizeof (cl_uint), device_param->kernel_params_mp_l[8]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 9, sizeof (cl_uint), device_param->kernel_params_mp_l[9]); if (CL_rc == -1) return -1; break; } - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - const size_t global_work_size[3] = { num_elements, 1, 1 }; const size_t local_work_size[3] = { kernel_threads, 1, 1 }; - CL_err = hc_clEnqueueNDRangeKernel (opencl_ctx->ocl, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); + CL_rc = hc_clEnqueueNDRangeKernel (hashcat_ctx, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueNDRangeKernel(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + CL_rc = hc_clFlush (hashcat_ctx, device_param->command_queue); - CL_err = hc_clFlush (opencl_ctx->ocl, device_param->command_queue); + if (CL_rc == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clFlush(): %s\n", val2cstr_cl (CL_err)); + CL_rc = hc_clFinish (hashcat_ctx, device_param->command_queue); - return -1; - } - - CL_err = hc_clFinish (opencl_ctx->ocl, device_param->command_queue); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clFinish(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; return 0; } int run_kernel_tm (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) { - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - - cl_int CL_err = CL_SUCCESS; + int CL_rc = CL_SUCCESS; const u32 num_elements = 1024; // fixed @@ -732,41 +1347,24 @@ int run_kernel_tm (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) const size_t global_work_size[3] = { num_elements, 1, 1 }; const size_t local_work_size[3] = { kernel_threads, 1, 1 }; - CL_err = hc_clEnqueueNDRangeKernel (opencl_ctx->ocl, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); + CL_rc = hc_clEnqueueNDRangeKernel (hashcat_ctx, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueNDRangeKernel(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + CL_rc = hc_clFlush (hashcat_ctx, device_param->command_queue); - CL_err = hc_clFlush (opencl_ctx->ocl, device_param->command_queue); + if (CL_rc == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clFlush(): %s\n", val2cstr_cl (CL_err)); + CL_rc = hc_clFinish (hashcat_ctx, device_param->command_queue); - return -1; - } - - CL_err = hc_clFinish (opencl_ctx->ocl, device_param->command_queue); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clFinish(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; return 0; } int run_kernel_amp (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 num) { - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - - cl_int CL_err = CL_SUCCESS; + int CL_rc = CL_SUCCESS; u32 num_elements = num; @@ -781,53 +1379,31 @@ int run_kernel_amp (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, cl_kernel kernel = device_param->kernel_amp; - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 6, sizeof (cl_uint), device_param->kernel_params_amp[6]); + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 6, sizeof (cl_uint), device_param->kernel_params_amp[6]); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; const size_t global_work_size[3] = { num_elements, 1, 1 }; const size_t local_work_size[3] = { kernel_threads, 1, 1 }; - CL_err = hc_clEnqueueNDRangeKernel (opencl_ctx->ocl, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); + CL_rc = hc_clEnqueueNDRangeKernel (hashcat_ctx, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueNDRangeKernel(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + CL_rc = hc_clFlush (hashcat_ctx, device_param->command_queue); - CL_err = hc_clFlush (opencl_ctx->ocl, device_param->command_queue); + if (CL_rc == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clFlush(): %s\n", val2cstr_cl (CL_err)); + CL_rc = hc_clFinish (hashcat_ctx, device_param->command_queue); - return -1; - } - - CL_err = hc_clFinish (opencl_ctx->ocl, device_param->command_queue); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clFinish(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; return 0; } int run_kernel_memset (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, cl_mem buf, const u32 value, const u32 num) { - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - - cl_int CL_err = CL_SUCCESS; + int CL_rc = CL_SUCCESS; const u32 num16d = num / 16; const u32 num16m = num % 16; @@ -845,46 +1421,24 @@ int run_kernel_memset (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_par cl_kernel kernel = device_param->kernel_memset; - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 0, sizeof (cl_mem), (void *) &buf); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 1, sizeof (cl_uint), device_param->kernel_params_memset[1]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, kernel, 2, sizeof (cl_uint), device_param->kernel_params_memset[2]); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 0, sizeof (cl_mem), (void *) &buf); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 1, sizeof (cl_uint), device_param->kernel_params_memset[1]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, kernel, 2, sizeof (cl_uint), device_param->kernel_params_memset[2]); if (CL_rc == -1) return -1; const size_t global_work_size[3] = { num_elements, 1, 1 }; const size_t local_work_size[3] = { kernel_threads, 1, 1 }; - CL_err = hc_clEnqueueNDRangeKernel (opencl_ctx->ocl, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); + CL_rc = hc_clEnqueueNDRangeKernel (hashcat_ctx, device_param->command_queue, kernel, 1, NULL, global_work_size, local_work_size, 0, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueNDRangeKernel(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + CL_rc = hc_clFlush (hashcat_ctx, device_param->command_queue); - CL_err = hc_clFlush (opencl_ctx->ocl, device_param->command_queue); + if (CL_rc == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clFlush(): %s\n", val2cstr_cl (CL_err)); + CL_rc = hc_clFinish (hashcat_ctx, device_param->command_queue); - return -1; - } - - CL_err = hc_clFinish (opencl_ctx->ocl, device_param->command_queue); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clFinish(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } if (num16m) @@ -896,14 +1450,9 @@ int run_kernel_memset (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_par tmp[2] = value; tmp[3] = value; - CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, buf, CL_TRUE, num16d * 16, num16m, tmp, 0, NULL, NULL); + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, buf, CL_TRUE, num16d * 16, num16m, tmp, 0, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } return 0; @@ -918,22 +1467,16 @@ int run_copy (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const { combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; user_options_t *user_options = hashcat_ctx->user_options; user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; - cl_int CL_err = CL_SUCCESS; + int CL_rc = CL_SUCCESS; if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) { - CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, pws_cnt * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, pws_cnt * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) { @@ -991,14 +1534,9 @@ int run_copy (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const } } - CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, pws_cnt * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_pws_buf, CL_TRUE, 0, pws_cnt * sizeof (pw_t), device_param->pws_buf, 0, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } else if (user_options_extra->attack_kern == ATTACK_KERN_BF) { @@ -1006,7 +1544,9 @@ int run_copy (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const device_param->kernel_params_mp_l_buf64[3] = off; - run_kernel_mp (hashcat_ctx, device_param, KERN_RUN_MP_L, pws_cnt); + CL_rc = run_kernel_mp (hashcat_ctx, device_param, KERN_RUN_MP_L, pws_cnt); + + if (CL_rc == -1) return -1; } return 0; @@ -1018,7 +1558,6 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co hashconfig_t *hashconfig = hashcat_ctx->hashconfig; hashes_t *hashes = hashcat_ctx->hashes; mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; status_ctx_t *status_ctx = hashcat_ctx->status_ctx; straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; user_options_t *user_options = hashcat_ctx->user_options; @@ -1222,7 +1761,9 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co device_param->kernel_params_mp_r_buf64[3] = off; - run_kernel_mp (hashcat_ctx, device_param, KERN_RUN_MP_R, innerloop_left); + int CL_rc = run_kernel_mp (hashcat_ctx, device_param, KERN_RUN_MP_R, innerloop_left); + + if (CL_rc == -1) return -1; } else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) { @@ -1230,7 +1771,9 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co device_param->kernel_params_mp_buf64[3] = off; - run_kernel_mp (hashcat_ctx, device_param, KERN_RUN_MP, innerloop_left); + int CL_rc = run_kernel_mp (hashcat_ctx, device_param, KERN_RUN_MP, innerloop_left); + + if (CL_rc == -1) return -1; } else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) { @@ -1238,68 +1781,45 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co device_param->kernel_params_mp_buf64[3] = off; - run_kernel_mp (hashcat_ctx, device_param, KERN_RUN_MP, innerloop_left); + int CL_rc = run_kernel_mp (hashcat_ctx, device_param, KERN_RUN_MP, innerloop_left); + + if (CL_rc == -1) return -1; } // copy amplifiers if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) { - cl_int CL_err = hc_clEnqueueCopyBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_rules, device_param->d_rules_c, innerloop_pos * sizeof (kernel_rule_t), 0, innerloop_left * sizeof (kernel_rule_t), 0, NULL, NULL); + int CL_rc = hc_clEnqueueCopyBuffer (hashcat_ctx, device_param->command_queue, device_param->d_rules, device_param->d_rules_c, innerloop_pos * sizeof (kernel_rule_t), 0, innerloop_left * sizeof (kernel_rule_t), 0, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueCopyBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } else if (user_options->attack_mode == ATTACK_MODE_COMBI) { - cl_int CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_combs_c, CL_TRUE, 0, innerloop_left * sizeof (comb_t), device_param->combs_buf, 0, NULL, NULL); + int CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_combs_c, CL_TRUE, 0, innerloop_left * sizeof (comb_t), device_param->combs_buf, 0, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } else if (user_options->attack_mode == ATTACK_MODE_BF) { - cl_int CL_err = hc_clEnqueueCopyBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bfs, device_param->d_bfs_c, 0, 0, innerloop_left * sizeof (bf_t), 0, NULL, NULL); + int CL_rc = hc_clEnqueueCopyBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bfs, device_param->d_bfs_c, 0, 0, innerloop_left * sizeof (bf_t), 0, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueCopyBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) { - cl_int CL_err = hc_clEnqueueCopyBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_combs, device_param->d_combs_c, 0, 0, innerloop_left * sizeof (comb_t), 0, NULL, NULL); + int CL_rc = hc_clEnqueueCopyBuffer (hashcat_ctx, device_param->command_queue, device_param->d_combs, device_param->d_combs_c, 0, 0, innerloop_left * sizeof (comb_t), 0, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueCopyBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) { - cl_int CL_err = hc_clEnqueueCopyBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_combs, device_param->d_combs_c, 0, 0, innerloop_left * sizeof (comb_t), 0, NULL, NULL); + int CL_rc = hc_clEnqueueCopyBuffer (hashcat_ctx, device_param->command_queue, device_param->d_combs, device_param->d_combs_c, 0, 0, innerloop_left * sizeof (comb_t), 0, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueCopyBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } - if (user_options->benchmark == true) + if (user_options->speed_only == true) { hc_timer_set (&device_param->timer_speed); } @@ -1312,7 +1832,7 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co * result */ - if (user_options->benchmark == false) + if (user_options->speed_only == false) { check_cracked (hashcat_ctx, device_param, salt_pos); } @@ -1333,7 +1853,7 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co * speed */ - double speed_ms = hc_timer_get (device_param->timer_speed); + double speed_msec = hc_timer_get (device_param->timer_speed); hc_timer_set (&device_param->timer_speed); @@ -1343,7 +1863,7 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co device_param->speed_cnt[speed_pos] = perf_sum_all; - device_param->speed_ms[speed_pos] = speed_ms; + device_param->speed_msec[speed_pos] = speed_msec; //hc_thread_mutex_unlock (status_ctx->mux_display); @@ -1358,19 +1878,21 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co * benchmark */ - if (user_options->benchmark == true) break; + if (user_options->speed_only == true) break; if (status_ctx->run_thread_level2 == false) break; } - device_param->innerloop_pos = 0; - device_param->innerloop_left = 0; + //status screen makes use of this, can't reset here + //device_param->innerloop_pos = 0; + //device_param->innerloop_left = 0; if (status_ctx->run_thread_level2 == false) break; } - device_param->outerloop_pos = 0; - device_param->outerloop_left = 0; + //status screen makes use of this, can't reset here + //device_param->outerloop_pos = 0; + //device_param->outerloop_left = 0; device_param->speed_pos = speed_pos; @@ -1390,24 +1912,31 @@ int opencl_ctx_init (hashcat_ctx_t *hashcat_ctx) if (user_options->usage == true) return 0; if (user_options->version == true) return 0; - opencl_ctx->ocl = (OCL_PTR *) mymalloc (sizeof (OCL_PTR)); - - hc_device_param_t *devices_param = (hc_device_param_t *) mycalloc (DEVICES_MAX, sizeof (hc_device_param_t)); + hc_device_param_t *devices_param = (hc_device_param_t *) hccalloc (hashcat_ctx, DEVICES_MAX, sizeof (hc_device_param_t)); VERIFY_PTR (devices_param); opencl_ctx->devices_param = devices_param; /** * Load and map OpenCL library calls - * TODO: remove exit() calls in there */ - ocl_init (opencl_ctx->ocl); + OCL_PTR *ocl = (OCL_PTR *) hcmalloc (hashcat_ctx, sizeof (OCL_PTR)); VERIFY_PTR (ocl); + + opencl_ctx->ocl = ocl; + + const int rc_ocl_init = ocl_init (hashcat_ctx); + + if (rc_ocl_init == -1) return -1; /** * OpenCL platform selection */ - u32 opencl_platforms_filter = setup_opencl_platforms_filter (user_options->opencl_platforms); + u32 opencl_platforms_filter; + + const int rc_platforms_filter = setup_opencl_platforms_filter (hashcat_ctx, user_options->opencl_platforms, &opencl_platforms_filter); + + if (rc_platforms_filter == -1) return -1; opencl_ctx->opencl_platforms_filter = opencl_platforms_filter; @@ -1415,7 +1944,11 @@ int opencl_ctx_init (hashcat_ctx_t *hashcat_ctx) * OpenCL device selection */ - u32 devices_filter = setup_devices_filter (user_options->opencl_devices); + u32 devices_filter; + + const int rc_devices_filter = setup_devices_filter (hashcat_ctx, user_options->opencl_devices, &devices_filter); + + if (rc_devices_filter == -1) return -1; opencl_ctx->devices_filter = devices_filter; @@ -1423,7 +1956,11 @@ int opencl_ctx_init (hashcat_ctx_t *hashcat_ctx) * OpenCL device type selection */ - cl_device_type device_types_filter = setup_device_types_filter (user_options->opencl_device_types); + cl_device_type device_types_filter; + + const int rc_device_types_filter = setup_device_types_filter (hashcat_ctx, user_options->opencl_device_types, &device_types_filter); + + if (rc_device_types_filter == -1) return -1; opencl_ctx->device_types_filter = device_types_filter; @@ -1432,28 +1969,23 @@ int opencl_ctx_init (hashcat_ctx_t *hashcat_ctx) */ cl_uint platforms_cnt = 0; - cl_platform_id *platforms = (cl_platform_id *) mycalloc (CL_PLATFORMS_MAX, sizeof (cl_platform_id)); + cl_platform_id *platforms = (cl_platform_id *) hccalloc (hashcat_ctx, CL_PLATFORMS_MAX, sizeof (cl_platform_id)); VERIFY_PTR (platforms); cl_uint platform_devices_cnt = 0; - cl_device_id *platform_devices = (cl_device_id *) mycalloc (DEVICES_MAX, sizeof (cl_device_id)); + cl_device_id *platform_devices = (cl_device_id *) hccalloc (hashcat_ctx, DEVICES_MAX, sizeof (cl_device_id)); VERIFY_PTR (platform_devices); - cl_int CL_err = hc_clGetPlatformIDs (opencl_ctx->ocl, CL_PLATFORMS_MAX, platforms, &platforms_cnt); + int CL_rc = hc_clGetPlatformIDs (hashcat_ctx, CL_PLATFORMS_MAX, platforms, &platforms_cnt); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetPlatformIDs(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; if (platforms_cnt == 0) { - log_info ("ATTENTION! No OpenCL compatible platform found"); - log_info (""); - log_info ("You're probably missing the OpenCL runtime installation"); - log_info (" AMD users require AMD drivers 14.9 or later (recommended 15.12 or later)"); - log_info (" Intel users require Intel OpenCL Runtime 14.2 or later (recommended 15.1 or later)"); - log_info (" NVidia users require NVidia drivers 346.59 or later (recommended 361.x or later)"); - log_info (""); + event_log_error (hashcat_ctx, "ATTENTION! No OpenCL compatible platform found"); + event_log_error (hashcat_ctx, ""); + event_log_error (hashcat_ctx, "You're probably missing the OpenCL runtime installation"); + event_log_error (hashcat_ctx, "* AMD users require AMD drivers 14.9 or later (recommended 15.12 or later)"); + event_log_error (hashcat_ctx, "* Intel users require Intel OpenCL Runtime 14.2 or later (recommended 15.1 or later)"); + event_log_error (hashcat_ctx, "* NVidia users require NVidia drivers 346.59 or later (recommended 361.x or later)"); + event_log_error (hashcat_ctx, ""); return -1; } @@ -1464,7 +1996,7 @@ int opencl_ctx_init (hashcat_ctx_t *hashcat_ctx) if (opencl_platforms_filter > platform_cnt_mask) { - log_error ("ERROR: The platform selected by the --opencl-platforms parameter is larger than the number of available platforms (%d)", platforms_cnt); + event_log_error (hashcat_ctx, "The platform selected by the --opencl-platforms parameter is larger than the number of available platforms (%d)", platforms_cnt); return -1; } @@ -1485,18 +2017,9 @@ int opencl_ctx_init (hashcat_ctx_t *hashcat_ctx) cl_platform_id platform = platforms[platform_id]; - cl_int CL_err = hc_clGetDeviceIDs (opencl_ctx->ocl, platform, CL_DEVICE_TYPE_ALL, DEVICES_MAX, platform_devices, &platform_devices_cnt); + int CL_rc = hc_clGetDeviceIDs (hashcat_ctx, platform, CL_DEVICE_TYPE_ALL, DEVICES_MAX, platform_devices, &platform_devices_cnt); - if (CL_err != CL_SUCCESS) - { - //log_error ("ERROR: clGetDeviceIDs(): %s\n", val2cstr_cl (CL_err)); - - //return -1; - - // Silently ignore at this point, it will be reused later and create a note for the user at that point - - continue; - } + if (CL_rc == -1) continue; for (u32 platform_devices_id = 0; platform_devices_id < platform_devices_cnt; platform_devices_id++) { @@ -1504,14 +2027,9 @@ int opencl_ctx_init (hashcat_ctx_t *hashcat_ctx) cl_device_type device_type; - cl_int CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device, CL_DEVICE_TYPE, sizeof (device_type), &device_type, NULL); + int CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device, CL_DEVICE_TYPE, sizeof (device_type), &device_type, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; device_types_all |= device_type; } @@ -1554,15 +2072,13 @@ void opencl_ctx_destroy (hashcat_ctx_t *hashcat_ctx) if (opencl_ctx->enabled == false) return; - myfree (opencl_ctx->devices_param); + ocl_close (hashcat_ctx); - ocl_close (opencl_ctx->ocl); + hcfree (opencl_ctx->devices_param); - myfree (opencl_ctx->ocl); + hcfree (opencl_ctx->platforms); - myfree (opencl_ctx->platforms); - - myfree (opencl_ctx->platform_devices); + hcfree (opencl_ctx->platform_devices); memset (opencl_ctx, 0, sizeof (opencl_ctx_t)); } @@ -1583,10 +2099,10 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) cl_uint platform_devices_cnt = opencl_ctx->platform_devices_cnt; cl_device_id *platform_devices = opencl_ctx->platform_devices; - int need_adl = 0; - int need_nvml = 0; - int need_nvapi = 0; - int need_xnvctrl = 0; + bool need_adl = false; + bool need_nvml = false; + bool need_nvapi = false; + bool need_xnvctrl = false; u32 devices_cnt = 0; @@ -1599,20 +2115,15 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) for (u32 platform_id = 0; platform_id < platforms_cnt; platform_id++) { - cl_int CL_err = CL_SUCCESS; + int CL_rc = CL_SUCCESS; cl_platform_id platform = platforms[platform_id]; char platform_vendor[HCBUFSIZ_TINY] = { 0 }; - CL_err = hc_clGetPlatformInfo (opencl_ctx->ocl, platform, CL_PLATFORM_VENDOR, sizeof (platform_vendor), platform_vendor, NULL); + CL_rc = hc_clGetPlatformInfo (hashcat_ctx, platform, CL_PLATFORM_VENDOR, sizeof (platform_vendor), platform_vendor, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetPlatformInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; // find our own platform vendor because pocl and mesa are pushing original vendor_id through opencl // this causes trouble with vendor id based macros @@ -1659,11 +2170,11 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) u32 platform_skipped = ((opencl_ctx->opencl_platforms_filter & (1u << platform_id)) == 0); - CL_err = hc_clGetDeviceIDs (opencl_ctx->ocl, platform, CL_DEVICE_TYPE_ALL, DEVICES_MAX, platform_devices, &platform_devices_cnt); + CL_rc = hc_clGetDeviceIDs (hashcat_ctx, platform, CL_DEVICE_TYPE_ALL, DEVICES_MAX, platform_devices, &platform_devices_cnt); - if (CL_err != CL_SUCCESS) + if (CL_rc == -1) { - //log_error ("ERROR: clGetDeviceIDs(): %s\n", val2cstr_cl (CL_err)); + //event_log_error (hashcat_ctx, "clGetDeviceIDs(): %s", val2cstr_cl (CL_rc)); //return -1; @@ -1674,52 +2185,42 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) { char platform_name[HCBUFSIZ_TINY] = { 0 }; - CL_err = hc_clGetPlatformInfo (opencl_ctx->ocl, platform, CL_PLATFORM_NAME, HCBUFSIZ_TINY, platform_name, NULL); + CL_rc = hc_clGetPlatformInfo (hashcat_ctx, platform, CL_PLATFORM_NAME, HCBUFSIZ_TINY, platform_name, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetPlatformInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; char platform_version[HCBUFSIZ_TINY] = { 0 }; - CL_err = hc_clGetPlatformInfo (opencl_ctx->ocl, platform, CL_PLATFORM_VERSION, sizeof (platform_version), platform_version, NULL); + CL_rc = hc_clGetPlatformInfo (hashcat_ctx, platform, CL_PLATFORM_VERSION, sizeof (platform_version), platform_version, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetPlatformInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; fprintf (stdout, "\nPlatform ID #%u\n Vendor : %s\n Name : %s\n Version : %s\n\n", platform_id + 1, platform_vendor, platform_name, platform_version); } - if ((user_options->benchmark == true || user_options->quiet == false)) + if ((user_options->benchmark == true || user_options->speed_only == true || user_options->quiet == false)) { if (user_options->machine_readable == false) { if (platform_skipped == 0) { - const int len = log_info ("OpenCL Platform #%u: %s", platform_id + 1, platform_vendor); + const int len = event_log_info (hashcat_ctx, "OpenCL Platform #%u: %s", platform_id + 1, platform_vendor); char line[256] = { 0 }; for (int i = 0; i < len; i++) line[i] = '='; - log_info (line); + event_log_info (hashcat_ctx, line); } else if (platform_skipped == 1) { - log_info ("OpenCL Platform #%u: %s, skipped", platform_id + 1, platform_vendor); - log_info (""); + event_log_info (hashcat_ctx, "OpenCL Platform #%u: %s, skipped", platform_id + 1, platform_vendor); + event_log_info (hashcat_ctx, ""); } else if (platform_skipped == 2) { - log_info ("OpenCL Platform #%u: %s, skipped! No OpenCL compatible devices found", platform_id + 1, platform_vendor); - log_info (""); + event_log_info (hashcat_ctx, "OpenCL Platform #%u: %s, skipped! No OpenCL compatible devices found", platform_id + 1, platform_vendor); + event_log_info (hashcat_ctx, ""); } } } @@ -1751,14 +2252,9 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) cl_device_type device_type; - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_TYPE, sizeof (device_type), &device_type, NULL); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_TYPE, sizeof (device_type), &device_type, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; device_type &= ~CL_DEVICE_TYPE_DEFAULT; @@ -1766,49 +2262,29 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) // device_name - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_NAME, 0, NULL, ¶m_value_size); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_NAME, 0, NULL, ¶m_value_size); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + char *device_name = (char *) hcmalloc (hashcat_ctx, param_value_size); VERIFY_PTR (device_name); - char *device_name = (char *) mymalloc (param_value_size); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_NAME, param_value_size, device_name, NULL); - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_NAME, param_value_size, device_name, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; device_param->device_name = device_name; // device_vendor - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_VENDOR, 0, NULL, ¶m_value_size); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_VENDOR, 0, NULL, ¶m_value_size); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + char *device_vendor = (char *) hcmalloc (hashcat_ctx, param_value_size); VERIFY_PTR (device_vendor); - char *device_vendor = (char *) mymalloc (param_value_size); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_VENDOR, param_value_size, device_vendor, NULL); - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_VENDOR, param_value_size, device_vendor, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; device_param->device_vendor = device_vendor; @@ -1855,49 +2331,29 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) // device_version - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_VERSION, 0, NULL, ¶m_value_size); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_VERSION, 0, NULL, ¶m_value_size); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + char *device_version = (char *) hcmalloc (hashcat_ctx, param_value_size); VERIFY_PTR (device_version); - char *device_version = (char *) mymalloc (param_value_size); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_VERSION, param_value_size, device_version, NULL); - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_VERSION, param_value_size, device_version, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; device_param->device_version = device_version; // device_opencl_version - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_OPENCL_C_VERSION, 0, NULL, ¶m_value_size); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_OPENCL_C_VERSION, 0, NULL, ¶m_value_size); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + char *device_opencl_version = (char *) hcmalloc (hashcat_ctx, param_value_size); VERIFY_PTR (device_opencl_version); - char *device_opencl_version = (char *) mymalloc (param_value_size); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_OPENCL_C_VERSION, param_value_size, device_opencl_version, NULL); - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_OPENCL_C_VERSION, param_value_size, device_opencl_version, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; device_param->opencl_v12 = device_opencl_version[9] > '1' || device_opencl_version[11] >= '2'; @@ -1905,14 +2361,9 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) cl_uint device_processors; - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof (device_processors), &device_processors, NULL); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof (device_processors), &device_processors, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; device_param->device_processors = device_processors; @@ -1921,14 +2372,9 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) cl_ulong device_maxmem_alloc; - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof (device_maxmem_alloc), &device_maxmem_alloc, NULL); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof (device_maxmem_alloc), &device_maxmem_alloc, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; device_param->device_maxmem_alloc = MIN (device_maxmem_alloc, 0x7fffffff); @@ -1936,14 +2382,9 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) cl_ulong device_global_mem; - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof (device_global_mem), &device_global_mem, NULL); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof (device_global_mem), &device_global_mem, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; device_param->device_global_mem = device_global_mem; @@ -1951,14 +2392,9 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) size_t device_maxworkgroup_size; - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof (device_maxworkgroup_size), &device_maxworkgroup_size, NULL); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof (device_maxworkgroup_size), &device_maxworkgroup_size, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; device_param->device_maxworkgroup_size = device_maxworkgroup_size; @@ -1966,14 +2402,9 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) cl_uint device_maxclock_frequency; - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof (device_maxclock_frequency), &device_maxclock_frequency, NULL); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof (device_maxclock_frequency), &device_maxclock_frequency, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; device_param->device_maxclock_frequency = device_maxclock_frequency; @@ -1981,18 +2412,13 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) cl_bool device_endian_little; - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_ENDIAN_LITTLE, sizeof (device_endian_little), &device_endian_little, NULL); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_ENDIAN_LITTLE, sizeof (device_endian_little), &device_endian_little, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; if (device_endian_little == CL_FALSE) { - log_info ("- Device #%u: WARNING: Not a little endian device", device_id + 1); + event_log_warning (hashcat_ctx, "* Device #%u: Not a little endian device", device_id + 1); device_param->skipped = 1; } @@ -2001,18 +2427,13 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) cl_bool device_available; - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_AVAILABLE, sizeof (device_available), &device_available, NULL); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_AVAILABLE, sizeof (device_available), &device_available, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; if (device_available == CL_FALSE) { - log_info ("- Device #%u: WARNING: Device not available", device_id + 1); + event_log_warning (hashcat_ctx, "* Device #%u: Device not available", device_id + 1); device_param->skipped = 1; } @@ -2021,18 +2442,13 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) cl_bool device_compiler_available; - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_COMPILER_AVAILABLE, sizeof (device_compiler_available), &device_compiler_available, NULL); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_COMPILER_AVAILABLE, sizeof (device_compiler_available), &device_compiler_available, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; if (device_compiler_available == CL_FALSE) { - log_info ("- Device #%u: WARNING: No compiler available for device", device_id + 1); + event_log_warning (hashcat_ctx, "* Device #%u: No compiler available for device", device_id + 1); device_param->skipped = 1; } @@ -2041,18 +2457,13 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) cl_device_exec_capabilities device_execution_capabilities; - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_EXECUTION_CAPABILITIES, sizeof (device_execution_capabilities), &device_execution_capabilities, NULL); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_EXECUTION_CAPABILITIES, sizeof (device_execution_capabilities), &device_execution_capabilities, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; if ((device_execution_capabilities & CL_EXEC_KERNEL) == 0) { - log_info ("- Device #%u: WARNING: Device does not support executing kernels", device_id + 1); + event_log_warning (hashcat_ctx, "* Device #%u: Device does not support executing kernels", device_id + 1); device_param->skipped = 1; } @@ -2061,58 +2472,43 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) size_t device_extensions_size; - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_EXTENSIONS, 0, NULL, &device_extensions_size); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_EXTENSIONS, 0, NULL, &device_extensions_size); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + char *device_extensions = hcmalloc (hashcat_ctx, device_extensions_size + 1); VERIFY_PTR (device_extensions); - char *device_extensions = mymalloc (device_extensions_size + 1); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_EXTENSIONS, device_extensions_size, device_extensions, NULL); - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_EXTENSIONS, device_extensions_size, device_extensions, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; if (strstr (device_extensions, "base_atomics") == 0) { - log_info ("- Device #%u: WARNING: Device does not support base atomics", device_id + 1); + event_log_warning (hashcat_ctx, "* Device #%u: Device does not support base atomics", device_id + 1); device_param->skipped = 1; } if (strstr (device_extensions, "byte_addressable_store") == 0) { - log_info ("- Device #%u: WARNING: Device does not support byte addressable store", device_id + 1); + event_log_warning (hashcat_ctx, "* Device #%u: Device does not support byte addressable store", device_id + 1); device_param->skipped = 1; } - myfree (device_extensions); + hcfree (device_extensions); // device_local_mem_size cl_ulong device_local_mem_size; - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_LOCAL_MEM_SIZE, sizeof (device_local_mem_size), &device_local_mem_size, NULL); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_LOCAL_MEM_SIZE, sizeof (device_local_mem_size), &device_local_mem_size, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; if (device_local_mem_size < 32768) { - log_info ("- Device #%u: WARNING: Device local mem size is too small", device_id + 1); + event_log_warning (hashcat_ctx, "* Device #%u: Device local mem size is too small", device_id + 1); device_param->skipped = 1; } @@ -2129,8 +2525,8 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) { if (user_options->force == 0) { - log_info ("- Device #%u: WARNING: Not a native Intel OpenCL runtime, expect massive speed loss", device_id + 1); - log_info (" You can use --force to override this but do not post error reports if you do so"); + event_log_warning (hashcat_ctx, "* Device #%u: Not a native Intel OpenCL runtime, expect massive speed loss", device_id + 1); + event_log_warning (hashcat_ctx, " You can use --force to override this but do not post error reports if you do so"); device_param->skipped = 1; } @@ -2144,31 +2540,21 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) // driver_version - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DRIVER_VERSION, 0, NULL, ¶m_value_size); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DRIVER_VERSION, 0, NULL, ¶m_value_size); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + char *driver_version = (char *) hcmalloc (hashcat_ctx, param_value_size); VERIFY_PTR (driver_version); - char *driver_version = (char *) mymalloc (param_value_size); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DRIVER_VERSION, param_value_size, driver_version, NULL); - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DRIVER_VERSION, param_value_size, driver_version, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; device_param->driver_version = driver_version; // device_name_chksum - char *device_name_chksum = (char *) mymalloc (HCBUFSIZ_TINY); + char *device_name_chksum = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (device_name_chksum); #if defined (__x86_64__) snprintf (device_name_chksum, HCBUFSIZ_TINY - 1, "%u-%u-%u-%s-%s-%s-%u", 64, device_param->platform_vendor_id, device_param->vector_width, device_param->device_name, device_param->device_version, device_param->driver_version, comptime); @@ -2190,19 +2576,19 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) { if ((device_param->platform_vendor_id == VENDOR_ID_AMD) && (device_param->device_vendor_id == VENDOR_ID_AMD)) { - need_adl = 1; + need_adl = true; } if ((device_param->platform_vendor_id == VENDOR_ID_NV) && (device_param->device_vendor_id == VENDOR_ID_NV)) { - need_nvml = 1; + need_nvml = true; #if defined (__linux__) - need_xnvctrl = 1; + need_xnvctrl = true; #endif #if defined (_WIN) - need_nvapi = 1; + need_nvapi = true; #endif } } @@ -2215,14 +2601,9 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) #define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 0x4005 - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, sizeof (kernel_exec_timeout), &kernel_exec_timeout, NULL); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, sizeof (kernel_exec_timeout), &kernel_exec_timeout, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; device_param->kernel_exec_timeout = kernel_exec_timeout; @@ -2232,23 +2613,13 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) #define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000 #define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001 - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, sizeof (sm_minor), &sm_minor, NULL); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, sizeof (sm_minor), &sm_minor, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, sizeof (sm_major), &sm_major, NULL); - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, sizeof (sm_major), &sm_major, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; device_param->sm_minor = sm_minor; device_param->sm_major = sm_major; @@ -2296,15 +2667,15 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) device_opencl_version); } - myfree (device_opencl_version); + hcfree (device_opencl_version); - if ((user_options->benchmark == true || user_options->quiet == false)) + if ((user_options->benchmark == true || user_options->speed_only == true || user_options->quiet == false)) { if (user_options->machine_readable == false) { if (device_param->skipped == 0) { - log_info ("- Device #%u: %s, %lu/%lu MB allocatable, %uMCU", + event_log_info (hashcat_ctx, "* Device #%u: %s, %lu/%lu MB allocatable, %uMCU", device_id + 1, device_name, (unsigned int) (device_maxmem_alloc / 1024 / 1024), @@ -2313,7 +2684,7 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) } else { - log_info ("- Device #%u: %s, skipped", + event_log_info (hashcat_ctx, "* Device #%u: %s, skipped", device_id + 1, device_name); } @@ -2349,25 +2720,27 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) if (catalyst_broken == 1) { - log_info ("ATTENTION! The Catalyst driver installed on your system is known to be broken!"); - log_info ("It passes over cracked hashes and will not report them as cracked"); - log_info ("You are STRONGLY encouraged not to use it"); - log_info ("You can use --force to override this but do not post error reports if you do so"); - log_info (""); + event_log_error (hashcat_ctx, "* Device #%u: The Catalyst driver installed on your system is known to be broken!", device_id + 1); + event_log_error (hashcat_ctx, ""); + event_log_error (hashcat_ctx, "It passes over cracked hashes and will not report them as cracked"); + event_log_error (hashcat_ctx, "You are STRONGLY encouraged not to use it"); + event_log_error (hashcat_ctx, "You can use --force to override this but do not post error reports if you do so"); + event_log_error (hashcat_ctx, ""); return -1; } if (catalyst_warn == 1) { - log_info ("ATTENTION! Unsupported or incorrectly installed Catalyst driver detected!"); - log_info ("You are STRONGLY encouraged to use the official supported catalyst driver"); - log_info ("See hashcat's homepage for official supported catalyst drivers"); + event_log_error (hashcat_ctx, "* Device #%u: Unsupported or incorrectly installed Catalyst driver detected!", device_id + 1); + event_log_error (hashcat_ctx, ""); + event_log_error (hashcat_ctx, "You are STRONGLY encouraged to use the official supported catalyst driver"); + event_log_error (hashcat_ctx, "See hashcat's homepage for official supported catalyst drivers"); #if defined (_WIN) - log_info ("Also see: http://hashcat.net/wiki/doku.php?id=upgrading_amd_drivers_how_to"); + event_log_error (hashcat_ctx, "Also see: http://hashcat.net/wiki/doku.php?id=upgrading_amd_drivers_how_to"); #endif - log_info ("You can use --force to override this but do not post error reports if you do so"); - log_info (""); + event_log_error (hashcat_ctx, "You can use --force to override this but do not post error reports if you do so"); + event_log_error (hashcat_ctx, ""); return -1; } @@ -2376,31 +2749,12 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) { if (device_param->kernel_exec_timeout != 0) { - log_info ("- Device #%u: WARNING! Kernel exec timeout is not disabled, it might cause you errors of code 702", device_id + 1); - log_info (" See the wiki on how to disable it: https://hashcat.net/wiki/doku.php?id=timeout_patch"); + event_log_warning (hashcat_ctx, "* Device #%u: Kernel exec timeout is not disabled, it might cause you errors of code 702", device_id + 1); + event_log_warning (hashcat_ctx, " See the wiki on how to disable it: https://hashcat.net/wiki/doku.php?id=timeout_patch"); } } } - /* turns out pocl still creates segfaults (because of llvm) - if (device_type & CL_DEVICE_TYPE_CPU) - { - if (platform_vendor_id == VENDOR_ID_AMD) - { - if (user_options->force == 0) - { - log_info ("ATTENTION! OpenCL support for CPU of catalyst driver is not reliable."); - log_info ("You are STRONGLY encouraged not to use it"); - log_info ("You can use --force to override this but do not post error reports if you do so"); - log_info ("A good alternative is the free pocl >= v0.13, but make sure to use a LLVM >= v3.8"); - log_info (""); - - return -1; - } - } - } - */ - /** * activate device */ @@ -2413,23 +2767,23 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) devices_cnt++; } - if ((user_options->benchmark == true || user_options->quiet == false)) + if ((user_options->benchmark == true || user_options->speed_only == true || user_options->quiet == false)) { if (user_options->machine_readable == false) { - log_info (""); + event_log_info (hashcat_ctx, ""); } } } if (user_options->opencl_info == true) { - exit (0); + return 0; } if (devices_active == 0) { - log_error ("ERROR: No devices found/left"); + event_log_error (hashcat_ctx, "No devices found/left"); return -1; } @@ -2442,13 +2796,13 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) if (opencl_ctx->devices_filter > devices_cnt_mask) { - log_error ("ERROR: The device specified by the --opencl-devices parameter is larger than the number of available devices (%d)", devices_cnt); + event_log_error (hashcat_ctx, "The device specified by the --opencl-devices parameter is larger than the number of available devices (%d)", devices_cnt); return -1; } } - opencl_ctx->target_ms = TARGET_MS_PROFILE[user_options->workload_profile - 1]; + opencl_ctx->target_msec = TARGET_MSEC_PROFILE[user_options->workload_profile - 1]; opencl_ctx->devices_cnt = devices_cnt; opencl_ctx->devices_active = devices_active; @@ -2473,19 +2827,19 @@ void opencl_ctx_devices_destroy (hashcat_ctx_t *hashcat_ctx) if (device_param->skipped) continue; - myfree (device_param->device_name); - myfree (device_param->device_name_chksum); - myfree (device_param->device_version); - myfree (device_param->driver_version); + hcfree (device_param->device_name); + hcfree (device_param->device_name_chksum); + hcfree (device_param->device_version); + hcfree (device_param->driver_version); } opencl_ctx->devices_cnt = 0; opencl_ctx->devices_active = 0; - opencl_ctx->need_adl = 0; - opencl_ctx->need_nvml = 0; - opencl_ctx->need_nvapi = 0; - opencl_ctx->need_xnvctrl = 0; + opencl_ctx->need_adl = false; + opencl_ctx->need_nvml = false; + opencl_ctx->need_nvapi = false; + opencl_ctx->need_xnvctrl = false; } void opencl_ctx_devices_update_power (hashcat_ctx_t *hashcat_ctx) @@ -2518,14 +2872,11 @@ void opencl_ctx_devices_update_power (hashcat_ctx_t *hashcat_ctx) { if (user_options->quiet == false) { - clear_prompt (); - - log_info ("ATTENTION!"); - log_info (" The wordlist or mask you are using is too small."); - log_info (" Therefore, hashcat is unable to utilize the full parallelization power of your device(s)."); - log_info (" The cracking speed will drop."); - log_info (" Workaround: https://hashcat.net/wiki/doku.php?id=frequently_asked_questions#how_to_create_more_work_for_full_speed"); - log_info (""); + event_log_warning (hashcat_ctx, "The wordlist or mask you are using is too small."); + event_log_warning (hashcat_ctx, "Therefore, hashcat is unable to utilize the full parallelization power of your device(s)."); + event_log_warning (hashcat_ctx, "The cracking speed will drop."); + event_log_warning (hashcat_ctx, "Workaround: https://hashcat.net/wiki/doku.php?id=frequently_asked_questions#how_to_create_more_work_for_full_speed"); + event_log_warning (hashcat_ctx, ""); } } } @@ -2609,7 +2960,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - cl_int CL_err = CL_SUCCESS; + int CL_rc = CL_SUCCESS; /** * host buffer @@ -2633,25 +2984,15 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) { if (hashconfig->opti_type & OPTI_TYPE_USES_BITS_64) { - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, sizeof (vector_width), &vector_width, NULL); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, sizeof (vector_width), &vector_width, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } else { - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, sizeof (vector_width), &vector_width, NULL); + CL_rc = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, sizeof (vector_width), &vector_width, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } } else @@ -2739,30 +3080,20 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) properties[1] = (cl_context_properties) device_param->platform; properties[2] = 0; - CL_err = hc_clCreateContext (opencl_ctx->ocl, properties, 1, &device_param->device, NULL, NULL, &device_param->context); + CL_rc = hc_clCreateContext (hashcat_ctx, properties, 1, &device_param->device, NULL, NULL, &device_param->context); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateContext(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; /** * create command-queue */ // not supported with NV - // device_param->command_queue = hc_clCreateCommandQueueWithProperties (device_param->context, device_param->device, NULL); + // device_param->command_queue = hc_clCreateCommandQueueWithProperties (hashcat_ctx, device_param->device, NULL); - CL_err = hc_clCreateCommandQueue (opencl_ctx->ocl, device_param->context, device_param->device, CL_QUEUE_PROFILING_ENABLE, &device_param->command_queue); + CL_rc = hc_clCreateCommandQueue (hashcat_ctx, device_param->context, device_param->device, CL_QUEUE_PROFILING_ENABLE, &device_param->command_queue); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateCommandQueue(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; /** * kernel threads: some algorithms need a fixed kernel-threads count @@ -2776,8 +3107,6 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) device_param->hardware_power = device_processors * kernel_threads; - hardware_power_all += device_param->hardware_power; - /** * create input buffers on device : calculate size of fixed memory buffers */ @@ -2831,7 +3160,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) || (hashes->salts_buf[i].scrypt_r != scrypt_r) || (hashes->salts_buf[i].scrypt_p != scrypt_p)) { - log_error ("ERROR: Mixed scrypt settings not supported"); + event_log_error (hashcat_ctx, "Mixed scrypt settings not supported"); return -1; } @@ -2892,14 +3221,14 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if ((size_scrypt / 4) > device_param->device_maxmem_alloc) { - log_info ("WARNING: Not enough single-block device memory allocatable to use --scrypt-tmto %d, increasing...", tmto); + event_log_warning (hashcat_ctx, "Not enough single-block device memory allocatable to use --scrypt-tmto %d, increasing...", tmto); continue; } if (size_scrypt > device_param->device_global_mem) { - log_info ("WARNING: Not enough total device memory allocatable to use --scrypt-tmto %d, increasing...", tmto); + event_log_warning (hashcat_ctx, "Not enough total device memory allocatable to use --scrypt-tmto %d, increasing...", tmto); continue; } @@ -2914,12 +3243,13 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (tmto == tmto_stop) { - log_error ("ERROR: Can't allocate enough device memory"); + event_log_error (hashcat_ctx, "Can't allocate enough device memory"); return -1; } - if (user_options->quiet == false) log_info ("SCRYPT tmto optimizer value set to: %u, mem: %" PRIu64 "\n", scrypt_tmto_final, size_scrypt); + if (user_options->quiet == false) event_log_info (hashcat_ctx, "SCRYPT tmto optimizer value set to: %u, mem: %" PRIu64, scrypt_tmto_final, size_scrypt); + if (user_options->quiet == false) event_log_info (hashcat_ctx, ""); } size_t size_scrypt4 = size_scrypt / 4; @@ -3015,7 +3345,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (kernel_accel_max < kernel_accel_min) { - log_error ("- Device #%u: Device does not provide enough allocatable device-memory to handle this attack", device_id + 1); + event_log_error (hashcat_ctx, "* Device #%u: Device does not provide enough allocatable device-memory to handle this attack", device_id + 1); return -1; } @@ -3026,7 +3356,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) /* if (kernel_accel_max < kernel_accel) { - if (user_options->quiet == false) log_info ("- Device #%u: Reduced maximum kernel-accel to %u", device_id + 1, kernel_accel_max); + if (user_options->quiet == false) event_log_info (hashcat_ctx, "* Device #%u: Reduced maximum kernel-accel to %u", device_id + 1, kernel_accel_max); device_param->kernel_accel = kernel_accel_max; } @@ -3046,7 +3376,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (chdir (folder_config->cpath_real) == -1) { - log_error ("ERROR: %s: %s", folder_config->cpath_real, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", folder_config->cpath_real, strerror (errno)); return -1; } @@ -3090,7 +3420,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (fd == NULL) { - log_error ("ERROR: %s: fopen(): %s", files_names[i], strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", files_names[i], strerror (errno)); return -1; } @@ -3101,7 +3431,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (n != 1) { - log_error ("ERROR: %s: fread(): %s", files_names[i], strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", files_names[i], strerror (errno)); return -1; } @@ -3122,7 +3452,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) strncpy (build_opts, build_opts_new, sizeof (build_opts)); #if defined (DEBUG) - log_info ("- Device #%u: build_opts '%s'\n", device_id + 1, build_opts); + event_log_info (hashcat_ctx, "* Device #%u: build_opts '%s'", device_id + 1, build_opts); #endif /** @@ -3142,7 +3472,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (stat (source_file, &sst) == -1) { - log_error ("ERROR: %s: %s", source_file, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", source_file, strerror (errno)); return -1; } @@ -3168,151 +3498,110 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) * kernel compile or load */ - size_t *kernel_lengths = (size_t *) mymalloc (sizeof (size_t)); + size_t *kernel_lengths = (size_t *) hcmalloc (hashcat_ctx, sizeof (size_t)); VERIFY_PTR (kernel_lengths); - char **kernel_sources = (char **) mymalloc (sizeof (char *)); + char **kernel_sources = (char **) hcmalloc (hashcat_ctx, sizeof (char *)); VERIFY_PTR (kernel_sources); if (opencl_ctx->force_jit_compilation == -1) { if (cached == 0) { - if (user_options->quiet == false) log_info ("- Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); + if (user_options->quiet == false) event_log_info_nn (hashcat_ctx, "Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); - read_kernel_binary (source_file, 1, kernel_lengths, kernel_sources); + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, 1, kernel_lengths, kernel_sources); - CL_err = hc_clCreateProgramWithSource (opencl_ctx->ocl, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program); + if (rc_read_kernel == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateProgramWithSource(): %s\n", val2cstr_cl (CL_err)); + CL_rc = hc_clCreateProgramWithSource (hashcat_ctx, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program); - return -1; - } + if (CL_rc == -1) return -1; - CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program, 1, &device_param->device, build_opts, NULL, NULL); + CL_rc = hc_clBuildProgram (hashcat_ctx, device_param->program, 1, &device_param->device, build_opts, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clBuildProgram(): %s\n", val2cstr_cl (CL_err)); - - //return -1; - } + //if (CL_rc == -1) return -1; size_t build_log_size = 0; - /* - CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + hc_clGetProgramBuildInfo (hashcat_ctx, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetProgramBuildInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - */ - - hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + //if (CL_rc == -1) return -1; #if defined (DEBUG) - if ((build_log_size != 0) || (CL_err != CL_SUCCESS)) + if ((build_log_size != 0) || (CL_rc == -1)) #else - if (CL_err != CL_SUCCESS) + if (CL_rc == -1) #endif { - char *build_log = (char *) mymalloc (build_log_size + 1); + char *build_log = (char *) hcmalloc (hashcat_ctx, build_log_size + 1); VERIFY_PTR (build_log); - CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); + int CL_rc_build = hc_clGetProgramBuildInfo (hashcat_ctx, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetProgramBuildInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc_build == -1) return -1; puts (build_log); - myfree (build_log); + hcfree (build_log); } - if (CL_err != CL_SUCCESS) + if (CL_rc == -1) { device_param->skipped = true; - log_info ("- Device #%u: Kernel %s build failure. Proceeding without this device.", device_id + 1, source_file); + event_log_error (hashcat_ctx, "Device #%u: Kernel %s build failure. Proceeding without this device.", device_id + 1, source_file); continue; } size_t binary_size; - CL_err = hc_clGetProgramInfo (opencl_ctx->ocl, device_param->program, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL); + CL_rc = hc_clGetProgramInfo (hashcat_ctx, device_param->program, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetProgramInfo(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + char *binary = (char *) hcmalloc (hashcat_ctx, binary_size); VERIFY_PTR (binary); - char *binary = (char *) mymalloc (binary_size); + CL_rc = hc_clGetProgramInfo (hashcat_ctx, device_param->program, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); - CL_err = hc_clGetProgramInfo (opencl_ctx->ocl, device_param->program, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); + if (CL_rc == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetProgramInfo(): %s\n", val2cstr_cl (CL_err)); + const int rc_write = write_kernel_binary (hashcat_ctx, cached_file, binary, binary_size); - return -1; - } + if (rc_write == -1) return -1; - write_kernel_binary (cached_file, binary, binary_size); - - myfree (binary); + hcfree (binary); } else { #if defined (DEBUG) - log_info ("- Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size); + event_log_info (hashcat_ctx, "Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size); #endif - read_kernel_binary (cached_file, 1, kernel_lengths, kernel_sources); + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, cached_file, 1, kernel_lengths, kernel_sources); - CL_err = hc_clCreateProgramWithBinary (opencl_ctx->ocl, device_param->context, 1, &device_param->device, kernel_lengths, (const unsigned char **) kernel_sources, NULL, &device_param->program); + if (rc_read_kernel == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateProgramWithBinary(): %s\n", val2cstr_cl (CL_err)); + CL_rc = hc_clCreateProgramWithBinary (hashcat_ctx, device_param->context, 1, &device_param->device, kernel_lengths, (const unsigned char **) kernel_sources, NULL, &device_param->program); - return -1; - } + if (CL_rc == -1) return -1; - CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program, 1, &device_param->device, build_opts, NULL, NULL); + CL_rc = hc_clBuildProgram (hashcat_ctx, device_param->program, 1, &device_param->device, build_opts, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clBuildProgram(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } } else { #if defined (DEBUG) - log_info ("- Device #%u: Kernel %s (%ld bytes)", device_id + 1, source_file, sst.st_size); + event_log_info (hashcat_ctx, "Device #%u: Kernel %s (%ld bytes)", device_id + 1, source_file, sst.st_size); #endif - read_kernel_binary (source_file, 1, kernel_lengths, kernel_sources); + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, 1, kernel_lengths, kernel_sources); - CL_err = hc_clCreateProgramWithSource (opencl_ctx->ocl, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program); + if (rc_read_kernel == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateProgramWithSource(): %s\n", val2cstr_cl (CL_err)); + CL_rc = hc_clCreateProgramWithSource (hashcat_ctx, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program); - return -1; - } + if (CL_rc == -1) return -1; char build_opts_update[1024] = { 0 }; @@ -3329,63 +3618,46 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) snprintf (build_opts_update, sizeof (build_opts_update) - 1, "%s", build_opts); } - CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program, 1, &device_param->device, build_opts_update, NULL, NULL); + CL_rc = hc_clBuildProgram (hashcat_ctx, device_param->program, 1, &device_param->device, build_opts_update, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clBuildProgram(): %s\n", val2cstr_cl (CL_err)); - - //return -1; - } + //if (CL_rc == -1) return -1; size_t build_log_size = 0; - /* - CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + hc_clGetProgramBuildInfo (hashcat_ctx, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetProgramBuildInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - */ - - hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + //if (CL_rc == -1) return -1; #if defined (DEBUG) - if ((build_log_size != 0) || (CL_err != CL_SUCCESS)) + if ((build_log_size != 0) || (CL_rc == -1)) #else - if (CL_err != CL_SUCCESS) + if (CL_rc == -1) #endif { - char *build_log = (char *) mymalloc (build_log_size + 1); + char *build_log = (char *) hcmalloc (hashcat_ctx, build_log_size + 1); VERIFY_PTR (build_log); - CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); + int CL_rc_build = hc_clGetProgramBuildInfo (hashcat_ctx, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetProgramBuildInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc_build == -1) return -1; puts (build_log); - myfree (build_log); + hcfree (build_log); } - if (CL_err != CL_SUCCESS) + if (CL_rc == -1) { device_param->skipped = true; - log_info ("- Device #%u: Kernel %s build failure. Proceeding without this device.", device_id + 1, source_file); + event_log_error (hashcat_ctx, "Device #%u: Kernel %s build failure. Proceeding without this device.", device_id + 1, source_file); + + continue; } } - myfree (kernel_lengths); - myfree (kernel_sources[0]); - myfree (kernel_sources); + hcfree (kernel_lengths); + hcfree (kernel_sources[0]); + hcfree (kernel_sources); } /** @@ -3406,7 +3678,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (stat (source_file, &sst) == -1) { - log_error ("ERROR: %s: %s", source_file, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", source_file, strerror (errno)); return -1; } @@ -3432,137 +3704,96 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) * kernel compile or load */ - size_t *kernel_lengths = (size_t *) mymalloc (sizeof (size_t)); + size_t *kernel_lengths = (size_t *) hcmalloc (hashcat_ctx, sizeof (size_t)); VERIFY_PTR (kernel_lengths); - char **kernel_sources = (char **) mymalloc (sizeof (char *)); + char **kernel_sources = (char **) hcmalloc (hashcat_ctx, sizeof (char *)); VERIFY_PTR (kernel_sources); if (cached == 0) { - if (user_options->quiet == false) log_info ("- Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); - if (user_options->quiet == false) log_info (""); + if (user_options->quiet == false) event_log_info_nn (hashcat_ctx, "Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); - read_kernel_binary (source_file, 1, kernel_lengths, kernel_sources); + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, 1, kernel_lengths, kernel_sources); - CL_err = hc_clCreateProgramWithSource (opencl_ctx->ocl, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program_mp); + if (rc_read_kernel == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateProgramWithSource(): %s\n", val2cstr_cl (CL_err)); + CL_rc = hc_clCreateProgramWithSource (hashcat_ctx, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program_mp); - return -1; - } + if (CL_rc == -1) return -1; - CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program_mp, 1, &device_param->device, build_opts, NULL, NULL); + CL_rc = hc_clBuildProgram (hashcat_ctx, device_param->program_mp, 1, &device_param->device, build_opts, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clBuildProgram(): %s\n", val2cstr_cl (CL_err)); - - //return -1; - } + //if (CL_rc == -1) return -1; size_t build_log_size = 0; - /* - CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_mp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + hc_clGetProgramBuildInfo (hashcat_ctx, device_param->program_mp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetProgramBuildInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - */ - - hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_mp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + //if (CL_rc == -1) return -1; #if defined (DEBUG) - if ((build_log_size != 0) || (CL_err != CL_SUCCESS)) + if ((build_log_size != 0) || (CL_rc == -1)) #else - if (CL_err != CL_SUCCESS) + if (CL_rc == -1) #endif { - char *build_log = (char *) mymalloc (build_log_size + 1); + char *build_log = (char *) hcmalloc (hashcat_ctx, build_log_size + 1); VERIFY_PTR (build_log); - CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_mp, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); + int CL_rc_build = hc_clGetProgramBuildInfo (hashcat_ctx, device_param->program_mp, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetProgramBuildInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc_build == -1) return -1; puts (build_log); - myfree (build_log); + hcfree (build_log); } - if (CL_err != CL_SUCCESS) + if (CL_rc == -1) { device_param->skipped = true; - log_info ("- Device #%u: Kernel %s build failure. Proceeding without this device.", device_id + 1, source_file); + event_log_error (hashcat_ctx, "Device #%u: Kernel %s build failure. Proceeding without this device.", device_id + 1, source_file); continue; } size_t binary_size; - CL_err = hc_clGetProgramInfo (opencl_ctx->ocl, device_param->program_mp, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL); + CL_rc = hc_clGetProgramInfo (hashcat_ctx, device_param->program_mp, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetProgramInfo(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + char *binary = (char *) hcmalloc (hashcat_ctx, binary_size); VERIFY_PTR (binary); - char *binary = (char *) mymalloc (binary_size); + CL_rc = hc_clGetProgramInfo (hashcat_ctx, device_param->program_mp, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); - CL_err = hc_clGetProgramInfo (opencl_ctx->ocl, device_param->program_mp, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); + if (CL_rc == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetProgramInfo(): %s\n", val2cstr_cl (CL_err)); + write_kernel_binary (hashcat_ctx, cached_file, binary, binary_size); - return -1; - } - - write_kernel_binary (cached_file, binary, binary_size); - - myfree (binary); + hcfree (binary); } else { #if defined (DEBUG) - log_info ("- Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size); + event_log_info (hashcat_ctx, "Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size); #endif - read_kernel_binary (cached_file, 1, kernel_lengths, kernel_sources); + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, cached_file, 1, kernel_lengths, kernel_sources); - CL_err = hc_clCreateProgramWithBinary (opencl_ctx->ocl, device_param->context, 1, &device_param->device, kernel_lengths, (const unsigned char **) kernel_sources, NULL, &device_param->program_mp); + if (rc_read_kernel == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateProgramWithBinary(): %s\n", val2cstr_cl (CL_err)); + CL_rc = hc_clCreateProgramWithBinary (hashcat_ctx, device_param->context, 1, &device_param->device, kernel_lengths, (const unsigned char **) kernel_sources, NULL, &device_param->program_mp); - return -1; - } + if (CL_rc == -1) return -1; - CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program_mp, 1, &device_param->device, build_opts, NULL, NULL); + CL_rc = hc_clBuildProgram (hashcat_ctx, device_param->program_mp, 1, &device_param->device, build_opts, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clBuildProgram(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } - myfree (kernel_lengths); - myfree (kernel_sources[0]); - myfree (kernel_sources); + hcfree (kernel_lengths); + hcfree (kernel_sources[0]); + hcfree (kernel_sources); } /** @@ -3587,7 +3818,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (stat (source_file, &sst) == -1) { - log_error ("ERROR: %s: %s", source_file, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", source_file, strerror (errno)); return -1; } @@ -3613,144 +3844,103 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) * kernel compile or load */ - size_t *kernel_lengths = (size_t *) mymalloc (sizeof (size_t)); + size_t *kernel_lengths = (size_t *) hcmalloc (hashcat_ctx, sizeof (size_t)); VERIFY_PTR (kernel_lengths); - char **kernel_sources = (char **) mymalloc (sizeof (char *)); + char **kernel_sources = (char **) hcmalloc (hashcat_ctx, sizeof (char *)); VERIFY_PTR (kernel_sources); if (cached == 0) { - if (user_options->quiet == false) log_info ("- Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); - if (user_options->quiet == false) log_info (""); + if (user_options->quiet == false) event_log_info_nn (hashcat_ctx, "Device #%u: Kernel %s not found in cache! Building may take a while...", device_id + 1, filename_from_filepath (cached_file)); - read_kernel_binary (source_file, 1, kernel_lengths, kernel_sources); + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, 1, kernel_lengths, kernel_sources); - CL_err = hc_clCreateProgramWithSource (opencl_ctx->ocl, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program_amp); + if (rc_read_kernel == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateProgramWithSource(): %s\n", val2cstr_cl (CL_err)); + CL_rc = hc_clCreateProgramWithSource (hashcat_ctx, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program_amp); - return -1; - } + if (CL_rc == -1) return -1; - CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program_amp, 1, &device_param->device, build_opts, NULL, NULL); + CL_rc = hc_clBuildProgram (hashcat_ctx, device_param->program_amp, 1, &device_param->device, build_opts, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clBuildProgram(): %s\n", val2cstr_cl (CL_err)); - - //return -1; - } + //if (CL_rc == -1) return -1; size_t build_log_size = 0; - /* - CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_amp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + hc_clGetProgramBuildInfo (hashcat_ctx, device_param->program_amp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetProgramBuildInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - */ - - hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_amp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + //if (CL_rc == -1) return -1; #if defined (DEBUG) - if ((build_log_size != 0) || (CL_err != CL_SUCCESS)) + if ((build_log_size != 0) || (CL_rc == -1)) #else - if (CL_err != CL_SUCCESS) + if (CL_rc == -1) #endif { - char *build_log = (char *) mymalloc (build_log_size + 1); + char *build_log = (char *) hcmalloc (hashcat_ctx, build_log_size + 1); VERIFY_PTR (build_log); - CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_amp, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); + CL_rc = hc_clGetProgramBuildInfo (hashcat_ctx, device_param->program_amp, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetProgramBuildInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; puts (build_log); - myfree (build_log); + hcfree (build_log); } - if (CL_err != CL_SUCCESS) + if (CL_rc == -1) { device_param->skipped = true; - log_info ("- Device #%u: Kernel %s build failure. Proceed without this device.", device_id + 1, source_file); + event_log_error (hashcat_ctx, "Device #%u: Kernel %s build failure. Proceed without this device.", device_id + 1, source_file); continue; } size_t binary_size; - CL_err = hc_clGetProgramInfo (opencl_ctx->ocl, device_param->program_amp, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL); + CL_rc = hc_clGetProgramInfo (hashcat_ctx, device_param->program_amp, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetProgramInfo(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + char *binary = (char *) hcmalloc (hashcat_ctx, binary_size); VERIFY_PTR (binary); - char *binary = (char *) mymalloc (binary_size); + CL_rc = hc_clGetProgramInfo (hashcat_ctx, device_param->program_amp, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); - CL_err = hc_clGetProgramInfo (opencl_ctx->ocl, device_param->program_amp, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); + if (CL_rc == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetProgramInfo(): %s\n", val2cstr_cl (CL_err)); + write_kernel_binary (hashcat_ctx, cached_file, binary, binary_size); - return -1; - } - - write_kernel_binary (cached_file, binary, binary_size); - - myfree (binary); + hcfree (binary); } else { #if defined (DEBUG) - if (user_options->quiet == false) log_info ("- Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size); + if (user_options->quiet == false) event_log_info (hashcat_ctx, "Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size); #endif - read_kernel_binary (cached_file, 1, kernel_lengths, kernel_sources); + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, cached_file, 1, kernel_lengths, kernel_sources); - CL_err = hc_clCreateProgramWithBinary (opencl_ctx->ocl, device_param->context, 1, &device_param->device, kernel_lengths, (const unsigned char **) kernel_sources, NULL, &device_param->program_amp); + if (rc_read_kernel == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateProgramWithBinary(): %s\n", val2cstr_cl (CL_err)); + CL_rc = hc_clCreateProgramWithBinary (hashcat_ctx, device_param->context, 1, &device_param->device, kernel_lengths, (const unsigned char **) kernel_sources, NULL, &device_param->program_amp); - return -1; - } + if (CL_rc == -1) return -1; - CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program_amp, 1, &device_param->device, build_opts, NULL, NULL); + CL_rc = hc_clBuildProgram (hashcat_ctx, device_param->program_amp, 1, &device_param->device, build_opts, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clBuildProgram(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } - myfree (kernel_lengths); - myfree (kernel_sources[0]); - myfree (kernel_sources); + hcfree (kernel_lengths); + hcfree (kernel_sources[0]); + hcfree (kernel_sources); } // return back to the folder we came from initially (workaround) if (chdir (folder_config->cwd) == -1) { - log_error ("ERROR: %s: %s", folder_config->cwd, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", folder_config->cwd, strerror (errno)); return -1; } @@ -3769,53 +3959,39 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) * global buffers */ - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_pws, NULL, &device_param->d_pws_buf); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_pws, NULL, &device_param->d_pws_amp_buf); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_tmps, NULL, &device_param->d_tmps); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_hooks, NULL, &device_param->d_hooks); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s1_a); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s1_b); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s1_c); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s1_d); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s2_a); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s2_b); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s2_c); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s2_d); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_plains, NULL, &device_param->d_plain_bufs); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_digests, NULL, &device_param->d_digests_buf); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_shown, NULL, &device_param->d_digests_shown); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_salts, NULL, &device_param->d_salt_bufs); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_results, NULL, &device_param->d_result); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV0_buf); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV1_buf); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV2_buf); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV3_buf); + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_pws, NULL, &device_param->d_pws_buf); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_pws, NULL, &device_param->d_pws_amp_buf); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_tmps, NULL, &device_param->d_tmps); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_hooks, NULL, &device_param->d_hooks); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s1_a); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s1_b); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s1_c); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s1_d); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s2_a); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s2_b); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s2_c); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s2_d); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_plains, NULL, &device_param->d_plain_bufs); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_digests, NULL, &device_param->d_digests_buf); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_shown, NULL, &device_param->d_digests_shown); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_salts, NULL, &device_param->d_salt_bufs); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_results, NULL, &device_param->d_result); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV0_buf); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV1_buf); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV2_buf); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV3_buf); if (CL_rc == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bitmap_s1_a, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_a, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bitmap_s1_b, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_b, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bitmap_s1_c, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_c, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bitmap_s1_d, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_d, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bitmap_s2_a, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_a, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bitmap_s2_b, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_b, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bitmap_s2_c, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_c, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_bitmap_s2_d, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_d, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_digests_buf, CL_TRUE, 0, size_digests, hashes->digests_buf, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_digests_shown, CL_TRUE, 0, size_shown, hashes->digests_shown, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_salt_bufs, CL_TRUE, 0, size_salts, hashes->salts_buf, 0, NULL, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s1_a, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_a, 0, NULL, NULL); if (CL_rc == -1) return -1; + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s1_b, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_b, 0, NULL, NULL); if (CL_rc == -1) return -1; + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s1_c, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_c, 0, NULL, NULL); if (CL_rc == -1) return -1; + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s1_d, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s1_d, 0, NULL, NULL); if (CL_rc == -1) return -1; + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s2_a, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_a, 0, NULL, NULL); if (CL_rc == -1) return -1; + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s2_b, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_b, 0, NULL, NULL); if (CL_rc == -1) return -1; + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s2_c, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_c, 0, NULL, NULL); if (CL_rc == -1) return -1; + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_bitmap_s2_d, CL_TRUE, 0, bitmap_ctx->bitmap_size, bitmap_ctx->bitmap_s2_d, 0, NULL, NULL); if (CL_rc == -1) return -1; + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_digests_buf, CL_TRUE, 0, size_digests, hashes->digests_buf, 0, NULL, NULL); if (CL_rc == -1) return -1; + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_digests_shown, CL_TRUE, 0, size_shown, hashes->digests_shown, 0, NULL, NULL); if (CL_rc == -1) return -1; + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_salt_bufs, CL_TRUE, 0, size_salts, hashes->salts_buf, 0, NULL, NULL); if (CL_rc == -1) return -1; /** * special buffers @@ -3823,89 +3999,51 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) { - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_rules, NULL, &device_param->d_rules); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_rules_c, NULL, &device_param->d_rules_c); + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_rules, NULL, &device_param->d_rules); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_rules_c, NULL, &device_param->d_rules_c); if (CL_rc == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_rules, CL_TRUE, 0, size_rules, straight_ctx->kernel_rules_buf, 0, NULL, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_rules, CL_TRUE, 0, size_rules, straight_ctx->kernel_rules_buf, 0, NULL, NULL); if (CL_rc == -1) return -1; } else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) { - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_combs, NULL, &device_param->d_combs); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_combs, NULL, &device_param->d_combs_c); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_root_css, NULL, &device_param->d_root_css_buf); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_markov_css, NULL, &device_param->d_markov_css_buf); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_combs, NULL, &device_param->d_combs); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_combs, NULL, &device_param->d_combs_c); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_root_css, NULL, &device_param->d_root_css_buf); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_markov_css, NULL, &device_param->d_markov_css_buf); if (CL_rc == -1) return -1; } else if (user_options_extra->attack_kern == ATTACK_KERN_BF) { - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_bfs, NULL, &device_param->d_bfs); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_bfs, NULL, &device_param->d_bfs_c); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_tm, NULL, &device_param->d_tm_c); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_root_css, NULL, &device_param->d_root_css_buf); - CL_err |= hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_markov_css, NULL, &device_param->d_markov_css_buf); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_bfs, NULL, &device_param->d_bfs); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_bfs, NULL, &device_param->d_bfs_c); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_tm, NULL, &device_param->d_tm_c); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_root_css, NULL, &device_param->d_root_css_buf); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_markov_css, NULL, &device_param->d_markov_css_buf); if (CL_rc == -1) return -1; } if (size_esalts) { - CL_err = hc_clCreateBuffer (opencl_ctx->ocl, device_param->context, CL_MEM_READ_ONLY, size_esalts, NULL, &device_param->d_esalt_bufs); + CL_rc = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_esalts, NULL, &device_param->d_esalt_bufs); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateBuffer(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_esalt_bufs, CL_TRUE, 0, size_esalts, hashes->esalts_buf, 0, NULL, NULL); - CL_err = hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_esalt_bufs, CL_TRUE, 0, size_esalts, hashes->esalts_buf, 0, NULL, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } /** * main host data */ - pw_t *pws_buf = (pw_t *) mymalloc (size_pws); + pw_t *pws_buf = (pw_t *) hcmalloc (hashcat_ctx, size_pws); VERIFY_PTR (pws_buf); device_param->pws_buf = pws_buf; - comb_t *combs_buf = (comb_t *) mycalloc (KERNEL_COMBS, sizeof (comb_t)); + comb_t *combs_buf = (comb_t *) hccalloc (hashcat_ctx, KERNEL_COMBS, sizeof (comb_t)); VERIFY_PTR (combs_buf); device_param->combs_buf = combs_buf; - void *hooks_buf = mymalloc (size_hooks); + void *hooks_buf = hcmalloc (hashcat_ctx, size_hooks); VERIFY_PTR (hooks_buf); device_param->hooks_buf = hooks_buf; @@ -4051,71 +4189,41 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) { snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_s%02d", hashconfig->kern_type, 4); - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel1); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel1); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_s%02d", hashconfig->kern_type, 8); - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel2); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel2); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_s%02d", hashconfig->kern_type, 16); - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel3); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel3); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } else { snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_m%02d", hashconfig->kern_type, 4); - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel1); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel1); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_m%02d", hashconfig->kern_type, 8); - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel2); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel2); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_m%02d", hashconfig->kern_type, 16); - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel3); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel3); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } if (user_options->attack_mode == ATTACK_MODE_BF) @@ -4124,23 +4232,13 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) { snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_tm", hashconfig->kern_type); - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel_tm); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel_tm); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + CL_rc = hc_clGetKernelWorkGroupInfo (hashcat_ctx, device_param->kernel_tm, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - CL_err = hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel_tm, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } } } @@ -4148,236 +4246,122 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) { snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_init", hashconfig->kern_type); - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel1); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel1); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_loop", hashconfig->kern_type); - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel2); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel2); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_comp", hashconfig->kern_type); - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel3); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel3); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; if (hashconfig->opts_type & OPTS_TYPE_HOOK12) { snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_hook12", hashconfig->kern_type); - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel12); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel12); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + CL_rc = hc_clGetKernelWorkGroupInfo (hashcat_ctx, device_param->kernel12, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - CL_err = hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel12, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } if (hashconfig->opts_type & OPTS_TYPE_HOOK23) { snprintf (kernel_name, sizeof (kernel_name) - 1, "m%05d_hook23", hashconfig->kern_type); - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, kernel_name, &device_param->kernel23); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel23); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + CL_rc = hc_clGetKernelWorkGroupInfo (hashcat_ctx, device_param->kernel23, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - CL_err = hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel23, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } } - CL_err |= hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel1, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - CL_err |= hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel2, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - CL_err |= hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel3, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_rc = hc_clGetKernelWorkGroupInfo (hashcat_ctx, device_param->kernel1, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); if (CL_rc == -1) return -1; + CL_rc = hc_clGetKernelWorkGroupInfo (hashcat_ctx, device_param->kernel2, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); if (CL_rc == -1) return -1; + CL_rc = hc_clGetKernelWorkGroupInfo (hashcat_ctx, device_param->kernel3, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); if (CL_rc == -1) return -1; for (u32 i = 0; i <= 23; i++) { - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel1, i, sizeof (cl_mem), device_param->kernel_params[i]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel2, i, sizeof (cl_mem), device_param->kernel_params[i]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel3, i, sizeof (cl_mem), device_param->kernel_params[i]); + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel1, i, sizeof (cl_mem), device_param->kernel_params[i]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel2, i, sizeof (cl_mem), device_param->kernel_params[i]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel3, i, sizeof (cl_mem), device_param->kernel_params[i]); if (CL_rc == -1) return -1; - if (hashconfig->opts_type & OPTS_TYPE_HOOK12) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel12, i, sizeof (cl_mem), device_param->kernel_params[i]); - if (hashconfig->opts_type & OPTS_TYPE_HOOK23) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel23, i, sizeof (cl_mem), device_param->kernel_params[i]); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (hashconfig->opts_type & OPTS_TYPE_HOOK12) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel12, i, sizeof (cl_mem), device_param->kernel_params[i]); if (CL_rc == -1) return -1; } + if (hashconfig->opts_type & OPTS_TYPE_HOOK23) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel23, i, sizeof (cl_mem), device_param->kernel_params[i]); if (CL_rc == -1) return -1; } } for (u32 i = 24; i <= 34; i++) { - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel1, i, sizeof (cl_uint), device_param->kernel_params[i]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel2, i, sizeof (cl_uint), device_param->kernel_params[i]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel3, i, sizeof (cl_uint), device_param->kernel_params[i]); + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel1, i, sizeof (cl_uint), device_param->kernel_params[i]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel2, i, sizeof (cl_uint), device_param->kernel_params[i]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel3, i, sizeof (cl_uint), device_param->kernel_params[i]); if (CL_rc == -1) return -1; - if (hashconfig->opts_type & OPTS_TYPE_HOOK12) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel12, i, sizeof (cl_uint), device_param->kernel_params[i]); - if (hashconfig->opts_type & OPTS_TYPE_HOOK23) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel23, i, sizeof (cl_uint), device_param->kernel_params[i]); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (hashconfig->opts_type & OPTS_TYPE_HOOK12) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel12, i, sizeof (cl_uint), device_param->kernel_params[i]); if (CL_rc == -1) return -1; } + if (hashconfig->opts_type & OPTS_TYPE_HOOK23) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel23, i, sizeof (cl_uint), device_param->kernel_params[i]); if (CL_rc == -1) return -1; } } // GPU memset - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, "gpu_memset", &device_param->kernel_memset); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program, "gpu_memset", &device_param->kernel_memset); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + CL_rc = hc_clGetKernelWorkGroupInfo (hashcat_ctx, device_param->kernel_memset, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - CL_err = hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel_memset, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); + if (CL_rc == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_memset, 0, sizeof (cl_mem), device_param->kernel_params_memset[0]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_memset, 1, sizeof (cl_uint), device_param->kernel_params_memset[1]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_memset, 2, sizeof (cl_uint), device_param->kernel_params_memset[2]); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_memset, 0, sizeof (cl_mem), device_param->kernel_params_memset[0]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_memset, 1, sizeof (cl_uint), device_param->kernel_params_memset[1]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_memset, 2, sizeof (cl_uint), device_param->kernel_params_memset[2]); if (CL_rc == -1) return -1; // MP start if (user_options->attack_mode == ATTACK_MODE_BF) { - CL_err |= hc_clCreateKernel (opencl_ctx->ocl, device_param->program_mp, "l_markov", &device_param->kernel_mp_l); - CL_err |= hc_clCreateKernel (opencl_ctx->ocl, device_param->program_mp, "r_markov", &device_param->kernel_mp_r); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program_mp, "l_markov", &device_param->kernel_mp_l); if (CL_rc == -1) return -1; + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program_mp, "r_markov", &device_param->kernel_mp_r); if (CL_rc == -1) return -1; - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - CL_err |= hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel_mp_l, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - CL_err |= hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel_mp_r, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_rc = hc_clGetKernelWorkGroupInfo (hashcat_ctx, device_param->kernel_mp_l, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); if (CL_rc == -1) return -1; + CL_rc = hc_clGetKernelWorkGroupInfo (hashcat_ctx, device_param->kernel_mp_r, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); if (CL_rc == -1) return -1; if (hashconfig->opts_type & OPTS_TYPE_PT_BITSLICE) { - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_tm, 0, sizeof (cl_mem), device_param->kernel_params_tm[0]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_tm, 1, sizeof (cl_mem), device_param->kernel_params_tm[1]); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_tm, 0, sizeof (cl_mem), device_param->kernel_params_tm[0]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_tm, 1, sizeof (cl_mem), device_param->kernel_params_tm[1]); if (CL_rc == -1) return -1; } } else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) { - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program_mp, "C_markov", &device_param->kernel_mp); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program_mp, "C_markov", &device_param->kernel_mp); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + CL_rc = hc_clGetKernelWorkGroupInfo (hashcat_ctx, device_param->kernel_mp, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - CL_err = hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel_mp, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) { - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program_mp, "C_markov", &device_param->kernel_mp); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program_mp, "C_markov", &device_param->kernel_mp); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + CL_rc = hc_clGetKernelWorkGroupInfo (hashcat_ctx, device_param->kernel_mp, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - CL_err = hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel_mp, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL) @@ -4386,23 +4370,13 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) } else { - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program_amp, "amp", &device_param->kernel_amp); + CL_rc = hc_clCreateKernel (hashcat_ctx, device_param->program_amp, "amp", &device_param->kernel_amp); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); + if (CL_rc == -1) return -1; - return -1; - } + CL_rc = hc_clGetKernelWorkGroupInfo (hashcat_ctx, device_param->kernel_amp, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - CL_err = hc_clGetKernelWorkGroupInfo (opencl_ctx->ocl, device_param->kernel_amp, device_param->device, CL_KERNEL_WORK_GROUP_SIZE, sizeof (size_t), &kernel_wgs_tmp, NULL); kernel_threads = MIN (kernel_threads, kernel_wgs_tmp); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL) @@ -4413,26 +4387,16 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) { for (u32 i = 0; i < 5; i++) { - CL_err = hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_amp, i, sizeof (cl_mem), device_param->kernel_params_amp[i]); + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_amp, i, sizeof (cl_mem), device_param->kernel_params_amp[i]); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } for (u32 i = 5; i < 7; i++) { - CL_err = hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_amp, i, sizeof (cl_uint), device_param->kernel_params_amp[i]); + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_amp, i, sizeof (cl_uint), device_param->kernel_params_amp[i]); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } } @@ -4443,12 +4407,12 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) // zero some data buffers - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_pws_buf, size_pws); - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_pws_amp_buf, size_pws); - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_tmps, size_tmps); - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_hooks, size_hooks); - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_plain_bufs, size_plains); - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_result, size_results); + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_pws_buf, size_pws); if (CL_rc == -1) return -1; + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_pws_amp_buf, size_pws); if (CL_rc == -1) return -1; + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_tmps, size_tmps); if (CL_rc == -1) return -1; + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_hooks, size_hooks); if (CL_rc == -1) return -1; + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_plain_bufs, size_plains); if (CL_rc == -1) return -1; + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_result, size_results); if (CL_rc == -1) return -1; /** * special buffers @@ -4456,22 +4420,22 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) { - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_rules_c, size_rules_c); + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_rules_c, size_rules_c); } else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) { - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_combs, size_combs); - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_combs_c, size_combs); - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_root_css_buf, size_root_css); - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_markov_css_buf, size_markov_css); + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_combs, size_combs); if (CL_rc == -1) return -1; + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_combs_c, size_combs); if (CL_rc == -1) return -1; + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_root_css_buf, size_root_css); if (CL_rc == -1) return -1; + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_markov_css_buf, size_markov_css); if (CL_rc == -1) return -1; } else if (user_options_extra->attack_kern == ATTACK_KERN_BF) { - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_bfs, size_bfs); - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_bfs_c, size_bfs); - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_tm_c, size_tm); - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_root_css_buf, size_root_css); - run_kernel_bzero (hashcat_ctx, device_param, device_param->d_markov_css_buf, size_markov_css); + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_bfs, size_bfs); if (CL_rc == -1) return -1; + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_bfs_c, size_bfs); if (CL_rc == -1) return -1; + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_tm_c, size_tm); if (CL_rc == -1) return -1; + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_root_css_buf, size_root_css); if (CL_rc == -1) return -1; + CL_rc = run_kernel_bzero (hashcat_ctx, device_param, device_param->d_markov_css_buf, size_markov_css); if (CL_rc == -1) return -1; } if ((user_options->attack_mode == ATTACK_MODE_HYBRID1) || (user_options->attack_mode == ATTACK_MODE_HYBRID2)) @@ -4498,14 +4462,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) device_param->kernel_params_mp_buf32[7] = 0; } - for (u32 i = 0; i < 3; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp[i]); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + for (u32 i = 0; i < 3; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_mp, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp[i]); if (CL_rc == -1) return -1; } } else if (user_options->attack_mode == ATTACK_MODE_BF) { @@ -4522,18 +4479,15 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS14) device_param->kernel_params_mp_l_buf32[7] = 1; if (hashconfig->opts_type & OPTS_TYPE_PT_ADDBITS15) device_param->kernel_params_mp_l_buf32[8] = 1; - for (u32 i = 0; i < 3; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_l, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp_l[i]); - for (u32 i = 0; i < 3; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_r, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp_r[i]); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + for (u32 i = 0; i < 3; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_mp_l, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp_l[i]); if (CL_rc == -1) return -1; } + for (u32 i = 0; i < 3; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_mp_r, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp_r[i]); if (CL_rc == -1) return -1; } } + + hardware_power_all += device_param->hardware_power; } + if (hardware_power_all == 0) return -1; + opencl_ctx->hardware_power_all = hardware_power_all; return 0; @@ -4551,68 +4505,61 @@ void opencl_session_destroy (hashcat_ctx_t *hashcat_ctx) if (device_param->skipped) continue; - cl_int CL_err = CL_SUCCESS; + hcfree (device_param->pws_buf); + hcfree (device_param->combs_buf); + hcfree (device_param->hooks_buf); - myfree (device_param->pws_buf); - myfree (device_param->combs_buf); - myfree (device_param->hooks_buf); + if (device_param->d_pws_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->d_pws_buf); + if (device_param->d_pws_amp_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->d_pws_amp_buf); + if (device_param->d_rules) hc_clReleaseMemObject (hashcat_ctx, device_param->d_rules); + if (device_param->d_rules_c) hc_clReleaseMemObject (hashcat_ctx, device_param->d_rules_c); + if (device_param->d_combs) hc_clReleaseMemObject (hashcat_ctx, device_param->d_combs); + if (device_param->d_combs_c) hc_clReleaseMemObject (hashcat_ctx, device_param->d_combs_c); + if (device_param->d_bfs) hc_clReleaseMemObject (hashcat_ctx, device_param->d_bfs); + if (device_param->d_bfs_c) hc_clReleaseMemObject (hashcat_ctx, device_param->d_bfs_c); + if (device_param->d_bitmap_s1_a) hc_clReleaseMemObject (hashcat_ctx, device_param->d_bitmap_s1_a); + if (device_param->d_bitmap_s1_b) hc_clReleaseMemObject (hashcat_ctx, device_param->d_bitmap_s1_b); + if (device_param->d_bitmap_s1_c) hc_clReleaseMemObject (hashcat_ctx, device_param->d_bitmap_s1_c); + if (device_param->d_bitmap_s1_d) hc_clReleaseMemObject (hashcat_ctx, device_param->d_bitmap_s1_d); + if (device_param->d_bitmap_s2_a) hc_clReleaseMemObject (hashcat_ctx, device_param->d_bitmap_s2_a); + if (device_param->d_bitmap_s2_b) hc_clReleaseMemObject (hashcat_ctx, device_param->d_bitmap_s2_b); + if (device_param->d_bitmap_s2_c) hc_clReleaseMemObject (hashcat_ctx, device_param->d_bitmap_s2_c); + if (device_param->d_bitmap_s2_d) hc_clReleaseMemObject (hashcat_ctx, device_param->d_bitmap_s2_d); + if (device_param->d_plain_bufs) hc_clReleaseMemObject (hashcat_ctx, device_param->d_plain_bufs); + if (device_param->d_digests_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->d_digests_buf); + if (device_param->d_digests_shown) hc_clReleaseMemObject (hashcat_ctx, device_param->d_digests_shown); + if (device_param->d_salt_bufs) hc_clReleaseMemObject (hashcat_ctx, device_param->d_salt_bufs); + if (device_param->d_esalt_bufs) hc_clReleaseMemObject (hashcat_ctx, device_param->d_esalt_bufs); + if (device_param->d_tmps) hc_clReleaseMemObject (hashcat_ctx, device_param->d_tmps); + if (device_param->d_hooks) hc_clReleaseMemObject (hashcat_ctx, device_param->d_hooks); + if (device_param->d_result) hc_clReleaseMemObject (hashcat_ctx, device_param->d_result); + if (device_param->d_scryptV0_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->d_scryptV0_buf); + if (device_param->d_scryptV1_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->d_scryptV1_buf); + if (device_param->d_scryptV2_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->d_scryptV2_buf); + if (device_param->d_scryptV3_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->d_scryptV3_buf); + if (device_param->d_root_css_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->d_root_css_buf); + if (device_param->d_markov_css_buf) hc_clReleaseMemObject (hashcat_ctx, device_param->d_markov_css_buf); + if (device_param->d_tm_c) hc_clReleaseMemObject (hashcat_ctx, device_param->d_tm_c); - if (device_param->d_pws_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_pws_buf); - if (device_param->d_pws_amp_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_pws_amp_buf); - if (device_param->d_rules) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_rules); - if (device_param->d_rules_c) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_rules_c); - if (device_param->d_combs) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_combs); - if (device_param->d_combs_c) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_combs_c); - if (device_param->d_bfs) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bfs); - if (device_param->d_bfs_c) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bfs_c); - if (device_param->d_bitmap_s1_a) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bitmap_s1_a); - if (device_param->d_bitmap_s1_b) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bitmap_s1_b); - if (device_param->d_bitmap_s1_c) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bitmap_s1_c); - if (device_param->d_bitmap_s1_d) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bitmap_s1_d); - if (device_param->d_bitmap_s2_a) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bitmap_s2_a); - if (device_param->d_bitmap_s2_b) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bitmap_s2_b); - if (device_param->d_bitmap_s2_c) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bitmap_s2_c); - if (device_param->d_bitmap_s2_d) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_bitmap_s2_d); - if (device_param->d_plain_bufs) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_plain_bufs); - if (device_param->d_digests_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_digests_buf); - if (device_param->d_digests_shown) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_digests_shown); - if (device_param->d_salt_bufs) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_salt_bufs); - if (device_param->d_esalt_bufs) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_esalt_bufs); - if (device_param->d_tmps) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_tmps); - if (device_param->d_hooks) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_hooks); - if (device_param->d_result) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_result); - if (device_param->d_scryptV0_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_scryptV0_buf); - if (device_param->d_scryptV1_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_scryptV1_buf); - if (device_param->d_scryptV2_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_scryptV2_buf); - if (device_param->d_scryptV3_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_scryptV3_buf); - if (device_param->d_root_css_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_root_css_buf); - if (device_param->d_markov_css_buf) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_markov_css_buf); - if (device_param->d_tm_c) CL_err |= hc_clReleaseMemObject (opencl_ctx->ocl, device_param->d_tm_c); + if (device_param->kernel1) hc_clReleaseKernel (hashcat_ctx, device_param->kernel1); + if (device_param->kernel12) hc_clReleaseKernel (hashcat_ctx, device_param->kernel12); + if (device_param->kernel2) hc_clReleaseKernel (hashcat_ctx, device_param->kernel2); + if (device_param->kernel23) hc_clReleaseKernel (hashcat_ctx, device_param->kernel23); + if (device_param->kernel3) hc_clReleaseKernel (hashcat_ctx, device_param->kernel3); + if (device_param->kernel_mp) hc_clReleaseKernel (hashcat_ctx, device_param->kernel_mp); + if (device_param->kernel_mp_l) hc_clReleaseKernel (hashcat_ctx, device_param->kernel_mp_l); + if (device_param->kernel_mp_r) hc_clReleaseKernel (hashcat_ctx, device_param->kernel_mp_r); + if (device_param->kernel_tm) hc_clReleaseKernel (hashcat_ctx, device_param->kernel_tm); + if (device_param->kernel_amp) hc_clReleaseKernel (hashcat_ctx, device_param->kernel_amp); + if (device_param->kernel_memset) hc_clReleaseKernel (hashcat_ctx, device_param->kernel_memset); - if (device_param->kernel1) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel1); - if (device_param->kernel12) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel12); - if (device_param->kernel2) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel2); - if (device_param->kernel23) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel23); - if (device_param->kernel3) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel3); - if (device_param->kernel_mp) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel_mp); - if (device_param->kernel_mp_l) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel_mp_l); - if (device_param->kernel_mp_r) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel_mp_r); - if (device_param->kernel_tm) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel_tm); - if (device_param->kernel_amp) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel_amp); - if (device_param->kernel_memset) CL_err |= hc_clReleaseKernel (opencl_ctx->ocl, device_param->kernel_memset); + if (device_param->program) hc_clReleaseProgram (hashcat_ctx, device_param->program); + if (device_param->program_mp) hc_clReleaseProgram (hashcat_ctx, device_param->program_mp); + if (device_param->program_amp) hc_clReleaseProgram (hashcat_ctx, device_param->program_amp); - if (device_param->program) CL_err |= hc_clReleaseProgram (opencl_ctx->ocl, device_param->program); - if (device_param->program_mp) CL_err |= hc_clReleaseProgram (opencl_ctx->ocl, device_param->program_mp); - if (device_param->program_amp) CL_err |= hc_clReleaseProgram (opencl_ctx->ocl, device_param->program_amp); + if (device_param->command_queue) hc_clReleaseCommandQueue (hashcat_ctx, device_param->command_queue); - if (device_param->command_queue) CL_err |= hc_clReleaseCommandQueue (opencl_ctx->ocl, device_param->command_queue); - - if (device_param->context) CL_err |= hc_clReleaseContext (opencl_ctx->ocl, device_param->context); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: hc_clReleaseContext(): %s\n", val2cstr_cl (CL_err)); - } + if (device_param->context) hc_clReleaseContext (hashcat_ctx, device_param->context); device_param->pws_buf = NULL; device_param->combs_buf = NULL; @@ -4682,12 +4629,12 @@ void opencl_session_reset (hashcat_ctx_t *hashcat_ctx) device_param->speed_pos = 0; - memset (device_param->speed_cnt, 0, SPEED_CACHE * sizeof (u64)); - memset (device_param->speed_ms, 0, SPEED_CACHE * sizeof (double)); + memset (device_param->speed_cnt, 0, SPEED_CACHE * sizeof (u64)); + memset (device_param->speed_msec, 0, SPEED_CACHE * sizeof (double)); device_param->exec_pos = 0; - memset (device_param->exec_ms, 0, EXEC_CACHE * sizeof (double)); + memset (device_param->exec_msec, 0, EXEC_CACHE * sizeof (double)); device_param->outerloop_pos = 0; device_param->outerloop_left = 0; @@ -4726,21 +4673,14 @@ int opencl_session_update_combinator (hashcat_ctx_t *hashcat_ctx) device_param->kernel_params_buf32[33] = combinator_ctx->combs_mode; - cl_int CL_err = CL_SUCCESS; + int CL_rc; - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel1, 33, sizeof (cl_uint), device_param->kernel_params[33]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel2, 33, sizeof (cl_uint), device_param->kernel_params[33]); - CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel3, 33, sizeof (cl_uint), device_param->kernel_params[33]); + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel1, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel2, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1; + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel3, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1; - if (hashconfig->opts_type & OPTS_TYPE_HOOK12) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel12, 33, sizeof (cl_uint), device_param->kernel_params[33]); - if (hashconfig->opts_type & OPTS_TYPE_HOOK23) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel23, 33, sizeof (cl_uint), device_param->kernel_params[33]); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (hashconfig->opts_type & OPTS_TYPE_HOOK12) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel12, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1; } + if (hashconfig->opts_type & OPTS_TYPE_HOOK23) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel23, 33, sizeof (cl_uint), device_param->kernel_params[33]); if (CL_rc == -1) return -1; } // kernel_params_amp @@ -4748,14 +4688,9 @@ int opencl_session_update_combinator (hashcat_ctx_t *hashcat_ctx) if (hashconfig->attack_exec == ATTACK_EXEC_OUTSIDE_KERNEL) { - CL_err = hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_amp, 5, sizeof (cl_uint), device_param->kernel_params_amp[5]); + CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_amp, 5, sizeof (cl_uint), device_param->kernel_params_amp[5]); - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_rc == -1) return -1; } } @@ -4778,27 +4713,13 @@ int opencl_session_update_mp (hashcat_ctx_t *hashcat_ctx) device_param->kernel_params_mp_buf64[3] = 0; device_param->kernel_params_mp_buf32[4] = mask_ctx->css_cnt; - cl_int CL_err = CL_SUCCESS; + int CL_rc = CL_SUCCESS; - for (u32 i = 3; i < 4; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp, i, sizeof (cl_ulong), (void *) device_param->kernel_params_mp[i]); - for (u32 i = 4; i < 8; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp[i]); + for (u32 i = 3; i < 4; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_mp, i, sizeof (cl_ulong), (void *) device_param->kernel_params_mp[i]); if (CL_rc == -1) return -1; } + for (u32 i = 4; i < 8; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_mp, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp[i]); if (CL_rc == -1) return -1; } - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_root_css_buf, CL_TRUE, 0, device_param->size_root_css, mask_ctx->root_css_buf, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_markov_css_buf, CL_TRUE, 0, device_param->size_markov_css, mask_ctx->markov_css_buf, 0, NULL, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_root_css_buf, CL_TRUE, 0, device_param->size_root_css, mask_ctx->root_css_buf, 0, NULL, NULL); if (CL_rc == -1) return -1; + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_markov_css_buf, CL_TRUE, 0, device_param->size_markov_css, mask_ctx->markov_css_buf, 0, NULL, NULL); if (CL_rc == -1) return -1; } return 0; @@ -4824,30 +4745,16 @@ int opencl_session_update_mp_rl (hashcat_ctx_t *hashcat_ctx, const u32 css_cnt_l device_param->kernel_params_mp_r_buf64[3] = 0; device_param->kernel_params_mp_r_buf32[4] = css_cnt_r; - cl_int CL_err = CL_SUCCESS; + int CL_rc = CL_SUCCESS; - for (u32 i = 3; i < 4; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_l, i, sizeof (cl_ulong), (void *) device_param->kernel_params_mp_l[i]); - for (u32 i = 4; i < 9; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_l, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp_l[i]); + for (u32 i = 3; i < 4; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_mp_l, i, sizeof (cl_ulong), (void *) device_param->kernel_params_mp_l[i]); if (CL_rc == -1) return -1; } + for (u32 i = 4; i < 9; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_mp_l, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp_l[i]); if (CL_rc == -1) return -1; } - for (u32 i = 3; i < 4; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_r, i, sizeof (cl_ulong), (void *) device_param->kernel_params_mp_r[i]); - for (u32 i = 4; i < 8; i++) CL_err |= hc_clSetKernelArg (opencl_ctx->ocl, device_param->kernel_mp_r, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp_r[i]); + for (u32 i = 3; i < 4; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_mp_r, i, sizeof (cl_ulong), (void *) device_param->kernel_params_mp_r[i]); if (CL_rc == -1) return -1; } + for (u32 i = 4; i < 8; i++) { CL_rc = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_mp_r, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp_r[i]); if (CL_rc == -1) return -1; } - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_root_css_buf, CL_TRUE, 0, device_param->size_root_css, mask_ctx->root_css_buf, 0, NULL, NULL); - CL_err |= hc_clEnqueueWriteBuffer (opencl_ctx->ocl, device_param->command_queue, device_param->d_markov_css_buf, CL_TRUE, 0, device_param->size_markov_css, mask_ctx->markov_css_buf, 0, NULL, NULL); - - if (CL_err != CL_SUCCESS) - { - log_error ("ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_root_css_buf, CL_TRUE, 0, device_param->size_root_css, mask_ctx->root_css_buf, 0, NULL, NULL); if (CL_rc == -1) return -1; + CL_rc = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_markov_css_buf, CL_TRUE, 0, device_param->size_markov_css, mask_ctx->markov_css_buf, 0, NULL, NULL); if (CL_rc == -1) return -1; } return 0; diff --git a/src/outfile.c b/src/outfile.c index 02df40c99..4a8549bed 100644 --- a/src/outfile.c +++ b/src/outfile.c @@ -6,7 +6,8 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" +#include "convert.h" #include "interface.h" #include "hashes.h" #include "mpsp.h" @@ -15,7 +16,7 @@ #include "opencl.h" #include "outfile.h" -void build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u32 *plain_buf, int *out_len) +int build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u32 *plain_buf, int *out_len) { combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; hashconfig_t *hashconfig = hashcat_ctx->hashconfig; @@ -35,7 +36,9 @@ void build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, p { pw_t pw; - gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + + if (rc == -1) return -1; for (int i = 0; i < 16; i++) { @@ -54,7 +57,9 @@ void build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, p { pw_t pw; - gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + + if (rc == -1) return -1; for (int i = 0; i < 16; i++) { @@ -104,7 +109,9 @@ void build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, p { pw_t pw; - gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + + if (rc == -1) return -1; for (int i = 0; i < 16; i++) { @@ -131,7 +138,9 @@ void build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, p { pw_t pw; - gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + + if (rc == -1) return -1; for (int i = 0; i < 16; i++) { @@ -182,9 +191,11 @@ void build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, p } *out_len = plain_len; + + return 0; } -void build_crackpos (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u64 *out_pos) +int build_crackpos (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u64 *out_pos) { combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; @@ -216,9 +227,11 @@ void build_crackpos (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param } *out_pos = crackpos; + + return 0; } -void build_debugdata (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u8 *debug_rule_buf, int *debug_rule_len, u8 *debug_plain_ptr, int *debug_plain_len) +int build_debugdata (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u8 *debug_rule_buf, int *debug_rule_len, u8 *debug_plain_ptr, int *debug_plain_len) { debugfile_ctx_t *debugfile_ctx = hashcat_ctx->debugfile_ctx; straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; @@ -227,15 +240,17 @@ void build_debugdata (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_para const u32 gidvid = plain->gidvid; const u32 il_pos = plain->il_pos; - if (user_options->attack_mode != ATTACK_MODE_STRAIGHT) return; + if (user_options->attack_mode != ATTACK_MODE_STRAIGHT) return 0; const u32 debug_mode = debugfile_ctx->mode; - if (debug_mode == 0) return; + if (debug_mode == 0) return 0; pw_t pw; - gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + + if (rc == -1) return -1; int plain_len = (int) pw.pw_len; @@ -254,49 +269,8 @@ void build_debugdata (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_para *debug_plain_len = plain_len; } -} -static void outfile_format_plain (hashcat_ctx_t *hashcat_ctx, const unsigned char *plain_ptr, const u32 plain_len) -{ - outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; - - bool needs_hexify = false; - - if (outfile_ctx->outfile_autohex == true) - { - for (u32 i = 0; i < plain_len; i++) - { - if (plain_ptr[i] < 0x20) - { - needs_hexify = true; - - break; - } - - if (plain_ptr[i] > 0x7f) - { - needs_hexify = true; - - break; - } - } - } - - if (needs_hexify == true) - { - fprintf (outfile_ctx->fp, "$HEX["); - - for (u32 i = 0; i < plain_len; i++) - { - fprintf (outfile_ctx->fp, "%02x", plain_ptr[i]); - } - - fprintf (outfile_ctx->fp, "]"); - } - else - { - fwrite (plain_ptr, plain_len, 1, outfile_ctx->fp); - } + return 0; } int outfile_init (hashcat_ctx_t *hashcat_ctx) @@ -304,17 +278,8 @@ int outfile_init (hashcat_ctx_t *hashcat_ctx) outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; user_options_t *user_options = hashcat_ctx->user_options; - if (user_options->outfile == NULL) - { - outfile_ctx->fp = stdout; - outfile_ctx->filename = NULL; - } - else - { - outfile_ctx->fp = NULL; - outfile_ctx->filename = user_options->outfile; - } - + outfile_ctx->fp = NULL; + outfile_ctx->filename = user_options->outfile; outfile_ctx->outfile_format = user_options->outfile_format; outfile_ctx->outfile_autohex = user_options->outfile_autohex; @@ -342,7 +307,7 @@ int outfile_write_open (hashcat_ctx_t *hashcat_ctx) if (outfile_ctx->fp == NULL) { - log_error ("ERROR: %s: %s", outfile_ctx->filename, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", outfile_ctx->filename, strerror (errno)); return -1; } @@ -354,48 +319,79 @@ void outfile_write_close (hashcat_ctx_t *hashcat_ctx) { outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; - if (outfile_ctx->fp == stdout) return; + if (outfile_ctx->fp == NULL) return; fclose (outfile_ctx->fp); } -void outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const unsigned char *plain_ptr, const u32 plain_len, const u64 crackpos, const unsigned char *username, const u32 user_len) +int outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const unsigned char *plain_ptr, const u32 plain_len, const u64 crackpos, const unsigned char *username, const u32 user_len, char tmp_buf[HCBUFSIZ_LARGE]) { - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; + const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + const outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; - if (outfile_ctx->outfile_format & OUTFILE_FMT_HASH) - { - fprintf (outfile_ctx->fp, "%s", out_buf); + int tmp_len = 0; - if (outfile_ctx->outfile_format & (OUTFILE_FMT_PLAIN | OUTFILE_FMT_HEXPLAIN | OUTFILE_FMT_CRACKPOS)) - { - fputc (hashconfig->separator, outfile_ctx->fp); - } - } - else if (user_len) + if (user_len > 0) { if (username != NULL) { - for (u32 i = 0; i < user_len; i++) - { - fprintf (outfile_ctx->fp, "%c", username[i]); - } + memcpy (tmp_buf + tmp_len, username, user_len); - if (outfile_ctx->outfile_format & (OUTFILE_FMT_PLAIN | OUTFILE_FMT_HEXPLAIN | OUTFILE_FMT_CRACKPOS)) + tmp_len += user_len; + + if (outfile_ctx->outfile_format & (OUTFILE_FMT_HASH | OUTFILE_FMT_PLAIN | OUTFILE_FMT_HEXPLAIN | OUTFILE_FMT_CRACKPOS)) { - fputc (hashconfig->separator, outfile_ctx->fp); + tmp_buf[tmp_len] = hashconfig->separator; + + tmp_len += 1; } } } + if (outfile_ctx->outfile_format & OUTFILE_FMT_HASH) + { + const size_t out_len = strlen (out_buf); + + memcpy (tmp_buf + tmp_len, out_buf, out_len); + + tmp_len += out_len; + + if (outfile_ctx->outfile_format & (OUTFILE_FMT_PLAIN | OUTFILE_FMT_HEXPLAIN | OUTFILE_FMT_CRACKPOS)) + { + tmp_buf[tmp_len] = hashconfig->separator; + + tmp_len += 1; + } + } + if (outfile_ctx->outfile_format & OUTFILE_FMT_PLAIN) { - outfile_format_plain (hashcat_ctx, plain_ptr, plain_len); + if (need_hexify (plain_ptr, plain_len) == true) + { + tmp_buf[tmp_len++] = '$'; + tmp_buf[tmp_len++] = 'H'; + tmp_buf[tmp_len++] = 'E'; + tmp_buf[tmp_len++] = 'X'; + tmp_buf[tmp_len++] = '['; + + exec_hexify ((const u8 *) plain_ptr, plain_len, (u8 *) tmp_buf + tmp_len); + + tmp_len += plain_len * 2; + + tmp_buf[tmp_len++] = ']'; + } + else + { + memcpy (tmp_buf + tmp_len, plain_ptr, plain_len); + + tmp_len += plain_len; + } if (outfile_ctx->outfile_format & (OUTFILE_FMT_HEXPLAIN | OUTFILE_FMT_CRACKPOS)) { - fputc (hashconfig->separator, outfile_ctx->fp); + tmp_buf[tmp_len] = hashconfig->separator; + + tmp_len += 1; } } @@ -403,21 +399,32 @@ void outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const unsig { for (u32 i = 0; i < plain_len; i++) { - fprintf (outfile_ctx->fp, "%02x", plain_ptr[i]); + exec_hexify ((const u8 *) plain_ptr, plain_len, (u8 *) tmp_buf + tmp_len); + + tmp_len += 2; } if (outfile_ctx->outfile_format & (OUTFILE_FMT_CRACKPOS)) { - fputc (hashconfig->separator, outfile_ctx->fp); + tmp_buf[tmp_len] = hashconfig->separator; + + tmp_len += 1; } } if (outfile_ctx->outfile_format & OUTFILE_FMT_CRACKPOS) { - fprintf (outfile_ctx->fp, "%" PRIu64, crackpos); + sprintf (tmp_buf + tmp_len, "%" PRIu64, crackpos); } - fputs (EOL, outfile_ctx->fp); + tmp_buf[tmp_len] = 0; + + if (outfile_ctx->fp) + { + fprintf (outfile_ctx->fp, "%s" EOL, tmp_buf); + } + + return tmp_len; } int outfile_and_hashfile (hashcat_ctx_t *hashcat_ctx) @@ -492,7 +499,7 @@ int outfile_and_hashfile (hashcat_ctx_t *hashcat_ctx) if (memcmp (&tmpstat_outfile, &tmpstat_hashfile, sizeof (hc_stat)) == 0) { - log_error ("ERROR: Hashfile and Outfile are not allowed to point to the same file"); + event_log_error (hashcat_ctx, "Hashfile and Outfile are not allowed to point to the same file"); return -1; } diff --git a/src/outfile_check.c b/src/outfile_check.c index bd0e655a2..cd8f1a37c 100644 --- a/src/outfile_check.c +++ b/src/outfile_check.c @@ -6,7 +6,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "outfile_check.h" #include "convert.h" @@ -16,7 +16,7 @@ #include "shared.h" #include "thread.h" -static void outfile_remove (hashcat_ctx_t *hashcat_ctx) +static int outfile_remove (hashcat_ctx_t *hashcat_ctx) { // some hash-dependent constants @@ -36,12 +36,12 @@ static void outfile_remove (hashcat_ctx_t *hashcat_ctx) u32 outfile_check_timer = user_options->outfile_check_timer; // buffers - hash_t hash_buf = { 0, 0, 0, 0, 0 }; + hash_t hash_buf = { 0, 0, 0, 0, 0, NULL, 0 }; - hash_buf.digest = mymalloc (dgst_size); + hash_buf.digest = hcmalloc (hashcat_ctx, dgst_size); VERIFY_PTR (hash_buf.digest); - if (is_salted) hash_buf.salt = (salt_t *) mymalloc (sizeof (salt_t)); - if (esalt_size) hash_buf.esalt = (void *) mymalloc (esalt_size); + if (is_salted) hash_buf.salt = (salt_t *) hcmalloc (hashcat_ctx, sizeof (salt_t)); VERIFY_PTR (hash_buf.salt); + if (esalt_size) hash_buf.esalt = (void *) hcmalloc (hashcat_ctx, esalt_size); VERIFY_PTR (hash_buf.esalt); u32 digest_buf[64] = { 0 }; @@ -75,7 +75,7 @@ static void outfile_remove (hashcat_ctx_t *hashcat_ctx) { if (outfile_check_stat.st_mtime > folder_mtime) { - char **out_files_new = scan_directory (root_directory); + char **out_files_new = scan_directory (hashcat_ctx, root_directory); int out_cnt_new = count_dictionaries (out_files_new); @@ -83,7 +83,7 @@ static void outfile_remove (hashcat_ctx_t *hashcat_ctx) if (out_cnt_new > 0) { - out_info_new = (outfile_data_t *) mycalloc (out_cnt_new, sizeof (outfile_data_t)); + out_info_new = (outfile_data_t *) hccalloc (hashcat_ctx, out_cnt_new, sizeof (outfile_data_t)); VERIFY_PTR (out_info_new); for (int i = 0; i < out_cnt_new; i++) { @@ -110,8 +110,8 @@ static void outfile_remove (hashcat_ctx_t *hashcat_ctx) } } - myfree (out_info); - myfree (out_files); + hcfree (out_info); + hcfree (out_files); out_files = out_files_new; out_cnt = out_cnt_new; @@ -146,7 +146,7 @@ static void outfile_remove (hashcat_ctx_t *hashcat_ctx) fseek (fp, out_info[j].seek, SEEK_SET); - char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE); + char *line_buf = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (line_buf); while (!feof (fp)) { @@ -263,7 +263,7 @@ static void outfile_remove (hashcat_ctx_t *hashcat_ctx) hashes->salts_done++; - if (hashes->salts_done == hashes->salts_cnt) mycracked (status_ctx); + if (hashes->salts_done == hashes->salts_cnt) mycracked (hashcat_ctx); } } } @@ -282,7 +282,7 @@ static void outfile_remove (hashcat_ctx_t *hashcat_ctx) if (status_ctx->devices_status == STATUS_CRACKED) break; } - myfree (line_buf); + hcfree (line_buf); out_info[j].seek = ftell (fp); @@ -298,22 +298,26 @@ static void outfile_remove (hashcat_ctx_t *hashcat_ctx) } } - myfree (hash_buf.esalt); + hcfree (hash_buf.esalt); - myfree (hash_buf.salt); + hcfree (hash_buf.salt); - myfree (hash_buf.digest); + hcfree (hash_buf.digest); - myfree (out_info); + hcfree (out_info); - myfree (out_files); + hcfree (out_files); + + return 0; } void *thread_outfile_remove (void *p) { hashcat_ctx_t *hashcat_ctx = (hashcat_ctx_t *) p; - outfile_remove (hashcat_ctx); + const int rc = outfile_remove (hashcat_ctx); + + if (rc == -1) return NULL; return NULL; } @@ -328,6 +332,7 @@ int outcheck_ctx_init (hashcat_ctx_t *hashcat_ctx) if (user_options->keyspace == true) return 0; if (user_options->benchmark == true) return 0; + if (user_options->speed_only == true) return 0; if (user_options->opencl_info == true) return 0; if (user_options->outfile_check_timer == 0) return 0; @@ -339,7 +344,7 @@ int outcheck_ctx_init (hashcat_ctx_t *hashcat_ctx) if (user_options->outfile_check_dir == NULL) { - outcheck_ctx->root_directory = (char *) mymalloc (HCBUFSIZ_TINY); + outcheck_ctx->root_directory = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (outcheck_ctx->root_directory); snprintf (outcheck_ctx->root_directory, HCBUFSIZ_TINY - 1, "%s/%s.%s", folder_config->session_dir, user_options->session, OUTFILES_DIR); } @@ -356,7 +361,7 @@ int outcheck_ctx_init (hashcat_ctx_t *hashcat_ctx) if (is_dir == 0) { - log_error ("ERROR: Directory specified in outfile-check '%s' is not a valid directory", outcheck_ctx->root_directory); + event_log_error (hashcat_ctx, "Directory specified in outfile-check '%s' is not a valid directory", outcheck_ctx->root_directory); return -1; } @@ -365,7 +370,7 @@ int outcheck_ctx_init (hashcat_ctx_t *hashcat_ctx) { if (hc_mkdir (outcheck_ctx->root_directory, 0700) == -1) { - log_error ("ERROR: %s: %s", outcheck_ctx->root_directory, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", outcheck_ctx->root_directory, strerror (errno)); return -1; } @@ -394,13 +399,13 @@ void outcheck_ctx_destroy (hashcat_ctx_t *hashcat_ctx) } else { - log_error ("ERROR: %s: %s", outcheck_ctx->root_directory, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", outcheck_ctx->root_directory, strerror (errno)); //return -1; } } - myfree (outcheck_ctx->root_directory); + hcfree (outcheck_ctx->root_directory); memset (outcheck_ctx, 0, sizeof (outcheck_ctx_t)); } diff --git a/src/potfile.c b/src/potfile.c index d98a1717d..b8dc4a150 100644 --- a/src/potfile.c +++ b/src/potfile.c @@ -7,7 +7,7 @@ #include "types.h" #include "convert.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "interface.h" #include "filehandling.h" #include "outfile.h" @@ -26,7 +26,7 @@ int sort_by_hash (const void *v1, const void *v2, void *v3); int sort_by_hash_no_salt (const void *v1, const void *v2, void *v3); // get rid of this later -int sort_by_pot (const void *v1, const void *v2, void *v3) +int sort_by_pot (const void *v1, const void *v2, MAYBE_UNUSED void *v3) { const pot_t *p1 = (const pot_t *) v1; const pot_t *p2 = (const pot_t *) v2; @@ -37,10 +37,8 @@ int sort_by_pot (const void *v1, const void *v2, void *v3) return sort_by_hash (h1, h2, v3); } -int sort_by_salt_buf (const void *v1, const void *v2, void *v3) +int sort_by_salt_buf (const void *v1, const void *v2, MAYBE_UNUSED void *v3) { - if (v3 == NULL) v3 = NULL; // make compiler happy - const pot_t *p1 = (const pot_t *) v1; const pot_t *p2 = (const pot_t *) v2; @@ -54,7 +52,7 @@ int sort_by_salt_buf (const void *v1, const void *v2, void *v3) while (n--) { - if (s1->salt_buf[n] > s2->salt_buf[n]) return ( 1); + if (s1->salt_buf[n] > s2->salt_buf[n]) return 1; if (s1->salt_buf[n] < s2->salt_buf[n]) return -1; } @@ -146,48 +144,6 @@ void *hc_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size return (NULL); } -static void potfile_format_plain (hashcat_ctx_t *hashcat_ctx, const unsigned char *plain_ptr, const u32 plain_len) -{ - potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; - - if (potfile_ctx->enabled == false) return; - - bool needs_hexify = false; - - for (u32 i = 0; i < plain_len; i++) - { - if (plain_ptr[i] < 0x20) - { - needs_hexify = true; - - break; - } - - if (plain_ptr[i] > 0x7f) - { - needs_hexify = true; - - break; - } - } - - if (needs_hexify == true) - { - fprintf (potfile_ctx->fp, "$HEX["); - - for (u32 i = 0; i < plain_len; i++) - { - fprintf (potfile_ctx->fp, "%02x", plain_ptr[i]); - } - - fprintf (potfile_ctx->fp, "]"); - } - else - { - fwrite (plain_ptr, plain_len, 1, potfile_ctx->fp); - } -} - int potfile_init (hashcat_ctx_t *hashcat_ctx) { folder_config_t *folder_config = hashcat_ctx->folder_config; @@ -200,6 +156,7 @@ int potfile_init (hashcat_ctx_t *hashcat_ctx) if (user_options->keyspace == true) return 0; if (user_options->opencl_info == true) return 0; if (user_options->stdout_flag == true) return 0; + if (user_options->speed_only == true) return 0; if (user_options->usage == true) return 0; if (user_options->version == true) return 0; if (user_options->potfile_disable == true) return 0; @@ -208,14 +165,14 @@ int potfile_init (hashcat_ctx_t *hashcat_ctx) if (user_options->potfile_path == NULL) { - potfile_ctx->filename = (char *) mymalloc (HCBUFSIZ_TINY); + potfile_ctx->filename = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (potfile_ctx->filename); potfile_ctx->fp = NULL; snprintf (potfile_ctx->filename, HCBUFSIZ_TINY - 1, "%s/hashcat.potfile", folder_config->profile_dir); } else { - potfile_ctx->filename = mystrdup (user_options->potfile_path); + potfile_ctx->filename = hcstrdup (hashcat_ctx, user_options->potfile_path); VERIFY_PTR (potfile_ctx->filename); potfile_ctx->fp = NULL; } @@ -225,11 +182,6 @@ int potfile_init (hashcat_ctx_t *hashcat_ctx) potfile_write_close (hashcat_ctx); - potfile_ctx->pot = NULL; - potfile_ctx->pot_cnt = 0; - potfile_ctx->pot_avail = 0; - potfile_ctx->pot_hashes_avail = 0; - return 0; } @@ -252,7 +204,7 @@ int potfile_read_open (hashcat_ctx_t *hashcat_ctx) if (potfile_ctx->fp == NULL) { - //log_error ("ERROR: %s: %s", potfile_ctx->filename, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", potfile_ctx->filename, strerror (errno)); return -1; } @@ -260,116 +212,6 @@ int potfile_read_open (hashcat_ctx_t *hashcat_ctx) return 0; } -void potfile_read_parse (hashcat_ctx_t *hashcat_ctx) -{ - potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - - if (potfile_ctx->enabled == false) return; - - if (potfile_ctx->fp == NULL) return; - - potfile_ctx->pot_avail = count_lines (potfile_ctx->fp); - - potfile_ctx->pot = (pot_t *) mycalloc (potfile_ctx->pot_avail, sizeof (pot_t)); - - rewind (potfile_ctx->fp); - - char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE); - - for (u32 line_num = 0; line_num < potfile_ctx->pot_avail; line_num++) - { - int line_len = fgetl (potfile_ctx->fp, line_buf); - - if (line_len == 0) continue; - - pot_t *pot_ptr = &potfile_ctx->pot[potfile_ctx->pot_cnt]; - - // we do not initialize all hashes_buf->digest etc at the beginning, since many lines may not be - // valid lines of this specific hash type (otherwise it would be more waste of memory than gain) - - if (potfile_ctx->pot_cnt == potfile_ctx->pot_hashes_avail) - { - potfile_hash_alloc (hashcat_ctx, INCR_POT); - } - - int parser_status; - - int iter = MAX_CUT_TRIES; - - hash_t *hashes_buf = &pot_ptr->hash; - - char *plain_buf = line_buf + line_len; - - int plain_len = 0; - - do - { - for (int i = line_len - 1; i; i--, plain_len++, plain_buf--, line_len--) - { - if (line_buf[i] == ':') - { - line_len--; - - break; - } - } - - if (hashconfig->hash_mode != 2500) - { - parser_status = hashconfig->parse_func (line_buf, line_len, hashes_buf, hashconfig); - } - else - { - int max_salt_size = sizeof (hashes_buf->salt->salt_buf); - - if (line_len > max_salt_size) - { - parser_status = PARSER_GLOBAL_LENGTH; - } - else - { - memset (&hashes_buf->salt->salt_buf, 0, max_salt_size); - - memcpy (&hashes_buf->salt->salt_buf, line_buf, line_len); - - hashes_buf->salt->salt_len = line_len; - - parser_status = PARSER_OK; - } - } - - // if NOT parsed without error, we add the ":" to the plain - - if (parser_status == PARSER_GLOBAL_LENGTH || parser_status == PARSER_HASH_LENGTH || parser_status == PARSER_SALT_LENGTH) - { - plain_len++; - plain_buf--; - } - - } while ((parser_status == PARSER_GLOBAL_LENGTH || parser_status == PARSER_HASH_LENGTH || parser_status == PARSER_SALT_LENGTH) && --iter); - - if (parser_status < PARSER_GLOBAL_ZERO) - { - // log_info ("WARNING: Potfile '%s' in line %u (%s): %s", potfile, line_num, line_buf, strparser (parser_status)); - - continue; - } - - if (plain_len >= HCBUFSIZ_TINY) continue; - - memcpy (pot_ptr->plain_buf, plain_buf, plain_len); - - pot_ptr->plain_len = plain_len; - - potfile_ctx->pot_cnt++; - } - - myfree (line_buf); - - hc_qsort_r (potfile_ctx->pot, potfile_ctx->pot_cnt, sizeof (pot_t), sort_by_pot, (void *) hashconfig); -} - void potfile_read_close (hashcat_ctx_t *hashcat_ctx) { potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; @@ -391,7 +233,7 @@ int potfile_write_open (hashcat_ctx_t *hashcat_ctx) if (potfile_ctx->fp == NULL) { - log_error ("ERROR: %s: %s", potfile_ctx->filename, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", potfile_ctx->filename, strerror (errno)); return -1; } @@ -414,352 +256,52 @@ void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, u8 * if (potfile_ctx->enabled == false) return; - FILE *fp = potfile_ctx->fp; + char tmp_buf[HCBUFSIZ_LARGE]; - fprintf (fp, "%s:", out_buf); + int tmp_len = 0; - potfile_format_plain (hashcat_ctx, plain_ptr, plain_len); - - fputc ('\n', fp); - - fflush (fp); -} - -void potfile_hash_alloc (hashcat_ctx_t *hashcat_ctx, const u32 num) -{ - potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - - if (potfile_ctx->enabled == false) return; - - u32 pos = 0; - - for (pos = 0; pos < num; pos++) + if (1) { - if ((potfile_ctx->pot_cnt + pos) >= potfile_ctx->pot_avail) break; + const size_t out_len = strlen (out_buf); - pot_t *tmp_pot = &potfile_ctx->pot[potfile_ctx->pot_cnt + pos]; + memcpy (tmp_buf + tmp_len, out_buf, out_len); - hash_t *tmp_hash = &tmp_pot->hash; + tmp_len += out_len; - tmp_hash->digest = mymalloc (hashconfig->dgst_size); + tmp_buf[tmp_len] = ':'; - if (hashconfig->is_salted) - { - tmp_hash->salt = (salt_t *) mymalloc (sizeof (salt_t)); - } - - if (hashconfig->esalt_size) - { - tmp_hash->esalt = mymalloc (hashconfig->esalt_size); - } - - potfile_ctx->pot_hashes_avail++; + tmp_len += 1; } -} -void potfile_hash_free (hashcat_ctx_t *hashcat_ctx) -{ - potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - - if (potfile_ctx->enabled == false) return; - - for (u32 i = 0; i < potfile_ctx->pot_cnt; i++) + if (1) { - pot_t *pot_ptr = &potfile_ctx->pot[i]; - - hash_t *hashes_buf = &pot_ptr->hash; - - myfree (hashes_buf->digest); - - if (hashconfig->is_salted) + if (need_hexify (plain_ptr, plain_len) == true) { - myfree (hashes_buf->salt); + tmp_buf[tmp_len++] = '$'; + tmp_buf[tmp_len++] = 'H'; + tmp_buf[tmp_len++] = 'E'; + tmp_buf[tmp_len++] = 'X'; + tmp_buf[tmp_len++] = '['; + + exec_hexify ((const u8 *) plain_ptr, plain_len, (u8 *) tmp_buf + tmp_len); + + tmp_len += plain_len * 2; + + tmp_buf[tmp_len++] = ']'; } - - if (hashconfig->esalt_size) + else { - myfree (hashes_buf->esalt); + memcpy (tmp_buf + tmp_len, plain_ptr, plain_len); + + tmp_len += plain_len; } } - myfree (potfile_ctx->pot); -} + tmp_buf[tmp_len] = 0; -void potfile_show_request (hashcat_ctx_t *hashcat_ctx, char *input_buf, int input_len, hash_t *hashes_buf, int (*sort_by_pot) (const void *, const void *, void *)) -{ - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; + fprintf (potfile_ctx->fp, "%s\n", tmp_buf); - if (potfile_ctx->enabled == false) return; - - pot_t pot_key; - - pot_key.hash.salt = hashes_buf->salt; - pot_key.hash.digest = hashes_buf->digest; - - pot_t *pot_ptr = (pot_t *) hc_bsearch_r (&pot_key, potfile_ctx->pot, potfile_ctx->pot_cnt, sizeof (pot_t), sort_by_pot, (void *) hashconfig); - - if (pot_ptr) - { - log_info_nn (""); - - input_buf[input_len] = 0; - - // user - unsigned char *username = NULL; - u32 user_len = 0; - - if (hashes_buf->hash_info) - { - user_t *user = hashes_buf->hash_info->user; - - if (user) - { - username = (unsigned char *) (user->user_name); - - user_len = user->user_len; - } - } - - // do output the line - - outfile_write (hashcat_ctx, input_buf, (const unsigned char *) pot_ptr->plain_buf, pot_ptr->plain_len, 0, username, user_len); - } -} - -void potfile_left_request (hashcat_ctx_t *hashcat_ctx, char *input_buf, int input_len, hash_t *hashes_buf, int (*sort_by_pot) (const void *, const void *, void *)) -{ - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; - - if (potfile_ctx->enabled == false) return; - - pot_t pot_key; - - memcpy (&pot_key.hash, hashes_buf, sizeof (hash_t)); - - pot_t *pot_ptr = (pot_t *) hc_bsearch_r (&pot_key, potfile_ctx->pot, potfile_ctx->pot_cnt, sizeof (pot_t), sort_by_pot, (void *) hashconfig); - - if (pot_ptr == NULL) - { - log_info_nn (""); - - input_buf[input_len] = 0; - - outfile_write (hashcat_ctx, input_buf, NULL, 0, 0, NULL, 0); - } -} - -void potfile_show_request_lm (hashcat_ctx_t *hashcat_ctx, char *input_buf, int input_len, hash_t *hash_left, hash_t *hash_right, int (*sort_by_pot) (const void *, const void *, void *)) -{ - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; - - if (potfile_ctx->enabled == false) return; - - // left - - pot_t pot_left_key; - - pot_left_key.hash.salt = hash_left->salt; - pot_left_key.hash.digest = hash_left->digest; - - pot_t *pot_left_ptr = (pot_t *) hc_bsearch_r (&pot_left_key, potfile_ctx->pot, potfile_ctx->pot_cnt, sizeof (pot_t), sort_by_pot, (void *) hashconfig); - - // right - - u32 weak_hash_found = 0; - - pot_t pot_right_key; - - pot_right_key.hash.salt = hash_right->salt; - pot_right_key.hash.digest = hash_right->digest; - - pot_t *pot_right_ptr = (pot_t *) hc_bsearch_r (&pot_right_key, potfile_ctx->pot, potfile_ctx->pot_cnt, sizeof (pot_t), sort_by_pot, (void *) hashconfig); - - if (pot_right_ptr == NULL) - { - // special case, if "weak hash" - - if (memcmp (hash_right->digest, LM_WEAK_HASH, 8) == 0) - { - weak_hash_found = 1; - - pot_right_ptr = (pot_t *) mycalloc (1, sizeof (pot_t)); - - // in theory this is not needed, but we are paranoia: - - memset (pot_right_ptr->plain_buf, 0, sizeof (pot_right_ptr->plain_buf)); - pot_right_ptr->plain_len = 0; - } - } - - if ((pot_left_ptr == NULL) && (pot_right_ptr == NULL)) - { - if (weak_hash_found == 1) myfree (pot_right_ptr); // this shouldn't happen at all: if weak_hash_found == 1, than pot_right_ptr is not NULL for sure - - return; - } - - // at least one half was found: - - log_info_nn (""); - - input_buf[input_len] = 0; - - // user - - unsigned char *username = NULL; - u32 user_len = 0; - - if (hash_left->hash_info) - { - user_t *user = hash_left->hash_info->user; - - if (user) - { - username = (unsigned char *) (user->user_name); - - user_len = user->user_len; - } - } - - // mask the part which was not found - - u32 left_part_masked = 0; - u32 right_part_masked = 0; - - u32 mask_plain_len = strlen (LM_MASKED_PLAIN); - - if (pot_left_ptr == NULL) - { - left_part_masked = 1; - - pot_left_ptr = (pot_t *) mycalloc (1, sizeof (pot_t)); - - memset (pot_left_ptr->plain_buf, 0, sizeof (pot_left_ptr->plain_buf)); - - memcpy (pot_left_ptr->plain_buf, LM_MASKED_PLAIN, mask_plain_len); - pot_left_ptr->plain_len = mask_plain_len; - } - - if (pot_right_ptr == NULL) - { - right_part_masked = 1; - - pot_right_ptr = (pot_t *) mycalloc (1, sizeof (pot_t)); - - memset (pot_right_ptr->plain_buf, 0, sizeof (pot_right_ptr->plain_buf)); - - memcpy (pot_right_ptr->plain_buf, LM_MASKED_PLAIN, mask_plain_len); - pot_right_ptr->plain_len = mask_plain_len; - } - - // create the pot_ptr out of pot_left_ptr and pot_right_ptr - - pot_t pot_ptr; - - pot_ptr.plain_len = pot_left_ptr->plain_len + pot_right_ptr->plain_len; - - memcpy (pot_ptr.plain_buf, pot_left_ptr->plain_buf, pot_left_ptr->plain_len); - - memcpy (pot_ptr.plain_buf + pot_left_ptr->plain_len, pot_right_ptr->plain_buf, pot_right_ptr->plain_len); - - // do output the line - - outfile_write (hashcat_ctx, input_buf, (unsigned char *) pot_ptr.plain_buf, pot_ptr.plain_len, 0, username, user_len); - - if (weak_hash_found == 1) myfree (pot_right_ptr); - - if (left_part_masked == 1) myfree (pot_left_ptr); - if (right_part_masked == 1) myfree (pot_right_ptr); -} - -void potfile_left_request_lm (hashcat_ctx_t *hashcat_ctx, char *input_buf, int input_len, hash_t *hash_left, hash_t *hash_right, int (*sort_by_pot) (const void *, const void *, void *)) -{ - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; - - if (potfile_ctx->enabled == false) return; - - // left - - pot_t pot_left_key; - - memcpy (&pot_left_key.hash, hash_left, sizeof (hash_t)); - - pot_t *pot_left_ptr = (pot_t *) hc_bsearch_r (&pot_left_key, potfile_ctx->pot, potfile_ctx->pot_cnt, sizeof (pot_t), sort_by_pot, (void *) hashconfig); - - // right - - pot_t pot_right_key; - - memcpy (&pot_right_key.hash, hash_right, sizeof (hash_t)); - - pot_t *pot_right_ptr = (pot_t *) hc_bsearch_r (&pot_right_key, potfile_ctx->pot, potfile_ctx->pot_cnt, sizeof (pot_t), sort_by_pot, (void *) hashconfig); - - u32 weak_hash_found = 0; - - if (pot_right_ptr == NULL) - { - // special case, if "weak hash" - - if (memcmp (hash_right->digest, LM_WEAK_HASH, 8) == 0) - { - weak_hash_found = 1; - - // we just need that pot_right_ptr is not a NULL pointer - - pot_right_ptr = (pot_t *) mycalloc (1, sizeof (pot_t)); - } - } - - if ((pot_left_ptr != NULL) && (pot_right_ptr != NULL)) - { - if (weak_hash_found == 1) myfree (pot_right_ptr); - - return; - } - - // ... at least one part was not cracked - - log_info_nn (""); - - input_buf[input_len] = 0; - - // only show the hash part which is still not cracked - - u32 user_len = (u32)input_len - 32u; - - char *hash_output = (char *) mymalloc (33); - - memcpy (hash_output, input_buf, input_len); - - if (pot_left_ptr != NULL) - { - // only show right part (because left part was already found) - - memcpy (hash_output + user_len, input_buf + user_len + 16, 16); - - hash_output[user_len + 16] = 0; - } - - if (pot_right_ptr != NULL) - { - // only show left part (because right part was already found) - - memcpy (hash_output + user_len, input_buf + user_len, 16); - - hash_output[user_len + 16] = 0; - } - - outfile_write (hashcat_ctx, hash_output, NULL, 0, 0, NULL, 0); - - myfree (hash_output); - - if (weak_hash_found == 1) myfree (pot_right_ptr); + fflush (potfile_ctx->fp); } int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx) @@ -771,25 +313,20 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx) if (potfile_ctx->enabled == false) return 0; hash_t *hashes_buf = hashes->hashes_buf; - u32 hashes_cnt = hashes->hashes_cnt; + u32 hashes_cnt = hashes->hashes_cnt; // no solution for these special hash types (for instane because they use hashfile in output etc) - if (hashconfig->hash_mode == 5200) - return 0; - - if ((hashconfig->hash_mode >= 6200) && (hashconfig->hash_mode <= 6299)) - return 0; - - if (hashconfig->hash_mode == 9000) - return 0; - - if ((hashconfig->hash_mode >= 13700) && (hashconfig->hash_mode <= 13799)) - return 0; + if (hashconfig->hash_mode == 5200) return 0; + if ((hashconfig->hash_mode >= 6200) + && (hashconfig->hash_mode <= 6299)) return 0; + if (hashconfig->hash_mode == 9000) return 0; + if ((hashconfig->hash_mode >= 13700) + && (hashconfig->hash_mode <= 13799)) return 0; hash_t hash_buf; - hash_buf.digest = mymalloc (hashconfig->dgst_size); + hash_buf.digest = hcmalloc (hashcat_ctx, hashconfig->dgst_size); VERIFY_PTR (hash_buf.digest); hash_buf.salt = NULL; hash_buf.esalt = NULL; hash_buf.hash_info = NULL; @@ -797,38 +334,34 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx) if (hashconfig->is_salted) { - hash_buf.salt = (salt_t *) mymalloc (sizeof (salt_t)); + hash_buf.salt = (salt_t *) hcmalloc (hashcat_ctx, sizeof (salt_t)); VERIFY_PTR (hash_buf.salt); } if (hashconfig->esalt_size) { - hash_buf.esalt = mymalloc (hashconfig->esalt_size); + hash_buf.esalt = hcmalloc (hashcat_ctx, hashconfig->esalt_size); VERIFY_PTR (hash_buf.esalt); } const int rc = potfile_read_open (hashcat_ctx); - if (rc == -1) return 0; + if (rc == -1) return -1; - int potfile_remove_cracks = 0; - - char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE); + char *line_buf = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (line_buf); // to be safe work with a copy (because of line_len loop, i etc) // moved up here because it's easier to handle continue case // it's just 64kb - char *line_buf_cpy = (char *) mymalloc (HCBUFSIZ_LARGE); + char *line_buf_cpy = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (line_buf_cpy); while (!feof (potfile_ctx->fp)) { - char *ptr = fgets (line_buf, HCBUFSIZ_LARGE - 1, potfile_ctx->fp); - - if (ptr == NULL) break; - - int line_len = strlen (line_buf); + int line_len = fgetl (potfile_ctx->fp, line_buf); if (line_len == 0) continue; + const int line_len_orig = line_len; + int iter = MAX_CUT_TRIES; for (int i = line_len - 1; i && iter; i--, line_len--) @@ -946,7 +479,15 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx) if (found == NULL) continue; - if (!found->cracked) potfile_remove_cracks++; + char *pw_buf = line_buf + line_len; + int pw_len = line_len_orig - line_len; + + found->pw_buf = (char *) hcmalloc (hashcat_ctx, pw_len + 1); VERIFY_PTR (found->pw_buf); + found->pw_len = pw_len; + + memcpy (found->pw_buf, pw_buf, pw_len); + + found->pw_buf[found->pw_len] = 0; found->cracked = 1; @@ -956,23 +497,145 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx) } } - myfree (line_buf_cpy); + hcfree (line_buf_cpy); - myfree (line_buf); + hcfree (line_buf); potfile_read_close (hashcat_ctx); if (hashconfig->esalt_size) { - myfree (hash_buf.esalt); + hcfree (hash_buf.esalt); } if (hashconfig->is_salted) { - myfree (hash_buf.salt); + hcfree (hash_buf.salt); } - myfree (hash_buf.digest); + hcfree (hash_buf.digest); - return potfile_remove_cracks; + return 0; +} + +int potfile_handle_show (hashcat_ctx_t *hashcat_ctx) +{ + hashes_t *hashes = hashcat_ctx->hashes; + + hash_t *hashes_buf = hashes->hashes_buf; + + u32 salts_cnt = hashes->salts_cnt; + salt_t *salts_buf = hashes->salts_buf; + + for (u32 salt_idx = 0; salt_idx < salts_cnt; salt_idx++) + { + salt_t *salt_buf = salts_buf + salt_idx; + + u32 digests_cnt = salt_buf->digests_cnt; + + for (u32 digest_idx = 0; digest_idx < digests_cnt; digest_idx++) + { + const u32 hashes_idx = salt_buf->digests_offset + digest_idx; + + u32 *digests_shown = hashes->digests_shown; + + if (digests_shown[hashes_idx] == 0) continue; + + char out_buf[HCBUFSIZ_LARGE]; // scratch buffer + + out_buf[0] = 0; + + ascii_digest (hashcat_ctx, out_buf, salt_idx, digest_idx); + + char tmp_buf[HCBUFSIZ_LARGE]; // scratch buffer + + hash_t *hash = &hashes_buf[hashes_idx]; + + // user + unsigned char *username = NULL; + + u32 user_len = 0; + + if (hash->hash_info != NULL) + { + user_t *user = hash->hash_info->user; + + if (user) + { + username = (unsigned char *) (user->user_name); + + user_len = user->user_len; + + username[user_len] = 0; + } + } + + const int tmp_len = outfile_write (hashcat_ctx, out_buf, (unsigned char *) hash->pw_buf, hash->pw_len, 0, username, user_len, tmp_buf); + + EVENT_DATA (EVENT_POTFILE_HASH_SHOW, tmp_buf, tmp_len); + } + } + + return 0; +} + +int potfile_handle_left (hashcat_ctx_t *hashcat_ctx) +{ + hashes_t *hashes = hashcat_ctx->hashes; + + hash_t *hashes_buf = hashes->hashes_buf; + + u32 salts_cnt = hashes->salts_cnt; + salt_t *salts_buf = hashes->salts_buf; + + for (u32 salt_idx = 0; salt_idx < salts_cnt; salt_idx++) + { + salt_t *salt_buf = salts_buf + salt_idx; + + u32 digests_cnt = salt_buf->digests_cnt; + + for (u32 digest_idx = 0; digest_idx < digests_cnt; digest_idx++) + { + const u32 hashes_idx = salt_buf->digests_offset + digest_idx; + + u32 *digests_shown = hashes->digests_shown; + + if (digests_shown[hashes_idx] == 1) continue; + + char out_buf[HCBUFSIZ_LARGE]; // scratch buffer + + out_buf[0] = 0; + + ascii_digest (hashcat_ctx, out_buf, salt_idx, digest_idx); + + hash_t *hash = &hashes_buf[hashes_idx]; + + // user + unsigned char *username = NULL; + + u32 user_len = 0; + + if (hash->hash_info != NULL) + { + user_t *user = hash->hash_info->user; + + if (user) + { + username = (unsigned char *) (user->user_name); + + user_len = user->user_len; + + username[user_len] = 0; + } + } + + char tmp_buf[HCBUFSIZ_LARGE]; // scratch buffer + + const int tmp_len = outfile_write (hashcat_ctx, out_buf, NULL, 0, 0, username, user_len, tmp_buf); + + EVENT_DATA (EVENT_POTFILE_HASH_LEFT, tmp_buf, tmp_len); + } + } + + return 0; } diff --git a/src/restore.c b/src/restore.c index b6be2495c..5bf889df6 100644 --- a/src/restore.c +++ b/src/restore.c @@ -6,7 +6,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "user_options.h" #include "restore.h" @@ -19,40 +19,7 @@ static void fsync (int fd) } #endif -u64 get_lowest_words_done (hashcat_ctx_t *hashcat_ctx) -{ - restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - - if (restore_ctx->enabled == false) return 0; - - restore_data_t *rd = restore_ctx->rd; - - u64 words_cur = -1llu; - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; - - const u64 words_done = device_param->words_done; - - if (words_done < words_cur) words_cur = words_done; - } - - // It's possible that a device's workload isn't finished right after a restore-case. - // In that case, this function would return 0 and overwrite the real restore point - // There's also status_ctx->words_cur which is set to rd->words_cur but it changes while - // the attack is running therefore we should stick to rd->words_cur. - // Note that -s influences rd->words_cur we should keep a close look on that. - - if (words_cur < rd->words_cur) words_cur = rd->words_cur; - - return words_cur; -} - -static void check_running_process (hashcat_ctx_t *hashcat_ctx) +static int check_running_process (hashcat_ctx_t *hashcat_ctx) { restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; @@ -60,24 +27,24 @@ static void check_running_process (hashcat_ctx_t *hashcat_ctx) FILE *fp = fopen (eff_restore_file, "rb"); - if (fp == NULL) return; + if (fp == NULL) return 0; - restore_data_t *rd = (restore_data_t *) mymalloc (sizeof (restore_data_t)); + restore_data_t *rd = (restore_data_t *) hcmalloc (hashcat_ctx, sizeof (restore_data_t)); VERIFY_PTR (rd); const size_t nread = fread (rd, sizeof (restore_data_t), 1, fp); if (nread != 1) { - log_error ("ERROR: Cannot read %s", eff_restore_file); + event_log_error (hashcat_ctx, "Cannot read %s", eff_restore_file); - exit (-1); + return -1; } fclose (fp); if (rd->pid) { - char *pidbin = (char *) mymalloc (HCBUFSIZ_LARGE); + char *pidbin = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (pidbin); int pidbin_len = -1; @@ -104,16 +71,16 @@ static void check_running_process (hashcat_ctx_t *hashcat_ctx) if (strcmp (argv0_r, pidbin_r) == 0) { - log_error ("ERROR: Already an instance %s running on pid %d", pidbin, rd->pid); + event_log_error (hashcat_ctx, "Already an instance %s running on pid %d", pidbin, rd->pid); - exit (-1); + return -1; } } #elif defined (_WIN) HANDLE hProcess = OpenProcess (PROCESS_ALL_ACCESS, FALSE, rd->pid); - char *pidbin2 = (char *) mymalloc (HCBUFSIZ_LARGE); + char *pidbin2 = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (pidbin2); int pidbin2_len = -1; @@ -127,38 +94,42 @@ static void check_running_process (hashcat_ctx_t *hashcat_ctx) { if (strcmp (pidbin, pidbin2) == 0) { - log_error ("ERROR: Already an instance %s running on pid %d", pidbin2, rd->pid); + event_log_error (hashcat_ctx, "Already an instance %s running on pid %d", pidbin2, rd->pid); - exit (-1); + return -1; } } - myfree (pidbin2); + hcfree (pidbin2); #endif - myfree (pidbin); + hcfree (pidbin); } if (rd->version < RESTORE_VERSION_MIN) { - log_error ("ERROR: Cannot use outdated %s. Please remove it.", eff_restore_file); + event_log_error (hashcat_ctx, "Cannot use outdated %s. Please remove it.", eff_restore_file); - exit (-1); + return -1; } - myfree (rd); + hcfree (rd); + + return 0; } -void init_restore (hashcat_ctx_t *hashcat_ctx) +static int init_restore (hashcat_ctx_t *hashcat_ctx) { restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; - restore_data_t *rd = (restore_data_t *) mymalloc (sizeof (restore_data_t)); + restore_data_t *rd = (restore_data_t *) hcmalloc (hashcat_ctx, sizeof (restore_data_t)); VERIFY_PTR (rd); restore_ctx->rd = rd; - check_running_process (hashcat_ctx); + const int rc = check_running_process (hashcat_ctx); + + if (rc == -1) return -1; rd->version = RESTORE_VERSION_CUR; @@ -173,17 +144,19 @@ void init_restore (hashcat_ctx_t *hashcat_ctx) if (getcwd (rd->cwd, 255) == NULL) { - log_error ("ERROR: getcwd(): %s", strerror (errno)); + event_log_error (hashcat_ctx, "getcwd(): %s", strerror (errno)); - exit (-1); + return -1; } + + return 0; } -void read_restore (hashcat_ctx_t *hashcat_ctx) +static int read_restore (hashcat_ctx_t *hashcat_ctx) { restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; - if (restore_ctx->enabled == false) return; + if (restore_ctx->enabled == false) return 0; char *eff_restore_file = restore_ctx->eff_restore_file; @@ -191,68 +164,75 @@ void read_restore (hashcat_ctx_t *hashcat_ctx) if (fp == NULL) { - log_error ("ERROR: Restore file '%s': %s", eff_restore_file, strerror (errno)); + event_log_error (hashcat_ctx, "Restore file '%s': %s", eff_restore_file, strerror (errno)); - exit (-1); + return -1; } restore_data_t *rd = restore_ctx->rd; if (fread (rd, sizeof (restore_data_t), 1, fp) != 1) { - log_error ("ERROR: Can't read %s", eff_restore_file); + event_log_error (hashcat_ctx, "Can't read %s", eff_restore_file); - exit (-1); + return -1; } - rd->argv = (char **) mycalloc (rd->argc, sizeof (char *)); + rd->argv = (char **) hccalloc (hashcat_ctx, rd->argc, sizeof (char *)); VERIFY_PTR (rd->argv); - char *buf = (char *) mymalloc (HCBUFSIZ_LARGE); + char *buf = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (buf); for (u32 i = 0; i < rd->argc; i++) { if (fgets (buf, HCBUFSIZ_LARGE - 1, fp) == NULL) { - log_error ("ERROR: Can't read %s", eff_restore_file); + event_log_error (hashcat_ctx, "Can't read %s", eff_restore_file); - exit (-1); + return -1; } size_t len = strlen (buf); if (len) buf[len - 1] = 0; - rd->argv[i] = mystrdup (buf); + rd->argv[i] = hcstrdup (hashcat_ctx, buf); } - myfree (buf); + hcfree (buf); fclose (fp); - log_info ("INFO: Changing current working directory to the path found within the .restore file: '%s'", rd->cwd); + event_log_info (hashcat_ctx, "INFO: Changing current working directory to '%s'", rd->cwd); + event_log_info (hashcat_ctx, ""); if (chdir (rd->cwd)) { - log_error ("ERROR: The directory '%s' does not exist. It is needed to restore (--restore) the session.\n" - " You could either create this directory (or link it) or update the .restore file using e.g. the analyze_hc_restore.pl tool:\n" - " https://github.com/philsmd/analyze_hc_restore\n" - " The directory must be relative to (or contain) all files/folders mentioned within the command line.", rd->cwd); + event_log_error (hashcat_ctx, + "The directory '%s' does not exist. It is needed to restore (--restore) the session." EOL + "You could either create this directory or update the .restore file using e.g. the analyze_hc_restore.pl tool:" EOL + "https://github.com/philsmd/analyze_hc_restore" EOL + "The directory must contain all files and folders mentioned within the command line.", rd->cwd); - exit (-1); + return -1; } + + return 0; } -void write_restore (hashcat_ctx_t *hashcat_ctx) +static int write_restore (hashcat_ctx_t *hashcat_ctx) { - restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; + const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + const restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; - if (restore_ctx->enabled == false) return; - - const u64 words_cur = get_lowest_words_done (hashcat_ctx); + if (restore_ctx->enabled == false) return 0; restore_data_t *rd = restore_ctx->rd; - rd->words_cur = words_cur; + rd->masks_pos = mask_ctx->masks_pos; + rd->dicts_pos = straight_ctx->dicts_pos; + rd->words_cur = status_ctx->words_cur; char *new_restore_file = restore_ctx->new_restore_file; @@ -260,16 +240,16 @@ void write_restore (hashcat_ctx_t *hashcat_ctx) if (fp == NULL) { - log_error ("ERROR: %s: %s", new_restore_file, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", new_restore_file, strerror (errno)); - exit (-1); + return -1; } if (setvbuf (fp, NULL, _IONBF, 0)) { - log_error ("ERROR: setvbuf file '%s': %s", new_restore_file, strerror (errno)); + event_log_error (hashcat_ctx, "setvbuf file '%s': %s", new_restore_file, strerror (errno)); - exit (-1); + return -1; } fwrite (rd, sizeof (restore_data_t), 1, fp); @@ -286,18 +266,22 @@ void write_restore (hashcat_ctx_t *hashcat_ctx) fsync (fileno (fp)); fclose (fp); + + return 0; } -void cycle_restore (hashcat_ctx_t *hashcat_ctx) +int cycle_restore (hashcat_ctx_t *hashcat_ctx) { restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; - if (restore_ctx->enabled == false) return; + if (restore_ctx->enabled == false) return 0; const char *eff_restore_file = restore_ctx->eff_restore_file; const char *new_restore_file = restore_ctx->new_restore_file; - write_restore (hashcat_ctx); + const int rc_write_restore = write_restore (hashcat_ctx); + + if (rc_write_restore == -1) return -1; struct stat st; @@ -305,14 +289,16 @@ void cycle_restore (hashcat_ctx_t *hashcat_ctx) { if (unlink (eff_restore_file)) { - log_info ("WARN: Unlink file '%s': %s", eff_restore_file, strerror (errno)); + event_log_warning (hashcat_ctx, "Unlink file '%s': %s", eff_restore_file, strerror (errno)); } } if (rename (new_restore_file, eff_restore_file)) { - log_info ("WARN: Rename file '%s' to '%s': %s", new_restore_file, eff_restore_file, strerror (errno)); + event_log_warning (hashcat_ctx, "Rename file '%s' to '%s': %s", new_restore_file, eff_restore_file, strerror (errno)); } + + return 0; } void unlink_restore (hashcat_ctx_t *hashcat_ctx) @@ -320,6 +306,8 @@ void unlink_restore (hashcat_ctx_t *hashcat_ctx) restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + if (restore_ctx->enabled == false) return; + if ((status_ctx->devices_status == STATUS_EXHAUSTED) && (status_ctx->run_thread_level1 == true)) // this is to check for [c]heckpoint { unlink (restore_ctx->eff_restore_file); @@ -333,44 +321,6 @@ void unlink_restore (hashcat_ctx_t *hashcat_ctx) } } -void stop_at_checkpoint (hashcat_ctx_t *hashcat_ctx) -{ - restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - - // this feature only makes sense if --restore-disable was not specified - - if (restore_ctx->enabled == false) - { - log_info ("WARNING: This feature is disabled when --restore-disable is specified"); - - return; - } - - if (status_ctx->devices_status != STATUS_RUNNING) return; - - if ((status_ctx->run_thread_level1 == true) && (status_ctx->run_thread_level2 == true)) - { - status_ctx->run_main_level1 = false; - status_ctx->run_main_level2 = false; - status_ctx->run_main_level3 = false; - status_ctx->run_thread_level1 = false; - status_ctx->run_thread_level2 = true; - - log_info ("Checkpoint enabled: Will quit at next Restore Point update"); - } - else - { - status_ctx->run_main_level1 = true; - status_ctx->run_main_level2 = true; - status_ctx->run_main_level3 = true; - status_ctx->run_thread_level1 = true; - status_ctx->run_thread_level2 = true; - - log_info ("Checkpoint disabled: Restore Point updates will no longer be monitored"); - } -} - int restore_ctx_init (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) { folder_config_t *folder_config = hashcat_ctx->folder_config; @@ -379,8 +329,22 @@ int restore_ctx_init (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) restore_ctx->enabled = false; - char *eff_restore_file = (char *) mymalloc (HCBUFSIZ_TINY); - char *new_restore_file = (char *) mymalloc (HCBUFSIZ_TINY); + if (user_options->benchmark == true) return 0; + if (user_options->keyspace == true) return 0; + if (user_options->left == true) return 0; + if (user_options->opencl_info == true) return 0; + if (user_options->show == true) return 0; + if (user_options->stdout_flag == true) return 0; + if (user_options->speed_only == true) return 0; + if (user_options->usage == true) return 0; + if (user_options->version == true) return 0; + if (user_options->restore_disable == true) return 0; + + if (argc == 0) return 0; + if (argv == NULL) return 0; + + char *eff_restore_file = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (eff_restore_file); + char *new_restore_file = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (new_restore_file); snprintf (eff_restore_file, HCBUFSIZ_TINY - 1, "%s/%s.restore", folder_config->session_dir, user_options->session); snprintf (new_restore_file, HCBUFSIZ_TINY - 1, "%s/%s.restore.new", folder_config->session_dir, user_options->session); @@ -391,32 +355,23 @@ int restore_ctx_init (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) restore_ctx->eff_restore_file = eff_restore_file; restore_ctx->new_restore_file = new_restore_file; - init_restore (hashcat_ctx); + const int rc_init_restore = init_restore (hashcat_ctx); - if (argc == 0) return 0; - if (argv == NULL) return 0; - - if (user_options->benchmark == true) return 0; - if (user_options->keyspace == true) return 0; - if (user_options->left == true) return 0; - if (user_options->opencl_info == true) return 0; - if (user_options->show == true) return 0; - if (user_options->stdout_flag == true) return 0; - if (user_options->usage == true) return 0; - if (user_options->version == true) return 0; - if (user_options->restore_disable == true) return 0; + if (rc_init_restore == -1) return -1; restore_ctx->enabled = true; if (user_options->restore == true) { - read_restore (hashcat_ctx); + const int rc_read_restore = read_restore (hashcat_ctx); + + if (rc_read_restore == -1) return -1; restore_data_t *rd = restore_ctx->rd; if (rd->version < RESTORE_VERSION_MIN) { - log_error ("ERROR: Incompatible restore-file version"); + event_log_error (hashcat_ctx, "Incompatible restore-file version"); return -1; } @@ -441,12 +396,12 @@ void restore_ctx_destroy (hashcat_ctx_t *hashcat_ctx) { restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; - myfree (restore_ctx->eff_restore_file); - myfree (restore_ctx->new_restore_file); - - myfree (restore_ctx->rd); - if (restore_ctx->enabled == false) return; + hcfree (restore_ctx->eff_restore_file); + hcfree (restore_ctx->new_restore_file); + + hcfree (restore_ctx->rd); + memset (restore_ctx, 0, sizeof (restore_ctx_t)); } diff --git a/src/rp.c b/src/rp.c index 82c4224ae..9049fcd84 100644 --- a/src/rp.c +++ b/src/rp.c @@ -10,7 +10,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "shared.h" #include "filehandling.h" #include "rp.h" @@ -728,12 +728,12 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 if (user_options->rp_files_cnt) { - all_kernel_rules_cnt = (u32 *) mycalloc (user_options->rp_files_cnt, sizeof (u32)); + all_kernel_rules_cnt = (u32 *) hccalloc (hashcat_ctx, user_options->rp_files_cnt, sizeof (u32)); VERIFY_PTR (all_kernel_rules_cnt); - all_kernel_rules_buf = (kernel_rule_t **) mycalloc (user_options->rp_files_cnt, sizeof (kernel_rule_t *)); + all_kernel_rules_buf = (kernel_rule_t **) hccalloc (hashcat_ctx, user_options->rp_files_cnt, sizeof (kernel_rule_t *)); VERIFY_PTR (all_kernel_rules_buf); } - char *rule_buf = (char *) mymalloc (HCBUFSIZ_LARGE); + char *rule_buf = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (rule_buf); int rule_len = 0; @@ -756,7 +756,7 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 if ((fp = fopen (rp_file, "rb")) == NULL) { - log_error ("ERROR: %s: %s", rp_file, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", rp_file, strerror (errno)); return -1; } @@ -773,7 +773,7 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 if (kernel_rules_avail == kernel_rules_cnt) { - kernel_rules_buf = (kernel_rule_t *) myrealloc (kernel_rules_buf, kernel_rules_avail * sizeof (kernel_rule_t), INCR_RULES * sizeof (kernel_rule_t)); + kernel_rules_buf = (kernel_rule_t *) hcrealloc (hashcat_ctx, kernel_rules_buf, kernel_rules_avail * sizeof (kernel_rule_t), INCR_RULES * sizeof (kernel_rule_t)); VERIFY_PTR (kernel_rules_buf); kernel_rules_avail += INCR_RULES; } @@ -785,14 +785,14 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 if (result == -1) { - log_info ("WARNING: Skipping invalid or unsupported rule in file %s on line %u: %s", rp_file, rule_line, rule_buf); + event_log_warning (hashcat_ctx, "Skipping invalid or unsupported rule in file %s on line %u: %s", rp_file, rule_line, rule_buf); continue; } if (cpu_rule_to_kernel_rule (rule_buf, rule_len, &kernel_rules_buf[kernel_rules_cnt]) == -1) { - log_info ("WARNING: Cannot convert rule for use on OpenCL device in file %s on line %u: %s", rp_file, rule_line, rule_buf); + event_log_warning (hashcat_ctx, "Cannot convert rule for use on OpenCL device in file %s on line %u: %s", rp_file, rule_line, rule_buf); memset (&kernel_rules_buf[kernel_rules_cnt], 0, sizeof (kernel_rule_t)); // needs to be cleared otherwise we could have some remaining data @@ -808,7 +808,7 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 all_kernel_rules_buf[i] = kernel_rules_buf; } - myfree (rule_buf); + hcfree (rule_buf); /** * merge rules @@ -816,7 +816,7 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 u32 kernel_rules_cnt = 1; - u32 *repeats = (u32 *) mycalloc (user_options->rp_files_cnt + 1, sizeof (u32)); + u32 *repeats = (u32 *) hccalloc (hashcat_ctx, user_options->rp_files_cnt + 1, sizeof (u32)); VERIFY_PTR (repeats); repeats[0] = kernel_rules_cnt; @@ -827,7 +827,7 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 repeats[i + 1] = kernel_rules_cnt; } - kernel_rule_t *kernel_rules_buf = (kernel_rule_t *) mycalloc (kernel_rules_cnt, sizeof (kernel_rule_t)); + kernel_rule_t *kernel_rules_buf = (kernel_rule_t *) hccalloc (hashcat_ctx, kernel_rules_cnt, sizeof (kernel_rule_t)); VERIFY_PTR (kernel_rules_buf); for (u32 i = 0; i < kernel_rules_cnt; i++) { @@ -846,7 +846,7 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 { if (out_pos == RULES_MAX - 1) { - // log_info ("WARNING: Truncating chaining of rule %d and rule %d as maximum number of function calls per rule exceeded", i, in_off); + // event_log_warning (hashcat_ctx, "Truncating chaining of rule %d and rule %d as maximum number of function calls per rule exceeded", i, in_off); break; } @@ -856,17 +856,17 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 } } - myfree (repeats); + hcfree (repeats); if (kernel_rules_cnt == 0) { - log_error ("ERROR: No valid rules left"); + event_log_error (hashcat_ctx, "No valid rules left"); return -1; } - myfree (all_kernel_rules_cnt); - myfree (all_kernel_rules_buf); + hcfree (all_kernel_rules_cnt); + hcfree (all_kernel_rules_buf); *out_cnt = kernel_rules_cnt; *out_buf = kernel_rules_buf; @@ -879,9 +879,9 @@ int kernel_rules_generate (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, const user_options_t *user_options = hashcat_ctx->user_options; u32 kernel_rules_cnt = 0; - kernel_rule_t *kernel_rules_buf = mycalloc (user_options->rp_gen, sizeof (kernel_rule_t)); + kernel_rule_t *kernel_rules_buf = hccalloc (hashcat_ctx, user_options->rp_gen, sizeof (kernel_rule_t)); VERIFY_PTR (kernel_rules_buf); - char *rule_buf = (char *) mymalloc (RP_RULE_BUFSIZ); + char *rule_buf = (char *) hcmalloc (hashcat_ctx, RP_RULE_BUFSIZ); VERIFY_PTR (rule_buf); for (kernel_rules_cnt = 0; kernel_rules_cnt < user_options->rp_gen; kernel_rules_cnt++) { @@ -892,7 +892,7 @@ int kernel_rules_generate (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, if (cpu_rule_to_kernel_rule (rule_buf, rule_len, &kernel_rules_buf[kernel_rules_cnt]) == -1) continue; } - myfree (rule_buf); + hcfree (rule_buf); *out_cnt = kernel_rules_cnt; *out_buf = kernel_rules_buf; diff --git a/src/rp_kernel_on_cpu.c b/src/rp_kernel_on_cpu.c index ab0835c15..b479de39d 100644 --- a/src/rp_kernel_on_cpu.c +++ b/src/rp_kernel_on_cpu.c @@ -3,9 +3,6 @@ * License.....: MIT */ -#pragma GCC diagnostic ignored "-Wunused-parameter" -#pragma GCC diagnostic ignored "-Wunused-function" - #include "common.h" #include "types.h" #include "bitops.h" @@ -1069,7 +1066,7 @@ static void reverse_block (u32 in0[4], u32 in1[4], u32 out0[4], u32 out1[4], con out1[3] = swap_workaround (tib41[3]); } -static u32 rule_op_mangle_lrest (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_lrest (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { buf0[0] |= (generate_cmask (buf0[0])); buf0[1] |= (generate_cmask (buf0[1])); @@ -1083,7 +1080,7 @@ static u32 rule_op_mangle_lrest (const u32 p0, const u32 p1, u32 buf0[4], u32 bu return in_len; } -static u32 rule_op_mangle_urest (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_urest (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { buf0[0] &= ~(generate_cmask (buf0[0])); buf0[1] &= ~(generate_cmask (buf0[1])); @@ -1097,7 +1094,7 @@ static u32 rule_op_mangle_urest (const u32 p0, const u32 p1, u32 buf0[4], u32 bu return in_len; } -static u32 rule_op_mangle_lrest_ufirst (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_lrest_ufirst (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { rule_op_mangle_lrest (p0, p1, buf0, buf1, in_len); @@ -1106,7 +1103,7 @@ static u32 rule_op_mangle_lrest_ufirst (const u32 p0, const u32 p1, u32 buf0[4], return in_len; } -static u32 rule_op_mangle_urest_lfirst (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_urest_lfirst (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { rule_op_mangle_urest (p0, p1, buf0, buf1, in_len); @@ -1115,7 +1112,7 @@ static u32 rule_op_mangle_urest_lfirst (const u32 p0, const u32 p1, u32 buf0[4], return in_len; } -static u32 rule_op_mangle_trest (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_trest (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { buf0[0] ^= (generate_cmask (buf0[0])); buf0[1] ^= (generate_cmask (buf0[1])); @@ -1129,7 +1126,7 @@ static u32 rule_op_mangle_trest (const u32 p0, const u32 p1, u32 buf0[4], u32 bu return in_len; } -static u32 rule_op_mangle_toggle_at (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_toggle_at (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (p0 >= in_len) return (in_len); @@ -1150,14 +1147,14 @@ static u32 rule_op_mangle_toggle_at (const u32 p0, const u32 p1, u32 buf0[4], u3 return in_len; } -static u32 rule_op_mangle_reverse (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_reverse (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { reverse_block (buf0, buf1, buf0, buf1, in_len); return in_len; } -static u32 rule_op_mangle_dupeword (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_dupeword (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if ((in_len + in_len) >= 32) return (in_len); @@ -1182,7 +1179,7 @@ static u32 rule_op_mangle_dupeword (const u32 p0, const u32 p1, u32 buf0[4], u32 return out_len; } -static u32 rule_op_mangle_dupeword_times (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_dupeword_times (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (((in_len * p0) + in_len) >= 32) return (in_len); @@ -1210,7 +1207,7 @@ static u32 rule_op_mangle_dupeword_times (const u32 p0, const u32 p1, u32 buf0[4 return out_len; } -static u32 rule_op_mangle_reflect (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_reflect (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if ((in_len + in_len) >= 32) return (in_len); @@ -1228,7 +1225,7 @@ static u32 rule_op_mangle_reflect (const u32 p0, const u32 p1, u32 buf0[4], u32 return out_len; } -static u32 rule_op_mangle_append (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_append (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if ((in_len + 1) >= 32) return (in_len); @@ -1241,7 +1238,7 @@ static u32 rule_op_mangle_append (const u32 p0, const u32 p1, u32 buf0[4], u32 b return out_len; } -static u32 rule_op_mangle_prepend (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_prepend (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if ((in_len + 1) >= 32) return (in_len); @@ -1256,7 +1253,7 @@ static u32 rule_op_mangle_prepend (const u32 p0, const u32 p1, u32 buf0[4], u32 return out_len; } -static u32 rule_op_mangle_rotate_left (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_rotate_left (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (in_len == 0) return (in_len); @@ -1283,7 +1280,7 @@ static u32 rule_op_mangle_rotate_left (const u32 p0, const u32 p1, u32 buf0[4], return in_len; } -static u32 rule_op_mangle_rotate_right (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_rotate_right (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (in_len == 0) return (in_len); @@ -1314,7 +1311,7 @@ static u32 rule_op_mangle_rotate_right (const u32 p0, const u32 p1, u32 buf0[4], return in_len; } -static u32 rule_op_mangle_delete_first (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_delete_first (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (in_len == 0) return (in_len); @@ -1325,7 +1322,7 @@ static u32 rule_op_mangle_delete_first (const u32 p0, const u32 p1, u32 buf0[4], return in_len1; } -static u32 rule_op_mangle_delete_last (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_delete_last (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (in_len == 0) return (in_len); @@ -1348,7 +1345,7 @@ static u32 rule_op_mangle_delete_last (const u32 p0, const u32 p1, u32 buf0[4], return in_len1; } -static u32 rule_op_mangle_delete_at (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_delete_at (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (p0 >= in_len) return (in_len); @@ -1423,7 +1420,7 @@ static u32 rule_op_mangle_delete_at (const u32 p0, const u32 p1, u32 buf0[4], u3 return out_len; } -static u32 rule_op_mangle_extract (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_extract (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (p0 >= in_len) return (in_len); @@ -1438,7 +1435,7 @@ static u32 rule_op_mangle_extract (const u32 p0, const u32 p1, u32 buf0[4], u32 return out_len; } -static u32 rule_op_mangle_omit (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_omit (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (p0 >= in_len) return (in_len); @@ -1524,7 +1521,7 @@ static u32 rule_op_mangle_omit (const u32 p0, const u32 p1, u32 buf0[4], u32 buf return out_len; } -static u32 rule_op_mangle_insert (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_insert (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (p0 > in_len) return (in_len); @@ -1596,7 +1593,7 @@ static u32 rule_op_mangle_insert (const u32 p0, const u32 p1, u32 buf0[4], u32 b return out_len; } -static u32 rule_op_mangle_overstrike (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_overstrike (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (p0 >= in_len) return (in_len); @@ -1619,7 +1616,7 @@ static u32 rule_op_mangle_overstrike (const u32 p0, const u32 p1, u32 buf0[4], u return in_len; } -static u32 rule_op_mangle_truncate_at (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_truncate_at (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (p0 >= in_len) return (in_len); @@ -1628,7 +1625,7 @@ static u32 rule_op_mangle_truncate_at (const u32 p0, const u32 p1, u32 buf0[4], return p0; } -static u32 rule_op_mangle_replace (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_replace (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { for (u32 i = 0; i < in_len; i++) { @@ -1672,7 +1669,7 @@ static u32 rule_op_mangle_replace (const u32 p0, const u32 p1, u32 buf0[4], u32 return in_len; } -static u32 rule_op_mangle_purgechar (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_purgechar (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { u32 out_len = 0; @@ -1714,14 +1711,14 @@ static u32 rule_op_mangle_purgechar (const u32 p0, const u32 p1, u32 buf0[4], u3 } /* -static u32 rule_op_mangle_togglecase_rec (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_togglecase_rec (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { // TODO return in_len; } */ -static u32 rule_op_mangle_dupechar_first (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_dupechar_first (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if ( in_len == 0) return (in_len); if ((in_len + p0) >= 32) return (in_len); @@ -1908,7 +1905,7 @@ static u32 rule_op_mangle_dupechar_first (const u32 p0, const u32 p1, u32 buf0[4 return out_len; } -static u32 rule_op_mangle_dupechar_last (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_dupechar_last (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if ( in_len == 0) return (in_len); if ((in_len + p0) >= 32) return (in_len); @@ -1943,7 +1940,7 @@ static u32 rule_op_mangle_dupechar_last (const u32 p0, const u32 p1, u32 buf0[4] return out_len; } -static u32 rule_op_mangle_dupechar_all (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_dupechar_all (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if ( in_len == 0) return (in_len); if ((in_len + in_len) >= 32) return (in_len); @@ -1976,7 +1973,7 @@ static u32 rule_op_mangle_dupechar_all (const u32 p0, const u32 p1, u32 buf0[4], return out_len; } -static u32 rule_op_mangle_switch_first (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_switch_first (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (in_len < 2) return (in_len); @@ -1985,7 +1982,7 @@ static u32 rule_op_mangle_switch_first (const u32 p0, const u32 p1, u32 buf0[4], return in_len; } -static u32 rule_op_mangle_switch_last (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_switch_last (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (in_len < 2) return (in_len); @@ -2070,7 +2067,7 @@ static u32 rule_op_mangle_switch_last (const u32 p0, const u32 p1, u32 buf0[4], return in_len; } -static u32 rule_op_mangle_switch_at (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_switch_at (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (p0 >= in_len) return (in_len); if (p1 >= in_len) return (in_len); @@ -2317,7 +2314,7 @@ static u32 rule_op_mangle_switch_at (const u32 p0, const u32 p1, u32 buf0[4], u3 return in_len; } -static u32 rule_op_mangle_chr_shiftl (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_chr_shiftl (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (p0 >= in_len) return (in_len); @@ -2339,7 +2336,7 @@ static u32 rule_op_mangle_chr_shiftl (const u32 p0, const u32 p1, u32 buf0[4], u return in_len; } -static u32 rule_op_mangle_chr_shiftr (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_chr_shiftr (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (p0 >= in_len) return (in_len); @@ -2361,7 +2358,7 @@ static u32 rule_op_mangle_chr_shiftr (const u32 p0, const u32 p1, u32 buf0[4], u return in_len; } -static u32 rule_op_mangle_chr_incr (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_chr_incr (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (p0 >= in_len) return (in_len); @@ -2385,7 +2382,7 @@ static u32 rule_op_mangle_chr_incr (const u32 p0, const u32 p1, u32 buf0[4], u32 return in_len; } -static u32 rule_op_mangle_chr_decr (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_chr_decr (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (p0 >= in_len) return (in_len); @@ -2409,7 +2406,7 @@ static u32 rule_op_mangle_chr_decr (const u32 p0, const u32 p1, u32 buf0[4], u32 return in_len; } -static u32 rule_op_mangle_replace_np1 (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_replace_np1 (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if ((p0 + 1) >= in_len) return (in_len); @@ -2436,7 +2433,7 @@ static u32 rule_op_mangle_replace_np1 (const u32 p0, const u32 p1, u32 buf0[4], return in_len; } -static u32 rule_op_mangle_replace_nm1 (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_replace_nm1 (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (p0 == 0) return (in_len); @@ -2465,7 +2462,7 @@ static u32 rule_op_mangle_replace_nm1 (const u32 p0, const u32 p1, u32 buf0[4], return in_len; } -static u32 rule_op_mangle_dupeblock_first (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_dupeblock_first (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (p0 > in_len) return (in_len); @@ -2503,7 +2500,7 @@ static u32 rule_op_mangle_dupeblock_first (const u32 p0, const u32 p1, u32 buf0[ return out_len; } -static u32 rule_op_mangle_dupeblock_last (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_dupeblock_last (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { if (p0 > in_len) return (in_len); @@ -2532,7 +2529,7 @@ static u32 rule_op_mangle_dupeblock_last (const u32 p0, const u32 p1, u32 buf0[4 return out_len; } -static u32 rule_op_mangle_title (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +static u32 rule_op_mangle_title (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { buf0[0] |= (generate_cmask (buf0[0])); buf0[1] |= (generate_cmask (buf0[1])); @@ -2653,7 +2650,7 @@ static u32 rule_op_mangle_title (const u32 p0, const u32 p1, u32 buf0[4], u32 bu return in_len; } -u32 apply_rule (const u32 name, const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len) +u32 apply_rule (const u32 name, MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED u32 buf0[4], MAYBE_UNUSED u32 buf1[4], const u32 in_len) { u32 out_len = in_len; @@ -2704,7 +2701,7 @@ u32 apply_rule (const u32 name, const u32 p0, const u32 p1, u32 buf0[4], u32 buf return out_len; } -u32 apply_rules (u32 *cmds, u32 buf0[4], u32 buf1[4], const u32 len) +u32 apply_rules (u32 *cmds, u32 buf0[4] MAYBE_UNUSED, u32 buf1[4] MAYBE_UNUSED, const u32 len) { u32 out_len = len; diff --git a/src/shared.c b/src/shared.c index c7c157b77..fb89e7ac6 100644 --- a/src/shared.c +++ b/src/shared.c @@ -99,7 +99,7 @@ void naive_escape (char *s, size_t s_max, const char key_char, const char escape strncpy (s, s_escaped, s_max - 1); } -void hc_sleep_ms (const u32 msec) +void hc_sleep_msec (const u32 msec) { #if defined (_WIN) Sleep (msec); diff --git a/src/status.c b/src/status.c index aed13408d..0f539a67f 100644 --- a/src/status.c +++ b/src/status.c @@ -6,7 +6,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "convert.h" #include "restore.h" #include "thread.h" @@ -14,6 +14,7 @@ #include "interface.h" #include "hwmon.h" #include "outfile.h" +#include "monitor.h" #include "status.h" static const char ST_0000[] = "Initializing"; @@ -25,8 +26,34 @@ 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_9999[] = "Unknown! Bug!"; -static void format_timer_display (struct tm *tm, char *buf, size_t len) +static char *status_get_rules_file (const hashcat_ctx_t *hashcat_ctx) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->rp_files_cnt > 0) + { + char *tmp_buf = (char *) malloc (HCBUFSIZ_TINY); + + int tmp_len = 0; + + u32 i; + + for (i = 0; i < user_options->rp_files_cnt - 1; i++) + { + tmp_len += snprintf (tmp_buf + tmp_len, HCBUFSIZ_TINY - tmp_len - 1, "%s, ", user_options->rp_files[i]); + } + + tmp_len += snprintf (tmp_buf + tmp_len, HCBUFSIZ_TINY - tmp_len - 1, "%s", user_options->rp_files[i]); + + return tmp_buf; // yes, user need to free() + } + + return NULL; +} + +void format_timer_display (struct tm *tm, char *buf, size_t len) { const char *time_entities_s[] = { "year", "day", "hour", "min", "sec" }; const char *time_entities_m[] = { "years", "days", "hours", "mins", "secs" }; @@ -67,7 +94,7 @@ static void format_timer_display (struct tm *tm, char *buf, size_t len) } } -static void format_speed_display (double val, char *buf, size_t len) +void format_speed_display (double val, char *buf, size_t len) { if (val <= 0) { @@ -101,626 +128,896 @@ static void format_speed_display (double val, char *buf, size_t len) } } -static char *strstatus (const u32 devices_status) -{ - switch (devices_status) - { - case STATUS_INIT: return ((char *) ST_0000); - case STATUS_AUTOTUNE: 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); - } - - return ((char *) "Uninitialized! Bug!"); -} - 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; + double exec_msec_sum = 0; - int exec_ms_cnt = 0; + int exec_msec_cnt = 0; for (int i = 0; i < last_num_entries; i++) { - double exec_ms = device_param->exec_ms[(exec_pos + i) % EXEC_CACHE]; + double exec_msec = device_param->exec_msec[(exec_pos + i) % EXEC_CACHE]; - if (exec_ms > 0) + if (exec_msec > 0) { - exec_ms_sum += exec_ms; + exec_msec_sum += exec_msec; - exec_ms_cnt++; + exec_msec_cnt++; } } - if (exec_ms_cnt == 0) return 0; + if (exec_msec_cnt == 0) return 0; - return exec_ms_sum / exec_ms_cnt; + return exec_msec_sum / exec_msec_cnt; } -void status_display_machine_readable (hashcat_ctx_t *hashcat_ctx) +int status_get_device_info_cnt (const hashcat_ctx_t *hashcat_ctx) { - combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; - hashes_t *hashes = hashcat_ctx->hashes; - mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; - user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; - user_options_t *user_options = hashcat_ctx->user_options; + const opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - if (status_ctx->devices_status == STATUS_INIT) - { - log_error ("ERROR: status view is not available during initialization phase"); - - return; - } - - if (status_ctx->devices_status == STATUS_AUTOTUNE) - { - log_error ("ERROR: status view is not available during autotune phase"); - - return; - } - - FILE *out = stdout; - - fprintf (out, "STATUS\t%u\t", status_ctx->devices_status); - - /** - * speed new - */ - - fprintf (out, "SPEED\t"); - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->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 (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->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 (hashcat_ctx); - - fprintf (out, "CURKU\t%" PRIu64 "\t", words_cur); - - /** - * counter - */ - - u64 progress_total = status_ctx->words_cnt * hashes->salts_cnt; - - u64 all_done = 0; - u64 all_rejected = 0; - u64 all_restored = 0; - - for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) - { - all_done += status_ctx->words_progress_done[salt_pos]; - all_rejected += status_ctx->words_progress_rejected[salt_pos]; - all_restored += status_ctx->words_progress_restored[salt_pos]; - } - - u64 progress_cur = all_restored + all_done + all_rejected; - u64 progress_end = progress_total; - - u64 progress_skip = 0; - - if (user_options->skip) - { - progress_skip = MIN (user_options->skip, status_ctx->words_base) * hashes->salts_cnt; - - if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_skip *= straight_ctx->kernel_rules_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_skip *= combinator_ctx->combs_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_skip *= mask_ctx->bfs_cnt; - } - - if (user_options->limit) - { - progress_end = MIN (user_options->limit, status_ctx->words_base) * hashes->salts_cnt; - - if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_end *= straight_ctx->kernel_rules_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_end *= combinator_ctx->combs_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_end *= mask_ctx->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", hashes->digests_done, hashes->digests_cnt); - fprintf (out, "RECSALT\t%u\t%u\t", hashes->salts_done, hashes->salts_cnt); - - /** - * temperature - */ - - if (user_options->gpu_temp_disable == false) - { - fprintf (out, "TEMP\t"); - - hc_thread_mutex_lock (status_ctx->mux_hwmon); - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; - - int temp = hm_get_temperature_with_device_id (hashcat_ctx, device_id); - - fprintf (out, "%d\t", temp); - } - - hc_thread_mutex_unlock (status_ctx->mux_hwmon); - } - - /** - * flush - */ - - fputs (EOL, out); - fflush (out); + return opencl_ctx->devices_cnt; } -void status_display (hashcat_ctx_t *hashcat_ctx) +int status_get_device_info_active (const hashcat_ctx_t *hashcat_ctx) { - combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; - cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - hashes_t *hashes = hashcat_ctx->hashes; - mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; - user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; - user_options_t *user_options = hashcat_ctx->user_options; + const opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - if (status_ctx->devices_status == STATUS_INIT) + return opencl_ctx->devices_active; +} + +bool status_get_skipped_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id) +{ + const opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + return device_param->skipped; +} + +char *status_get_session (const hashcat_ctx_t *hashcat_ctx) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + return user_options->session; +} + +char *status_get_status_string (const hashcat_ctx_t *hashcat_ctx) +{ + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + const int devices_status = status_ctx->devices_status; + + switch (devices_status) { - log_error ("ERROR: status view is not available during initialization phase"); - - return; + case STATUS_INIT: return ((char *) ST_0000); + case STATUS_AUTOTUNE: 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); } - if (status_ctx->devices_status == STATUS_AUTOTUNE) - { - log_error ("ERROR: status view is not available during autotune phase"); + return ((char *) ST_9999); +} - return; - } +int status_get_status_number (const hashcat_ctx_t *hashcat_ctx) +{ + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - // in this case some required buffers are free'd, ascii_digest() would run into segfault - if (status_ctx->shutdown_inner == 1) return; + return status_ctx->devices_status; +} - if (user_options->machine_readable == true) - { - status_display_machine_readable (hashcat_ctx); +char *status_get_hash_type (const hashcat_ctx_t *hashcat_ctx) +{ + const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - return; - } + return strhashtype (hashconfig->hash_mode); +} - char tmp_buf[1000] = { 0 }; - - u32 tmp_len = 0; - - log_info ("Session.Name...: %s", user_options->session); - - char *status_type = strstatus (status_ctx->devices_status); - - u32 hash_mode = hashconfig->hash_mode; - - char *hash_type = strhashtype (hash_mode); // not a bug - - log_info ("Status.........: %s", status_type); - - /** - * show rules - */ - - if (user_options->rp_files_cnt) - { - u32 i; - - for (i = 0, tmp_len = 0; i < user_options->rp_files_cnt - 1 && tmp_len < sizeof (tmp_buf); i++) - { - tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, "File (%s), ", user_options->rp_files[i]); - } - - snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, "File (%s)", user_options->rp_files[i]); - - log_info ("Rules.Type.....: %s", tmp_buf); - - tmp_len = 0; - } - - if (user_options->rp_gen) - { - log_info ("Rules.Type.....: Generated (%u)", user_options->rp_gen); - - if (user_options->rp_gen_seed) - { - log_info ("Rules.Seed.....: %u", user_options->rp_gen_seed); - } - } - - /** - * show input - */ - - char *custom_charset_1 = user_options->custom_charset_1; - char *custom_charset_2 = user_options->custom_charset_2; - char *custom_charset_3 = user_options->custom_charset_3; - char *custom_charset_4 = user_options->custom_charset_4; - - if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) - { - if (user_options_extra->wordlist_mode == WL_MODE_FILE) - { - log_info ("Input.Mode.....: File (%s)", straight_ctx->dict); - } - else if (user_options_extra->wordlist_mode == WL_MODE_STDIN) - { - log_info ("Input.Mode.....: Pipe"); - } - } - else if (user_options->attack_mode == ATTACK_MODE_COMBI) - { - log_info ("Input.Left.....: File (%s)", combinator_ctx->dict1); - log_info ("Input.Right....: File (%s)", combinator_ctx->dict2); - } - else if (user_options->attack_mode == ATTACK_MODE_BF) - { - char *mask = mask_ctx->mask; - - if (mask != NULL) - { - u32 mask_len = mask_ctx->css_cnt; - - tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, "Mask (%s)", mask); - - if (mask_len > 0) - { - if (hashconfig->opti_type & OPTI_TYPE_SINGLE_HASH) - { - if (hashconfig->opti_type & OPTI_TYPE_APPENDED_SALT) - { - mask_len -= hashes->salts_buf[0].salt_len; - } - } - - if (hashconfig->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 (mask_ctx->masks_cnt > 1) - { - const int maks_pos_done = ((status_ctx->devices_status == STATUS_EXHAUSTED) && (status_ctx->run_main_level1 == true)) ? 1 : 0; - - double mask_percentage = (double) (mask_ctx->masks_pos + maks_pos_done) / (double) mask_ctx->masks_cnt; - - tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, " (%.02f%%)", mask_percentage * 100); - } - - log_info ("Input.Mode.....: %s", tmp_buf); - - if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL)) - { - 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.Charset.: -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 (user_options->attack_mode == ATTACK_MODE_HYBRID1) - { - log_info ("Input.Left.....: File (%s)", straight_ctx->dict); - log_info ("Input.Right....: Mask (%s) [%i]", mask_ctx->mask, mask_ctx->css_cnt); - - if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL)) - { - 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.Charset.: -1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4); - } - } - else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) - { - log_info ("Input.Left.....: Mask (%s) [%i]", mask_ctx->mask, mask_ctx->css_cnt); - log_info ("Input.Right....: File (%s)", straight_ctx->dict); - - if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL)) - { - 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.Charset.: -1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4); - } - } +char *status_get_hash_target (const hashcat_ctx_t *hashcat_ctx) +{ + const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + const hashes_t *hashes = hashcat_ctx->hashes; if (hashes->digests_cnt == 1) { if (hashconfig->hash_mode == 2500) { + char *tmp_buf = (char *) malloc (HCBUFSIZ_TINY); + wpa_t *wpa = (wpa_t *) hashes->esalts_buf; - log_info ("Hash.Target....: %s (%02x:%02x:%02x:%02x:%02x:%02x <-> %02x:%02x:%02x:%02x:%02x:%02x)", - (char *) hashes->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]); + snprintf (tmp_buf, HCBUFSIZ_TINY - 1, "%s (%02x:%02x:%02x:%02x:%02x:%02x <-> %02x:%02x:%02x:%02x:%02x:%02x)", + (char *) hashes->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]); + + return tmp_buf; } else if (hashconfig->hash_mode == 5200) { - log_info ("Hash.Target....: File (%s)", hashes->hashfile); + return hashes->hashfile; } else if (hashconfig->hash_mode == 9000) { - log_info ("Hash.Target....: File (%s)", hashes->hashfile); + return hashes->hashfile; } else if ((hashconfig->hash_mode >= 6200) && (hashconfig->hash_mode <= 6299)) { - log_info ("Hash.Target....: File (%s)", hashes->hashfile); + return hashes->hashfile; } else if ((hashconfig->hash_mode >= 13700) && (hashconfig->hash_mode <= 13799)) { - log_info ("Hash.Target....: File (%s)", hashes->hashfile); + return hashes->hashfile; } else { - char out_buf[HCBUFSIZ_LARGE] = { 0 }; + char *tmp_buf = (char *) malloc (HCBUFSIZ_LARGE); - ascii_digest (out_buf, 0, 0, hashconfig, hashes); + tmp_buf[0] = 0; - // limit length - if (strlen (out_buf) > 40) - { - out_buf[41] = '.'; - out_buf[42] = '.'; - out_buf[43] = '.'; - out_buf[44] = 0; - } + ascii_digest ((hashcat_ctx_t *) hashcat_ctx, tmp_buf, 0, 0); - log_info ("Hash.Target....: %s", out_buf); + char *tmp_buf2 = strdup (tmp_buf); + + free (tmp_buf); + + return tmp_buf2; } } else { if (hashconfig->hash_mode == 3000) { + char *tmp_buf = (char *) malloc (HCBUFSIZ_TINY); + char out_buf1[32] = { 0 }; char out_buf2[32] = { 0 }; - ascii_digest (out_buf1, 0, 0, hashconfig, hashes); - ascii_digest (out_buf2, 0, 1, hashconfig, hashes); + ascii_digest ((hashcat_ctx_t *) hashcat_ctx, out_buf1, 0, 0); + ascii_digest ((hashcat_ctx_t *) hashcat_ctx, out_buf2, 0, 1); - log_info ("Hash.Target....: %s, %s", out_buf1, out_buf2); + snprintf (tmp_buf, HCBUFSIZ_TINY - 1, "%s, %s", out_buf1, out_buf2); + + return tmp_buf; } else { - log_info ("Hash.Target....: File (%s)", hashes->hashfile); + return hashes->hashfile; } } - log_info ("Hash.Type......: %s", hash_type); + return NULL; +} - /** - * speed new - */ +int status_get_input_mode (const hashcat_ctx_t *hashcat_ctx) +{ + const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; + const user_options_t *user_options = hashcat_ctx->user_options; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; - u64 speed_cnt[DEVICES_MAX] = { 0 }; - double speed_ms[DEVICES_MAX] = { 0 }; + bool has_wordlist = false; + bool has_rule_file = false; + bool has_rule_gen = false; + bool has_base_left = false; + bool has_mask_cs = false; - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + if (user_options_extra->wordlist_mode == WL_MODE_FILE) has_wordlist = true; + + if (user_options->rp_files_cnt > 0) has_rule_file = true; + if (user_options->rp_gen > 0) has_rule_gen = true; + + if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_LEFT) has_base_left = true; + + if (user_options->custom_charset_1) has_mask_cs = true; + if (user_options->custom_charset_2) has_mask_cs = true; + if (user_options->custom_charset_3) has_mask_cs = true; + if (user_options->custom_charset_4) has_mask_cs = true; + + if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) { - hc_device_param_t *device_param = &opencl_ctx->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++) + if (has_wordlist == true) { - speed_cnt[device_id] += device_param->speed_cnt[i]; - speed_ms[device_id] += device_param->speed_ms[i]; + if (has_rule_file == true) + { + return INPUT_MODE_STRAIGHT_FILE_RULES_FILE; + } + else if (has_rule_gen == true) + { + return INPUT_MODE_STRAIGHT_FILE_RULES_GEN; + } + else + { + return INPUT_MODE_STRAIGHT_FILE; + } } - - 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 (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; - - hashes_dev_ms[device_id] = 0; - - if (speed_ms[device_id] > 0) + else { - hashes_dev_ms[device_id] = (double) speed_cnt[device_id] / speed_ms[device_id]; - - hashes_all_ms += hashes_dev_ms[device_id]; + if (has_rule_file == true) + { + return INPUT_MODE_STRAIGHT_STDIN_RULES_FILE; + } + else if (has_rule_gen == true) + { + return INPUT_MODE_STRAIGHT_STDIN_RULES_GEN; + } + else + { + return INPUT_MODE_STRAIGHT_STDIN; + } } } - - /** - * exec time - */ - - double exec_all_ms[DEVICES_MAX] = { 0 }; - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + else if (user_options->attack_mode == ATTACK_MODE_COMBI) { - hc_device_param_t *device_param = &opencl_ctx->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 = hc_timer_get (status_ctx->timer_running); - - double ms_paused = status_ctx->ms_paused; - - if (status_ctx->devices_status == STATUS_PAUSED) - { - double ms_paused_tmp = hc_timer_get (status_ctx->timer_paused); - - 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) + if (has_base_left == true) { - 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 (&status_ctx->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); + return INPUT_MODE_COMBINATOR_BASE_LEFT; } + else + { + return INPUT_MODE_COMBINATOR_BASE_RIGHT; + } + } + else if (user_options->attack_mode == ATTACK_MODE_BF) + { + if (has_mask_cs == true) + { + return INPUT_MODE_MASK_CS; + } + else + { + return INPUT_MODE_MASK; + } + } + else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) + { + if (has_mask_cs == true) + { + return INPUT_MODE_HYBRID1_CS; + } + else + { + return INPUT_MODE_HYBRID1; + } + } + else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) + { + if (has_mask_cs == true) + { + return INPUT_MODE_HYBRID2_CS; + } + else + { + return INPUT_MODE_HYBRID2; + } + } + + return INPUT_MODE_NONE; +} + +char *status_get_input_base (const hashcat_ctx_t *hashcat_ctx) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) + { + const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; + + return straight_ctx->dict; + } + else if (user_options->attack_mode == ATTACK_MODE_COMBI) + { + const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; + + if (combinator_ctx->combs_mode == INPUT_MODE_COMBINATOR_BASE_LEFT) + { + return combinator_ctx->dict1; + } + else + { + return combinator_ctx->dict2; + } + } + else if (user_options->attack_mode == ATTACK_MODE_BF) + { + const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + + return mask_ctx->mask; + } + else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) + { + const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; + + return straight_ctx->dict; + } + else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) + { + const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; + + return straight_ctx->dict; + } + + return NULL; +} + +char *status_get_input_mod (const hashcat_ctx_t *hashcat_ctx) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->attack_mode == ATTACK_MODE_STRAIGHT) + { + return status_get_rules_file (hashcat_ctx); + } + else if (user_options->attack_mode == ATTACK_MODE_COMBI) + { + const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; + + if (combinator_ctx->combs_mode == INPUT_MODE_COMBINATOR_BASE_LEFT) + { + return combinator_ctx->dict2; + } + else + { + return combinator_ctx->dict1; + } + } + else if (user_options->attack_mode == ATTACK_MODE_BF) + { + + } + else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) + { + const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + + return mask_ctx->mask; + } + else if (user_options->attack_mode == ATTACK_MODE_HYBRID2) + { + const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + + return mask_ctx->mask; + } + + return NULL; +} + +char *status_get_input_charset (const hashcat_ctx_t *hashcat_ctx) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + const char *custom_charset_1 = user_options->custom_charset_1; + const char *custom_charset_2 = user_options->custom_charset_2; + const char *custom_charset_3 = user_options->custom_charset_3; + const char *custom_charset_4 = user_options->custom_charset_4; + + if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL)) + { + char *tmp_buf = (char *) malloc (HCBUFSIZ_TINY); + + 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"; + + snprintf (tmp_buf, HCBUFSIZ_TINY - 1, "-1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4); + + return tmp_buf; + } + + return NULL; +} + +char *status_get_input_candidates_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id) +{ + const opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + char *display = (char *) malloc (HCBUFSIZ_TINY); + + if (user_options_extra->attack_kern == ATTACK_KERN_BF) + { + snprintf (display, HCBUFSIZ_TINY - 1, "[Generating]"); } else { - log_info ("Time.Started...: 0 secs"); + snprintf (display, HCBUFSIZ_TINY - 1, "[Copying]"); } - /** - * counters - */ + if (device_param->skipped == true) return display; - u64 progress_total = status_ctx->words_cnt * hashes->salts_cnt; + if ((device_param->outerloop_left == 0) || (device_param->innerloop_left == 0)) return display; - u64 all_done = 0; - u64 all_rejected = 0; - u64 all_restored = 0; + const u32 outerloop_first = 0; + const u32 outerloop_last = device_param->outerloop_left - 1; - u64 progress_noneed = 0; + const u32 innerloop_first = 0; + const u32 innerloop_last = device_param->innerloop_left - 1; + + plain_t plain1 = { 0, 0, 0, outerloop_first, innerloop_first }; + plain_t plain2 = { 0, 0, 0, outerloop_last, innerloop_last }; + + u32 plain_buf1[16] = { 0 }; + u32 plain_buf2[16] = { 0 }; + + u8 *plain_ptr1 = (u8 *) plain_buf1; + u8 *plain_ptr2 = (u8 *) plain_buf2; + + int plain_len1 = 0; + int plain_len2 = 0; + + build_plain ((hashcat_ctx_t *) hashcat_ctx, device_param, &plain1, plain_buf1, &plain_len1); + build_plain ((hashcat_ctx_t *) hashcat_ctx, device_param, &plain2, plain_buf2, &plain_len2); + + const bool need_hex1 = need_hexify (plain_ptr1, plain_len1); + const bool need_hex2 = need_hexify (plain_ptr2, plain_len2); + + if ((need_hex1 == true) || (need_hex2 == true)) + { + exec_hexify (plain_ptr1, plain_len1, plain_ptr1); + exec_hexify (plain_ptr2, plain_len2, plain_ptr2); + + plain_ptr1[plain_len1 * 2] = 0; + plain_ptr2[plain_len2 * 2] = 0; + + snprintf (display, HCBUFSIZ_TINY - 1, "$HEX[%s] -> $HEX[%s]", plain_ptr1, plain_ptr2); + } + else + { + snprintf (display, HCBUFSIZ_TINY - 1, "%s -> %s", plain_ptr1, plain_ptr2); + } + + return display; +} + +int status_get_digests_done (const hashcat_ctx_t *hashcat_ctx) +{ + const hashes_t *hashes = hashcat_ctx->hashes; + + return hashes->digests_done; +} + +int status_get_digests_cnt (const hashcat_ctx_t *hashcat_ctx) +{ + const hashes_t *hashes = hashcat_ctx->hashes; + + return hashes->digests_cnt; +} + +double status_get_digests_percent (const hashcat_ctx_t *hashcat_ctx) +{ + const hashes_t *hashes = hashcat_ctx->hashes; + + return ((double) hashes->digests_done / (double) hashes->digests_cnt) * 100; +} + +int status_get_salts_done (const hashcat_ctx_t *hashcat_ctx) +{ + const hashes_t *hashes = hashcat_ctx->hashes; + + return hashes->salts_done; +} + +int status_get_salts_cnt (const hashcat_ctx_t *hashcat_ctx) +{ + const hashes_t *hashes = hashcat_ctx->hashes; + + return hashes->salts_cnt; +} + +double status_get_salts_percent (const hashcat_ctx_t *hashcat_ctx) +{ + const hashes_t *hashes = hashcat_ctx->hashes; + + return ((double) hashes->salts_done / (double) hashes->salts_cnt) * 100; +} + +double status_get_msec_running (const hashcat_ctx_t *hashcat_ctx) +{ + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + double msec_running = hc_timer_get (status_ctx->timer_running); + + return msec_running; +} + +double status_get_msec_paused (const hashcat_ctx_t *hashcat_ctx) +{ + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + double msec_paused = status_ctx->msec_paused; + + if (status_ctx->devices_status == STATUS_PAUSED) + { + double msec_paused_tmp = hc_timer_get (status_ctx->timer_paused); + + msec_paused += msec_paused_tmp; + } + + return msec_paused; +} + +double status_get_msec_real (const hashcat_ctx_t *hashcat_ctx) +{ + const double msec_running = status_get_msec_running (hashcat_ctx); + const double msec_paused = status_get_msec_paused (hashcat_ctx); + + const double msec_real = msec_running - msec_paused; + + return msec_real; +} + +char *status_get_time_started_absolute (const hashcat_ctx_t *hashcat_ctx) +{ + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + const time_t time_start = status_ctx->runtime_start; + + char *start = ctime (&time_start); + + const 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; + + return start; +} + +char *status_get_time_started_relative (const hashcat_ctx_t *hashcat_ctx) +{ + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + time_t time_now; + + time (&time_now); + + const time_t time_start = status_ctx->runtime_start; + + #if defined (_WIN) + + __time64_t sec_run = time_now - time_start; + + #else + + time_t sec_run = time_now - time_start; + + #endif + + struct tm *tmp; + + #if defined (_WIN) + + tmp = _gmtime64 (&sec_run); + + #else + + tmp = gmtime (&sec_run); + + #endif + + char *display_run = (char *) malloc (HCBUFSIZ_TINY); + + format_timer_display (tmp, display_run, HCBUFSIZ_TINY); + + return display_run; +} + +char *status_get_time_estimated_absolute (const hashcat_ctx_t *hashcat_ctx) +{ + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + + #if defined (_WIN) + __time64_t sec_etc = 0; + #else + time_t sec_etc = 0; + #endif + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + if (status_ctx->devices_status != STATUS_CRACKED) + { + const u64 progress_cur_relative_skip = status_get_progress_cur_relative_skip (hashcat_ctx); + const u64 progress_end_relative_skip = status_get_progress_end_relative_skip (hashcat_ctx); + + const u64 progress_ignore = status_get_progress_ignore (hashcat_ctx); + + const double hashes_msec_all = status_get_hashes_msec_all (hashcat_ctx); + + if (hashes_msec_all > 0) + { + const u64 progress_left_relative_skip = progress_end_relative_skip - progress_cur_relative_skip; + + u64 msec_left = (u64) ((progress_left_relative_skip - progress_ignore) / hashes_msec_all); + + sec_etc = msec_left / 1000; + } + } + } + + // we need this check to avoid integer overflow + #if defined (_WIN) + if (sec_etc > 100000000) + { + sec_etc = 100000000; + } + #endif + + time_t now; + + time (&now); + + now += sec_etc; + + char *etc = ctime (&now); + + const 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; + + return etc; +} + +char *status_get_time_estimated_relative (const hashcat_ctx_t *hashcat_ctx) +{ + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + const user_options_t *user_options = hashcat_ctx->user_options; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + + #if defined (_WIN) + __time64_t sec_etc = 0; + #else + time_t sec_etc = 0; + #endif + + if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + { + if (status_ctx->devices_status != STATUS_CRACKED) + { + const u64 progress_cur_relative_skip = status_get_progress_cur_relative_skip (hashcat_ctx); + const u64 progress_end_relative_skip = status_get_progress_end_relative_skip (hashcat_ctx); + + const u64 progress_ignore = status_get_progress_ignore (hashcat_ctx); + + const double hashes_msec_all = status_get_hashes_msec_all (hashcat_ctx); + + if (hashes_msec_all > 0) + { + const u64 progress_left_relative_skip = progress_end_relative_skip - progress_cur_relative_skip; + + u64 msec_left = (u64) ((progress_left_relative_skip - progress_ignore) / hashes_msec_all); + + sec_etc = msec_left / 1000; + } + } + } + + // we need this check to avoid integer overflow + #if defined (_WIN) + if (sec_etc > 100000000) + { + sec_etc = 100000000; + } + #endif + + struct tm *tmp; + + #if defined (_WIN) + tmp = _gmtime64 (&sec_etc); + #else + tmp = gmtime (&sec_etc); + #endif + + char *display = (char *) malloc (HCBUFSIZ_TINY); + + format_timer_display (tmp, display, HCBUFSIZ_TINY); + + if (user_options->runtime > 0) + { + const int runtime_left = get_runtime_left (hashcat_ctx); + + char *tmp = strdup (display); + + if (runtime_left > 0) + { + #if defined (_WIN) + __time64_t sec_left = runtime_left; + #else + time_t sec_left = runtime_left; + #endif + + struct tm *tmp_left; + + #if defined (_WIN) + tmp_left = _gmtime64 (&sec_left); + #else + tmp_left = gmtime (&sec_left); + #endif + + char *display_left = (char *) malloc (HCBUFSIZ_TINY); + + format_timer_display (tmp_left, display_left, HCBUFSIZ_TINY); + + snprintf (display, HCBUFSIZ_TINY - 1, "%s; Runtime limited: %s", tmp, display_left); + + free (display_left); + } + else + { + snprintf (display, HCBUFSIZ_TINY - 1, "%s; Runtime limit exceeded", tmp); + } + + free (tmp); + } + + return display; +} + +u64 status_get_restore_point (const hashcat_ctx_t *hashcat_ctx) +{ + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + const u64 restore_point = status_ctx->words_cur; + + return restore_point; +} + +u64 status_get_restore_total (const hashcat_ctx_t *hashcat_ctx) +{ + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + const u64 restore_total = status_ctx->words_base; + + return restore_total; +} + +double status_get_restore_percent (const hashcat_ctx_t *hashcat_ctx) +{ + double restore_percent = 0; + + const u64 restore_point = status_get_restore_point (hashcat_ctx); + const u64 restore_total = status_get_restore_total (hashcat_ctx); + + if (restore_total > 0) + { + restore_percent = ((double) restore_point / (double) restore_total) * 100; + } + + return restore_percent; +} + +int status_get_progress_mode (const hashcat_ctx_t *hashcat_ctx) +{ + const u64 progress_end_relative_skip = status_get_progress_end_relative_skip (hashcat_ctx); + + if (progress_end_relative_skip > 0) + { + return PROGRESS_MODE_KEYSPACE_KNOWN; + } + else + { + return PROGRESS_MODE_KEYSPACE_UNKNOWN; + } + + return PROGRESS_MODE_NONE; +} + +double status_get_progress_finished_percent (const hashcat_ctx_t *hashcat_ctx) +{ + const u64 progress_cur_relative_skip = status_get_progress_cur_relative_skip (hashcat_ctx); + const u64 progress_end_relative_skip = status_get_progress_end_relative_skip (hashcat_ctx); + + double progress_finished_percent = 0; + + if (progress_end_relative_skip > 0) + { + progress_finished_percent = ((double) progress_cur_relative_skip / (double) progress_end_relative_skip) * 100; + } + + return progress_finished_percent; +} + +u64 status_get_progress_done (const hashcat_ctx_t *hashcat_ctx) +{ + const hashes_t *hashes = hashcat_ctx->hashes; + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + u64 progress_done = 0; for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) { - all_done += status_ctx->words_progress_done[salt_pos]; - all_rejected += status_ctx->words_progress_rejected[salt_pos]; - all_restored += status_ctx->words_progress_restored[salt_pos]; + progress_done += status_ctx->words_progress_done[salt_pos]; + } - // Important for ETA only + return progress_done; +} +u64 status_get_progress_rejected (const hashcat_ctx_t *hashcat_ctx) +{ + const hashes_t *hashes = hashcat_ctx->hashes; + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + u64 progress_rejected = 0; + + for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) + { + progress_rejected += status_ctx->words_progress_rejected[salt_pos]; + } + + return progress_rejected; +} + +double status_get_progress_rejected_percent (const hashcat_ctx_t *hashcat_ctx) +{ + const u64 progress_cur = status_get_progress_cur (hashcat_ctx); + const u64 progress_rejected = status_get_progress_rejected (hashcat_ctx); + + double percent_rejected = 0; + + if (progress_cur) + { + percent_rejected = ((double) (progress_rejected) / (double) progress_cur) * 100; + } + + return percent_rejected; +} + +u64 status_get_progress_restored (const hashcat_ctx_t *hashcat_ctx) +{ + const hashes_t *hashes = hashcat_ctx->hashes; + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + u64 progress_restored = 0; + + for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) + { + progress_restored += status_ctx->words_progress_restored[salt_pos]; + } + + return progress_restored; +} + +u64 status_get_progress_cur (const hashcat_ctx_t *hashcat_ctx) +{ + const u64 progress_done = status_get_progress_done (hashcat_ctx); + const u64 progress_rejected = status_get_progress_rejected (hashcat_ctx); + const u64 progress_restored = status_get_progress_restored (hashcat_ctx); + + const u64 progress_cur = progress_done + progress_rejected + progress_restored; + + return progress_cur; +} + +u64 status_get_progress_ignore (const hashcat_ctx_t *hashcat_ctx) +{ + const hashes_t *hashes = hashcat_ctx->hashes; + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + // Important for ETA only + + u64 progress_ignore = 0; + + for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) + { if (hashes->salts_shown[salt_pos] == 1) { const u64 all = status_ctx->words_progress_done[salt_pos] @@ -729,26 +1026,28 @@ void status_display (hashcat_ctx_t *hashcat_ctx) const u64 left = status_ctx->words_cnt - all; - progress_noneed += left; + progress_ignore += left; } } - u64 progress_cur = all_restored + all_done + all_rejected; - u64 progress_end = progress_total; + return progress_ignore; +} - u64 progress_skip = 0; +u64 status_get_progress_end (const hashcat_ctx_t *hashcat_ctx) +{ + const hashes_t *hashes = hashcat_ctx->hashes; + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + const user_options_t *user_options = hashcat_ctx->user_options; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; - if (user_options->skip) - { - progress_skip = MIN (user_options->skip, status_ctx->words_base) * hashes->salts_cnt; - - if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_skip *= straight_ctx->kernel_rules_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_skip *= combinator_ctx->combs_cnt; - else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_skip *= mask_ctx->bfs_cnt; - } + u64 progress_end = status_ctx->words_cnt * hashes->salts_cnt; if (user_options->limit) { + const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; + const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; + progress_end = MIN (user_options->limit, status_ctx->words_base) * hashes->salts_cnt; if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_end *= straight_ctx->kernel_rules_cnt; @@ -756,593 +1055,424 @@ void status_display (hashcat_ctx_t *hashcat_ctx) else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_end *= mask_ctx->bfs_cnt; } - u64 progress_cur_relative_skip = progress_cur - progress_skip; - u64 progress_end_relative_skip = progress_end - progress_skip; + return progress_end; +} - if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) +u64 status_get_progress_skip (const hashcat_ctx_t *hashcat_ctx) +{ + const hashes_t *hashes = hashcat_ctx->hashes; + const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + const user_options_t *user_options = hashcat_ctx->user_options; + const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; + + u64 progress_skip = 0; + + if (user_options->skip) { - if (status_ctx->devices_status != STATUS_CRACKED) - { - #if defined (_WIN) - __time64_t sec_etc = 0; - #else - time_t sec_etc = 0; - #endif + const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; + const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; - if (hashes_all_ms > 0) - { - u64 progress_left_relative_skip = progress_end_relative_skip - progress_cur_relative_skip; + progress_skip = MIN (user_options->skip, status_ctx->words_base) * hashes->salts_cnt; - u64 ms_left = (u64) ((progress_left_relative_skip - progress_noneed) / hashes_all_ms); - - sec_etc = ms_left / 1000; - } - - #define SEC10YEARS (60 * 60 * 24 * 365 * 10) - - if (sec_etc == 0) - { - //log_info ("Time.Estimated.: 0 secs"); - } - else if ((u64) sec_etc > SEC10YEARS) - { - 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 (user_options->runtime) - { - time_t runtime_cur; - - time (&runtime_cur); - - #if defined (_WIN) - - __time64_t runtime_left = status_ctx->proc_start + user_options->runtime + status_ctx->prepare_time + (ms_paused / 1000) - runtime_cur; - - tmp = _gmtime64 (&runtime_left); - - #else - - time_t runtime_left = status_ctx->proc_start + user_options->runtime + status_ctx->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); - } - } - } - } + if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) progress_skip *= straight_ctx->kernel_rules_cnt; + else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) progress_skip *= combinator_ctx->combs_cnt; + else if (user_options_extra->attack_kern == ATTACK_KERN_BF) progress_skip *= mask_ctx->bfs_cnt; } - if (status_ctx->run_main_level1 == true) + return progress_skip; +} + +u64 status_get_progress_cur_relative_skip (const hashcat_ctx_t *hashcat_ctx) +{ + const u64 progress_skip = status_get_progress_skip (hashcat_ctx); + const u64 progress_cur = status_get_progress_cur (hashcat_ctx); + + u64 progress_cur_relative_skip = 0; + + if (progress_cur > 0) { - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; - - if ((device_param->outerloop_left == 0) || (device_param->innerloop_left == 0)) - { - if (user_options_extra->attack_kern == ATTACK_KERN_BF) - { - log_info ("Candidates.#%d..: [Generating]", device_id + 1); - } - else - { - log_info ("Candidates.#%d..: [Copying]", device_id + 1); - } - - continue; - } - - const u32 outerloop_first = 0; - const u32 outerloop_last = device_param->outerloop_left - 1; - - const u32 innerloop_first = 0; - const u32 innerloop_last = device_param->innerloop_left - 1; - - plain_t plain1 = { 0, 0, 0, outerloop_first, innerloop_first }; - plain_t plain2 = { 0, 0, 0, outerloop_last, innerloop_last }; - - u32 plain_buf1[16] = { 0 }; - u32 plain_buf2[16] = { 0 }; - - u8 *plain_ptr1 = (u8 *) plain_buf1; - u8 *plain_ptr2 = (u8 *) plain_buf2; - - int plain_len1 = 0; - int plain_len2 = 0; - - build_plain (hashcat_ctx, device_param, &plain1, plain_buf1, &plain_len1); - build_plain (hashcat_ctx, device_param, &plain2, plain_buf2, &plain_len2); - - bool need_hex1 = need_hexify (plain_ptr1, plain_len1); - bool need_hex2 = need_hexify (plain_ptr2, plain_len2); - - if ((need_hex1 == true) || (need_hex2 == true)) - { - exec_hexify (plain_ptr1, plain_len1, plain_ptr1); - exec_hexify (plain_ptr2, plain_len2, plain_ptr2); - - plain_ptr1[plain_len1 * 2] = 0; - plain_ptr2[plain_len2 * 2] = 0; - - log_info ("Candidates.#%d..: $HEX[%s] -> $HEX[%s]", device_id + 1, plain_ptr1, plain_ptr2); - } - else - { - log_info ("Candidates.#%d..: %s -> %s", device_id + 1, plain_ptr1, plain_ptr2); - } - } + progress_cur_relative_skip = progress_cur - progress_skip; } + return progress_cur_relative_skip; +} + +u64 status_get_progress_end_relative_skip (const hashcat_ctx_t *hashcat_ctx) +{ + const u64 progress_skip = status_get_progress_skip (hashcat_ctx); + const u64 progress_end = status_get_progress_end (hashcat_ctx); + + u64 progress_end_relative_skip = 0; + + if (progress_end > 0) + { + progress_end_relative_skip = progress_end - progress_skip; + } + + return progress_end_relative_skip; +} + +double status_get_hashes_msec_all (const hashcat_ctx_t *hashcat_ctx) +{ + const opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + double hashes_all_msec = 0; + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) { - hc_device_param_t *device_param = &opencl_ctx->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 ((double) 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]); + hashes_all_msec += status_get_hashes_msec_dev (hashcat_ctx, device_id); } - char display_all_cur[16] = { 0 }; + return hashes_all_msec; +} - strncpy (display_all_cur, "0.00", 4); +double status_get_hashes_msec_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id) +{ + const opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - format_speed_display ((double) hashes_all_ms * 1000, display_all_cur, sizeof (display_all_cur)); + u64 speed_cnt = 0; + double speed_msec = 0; - if (opencl_ctx->devices_active > 1) log_info ("Speed.Dev.#*...: %9sH/s", display_all_cur); + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - const double digests_percent = (double) hashes->digests_done / hashes->digests_cnt; - const double salts_percent = (double) hashes->salts_done / hashes->salts_cnt; - - log_info ("Recovered......: %u/%u (%.2f%%) Digests, %u/%u (%.2f%%) Salts", hashes->digests_done, hashes->digests_cnt, digests_percent * 100, hashes->salts_done, hashes->salts_cnt, salts_percent * 100); - - // crack-per-time - - if (hashes->digests_cnt > 100) + if (device_param->skipped == false) { - 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++) + for (int i = 0; i < SPEED_CACHE; i++) { - const u32 cracked = cpt_ctx->cpt_buf[i].cracked; - const time_t timestamp = cpt_ctx->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) cpt_ctx->cpt_total / ((ms_real / 1000) / 60); - double cpt_avg_hour = (double) cpt_ctx->cpt_total / ((ms_real / 1000) / 3600); - double cpt_avg_day = (double) cpt_ctx->cpt_total / ((ms_real / 1000) / 86400); - - if ((cpt_ctx->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 ((cpt_ctx->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 ((cpt_ctx->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); + speed_cnt += device_param->speed_cnt[i]; + speed_msec += device_param->speed_msec[i]; } } - // Restore point + speed_cnt /= SPEED_CACHE; + speed_msec /= SPEED_CACHE; - u64 restore_point = get_lowest_words_done (hashcat_ctx); + double hashes_dev_msec = 0; - u64 restore_total = status_ctx->words_base; - - double percent_restore = 0; - - if (restore_total != 0) percent_restore = (double) restore_point / (double) restore_total; - - if (progress_end_relative_skip) + if (speed_msec > 0) { - if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) + hashes_dev_msec = (double) speed_cnt / speed_msec; + } + + return hashes_dev_msec; +} + +double status_get_hashes_msec_dev_benchmark (const hashcat_ctx_t *hashcat_ctx, const int device_id) +{ + // this function increases accuracy for benchmark modes + + const opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + u64 speed_cnt = 0; + double speed_msec = 0; + + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + if (device_param->skipped == false) + { + speed_cnt += device_param->speed_cnt[0]; + speed_msec += device_param->speed_msec[0]; + } + + double hashes_dev_msec = 0; + + if (speed_msec > 0) + { + hashes_dev_msec = (double) speed_cnt / speed_msec; + } + + return hashes_dev_msec; +} + +double status_get_exec_msec_all (const hashcat_ctx_t *hashcat_ctx) +{ + const opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + double exec_all_msec = 0; + + for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + { + exec_all_msec += status_get_exec_msec_dev (hashcat_ctx, device_id); + } + + return exec_all_msec; +} + +double status_get_exec_msec_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id) +{ + const opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; + + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + double exec_dev_msec = 0; + + if (device_param->skipped == false) + { + exec_dev_msec = get_avg_exec_time (device_param, EXEC_CACHE); + } + + return exec_dev_msec; +} + +char *status_get_speed_sec_all (const hashcat_ctx_t *hashcat_ctx) +{ + const double hashes_msec_all = status_get_hashes_msec_all (hashcat_ctx); + + char *display = (char *) malloc (HCBUFSIZ_TINY); + + format_speed_display (hashes_msec_all * 1000, display, HCBUFSIZ_TINY); + + return display; +} + +char *status_get_speed_sec_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id) +{ + const double hashes_msec_dev = status_get_hashes_msec_dev (hashcat_ctx, device_id); + + char *display = (char *) malloc (HCBUFSIZ_TINY); + + format_speed_display (hashes_msec_dev * 1000, display, HCBUFSIZ_TINY); + + return display; +} + +int status_get_cpt_cur_min (const hashcat_ctx_t *hashcat_ctx) +{ + const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; + + const time_t now = time (NULL); + + int cpt_cur_min = 0; + + for (int i = 0; i < CPT_BUF; i++) + { + const u32 cracked = cpt_ctx->cpt_buf[i].cracked; + const time_t timestamp = cpt_ctx->cpt_buf[i].timestamp; + + if ((timestamp + 60) > now) { - 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 (user_options->restore_disable == false) - { - if (percent_finished != 1) - { - log_info ("Restore.Point..: %" PRIu64 "/%" PRIu64 " (%.02f%%)", restore_point, restore_total, percent_restore * 100); - } - } + cpt_cur_min += cracked; } } + + return cpt_cur_min; +} + +int status_get_cpt_cur_hour (const hashcat_ctx_t *hashcat_ctx) +{ + const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; + + const time_t now = time (NULL); + + int cpt_cur_hour = 0; + + for (int i = 0; i < CPT_BUF; i++) + { + const u32 cracked = cpt_ctx->cpt_buf[i].cracked; + const time_t timestamp = cpt_ctx->cpt_buf[i].timestamp; + + if ((timestamp + 3600) > now) + { + cpt_cur_hour += cracked; + } + } + + return cpt_cur_hour; +} + +int status_get_cpt_cur_day (const hashcat_ctx_t *hashcat_ctx) +{ + const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; + + const time_t now = time (NULL); + + int cpt_cur_day = 0; + + for (int i = 0; i < CPT_BUF; i++) + { + const u32 cracked = cpt_ctx->cpt_buf[i].cracked; + const time_t timestamp = cpt_ctx->cpt_buf[i].timestamp; + + if ((timestamp + 86400) > now) + { + cpt_cur_day += cracked; + } + } + + return cpt_cur_day; +} + +double status_get_cpt_avg_min (const hashcat_ctx_t *hashcat_ctx) +{ + const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; + + const double msec_real = status_get_msec_real (hashcat_ctx); + + const double cpt_avg_min = (double) cpt_ctx->cpt_total / ((msec_real / 1000) / 60); + + return cpt_avg_min; +} + +double status_get_cpt_avg_hour (const hashcat_ctx_t *hashcat_ctx) +{ + const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; + + const double msec_real = status_get_msec_real (hashcat_ctx); + + const double cpt_avg_hour = (double) cpt_ctx->cpt_total / ((msec_real / 1000) / 3600); + + return cpt_avg_hour; +} + +double status_get_cpt_avg_day (const hashcat_ctx_t *hashcat_ctx) +{ + const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; + + const double msec_real = status_get_msec_real (hashcat_ctx); + + const double cpt_avg_day = (double) cpt_ctx->cpt_total / ((msec_real / 1000) / 86400); + + return cpt_avg_day; +} + +char *status_get_cpt (const hashcat_ctx_t *hashcat_ctx) +{ + const cpt_ctx_t *cpt_ctx = hashcat_ctx->cpt_ctx; + + const time_t now = time (NULL); + + char *cpt = (char *) malloc (HCBUFSIZ_TINY); + + const int cpt_cur_min = status_get_cpt_cur_min (hashcat_ctx); + const int cpt_cur_hour = status_get_cpt_cur_hour (hashcat_ctx); + const int cpt_cur_day = status_get_cpt_cur_day (hashcat_ctx); + + const double cpt_avg_min = status_get_cpt_avg_min (hashcat_ctx); + const double cpt_avg_hour = status_get_cpt_avg_hour (hashcat_ctx); + const double cpt_avg_day = status_get_cpt_avg_day (hashcat_ctx); + + if ((cpt_ctx->cpt_start + 86400) < now) + { + snprintf (cpt, HCBUFSIZ_TINY - 1, "CUR:%u,%u,%u 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 ((cpt_ctx->cpt_start + 3600) < now) + { + snprintf (cpt, HCBUFSIZ_TINY - 1, "CUR:%u,%u,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 ((cpt_ctx->cpt_start + 60) < now) + { + snprintf (cpt, HCBUFSIZ_TINY - 1, "CUR:%u,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 { - if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) - { - log_info ("Progress.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); - log_info ("Rejected.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); - - if (user_options->restore_disable == false) - { - 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 (user_options->restore_disable == false) - //{ - // log_info ("Restore.Point..: %" PRIu64 "", restore_point); - //} - } + snprintf (cpt, HCBUFSIZ_TINY - 1, "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); } - if (status_ctx->run_main_level1 == false) return; - - if (user_options->gpu_temp_disable == false) - { - hc_thread_mutex_lock (status_ctx->mux_hwmon); - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; - - if (device_param->skipped) continue; - - const int num_temperature = hm_get_temperature_with_device_id (hashcat_ctx, device_id); - const int num_fanspeed = hm_get_fanspeed_with_device_id (hashcat_ctx, device_id); - const int num_utilization = hm_get_utilization_with_device_id (hashcat_ctx, device_id); - const int num_corespeed = hm_get_corespeed_with_device_id (hashcat_ctx, device_id); - const int num_memoryspeed = hm_get_memoryspeed_with_device_id (hashcat_ctx, device_id); - const int num_buslanes = hm_get_buslanes_with_device_id (hashcat_ctx, device_id); - const int num_throttle = hm_get_throttle_with_device_id (hashcat_ctx, 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 (status_ctx->mux_hwmon); - } + return cpt; } -void status_benchmark_automate (hashcat_ctx_t *hashcat_ctx) +char *status_get_hwmon_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id) { - hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + const opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - if (status_ctx->devices_status == STATUS_INIT) + hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + + char *output_buf = (char *) malloc (HCBUFSIZ_TINY); + + snprintf (output_buf, HCBUFSIZ_TINY - 1, "N/A"); + + if (device_param->skipped == true) return output_buf; + + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + hc_thread_mutex_lock (status_ctx->mux_hwmon); + + const int num_temperature = hm_get_temperature_with_device_id ((hashcat_ctx_t *) hashcat_ctx, device_id); + const int num_fanspeed = hm_get_fanspeed_with_device_id ((hashcat_ctx_t *) hashcat_ctx, device_id); + const int num_utilization = hm_get_utilization_with_device_id ((hashcat_ctx_t *) hashcat_ctx, device_id); + const int num_corespeed = hm_get_corespeed_with_device_id ((hashcat_ctx_t *) hashcat_ctx, device_id); + const int num_memoryspeed = hm_get_memoryspeed_with_device_id ((hashcat_ctx_t *) hashcat_ctx, device_id); + const int num_buslanes = hm_get_buslanes_with_device_id ((hashcat_ctx_t *) hashcat_ctx, device_id); + const int num_throttle = hm_get_throttle_with_device_id ((hashcat_ctx_t *) hashcat_ctx, device_id); + + int output_len = 0; + + if (num_temperature >= 0) { - log_error ("ERROR: status view is not available during initialization phase"); + snprintf (output_buf + output_len, HCBUFSIZ_TINY - output_len, "Temp:%3uc ", num_temperature); - return; + output_len = strlen (output_buf); } - if (status_ctx->devices_status == STATUS_AUTOTUNE) + if (num_fanspeed >= 0) { - log_error ("ERROR: status view is not available during autotune phase"); + snprintf (output_buf + output_len, HCBUFSIZ_TINY - output_len, "Fan:%3u%% ", num_fanspeed); - return; + output_len = strlen (output_buf); } - u64 speed_cnt[DEVICES_MAX] = { 0 }; - double speed_ms[DEVICES_MAX] = { 0 }; - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + if (num_utilization >= 0) { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + snprintf (output_buf + output_len, HCBUFSIZ_TINY - output_len, "Util:%3u%% ", num_utilization); - if (device_param->skipped) continue; - - speed_cnt[device_id] = device_param->speed_cnt[0]; - speed_ms[device_id] = device_param->speed_ms[0]; + output_len = strlen (output_buf); } - u64 hashes_dev_ms[DEVICES_MAX] = { 0 }; - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + if (num_corespeed >= 0) { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + snprintf (output_buf + output_len, HCBUFSIZ_TINY - output_len, "Core:%4uMhz ", num_corespeed); - 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]; - } + output_len = strlen (output_buf); } - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + if (num_memoryspeed >= 0) { - hc_device_param_t *device_param = &opencl_ctx->devices_param[device_id]; + snprintf (output_buf + output_len, HCBUFSIZ_TINY - output_len, "Mem:%4uMhz ", num_memoryspeed); - if (device_param->skipped) continue; - - log_info ("%u:%u:%" PRIu64 "", device_id + 1, hashconfig->hash_mode, (hashes_dev_ms[device_id] * 1000)); - } -} - -void status_benchmark (hashcat_ctx_t *hashcat_ctx) -{ - opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - user_options_t *user_options = hashcat_ctx->user_options; - - if (status_ctx->devices_status == STATUS_INIT) - { - log_error ("ERROR: status view is not available during initialization phase"); - - return; + output_len = strlen (output_buf); } - if (status_ctx->devices_status == STATUS_AUTOTUNE) + if (num_buslanes >= 0) { - log_error ("ERROR: status view is not available during autotune phase"); + snprintf (output_buf + output_len, HCBUFSIZ_TINY - output_len, "Lanes:%u ", num_buslanes); - return; + output_len = strlen (output_buf); } - if (status_ctx->shutdown_inner == 1) return; - - if (user_options->machine_readable == true) + if (num_throttle >= 0) { - status_benchmark_automate (hashcat_ctx); + snprintf (output_buf + output_len, HCBUFSIZ_TINY - output_len, "*Throttled* "); - return; + output_len = strlen (output_buf); } - u64 speed_cnt[DEVICES_MAX] = { 0 }; - double speed_ms[DEVICES_MAX] = { 0 }; - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) + if (output_len > 0) { - hc_device_param_t *device_param = &opencl_ctx->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]; + output_buf[output_len - 1] = 0; } - double hashes_all_ms = 0; + hc_thread_mutex_unlock (status_ctx->mux_hwmon); - double hashes_dev_ms[DEVICES_MAX] = { 0 }; - - for (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->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 (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->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 (u32 device_id = 0; device_id < opencl_ctx->devices_cnt; device_id++) - { - hc_device_param_t *device_param = &opencl_ctx->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 ((double) hashes_dev_ms[device_id] * 1000, display_dev_cur, sizeof (display_dev_cur)); - - if (opencl_ctx->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 ((double) hashes_all_ms * 1000, display_all_cur, sizeof (display_all_cur)); - - if (opencl_ctx->devices_active > 1) log_info ("Speed.Dev.#*.: %9sH/s", display_all_cur); + return output_buf; } int status_progress_init (hashcat_ctx_t *hashcat_ctx) @@ -1350,9 +1480,9 @@ int status_progress_init (hashcat_ctx_t *hashcat_ctx) status_ctx_t *status_ctx = hashcat_ctx->status_ctx; hashes_t *hashes = hashcat_ctx->hashes; - status_ctx->words_progress_done = (u64 *) mycalloc (hashes->salts_cnt, sizeof (u64)); - status_ctx->words_progress_rejected = (u64 *) mycalloc (hashes->salts_cnt, sizeof (u64)); - status_ctx->words_progress_restored = (u64 *) mycalloc (hashes->salts_cnt, sizeof (u64)); + status_ctx->words_progress_done = (u64 *) hccalloc (hashcat_ctx, hashes->salts_cnt, sizeof (u64)); VERIFY_PTR (status_ctx->words_progress_done); + status_ctx->words_progress_rejected = (u64 *) hccalloc (hashcat_ctx, hashes->salts_cnt, sizeof (u64)); VERIFY_PTR (status_ctx->words_progress_rejected); + status_ctx->words_progress_restored = (u64 *) hccalloc (hashcat_ctx, hashes->salts_cnt, sizeof (u64)); VERIFY_PTR (status_ctx->words_progress_restored); return 0; } @@ -1361,9 +1491,9 @@ void status_progress_destroy (hashcat_ctx_t *hashcat_ctx) { status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - myfree (status_ctx->words_progress_done); - myfree (status_ctx->words_progress_rejected); - myfree (status_ctx->words_progress_restored); + hcfree (status_ctx->words_progress_done); + hcfree (status_ctx->words_progress_rejected); + hcfree (status_ctx->words_progress_restored); status_ctx->words_progress_done = NULL; status_ctx->words_progress_rejected = NULL; diff --git a/src/stdout.c b/src/stdout.c index 1ebf39c46..a7020f18b 100644 --- a/src/stdout.c +++ b/src/stdout.c @@ -5,7 +5,7 @@ #include "common.h" #include "types.h" -#include "logging.h" +#include "event.h" #include "locking.h" #include "rp_kernel_on_cpu.h" #include "mpsp.h" @@ -35,7 +35,7 @@ static void out_push (out_t *out, const u8 *pw_buf, const int pw_len) } } -void process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 pws_cnt) +int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 pws_cnt) { combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; hashconfig_t *hashconfig = hashcat_ctx->hashconfig; @@ -56,11 +56,13 @@ void process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param { if ((out.fp = fopen (filename, "ab")) != NULL) { - lock_file (out.fp); + const int rc = lock_file (out.fp); + + if (rc == -1) return -1; } else { - log_error ("ERROR: %s: %s", filename, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", filename, strerror (errno)); out.fp = stdout; } @@ -82,7 +84,9 @@ void process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param for (u32 gidvid = 0; gidvid < pws_cnt; gidvid++) { - gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + + if (rc == -1) return -1; const u32 pos = device_param->innerloop_pos; @@ -109,7 +113,9 @@ void process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param for (u32 gidvid = 0; gidvid < pws_cnt; gidvid++) { - gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + + if (rc == -1) return -1; for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { @@ -175,7 +181,9 @@ void process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param for (u32 gidvid = 0; gidvid < pws_cnt; gidvid++) { - gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + + if (rc == -1) return -1; for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { @@ -205,7 +213,9 @@ void process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param for (u32 gidvid = 0; gidvid < pws_cnt; gidvid++) { - gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw); + + if (rc == -1) return -1; for (u32 il_pos = 0; il_pos < il_cnt; il_pos++) { @@ -240,4 +250,6 @@ void process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param fclose (out.fp); } + + return 0; } diff --git a/src/straight.c b/src/straight.c index b00981a4f..5b2af2e43 100644 --- a/src/straight.c +++ b/src/straight.c @@ -10,7 +10,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "logfile.h" #include "shared.h" #include "filehandling.h" @@ -20,18 +20,22 @@ #include "straight.h" #include "wordlist.h" -static void straight_ctx_add_wl (straight_ctx_t *straight_ctx, const char *dict) +static int straight_ctx_add_wl (hashcat_ctx_t *hashcat_ctx, const char *dict) { + straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; + if (straight_ctx->dicts_avail == straight_ctx->dicts_cnt) { - straight_ctx->dicts = (char **) myrealloc (straight_ctx->dicts, straight_ctx->dicts_avail * sizeof (char *), INCR_DICTS * sizeof (char *)); + straight_ctx->dicts = (char **) hcrealloc (hashcat_ctx, straight_ctx->dicts, straight_ctx->dicts_avail * sizeof (char *), INCR_DICTS * sizeof (char *)); VERIFY_PTR (straight_ctx->dicts); straight_ctx->dicts_avail += INCR_DICTS; } - straight_ctx->dicts[straight_ctx->dicts_cnt] = mystrdup (dict); + straight_ctx->dicts[straight_ctx->dicts_cnt] = hcstrdup (hashcat_ctx, dict); VERIFY_PTR (straight_ctx->dicts[straight_ctx->dicts_cnt]); straight_ctx->dicts_cnt++; + + return 0; } int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) @@ -69,7 +73,7 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) if (fd2 == NULL) { - log_error ("ERROR: %s: %s", straight_ctx->dict, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", straight_ctx->dict, strerror (errno)); return -1; } @@ -97,7 +101,7 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) if (fd2 == NULL) { - log_error ("ERROR: %s: %s", combinator_ctx->dict1, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", combinator_ctx->dict1, strerror (errno)); return -1; } @@ -112,7 +116,7 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) if (fd2 == NULL) { - log_error ("ERROR: %s: %s", combinator_ctx->dict2, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", combinator_ctx->dict2, strerror (errno)); return -1; } @@ -151,7 +155,7 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) if (fd2 == NULL) { - log_error ("ERROR: %s: %s", straight_ctx->dict, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", straight_ctx->dict, strerror (errno)); return -1; } @@ -196,7 +200,7 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) if ((user_options->rp_files_cnt == 0) && (user_options->rp_gen == 0)) { - straight_ctx->kernel_rules_buf = (kernel_rule_t *) mymalloc (sizeof (kernel_rule_t)); + straight_ctx->kernel_rules_buf = (kernel_rule_t *) hcmalloc (hashcat_ctx, sizeof (kernel_rule_t)); VERIFY_PTR (straight_ctx->kernel_rules_buf); straight_ctx->kernel_rules_buf[0].cmds[0] = RULE_OP_MANGLE_NOOP; @@ -272,7 +276,7 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) if (stat (l0_filename, &l0_stat) == -1) { - log_error ("ERROR: %s: %s", l0_filename, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", l0_filename, strerror (errno)); return -1; } @@ -281,7 +285,7 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) { char **dictionary_files = NULL; - dictionary_files = scan_directory (l0_filename); + dictionary_files = scan_directory (hashcat_ctx, l0_filename); if (dictionary_files != NULL) { @@ -295,29 +299,33 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) if (stat (l1_filename, &l1_stat) == -1) { - log_error ("ERROR: %s: %s", l1_filename, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", l1_filename, strerror (errno)); return -1; } if (S_ISREG (l1_stat.st_mode)) { - straight_ctx_add_wl (straight_ctx, l1_filename); + const int rc = straight_ctx_add_wl (hashcat_ctx, l1_filename); + + if (rc == -1) return -1; } } } - myfree (dictionary_files); + hcfree (dictionary_files); } else { - straight_ctx_add_wl (straight_ctx, l0_filename); + const int rc = straight_ctx_add_wl (hashcat_ctx, l0_filename); + + if (rc == -1) return -1; } } if (straight_ctx->dicts_cnt == 0) { - log_error ("ERROR: No usable dictionary file found."); + event_log_error (hashcat_ctx, "No usable dictionary file found."); return -1; } @@ -341,7 +349,7 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) if (stat (l0_filename, &l0_stat) == -1) { - log_error ("ERROR: %s: %s", l0_filename, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", l0_filename, strerror (errno)); return -1; } @@ -350,7 +358,7 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) { char **dictionary_files = NULL; - dictionary_files = scan_directory (l0_filename); + dictionary_files = scan_directory (hashcat_ctx, l0_filename); if (dictionary_files != NULL) { @@ -364,29 +372,33 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) if (stat (l1_filename, &l1_stat) == -1) { - log_error ("ERROR: %s: %s", l1_filename, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", l1_filename, strerror (errno)); return -1; } if (S_ISREG (l1_stat.st_mode)) { - straight_ctx_add_wl (straight_ctx, l1_filename); + const int rc = straight_ctx_add_wl (hashcat_ctx, l1_filename); + + if (rc == -1) return -1; } } } - myfree (dictionary_files); + hcfree (dictionary_files); } else { - straight_ctx_add_wl (straight_ctx, l0_filename); + const int rc = straight_ctx_add_wl (hashcat_ctx, l0_filename); + + if (rc == -1) return -1; } } if (straight_ctx->dicts_cnt == 0) { - log_error ("ERROR: No usable dictionary file found."); + event_log_error (hashcat_ctx, "No usable dictionary file found."); return -1; } @@ -401,7 +413,7 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) if (stat (l0_filename, &l0_stat) == -1) { - log_error ("ERROR: %s: %s", l0_filename, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", l0_filename, strerror (errno)); return -1; } @@ -410,7 +422,7 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) { char **dictionary_files = NULL; - dictionary_files = scan_directory (l0_filename); + dictionary_files = scan_directory (hashcat_ctx, l0_filename); if (dictionary_files != NULL) { @@ -424,29 +436,33 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) if (stat (l1_filename, &l1_stat) == -1) { - log_error ("ERROR: %s: %s", l1_filename, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", l1_filename, strerror (errno)); return -1; } if (S_ISREG (l1_stat.st_mode)) { - straight_ctx_add_wl (straight_ctx, l1_filename); + const int rc = straight_ctx_add_wl (hashcat_ctx, l1_filename); + + if (rc == -1) return -1; } } } - myfree (dictionary_files); + hcfree (dictionary_files); } else { - straight_ctx_add_wl (straight_ctx, l0_filename); + const int rc = straight_ctx_add_wl (hashcat_ctx, l0_filename); + + if (rc == -1) return -1; } } if (straight_ctx->dicts_cnt == 0) { - log_error ("ERROR: No usable dictionary file found."); + event_log_error (hashcat_ctx, "No usable dictionary file found."); return -1; } @@ -463,12 +479,12 @@ void straight_ctx_destroy (hashcat_ctx_t *hashcat_ctx) for (u32 dict_pos = 0; dict_pos < straight_ctx->dicts_cnt; dict_pos++) { - myfree (straight_ctx->dicts[dict_pos]); + hcfree (straight_ctx->dicts[dict_pos]); } - myfree (straight_ctx->dicts); + hcfree (straight_ctx->dicts); - myfree (straight_ctx->kernel_rules_buf); + hcfree (straight_ctx->kernel_rules_buf); memset (straight_ctx, 0, sizeof (straight_ctx_t)); } diff --git a/src/terminal.c b/src/terminal.c index db519f94a..c09f953e5 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -5,13 +5,19 @@ #include "common.h" #include "types.h" -#include "logging.h" +#include "memory.h" +#include "event.h" +#include "convert.h" #include "thread.h" #include "timer.h" #include "status.h" #include "restore.h" #include "shared.h" +#include "hwmon.h" +#include "interface.h" +#include "outfile.h" #include "terminal.h" +#include "hashcat.h" const char *PROMPT = "[s]tatus [p]ause [r]esume [b]ypass [c]heckpoint [q]uit => "; @@ -29,23 +35,28 @@ void welcome_screen (hashcat_ctx_t *hashcat_ctx, const time_t proc_start, const { if (user_options->machine_readable == false) { - log_info ("%s (%s) starting in benchmark-mode...", PROGNAME, version_tag); - log_info (""); + event_log_info (hashcat_ctx, "%s (%s) starting in benchmark mode...", PROGNAME, version_tag); + event_log_info (hashcat_ctx, ""); } else { - log_info ("# %s (%s) %s", PROGNAME, version_tag, ctime (&proc_start)); + event_log_info (hashcat_ctx, "# %s (%s) %s", PROGNAME, version_tag, ctime (&proc_start)); } } else if (user_options->restore == true) { - log_info ("%s (%s) starting in restore-mode...", PROGNAME, version_tag); - log_info (""); + event_log_info (hashcat_ctx, "%s (%s) starting in restore mode...", PROGNAME, version_tag); + event_log_info (hashcat_ctx, ""); + } + else if (user_options->speed_only == true) + { + event_log_info (hashcat_ctx, "%s (%s) starting in speed-only mode...", PROGNAME, version_tag); + event_log_info (hashcat_ctx, ""); } else { - log_info ("%s (%s) starting...", PROGNAME, version_tag); - log_info (""); + event_log_info (hashcat_ctx, "%s (%s) starting...", PROGNAME, version_tag); + event_log_info (hashcat_ctx, ""); } } @@ -59,32 +70,32 @@ void goodbye_screen (hashcat_ctx_t *hashcat_ctx, const time_t proc_start, const if (user_options->show == true) return; if (user_options->left == true) return; - log_info_nn ("Started: %s", ctime (&proc_start)); - log_info_nn ("Stopped: %s", ctime (&proc_stop)); + event_log_info_nn (hashcat_ctx, "Started: %s", ctime (&proc_start)); + event_log_info_nn (hashcat_ctx, "Stopped: %s", ctime (&proc_stop)); } -int setup_console () +int setup_console (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx) { #if defined (_WIN) SetConsoleWindowSize (132); if (_setmode (_fileno (stdin), _O_BINARY) == -1) { - log_error ("ERROR: %s: %s", "stdin", strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", "stdin", strerror (errno)); return -1; } if (_setmode (_fileno (stdout), _O_BINARY) == -1) { - log_error ("ERROR: %s: %s", "stdout", strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", "stdout", strerror (errno)); return -1; } if (_setmode (_fileno (stderr), _O_BINARY) == -1) { - log_error ("ERROR: %s: %s", "stderr", strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", "stderr", strerror (errno)); return -1; } @@ -120,7 +131,7 @@ static void keypress (hashcat_ctx_t *hashcat_ctx) user_options_t *user_options = hashcat_ctx->user_options; // this is required, because some of the variables down there are not initialized at that point - while (status_ctx->devices_status == STATUS_INIT) hc_sleep_ms (100); + while (status_ctx->devices_status == STATUS_INIT) hc_sleep_msec (100); const bool quiet = user_options->quiet; @@ -141,7 +152,7 @@ static void keypress (hashcat_ctx_t *hashcat_ctx) hc_thread_mutex_lock (status_ctx->mux_display); - log_info (""); + event_log_info (hashcat_ctx, ""); switch (ch) { @@ -149,11 +160,11 @@ static void keypress (hashcat_ctx_t *hashcat_ctx) case '\r': case '\n': - log_info (""); + event_log_info (hashcat_ctx, ""); status_display (hashcat_ctx); - log_info (""); + event_log_info (hashcat_ctx, ""); if (quiet == false) send_prompt (); @@ -161,11 +172,13 @@ static void keypress (hashcat_ctx_t *hashcat_ctx) case 'b': - log_info (""); + event_log_info (hashcat_ctx, ""); - bypass (status_ctx); + bypass (hashcat_ctx); - log_info (""); + event_log_info (hashcat_ctx, "Next dictionary / mask in queue selected, bypassing current one"); + + event_log_info (hashcat_ctx, ""); if (quiet == false) send_prompt (); @@ -173,11 +186,16 @@ static void keypress (hashcat_ctx_t *hashcat_ctx) case 'p': - log_info (""); + event_log_info (hashcat_ctx, ""); - SuspendThreads (status_ctx); + SuspendThreads (hashcat_ctx); - log_info (""); + if (status_ctx->devices_status == STATUS_PAUSED) + { + event_log_info (hashcat_ctx, "Paused"); + } + + event_log_info (hashcat_ctx, ""); if (quiet == false) send_prompt (); @@ -185,11 +203,16 @@ static void keypress (hashcat_ctx_t *hashcat_ctx) case 'r': - log_info (""); + event_log_info (hashcat_ctx, ""); - ResumeThreads (status_ctx); + ResumeThreads (hashcat_ctx); - log_info (""); + if (status_ctx->devices_status == STATUS_RUNNING) + { + event_log_info (hashcat_ctx, "Resumed"); + } + + event_log_info (hashcat_ctx, ""); if (quiet == false) send_prompt (); @@ -197,11 +220,11 @@ static void keypress (hashcat_ctx_t *hashcat_ctx) case 'c': - log_info (""); + event_log_info (hashcat_ctx, ""); stop_at_checkpoint (hashcat_ctx); - log_info (""); + event_log_info (hashcat_ctx, ""); if (quiet == false) send_prompt (); @@ -209,9 +232,9 @@ static void keypress (hashcat_ctx_t *hashcat_ctx) case 'q': - log_info (""); + event_log_info (hashcat_ctx, ""); - myabort (status_ctx); + myquit (hashcat_ctx); break; } @@ -422,3 +445,466 @@ int tty_fix() return 0; } #endif + +void status_display_machine_readable (hashcat_ctx_t *hashcat_ctx) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + hashcat_status_t *hashcat_status = (hashcat_status_t *) hcmalloc (hashcat_ctx, sizeof (hashcat_status_t)); + + const int rc_status = hashcat_get_status (hashcat_ctx, hashcat_status); + + if (rc_status == -1) + { + hcfree (hashcat_status); + + return; + } + + printf ("STATUS\t%u\t", hashcat_status->status_number); + + printf ("SPEED\t"); + + for (int device_id = 0; device_id < hashcat_status->device_info_cnt; device_id++) + { + const device_info_t *device_info = hashcat_status->device_info_buf + device_id; + + if (device_info->skipped_dev == true) continue; + + printf ("%" PRIu64 "\t", (u64) device_info->hashes_msec_dev); + + // that 1\t is for backward compatibility + printf ("1\t"); + } + + printf ("EXEC_RUNTIME\t"); + + for (int device_id = 0; device_id < hashcat_status->device_info_cnt; device_id++) + { + const device_info_t *device_info = hashcat_status->device_info_buf + device_id; + + if (device_info->skipped_dev == true) continue; + + printf ("%f\t", device_info->exec_msec_dev); + } + + printf ("CURKU\t%" PRIu64 "\t", hashcat_status->restore_point); + + printf ("PROGRESS\t%" PRIu64 "\t%" PRIu64 "\t", hashcat_status->progress_cur_relative_skip, hashcat_status->progress_end_relative_skip); + + printf ("RECHASH\t%u\t%u\t", hashcat_status->digests_done, hashcat_status->digests_cnt); + + printf ("RECSALT\t%u\t%u\t", hashcat_status->salts_done, hashcat_status->salts_cnt); + + if (user_options->gpu_temp_disable == false) + { + printf ("TEMP\t"); + + for (int device_id = 0; device_id < hashcat_status->device_info_cnt; device_id++) + { + const device_info_t *device_info = hashcat_status->device_info_buf + device_id; + + if (device_info->skipped_dev == true) continue; + + // ok, little cheat here... + + const int temp = hm_get_temperature_with_device_id (hashcat_ctx, device_id); + + printf ("%d\t", temp); + } + } + + printf (EOL); + + fflush (stdout); + + hcfree (hashcat_status); +} + +void status_display (hashcat_ctx_t *hashcat_ctx) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->machine_readable == true) + { + status_display_machine_readable (hashcat_ctx); + + return; + } + + hashcat_status_t *hashcat_status = (hashcat_status_t *) hcmalloc (hashcat_ctx, sizeof (hashcat_status_t)); + + const int rc_status = hashcat_get_status (hashcat_ctx, hashcat_status); + + if (rc_status == -1) + { + hcfree (hashcat_status); + + return; + } + + /** + * show something + */ + + event_log_info (hashcat_ctx, + "Session........: %s", + hashcat_status->session); + + event_log_info (hashcat_ctx, + "Status.........: %s", + hashcat_status->status_string); + + event_log_info (hashcat_ctx, + "Hash.Type......: %s", + hashcat_status->hash_type); + + event_log_info (hashcat_ctx, + "Hash.Target....: %s", + hashcat_status->hash_target); + + event_log_info (hashcat_ctx, + "Time.Started...: %s (%s)", + hashcat_status->time_started_absolute, + hashcat_status->time_started_relative); + + event_log_info (hashcat_ctx, + "Time.Estimated.: %s (%s)", + hashcat_status->time_estimated_absolute, + hashcat_status->time_estimated_relative); + + switch (hashcat_status->input_mode) + { + case INPUT_MODE_STRAIGHT_FILE: + + event_log_info (hashcat_ctx, + "Input.Base.....: File (%s)", + hashcat_status->input_base); + + break; + + case INPUT_MODE_STRAIGHT_FILE_RULES_FILE: + + event_log_info (hashcat_ctx, + "Input.Base.....: File (%s)", + hashcat_status->input_base); + + event_log_info (hashcat_ctx, + "Input.Mod......: Rules (%s)", + hashcat_status->input_mod); + + break; + + case INPUT_MODE_STRAIGHT_FILE_RULES_GEN: + + event_log_info (hashcat_ctx, + "Input.Base.....: File (%s)", + hashcat_status->input_base); + + event_log_info (hashcat_ctx, + "Input.Mod......: Rules (Generated)"); + + break; + + case INPUT_MODE_STRAIGHT_STDIN: + + event_log_info (hashcat_ctx, + "Input.Base.....: Pipe"); + + break; + + case INPUT_MODE_STRAIGHT_STDIN_RULES_FILE: + + event_log_info (hashcat_ctx, + "Input.Base.....: Pipe"); + + event_log_info (hashcat_ctx, + "Input.Mod......: Rules (%s)", + hashcat_status->input_mod); + + break; + + case INPUT_MODE_STRAIGHT_STDIN_RULES_GEN: + + event_log_info (hashcat_ctx, + "Input.Base.....: Pipe"); + + event_log_info (hashcat_ctx, + "Input.Mod......: Rules (Generated)"); + + break; + + case INPUT_MODE_COMBINATOR_BASE_LEFT: + + event_log_info (hashcat_ctx, + "Input.Base.....: File (%s), Left Side", + hashcat_status->input_base); + + event_log_info (hashcat_ctx, + "Input.Mod......: File (%s), Right Side", + hashcat_status->input_mod); + + break; + + case INPUT_MODE_COMBINATOR_BASE_RIGHT: + + event_log_info (hashcat_ctx, + "Input.Base.....: File (%s), Right Side", + hashcat_status->input_base); + + event_log_info (hashcat_ctx, + "Input.Mod......: File (%s), Left Side", + hashcat_status->input_mod); + + break; + + case INPUT_MODE_MASK: + + event_log_info (hashcat_ctx, + "Input.Mask.....: %s", + hashcat_status->input_base); + + break; + + case INPUT_MODE_MASK_CS: + + event_log_info (hashcat_ctx, + "Input.Mask.....: %s", + hashcat_status->input_base); + + event_log_info (hashcat_ctx, + "Input.Charset..: %s", + hashcat_status->input_charset); + + break; + + case INPUT_MODE_HYBRID1: + + event_log_info (hashcat_ctx, + "Input.Base.....: File (%s), Left Side", + hashcat_status->input_base); + + event_log_info (hashcat_ctx, + "Input.Mod......: Mask (%s), Right Side", + hashcat_status->input_mod); + + break; + + case INPUT_MODE_HYBRID1_CS: + + event_log_info (hashcat_ctx, + "Input.Base.....: File (%s), Left Side", + hashcat_status->input_base); + + event_log_info (hashcat_ctx, + "Input.Mod......: Mask (%s), Right Side", + hashcat_status->input_mod); + + event_log_info (hashcat_ctx, + "Input.Charset..: %s", + hashcat_status->input_charset); + + break; + + case INPUT_MODE_HYBRID2: + + event_log_info (hashcat_ctx, + "Input.Base.....: File (%s), Right Side", + hashcat_status->input_base); + + event_log_info (hashcat_ctx, + "Input.Mod......: Mask (%s), Left Side", + hashcat_status->input_mod); + + break; + + case INPUT_MODE_HYBRID2_CS: + + event_log_info (hashcat_ctx, + "Input.Base.....: File (%s), Right Side", + hashcat_status->input_base); + + event_log_info (hashcat_ctx, + "Input.Mod......: Mask (%s), Left Side", + hashcat_status->input_mod); + + event_log_info (hashcat_ctx, + "Input.Charset..: %s", + hashcat_status->input_charset); + + break; + } + + for (int device_id = 0; device_id < hashcat_status->device_info_cnt; device_id++) + { + const device_info_t *device_info = hashcat_status->device_info_buf + device_id; + + if (device_info->skipped_dev == true) continue; + + event_log_info (hashcat_ctx, + "Speed.Dev.#%d...: %9sH/s (%0.2fms)", device_id + 1, + device_info->speed_sec_dev, + device_info->exec_msec_dev); + } + + if (hashcat_status->device_info_active > 1) + { + event_log_info (hashcat_ctx, + "Speed.Dev.#*...: %9sH/s", + hashcat_status->speed_sec_all); + } + + event_log_info (hashcat_ctx, + "Recovered......: %u/%u (%.2f%%) Digests, %u/%u (%.2f%%) Salts", + hashcat_status->digests_done, + hashcat_status->digests_cnt, + hashcat_status->digests_percent, + hashcat_status->salts_done, + hashcat_status->salts_cnt, + hashcat_status->salts_percent); + + event_log_info (hashcat_ctx, + "Recovered/Time.: %s", + hashcat_status->cpt); + + switch (hashcat_status->progress_mode) + { + case PROGRESS_MODE_KEYSPACE_KNOWN: + + event_log_info (hashcat_ctx, + "Progress.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", + hashcat_status->progress_cur_relative_skip, + hashcat_status->progress_end_relative_skip, + hashcat_status->progress_finished_percent); + + event_log_info (hashcat_ctx, + "Rejected.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", + hashcat_status->progress_rejected, + hashcat_status->progress_cur_relative_skip, + hashcat_status->progress_rejected_percent); + + event_log_info (hashcat_ctx, + "Restore.Point..: %" PRIu64 "/%" PRIu64 " (%.02f%%)", + hashcat_status->restore_point, + hashcat_status->restore_total, + hashcat_status->restore_percent); + + break; + + case PROGRESS_MODE_KEYSPACE_UNKNOWN: + + event_log_info (hashcat_ctx, + "Progress.......: %" PRIu64, + hashcat_status->progress_cur_relative_skip); + + event_log_info (hashcat_ctx, + "Rejected.......: %" PRIu64, + hashcat_status->progress_rejected); + + event_log_info (hashcat_ctx, + "Restore.Point..: %" PRIu64, + hashcat_status->restore_point); + + break; + } + + for (int device_id = 0; device_id < hashcat_status->device_info_cnt; device_id++) + { + const device_info_t *device_info = hashcat_status->device_info_buf + device_id; + + if (device_info->skipped_dev == true) continue; + + event_log_info (hashcat_ctx, + "Candidates.#%d..: %s", device_id + 1, + device_info->input_candidates_dev); + } + + if (user_options->gpu_temp_disable == false) + { + for (int device_id = 0; device_id < hashcat_status->device_info_cnt; device_id++) + { + const device_info_t *device_info = hashcat_status->device_info_buf + device_id; + + if (device_info->skipped_dev == true) continue; + + event_log_info (hashcat_ctx, + "HWMon.Dev.#%d...: %s", device_id + 1, + device_info->hwmon_dev); + } + } + + hcfree (hashcat_status); +} + +void status_benchmark_automate (hashcat_ctx_t *hashcat_ctx) +{ + hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + + const u32 hash_mode = hashconfig->hash_mode; + + hashcat_status_t *hashcat_status = (hashcat_status_t *) hcmalloc (hashcat_ctx, sizeof (hashcat_status_t)); + + const int rc_status = hashcat_get_status (hashcat_ctx, hashcat_status); + + if (rc_status == -1) + { + hcfree (hashcat_status); + + return; + } + + for (int device_id = 0; device_id < hashcat_status->device_info_cnt; device_id++) + { + const device_info_t *device_info = hashcat_status->device_info_buf + device_id; + + if (device_info->skipped_dev == true) continue; + + event_log_info (hashcat_ctx, "%u:%u:%" PRIu64, device_id + 1, hash_mode, (u64) (device_info->hashes_msec_dev_benchmark * 1000)); + } + + hcfree (hashcat_status); +} + +void status_benchmark (hashcat_ctx_t *hashcat_ctx) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->machine_readable == true) + { + status_benchmark_automate (hashcat_ctx); + + return; + } + + hashcat_status_t *hashcat_status = (hashcat_status_t *) hcmalloc (hashcat_ctx, sizeof (hashcat_status_t)); + + const int rc_status = hashcat_get_status (hashcat_ctx, hashcat_status); + + if (rc_status == -1) + { + hcfree (hashcat_status); + + return; + } + + for (int device_id = 0; device_id < hashcat_status->device_info_cnt; device_id++) + { + const device_info_t *device_info = hashcat_status->device_info_buf + device_id; + + if (device_info->skipped_dev == true) continue; + + event_log_info (hashcat_ctx, + "Speed.Dev.#%d...: %9sH/s (%0.2fms)", device_id + 1, + device_info->speed_sec_dev, + device_info->exec_msec_dev); + } + + if (hashcat_status->device_info_active > 1) + { + event_log_info (hashcat_ctx, + "Speed.Dev.#*...: %9sH/s", + hashcat_status->speed_sec_all); + } + + hcfree (hashcat_status); +} diff --git a/src/thread.c b/src/thread.c index 919e09452..e3cd7e6bc 100644 --- a/src/thread.c +++ b/src/thread.c @@ -6,7 +6,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "timer.h" #include "shared.h" #include "thread.h" @@ -116,8 +116,10 @@ void hc_signal (void (callback) (int)) #endif */ -void mycracked (status_ctx_t *status_ctx) +int mycracked (hashcat_ctx_t *hashcat_ctx) { + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + //if (status_ctx->devices_status != STATUS_RUNNING) return; status_ctx->devices_status = STATUS_CRACKED; @@ -127,11 +129,16 @@ void mycracked (status_ctx_t *status_ctx) status_ctx->run_main_level3 = false; status_ctx->run_thread_level1 = false; status_ctx->run_thread_level2 = false; + + return 0; } -void myabort (status_ctx_t *status_ctx) +int myabort (hashcat_ctx_t *hashcat_ctx) { + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + //those checks create problems in benchmark mode, it's simply too short of a timeframe where it's running as STATUS_RUNNING + // not sure if this is still valid, but abort is also called by gpu temp monitor //if (status_ctx->devices_status != STATUS_RUNNING) return; status_ctx->devices_status = STATUS_ABORTED; @@ -141,11 +148,15 @@ void myabort (status_ctx_t *status_ctx) status_ctx->run_main_level3 = false; status_ctx->run_thread_level1 = false; status_ctx->run_thread_level2 = false; + + return 0; } -void myquit (status_ctx_t *status_ctx) +int myquit (hashcat_ctx_t *hashcat_ctx) { - //if (status_ctx->devices_status != STATUS_RUNNING) return; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + if (status_ctx->devices_status != STATUS_RUNNING) return -1; status_ctx->devices_status = STATUS_QUIT; @@ -154,11 +165,15 @@ void myquit (status_ctx_t *status_ctx) status_ctx->run_main_level3 = false; status_ctx->run_thread_level1 = false; status_ctx->run_thread_level2 = false; + + return 0; } -void bypass (status_ctx_t *status_ctx) +int bypass (hashcat_ctx_t *hashcat_ctx) { - //if (status_ctx->devices_status != STATUS_RUNNING) return; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + if (status_ctx->devices_status != STATUS_RUNNING) return -1; status_ctx->devices_status = STATUS_BYPASS; @@ -168,29 +183,76 @@ void bypass (status_ctx_t *status_ctx) status_ctx->run_thread_level1 = false; status_ctx->run_thread_level2 = false; - log_info ("Next dictionary / mask in queue selected, bypassing current one"); + return 0; } -void SuspendThreads (status_ctx_t *status_ctx) +int SuspendThreads (hashcat_ctx_t *hashcat_ctx) { - if (status_ctx->devices_status != STATUS_RUNNING) return; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + if (status_ctx->devices_status != STATUS_RUNNING) return -1; hc_timer_set (&status_ctx->timer_paused); status_ctx->devices_status = STATUS_PAUSED; - log_info ("Paused"); + return 0; } -void ResumeThreads (status_ctx_t *status_ctx) +int ResumeThreads (hashcat_ctx_t *hashcat_ctx) { - if (status_ctx->devices_status != STATUS_PAUSED) return; + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; - double ms_paused = hc_timer_get (status_ctx->timer_paused); + if (status_ctx->devices_status != STATUS_PAUSED) return -1; - status_ctx->ms_paused += ms_paused; + const double msec_paused = hc_timer_get (status_ctx->timer_paused); + + status_ctx->msec_paused += msec_paused; status_ctx->devices_status = STATUS_RUNNING; - log_info ("Resumed"); + return 0; +} + +int stop_at_checkpoint (hashcat_ctx_t *hashcat_ctx) +{ + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + + if (status_ctx->devices_status != STATUS_RUNNING) return -1; + + // this feature only makes sense if --restore-disable was not specified + + restore_ctx_t *restore_ctx = hashcat_ctx->restore_ctx; + + if (restore_ctx->enabled == false) + { + event_log_warning (hashcat_ctx, "This feature is disabled when --restore-disable is specified"); + + return -1; + } + + // Enable or Disable + + if ((status_ctx->run_thread_level1 == true) && (status_ctx->run_thread_level2 == true)) + { + status_ctx->run_main_level1 = false; + status_ctx->run_main_level2 = false; + status_ctx->run_main_level3 = false; + status_ctx->run_thread_level1 = false; + status_ctx->run_thread_level2 = true; + + event_log_info (hashcat_ctx, "Checkpoint enabled: Will quit at next Restore Point update"); + } + else + { + status_ctx->run_main_level1 = true; + status_ctx->run_main_level2 = true; + status_ctx->run_main_level3 = true; + status_ctx->run_thread_level1 = true; + status_ctx->run_thread_level2 = true; + + event_log_info (hashcat_ctx, "Checkpoint disabled: Restore Point updates will no longer be monitored"); + } + + return 0; } diff --git a/src/tuningdb.c b/src/tuningdb.c index 88968e470..9153d53b1 100644 --- a/src/tuningdb.c +++ b/src/tuningdb.c @@ -7,7 +7,7 @@ #include "types.h" #include "interface.h" #include "timer.h" -#include "logging.h" +#include "event.h" #include "memory.h" #include "filehandling.h" #include "ext_OpenCL.h" @@ -67,7 +67,7 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) tuning_db->enabled = true; - char *tuning_db_file = (char *) mymalloc (HCBUFSIZ_TINY); + char *tuning_db_file = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_TINY); VERIFY_PTR (tuning_db_file); snprintf (tuning_db_file, HCBUFSIZ_TINY - 1, "%s/%s", folder_config->shared_dir, TUNING_DB_FILE); @@ -75,28 +75,28 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) if (fp == NULL) { - log_error ("%s: %s", tuning_db_file, strerror (errno)); + event_log_error (hashcat_ctx, "%s: %s", tuning_db_file, strerror (errno)); return -1; } - myfree (tuning_db_file); + hcfree (tuning_db_file); - int num_lines = count_lines (fp); + int num_lines = count_lines (hashcat_ctx, fp); // a bit over-allocated - tuning_db->alias_buf = (tuning_db_alias_t *) mycalloc (num_lines + 1, sizeof (tuning_db_alias_t)); + tuning_db->alias_buf = (tuning_db_alias_t *) hccalloc (hashcat_ctx, num_lines + 1, sizeof (tuning_db_alias_t)); VERIFY_PTR (tuning_db->alias_buf); tuning_db->alias_cnt = 0; - tuning_db->entry_buf = (tuning_db_entry_t *) mycalloc (num_lines + 1, sizeof (tuning_db_entry_t)); + tuning_db->entry_buf = (tuning_db_entry_t *) hccalloc (hashcat_ctx, num_lines + 1, sizeof (tuning_db_entry_t)); VERIFY_PTR (tuning_db->entry_buf); tuning_db->entry_cnt = 0; rewind (fp); int line_num = 0; - char *buf = (char *) mymalloc (HCBUFSIZ_LARGE); + char *buf = (char *) hcmalloc (hashcat_ctx, HCBUFSIZ_LARGE); VERIFY_PTR (buf); while (!feof (fp)) { @@ -138,8 +138,8 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) tuning_db_alias_t *alias = &tuning_db->alias_buf[tuning_db->alias_cnt]; - alias->device_name = mystrdup (device_name); - alias->alias_name = mystrdup (alias_name); + alias->device_name = hcstrdup (hashcat_ctx, device_name); + alias->alias_name = hcstrdup (hashcat_ctx, alias_name); tuning_db->alias_cnt++; } @@ -150,7 +150,7 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) (token_ptr[1][0] != '3') && (token_ptr[1][0] != '*')) { - log_info ("WARNING: Tuning-db: Invalid attack_mode '%c' in Line '%u'", token_ptr[1][0], line_num); + event_log_warning (hashcat_ctx, "Tuning-db: Invalid attack_mode '%c' in Line '%u'", token_ptr[1][0], line_num); continue; } @@ -161,7 +161,7 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) (token_ptr[3][0] != '8') && (token_ptr[3][0] != 'N')) { - log_info ("WARNING: Tuning-db: Invalid vector_width '%c' in Line '%u'", token_ptr[3][0], line_num); + event_log_warning (hashcat_ctx, "Tuning-db: Invalid vector_width '%c' in Line '%u'", token_ptr[3][0], line_num); continue; } @@ -184,7 +184,7 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) if ((kernel_accel < 1) || (kernel_accel > 1024)) { - log_info ("WARNING: Tuning-db: Invalid kernel_accel '%d' in Line '%u'", kernel_accel, line_num); + event_log_warning (hashcat_ctx, "Tuning-db: Invalid kernel_accel '%d' in Line '%u'", kernel_accel, line_num); continue; } @@ -200,7 +200,7 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) if ((kernel_loops < 1) || (kernel_loops > 1024)) { - log_info ("WARNING: Tuning-db: Invalid kernel_loops '%d' in Line '%u'", kernel_loops, line_num); + event_log_warning (hashcat_ctx, "Tuning-db: Invalid kernel_loops '%d' in Line '%u'", kernel_loops, line_num); continue; } @@ -212,7 +212,7 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) tuning_db_entry_t *entry = &tuning_db->entry_buf[tuning_db->entry_cnt]; - entry->device_name = mystrdup (device_name); + entry->device_name = hcstrdup (hashcat_ctx, device_name); entry->attack_mode = attack_mode; entry->hash_type = hash_type; entry->vector_width = vector_width; @@ -223,13 +223,13 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) } else { - log_info ("WARNING: Tuning-db: Invalid number of token in Line '%u'", line_num); + event_log_warning (hashcat_ctx, "Tuning-db: Invalid number of token in Line '%u'", line_num); continue; } } - myfree (buf); + hcfree (buf); fclose (fp); @@ -255,19 +255,19 @@ void tuning_db_destroy (hashcat_ctx_t *hashcat_ctx) { tuning_db_alias_t *alias = &tuning_db->alias_buf[i]; - myfree (alias->device_name); - myfree (alias->alias_name); + hcfree (alias->device_name); + hcfree (alias->alias_name); } for (i = 0; i < tuning_db->entry_cnt; i++) { tuning_db_entry_t *entry = &tuning_db->entry_buf[i]; - myfree (entry->device_name); + hcfree (entry->device_name); } - myfree (tuning_db->alias_buf); - myfree (tuning_db->entry_buf); + hcfree (tuning_db->alias_buf); + hcfree (tuning_db->entry_buf); memset (tuning_db, 0, sizeof (tuning_db_t)); } @@ -280,7 +280,7 @@ tuning_db_entry_t *tuning_db_search (hashcat_ctx_t *hashcat_ctx, const char *dev // first we need to convert all spaces in the device_name to underscore - char *device_name_nospace = mystrdup (device_name); + char *device_name_nospace = hcstrdup (hashcat_ctx, device_name); int device_name_length = strlen (device_name_nospace); @@ -364,7 +364,7 @@ tuning_db_entry_t *tuning_db_search (hashcat_ctx_t *hashcat_ctx, const char *dev // free converted device_name - myfree (device_name_nospace); + hcfree (device_name_nospace); return entry; } diff --git a/src/usage.c b/src/usage.c index 0d4b4d0d8..5df411326 100644 --- a/src/usage.c +++ b/src/usage.c @@ -4,7 +4,6 @@ */ #include "common.h" -#include "logging.h" #include "usage.h" static const char *USAGE_MINI[] = @@ -69,6 +68,7 @@ static const char *USAGE_BIG[] = " --veracrypt-keyfiles | File | Keyfiles used, separate with comma | --veracrypt-key=x.txt", " --veracrypt-pim | Num | VeraCrypt personal iterations multiplier | --veracrypt-pim=1000", " -b, --benchmark | | Run benchmark |", + " --speed-only | | Just return expected speed of the attack and quit |", " -c, --segment-size | Num | Sets size in MB to cache from the wordfile to X | -c 32", " --bitmap-min | Num | Sets minimum bits allowed for bitmaps to X | --bitmap-min=24", " --bitmap-max | Num | Sets maximum bits allowed for bitmaps to X | --bitmap-max=24", @@ -411,10 +411,18 @@ static const char *USAGE_BIG[] = void usage_mini_print (const char *progname) { - for (int i = 0; USAGE_MINI[i] != NULL; i++) log_info (USAGE_MINI[i], progname); + for (int i = 0; USAGE_MINI[i] != NULL; i++) + { + printf (USAGE_MINI[i], progname); + printf (EOL); + } } void usage_big_print (const char *progname) { - for (int i = 0; USAGE_BIG[i] != NULL; i++) log_info (USAGE_BIG[i], progname); + for (int i = 0; USAGE_BIG[i] != NULL; i++) + { + printf (USAGE_BIG[i], progname); + printf (EOL); + } } diff --git a/src/user_options.c b/src/user_options.c index b97775aef..ba9c64cd4 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -6,7 +6,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "logfile.h" #include "interface.h" #include "shared.h" @@ -18,86 +18,87 @@ static const char short_options[] = "hVvm:a:r:j:k:g:o:t:d:D:n:u:c:p:s:l:1:2:3:4: static const struct option long_options[] = { - {"help", no_argument, 0, IDX_HELP}, - {"version", no_argument, 0, IDX_VERSION}, - {"quiet", no_argument, 0, IDX_QUIET}, - {"show", no_argument, 0, IDX_SHOW}, - {"left", no_argument, 0, IDX_LEFT}, - {"username", no_argument, 0, IDX_USERNAME}, - {"remove", no_argument, 0, IDX_REMOVE}, - {"remove-timer", required_argument, 0, IDX_REMOVE_TIMER}, - {"skip", required_argument, 0, IDX_SKIP}, - {"limit", required_argument, 0, IDX_LIMIT}, - {"keyspace", no_argument, 0, IDX_KEYSPACE}, - {"potfile-disable", no_argument, 0, IDX_POTFILE_DISABLE}, - {"potfile-path", required_argument, 0, IDX_POTFILE_PATH}, - {"debug-mode", required_argument, 0, IDX_DEBUG_MODE}, - {"debug-file", required_argument, 0, IDX_DEBUG_FILE}, - {"induction-dir", required_argument, 0, IDX_INDUCTION_DIR}, - {"outfile-check-dir", required_argument, 0, IDX_OUTFILE_CHECK_DIR}, - {"force", no_argument, 0, IDX_FORCE}, - {"benchmark", no_argument, 0, IDX_BENCHMARK}, - {"stdout", no_argument, 0, IDX_STDOUT_FLAG}, - {"restore", no_argument, 0, IDX_RESTORE}, - {"restore-disable", no_argument, 0, IDX_RESTORE_DISABLE}, - {"status", no_argument, 0, IDX_STATUS}, - {"status-timer", required_argument, 0, IDX_STATUS_TIMER}, - {"machine-readable", no_argument, 0, IDX_MACHINE_READABLE}, - {"loopback", no_argument, 0, IDX_LOOPBACK}, - {"weak-hash-threshold", required_argument, 0, IDX_WEAK_HASH_THRESHOLD}, - {"session", required_argument, 0, IDX_SESSION}, - {"runtime", required_argument, 0, IDX_RUNTIME}, - {"generate-rules", required_argument, 0, IDX_RP_GEN}, - {"generate-rules-func-min", required_argument, 0, IDX_RP_GEN_FUNC_MIN}, - {"generate-rules-func-max", required_argument, 0, IDX_RP_GEN_FUNC_MAX}, - {"generate-rules-seed", required_argument, 0, IDX_RP_GEN_SEED}, - {"rule-left", required_argument, 0, IDX_RULE_BUF_L}, - {"rule-right", required_argument, 0, IDX_RULE_BUF_R}, - {"hash-type", required_argument, 0, IDX_HASH_MODE}, {"attack-mode", required_argument, 0, IDX_ATTACK_MODE}, - {"rules-file", required_argument, 0, IDX_RP_FILE}, - {"outfile", required_argument, 0, IDX_OUTFILE}, - {"outfile-format", required_argument, 0, IDX_OUTFILE_FORMAT}, - {"outfile-autohex-disable", no_argument, 0, IDX_OUTFILE_AUTOHEX_DISABLE}, - {"outfile-check-timer", required_argument, 0, IDX_OUTFILE_CHECK_TIMER}, - {"hex-charset", no_argument, 0, IDX_HEX_CHARSET}, - {"hex-salt", no_argument, 0, IDX_HEX_SALT}, - {"hex-wordlist", no_argument, 0, IDX_HEX_WORDLIST}, - {"markov-disable", no_argument, 0, IDX_MARKOV_DISABLE}, - {"markov-classic", no_argument, 0, IDX_MARKOV_CLASSIC}, - {"markov-threshold", required_argument, 0, IDX_MARKOV_THRESHOLD}, - {"markov-hcstat", required_argument, 0, IDX_MARKOV_HCSTAT}, - {"cpu-affinity", required_argument, 0, IDX_CPU_AFFINITY}, - {"opencl-info", no_argument, 0, IDX_OPENCL_INFO}, - {"opencl-devices", required_argument, 0, IDX_OPENCL_DEVICES}, - {"opencl-platforms", required_argument, 0, IDX_OPENCL_PLATFORMS}, - {"opencl-device-types", required_argument, 0, IDX_OPENCL_DEVICE_TYPES}, - {"opencl-vector-width", required_argument, 0, IDX_OPENCL_VECTOR_WIDTH}, - {"workload-profile", required_argument, 0, IDX_WORKLOAD_PROFILE}, - {"kernel-accel", required_argument, 0, IDX_KERNEL_ACCEL}, - {"kernel-loops", required_argument, 0, IDX_KERNEL_LOOPS}, - {"nvidia-spin-damp", required_argument, 0, IDX_NVIDIA_SPIN_DAMP}, - {"gpu-temp-disable", no_argument, 0, IDX_GPU_TEMP_DISABLE}, - {"gpu-temp-abort", required_argument, 0, IDX_GPU_TEMP_ABORT}, - {"gpu-temp-retain", required_argument, 0, IDX_GPU_TEMP_RETAIN}, - {"powertune-enable", no_argument, 0, IDX_POWERTUNE_ENABLE}, - {"logfile-disable", no_argument, 0, IDX_LOGFILE_DISABLE}, - {"truecrypt-keyfiles", required_argument, 0, IDX_TRUECRYPT_KEYFILES}, - {"veracrypt-keyfiles", required_argument, 0, IDX_VERACRYPT_KEYFILES}, - {"veracrypt-pim", required_argument, 0, IDX_VERACRYPT_PIM}, - {"segment-size", required_argument, 0, IDX_SEGMENT_SIZE}, - {"scrypt-tmto", required_argument, 0, IDX_SCRYPT_TMTO}, - {"seperator", required_argument, 0, IDX_SEPARATOR}, - {"separator", required_argument, 0, IDX_SEPARATOR}, - {"bitmap-min", required_argument, 0, IDX_BITMAP_MIN}, + {"benchmark", no_argument, 0, IDX_BENCHMARK}, {"bitmap-max", required_argument, 0, IDX_BITMAP_MAX}, - {"increment", no_argument, 0, IDX_INCREMENT}, - {"increment-min", required_argument, 0, IDX_INCREMENT_MIN}, - {"increment-max", required_argument, 0, IDX_INCREMENT_MAX}, + {"bitmap-min", required_argument, 0, IDX_BITMAP_MIN}, + {"cpu-affinity", required_argument, 0, IDX_CPU_AFFINITY}, {"custom-charset1", required_argument, 0, IDX_CUSTOM_CHARSET_1}, {"custom-charset2", required_argument, 0, IDX_CUSTOM_CHARSET_2}, {"custom-charset3", required_argument, 0, IDX_CUSTOM_CHARSET_3}, {"custom-charset4", required_argument, 0, IDX_CUSTOM_CHARSET_4}, + {"debug-file", required_argument, 0, IDX_DEBUG_FILE}, + {"debug-mode", required_argument, 0, IDX_DEBUG_MODE}, + {"force", no_argument, 0, IDX_FORCE}, + {"generate-rules-func-max", required_argument, 0, IDX_RP_GEN_FUNC_MAX}, + {"generate-rules-func-min", required_argument, 0, IDX_RP_GEN_FUNC_MIN}, + {"generate-rules", required_argument, 0, IDX_RP_GEN}, + {"generate-rules-seed", required_argument, 0, IDX_RP_GEN_SEED}, + {"gpu-temp-abort", required_argument, 0, IDX_GPU_TEMP_ABORT}, + {"gpu-temp-disable", no_argument, 0, IDX_GPU_TEMP_DISABLE}, + {"gpu-temp-retain", required_argument, 0, IDX_GPU_TEMP_RETAIN}, + {"hash-type", required_argument, 0, IDX_HASH_MODE}, + {"help", no_argument, 0, IDX_HELP}, + {"hex-charset", no_argument, 0, IDX_HEX_CHARSET}, + {"hex-salt", no_argument, 0, IDX_HEX_SALT}, + {"hex-wordlist", no_argument, 0, IDX_HEX_WORDLIST}, + {"increment-max", required_argument, 0, IDX_INCREMENT_MAX}, + {"increment-min", required_argument, 0, IDX_INCREMENT_MIN}, + {"increment", no_argument, 0, IDX_INCREMENT}, + {"induction-dir", required_argument, 0, IDX_INDUCTION_DIR}, + {"kernel-accel", required_argument, 0, IDX_KERNEL_ACCEL}, + {"kernel-loops", required_argument, 0, IDX_KERNEL_LOOPS}, + {"keyspace", no_argument, 0, IDX_KEYSPACE}, + {"left", no_argument, 0, IDX_LEFT}, + {"limit", required_argument, 0, IDX_LIMIT}, + {"logfile-disable", no_argument, 0, IDX_LOGFILE_DISABLE}, + {"loopback", no_argument, 0, IDX_LOOPBACK}, + {"machine-readable", no_argument, 0, IDX_MACHINE_READABLE}, + {"markov-classic", no_argument, 0, IDX_MARKOV_CLASSIC}, + {"markov-disable", no_argument, 0, IDX_MARKOV_DISABLE}, + {"markov-hcstat", required_argument, 0, IDX_MARKOV_HCSTAT}, + {"markov-threshold", required_argument, 0, IDX_MARKOV_THRESHOLD}, + {"nvidia-spin-damp", required_argument, 0, IDX_NVIDIA_SPIN_DAMP}, + {"opencl-devices", required_argument, 0, IDX_OPENCL_DEVICES}, + {"opencl-device-types", required_argument, 0, IDX_OPENCL_DEVICE_TYPES}, + {"opencl-info", no_argument, 0, IDX_OPENCL_INFO}, + {"opencl-platforms", required_argument, 0, IDX_OPENCL_PLATFORMS}, + {"opencl-vector-width", required_argument, 0, IDX_OPENCL_VECTOR_WIDTH}, + {"outfile-autohex-disable", no_argument, 0, IDX_OUTFILE_AUTOHEX_DISABLE}, + {"outfile-check-dir", required_argument, 0, IDX_OUTFILE_CHECK_DIR}, + {"outfile-check-timer", required_argument, 0, IDX_OUTFILE_CHECK_TIMER}, + {"outfile-format", required_argument, 0, IDX_OUTFILE_FORMAT}, + {"outfile", required_argument, 0, IDX_OUTFILE}, + {"potfile-disable", no_argument, 0, IDX_POTFILE_DISABLE}, + {"potfile-path", required_argument, 0, IDX_POTFILE_PATH}, + {"powertune-enable", no_argument, 0, IDX_POWERTUNE_ENABLE}, + {"quiet", no_argument, 0, IDX_QUIET}, + {"remove", no_argument, 0, IDX_REMOVE}, + {"remove-timer", required_argument, 0, IDX_REMOVE_TIMER}, + {"restore-disable", no_argument, 0, IDX_RESTORE_DISABLE}, + {"restore", no_argument, 0, IDX_RESTORE}, + {"rule-left", required_argument, 0, IDX_RULE_BUF_L}, + {"rule-right", required_argument, 0, IDX_RULE_BUF_R}, + {"rules-file", required_argument, 0, IDX_RP_FILE}, + {"runtime", required_argument, 0, IDX_RUNTIME}, + {"scrypt-tmto", required_argument, 0, IDX_SCRYPT_TMTO}, + {"segment-size", required_argument, 0, IDX_SEGMENT_SIZE}, + {"separator", required_argument, 0, IDX_SEPARATOR}, + {"seperator", required_argument, 0, IDX_SEPARATOR}, + {"session", required_argument, 0, IDX_SESSION}, + {"show", no_argument, 0, IDX_SHOW}, + {"skip", required_argument, 0, IDX_SKIP}, + {"status", no_argument, 0, IDX_STATUS}, + {"status-timer", required_argument, 0, IDX_STATUS_TIMER}, + {"stdout", no_argument, 0, IDX_STDOUT_FLAG}, + {"speed-only", no_argument, 0, IDX_SPEED_ONLY}, + {"truecrypt-keyfiles", required_argument, 0, IDX_TRUECRYPT_KEYFILES}, + {"username", no_argument, 0, IDX_USERNAME}, + {"veracrypt-keyfiles", required_argument, 0, IDX_VERACRYPT_KEYFILES}, + {"veracrypt-pim", required_argument, 0, IDX_VERACRYPT_PIM}, + {"version", no_argument, 0, IDX_VERSION}, + {"weak-hash-threshold", required_argument, 0, IDX_WEAK_HASH_THRESHOLD}, + {"workload-profile", required_argument, 0, IDX_WORKLOAD_PROFILE}, {0, 0, 0, 0} }; @@ -108,7 +109,7 @@ static char DEF_MASK_CS_1[] = "?l?d?u"; static char DEF_MASK_CS_2[] = "?l?d"; static char DEF_MASK_CS_3[] = "?l?d*!$@_"; -void user_options_init (hashcat_ctx_t *hashcat_ctx) +int user_options_init (hashcat_ctx_t *hashcat_ctx) { user_options_t *user_options = hashcat_ctx->user_options; @@ -183,6 +184,7 @@ void user_options_init (hashcat_ctx_t *hashcat_ctx) user_options->status = STATUS; user_options->status_timer = STATUS_TIMER; user_options->stdout_flag = STDOUT_FLAG; + user_options->speed_only = SPEED_ONLY; user_options->truecrypt_keyfiles = NULL; user_options->usage = USAGE; user_options->username = USERNAME; @@ -192,17 +194,19 @@ void user_options_init (hashcat_ctx_t *hashcat_ctx) user_options->weak_hash_threshold = WEAK_HASH_THRESHOLD; user_options->workload_profile = WORKLOAD_PROFILE; user_options->rp_files_cnt = 0; - user_options->rp_files = (char **) mycalloc (256, sizeof (char *)); + user_options->rp_files = (char **) hccalloc (hashcat_ctx, 256, sizeof (char *)); VERIFY_PTR (user_options->rp_files); user_options->hc_bin = PROGNAME; user_options->hc_argc = 0; user_options->hc_argv = NULL; + + return 0; } void user_options_destroy (hashcat_ctx_t *hashcat_ctx) { user_options_t *user_options = hashcat_ctx->user_options; - myfree (user_options->rp_files); + hcfree (user_options->rp_files); //do not reset this, it might be used from main.c //memset (user_options, 0, sizeof (user_options_t)); @@ -245,6 +249,7 @@ int user_options_getopt (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) case IDX_KEYSPACE: user_options->keyspace = true; break; case IDX_BENCHMARK: user_options->benchmark = true; break; case IDX_STDOUT_FLAG: user_options->stdout_flag = true; break; + case IDX_SPEED_ONLY: user_options->speed_only = true; break; case IDX_RESTORE_DISABLE: user_options->restore_disable = true; break; case IDX_STATUS: user_options->status = true; break; case IDX_STATUS_TIMER: user_options->status_timer = atoi (optarg); break; @@ -320,7 +325,7 @@ int user_options_getopt (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) default: { - log_error ("ERROR: Invalid argument specified"); + event_log_error (hashcat_ctx, "Invalid argument specified"); return -1; } @@ -329,7 +334,7 @@ int user_options_getopt (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) if (optopt != 0) { - log_error ("ERROR: Invalid argument specified"); + event_log_error (hashcat_ctx, "Invalid argument specified"); return -1; } @@ -348,14 +353,14 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) if (user_options->hc_argc < 0) { - log_error ("ERROR: hc_argc %d is invalid", user_options->hc_argc); + event_log_error (hashcat_ctx, "hc_argc %d is invalid", user_options->hc_argc); return -1; } if (user_options->hc_argv == NULL) { - log_error ("ERROR: hc_argv is NULL"); + event_log_error (hashcat_ctx, "hc_argv is NULL"); return -1; } @@ -367,21 +372,21 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) && (user_options->attack_mode != ATTACK_MODE_HYBRID2) && (user_options->attack_mode != ATTACK_MODE_NONE)) { - log_error ("ERROR: Invalid attack-mode specified"); + event_log_error (hashcat_ctx, "Invalid attack-mode specified"); return -1; } if (user_options->runtime_chgd == true && user_options->runtime == 0) { - log_error ("ERROR: Invalid runtime specified"); + event_log_error (hashcat_ctx, "Invalid runtime specified"); return -1; } if (user_options->hash_mode > 14100) { - log_error ("ERROR: Invalid hash-type specified"); + event_log_error (hashcat_ctx, "Invalid hash-type specified"); return -1; } @@ -393,7 +398,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) || ((user_options->hash_mode >= 6200) && (user_options->hash_mode <= 6299)) || ((user_options->hash_mode >= 13700) && (user_options->hash_mode <= 13799))) { - log_error ("ERROR: Mixing support for user names and hashes of type %s is not supported", strhashtype (user_options->hash_mode)); + event_log_error (hashcat_ctx, "Mixing support for user names and hashes of type %s is not supported", strhashtype (user_options->hash_mode)); return -1; } @@ -401,7 +406,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) if (user_options->outfile_format > 16) { - log_error ("ERROR: Invalid outfile-format specified"); + event_log_error (hashcat_ctx, "Invalid outfile-format specified"); return -1; } @@ -410,7 +415,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->outfile_format_chgd == true) { - log_error ("ERROR: Mixing outfile-format > 1 with left parameter is not allowed"); + event_log_error (hashcat_ctx, "Mixing outfile-format > 1 with left parameter is not allowed"); return -1; } @@ -420,7 +425,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->outfile_format_chgd == true) { - log_error ("ERROR: Mixing outfile-format > 7 with show parameter is not allowed"); + event_log_error (hashcat_ctx, "Mixing outfile-format > 7 with show parameter is not allowed"); return -1; } @@ -428,49 +433,49 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) if (user_options->increment_min < INCREMENT_MIN) { - log_error ("ERROR: Invalid increment-min specified"); + event_log_error (hashcat_ctx, "Invalid increment-min specified"); return -1; } if (user_options->increment_max > INCREMENT_MAX) { - log_error ("ERROR: Invalid increment-max specified"); + event_log_error (hashcat_ctx, "Invalid increment-max specified"); return -1; } if (user_options->increment_min > user_options->increment_max) { - log_error ("ERROR: Invalid increment-min specified"); + event_log_error (hashcat_ctx, "Invalid increment-min specified"); return -1; } if ((user_options->increment == true) && (user_options->attack_mode == ATTACK_MODE_STRAIGHT)) { - log_error ("ERROR: Increment is not allowed in attack-mode 0"); + event_log_error (hashcat_ctx, "Increment is not allowed in attack-mode 0"); return -1; } if ((user_options->increment == false) && (user_options->increment_min_chgd == true)) { - log_error ("ERROR: Increment-min is only supported combined with increment switch"); + event_log_error (hashcat_ctx, "Increment-min is only supported combined with increment switch"); return -1; } if ((user_options->increment == false) && (user_options->increment_max_chgd == true)) { - log_error ("ERROR: Increment-max is only supported combined with increment switch"); + event_log_error (hashcat_ctx, "Increment-max is only supported combined with increment switch"); return -1; } if (user_options->rp_files_cnt > 0 && user_options->rp_gen == true) { - log_error ("ERROR: Use of both rules-file and rules-generate is not supported"); + event_log_error (hashcat_ctx, "Use of both rules-file and rules-generate is not supported"); return -1; } @@ -479,7 +484,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->attack_mode != ATTACK_MODE_STRAIGHT) { - log_error ("ERROR: Use of rules-file or rules-generate only allowed in attack-mode 0"); + event_log_error (hashcat_ctx, "Use of rules-file or rules-generate only allowed in attack-mode 0"); return -1; } @@ -487,14 +492,14 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) if (user_options->bitmap_min > user_options->bitmap_max) { - log_error ("ERROR: Invalid bitmap-min specified"); + event_log_error (hashcat_ctx, "Invalid bitmap-min specified"); return -1; } if (user_options->rp_gen_func_min > user_options->rp_gen_func_max) { - log_error ("ERROR: Invalid rp-gen-func-min specified"); + event_log_error (hashcat_ctx, "Invalid rp-gen-func-min specified"); return -1; } @@ -503,24 +508,24 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->force == false) { - log_info ("The manual use of the -n option (or --kernel-accel) is outdated"); - log_info ("Please consider using the -w option instead"); - log_info ("You can use --force to override this but do not post error reports if you do so"); - log_info (""); + event_log_info (hashcat_ctx, "The manual use of the -n option (or --kernel-accel) is outdated"); + event_log_info (hashcat_ctx, "Please consider using the -w option instead"); + event_log_info (hashcat_ctx, "You can use --force to override this but do not post error reports if you do so"); + event_log_info (hashcat_ctx, ""); return -1; } if (user_options->kernel_accel < 1) { - log_error ("ERROR: Invalid kernel-accel specified"); + event_log_error (hashcat_ctx, "Invalid kernel-accel specified"); return -1; } if (user_options->kernel_accel > 1024) { - log_error ("ERROR: Invalid kernel-accel specified"); + event_log_error (hashcat_ctx, "Invalid kernel-accel specified"); return -1; } @@ -530,24 +535,24 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->force == false) { - log_info ("The manual use of the -u option (or --kernel-loops) is outdated"); - log_info ("Please consider using the -w option instead"); - log_info ("You can use --force to override this but do not post error reports if you do so"); - log_info (""); + event_log_info (hashcat_ctx, "The manual use of the -u option (or --kernel-loops) is outdated"); + event_log_info (hashcat_ctx, "Please consider using the -w option instead"); + event_log_info (hashcat_ctx, "You can use --force to override this but do not post error reports if you do so"); + event_log_info (hashcat_ctx, ""); return -1; } if (user_options->kernel_loops < 1) { - log_error ("ERROR: Invalid kernel-loops specified"); + event_log_error (hashcat_ctx, "Invalid kernel-loops specified"); return -1; } if (user_options->kernel_loops > 1024) { - log_error ("ERROR: Invalid kernel-loops specified"); + event_log_error (hashcat_ctx, "Invalid kernel-loops specified"); return -1; } @@ -555,7 +560,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) if ((user_options->workload_profile < 1) || (user_options->workload_profile > 4)) { - log_error ("ERROR: workload-profile %i not available", user_options->workload_profile); + event_log_error (hashcat_ctx, "workload-profile %i not available", user_options->workload_profile); return -1; } @@ -564,7 +569,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (is_power_of_2 (user_options->opencl_vector_width) == false || user_options->opencl_vector_width > 16) { - log_error ("ERROR: opencl-vector-width %i not allowed", user_options->opencl_vector_width); + event_log_error (hashcat_ctx, "opencl-vector-width %i not allowed", user_options->opencl_vector_width); return -1; } @@ -574,14 +579,14 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->remove == true) { - log_error ("ERROR: Mixing remove parameter not allowed with show parameter or left parameter"); + event_log_error (hashcat_ctx, "Mixing remove parameter not allowed with show parameter or left parameter"); return -1; } if (user_options->potfile_disable == true) { - log_error ("ERROR: Mixing potfile-disable parameter not allowed with show parameter or left parameter"); + event_log_error (hashcat_ctx, "Mixing potfile-disable parameter not allowed with show parameter or left parameter"); return -1; } @@ -591,7 +596,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->outfile_autohex == false) { - log_error ("ERROR: Mixing outfile-autohex-disable parameter not allowed with show parameter"); + event_log_error (hashcat_ctx, "Mixing outfile-autohex-disable parameter not allowed with show parameter"); return -1; } @@ -601,13 +606,13 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->show == true) { - log_error ("ERROR: Combining show parameter with keyspace parameter is not allowed"); + event_log_error (hashcat_ctx, "Combining show parameter with keyspace parameter is not allowed"); return -1; } else if (user_options->left == true) { - log_error ("ERROR: Combining left parameter with keyspace parameter is not allowed"); + event_log_error (hashcat_ctx, "Combining left parameter with keyspace parameter is not allowed"); return -1; } @@ -617,14 +622,14 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->remove == false) { - log_error ("ERROR: Parameter remove-timer require parameter remove enabled"); + event_log_error (hashcat_ctx, "Parameter remove-timer require parameter remove enabled"); return -1; } if (user_options->remove_timer < 1) { - log_error ("ERROR: Parameter remove-timer must have a value greater than or equal to 1"); + event_log_error (hashcat_ctx, "Parameter remove-timer must have a value greater than or equal to 1"); return -1; } @@ -636,14 +641,14 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if ((user_options->rp_files_cnt == 0) && (user_options->rp_gen == 0)) { - log_error ("ERROR: Parameter loopback not allowed without rules-file or rules-generate"); + event_log_error (hashcat_ctx, "Parameter loopback not allowed without rules-file or rules-generate"); return -1; } } else { - log_error ("ERROR: Parameter loopback allowed in attack-mode 0 only"); + event_log_error (hashcat_ctx, "Parameter loopback allowed in attack-mode 0 only"); return -1; } @@ -654,14 +659,14 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->attack_mode != ATTACK_MODE_STRAIGHT) { - log_error ("ERROR: Parameter debug-mode option is only available with attack-mode 0"); + event_log_error (hashcat_ctx, "Parameter debug-mode option is only available with attack-mode 0"); return -1; } if ((user_options->rp_files_cnt == 0) && (user_options->rp_gen == 0)) { - log_error ("ERROR: Parameter debug-mode not allowed without rules-file or rules-generate"); + event_log_error (hashcat_ctx, "Parameter debug-mode not allowed without rules-file or rules-generate"); return -1; } @@ -669,7 +674,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) if (user_options->debug_mode > 4) { - log_error ("ERROR: Invalid debug-mode specified"); + event_log_error (hashcat_ctx, "Invalid debug-mode specified"); return -1; } @@ -678,7 +683,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->debug_mode < 1) { - log_error ("ERROR: Parameter debug-file requires parameter debug-mode to be set"); + event_log_error (hashcat_ctx, "Parameter debug-file requires parameter debug-mode to be set"); return -1; } @@ -688,7 +693,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->attack_mode == ATTACK_MODE_BF) { - log_error ("ERROR: Parameter induction-dir not allowed with brute-force attacks"); + event_log_error (hashcat_ctx, "Parameter induction-dir not allowed with brute-force attacks"); return -1; } @@ -698,7 +703,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if ((user_options->weak_hash_threshold != WEAK_HASH_THRESHOLD) && (user_options->weak_hash_threshold != 0)) { - log_error ("ERROR: setting --weak-hash-threshold allowed only in straight-attack mode"); + event_log_error (hashcat_ctx, "setting --weak-hash-threshold allowed only in straight-attack mode"); return -1; } @@ -706,7 +711,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) if (user_options->nvidia_spin_damp > 100) { - log_error ("ERROR: setting --nvidia-spin-damp must be between 0 and 100 (inclusive)"); + event_log_error (hashcat_ctx, "setting --nvidia-spin-damp must be between 0 and 100 (inclusive)"); return -1; } @@ -715,7 +720,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->gpu_temp_abort < user_options->gpu_temp_retain) { - log_error ("ERROR: Invalid values for gpu-temp-abort. Parameter gpu-temp-abort is less than gpu-temp-retain."); + event_log_error (hashcat_ctx, "Invalid values for gpu-temp-abort. Parameter gpu-temp-abort is less than gpu-temp-retain."); return -1; } @@ -727,7 +732,7 @@ int user_options_sanity (hashcat_ctx_t *hashcat_ctx) { if (user_options->attack_mode != ATTACK_MODE_BF) { - log_error ("ERROR: Only attack-mode 3 allowed in benchmark mode"); + event_log_error (hashcat_ctx, "Only attack-mode 3 allowed in benchmark mode"); return -1; } @@ -907,7 +912,8 @@ void user_options_preprocess (hashcat_ctx_t *hashcat_ctx) if (user_options->opencl_info == true || user_options->keyspace == true || user_options->benchmark == true - || user_options->stdout_flag == true) + || user_options->stdout_flag == true + || user_options->speed_only == true) { user_options->show = false; user_options->left = false; @@ -930,6 +936,7 @@ void user_options_preprocess (hashcat_ctx_t *hashcat_ctx) user_options->session = "benchmark"; user_options->attack_mode = ATTACK_MODE_BF; user_options->increment = false; + user_options->speed_only = true; if (user_options->workload_profile_chgd == false) { @@ -966,7 +973,7 @@ void user_options_preprocess (hashcat_ctx_t *hashcat_ctx) user_options->quiet = true; user_options->opencl_platforms = NULL; user_options->opencl_devices = NULL; - user_options->opencl_device_types = mystrdup ("1,2,3"); + user_options->opencl_device_types = hcstrdup (hashcat_ctx, "1,2,3"); } if (user_options->left == true) @@ -1103,23 +1110,6 @@ void user_options_extra_init (hashcat_ctx_t *hashcat_ctx) user_options_extra->rule_len_l = (int) strlen (user_options->rule_buf_l); user_options_extra->rule_len_r = (int) strlen (user_options->rule_buf_r); - // wordlist_mode - - user_options_extra->wordlist_mode = WL_MODE_NONE; - - if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) - { - user_options_extra->wordlist_mode = (user_options->hc_argc >= 2) ? WL_MODE_FILE : WL_MODE_STDIN; - } - else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) - { - user_options_extra->wordlist_mode = WL_MODE_FILE; - } - else if (user_options_extra->attack_kern == ATTACK_KERN_BF) - { - user_options_extra->wordlist_mode = WL_MODE_MASK; - } - // hc_hash and hc_work* user_options_extra->hc_hash = NULL; @@ -1150,6 +1140,23 @@ void user_options_extra_init (hashcat_ctx_t *hashcat_ctx) user_options_extra->hc_workc = user_options->hc_argc - 1; user_options_extra->hc_workv = user_options->hc_argv + 1; } + + // wordlist_mode + + user_options_extra->wordlist_mode = WL_MODE_NONE; + + if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT) + { + user_options_extra->wordlist_mode = (user_options_extra->hc_workc >= 1) ? WL_MODE_FILE : WL_MODE_STDIN; + } + else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) + { + user_options_extra->wordlist_mode = WL_MODE_FILE; + } + else if (user_options_extra->attack_kern == ATTACK_KERN_BF) + { + user_options_extra->wordlist_mode = WL_MODE_MASK; + } } void user_options_extra_destroy (hashcat_ctx_t *hashcat_ctx) @@ -1196,66 +1203,7 @@ void user_options_logger (hashcat_ctx_t *hashcat_ctx) user_options_t *user_options = hashcat_ctx->user_options; logfile_ctx_t *logfile_ctx = hashcat_ctx->logfile_ctx; - logfile_top_uint (user_options->benchmark); - logfile_top_uint (user_options->force); - logfile_top_uint (user_options->gpu_temp_disable); - logfile_top_uint (user_options->hex_charset); - logfile_top_uint (user_options->hex_salt); - logfile_top_uint (user_options->hex_wordlist); - logfile_top_uint (user_options->increment); - logfile_top_uint (user_options->keyspace); - logfile_top_uint (user_options->left); - logfile_top_uint (user_options->logfile_disable); - logfile_top_uint (user_options->loopback); - logfile_top_uint (user_options->machine_readable); - logfile_top_uint (user_options->markov_classic); - logfile_top_uint (user_options->markov_disable); - logfile_top_uint (user_options->opencl_info); - logfile_top_uint (user_options->outfile_autohex); - logfile_top_uint (user_options->potfile_disable); - logfile_top_uint (user_options->powertune_enable); - logfile_top_uint (user_options->quiet); - logfile_top_uint (user_options->remove); - logfile_top_uint (user_options->restore); - logfile_top_uint (user_options->restore_disable); - logfile_top_uint (user_options->show); - logfile_top_uint (user_options->status); - logfile_top_uint (user_options->stdout_flag); - logfile_top_uint (user_options->usage); - logfile_top_uint (user_options->username); - logfile_top_uint (user_options->version); - logfile_top_uint (user_options->attack_mode); - logfile_top_uint (user_options->bitmap_max); - logfile_top_uint (user_options->bitmap_min); - logfile_top_uint (user_options->debug_mode); - logfile_top_uint (user_options->gpu_temp_abort); - logfile_top_uint (user_options->gpu_temp_retain); - logfile_top_uint (user_options->hash_mode); - logfile_top_uint (user_options->increment_max); - logfile_top_uint (user_options->increment_min); - logfile_top_uint (user_options->kernel_accel); - logfile_top_uint (user_options->kernel_loops); - logfile_top_uint (user_options->markov_threshold); - logfile_top_uint (user_options->nvidia_spin_damp); - logfile_top_uint (user_options->opencl_vector_width); - logfile_top_uint (user_options->outfile_check_timer); - logfile_top_uint (user_options->outfile_format); - logfile_top_uint (user_options->remove_timer); - logfile_top_uint (user_options->restore_timer); - logfile_top_uint (user_options->rp_files_cnt); - logfile_top_uint (user_options->rp_gen); - logfile_top_uint (user_options->rp_gen_func_max); - logfile_top_uint (user_options->rp_gen_func_min); - logfile_top_uint (user_options->rp_gen_seed); - logfile_top_uint (user_options->runtime); - logfile_top_uint (user_options->scrypt_tmto); - logfile_top_uint (user_options->segment_size); - logfile_top_uint (user_options->status_timer); - logfile_top_uint (user_options->veracrypt_pim); - logfile_top_uint (user_options->weak_hash_threshold); - logfile_top_uint (user_options->workload_profile); - logfile_top_uint64 (user_options->limit); - logfile_top_uint64 (user_options->skip); + logfile_top_char (user_options->separator); logfile_top_string (user_options->cpu_affinity); logfile_top_string (user_options->custom_charset_1); logfile_top_string (user_options->custom_charset_2); @@ -1273,8 +1221,68 @@ void user_options_logger (hashcat_ctx_t *hashcat_ctx) logfile_top_string (user_options->rp_files[0]); logfile_top_string (user_options->rule_buf_l); logfile_top_string (user_options->rule_buf_r); - logfile_top_char (user_options->separator); logfile_top_string (user_options->session); logfile_top_string (user_options->truecrypt_keyfiles); logfile_top_string (user_options->veracrypt_keyfiles); + logfile_top_uint64 (user_options->limit); + logfile_top_uint64 (user_options->skip); + logfile_top_uint (user_options->attack_mode); + logfile_top_uint (user_options->benchmark); + logfile_top_uint (user_options->bitmap_max); + logfile_top_uint (user_options->bitmap_min); + logfile_top_uint (user_options->debug_mode); + logfile_top_uint (user_options->force); + logfile_top_uint (user_options->gpu_temp_abort); + logfile_top_uint (user_options->gpu_temp_disable); + logfile_top_uint (user_options->gpu_temp_retain); + logfile_top_uint (user_options->hash_mode); + logfile_top_uint (user_options->hex_charset); + logfile_top_uint (user_options->hex_salt); + logfile_top_uint (user_options->hex_wordlist); + logfile_top_uint (user_options->increment); + logfile_top_uint (user_options->increment_max); + logfile_top_uint (user_options->increment_min); + logfile_top_uint (user_options->kernel_accel); + logfile_top_uint (user_options->kernel_loops); + logfile_top_uint (user_options->keyspace); + logfile_top_uint (user_options->left); + logfile_top_uint (user_options->logfile_disable); + logfile_top_uint (user_options->loopback); + logfile_top_uint (user_options->machine_readable); + logfile_top_uint (user_options->markov_classic); + logfile_top_uint (user_options->markov_disable); + logfile_top_uint (user_options->markov_threshold); + logfile_top_uint (user_options->nvidia_spin_damp); + logfile_top_uint (user_options->opencl_info); + logfile_top_uint (user_options->opencl_vector_width); + logfile_top_uint (user_options->outfile_autohex); + logfile_top_uint (user_options->outfile_check_timer); + logfile_top_uint (user_options->outfile_format); + logfile_top_uint (user_options->potfile_disable); + logfile_top_uint (user_options->powertune_enable); + logfile_top_uint (user_options->quiet); + logfile_top_uint (user_options->remove); + logfile_top_uint (user_options->remove_timer); + logfile_top_uint (user_options->restore); + logfile_top_uint (user_options->restore_disable); + logfile_top_uint (user_options->restore_timer); + logfile_top_uint (user_options->rp_files_cnt); + logfile_top_uint (user_options->rp_gen); + logfile_top_uint (user_options->rp_gen_func_max); + logfile_top_uint (user_options->rp_gen_func_min); + logfile_top_uint (user_options->rp_gen_seed); + logfile_top_uint (user_options->runtime); + logfile_top_uint (user_options->scrypt_tmto); + logfile_top_uint (user_options->segment_size); + logfile_top_uint (user_options->show); + logfile_top_uint (user_options->status); + logfile_top_uint (user_options->status_timer); + logfile_top_uint (user_options->stdout_flag); + logfile_top_uint (user_options->speed_only); + logfile_top_uint (user_options->usage); + logfile_top_uint (user_options->username); + logfile_top_uint (user_options->veracrypt_pim); + logfile_top_uint (user_options->version); + logfile_top_uint (user_options->weak_hash_threshold); + logfile_top_uint (user_options->workload_profile); } diff --git a/src/weak_hash.c b/src/weak_hash.c index a39df35ac..96ebf14aa 100644 --- a/src/weak_hash.c +++ b/src/weak_hash.c @@ -5,12 +5,12 @@ #include "common.h" #include "types.h" -#include "logging.h" +#include "event.h" #include "opencl.h" #include "hashes.h" #include "weak_hash.h" -void weak_hash_check (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 salt_pos) +int weak_hash_check (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u32 salt_pos) { hashconfig_t *hashconfig = hashcat_ctx->hashconfig; hashes_t *hashes = hashcat_ctx->hashes; @@ -33,13 +33,19 @@ void weak_hash_check (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_para * run the kernel */ + int CL_rc; + if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL) { - run_kernel (hashcat_ctx, device_param, KERN_RUN_1, 1, false, 0); + CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_1, 1, false, 0); + + if (CL_rc == -1) return -1; } else { - run_kernel (hashcat_ctx, device_param, KERN_RUN_1, 1, false, 0); + CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_1, 1, false, 0); + + if (CL_rc == -1) return -1; u32 loop_step = 16; @@ -54,10 +60,14 @@ void weak_hash_check (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_para device_param->kernel_params_buf32[28] = loop_pos; device_param->kernel_params_buf32[29] = loop_left; - run_kernel (hashcat_ctx, device_param, KERN_RUN_2, 1, false, 0); + CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_2, 1, false, 0); + + if (CL_rc == -1) return -1; } - run_kernel (hashcat_ctx, device_param, KERN_RUN_3, 1, false, 0); + CL_rc = run_kernel (hashcat_ctx, device_param, KERN_RUN_3, 1, false, 0); + + if (CL_rc == -1) return -1; } /** @@ -80,4 +90,6 @@ void weak_hash_check (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_para device_param->kernel_params_buf32[34] = 0; straight_ctx->kernel_rules_buf[0].cmds[0] = cmd0_rule_old; + + return 0; } diff --git a/src/win_file_globbing.mk b/src/win_file_globbing.mk index b136eef4d..cd6cb97f7 100644 --- a/src/win_file_globbing.mk +++ b/src/win_file_globbing.mk @@ -18,8 +18,13 @@ ifneq (,$(IS_WIN_BUILD)) # entering this code path means: we need to check for CRT_glob.o since we try to build binaries for windows operating systems +ifeq ($(UNAME),MSYS2) +CRT_GLOB_LIB_PATH_32 ?= /mingw32/i686-w64-mingw32/lib/ +CRT_GLOB_LIB_PATH_64 ?= /mingw64/x86_64-w64-mingw32/lib/ +else CRT_GLOB_LIB_PATH_32 ?= /usr/i686-w64-mingw32/lib/ CRT_GLOB_LIB_PATH_64 ?= /usr/x86_64-w64-mingw32/lib/ +endif CRT_GLOB_LIB_SYSROOT_32 := $(shell $(CC_WIN_32) --verbose 2>&1 | $(EGREP) -m 1 -o '(with-sysroot="[^"]"|with-sysroot=[^ ]*)' | $(SED) 's/^with-sysroot="\?\([^"]*\)"\?$$/\1/') CRT_GLOB_LIB_SYSROOT_64 := $(shell $(CC_WIN_64) --verbose 2>&1 | $(EGREP) -m 1 -o '(with-sysroot="[^"]"|with-sysroot=[^ ]*)' | $(SED) 's/^with-sysroot="\?\([^"]*\)"\?$$/\1/') diff --git a/src/wordlist.c b/src/wordlist.c index 2e73bc6c6..5aff5fa02 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -6,7 +6,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "convert.h" #include "dictstat.h" #include "thread.h" @@ -58,7 +58,7 @@ u32 convert_from_hex (hashcat_ctx_t *hashcat_ctx, char *line_buf, const u32 line return (line_len); } -void load_segment (hashcat_ctx_t *hashcat_ctx, FILE *fd) +int load_segment (hashcat_ctx_t *hashcat_ctx, FILE *fd) { wl_data_t *wl_data = hashcat_ctx->wl_data; @@ -70,15 +70,15 @@ void load_segment (hashcat_ctx_t *hashcat_ctx, FILE *fd) wl_data->buf[wl_data->cnt] = 0; - if (wl_data->cnt == 0) return; + if (wl_data->cnt == 0) return 0; - if (wl_data->buf[wl_data->cnt - 1] == '\n') return; + if (wl_data->buf[wl_data->cnt - 1] == '\n') return 0; 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->buf = (char *) hcrealloc (hashcat_ctx, wl_data->buf, wl_data->avail, wl_data->incr); VERIFY_PTR (wl_data->buf); wl_data->avail += wl_data->incr; } @@ -103,7 +103,7 @@ void load_segment (hashcat_ctx_t *hashcat_ctx, FILE *fd) wl_data->buf[wl_data->cnt - 1] = '\n'; } - return; + return 0; } void get_next_word_lm (char *buf, u64 sz, u64 *len, u64 *off) @@ -322,8 +322,8 @@ u64 count_words (hashcat_ctx_t *hashcat_ctx, FILE *fd, const char *dictfile) keyspace *= combinator_ctx->combs_cnt; } - if (user_options->quiet == false) log_info ("Cache-hit dictionary stats %s: %" PRIu64 " bytes, %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, d.stat.st_size, cached_cnt, keyspace); - if (user_options->quiet == false) log_info (""); + if (user_options->quiet == false) event_log_info (hashcat_ctx, "Cache-hit dictionary stats %s: %" PRIu64 " bytes, %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, d.stat.st_size, cached_cnt, keyspace); + if (user_options->quiet == false) event_log_info (hashcat_ctx, ""); //hc_signal (sigHandler_default); @@ -399,13 +399,13 @@ u64 count_words (hashcat_ctx_t *hashcat_ctx, FILE *fd, const char *dictfile) double percent = (double) comp / (double) d.stat.st_size; - if (user_options->quiet == false) log_info_nn ("Generating dictionary stats for %s: %" PRIu64 " bytes (%.2f%%), %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, comp, percent * 100, cnt2, cnt); + if (user_options->quiet == false) event_log_info_nn (hashcat_ctx, "Generating dictionary stats for %s: %" PRIu64 " bytes (%.2f%%), %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, comp, percent * 100, cnt2, cnt); time (&prev); } - if (user_options->quiet == false) log_info ("Generated dictionary stats for %s: %" PRIu64 " bytes, %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, comp, cnt2, cnt); - if (user_options->quiet == false) log_info (""); + if (user_options->quiet == false) event_log_info (hashcat_ctx, "Generated dictionary stats for %s: %" PRIu64 " bytes, %" PRIu64 " words, %" PRIu64 " keyspace", dictfile, comp, cnt2, cnt); + if (user_options->quiet == false) event_log_info (hashcat_ctx, ""); dictstat_append (hashcat_ctx, &d); @@ -414,7 +414,7 @@ u64 count_words (hashcat_ctx_t *hashcat_ctx, FILE *fd, const char *dictfile) return (cnt); } -void wl_data_init (hashcat_ctx_t *hashcat_ctx) +int wl_data_init (hashcat_ctx_t *hashcat_ctx) { hashconfig_t *hashconfig = hashcat_ctx->hashconfig; user_options_t *user_options = hashcat_ctx->user_options; @@ -422,16 +422,15 @@ void wl_data_init (hashcat_ctx_t *hashcat_ctx) wl_data->enabled = false; - if (user_options->benchmark == true) return; - if (user_options->keyspace == true) return; - if (user_options->left == true) return; - if (user_options->opencl_info == true) return; - if (user_options->usage == true) return; - if (user_options->version == true) return; + if (user_options->benchmark == true) return 0; + if (user_options->left == true) return 0; + if (user_options->opencl_info == true) return 0; + if (user_options->usage == true) return 0; + if (user_options->version == true) return 0; wl_data->enabled = true; - wl_data->buf = (char *) mymalloc (user_options->segment_size); + wl_data->buf = (char *) hcmalloc (hashcat_ctx, user_options->segment_size); VERIFY_PTR (wl_data->buf); wl_data->avail = user_options->segment_size; wl_data->incr = user_options->segment_size; wl_data->cnt = 0; @@ -452,6 +451,8 @@ void wl_data_init (hashcat_ctx_t *hashcat_ctx) { wl_data->func = get_next_word_lm; } + + return 0; } void wl_data_destroy (hashcat_ctx_t *hashcat_ctx) @@ -460,7 +461,7 @@ void wl_data_destroy (hashcat_ctx_t *hashcat_ctx) if (wl_data->enabled == false) return; - myfree (wl_data->buf); + hcfree (wl_data->buf); memset (wl_data, 0, sizeof (wl_data_t)); }