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/ext_ADL.h b/include/ext_ADL.h index f2f446a4b..5961cbf97 100644 --- a/include/ext_ADL.h +++ b/include/ext_ADL.h @@ -352,44 +352,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..b9ff6444f 100644 --- a/include/ext_nvml.h +++ b/include/ext_nvml.h @@ -221,28 +221,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/folder.h b/include/folder.h index f850ec276..652fe6b52 100644 --- a/include/folder.h +++ b/include/folder.h @@ -29,7 +29,6 @@ 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); diff --git a/include/hashes.h b/include/hashes.h index 561e7d0cf..79219b38c 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); diff --git a/include/hwmon.h b/include/hwmon.h index 1a0db1475..fed552356 100644 --- a/include/hwmon.h +++ b/include/hwmon.h @@ -6,6 +6,109 @@ #ifndef _HWMON_H #define _HWMON_H +// nvml functions + +int nvml_init (hashcat_ctx_t *hashcat_ctx); +void nvml_close (hashcat_ctx_t *hashcat_ctx); + +int hm_NVML_nvmlInit (hashcat_ctx_t *hashcat_ctx); +int hm_NVML_nvmlShutdown (hashcat_ctx_t *hashcat_ctx); + +int hm_NVML_nvmlDeviceGetHandleByIndex (hashcat_ctx_t *hashcat_ctx, unsigned int index, nvmlDevice_t *device); + +int hm_NVML_nvmlDeviceGetName (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, char *name, unsigned int length); +int hm_NVML_nvmlDeviceGetTemperature (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int *temp); +int hm_NVML_nvmlDeviceGetFanSpeed (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned int *speed); +int hm_NVML_nvmlDeviceGetPowerUsage (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned int *power); +int hm_NVML_nvmlDeviceGetUtilizationRates (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, nvmlUtilization_t *utilization); +int hm_NVML_nvmlDeviceGetClockInfo (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, nvmlClockType_t type, unsigned int *clock); +int hm_NVML_nvmlDeviceGetTemperatureThreshold (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, nvmlTemperatureThresholds_t thresholdType, unsigned int *temp); +int hm_NVML_nvmlDeviceGetCurrPcieLinkGeneration (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned int *currLinkGen); +int hm_NVML_nvmlDeviceGetCurrPcieLinkWidth (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned int *currLinkWidth); +int hm_NVML_nvmlDeviceGetCurrentClocksThrottleReasons (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned long long *clocksThrottleReasons); +int hm_NVML_nvmlDeviceGetSupportedClocksThrottleReasons (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned long long *supportedClocksThrottleReasons); +int hm_NVML_nvmlDeviceSetComputeMode (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, nvmlComputeMode_t mode); +int hm_NVML_nvmlDeviceSetGpuOperationMode (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, nvmlGpuOperationMode_t mode); +int hm_NVML_nvmlDeviceGetPowerManagementLimitConstraints (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned int *minLimit, unsigned int *maxLimit); +int hm_NVML_nvmlDeviceSetPowerManagementLimit (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned int limit); +int hm_NVML_nvmlDeviceGetPowerManagementLimit (hashcat_ctx_t *hashcat_ctx, nvmlDevice_t device, unsigned int *limit); + +// nvapi functions + +int nvapi_init (hashcat_ctx_t *hashcat_ctx); +void nvapi_close (hashcat_ctx_t *hashcat_ctx); + +int hm_NvAPI_QueryInterface (hashcat_ctx_t *hashcat_ctx, unsigned int offset); + +int hm_NvAPI_Initialize (hashcat_ctx_t *hashcat_ctx); +int hm_NvAPI_Unload (hashcat_ctx_t *hashcat_ctx); + +int hm_NvAPI_EnumPhysicalGPUs (hashcat_ctx_t *hashcat_ctx, NvPhysicalGpuHandle nvGPUHandle[NVAPI_MAX_PHYSICAL_GPUS], NvU32 *pGpuCount); +int hm_NvAPI_GPU_GetPerfPoliciesInfo (hashcat_ctx_t *hashcat_ctx, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_INFO_PARAMS_V1 *perfPolicies_info); +int hm_NvAPI_GPU_GetPerfPoliciesStatus (hashcat_ctx_t *hashcat_ctx, NvPhysicalGpuHandle hPhysicalGpu, NV_GPU_PERF_POLICIES_STATUS_PARAMS_V1 *perfPolicies_status); +int hm_NvAPI_GPU_SetCoolerLevels (hashcat_ctx_t *hashcat_ctx, NvPhysicalGpuHandle hPhysicalGpu, NvU32 coolerIndex, NV_GPU_COOLER_LEVELS *pCoolerLevels); +int hm_NvAPI_GPU_RestoreCoolerSettings (hashcat_ctx_t *hashcat_ctx, NvPhysicalGpuHandle hPhysicalGpu, NvU32 coolerIndex); + +// xnvctrl functions + +int xnvctrl_init (hashcat_ctx_t *hashcat_ctx); +void xnvctrl_close (hashcat_ctx_t *hashcat_ctx); + +int hm_XNVCTRL_XOpenDisplay (hashcat_ctx_t *hashcat_ctx); +void hm_XNVCTRL_XCloseDisplay (hashcat_ctx_t *hashcat_ctx); + +int get_core_threshold (hashcat_ctx_t *hashcat_ctx, const int gpu, int *val); + +int get_fan_control (hashcat_ctx_t *hashcat_ctx, const int gpu, int *val); +int set_fan_control (hashcat_ctx_t *hashcat_ctx, const int gpu, int val); + +int get_fan_speed_current (hashcat_ctx_t *hashcat_ctx, const int gpu, int *val); +int get_fan_speed_target (hashcat_ctx_t *hashcat_ctx, const int gpu, int *val); +int set_fan_speed_target (hashcat_ctx_t *hashcat_ctx, const int gpu, int val); + +// ADL functions + +int adl_init (hashcat_ctx_t *hashcat_ctx); +void adl_close (hashcat_ctx_t *hashcat_ctx); + +int hm_ADL_Main_Control_Destroy (hashcat_ctx_t *hashcat_ctx); +int hm_ADL_Main_Control_Create (hashcat_ctx_t *hashcat_ctx, ADL_MAIN_MALLOC_CALLBACK callback, int iEnumConnectedAdapters); + +int hm_ADL_Adapter_NumberOfAdapters_Get (hashcat_ctx_t *hashcat_ctx, int *lpNumAdapters); +int hm_ADL_Adapter_AdapterInfo_Get (hashcat_ctx_t *hashcat_ctx, LPAdapterInfo lpInfo, int iInputSize); +int hm_ADL_Display_DisplayInfo_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *iNumDisplays, ADLDisplayInfo **lppInfo, int iForceDetect); +int hm_ADL_Overdrive5_Temperature_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int iThermalControllerIndex, ADLTemperature *lpTemperature); +int hm_ADL_Overdrive6_Temperature_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *iTemperature); +int hm_ADL_Overdrive_CurrentActivity_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLPMActivity *lpActivity); +int hm_ADL_Overdrive_ThermalDevices_Enum (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int iThermalControllerIndex, ADLThermalControllerInfo *lpThermalControllerInfo); +int hm_ADL_Adapter_ID_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *lpAdapterID); +int hm_ADL_Adapter_VideoBiosInfo_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLBiosInfo *lpBiosInfo); +int hm_ADL_Overdrive5_FanSpeedInfo_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int iThermalControllerIndex, ADLFanSpeedInfo *lpFanSpeedInfo); +int hm_ADL_Overdrive5_FanSpeed_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int iThermalControllerIndex, ADLFanSpeedValue *lpFanSpeedValue); +int hm_ADL_Overdrive6_FanSpeed_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLOD6FanSpeedInfo *lpFanSpeedInfo); +int hm_ADL_Overdrive5_FanSpeed_Set (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int iThermalControllerIndex, ADLFanSpeedValue *lpFanSpeedValue); +int hm_ADL_Overdrive6_FanSpeed_Set (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLOD6FanSpeedValue *lpFanSpeedValue); +int hm_ADL_Overdrive5_FanSpeedToDefault_Set (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int iThermalControllerIndex); +int hm_ADL_Overdrive_ODParameters_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLODParameters *lpOdParameters); +int hm_ADL_Overdrive_ODPerformanceLevels_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int iDefault, ADLODPerformanceLevels *lpOdPerformanceLevels); +int hm_ADL_Overdrive_ODPerformanceLevels_Set (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLODPerformanceLevels *lpOdPerformanceLevels); +int hm_ADL_Overdrive_PowerControlInfo_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLOD6PowerControlInfo *); +int hm_ADL_Overdrive_PowerControl_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *level); +int hm_ADL_Overdrive_PowerControl_Set (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int level); +int hm_ADL_Adapter_Active_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *lpStatus); +//int hm_ADL_DisplayEnable_Set (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *lpDisplayIndexList, int iDisplayListSize, int bPersistOnly); +int hm_ADL_Overdrive_Caps (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *od_supported, int *od_enabled, int *od_version); +int hm_ADL_Overdrive_CurrentStatus_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLOD6CurrentStatus *status); +int hm_ADL_Overdrive_StateInfo_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int type, ADLOD6MemClockState *state); +int hm_ADL_Overdrive_Capabilities_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLOD6Capabilities *caps); +int hm_ADL_Overdrive_State_Set (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int type, ADLOD6StateInfo *state); +int hm_ADL_Overdrive6_PowerControl_Caps (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *lpSupported); +int hm_ADL_Overdrive6_TargetTemperatureData_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, int *cur_temp, int *default_temp); +int hm_ADL_Overdrive6_TargetTemperatureRangeInfo_Get (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex, ADLOD6ParameterRange *lpTargetTemperatureInfo); +int hm_ADL_Overdrive6_FanSpeed_Reset (hashcat_ctx_t *hashcat_ctx, int iAdapterIndex); + +// general functions + int hm_get_threshold_slowdown_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 device_id); int hm_get_threshold_shutdown_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 device_id); int hm_get_temperature_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 device_id); 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..b68bc526b 100644 --- a/include/memory.h +++ b/include/memory.h @@ -6,6 +6,7 @@ #ifndef _MEMORY_H #define _MEMORY_H +#include #include #include diff --git a/include/mpsp.h b/include/mpsp.h index 54fa909b0..44a6c0dca 100644 --- a/include/mpsp.h +++ b/include/mpsp.h @@ -23,20 +23,18 @@ 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]); +int mp_css_to_uniq_tbl (hashcat_ctx_t *hashcat_ctx, 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); +int mp_setup_usr (hashcat_ctx_t *hashcat_ctx, cs_t *mp_sys, cs_t *mp_usr, char *buf, u32 index); 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); 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/restore.h b/include/restore.h index 72a06955c..f42760638 100644 --- a/include/restore.h +++ b/include/restore.h @@ -25,13 +25,7 @@ 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); 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..a90ad77a1 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 (hashcat_ctx_t *hashcat_ctx); void send_prompt (); void clear_prompt (); diff --git a/include/thread.h b/include/thread.h index b73796af3..907af8aaa 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 mycracked (hashcat_ctx_t *hashcat_ctx); +void myabort (hashcat_ctx_t *hashcat_ctx); +void myquit (hashcat_ctx_t *hashcat_ctx); +void bypass (hashcat_ctx_t *hashcat_ctx); -void SuspendThreads (status_ctx_t *status_ctx); -void ResumeThreads (status_ctx_t *status_ctx); +void SuspendThreads (hashcat_ctx_t *hashcat_ctx); +void ResumeThreads (hashcat_ctx_t *hashcat_ctx); #endif // _THREAD_H diff --git a/include/types.h b/include/types.h index 0aa060ebc..e94ec7fed 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) @@ -418,6 +412,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; @@ -613,6 +608,8 @@ typedef struct wordr } wordr_t; +#include "ext_OpenCL.h" + typedef struct hc_device_param { cl_device_id device; @@ -819,15 +816,51 @@ typedef struct opencl_ctx double target_ms; - 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 { @@ -888,20 +921,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; @@ -1301,23 +1320,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; 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/src/Makefile b/src/Makefile index fa3920d78..f16476458 100644 --- a/src/Makefile +++ b/src/Makefile @@ -163,7 +163,7 @@ LFLAGS_CROSS_WIN := -lpsapi ## 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 event 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) diff --git a/src/autotune.c b/src/autotune.c index 0efeb165b..f0203345e 100644 --- a/src/autotune.c +++ b/src/autotune.c @@ -95,7 +95,7 @@ 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_int CL_err = 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) { @@ -109,7 +109,7 @@ static int autotune (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param { 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_int CL_err = 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) { @@ -248,8 +248,8 @@ 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)); @@ -280,6 +280,8 @@ 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 (); diff --git a/src/ext_ADL.c b/src/ext_ADL.c index 374673566..b8384997e 100644 --- a/src/ext_ADL.c +++ b/src/ext_ADL.c @@ -4,612 +4,11 @@ */ #include "common.h" -#include "logging.h" +#include "types.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); -} 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/folder.c b/src/folder.c index 368df70c8..6e595b3a5 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,7 +26,7 @@ int sort_by_stringptr (const void *p1, const void *p2) return strcmp (*s1, *s2); } -char *get_exec_path () +static char *get_exec_path () { size_t exec_path_len = 1024; @@ -48,12 +48,7 @@ char *get_exec_path () u32 size = (u32) exec_path_len; - if (_NSGetExecutablePath (exec_path, &size) != 0) - { - log_error("! executable path buffer too small\n"); - - exit (-1); - } + if (_NSGetExecutablePath (exec_path, &size) != 0) return NULL; const size_t len = strlen (exec_path); @@ -170,7 +165,7 @@ char **scan_directory (const char *path) if (readdir_r (d, &e, &de) != 0) { - log_error ("ERROR: readdir_r() failed"); + event_log_error (hashcat_ctx, "ERROR: readdir_r() failed"); break; } @@ -251,7 +246,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, const char *install_folder, if (getcwd (cwd, HCBUFSIZ_TINY - 1) == NULL) { - log_error ("ERROR: getcwd(): %s", strerror (errno)); + event_log_error (hashcat_ctx, "ERROR: getcwd(): %s", strerror (errno)); return -1; } @@ -262,6 +257,13 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, const char *install_folder, char *exec_path = get_exec_path (); + if (exec_path == NULL) + { + event_log_error (hashcat_ctx, "ERROR: get_exec_path() failed"); + + return -1; + } + #if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) if (install_folder == NULL) install_folder = "/"; // makes library use easier @@ -271,14 +273,14 @@ 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, "ERROR: %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, "ERROR: %s: %s", resolved_exec_path, strerror (errno)); return -1; } @@ -342,7 +344,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, const char *install_folder, if (GetFullPathName (cpath, HCBUFSIZ_TINY - 1, cpath_real, NULL) == 0) { - log_error ("ERROR: %s: %s", cpath, "GetFullPathName()"); + event_log_error (hashcat_ctx, "ERROR: %s: %s", cpath, "GetFullPathName()"); return -1; } @@ -355,7 +357,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, const char *install_folder, if (realpath (cpath, cpath_real) == NULL) { - log_error ("ERROR: %s: %s", cpath, strerror (errno)); + event_log_error (hashcat_ctx, "ERROR: %s: %s", cpath, strerror (errno)); return -1; } diff --git a/src/hashcat.c b/src/hashcat.c index 0ea3c91ca..6ba021604 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -1023,8 +1023,19 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold dictstat_write (hashcat_ctx); + // final logfile entry + + time (&status_ctx->proc_stop); + + logfile_top_uint (status_ctx->proc_start); + logfile_top_uint (status_ctx->proc_stop); + + EVENT (EVENT_LOGFILE_TOP_FINALIZE); + // free memory + EVENT (EVENT_GOODBYE_SCREEN); + debugfile_destroy (hashcat_ctx); tuning_db_destroy (hashcat_ctx); @@ -1051,13 +1062,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold restore_ctx_destroy (hashcat_ctx); - time (&status_ctx->proc_stop); - - logfile_top_uint (status_ctx->proc_start); - logfile_top_uint (status_ctx->proc_stop); - - EVENT (EVENT_LOGFILE_TOP_FINALIZE); - user_options_extra_destroy (hashcat_ctx); user_options_destroy (hashcat_ctx); @@ -1069,8 +1073,6 @@ int hashcat (hashcat_ctx_t *hashcat_ctx, char *install_folder, char *shared_fold if (status_ctx->devices_status == STATUS_EXHAUSTED) rc_final = 1; if (status_ctx->devices_status == STATUS_CRACKED) rc_final = 0; - EVENT (EVENT_GOODBYE_SCREEN); - event_ctx_destroy (hashcat_ctx); status_ctx_destroy (hashcat_ctx); diff --git a/src/hashes.c b/src/hashes.c index 02f292886..40d9e59d6 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" @@ -117,7 +117,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 +139,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, "ERROR: %s: %s", new_hashfile, strerror (errno)); - exit (-1); + return -1; } for (u32 salt_pos = 0; salt_pos < hashes->salts_cnt; salt_pos++) @@ -198,21 +198,23 @@ 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, "ERROR: 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, "ERROR: 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) @@ -309,11 +311,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 +322,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, "ERROR: clEnqueueReadBuffer(): %s\n", val2cstr_cl (CL_err)); return -1; } @@ -334,15 +335,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)); - 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, "ERROR: clEnqueueReadBuffer(): %s\n", val2cstr_cl (CL_err)); return -1; } @@ -375,7 +376,7 @@ 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]); } @@ -408,11 +409,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, "ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); return -1; } @@ -420,11 +421,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, "ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); return -1; } @@ -478,7 +479,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, "ERROR: %s: %s", hashes->hashfile, strerror (errno)); return -1; } @@ -500,12 +501,12 @@ 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, "ERROR: %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); @@ -513,7 +514,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) if (hashes_avail == 0) { - log_error ("ERROR: hashfile is empty or corrupt"); + event_log_error (hashcat_ctx, "ERROR: hashfile is empty or corrupt"); fclose (fp); @@ -524,7 +525,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, "ERROR: remove not supported in native hashfile-format mode"); fclose (fp); @@ -666,7 +667,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 { @@ -688,7 +689,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, "ERROR: hccap file not specified"); return -1; } @@ -701,14 +702,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, "ERROR: %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, "ERROR: hccap file is empty or corrupt"); fclose (fp); @@ -734,7 +735,7 @@ 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; } @@ -806,7 +807,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) } 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); @@ -821,7 +822,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) } 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)); } // show / left @@ -848,7 +849,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) } 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)); } } } @@ -868,7 +869,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) } 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,7 +882,7 @@ 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, "ERROR: %s: %s", hashfile, strerror (errno)); return -1; } @@ -910,7 +911,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)); continue; } @@ -963,7 +964,7 @@ 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; } @@ -976,14 +977,14 @@ 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_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++; @@ -998,12 +999,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->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); 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); @@ -1017,12 +1018,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->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); 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); @@ -1035,7 +1036,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) 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 +1044,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) { @@ -1062,7 +1063,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,7 +1072,7 @@ 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; @@ -1122,7 +1122,7 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx) salts_buf_new = (salt_t *) mycalloc (1, sizeof (salt_t)); } - 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; @@ -1248,7 +1248,7 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx) salts_done++; } - if (salts_done == salts_cnt) mycracked (status_ctx); + if (salts_done == salts_cnt) mycracked (hashcat_ctx); } myfree (hashes->digests_buf); diff --git a/src/hwmon.c b/src/hwmon.c index e0fc636d1..b83502c7b 100644 --- a/src/hwmon.c +++ b/src/hwmon.c @@ -6,16 +6,1799 @@ #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) +// nvml functions + +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) + { + 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) + // 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); + + myfree (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, 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 (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); + + myfree (nvml); + } +} + +static const char *hm_NVML_nvmlErrorString (NVML_PTR *nvml, const nvmlReturn_t nvml_rc) +{ + return nvml->nvmlErrorString (nvml_rc); +} + +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, "%s %d %s\n", "nvmlInit()", nvml_rc, string); + + return -1; + } + + return 0; +} + +int hm_NVML_nvmlShutdown (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->nvmlShutdown (); + + if (nvml_rc != NVML_SUCCESS) + { + const char *string = hm_NVML_nvmlErrorString (nvml, nvml_rc); + + event_log_error (hashcat_ctx, "%s %d %s\n", "nvmlShutdown()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceGetHandleByIndex()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceGetName()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceGetTemperature()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceGetFanSpeed()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceGetPowerUsage()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceGetUtilizationRates()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceGetClockInfo()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceGetTemperatureThreshold()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceGetCurrPcieLinkGeneration()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceGetCurrPcieLinkWidth()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceGetCurrentClocksThrottleReasons()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceGetSupportedClocksThrottleReasons()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceSetComputeMode()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceSetGpuOperationMode()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceGetPowerManagementLimitConstraints()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceSetPowerManagementLimit()", nvml_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "nvmlDeviceGetPowerManagementLimit()", nvml_rc, string); + + return -1; + } + + return 0; +} + +// nvapi functions + +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; +} + +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); + + myfree (nvapi); + } +} + +static void hm_NvAPI_GetErrorMessage (NVAPI_PTR *nvapi, const NvAPI_Status NvAPI_rc, NvAPI_ShortString string) +{ + nvapi->NvAPI_GetErrorMessage (NvAPI_rc, string); +} + +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, "%s %d %s\n", "NvAPI_Initialize()", NvAPI_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "NvAPI_Unload()", NvAPI_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "NvAPI_EnumPhysicalGPUs()", NvAPI_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "NvAPI_GPU_GetPerfPoliciesInfo()", NvAPI_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "NvAPI_GPU_GetPerfPoliciesStatus()", NvAPI_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "NvAPI_GPU_SetCoolerLevels()", NvAPI_rc, string); + + return -1; + } + + return 0; +} + +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, "%s %d %s\n", "NvAPI_GPU_RestoreCoolerSettings()", NvAPI_rc, string); + + return -1; + } + + return 0; +} + +#if defined (__MINGW64__) + +void __security_check_cookie (uintptr_t _StackCookie) +{ + (void) _StackCookie; +} + +void __GSHandlerCheck () +{ +} + +#endif + +// xnvctrl functions + +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) + { + //if (user_options->quiet == false) event_log_error (hashcat_ctx, "Failed loading the X11 library: %s", dlerror()); + //if (user_options->quiet == false) event_log_info (hashcat_ctx, " Please install libx11-dev package."); + //if (user_options->quiet == false) event_log_info (hashcat_ctx, ""); + + return -1; + } + + xnvctrl->lib_xnvctrl = dlopen ("libXNVCtrl.so", RTLD_LAZY); + + if (xnvctrl->lib_xnvctrl == NULL) + { + //if (user_options->quiet == false) event_log_error (hashcat_ctx, "Failed loading the XNVCTRL library: %s", dlerror()); + //if (user_options->quiet == false) event_log_info (hashcat_ctx, " Please install libxnvctrl-dev package."); + //if (user_options->quiet == false) event_log_info (hashcat_ctx, ""); + + 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 (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 + + myfree (xnvctrl); + } +} + +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, "%s\n", "XOpenDisplay() failed"); + + return -1; + } + + xnvctrl->dpy = dpy; + + return 0; +} + +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); +} + +int 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, "%s\n", "XNVCTRLQueryTargetAttribute(NV_CTRL_GPU_COOLER_MANUAL_CONTROL) failed"); + + return -1; + } + + return 0; +} + +int 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 = 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 = get_fan_control (hashcat_ctx, gpu, &cur); + + if (rc == -1) return -1; + + if (cur != val) return -1; + + return 0; +} + +int 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, "%s\n", "XNVCTRLQueryTargetAttribute(NV_CTRL_GPU_CORE_THRESHOLD) failed"); + + return -1; + } + + return 0; +} + +int 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, "%s\n", "XNVCTRLQueryTargetAttribute(NV_CTRL_THERMAL_COOLER_CURRENT_LEVEL) failed"); + + return -1; + } + + return 0; +} + +int 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\n", "XNVCTRLQueryTargetAttribute(NV_CTRL_THERMAL_COOLER_LEVEL) failed"); + + return -1; + } + + return 0; +} + +int 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 = 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 = get_fan_speed_target (hashcat_ctx, gpu, &cur); + + if (rc == -1) return -1; + + if (cur != val) return -1; + + return 0; +} + +// ADL functions + +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; +} + +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); + + myfree (adl); + } +} + +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, "%s: %d\n", "ADL_Main_Control_Destroy()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Main_Control_Create()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Adapter_NumberOfAdapters_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Adapter_AdapterInfo_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Display_DisplayInfo_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Adapter_ID_Get()", ADL_rc); + + return -1; + } + + return ADL_rc; +} + +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, "%s: %d\n", "ADL_Adapter_VideoBiosInfo_Get()", ADL_rc); + + return -1; + } + + return ADL_rc; +} + +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, "%s: %d\n", "ADL_Overdrive5_ThermalDevices_Enum()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive5_Temperature_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive6_Temperature_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive5_CurrentActivity_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive5_FanSpeedInfo_Get()", ADL_rc); + + return -1; + } + + return ADL_rc; +} + +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, "%s: %d\n", "ADL_Overdrive5_FanSpeed_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive6_FanSpeed_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive5_FanSpeed_Set()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive6_FanSpeed_Set()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive5_FanSpeedToDefault_Set()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive5_ODParameters_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive5_ODPerformanceLevels_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive5_ODPerformanceLevels_Set()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive6_PowerControlInfo_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive6_PowerControl_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive6_PowerControl_Set()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Adapter_Active_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +/* +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, "%s: %d\n", "ADL_DisplayEnable_Set()", ADL_rc); + + return -1; + } + + return 0; +} +*/ + +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, "%s: %d\n", "ADL_Overdrive_Caps()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive6_PowerControl_Caps()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive6_Capabilities_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive6_StateInfo_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive6_CurrentStatus_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive6_State_Set()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive6_TargetTemperatureData_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive6_TargetTemperatureRangeInfo_Get()", ADL_rc); + + return -1; + } + + return 0; +} + +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, "%s: %d\n", "ADL_Overdrive6_FanSpeed_Reset()", ADL_rc); + + return -1; + } + + return 0; +} + +// general functions + +static int get_adapters_num_adl (hashcat_ctx_t *hashcat_ctx, int *iNumberAdapters) { - if (hm_ADL_Adapter_NumberOfAdapters_Get (adl, iNumberAdapters) != ADL_OK) return -1; + const int hm_rc = hm_ADL_Adapter_NumberOfAdapters_Get (hashcat_ctx, iNumberAdapters); + + if (hm_rc == -1) return -1; if (iNumberAdapters == 0) { - log_info ("WARN: No ADL adapters found."); + event_log_error (hashcat_ctx, "No ADL adapters found."); return -1; } @@ -23,26 +1806,26 @@ 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 LPAdapterInfo hm_get_adapter_info_adl (hashcat_ctx_t *hashcat_ctx, int iNumberAdapters) { size_t AdapterInfoSize = iNumberAdapters * sizeof (AdapterInfo); LPAdapterInfo lpAdapterInfo = (LPAdapterInfo) mymalloc (AdapterInfoSize); - if (hm_ADL_Adapter_AdapterInfo_Get (adl, lpAdapterInfo, AdapterInfoSize) != ADL_OK) return NULL; + if (hm_ADL_Adapter_AdapterInfo_Get (hashcat_ctx, lpAdapterInfo, AdapterInfoSize) == -1) return NULL; return lpAdapterInfo; } -static int hm_get_adapter_index_nvapi (const hwmon_ctx_t *hwmon_ctx, HM_ADAPTER_NVAPI *nvapiGPUHandle) +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,24 +1833,24 @@ 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; for (u32 i = 0; i < DEVICES_MAX; i++) { - if (hm_NVML_nvmlDeviceGetHandleByIndex (hwmon_ctx->hm_nvml, 1, i, &nvmlGPUHandle[i]) != NVML_SUCCESS) break; + 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 (hwmon_ctx->hm_nvml, nvGPUHandle[i], name, sizeof (name) - 1); + // hm_NVML_nvmlDeviceGetName (hashcat_ctx, 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; } @@ -188,7 +1971,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 +2001,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 +2021,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 +2039,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 +2055,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 +2071,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 +2121,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 +2134,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 +2170,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 +2197,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 +2205,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 +2216,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 +2248,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 +2293,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 +2303,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 +2314,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 +2340,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 +2350,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 +2375,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 +2385,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 +2410,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 +2420,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 +2445,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 +2455,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; } @@ -695,8 +2482,8 @@ int hm_get_throttle_with_device_id (hashcat_ctx_t *hashcat_ctx, const u32 device 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; @@ -737,7 +2524,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 +2537,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 +2546,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 +2584,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 +2610,7 @@ 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 (set_fan_speed_target (hashcat_ctx, hwmon_ctx->hm_device[device_id].xnvctrl, fanspeed) == -1) return -1; return 0; } @@ -860,28 +2647,66 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) NVML_PTR *nvml = (NVML_PTR *) mymalloc (sizeof (NVML_PTR)); XNVCTRL_PTR *xnvctrl = (XNVCTRL_PTR *) mymalloc (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 *) 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) + { + myfree (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) + { + myfree (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) + { + myfree (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) + { + myfree (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)); - 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 +2719,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); } } - 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)); - 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; @@ -929,14 +2749,9 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) } } - 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,29 +2763,24 @@ 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 (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 = hm_get_adapter_info_adl (hashcat_ctx, hm_adapters_num); if (lpAdapterInfo == NULL) return -1; @@ -982,11 +2792,11 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) 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); @@ -1086,9 +2896,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, "ERROR: Failed to get ADL PowerControl Capabilities"); return -1; } @@ -1101,21 +2911,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, "ERROR: 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, "ERROR: Failed to set new ADL PowerControl values"); return -1; } @@ -1126,9 +2936,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, "ERROR: Failed to get ADL memory and engine clock frequency"); return -1; } @@ -1137,9 +2947,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, "ERROR: Failed to get ADL device capabilities"); return -1; } @@ -1157,12 +2967,12 @@ 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)); @@ -1174,9 +2984,9 @@ 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_info (hashcat_ctx, "ERROR: Failed to set ADL performance state"); return -1; } @@ -1191,16 +3001,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, "ERROR: 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, "ERROR: Failed to set new ADL PowerControl values"); return -1; } @@ -1216,7 +3026,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 +3038,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 @@ -1277,7 +3087,7 @@ 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); + rc = set_fan_control (hashcat_ctx, hwmon_ctx->hm_device[device_id].xnvctrl, NV_CTRL_GPU_COOLER_MANUAL_CONTROL_TRUE); #endif #if defined (_WIN) @@ -1291,7 +3101,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; } @@ -1336,7 +3146,7 @@ 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); + rc = set_fan_control (hashcat_ctx, hwmon_ctx->hm_device[device_id].xnvctrl, NV_CTRL_GPU_COOLER_MANUAL_CONTROL_FALSE); #endif #if defined (_WIN) @@ -1344,7 +3154,7 @@ void hwmon_ctx_destroy (hashcat_ctx_t *hashcat_ctx) #endif } - 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 +3175,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, "ERROR: Failed to get ADL PowerControl Capabilities"); continue; } @@ -1376,9 +3186,9 @@ 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_info (hashcat_ctx, "ERROR: Failed to restore the ADL PowerControl values"); continue; } @@ -1394,9 +3204,9 @@ 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, "ERROR: Failed to restore ADL performance state"); continue; } @@ -1412,7 +3222,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,30 +3231,30 @@ 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 diff --git a/src/induct.c b/src/induct.c index 61a0f454e..9a198c585 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" @@ -64,14 +64,14 @@ int induct_ctx_init (hashcat_ctx_t *hashcat_ctx) 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, "ERROR: 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, "ERROR: %s: %s", root_directory, strerror (errno)); return -1; } @@ -79,7 +79,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, "ERROR: %s: %s", root_directory, strerror (errno)); return -1; } @@ -142,7 +142,7 @@ 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, "ERROR: %s: %s", induct_ctx->root_directory, strerror (errno)); //return -1; } diff --git a/src/interface.c b/src/interface.c index df482ec9a..7c3064973 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"; @@ -2638,12 +2639,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 +2687,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; } @@ -2746,21 +2743,11 @@ int psafe2_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h 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; @@ -2793,21 +2780,11 @@ int psafe3_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const h 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; @@ -5122,21 +5099,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 }; @@ -5171,21 +5138,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 }; @@ -5220,21 +5177,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 }; @@ -5269,21 +5216,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 }; @@ -5318,21 +5255,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 }; @@ -5367,21 +5294,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 }; @@ -10810,8 +10727,6 @@ int sip_auth_parse_hash (char *input_buf, u32 input_len, hash_t *hash_buf, const 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); @@ -13103,7 +13018,9 @@ 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); @@ -19814,7 +19731,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, "ERROR: Unknown hash-type '%u' selected", hashconfig->hash_mode); return -1; } @@ -19826,7 +19743,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, "ERROR: Parameter hex-salt not valid for hash-type %u", hashconfig->hash_mode); return -1; } 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..7f956c28a 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 () @@ -90,7 +90,7 @@ int logfile_init (hashcat_ctx_t *hashcat_ctx) if (fp == NULL) { - log_error ("ERROR: %s: %s", logfile_ctx->logfile, strerror (errno)); + event_log_error (hashcat_ctx, "ERROR: %s: %s", logfile_ctx->logfile, strerror (errno)); return -1; } 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..63f60de9c 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" @@ -105,7 +105,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, "ERROR: %s: %s", loopback_ctx->filename, strerror (errno)); return -1; } diff --git a/src/main.c b/src/main.c index 42e193551..a98cb9e8d 100644 --- a/src/main.c +++ b/src/main.c @@ -89,7 +89,7 @@ static int main_welcome_screen (hashcat_ctx_t *hashcat_ctx, const void *buf, con { // sets dos window size (windows only) - setup_console (); + setup_console (hashcat_ctx); // Inform user things getting started @@ -324,7 +324,7 @@ static int main_potfile_remove_parse (hashcat_ctx_t *hashcat_ctx, const void *bu if (user_options->quiet == true) return 0; - event_log_info (hashcat_ctx, "Comparing hashes with potfile entries..."); + event_log_info_nn (hashcat_ctx, "Comparing hashes with potfile entries..."); return 0; } diff --git a/src/memory.c b/src/memory.c index 506e331a3..12ed019fb 100644 --- a/src/memory.c +++ b/src/memory.c @@ -4,7 +4,6 @@ */ #include "common.h" -#include "logging.h" #include "memory.h" void *mycalloc (size_t nmemb, size_t size) @@ -13,7 +12,7 @@ void *mycalloc (size_t nmemb, size_t size) if (p == NULL) { - log_error ("ERROR: %s", MSG_ENOMEM); + fprintf (stderr, "ERROR: %s", MSG_ENOMEM); exit (-1); } @@ -27,7 +26,7 @@ void *mymalloc (size_t size) if (p == NULL) { - log_error ("ERROR: %s", MSG_ENOMEM); + fprintf (stderr, "ERROR: %s", MSG_ENOMEM); exit (-1); } @@ -50,7 +49,7 @@ void *myrealloc (void *ptr, size_t oldsz, size_t add) if (p == NULL) { - log_error ("ERROR: %s", MSG_ENOMEM); + fprintf (stderr, "ERROR: %s", MSG_ENOMEM); exit (-1); } diff --git a/src/monitor.c b/src/monitor.c index b268d6289..d9da8752b 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -5,7 +5,7 @@ #include "common.h" #include "types.h" -#include "logging.h" +#include "event.h" #include "memory.h" #include "hwmon.h" #include "timer.h" @@ -17,7 +17,7 @@ #include "shared.h" #include "monitor.h" -static void monitor (hashcat_ctx_t *hashcat_ctx) +static int monitor (hashcat_ctx_t *hashcat_ctx) { hashes_t *hashes = hashcat_ctx->hashes; hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx; @@ -64,7 +64,7 @@ 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 @@ -115,11 +115,11 @@ static void monitor (hashcat_ctx_t *hashcat_ctx) 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); + 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 (hwmon_ctx->hm_nvapi, hwmon_ctx->hm_device[device_id].nvapi, &perfPolicies_status); + hm_NvAPI_GPU_GetPerfPoliciesStatus (hashcat_ctx, hwmon_ctx->hm_device[device_id].nvapi, &perfPolicies_status); if (perfPolicies_status.throttle & 2) { @@ -127,11 +127,11 @@ static void monitor (hashcat_ctx_t *hashcat_ctx) { if (user_options->quiet == false) clear_prompt (); - log_info ("WARNING: Drivers temperature threshold hit on GPU #%d, expect performance to drop...", device_id + 1); + event_log_warning (hashcat_ctx, "Drivers temperature threshold hit on GPU #%d, expect performance to drop...", device_id + 1); if (slowdown_warnings == 2) { - log_info (""); + event_log_info (hashcat_ctx, ""); } if (user_options->quiet == false) send_prompt (); @@ -174,9 +174,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_log_error (hashcat_ctx, "ERROR: Temperature limit on GPU %d reached, aborting...", device_id + 1); - myabort (status_ctx); + myabort (hashcat_ctx); break; } @@ -259,7 +259,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; } @@ -286,10 +288,10 @@ static void monitor (hashcat_ctx_t *hashcat_ctx) { if (user_options->benchmark == false) { - if (user_options->quiet == false) log_info ("\nNOTE: Runtime limit reached, aborting...\n"); + if (user_options->quiet == false) event_log_info (hashcat_ctx, "\nNOTE: Runtime limit reached, aborting...\n"); } - myabort (status_ctx); + myabort (hashcat_ctx); } } @@ -303,7 +305,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; @@ -320,11 +324,11 @@ static void monitor (hashcat_ctx_t *hashcat_ctx) if (user_options->quiet == false) clear_prompt (); - if (user_options->quiet == false) log_info (""); + if (user_options->quiet == false) event_log_info (hashcat_ctx, ""); status_display (hashcat_ctx); - if (user_options->quiet == false) log_info (""); + if (user_options->quiet == false) event_log_info (hashcat_ctx, ""); hc_thread_mutex_unlock (status_ctx->mux_display); @@ -339,7 +343,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 +353,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); myfree (temp_diff_old); myfree (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..b28d8f43f 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" @@ -130,15 +130,15 @@ void mp_css_unicode_expand (mask_ctx_t *mask_ctx) mask_ctx->css_cnt = css_cnt_unicode; } -void mp_css_to_uniq_tbl (u32 css_cnt, cs_t *css, u32 uniq_tbls[SP_PW_MAX][CHARSIZ]) +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, "ERROR: Mask length is too long"); - exit (-1); + return -1; } for (u32 css_pos = 0; css_pos < css_cnt; css_pos++) @@ -155,10 +155,14 @@ 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 void 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); @@ -192,8 +196,10 @@ static void mp_add_cs_buf (u32 *in_buf, size_t in_len, cs_t *css, u32 css_cnt, c myfree (css_uniq); } -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++) @@ -210,34 +216,34 @@ static void mp_expand (char *in_buf, size_t in_len, cs_t *mp_sys, cs_t *mp_usr, 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': 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': 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': 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': 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': 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': 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, "ERROR: Custom-charset 1 is undefined"); return -1; } + 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, "ERROR: Custom-charset 2 is undefined"); return -1; } + 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, "ERROR: Custom-charset 3 is undefined"); return -1; } + 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, "ERROR: Custom-charset 4 is undefined"); return -1; } + 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 '?': 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; } } else @@ -248,18 +254,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, "ERROR: 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, "ERROR: Invalid hex character detected in mask %s", in_buf); - exit (-1); + return -1; } u32 chr = 0; @@ -267,32 +273,24 @@ 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); + mp_add_cs_buf (hashcat_ctx, &chr, 1, mp_usr, mp_usr_offset); } else { u32 chr = p0; - mp_add_cs_buf (&chr, 1, mp_usr, mp_usr_offset, hashconfig); + mp_add_cs_buf (hashcat_ctx, &chr, 1, mp_usr, mp_usr_offset); } } } -} -u64 mp_get_sum (u32 css_cnt, cs_t *css) -{ - u64 sum = 1; - - for (u32 css_pos = 0; css_pos < css_cnt; css_pos++) - { - sum *= css[css_pos].cs_len; - } - - return (sum); + return 0; } -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) +static cs_t *mp_gen_css (hashcat_ctx_t *hashcat_ctx, char *mask_buf, size_t mask_len, cs_t *mp_sys, cs_t *mp_usr, u32 *css_cnt) { + const user_options_t *user_options = hashcat_ctx->user_options; + cs_t *css = (cs_t *) mycalloc (256, sizeof (cs_t)); u32 mask_pos; @@ -314,34 +312,34 @@ cs_t *mp_gen_css (char *mask_buf, size_t mask_len, cs_t *mp_sys, cs_t *mp_usr, u switch (p1) { - case 'l': mp_add_cs_buf (mp_sys[0].cs_buf, mp_sys[0].cs_len, css, css_pos, hashconfig); + case 'l': mp_add_cs_buf (hashcat_ctx, mp_sys[0].cs_buf, mp_sys[0].cs_len, css, 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': mp_add_cs_buf (hashcat_ctx, mp_sys[1].cs_buf, mp_sys[1].cs_len, css, 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': mp_add_cs_buf (hashcat_ctx, mp_sys[2].cs_buf, mp_sys[2].cs_len, css, 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': mp_add_cs_buf (hashcat_ctx, mp_sys[3].cs_buf, mp_sys[3].cs_len, css, 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': mp_add_cs_buf (hashcat_ctx, mp_sys[4].cs_buf, mp_sys[4].cs_len, css, 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': mp_add_cs_buf (hashcat_ctx, mp_sys[5].cs_buf, mp_sys[5].cs_len, css, 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, "ERROR: Custom-charset 1 is undefined\n"); return NULL; } + mp_add_cs_buf (hashcat_ctx, mp_usr[0].cs_buf, mp_usr[0].cs_len, css, 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, "ERROR: Custom-charset 2 is undefined\n"); return NULL; } + mp_add_cs_buf (hashcat_ctx, mp_usr[1].cs_buf, mp_usr[1].cs_len, css, 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, "ERROR: Custom-charset 3 is undefined\n"); return NULL; } + mp_add_cs_buf (hashcat_ctx, mp_usr[2].cs_buf, mp_usr[2].cs_len, css, 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, "ERROR: Custom-charset 4 is undefined\n"); return NULL; } + mp_add_cs_buf (hashcat_ctx, mp_usr[3].cs_buf, mp_usr[3].cs_len, css, css_pos); break; - case '?': mp_add_cs_buf (&chr, 1, css, css_pos, hashconfig); + case '?': mp_add_cs_buf (hashcat_ctx, &chr, 1, css, css_pos); break; - default: log_error ("ERROR: Syntax error: %s", mask_buf); - exit (-1); + default: event_log_error (hashcat_ctx, "ERROR: Syntax error: %s", mask_buf); + return NULL; } } else @@ -354,9 +352,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, "ERROR: The hex-charset option always expects couples of exactly 2 hexadecimal chars, failed mask: %s", mask_buf); - exit (-1); + return NULL; } char p1 = mask_buf[mask_pos]; @@ -365,9 +363,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, "ERROR: Invalid hex character detected in mask %s", mask_buf); - exit (-1); + return NULL; } u32 chr = 0; @@ -375,22 +373,22 @@ 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); + mp_add_cs_buf (hashcat_ctx, &chr, 1, css, css_pos); } else { u32 chr = (u32) p0; - mp_add_cs_buf (&chr, 1, css, css_pos, hashconfig); + mp_add_cs_buf (hashcat_ctx, &chr, 1, css, css_pos); } } } if (css_pos == 0) { - log_error ("ERROR: Invalid mask length (0)"); + event_log_error (hashcat_ctx, "ERROR: Invalid mask length (0)"); - exit (-1); + return NULL; } *css_cnt = css_pos; @@ -398,6 +396,80 @@ cs_t *mp_gen_css (char *mask_buf, size_t mask_len, cs_t *mp_sys, cs_t *mp_usr, u return (css); } +static char *mp_get_truncated_mask (hashcat_ctx_t *hashcat_ctx, const char *mask_buf, const size_t mask_len, const u32 len) +{ + const user_options_t *user_options = hashcat_ctx->user_options; + + char *new_mask_buf = (char *) mymalloc (256); + + u32 mask_pos; + + u32 css_pos; + + for (mask_pos = 0, css_pos = 0; mask_pos < mask_len; mask_pos++, css_pos++) + { + if (css_pos == len) break; + + char p0 = mask_buf[mask_pos]; + + new_mask_buf[mask_pos] = p0; + + if (p0 == '?') + { + mask_pos++; + + if (mask_pos == mask_len) break; + + new_mask_buf[mask_pos] = mask_buf[mask_pos]; + } + else + { + if (user_options->hex_charset == true) + { + mask_pos++; + + if (mask_pos == mask_len) + { + event_log_error (hashcat_ctx, "ERROR: The hex-charset option always expects couples of exactly 2 hexadecimal chars, failed mask: %s", mask_buf); + + return NULL; + } + + char p1 = mask_buf[mask_pos]; + + // if they are not valid hex character, show an error: + + if ((is_valid_hex_char ((u8) p0) == false) || (is_valid_hex_char ((u8) p1) == false)) + { + event_log_error (hashcat_ctx, "ERROR: Invalid hex character detected in mask: %s", mask_buf); + + return NULL; + } + + new_mask_buf[mask_pos] = p1; + } + } + } + + if (css_pos == len) return (new_mask_buf); + + myfree (new_mask_buf); + + return (NULL); +} + +u64 mp_get_sum (u32 css_cnt, cs_t *css) +{ + u64 sum = 1; + + for (u32 css_pos = 0; css_pos < css_cnt; css_pos++) + { + sum *= css[css_pos].cs_len; + } + + return (sum); +} + void mp_exec (u64 val, char *buf, cs_t *css, int css_cnt) { for (int i = 0; i < css_cnt; i++) @@ -469,13 +541,15 @@ void mp_setup_sys (cs_t *mp_sys) 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) +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 { - mp_expand (buf, strlen (buf), mp_sys, mp_usr, index, 1, hashconfig, user_options); + const int rc = mp_expand (hashcat_ctx, buf, strlen (buf), mp_sys, mp_usr, index, 1); + + if (rc == -1) return -1; } else { @@ -489,131 +563,45 @@ void mp_setup_usr (cs_t *mp_sys, cs_t *mp_usr, char *buf, u32 index, const hashc 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); - - u32 mask_pos; - - u32 css_pos; - - for (mask_pos = 0, css_pos = 0; mask_pos < mask_len; mask_pos++, css_pos++) - { - if (css_pos == len) break; - - char p0 = mask_buf[mask_pos]; - - new_mask_buf[mask_pos] = p0; - - if (p0 == '?') - { - mask_pos++; + event_log_warning (hashcat_ctx, "Charset file corrupted"); - if (mask_pos == mask_len) break; + const int rc = mp_expand (hashcat_ctx, buf, strlen (buf), mp_sys, mp_usr, index, 1); - new_mask_buf[mask_pos] = mask_buf[mask_pos]; + if (rc == -1) return -1; } else { - if (user_options->hex_charset == true) - { - mask_pos++; - - 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); + const int rc = mp_expand (hashcat_ctx, mp_file, (size_t) len, mp_sys, mp_usr, index, 0); - exit (-1); - } - - char p1 = mask_buf[mask_pos]; - - // if they are not valid hex character, show an error: - - 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); - - exit (-1); - } - - new_mask_buf[mask_pos] = p1; - } + if (rc == -1) return -1; } } - 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) +void mp_reset_usr (cs_t *mp_usr, u32 index) { - u64 sum = 1; - - u32 i; - - for (i = start; i < stop; i++) - { - sum *= root_css_buf[i].cs_len; - } + mp_usr[index].cs_len = 0; - return (sum); + memset (mp_usr[index].cs_buf, 0, sizeof (mp_usr[index].cs_buf)); } -void sp_exec (u64 ctx, char *pw_buf, cs_t *root_css_buf, cs_t *markov_css_buf, u32 start, u32 stop) +static int sp_setup_tbl (hashcat_ctx_t *hashcat_ctx) { - u64 v = ctx; - - cs_t *cs = &root_css_buf[start]; - - u32 i; + 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; - 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]; + char *shared_dir = folder_config->shared_dir; - pw_buf[i - start] = (char) k; - - cs = &markov_css_buf[(i * CHARSIZ) + k]; - } -} - -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; + char *hcstat = user_options->markov_hcstat; + u32 disable = user_options->markov_disable; + u32 classic = user_options->markov_classic; - return b2->val - b1->val; -} + 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; @@ -668,27 +656,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); @@ -813,6 +801,53 @@ 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; +} + +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); +} + +void sp_exec (u64 ctx, char *pw_buf, cs_t *root_css_buf, cs_t *markov_css_buf, u32 start, u32 stop) +{ + u64 v = ctx; + + 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]; + } +} + +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; } 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]) @@ -947,13 +982,16 @@ static void mask_append_final (mask_ctx_t *mask_ctx, const char *mask) mask_ctx->masks_cnt++; } -static void mask_append (mask_ctx_t *mask_ctx, const user_options_t *user_options, const char *mask) +static void mask_append (hashcat_ctx_t *hashcat_ctx, const char *mask) { + mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + 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 = mp_get_truncated_mask (hashcat_ctx, mask, strlen (mask), increment_len); if (mask_truncated == NULL) break; @@ -991,11 +1029,13 @@ 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 = mp_gen_css (hashcat_ctx, mask_ctx->mask, strlen (mask_ctx->mask), mask_ctx->mp_sys, mask_ctx->mp_usr, &mask_ctx->css_cnt); + + if (mask_ctx->css_buf == NULL) 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 +1060,9 @@ 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 = mp_gen_css (hashcat_ctx, mask_ctx->mask, strlen (mask_ctx->mask), mask_ctx->mp_sys, mask_ctx->mp_usr, &mask_ctx->css_cnt); + + if (mask_ctx->css_buf == NULL) return -1; // special case for benchmark @@ -1045,12 +1087,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 @@ -1083,7 +1125,7 @@ int mask_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) 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); @@ -1108,8 +1150,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; @@ -1130,7 +1170,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) 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)); - 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)); @@ -1148,10 +1188,10 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) 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 +1205,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (stat (arg, &file_stat) == -1) { - mask_append (mask_ctx, user_options, arg); + mask_append (hashcat_ctx, arg); } else { @@ -1177,7 +1217,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, "ERROR: %s: %s", arg, strerror (errno)); return -1; } @@ -1188,7 +1228,7 @@ 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, "ERROR: %s: %s", arg, strerror (errno)); return -1; } @@ -1203,7 +1243,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (line_buf[0] == '#') continue; - mask_append (mask_ctx, user_options, line_buf); + mask_append (hashcat_ctx, line_buf); } myfree (line_buf); @@ -1212,7 +1252,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) } else { - log_error ("ERROR: %s: unsupported file-type", arg); + event_log_error (hashcat_ctx, "ERROR: %s: unsupported file-type", arg); return -1; } @@ -1223,14 +1263,14 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) { const char *mask = DEF_MASK; - mask_append (mask_ctx, user_options, mask); + mask_append (hashcat_ctx, mask); } } else { const char *mask = hashconfig_benchmark_mask (hashcat_ctx); - mask_append (mask_ctx, user_options, mask); + mask_append (hashcat_ctx, mask); } } else if (user_options->attack_mode == ATTACK_MODE_HYBRID1) @@ -1245,7 +1285,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (stat (arg, &file_stat) == -1) { - mask_append (mask_ctx, user_options, arg); + mask_append (hashcat_ctx, arg); } else { @@ -1257,7 +1297,7 @@ 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, "ERROR: %s: %s", arg, strerror (errno)); return -1; } @@ -1272,7 +1312,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (line_buf[0] == '#') continue; - mask_append (mask_ctx, user_options, line_buf); + mask_append (hashcat_ctx, line_buf); } myfree (line_buf); @@ -1281,7 +1321,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) } else { - log_error ("ERROR: %s: unsupported file-type", arg); + event_log_error (hashcat_ctx, "ERROR: %s: unsupported file-type", arg); return -1; } @@ -1299,7 +1339,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (stat (arg, &file_stat) == -1) { - mask_append (mask_ctx, user_options, arg); + mask_append (hashcat_ctx, arg); } else { @@ -1311,7 +1351,7 @@ 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, "ERROR: %s: %s", arg, strerror (errno)); return -1; } @@ -1326,7 +1366,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (line_buf[0] == '#') continue; - mask_append (mask_ctx, user_options, line_buf); + mask_append (hashcat_ctx, line_buf); } myfree (line_buf); @@ -1335,7 +1375,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) } else { - log_error ("ERROR: %s: unsupported file-type", arg); + event_log_error (hashcat_ctx, "ERROR: %s: unsupported file-type", arg); return -1; } @@ -1344,7 +1384,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, "ERROR: Invalid mask"); return -1; } @@ -1382,7 +1422,6 @@ void mask_ctx_destroy (hashcat_ctx_t *hashcat_ctx) 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 +1471,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, "ERROR: Invalid line '%s' in maskfile", mask_buf); return -1; } @@ -1457,25 +1496,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 956518c19..85013a8ec 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -24,6 +24,7 @@ #include "hashes.h" #include "cpu_md5.h" #include "event.h" +#include "dynloader.h" #include "opencl.h" static const u32 full01 = 0x01010101; @@ -97,7 +98,7 @@ 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 (hashcat_ctx_t *hashcat_ctx, 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; @@ -115,7 +116,7 @@ static u32 setup_opencl_platforms_filter (hashcat_ctx_t *hashcat_ctx, const char { event_log_error (hashcat_ctx, "ERROR: Invalid OpenCL platform %u specified", platform); - exit (-1); + return -1; } opencl_platforms_filter |= 1u << (platform - 1); @@ -129,10 +130,12 @@ static u32 setup_opencl_platforms_filter (hashcat_ctx_t *hashcat_ctx, const char opencl_platforms_filter = -1u; } - return opencl_platforms_filter; + *out = opencl_platforms_filter; + + return 0; } -static u32 setup_devices_filter (hashcat_ctx_t *hashcat_ctx, const char *opencl_devices) +static int setup_devices_filter (hashcat_ctx_t *hashcat_ctx, const char *opencl_devices, u32 *out) { u32 devices_filter = 0; @@ -150,7 +153,7 @@ static u32 setup_devices_filter (hashcat_ctx_t *hashcat_ctx, const char *opencl_ { event_log_error (hashcat_ctx, "ERROR: Invalid device_id %u specified", device_id); - exit (-1); + return -1; } devices_filter |= 1u << (device_id - 1); @@ -164,10 +167,12 @@ static u32 setup_devices_filter (hashcat_ctx_t *hashcat_ctx, const char *opencl_ devices_filter = -1u; } - return devices_filter; + *out = devices_filter; + + return 0; } -static cl_device_type setup_device_types_filter (hashcat_ctx_t *hashcat_ctx, 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; @@ -185,7 +190,7 @@ static cl_device_type setup_device_types_filter (hashcat_ctx_t *hashcat_ctx, con { event_log_error (hashcat_ctx, "ERROR: Invalid device_type %u specified", device_type); - exit (-1); + return -1; } device_types_filter |= 1u << device_type; @@ -199,86 +204,757 @@ static cl_device_type setup_device_types_filter (hashcat_ctx_t *hashcat_ctx, con // Do not use CPU by default, this often reduces GPU performance because // the CPU is too busy to handle GPU synchronization - device_types_filter = CL_DEVICE_TYPE_ALL & ~CL_DEVICE_TYPE_CPU; + device_types_filter = CL_DEVICE_TYPE_ALL & ~CL_DEVICE_TYPE_CPU; + } + + *out = device_types_filter; + + return 0; +} + +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"); + + if (fp != NULL) + { + struct stat st; + + memset (&st, 0, sizeof (st)); + + stat (kernel_file, &st); + + char *buf = (char *) mymalloc (st.st_size + 1); + + size_t num_read = fread (buf, sizeof (char), st.st_size, fp); + + if (num_read != (size_t) st.st_size) + { + event_log_error (hashcat_ctx, "ERROR: %s: %s", kernel_file, strerror (errno)); + + return -1; + } + + fclose (fp); + + buf[st.st_size] = 0; + + for (int i = 0; i < num_devices; i++) + { + kernel_lengths[i] = (size_t) st.st_size; + + kernel_sources[i] = buf; + } + } + else + { + event_log_error (hashcat_ctx, "ERROR: %s: %s", kernel_file, strerror (errno)); + + return -1; + } + + return 0; +} + +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 (kernel_file, "wb"); + + if (fp == NULL) + { + event_log_error (hashcat_ctx, "ERROR: %s: %s", kernel_file, strerror (errno)); + + return -1; + } + + const int rc = lock_file (fp); + + if (rc == -1) return -1; + + 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_info (hashcat_ctx, ""); + event_log_info (hashcat_ctx, "ATTENTION! Can't find OpenCL ICD loader library"); + event_log_info (hashcat_ctx, ""); + #if defined (__linux__) + event_log_info (hashcat_ctx, "You're probably missing the \"ocl-icd-libopencl1\" package (Debian/Ubuntu)"); + event_log_info (hashcat_ctx, " sudo apt-get install ocl-icd-libopencl1"); + event_log_info (hashcat_ctx, ""); + #elif defined (_WIN) + event_log_info (hashcat_ctx, "You're probably missing the OpenCL runtime installation"); + event_log_info (hashcat_ctx, " AMD users require AMD drivers 14.9 or later (recommended 15.12 or later)"); + event_log_info (hashcat_ctx, " Intel users require Intel OpenCL Runtime 14.2 or later (recommended 15.1 or later)"); + event_log_info (hashcat_ctx, " NVidia users require NVidia drivers 346.59 or later (recommended 361.x or later)"); + event_log_info (hashcat_ctx, ""); + #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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: clGetProgramBuildInfo(): %s", val2cstr_cl (CL_err)); + + return -1; } - return device_types_filter; + return 0; } -static void read_kernel_binary (hashcat_ctx_t *hashcat_ctx, const char *kernel_file, int num_devices, size_t *kernel_lengths, char **kernel_sources) +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) { - FILE *fp = fopen (kernel_file, "rb"); - - if (fp != NULL) - { - struct stat st; - - memset (&st, 0, sizeof (st)); + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - stat (kernel_file, &st); + OCL_PTR *ocl = opencl_ctx->ocl; - char *buf = (char *) mymalloc (st.st_size + 1); + const cl_int CL_err = ocl->clGetProgramInfo (program, param_name, param_value_size, param_value, param_value_size_ret); - size_t num_read = fread (buf, sizeof (char), st.st_size, fp); + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "ERROR: clGetProgramInfo(): %s", val2cstr_cl (CL_err)); - if (num_read != (size_t) st.st_size) - { - event_log_error (hashcat_ctx, "ERROR: %s: %s", kernel_file, strerror (errno)); + return -1; + } - exit (-1); - } + return 0; +} - fclose (fp); +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; - buf[st.st_size] = 0; + OCL_PTR *ocl = opencl_ctx->ocl; - for (int i = 0; i < num_devices; i++) - { - kernel_lengths[i] = (size_t) st.st_size; + const cl_int CL_err = ocl->clWaitForEvents (num_events, event_list); - kernel_sources[i] = buf; - } - } - else + if (CL_err != CL_SUCCESS) { - event_log_error (hashcat_ctx, "ERROR: %s: %s", kernel_file, strerror (errno)); + event_log_error (hashcat_ctx, "ERROR: clWaitForEvents(): %s", val2cstr_cl (CL_err)); - exit (-1); + return -1; } - return; + return 0; } -static void write_kernel_binary (hashcat_ctx_t *hashcat_ctx, char *kernel_file, char *binary, size_t binary_size) +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) { - if (binary_size > 0) - { - FILE *fp = fopen (kernel_file, "wb"); + opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - if (fp == NULL) - { - event_log_error (hashcat_ctx, "ERROR: %s: %s", kernel_file, strerror (errno)); + OCL_PTR *ocl = opencl_ctx->ocl; - exit (-1); - } + const cl_int CL_err = ocl->clGetEventProfilingInfo (event, param_name, param_value_size, param_value, param_value_size_ret); - lock_file (fp); - fwrite (binary, sizeof (char), binary_size, fp); + if (CL_err != CL_SUCCESS) + { + event_log_error (hashcat_ctx, "ERROR: clGetEventProfilingInfo(): %s", val2cstr_cl (CL_err)); - fflush (fp); - fclose (fp); + 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) +int hc_clReleaseEvent (hashcat_ctx_t *hashcat_ctx, cl_event event) { opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; - 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); + OCL_PTR *ocl = opencl_ctx->ocl; + + const cl_int CL_err = ocl->clReleaseEvent (event); if (CL_err != CL_SUCCESS) { - event_log_error (hashcat_ctx, "ERROR: clEnqueueReadBuffer(): %s\n", val2cstr_cl (CL_err)); + event_log_error (hashcat_ctx, "ERROR: clReleaseEvent(): %s", val2cstr_cl (CL_err)); return -1; } @@ -286,11 +962,19 @@ int gidd_to_pw_t (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, c return 0; } +int gidd_to_pw_t (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u64 gidd, pw_t *pw) +{ + cl_int CL_err = 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); + + if (CL_err != CL_SUCCESS) return -1; + + return 0; +} + 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) { 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; @@ -298,9 +982,7 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, if (hashconfig->hash_mode == 2000) { - process_stdout (hashcat_ctx, device_param, pws_cnt); - - return 0; + return process_stdout (hashcat_ctx, device_param, pws_cnt); } if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL) @@ -315,14 +997,9 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, run_kernel_tm (hashcat_ctx, device_param); - 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_err = 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_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueCopyBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -1) return -1; } } @@ -349,25 +1026,15 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, { 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_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueReadBuffer(): %s\n", val2cstr_cl (CL_err)); + CL_err = 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_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); + CL_err = 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); - return -1; - } + if (CL_err == -1) return -1; } u32 iter = hashes->salts_buf[salt_pos].salt_iter; @@ -413,25 +1080,15 @@ int choose_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, { 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_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueReadBuffer(): %s\n", val2cstr_cl (CL_err)); + CL_err = 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_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); + CL_err = 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); - return -1; - } + if (CL_err == -1) return -1; } run_kernel (hashcat_ctx, device_param, KERN_RUN_3, pws_cnt, false, 0); @@ -443,7 +1100,6 @@ 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; @@ -468,24 +1124,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]); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 24, sizeof (cl_uint), device_param->kernel_params[24]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 25, sizeof (cl_uint), device_param->kernel_params[25]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 26, sizeof (cl_uint), device_param->kernel_params[26]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 27, sizeof (cl_uint), device_param->kernel_params[27]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 28, sizeof (cl_uint), device_param->kernel_params[28]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 29, sizeof (cl_uint), device_param->kernel_params[29]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 30, sizeof (cl_uint), device_param->kernel_params[30]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 31, sizeof (cl_uint), device_param->kernel_params[31]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 32, sizeof (cl_uint), device_param->kernel_params[32]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 33, sizeof (cl_uint), device_param->kernel_params[33]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 34, sizeof (cl_uint), device_param->kernel_params[34]); - return -1; - } + if (CL_err == -1) return -1; cl_event event; @@ -494,14 +1145,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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueNDRangeKernel(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clEnqueueNDRangeKernel (hashcat_ctx, device_param->command_queue, kernel, 2, NULL, global_work_size, local_work_size, 0, NULL, &event); - return -1; - } + if (CL_err == -1) return -1; } else { @@ -518,24 +1164,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_err = 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) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueNDRangeKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -1) return -1; } - CL_err = hc_clFlush (opencl_ctx->ocl, device_param->command_queue); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clFlush(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clFlush (hashcat_ctx, device_param->command_queue); - return -1; - } + if (CL_err == -1) return -1; if (device_param->nvidia_spin_damp > 0) { @@ -553,27 +1189,17 @@ int run_kernel (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, con } } - CL_err = hc_clWaitForEvents (opencl_ctx->ocl, 1, &event); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clWaitForEvents(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clWaitForEvents (hashcat_ctx, 1, &event); - return -1; - } + if (CL_err == -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) - { - event_log_error (hashcat_ctx, "ERROR: clGetEventProfilingInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err |= hc_clGetEventProfilingInfo (hashcat_ctx, event, CL_PROFILING_COMMAND_START, sizeof (time_start), &time_start, NULL); + CL_err |= hc_clGetEventProfilingInfo (hashcat_ctx, event, CL_PROFILING_COMMAND_END, sizeof (time_end), &time_end, NULL); - return -1; - } + if (CL_err == -1) return -1; const double exec_us = (double) (time_end - time_start) / 1000; @@ -606,31 +1232,19 @@ 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_err = hc_clReleaseEvent (hashcat_ctx, event); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clReleaseEvent(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - CL_err = hc_clFinish (opencl_ctx->ocl, device_param->command_queue); + if (CL_err == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clFinish(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clFinish (hashcat_ctx, device_param->command_queue); - return -1; - } + if (CL_err == -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; u32 num_elements = num; @@ -660,74 +1274,52 @@ 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_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp[3]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp[4]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp[5]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp[6]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp[7]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 8, sizeof (cl_uint), device_param->kernel_params_mp[8]); 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_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp_r[3]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp_r[4]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp_r[5]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp_r[6]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp_r[7]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 8, sizeof (cl_uint), device_param->kernel_params_mp_r[8]); 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_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 3, sizeof (cl_ulong), device_param->kernel_params_mp_l[3]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 4, sizeof (cl_uint), device_param->kernel_params_mp_l[4]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 5, sizeof (cl_uint), device_param->kernel_params_mp_l[5]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 6, sizeof (cl_uint), device_param->kernel_params_mp_l[6]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 7, sizeof (cl_uint), device_param->kernel_params_mp_l[7]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 8, sizeof (cl_uint), device_param->kernel_params_mp_l[8]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 9, sizeof (cl_uint), device_param->kernel_params_mp_l[9]); break; } - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueNDRangeKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - CL_err = hc_clFlush (opencl_ctx->ocl, device_param->command_queue); + CL_err = 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) - { - event_log_error (hashcat_ctx, "ERROR: clFlush(): %s\n", val2cstr_cl (CL_err)); + if (CL_err == -1) return -1; - return -1; - } + CL_err = hc_clFlush (hashcat_ctx, device_param->command_queue); - CL_err = hc_clFinish (opencl_ctx->ocl, device_param->command_queue); + if (CL_err == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clFinish(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clFinish (hashcat_ctx, device_param->command_queue); - return -1; - } + if (CL_err == -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; const u32 num_elements = 1024; // fixed @@ -739,40 +1331,23 @@ 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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueNDRangeKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - CL_err = hc_clFlush (opencl_ctx->ocl, device_param->command_queue); + CL_err = 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) - { - event_log_error (hashcat_ctx, "ERROR: clFlush(): %s\n", val2cstr_cl (CL_err)); + if (CL_err == -1) return -1; - return -1; - } + CL_err = hc_clFlush (hashcat_ctx, device_param->command_queue); - CL_err = hc_clFinish (opencl_ctx->ocl, device_param->command_queue); + if (CL_err == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clFinish(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clFinish (hashcat_ctx, device_param->command_queue); - return -1; - } + if (CL_err == -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; u32 num_elements = num; @@ -788,52 +1363,30 @@ 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]); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 6, sizeof (cl_uint), device_param->kernel_params_amp[6]); - return -1; - } + if (CL_err == -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_err = 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) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueNDRangeKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - CL_err = hc_clFlush (opencl_ctx->ocl, device_param->command_queue); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clFlush(): %s\n", val2cstr_cl (CL_err)); + if (CL_err == -1) return -1; - return -1; - } + CL_err = hc_clFlush (hashcat_ctx, device_param->command_queue); - CL_err = hc_clFinish (opencl_ctx->ocl, device_param->command_queue); + if (CL_err == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clFinish(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clFinish (hashcat_ctx, device_param->command_queue); - return -1; - } + if (CL_err == -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; const u32 num16d = num / 16; @@ -852,46 +1405,26 @@ 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) - { - event_log_error (hashcat_ctx, "ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 0, sizeof (cl_mem), (void *) &buf); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 1, sizeof (cl_uint), device_param->kernel_params_memset[1]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, kernel, 2, sizeof (cl_uint), device_param->kernel_params_memset[2]); - return -1; - } + if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueNDRangeKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - CL_err = hc_clFlush (opencl_ctx->ocl, device_param->command_queue); + CL_err = 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) - { - event_log_error (hashcat_ctx, "ERROR: clFlush(): %s\n", val2cstr_cl (CL_err)); + if (CL_err == -1) return -1; - return -1; - } + CL_err = hc_clFlush (hashcat_ctx, device_param->command_queue); - CL_err = hc_clFinish (opencl_ctx->ocl, device_param->command_queue); + if (CL_err == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clFinish(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clFinish (hashcat_ctx, device_param->command_queue); - return -1; - } + if (CL_err == -1) return -1; } if (num16m) @@ -903,14 +1436,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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, buf, CL_TRUE, num16d * 16, num16m, tmp, 0, NULL, NULL); - return -1; - } + if (CL_err == -1) return -1; } return 0; @@ -925,7 +1453,6 @@ 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; @@ -933,14 +1460,9 @@ int run_copy (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const 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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); + CL_err = 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); - return -1; - } + if (CL_err == -1) return -1; } else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI) { @@ -998,14 +1520,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_err = 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) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -1) return -1; } else if (user_options_extra->attack_kern == ATTACK_KERN_BF) { @@ -1025,7 +1542,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; @@ -1252,58 +1768,33 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co 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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueCopyBuffer(): %s\n", val2cstr_cl (CL_err)); + cl_int CL_err = 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); - return -1; - } + if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); + cl_int CL_err = 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); - return -1; - } + if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueCopyBuffer(): %s\n", val2cstr_cl (CL_err)); + cl_int CL_err = 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); - return -1; - } + if (CL_err == -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); + cl_int CL_err = 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) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueCopyBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueCopyBuffer(): %s\n", val2cstr_cl (CL_err)); + cl_int CL_err = 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); - return -1; - } + if (CL_err == -1) return -1; } if (user_options->benchmark == true) @@ -1397,24 +1888,29 @@ 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)); 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 *) mymalloc (sizeof (OCL_PTR)); + + opencl_ctx->ocl = ocl; + + ocl_init (hashcat_ctx); /** * OpenCL platform selection */ - u32 opencl_platforms_filter = setup_opencl_platforms_filter (hashcat_ctx, 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; @@ -1422,7 +1918,11 @@ int opencl_ctx_init (hashcat_ctx_t *hashcat_ctx) * OpenCL device selection */ - u32 devices_filter = setup_devices_filter (hashcat_ctx, 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; @@ -1430,7 +1930,11 @@ int opencl_ctx_init (hashcat_ctx_t *hashcat_ctx) * OpenCL device type selection */ - cl_device_type device_types_filter = setup_device_types_filter (hashcat_ctx, 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; @@ -1443,14 +1947,9 @@ int opencl_ctx_init (hashcat_ctx_t *hashcat_ctx) cl_uint platform_devices_cnt = 0; cl_device_id *platform_devices = (cl_device_id *) mycalloc (DEVICES_MAX, sizeof (cl_device_id)); - cl_int CL_err = hc_clGetPlatformIDs (opencl_ctx->ocl, CL_PLATFORMS_MAX, platforms, &platforms_cnt); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetPlatformIDs(): %s\n", val2cstr_cl (CL_err)); + cl_int CL_err = hc_clGetPlatformIDs (hashcat_ctx, CL_PLATFORMS_MAX, platforms, &platforms_cnt); - return -1; - } + if (CL_err == -1) return -1; if (platforms_cnt == 0) { @@ -1492,18 +1991,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); - - if (CL_err != CL_SUCCESS) - { - //event_log_error (hashcat_ctx, "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 + cl_int CL_err = hc_clGetDeviceIDs (hashcat_ctx, platform, CL_DEVICE_TYPE_ALL, DEVICES_MAX, platform_devices, &platform_devices_cnt); - continue; - } + if (CL_err != CL_SUCCESS) continue; for (u32 platform_devices_id = 0; platform_devices_id < platform_devices_cnt; platform_devices_id++) { @@ -1511,14 +2001,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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + cl_int CL_err = hc_clGetDeviceInfo (hashcat_ctx, device, CL_DEVICE_TYPE, sizeof (device_type), &device_type, NULL); - return -1; - } + if (CL_err == -1) return -1; device_types_all |= device_type; } @@ -1561,11 +2046,9 @@ void opencl_ctx_destroy (hashcat_ctx_t *hashcat_ctx) if (opencl_ctx->enabled == false) return; - myfree (opencl_ctx->devices_param); - - ocl_close (opencl_ctx->ocl); + ocl_close (hashcat_ctx); - myfree (opencl_ctx->ocl); + myfree (opencl_ctx->devices_param); myfree (opencl_ctx->platforms); @@ -1590,10 +2073,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; @@ -1612,14 +2095,9 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) char platform_vendor[HCBUFSIZ_TINY] = { 0 }; - CL_err = hc_clGetPlatformInfo (opencl_ctx->ocl, platform, CL_PLATFORM_VENDOR, sizeof (platform_vendor), platform_vendor, NULL); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetPlatformInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetPlatformInfo (hashcat_ctx, platform, CL_PLATFORM_VENDOR, sizeof (platform_vendor), platform_vendor, NULL); - return -1; - } + if (CL_err == -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 @@ -1666,11 +2144,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_err = hc_clGetDeviceIDs (hashcat_ctx, platform, CL_DEVICE_TYPE_ALL, DEVICES_MAX, platform_devices, &platform_devices_cnt); if (CL_err != CL_SUCCESS) { - //event_log_error (hashcat_ctx, "ERROR: clGetDeviceIDs(): %s\n", val2cstr_cl (CL_err)); + //event_log_error (hashcat_ctx, "ERROR: clGetDeviceIDs(): %s", val2cstr_cl (CL_err)); //return -1; @@ -1681,25 +2159,15 @@ 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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetPlatformInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetPlatformInfo (hashcat_ctx, platform, CL_PLATFORM_NAME, HCBUFSIZ_TINY, platform_name, NULL); - return -1; - } + if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetPlatformInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetPlatformInfo (hashcat_ctx, platform, CL_PLATFORM_VERSION, sizeof (platform_version), platform_version, NULL); - return -1; - } + if (CL_err == -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); } @@ -1758,14 +2226,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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_TYPE, sizeof (device_type), &device_type, NULL); - return -1; - } + if (CL_err == -1) return -1; device_type &= ~CL_DEVICE_TYPE_DEFAULT; @@ -1773,49 +2236,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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_NAME, 0, NULL, ¶m_value_size); - return -1; - } + if (CL_err == -1) return -1; char *device_name = (char *) mymalloc (param_value_size); - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_NAME, param_value_size, device_name, NULL); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_NAME, param_value_size, device_name, NULL); - return -1; - } + if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_VENDOR, 0, NULL, ¶m_value_size); - return -1; - } + if (CL_err == -1) return -1; char *device_vendor = (char *) mymalloc (param_value_size); - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_VENDOR, param_value_size, device_vendor, NULL); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_VENDOR, param_value_size, device_vendor, NULL); - return -1; - } + if (CL_err == -1) return -1; device_param->device_vendor = device_vendor; @@ -1862,49 +2305,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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_VERSION, 0, NULL, ¶m_value_size); - return -1; - } + if (CL_err == -1) return -1; char *device_version = (char *) mymalloc (param_value_size); - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_VERSION, param_value_size, device_version, NULL); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_VERSION, param_value_size, device_version, NULL); - return -1; - } + if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_OPENCL_C_VERSION, 0, NULL, ¶m_value_size); - return -1; - } + if (CL_err == -1) return -1; char *device_opencl_version = (char *) mymalloc (param_value_size); - 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) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_OPENCL_C_VERSION, param_value_size, device_opencl_version, NULL); - return -1; - } + if (CL_err == -1) return -1; device_param->opencl_v12 = device_opencl_version[9] > '1' || device_opencl_version[11] >= '2'; @@ -1912,14 +2335,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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof (device_processors), &device_processors, NULL); - return -1; - } + if (CL_err == -1) return -1; device_param->device_processors = device_processors; @@ -1928,14 +2346,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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof (device_maxmem_alloc), &device_maxmem_alloc, NULL); - return -1; - } + if (CL_err == -1) return -1; device_param->device_maxmem_alloc = MIN (device_maxmem_alloc, 0x7fffffff); @@ -1943,14 +2356,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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof (device_global_mem), &device_global_mem, NULL); - return -1; - } + if (CL_err == -1) return -1; device_param->device_global_mem = device_global_mem; @@ -1958,14 +2366,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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof (device_maxworkgroup_size), &device_maxworkgroup_size, NULL); - return -1; - } + if (CL_err == -1) return -1; device_param->device_maxworkgroup_size = device_maxworkgroup_size; @@ -1973,14 +2376,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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof (device_maxclock_frequency), &device_maxclock_frequency, NULL); - return -1; - } + if (CL_err == -1) return -1; device_param->device_maxclock_frequency = device_maxclock_frequency; @@ -1988,14 +2386,9 @@ 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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_ENDIAN_LITTLE, sizeof (device_endian_little), &device_endian_little, NULL); - return -1; - } + if (CL_err == -1) return -1; if (device_endian_little == CL_FALSE) { @@ -2008,14 +2401,9 @@ 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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_AVAILABLE, sizeof (device_available), &device_available, NULL); - return -1; - } + if (CL_err == -1) return -1; if (device_available == CL_FALSE) { @@ -2028,14 +2416,9 @@ 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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_COMPILER_AVAILABLE, sizeof (device_compiler_available), &device_compiler_available, NULL); - return -1; - } + if (CL_err == -1) return -1; if (device_compiler_available == CL_FALSE) { @@ -2048,14 +2431,9 @@ 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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_EXECUTION_CAPABILITIES, sizeof (device_execution_capabilities), &device_execution_capabilities, NULL); - return -1; - } + if (CL_err == -1) return -1; if ((device_execution_capabilities & CL_EXEC_KERNEL) == 0) { @@ -2068,25 +2446,15 @@ 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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_EXTENSIONS, 0, NULL, &device_extensions_size); - return -1; - } + if (CL_err == -1) return -1; char *device_extensions = mymalloc (device_extensions_size + 1); - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DEVICE_EXTENSIONS, device_extensions_size, device_extensions, NULL); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_EXTENSIONS, device_extensions_size, device_extensions, NULL); - return -1; - } + if (CL_err == -1) return -1; if (strstr (device_extensions, "base_atomics") == 0) { @@ -2108,14 +2476,9 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) 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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_LOCAL_MEM_SIZE, sizeof (device_local_mem_size), &device_local_mem_size, NULL); - return -1; - } + if (CL_err == -1) return -1; if (device_local_mem_size < 32768) { @@ -2151,25 +2514,15 @@ 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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DRIVER_VERSION, 0, NULL, ¶m_value_size); - return -1; - } + if (CL_err == -1) return -1; char *driver_version = (char *) mymalloc (param_value_size); - CL_err = hc_clGetDeviceInfo (opencl_ctx->ocl, device_param->device, CL_DRIVER_VERSION, param_value_size, driver_version, NULL); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DRIVER_VERSION, param_value_size, driver_version, NULL); - return -1; - } + if (CL_err == -1) return -1; device_param->driver_version = driver_version; @@ -2197,19 +2550,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 } } @@ -2222,14 +2575,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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, sizeof (kernel_exec_timeout), &kernel_exec_timeout, NULL); - return -1; - } + if (CL_err == -1) return -1; device_param->kernel_exec_timeout = kernel_exec_timeout; @@ -2239,23 +2587,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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, sizeof (sm_minor), &sm_minor, 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 == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, sizeof (sm_major), &sm_major, NULL); - return -1; - } + if (CL_err == -1) return -1; device_param->sm_minor = sm_minor; device_param->sm_major = sm_major; @@ -2431,7 +2769,7 @@ int opencl_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime) if (user_options->opencl_info == true) { - exit (0); + return 0; } if (devices_active == 0) @@ -2489,10 +2827,10 @@ void opencl_ctx_devices_destroy (hashcat_ctx_t *hashcat_ctx) 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) @@ -2640,25 +2978,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_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, sizeof (vector_width), &vector_width, NULL); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -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_err = hc_clGetDeviceInfo (hashcat_ctx, device_param->device, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, sizeof (vector_width), &vector_width, NULL); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetDeviceInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -1) return -1; } } else @@ -2746,30 +3074,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_err = hc_clCreateContext (hashcat_ctx, properties, 1, &device_param->device, NULL, NULL, &device_param->context); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateContext(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -1) return -1; /** * create command-queue */ // not supported with NV - // device_param->command_queue = hc_clCreateCommandQueueWithProperties (device_param->context, 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); + // device_param->command_queue = hc_clCreateCommandQueueWithProperties (hashcat_ctx, device_param->device, NULL); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateCommandQueue(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clCreateCommandQueue (hashcat_ctx, device_param->context, device_param->device, CL_QUEUE_PROFILING_ENABLE, &device_param->command_queue); - return -1; - } + if (CL_err == -1) return -1; /** * kernel threads: some algorithms need a fixed kernel-threads count @@ -2926,7 +3244,8 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) return -1; } - if (user_options->quiet == false) event_log_info (hashcat_ctx, "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; @@ -3129,7 +3448,7 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) strncpy (build_opts, build_opts_new, sizeof (build_opts)); #if defined (DEBUG) - event_log_info (hashcat_ctx, "- 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 /** @@ -3185,40 +3504,23 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) { if (user_options->quiet == false) event_log_info (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 (hashcat_ctx, 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 (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateProgramWithSource(): %s\n", val2cstr_cl (CL_err)); + if (rc_read_kernel == -1) return -1; - return -1; - } + CL_err = hc_clCreateProgramWithSource (hashcat_ctx, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program); - CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program, 1, &device_param->device, build_opts, NULL, NULL); + if (CL_err == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clBuildProgram(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clBuildProgram (hashcat_ctx, device_param->program, 1, &device_param->device, build_opts, NULL, NULL); - //return -1; - } + //if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetProgramBuildInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - */ + hc_clGetProgramBuildInfo (hashcat_ctx, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); - hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + //if (CL_err == -1) return -1; #if defined (DEBUG) if ((build_log_size != 0) || (CL_err != CL_SUCCESS)) @@ -3228,14 +3530,9 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) { char *build_log = (char *) mymalloc (build_log_size + 1); - CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetProgramBuildInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetProgramBuildInfo (hashcat_ctx, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); - return -1; - } + if (CL_err == -1) return -1; puts (build_log); @@ -3253,27 +3550,19 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) size_t binary_size; - CL_err = hc_clGetProgramInfo (opencl_ctx->ocl, device_param->program, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetProgramInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetProgramInfo (hashcat_ctx, device_param->program, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL); - return -1; - } + if (CL_err == -1) return -1; char *binary = (char *) mymalloc (binary_size); - CL_err = hc_clGetProgramInfo (opencl_ctx->ocl, device_param->program, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); + CL_err = hc_clGetProgramInfo (hashcat_ctx, device_param->program, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetProgramInfo(): %s\n", val2cstr_cl (CL_err)); + if (CL_err == -1) return -1; - return -1; - } + const int rc_write = write_kernel_binary (hashcat_ctx, cached_file, binary, binary_size); - write_kernel_binary (hashcat_ctx, cached_file, binary, binary_size); + if (rc_write == -1) return -1; myfree (binary); } @@ -3283,25 +3572,17 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) event_log_info (hashcat_ctx, "- Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size); #endif - 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); + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, cached_file, 1, kernel_lengths, kernel_sources); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateProgramWithBinary(): %s\n", val2cstr_cl (CL_err)); + if (rc_read_kernel == -1) return -1; - return -1; - } + CL_err = hc_clCreateProgramWithBinary (hashcat_ctx, device_param->context, 1, &device_param->device, kernel_lengths, (const unsigned char **) kernel_sources, NULL, &device_param->program); - CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program, 1, &device_param->device, build_opts, NULL, NULL); + if (CL_err == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clBuildProgram(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clBuildProgram (hashcat_ctx, device_param->program, 1, &device_param->device, build_opts, NULL, NULL); - return -1; - } + if (CL_err == -1) return -1; } } else @@ -3310,16 +3591,13 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) event_log_info (hashcat_ctx, "- Device #%u: Kernel %s (%ld bytes)", device_id + 1, source_file, sst.st_size); #endif - read_kernel_binary (hashcat_ctx, 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) - { - event_log_error (hashcat_ctx, "ERROR: clCreateProgramWithSource(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clCreateProgramWithSource (hashcat_ctx, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program); - return -1; - } + if (CL_err == -1) return -1; char build_opts_update[1024] = { 0 }; @@ -3336,29 +3614,15 @@ 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_err = hc_clBuildProgram (hashcat_ctx, device_param->program, 1, &device_param->device, build_opts_update, NULL, NULL); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clBuildProgram(): %s\n", val2cstr_cl (CL_err)); - - //return -1; - } + //if (CL_err == -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) - { - event_log_error (hashcat_ctx, "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_err == -1) return -1; #if defined (DEBUG) if ((build_log_size != 0) || (CL_err != CL_SUCCESS)) @@ -3368,14 +3632,9 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) { char *build_log = (char *) mymalloc (build_log_size + 1); - CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetProgramBuildInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetProgramBuildInfo (hashcat_ctx, device_param->program, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); - return -1; - } + if (CL_err == -1) return -1; puts (build_log); @@ -3448,40 +3707,23 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (user_options->quiet == false) event_log_info (hashcat_ctx, "- 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 (hashcat_ctx, ""); - 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); + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, 1, kernel_lengths, kernel_sources); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateProgramWithSource(): %s\n", val2cstr_cl (CL_err)); + if (rc_read_kernel == -1) return -1; - return -1; - } + CL_err = hc_clCreateProgramWithSource (hashcat_ctx, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program_mp); - CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program_mp, 1, &device_param->device, build_opts, NULL, NULL); + if (CL_err == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clBuildProgram(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clBuildProgram (hashcat_ctx, device_param->program_mp, 1, &device_param->device, build_opts, NULL, NULL); - //return -1; - } + //if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetProgramBuildInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - */ + hc_clGetProgramBuildInfo (hashcat_ctx, device_param->program_mp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); - hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_mp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + //if (CL_err == -1) return -1; #if defined (DEBUG) if ((build_log_size != 0) || (CL_err != CL_SUCCESS)) @@ -3491,14 +3733,9 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) { char *build_log = (char *) mymalloc (build_log_size + 1); - CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_mp, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetProgramBuildInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetProgramBuildInfo (hashcat_ctx, device_param->program_mp, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); - return -1; - } + if (CL_err == -1) return -1; puts (build_log); @@ -3516,25 +3753,15 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) 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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetProgramInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetProgramInfo (hashcat_ctx, device_param->program_mp, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL); - return -1; - } + if (CL_err == -1) return -1; char *binary = (char *) mymalloc (binary_size); - CL_err = hc_clGetProgramInfo (opencl_ctx->ocl, device_param->program_mp, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetProgramInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetProgramInfo (hashcat_ctx, device_param->program_mp, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); - return -1; - } + if (CL_err == -1) return -1; write_kernel_binary (hashcat_ctx, cached_file, binary, binary_size); @@ -3546,25 +3773,17 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) event_log_info (hashcat_ctx, "- Device #%u: Kernel %s (%ld bytes)", device_id + 1, cached_file, cst.st_size); #endif - read_kernel_binary (hashcat_ctx, 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) - { - event_log_error (hashcat_ctx, "ERROR: clCreateProgramWithBinary(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_err = hc_clCreateProgramWithBinary (hashcat_ctx, device_param->context, 1, &device_param->device, kernel_lengths, (const unsigned char **) kernel_sources, NULL, &device_param->program_mp); - CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program_mp, 1, &device_param->device, build_opts, NULL, NULL); + if (CL_err == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clBuildProgram(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clBuildProgram (hashcat_ctx, device_param->program_mp, 1, &device_param->device, build_opts, NULL, NULL); - return -1; - } + if (CL_err == -1) return -1; } myfree (kernel_lengths); @@ -3629,40 +3848,23 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) if (user_options->quiet == false) event_log_info (hashcat_ctx, "- 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 (hashcat_ctx, ""); - 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 (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateProgramWithSource(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + const int rc_read_kernel = read_kernel_binary (hashcat_ctx, source_file, 1, kernel_lengths, kernel_sources); - CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program_amp, 1, &device_param->device, build_opts, NULL, NULL); + if (rc_read_kernel == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clBuildProgram(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clCreateProgramWithSource (hashcat_ctx, device_param->context, 1, (const char **) kernel_sources, NULL, &device_param->program_amp); - //return -1; - } + if (CL_err == -1) return -1; - size_t build_log_size = 0; + CL_err = hc_clBuildProgram (hashcat_ctx, device_param->program_amp, 1, &device_param->device, build_opts, NULL, NULL); - /* - CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_amp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + //if (CL_err == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetProgramBuildInfo(): %s\n", val2cstr_cl (CL_err)); + size_t build_log_size = 0; - return -1; - } - */ + hc_clGetProgramBuildInfo (hashcat_ctx, device_param->program_amp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); - hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_amp, device_param->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &build_log_size); + //if (CL_err == -1) return -1; #if defined (DEBUG) if ((build_log_size != 0) || (CL_err != CL_SUCCESS)) @@ -3672,14 +3874,9 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) { char *build_log = (char *) mymalloc (build_log_size + 1); - CL_err = hc_clGetProgramBuildInfo (opencl_ctx->ocl, device_param->program_amp, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetProgramBuildInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetProgramBuildInfo (hashcat_ctx, device_param->program_amp, device_param->device, CL_PROGRAM_BUILD_LOG, build_log_size, build_log, NULL); - return -1; - } + if (CL_err == -1) return -1; puts (build_log); @@ -3697,25 +3894,15 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) 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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetProgramInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetProgramInfo (hashcat_ctx, device_param->program_amp, CL_PROGRAM_BINARY_SIZES, sizeof (size_t), &binary_size, NULL); - return -1; - } + if (CL_err == -1) return -1; char *binary = (char *) mymalloc (binary_size); - CL_err = hc_clGetProgramInfo (opencl_ctx->ocl, device_param->program_amp, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetProgramInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clGetProgramInfo (hashcat_ctx, device_param->program_amp, CL_PROGRAM_BINARIES, sizeof (binary), &binary, NULL); - return -1; - } + if (CL_err == -1) return -1; write_kernel_binary (hashcat_ctx, cached_file, binary, binary_size); @@ -3727,25 +3914,17 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) 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 (hashcat_ctx, 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) - { - event_log_error (hashcat_ctx, "ERROR: clCreateProgramWithBinary(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_err = hc_clCreateProgramWithBinary (hashcat_ctx, device_param->context, 1, &device_param->device, kernel_lengths, (const unsigned char **) kernel_sources, NULL, &device_param->program_amp); - CL_err = hc_clBuildProgram (opencl_ctx->ocl, device_param->program_amp, 1, &device_param->device, build_opts, NULL, NULL); + if (CL_err == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clBuildProgram(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clBuildProgram (hashcat_ctx, device_param->program_amp, 1, &device_param->device, build_opts, NULL, NULL); - return -1; - } + if (CL_err == -1) return -1; } myfree (kernel_lengths); @@ -3776,53 +3955,43 @@ 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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "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) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_pws, NULL, &device_param->d_pws_buf); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_pws, NULL, &device_param->d_pws_amp_buf); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_tmps, NULL, &device_param->d_tmps); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_hooks, NULL, &device_param->d_hooks); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s1_a); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s1_b); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s1_c); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s1_d); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s2_a); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s2_b); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s2_c); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, bitmap_ctx->bitmap_size, NULL, &device_param->d_bitmap_s2_d); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_plains, NULL, &device_param->d_plain_bufs); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_digests, NULL, &device_param->d_digests_buf); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_shown, NULL, &device_param->d_digests_shown); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_salts, NULL, &device_param->d_salt_bufs); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_results, NULL, &device_param->d_result); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV0_buf); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV1_buf); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV2_buf); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_WRITE, size_scrypt4, NULL, &device_param->d_scryptV3_buf); + + if (CL_err == -1) return -1; + + CL_err |= 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); + CL_err |= 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); + CL_err |= 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); + CL_err |= 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); + CL_err |= 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); + CL_err |= 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); + CL_err |= 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); + CL_err |= 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); + CL_err |= hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_digests_buf, CL_TRUE, 0, size_digests, hashes->digests_buf, 0, NULL, NULL); + CL_err |= hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_digests_shown, CL_TRUE, 0, size_shown, hashes->digests_shown, 0, NULL, NULL); + CL_err |= 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_err == -1) return -1; /** * special buffers @@ -3830,74 +3999,44 @@ 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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateBuffer(): %s\n", val2cstr_cl (CL_err)); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_rules, NULL, &device_param->d_rules); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_rules_c, NULL, &device_param->d_rules_c); - return -1; - } + if (CL_err == -1) 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) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); + CL_err = 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); - return -1; - } + if (CL_err == -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) - { - event_log_error (hashcat_ctx, "ERROR: clCreateBuffer(): %s\n", val2cstr_cl (CL_err)); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_combs, NULL, &device_param->d_combs); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_combs, NULL, &device_param->d_combs_c); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_root_css, NULL, &device_param->d_root_css_buf); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_markov_css, NULL, &device_param->d_markov_css_buf); - return -1; - } + if (CL_err == -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) - { - event_log_error (hashcat_ctx, "ERROR: clCreateBuffer(): %s\n", val2cstr_cl (CL_err)); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_bfs, NULL, &device_param->d_bfs); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_bfs, NULL, &device_param->d_bfs_c); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_tm, NULL, &device_param->d_tm_c); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_root_css, NULL, &device_param->d_root_css_buf); + CL_err |= hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_markov_css, NULL, &device_param->d_markov_css_buf); - return -1; - } + if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateBuffer(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clCreateBuffer (hashcat_ctx, device_param->context, CL_MEM_READ_ONLY, size_esalts, NULL, &device_param->d_esalt_bufs); - return -1; - } + if (CL_err == -1) return -1; - 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) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clEnqueueWriteBuffer (hashcat_ctx, device_param->command_queue, device_param->d_esalt_bufs, CL_TRUE, 0, size_esalts, hashes->esalts_buf, 0, NULL, NULL); - return -1; - } + if (CL_err == -1) return -1; } /** @@ -4058,71 +4197,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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel1); - return -1; - } + if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel2); - return -1; - } + if (CL_err == -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_err = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel3); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel1); - return -1; - } + if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel2); - return -1; - } + if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel3); - return -1; - } + if (CL_err == -1) return -1; } if (user_options->attack_mode == ATTACK_MODE_BF) @@ -4131,23 +4240,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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_err = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel_tm); - 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 == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = 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); - return -1; - } + if (CL_err == -1) return -1; } } } @@ -4155,236 +4254,136 @@ 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_err = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel1); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -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_err = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel2); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -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_err = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel3); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -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_err = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel12); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - 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 == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = 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); - return -1; - } + if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_err = hc_clCreateKernel (hashcat_ctx, device_param->program, kernel_name, &device_param->kernel23); - 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 == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = 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); - return -1; - } + if (CL_err == -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); + CL_err |= 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); + CL_err |= 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); + CL_err |= 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_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -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]); - - 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]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel1, i, sizeof (cl_mem), device_param->kernel_params[i]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel2, i, sizeof (cl_mem), device_param->kernel_params[i]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel3, i, sizeof (cl_mem), device_param->kernel_params[i]); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); + if (hashconfig->opts_type & OPTS_TYPE_HOOK12) CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel12, i, sizeof (cl_mem), device_param->kernel_params[i]); + if (hashconfig->opts_type & OPTS_TYPE_HOOK23) CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel23, i, sizeof (cl_mem), device_param->kernel_params[i]); - return -1; - } + if (CL_err == -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]); - - 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]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel1, i, sizeof (cl_uint), device_param->kernel_params[i]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel2, i, sizeof (cl_uint), device_param->kernel_params[i]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel3, i, sizeof (cl_uint), device_param->kernel_params[i]); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); + if (hashconfig->opts_type & OPTS_TYPE_HOOK12) CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel12, i, sizeof (cl_uint), device_param->kernel_params[i]); + if (hashconfig->opts_type & OPTS_TYPE_HOOK23) CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel23, i, sizeof (cl_uint), device_param->kernel_params[i]); - return -1; - } + if (CL_err == -1) return -1; } // GPU memset - CL_err = hc_clCreateKernel (opencl_ctx->ocl, device_param->program, "gpu_memset", &device_param->kernel_memset); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } - - 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); + CL_err = hc_clCreateKernel (hashcat_ctx, device_param->program, "gpu_memset", &device_param->kernel_memset); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); + if (CL_err == -1) return -1; - return -1; - } + CL_err = 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_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 == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); + CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel_memset, 0, sizeof (cl_mem), device_param->kernel_params_memset[0]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel_memset, 1, sizeof (cl_uint), device_param->kernel_params_memset[1]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel_memset, 2, sizeof (cl_uint), device_param->kernel_params_memset[2]); - return -1; - } + if (CL_err == -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_err |= hc_clCreateKernel (hashcat_ctx, device_param->program_mp, "l_markov", &device_param->kernel_mp_l); + CL_err |= hc_clCreateKernel (hashcat_ctx, device_param->program_mp, "r_markov", &device_param->kernel_mp_r); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -1) 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); + CL_err |= 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); + CL_err |= 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_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -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]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel_tm, 0, sizeof (cl_mem), device_param->kernel_params_tm[0]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel_tm, 1, sizeof (cl_mem), device_param->kernel_params_tm[1]); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_err = hc_clCreateKernel (hashcat_ctx, device_param->program_mp, "C_markov", &device_param->kernel_mp); - 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 == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = 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); - return -1; - } + if (CL_err == -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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_err = hc_clCreateKernel (hashcat_ctx, device_param->program_mp, "C_markov", &device_param->kernel_mp); - 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 == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = 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); - return -1; - } + if (CL_err == -1) return -1; } if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL) @@ -4393,23 +4392,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); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clCreateKernel(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + CL_err = hc_clCreateKernel (hashcat_ctx, device_param->program_amp, "amp", &device_param->kernel_amp); - 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 == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clGetKernelWorkGroupInfo(): %s\n", val2cstr_cl (CL_err)); + CL_err = 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); - return -1; - } + if (CL_err == -1) return -1; } if (hashconfig->attack_exec == ATTACK_EXEC_INSIDE_KERNEL) @@ -4420,26 +4409,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]); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_amp, i, sizeof (cl_mem), device_param->kernel_params_amp[i]); - return -1; - } + if (CL_err == -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]); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); + CL_err = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_amp, i, sizeof (cl_uint), device_param->kernel_params_amp[i]); - return -1; - } + if (CL_err == -1) return -1; } } @@ -4505,14 +4484,9 @@ 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) - { - event_log_error (hashcat_ctx, "ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); + for (u32 i = 0; i < 3; i++) CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel_mp, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp[i]); - return -1; - } + if (CL_err == -1) return -1; } else if (user_options->attack_mode == ATTACK_MODE_BF) { @@ -4529,15 +4503,10 @@ 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) - { - event_log_error (hashcat_ctx, "ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); + for (u32 i = 0; i < 3; i++) CL_err |= hc_clSetKernelArg (hashcat_ctx, 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 (hashcat_ctx, device_param->kernel_mp_r, i, sizeof (cl_mem), (void *) device_param->kernel_params_mp_r[i]); - return -1; - } + if (CL_err == -1) return -1; } } @@ -4564,62 +4533,59 @@ void opencl_session_destroy (hashcat_ctx_t *hashcat_ctx) myfree (device_param->combs_buf); myfree (device_param->hooks_buf); - 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) 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) 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) 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) - { - event_log_error (hashcat_ctx, "ERROR: hc_clReleaseContext(): %s\n", val2cstr_cl (CL_err)); - } + if (device_param->d_pws_buf) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_pws_buf); + if (device_param->d_pws_amp_buf) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_pws_amp_buf); + if (device_param->d_rules) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_rules); + if (device_param->d_rules_c) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_rules_c); + if (device_param->d_combs) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_combs); + if (device_param->d_combs_c) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_combs_c); + if (device_param->d_bfs) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_bfs); + if (device_param->d_bfs_c) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_bfs_c); + if (device_param->d_bitmap_s1_a) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_bitmap_s1_a); + if (device_param->d_bitmap_s1_b) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_bitmap_s1_b); + if (device_param->d_bitmap_s1_c) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_bitmap_s1_c); + if (device_param->d_bitmap_s1_d) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_bitmap_s1_d); + if (device_param->d_bitmap_s2_a) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_bitmap_s2_a); + if (device_param->d_bitmap_s2_b) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_bitmap_s2_b); + if (device_param->d_bitmap_s2_c) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_bitmap_s2_c); + if (device_param->d_bitmap_s2_d) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_bitmap_s2_d); + if (device_param->d_plain_bufs) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_plain_bufs); + if (device_param->d_digests_buf) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_digests_buf); + if (device_param->d_digests_shown) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_digests_shown); + if (device_param->d_salt_bufs) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_salt_bufs); + if (device_param->d_esalt_bufs) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_esalt_bufs); + if (device_param->d_tmps) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_tmps); + if (device_param->d_hooks) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_hooks); + if (device_param->d_result) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_result); + if (device_param->d_scryptV0_buf) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_scryptV0_buf); + if (device_param->d_scryptV1_buf) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_scryptV1_buf); + if (device_param->d_scryptV2_buf) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_scryptV2_buf); + if (device_param->d_scryptV3_buf) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_scryptV3_buf); + if (device_param->d_root_css_buf) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_root_css_buf); + if (device_param->d_markov_css_buf) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_markov_css_buf); + if (device_param->d_tm_c) CL_err |= hc_clReleaseMemObject (hashcat_ctx, device_param->d_tm_c); + + if (device_param->kernel1) CL_err |= hc_clReleaseKernel (hashcat_ctx, device_param->kernel1); + if (device_param->kernel12) CL_err |= hc_clReleaseKernel (hashcat_ctx, device_param->kernel12); + if (device_param->kernel2) CL_err |= hc_clReleaseKernel (hashcat_ctx, device_param->kernel2); + if (device_param->kernel23) CL_err |= hc_clReleaseKernel (hashcat_ctx, device_param->kernel23); + if (device_param->kernel3) CL_err |= hc_clReleaseKernel (hashcat_ctx, device_param->kernel3); + if (device_param->kernel_mp) CL_err |= hc_clReleaseKernel (hashcat_ctx, device_param->kernel_mp); + if (device_param->kernel_mp_l) CL_err |= hc_clReleaseKernel (hashcat_ctx, device_param->kernel_mp_l); + if (device_param->kernel_mp_r) CL_err |= hc_clReleaseKernel (hashcat_ctx, device_param->kernel_mp_r); + if (device_param->kernel_tm) CL_err |= hc_clReleaseKernel (hashcat_ctx, device_param->kernel_tm); + if (device_param->kernel_amp) CL_err |= hc_clReleaseKernel (hashcat_ctx, device_param->kernel_amp); + if (device_param->kernel_memset) CL_err |= hc_clReleaseKernel (hashcat_ctx, device_param->kernel_memset); + + if (device_param->program) CL_err |= hc_clReleaseProgram (hashcat_ctx, device_param->program); + if (device_param->program_mp) CL_err |= hc_clReleaseProgram (hashcat_ctx, device_param->program_mp); + if (device_param->program_amp) CL_err |= hc_clReleaseProgram (hashcat_ctx, device_param->program_amp); + + if (device_param->command_queue) CL_err |= hc_clReleaseCommandQueue (hashcat_ctx, device_param->command_queue); + + if (device_param->context) CL_err |= hc_clReleaseContext (hashcat_ctx, device_param->context); + + //if (CL_err == -1) return -1; device_param->pws_buf = NULL; device_param->combs_buf = NULL; @@ -4735,19 +4701,14 @@ int opencl_session_update_combinator (hashcat_ctx_t *hashcat_ctx) cl_int CL_err = CL_SUCCESS; - 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]); - - 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]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel1, 33, sizeof (cl_uint), device_param->kernel_params[33]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel2, 33, sizeof (cl_uint), device_param->kernel_params[33]); + CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel3, 33, sizeof (cl_uint), device_param->kernel_params[33]); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); + if (hashconfig->opts_type & OPTS_TYPE_HOOK12) CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel12, 33, sizeof (cl_uint), device_param->kernel_params[33]); + if (hashconfig->opts_type & OPTS_TYPE_HOOK23) CL_err |= hc_clSetKernelArg (hashcat_ctx, device_param->kernel23, 33, sizeof (cl_uint), device_param->kernel_params[33]); - return -1; - } + if (CL_err == -1) return -1; // kernel_params_amp @@ -4755,14 +4716,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_err = hc_clSetKernelArg (hashcat_ctx, device_param->kernel_amp, 5, sizeof (cl_uint), device_param->kernel_params_amp[5]); - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + if (CL_err == -1) return -1; } } @@ -4787,25 +4743,15 @@ int opencl_session_update_mp (hashcat_ctx_t *hashcat_ctx) cl_int CL_err = 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]); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); - - return -1; - } + for (u32 i = 3; i < 4; i++) CL_err |= hc_clSetKernelArg (hashcat_ctx, 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 (hashcat_ctx, device_param->kernel_mp, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp[i]); - 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 == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); + CL_err |= 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); + CL_err |= 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); - return -1; - } + if (CL_err == -1) return -1; } return 0; @@ -4833,28 +4779,18 @@ int opencl_session_update_mp_rl (hashcat_ctx_t *hashcat_ctx, const u32 css_cnt_l cl_int CL_err = 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_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]); - - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clSetKernelArg(): %s\n", val2cstr_cl (CL_err)); + for (u32 i = 3; i < 4; i++) CL_err |= hc_clSetKernelArg (hashcat_ctx, 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 (hashcat_ctx, device_param->kernel_mp_l, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp_l[i]); - return -1; - } + for (u32 i = 3; i < 4; i++) CL_err |= hc_clSetKernelArg (hashcat_ctx, 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 (hashcat_ctx, device_param->kernel_mp_r, i, sizeof (cl_uint), (void *) device_param->kernel_params_mp_r[i]); - 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 == -1) return -1; - if (CL_err != CL_SUCCESS) - { - event_log_error (hashcat_ctx, "ERROR: clEnqueueWriteBuffer(): %s\n", val2cstr_cl (CL_err)); + CL_err |= 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); + CL_err |= 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); - return -1; - } + if (CL_err == -1) return -1; } return 0; diff --git a/src/outfile.c b/src/outfile.c index 02df40c99..7067d697c 100644 --- a/src/outfile.c +++ b/src/outfile.c @@ -6,7 +6,7 @@ #include "common.h" #include "types.h" #include "memory.h" -#include "logging.h" +#include "event.h" #include "interface.h" #include "hashes.h" #include "mpsp.h" @@ -342,7 +342,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, "ERROR: %s: %s", outfile_ctx->filename, strerror (errno)); return -1; } @@ -492,7 +492,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, "ERROR: 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..0032666b8 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" @@ -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); } } } @@ -356,7 +356,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, "ERROR: Directory specified in outfile-check '%s' is not a valid directory", outcheck_ctx->root_directory); return -1; } @@ -365,7 +365,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, "ERROR: %s: %s", outcheck_ctx->root_directory, strerror (errno)); return -1; } @@ -394,7 +394,7 @@ 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, "ERROR: %s: %s", outcheck_ctx->root_directory, strerror (errno)); //return -1; } diff --git a/src/potfile.c b/src/potfile.c index d6940947e..1e6597c70 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" @@ -351,7 +351,7 @@ void potfile_read_parse (hashcat_ctx_t *hashcat_ctx) if (parser_status < PARSER_GLOBAL_ZERO) { - // log_info ("WARNING: Potfile '%s' in line %u (%s): %s", potfile, line_num, line_buf, strparser (parser_status)); + // event_log_warning (hashcat_ctx, "Potfile '%s' in line %u (%s): %s", potfile, line_num, line_buf, strparser (parser_status)); continue; } @@ -391,7 +391,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, "ERROR: %s: %s", potfile_ctx->filename, strerror (errno)); return -1; } @@ -503,7 +503,7 @@ void potfile_show_request (hashcat_ctx_t *hashcat_ctx, char *input_buf, int inpu if (pot_ptr) { - log_info_nn (""); + event_log_info_nn (hashcat_ctx, ""); input_buf[input_len] = 0; @@ -544,7 +544,7 @@ void potfile_left_request (hashcat_ctx_t *hashcat_ctx, char *input_buf, int inpu if (pot_ptr == NULL) { - log_info_nn (""); + event_log_info_nn (hashcat_ctx, ""); input_buf[input_len] = 0; @@ -605,7 +605,7 @@ void potfile_show_request_lm (hashcat_ctx_t *hashcat_ctx, char *input_buf, int i // at least one half was found: - log_info_nn (""); + event_log_info_nn (hashcat_ctx, ""); input_buf[input_len] = 0; @@ -725,7 +725,7 @@ void potfile_left_request_lm (hashcat_ctx_t *hashcat_ctx, char *input_buf, int i // ... at least one part was not cracked - log_info_nn (""); + event_log_info_nn (hashcat_ctx, ""); input_buf[input_len] = 0; diff --git a/src/restore.c b/src/restore.c index b6be2495c..762cb26d5 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" @@ -52,7 +52,7 @@ u64 get_lowest_words_done (hashcat_ctx_t *hashcat_ctx) 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,7 +60,7 @@ 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)); @@ -68,9 +68,9 @@ static void check_running_process (hashcat_ctx_t *hashcat_ctx) if (nread != 1) { - log_error ("ERROR: Cannot read %s", eff_restore_file); + event_log_error (hashcat_ctx, "ERROR: Cannot read %s", eff_restore_file); - exit (-1); + return -1; } fclose (fp); @@ -104,9 +104,9 @@ 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, "ERROR: Already an instance %s running on pid %d", pidbin, rd->pid); - exit (-1); + return -1; } } @@ -127,9 +127,9 @@ 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, "ERROR: Already an instance %s running on pid %d", pidbin2, rd->pid); - exit (-1); + return -1; } } @@ -142,15 +142,17 @@ static void check_running_process (hashcat_ctx_t *hashcat_ctx) if (rd->version < RESTORE_VERSION_MIN) { - log_error ("ERROR: Cannot use outdated %s. Please remove it.", eff_restore_file); + event_log_error (hashcat_ctx, "ERROR: Cannot use outdated %s. Please remove it.", eff_restore_file); - exit (-1); + return -1; } myfree (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; @@ -158,7 +160,9 @@ void init_restore (hashcat_ctx_t *hashcat_ctx) 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 +177,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, "ERROR: 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,18 +197,18 @@ 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, "ERROR: 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, "ERROR: Can't read %s", eff_restore_file); - exit (-1); + return -1; } rd->argv = (char **) mycalloc (rd->argc, sizeof (char *)); @@ -213,9 +219,9 @@ void read_restore (hashcat_ctx_t *hashcat_ctx) { if (fgets (buf, HCBUFSIZ_LARGE - 1, fp) == NULL) { - log_error ("ERROR: Can't read %s", eff_restore_file); + event_log_error (hashcat_ctx, "ERROR: Can't read %s", eff_restore_file); - exit (-1); + return -1; } size_t len = strlen (buf); @@ -229,24 +235,26 @@ void read_restore (hashcat_ctx_t *hashcat_ctx) 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 the path found within the .restore file: '%s'", rd->cwd); if (chdir (rd->cwd)) { - log_error ("ERROR: The directory '%s' does not exist. It is needed to restore (--restore) the session.\n" + event_log_error (hashcat_ctx, "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); - 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; - if (restore_ctx->enabled == false) return; + if (restore_ctx->enabled == false) return 0; const u64 words_cur = get_lowest_words_done (hashcat_ctx); @@ -260,16 +268,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, "ERROR: %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, "ERROR: setvbuf file '%s': %s", new_restore_file, strerror (errno)); - exit (-1); + return -1; } fwrite (rd, sizeof (restore_data_t), 1, fp); @@ -286,18 +294,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 +317,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) @@ -342,7 +356,7 @@ void stop_at_checkpoint (hashcat_ctx_t *hashcat_ctx) if (restore_ctx->enabled == false) { - log_info ("WARNING: This feature is disabled when --restore-disable is specified"); + event_log_warning (hashcat_ctx, "This feature is disabled when --restore-disable is specified"); return; } @@ -357,7 +371,7 @@ void stop_at_checkpoint (hashcat_ctx_t *hashcat_ctx) status_ctx->run_thread_level1 = false; status_ctx->run_thread_level2 = true; - log_info ("Checkpoint enabled: Will quit at next Restore Point update"); + event_log_info (hashcat_ctx, "Checkpoint enabled: Will quit at next Restore Point update"); } else { @@ -367,7 +381,7 @@ void stop_at_checkpoint (hashcat_ctx_t *hashcat_ctx) status_ctx->run_thread_level1 = true; status_ctx->run_thread_level2 = true; - log_info ("Checkpoint disabled: Restore Point updates will no longer be monitored"); + event_log_info (hashcat_ctx, "Checkpoint disabled: Restore Point updates will no longer be monitored"); } } @@ -391,7 +405,9 @@ 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 (rc_init_restore == -1) return -1; if (argc == 0) return 0; if (argv == NULL) return 0; @@ -410,13 +426,15 @@ int restore_ctx_init (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) 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, "ERROR: Incompatible restore-file version"); return -1; } diff --git a/src/rp.c b/src/rp.c index 82c4224ae..919e33f41 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" @@ -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, "ERROR: %s: %s", rp_file, strerror (errno)); return -1; } @@ -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 @@ -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; } @@ -860,7 +860,7 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 if (kernel_rules_cnt == 0) { - log_error ("ERROR: No valid rules left"); + event_log_error (hashcat_ctx, "ERROR: No valid rules left"); return -1; } diff --git a/src/status.c b/src/status.c index aed13408d..448f47971 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" @@ -159,14 +159,14 @@ void status_display_machine_readable (hashcat_ctx_t *hashcat_ctx) if (status_ctx->devices_status == STATUS_INIT) { - log_error ("ERROR: status view is not available during initialization phase"); + event_log_error (hashcat_ctx, "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"); + event_log_error (hashcat_ctx, "ERROR: status view is not available during autotune phase"); return; } @@ -326,14 +326,14 @@ void status_display (hashcat_ctx_t *hashcat_ctx) if (status_ctx->devices_status == STATUS_INIT) { - log_error ("ERROR: status view is not available during initialization phase"); + event_log_error (hashcat_ctx, "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"); + event_log_error (hashcat_ctx, "ERROR: status view is not available during autotune phase"); return; } @@ -352,7 +352,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx) u32 tmp_len = 0; - log_info ("Session.Name...: %s", user_options->session); + event_log_info (hashcat_ctx, "Session.Name...: %s", user_options->session); char *status_type = strstatus (status_ctx->devices_status); @@ -360,7 +360,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx) char *hash_type = strhashtype (hash_mode); // not a bug - log_info ("Status.........: %s", status_type); + event_log_info (hashcat_ctx, "Status.........: %s", status_type); /** * show rules @@ -377,18 +377,18 @@ void status_display (hashcat_ctx_t *hashcat_ctx) snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, "File (%s)", user_options->rp_files[i]); - log_info ("Rules.Type.....: %s", tmp_buf); + event_log_info (hashcat_ctx, "Rules.Type.....: %s", tmp_buf); tmp_len = 0; } if (user_options->rp_gen) { - log_info ("Rules.Type.....: Generated (%u)", user_options->rp_gen); + event_log_info (hashcat_ctx, "Rules.Type.....: Generated (%u)", user_options->rp_gen); if (user_options->rp_gen_seed) { - log_info ("Rules.Seed.....: %u", user_options->rp_gen_seed); + event_log_info (hashcat_ctx, "Rules.Seed.....: %u", user_options->rp_gen_seed); } } @@ -405,17 +405,17 @@ void status_display (hashcat_ctx_t *hashcat_ctx) { if (user_options_extra->wordlist_mode == WL_MODE_FILE) { - log_info ("Input.Mode.....: File (%s)", straight_ctx->dict); + event_log_info (hashcat_ctx, "Input.Mode.....: File (%s)", straight_ctx->dict); } else if (user_options_extra->wordlist_mode == WL_MODE_STDIN) { - log_info ("Input.Mode.....: Pipe"); + event_log_info (hashcat_ctx, "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); + event_log_info (hashcat_ctx, "Input.Left.....: File (%s)", combinator_ctx->dict1); + event_log_info (hashcat_ctx, "Input.Right....: File (%s)", combinator_ctx->dict2); } else if (user_options->attack_mode == ATTACK_MODE_BF) { @@ -451,7 +451,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx) tmp_len += snprintf (tmp_buf + tmp_len, sizeof (tmp_buf) - tmp_len, " (%.02f%%)", mask_percentage * 100); } - log_info ("Input.Mode.....: %s", tmp_buf); + event_log_info (hashcat_ctx, "Input.Mode.....: %s", tmp_buf); if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL)) { @@ -460,7 +460,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx) 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); + event_log_info (hashcat_ctx, "Custom.Charset.: -1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4); } } @@ -468,8 +468,8 @@ void status_display (hashcat_ctx_t *hashcat_ctx) } 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); + event_log_info (hashcat_ctx, "Input.Left.....: File (%s)", straight_ctx->dict); + event_log_info (hashcat_ctx, "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)) { @@ -478,13 +478,13 @@ void status_display (hashcat_ctx_t *hashcat_ctx) 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); + event_log_info (hashcat_ctx, "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); + event_log_info (hashcat_ctx, "Input.Left.....: Mask (%s) [%i]", mask_ctx->mask, mask_ctx->css_cnt); + event_log_info (hashcat_ctx, "Input.Right....: File (%s)", straight_ctx->dict); if ((custom_charset_1 != NULL) || (custom_charset_2 != NULL) || (custom_charset_3 != NULL) || (custom_charset_4 != NULL)) { @@ -493,7 +493,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx) 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); + event_log_info (hashcat_ctx, "Custom.Charset.: -1 %s, -2 %s, -3 %s, -4 %s", custom_charset_1, custom_charset_2, custom_charset_3, custom_charset_4); } } @@ -503,7 +503,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx) { 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)", + event_log_info (hashcat_ctx, "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], @@ -520,19 +520,19 @@ void status_display (hashcat_ctx_t *hashcat_ctx) } else if (hashconfig->hash_mode == 5200) { - log_info ("Hash.Target....: File (%s)", hashes->hashfile); + event_log_info (hashcat_ctx, "Hash.Target....: File (%s)", hashes->hashfile); } else if (hashconfig->hash_mode == 9000) { - log_info ("Hash.Target....: File (%s)", hashes->hashfile); + event_log_info (hashcat_ctx, "Hash.Target....: File (%s)", hashes->hashfile); } else if ((hashconfig->hash_mode >= 6200) && (hashconfig->hash_mode <= 6299)) { - log_info ("Hash.Target....: File (%s)", hashes->hashfile); + event_log_info (hashcat_ctx, "Hash.Target....: File (%s)", hashes->hashfile); } else if ((hashconfig->hash_mode >= 13700) && (hashconfig->hash_mode <= 13799)) { - log_info ("Hash.Target....: File (%s)", hashes->hashfile); + event_log_info (hashcat_ctx, "Hash.Target....: File (%s)", hashes->hashfile); } else { @@ -549,7 +549,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx) out_buf[44] = 0; } - log_info ("Hash.Target....: %s", out_buf); + event_log_info (hashcat_ctx, "Hash.Target....: %s", out_buf); } } else @@ -562,15 +562,15 @@ void status_display (hashcat_ctx_t *hashcat_ctx) ascii_digest (out_buf1, 0, 0, hashconfig, hashes); ascii_digest (out_buf2, 0, 1, hashconfig, hashes); - log_info ("Hash.Target....: %s, %s", out_buf1, out_buf2); + event_log_info (hashcat_ctx, "Hash.Target....: %s, %s", out_buf1, out_buf2); } else { - log_info ("Hash.Target....: File (%s)", hashes->hashfile); + event_log_info (hashcat_ctx, "Hash.Target....: File (%s)", hashes->hashfile); } } - log_info ("Hash.Type......: %s", hash_type); + event_log_info (hashcat_ctx, "Hash.Type......: %s", hash_type); /** * speed new @@ -693,12 +693,12 @@ void status_display (hashcat_ctx_t *hashcat_ctx) 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); + event_log_info (hashcat_ctx, "Time.Started...: %s (%s)", start, display_run); } } else { - log_info ("Time.Started...: 0 secs"); + event_log_info (hashcat_ctx, "Time.Started...: 0 secs"); } /** @@ -786,7 +786,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx) } else if ((u64) sec_etc > SEC10YEARS) { - log_info ("Time.Estimated.: > 10 Years"); + event_log_info (hashcat_ctx, "Time.Estimated.: > 10 Years"); } else { @@ -849,16 +849,16 @@ void status_display (hashcat_ctx_t *hashcat_ctx) format_timer_display (&tm_runtime, display_runtime, sizeof (display_runtime)); - log_info ("Time.Estimated.: %s (%s), but limited (%s)", etc, display_etc, display_runtime); + event_log_info (hashcat_ctx, "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); + event_log_info (hashcat_ctx, "Time.Estimated.: %s (%s), but limit exceeded", etc, display_etc); } } else { - log_info ("Time.Estimated.: %s (%s)", etc, display_etc); + event_log_info (hashcat_ctx, "Time.Estimated.: %s (%s)", etc, display_etc); } } } @@ -877,11 +877,11 @@ void status_display (hashcat_ctx_t *hashcat_ctx) { if (user_options_extra->attack_kern == ATTACK_KERN_BF) { - log_info ("Candidates.#%d..: [Generating]", device_id + 1); + event_log_info (hashcat_ctx, "Candidates.#%d..: [Generating]", device_id + 1); } else { - log_info ("Candidates.#%d..: [Copying]", device_id + 1); + event_log_info (hashcat_ctx, "Candidates.#%d..: [Copying]", device_id + 1); } continue; @@ -919,11 +919,11 @@ void status_display (hashcat_ctx_t *hashcat_ctx) 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); + event_log_info (hashcat_ctx, "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); + event_log_info (hashcat_ctx, "Candidates.#%d..: %s -> %s", device_id + 1, plain_ptr1, plain_ptr2); } } } @@ -940,7 +940,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx) 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]); + event_log_info (hashcat_ctx, "Speed.Dev.#%d...: %9sH/s (%0.2fms)", device_id + 1, display_dev_cur, exec_all_ms[device_id]); } char display_all_cur[16] = { 0 }; @@ -949,12 +949,12 @@ void status_display (hashcat_ctx_t *hashcat_ctx) 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); + if (opencl_ctx->devices_active > 1) event_log_info (hashcat_ctx, "Speed.Dev.#*...: %9sH/s", display_all_cur); 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); + event_log_info (hashcat_ctx, "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 @@ -995,7 +995,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx) 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)", + event_log_info (hashcat_ctx, "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, @@ -1005,7 +1005,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx) } 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)", + event_log_info (hashcat_ctx, "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, @@ -1014,7 +1014,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx) } 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)", + event_log_info (hashcat_ctx, "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, @@ -1022,7 +1022,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx) } else { - log_info ("Recovered/Time.: CUR:N/A,N/A,N/A AVG:%0.2f,%0.2f,%0.2f (Min,Hour,Day)", + event_log_info (hashcat_ctx, "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); @@ -1051,14 +1051,14 @@ void status_display (hashcat_ctx_t *hashcat_ctx) 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); + event_log_info (hashcat_ctx, "Progress.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", progress_cur_relative_skip, progress_end_relative_skip, percent_finished * 100); + event_log_info (hashcat_ctx, "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); + event_log_info (hashcat_ctx, "Restore.Point..: %" PRIu64 "/%" PRIu64 " (%.02f%%)", restore_point, restore_total, percent_restore * 100); } } } @@ -1067,24 +1067,24 @@ void status_display (hashcat_ctx_t *hashcat_ctx) { 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); + event_log_info (hashcat_ctx, "Progress.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); + event_log_info (hashcat_ctx, "Rejected.......: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); if (user_options->restore_disable == false) { - log_info ("Restore.Point..: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); + event_log_info (hashcat_ctx, "Restore.Point..: %" PRIu64 "/%" PRIu64 " (%.02f%%)", 0ull, 0ull, 100); } } else { - log_info ("Progress.......: %" PRIu64 "", progress_cur_relative_skip); - log_info ("Rejected.......: %" PRIu64 "", all_rejected); + event_log_info (hashcat_ctx, "Progress.......: %" PRIu64 "", progress_cur_relative_skip); + event_log_info (hashcat_ctx, "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); + // event_log_info (hashcat_ctx, "Restore.Point..: %" PRIu64 "", restore_point); //} } } @@ -1169,7 +1169,7 @@ void status_display (hashcat_ctx_t *hashcat_ctx) output_len = strlen (output_buf); } - log_info ("HWMon.Dev.#%d...:%s", device_id + 1, output_buf); + event_log_info (hashcat_ctx, "HWMon.Dev.#%d...:%s", device_id + 1, output_buf); } hc_thread_mutex_unlock (status_ctx->mux_hwmon); @@ -1184,14 +1184,14 @@ void status_benchmark_automate (hashcat_ctx_t *hashcat_ctx) if (status_ctx->devices_status == STATUS_INIT) { - log_error ("ERROR: status view is not available during initialization phase"); + event_log_error (hashcat_ctx, "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"); + event_log_error (hashcat_ctx, "ERROR: status view is not available during autotune phase"); return; } @@ -1231,7 +1231,7 @@ void status_benchmark_automate (hashcat_ctx_t *hashcat_ctx) if (device_param->skipped) continue; - log_info ("%u:%u:%" PRIu64 "", device_id + 1, hashconfig->hash_mode, (hashes_dev_ms[device_id] * 1000)); + event_log_info (hashcat_ctx, "%u:%u:%" PRIu64 "", device_id + 1, hashconfig->hash_mode, (hashes_dev_ms[device_id] * 1000)); } } @@ -1243,14 +1243,14 @@ void status_benchmark (hashcat_ctx_t *hashcat_ctx) if (status_ctx->devices_status == STATUS_INIT) { - log_error ("ERROR: status view is not available during initialization phase"); + event_log_error (hashcat_ctx, "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"); + event_log_error (hashcat_ctx, "ERROR: status view is not available during autotune phase"); return; } @@ -1328,11 +1328,11 @@ void status_benchmark (hashcat_ctx_t *hashcat_ctx) 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]); + event_log_info (hashcat_ctx, "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]); + event_log_info (hashcat_ctx, "Speed.Dev.#%d.: %9sH/s (%0.2fms)", device_id + 1, display_dev_cur, exec_all_ms[device_id]); } } @@ -1342,7 +1342,7 @@ void status_benchmark (hashcat_ctx_t *hashcat_ctx) 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); + if (opencl_ctx->devices_active > 1) event_log_info (hashcat_ctx, "Speed.Dev.#*.: %9sH/s", display_all_cur); } int status_progress_init (hashcat_ctx_t *hashcat_ctx) diff --git a/src/stdout.c b/src/stdout.c index 1ebf39c46..96d668e7c 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, "ERROR: %s: %s", filename, strerror (errno)); out.fp = stdout; } @@ -240,4 +242,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..e89fa827f 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" @@ -69,7 +69,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, "ERROR: %s: %s", straight_ctx->dict, strerror (errno)); return -1; } @@ -97,7 +97,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, "ERROR: %s: %s", combinator_ctx->dict1, strerror (errno)); return -1; } @@ -112,7 +112,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, "ERROR: %s: %s", combinator_ctx->dict2, strerror (errno)); return -1; } @@ -151,7 +151,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, "ERROR: %s: %s", straight_ctx->dict, strerror (errno)); return -1; } @@ -272,7 +272,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, "ERROR: %s: %s", l0_filename, strerror (errno)); return -1; } @@ -295,7 +295,7 @@ 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, "ERROR: %s: %s", l1_filename, strerror (errno)); return -1; } @@ -317,7 +317,7 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) if (straight_ctx->dicts_cnt == 0) { - log_error ("ERROR: No usable dictionary file found."); + event_log_error (hashcat_ctx, "ERROR: No usable dictionary file found."); return -1; } @@ -341,7 +341,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, "ERROR: %s: %s", l0_filename, strerror (errno)); return -1; } @@ -364,7 +364,7 @@ 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, "ERROR: %s: %s", l1_filename, strerror (errno)); return -1; } @@ -386,7 +386,7 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) if (straight_ctx->dicts_cnt == 0) { - log_error ("ERROR: No usable dictionary file found."); + event_log_error (hashcat_ctx, "ERROR: No usable dictionary file found."); return -1; } @@ -401,7 +401,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, "ERROR: %s: %s", l0_filename, strerror (errno)); return -1; } @@ -424,7 +424,7 @@ 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, "ERROR: %s: %s", l1_filename, strerror (errno)); return -1; } @@ -446,7 +446,7 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) if (straight_ctx->dicts_cnt == 0) { - log_error ("ERROR: No usable dictionary file found."); + event_log_error (hashcat_ctx, "ERROR: No usable dictionary file found."); return -1; } diff --git a/src/terminal.c b/src/terminal.c index db519f94a..cd0a72bec 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -5,7 +5,7 @@ #include "common.h" #include "types.h" -#include "logging.h" +#include "event.h" #include "thread.h" #include "timer.h" #include "status.h" @@ -29,23 +29,23 @@ 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 { - 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 +59,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 (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, "ERROR: %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, "ERROR: %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, "ERROR: %s: %s", "stderr", strerror (errno)); return -1; } @@ -141,7 +141,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 +149,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 +161,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 +175,16 @@ static void keypress (hashcat_ctx_t *hashcat_ctx) case 'p': - log_info (""); + event_log_info (hashcat_ctx, ""); + + SuspendThreads (hashcat_ctx); - SuspendThreads (status_ctx); + if (status_ctx->devices_status == STATUS_PAUSED) + { + event_log_info (hashcat_ctx, "Paused"); + } - log_info (""); + event_log_info (hashcat_ctx, ""); if (quiet == false) send_prompt (); @@ -185,11 +192,16 @@ static void keypress (hashcat_ctx_t *hashcat_ctx) case 'r': - log_info (""); + event_log_info (hashcat_ctx, ""); + + ResumeThreads (hashcat_ctx); - ResumeThreads (status_ctx); + if (status_ctx->devices_status == STATUS_RUNNING) + { + event_log_info (hashcat_ctx, "Resumed"); + } - log_info (""); + event_log_info (hashcat_ctx, ""); if (quiet == false) send_prompt (); @@ -197,11 +209,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 +221,9 @@ static void keypress (hashcat_ctx_t *hashcat_ctx) case 'q': - log_info (""); + event_log_info (hashcat_ctx, ""); - myabort (status_ctx); + myabort (hashcat_ctx); break; } diff --git a/src/thread.c b/src/thread.c index 919e09452..bedba5f78 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) +void 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; @@ -129,8 +131,10 @@ void mycracked (status_ctx_t *status_ctx) status_ctx->run_thread_level2 = false; } -void myabort (status_ctx_t *status_ctx) +void 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 //if (status_ctx->devices_status != STATUS_RUNNING) return; @@ -143,8 +147,10 @@ void myabort (status_ctx_t *status_ctx) status_ctx->run_thread_level2 = false; } -void myquit (status_ctx_t *status_ctx) +void myquit (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_QUIT; @@ -156,8 +162,10 @@ void myquit (status_ctx_t *status_ctx) status_ctx->run_thread_level2 = false; } -void bypass (status_ctx_t *status_ctx) +void bypass (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_BYPASS; @@ -167,23 +175,23 @@ void bypass (status_ctx_t *status_ctx) status_ctx->run_main_level3 = true; status_ctx->run_thread_level1 = false; status_ctx->run_thread_level2 = false; - - log_info ("Next dictionary / mask in queue selected, bypassing current one"); } -void SuspendThreads (status_ctx_t *status_ctx) +void SuspendThreads (hashcat_ctx_t *hashcat_ctx) { + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + if (status_ctx->devices_status != STATUS_RUNNING) return; hc_timer_set (&status_ctx->timer_paused); status_ctx->devices_status = STATUS_PAUSED; - - log_info ("Paused"); } -void ResumeThreads (status_ctx_t *status_ctx) +void ResumeThreads (hashcat_ctx_t *hashcat_ctx) { + status_ctx_t *status_ctx = hashcat_ctx->status_ctx; + if (status_ctx->devices_status != STATUS_PAUSED) return; double ms_paused = hc_timer_get (status_ctx->timer_paused); @@ -191,6 +199,4 @@ void ResumeThreads (status_ctx_t *status_ctx) status_ctx->ms_paused += ms_paused; status_ctx->devices_status = STATUS_RUNNING; - - log_info ("Resumed"); } diff --git a/src/tuningdb.c b/src/tuningdb.c index 88968e470..6aa11307c 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" @@ -75,7 +75,7 @@ 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; } @@ -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; } @@ -223,7 +223,7 @@ 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; } diff --git a/src/usage.c b/src/usage.c index 0d4b4d0d8..71de716e4 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[] = @@ -411,10 +410,10 @@ 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); } 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); } diff --git a/src/user_options.c b/src/user_options.c index b97775aef..f12e2deb0 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" @@ -320,7 +320,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, "ERROR: Invalid argument specified"); return -1; } @@ -329,7 +329,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, "ERROR: Invalid argument specified"); return -1; } @@ -348,14 +348,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, "ERROR: 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, "ERROR: hc_argv is NULL"); return -1; } @@ -367,21 +367,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, "ERROR: 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, "ERROR: Invalid runtime specified"); return -1; } if (user_options->hash_mode > 14100) { - log_error ("ERROR: Invalid hash-type specified"); + event_log_error (hashcat_ctx, "ERROR: Invalid hash-type specified"); return -1; } @@ -393,7 +393,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, "ERROR: Mixing support for user names and hashes of type %s is not supported", strhashtype (user_options->hash_mode)); return -1; } @@ -401,7 +401,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, "ERROR: Invalid outfile-format specified"); return -1; } @@ -410,7 +410,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, "ERROR: Mixing outfile-format > 1 with left parameter is not allowed"); return -1; } @@ -420,7 +420,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, "ERROR: Mixing outfile-format > 7 with show parameter is not allowed"); return -1; } @@ -428,49 +428,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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: 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, "ERROR: Use of both rules-file and rules-generate is not supported"); return -1; } @@ -479,7 +479,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, "ERROR: Use of rules-file or rules-generate only allowed in attack-mode 0"); return -1; } @@ -487,14 +487,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, "ERROR: 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, "ERROR: Invalid rp-gen-func-min specified"); return -1; } @@ -503,24 +503,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, "ERROR: Invalid kernel-accel specified"); return -1; } if (user_options->kernel_accel > 1024) { - log_error ("ERROR: Invalid kernel-accel specified"); + event_log_error (hashcat_ctx, "ERROR: Invalid kernel-accel specified"); return -1; } @@ -530,24 +530,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, "ERROR: Invalid kernel-loops specified"); return -1; } if (user_options->kernel_loops > 1024) { - log_error ("ERROR: Invalid kernel-loops specified"); + event_log_error (hashcat_ctx, "ERROR: Invalid kernel-loops specified"); return -1; } @@ -555,7 +555,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, "ERROR: workload-profile %i not available", user_options->workload_profile); return -1; } @@ -564,7 +564,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, "ERROR: opencl-vector-width %i not allowed", user_options->opencl_vector_width); return -1; } @@ -574,14 +574,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, "ERROR: 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, "ERROR: Mixing potfile-disable parameter not allowed with show parameter or left parameter"); return -1; } @@ -591,7 +591,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, "ERROR: Mixing outfile-autohex-disable parameter not allowed with show parameter"); return -1; } @@ -601,13 +601,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, "ERROR: 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, "ERROR: Combining left parameter with keyspace parameter is not allowed"); return -1; } @@ -617,14 +617,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, "ERROR: 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, "ERROR: Parameter remove-timer must have a value greater than or equal to 1"); return -1; } @@ -636,14 +636,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, "ERROR: 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, "ERROR: Parameter loopback allowed in attack-mode 0 only"); return -1; } @@ -654,14 +654,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, "ERROR: 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, "ERROR: Parameter debug-mode not allowed without rules-file or rules-generate"); return -1; } @@ -669,7 +669,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, "ERROR: Invalid debug-mode specified"); return -1; } @@ -678,7 +678,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, "ERROR: Parameter debug-file requires parameter debug-mode to be set"); return -1; } @@ -688,7 +688,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, "ERROR: Parameter induction-dir not allowed with brute-force attacks"); return -1; } @@ -698,7 +698,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, "ERROR: setting --weak-hash-threshold allowed only in straight-attack mode"); return -1; } @@ -706,7 +706,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, "ERROR: setting --nvidia-spin-damp must be between 0 and 100 (inclusive)"); return -1; } @@ -715,7 +715,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, "ERROR: Invalid values for gpu-temp-abort. Parameter gpu-temp-abort is less than gpu-temp-retain."); return -1; } @@ -727,7 +727,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, "ERROR: Only attack-mode 3 allowed in benchmark mode"); return -1; } diff --git a/src/weak_hash.c b/src/weak_hash.c index a39df35ac..a40e82df9 100644 --- a/src/weak_hash.c +++ b/src/weak_hash.c @@ -5,7 +5,7 @@ #include "common.h" #include "types.h" -#include "logging.h" +#include "event.h" #include "opencl.h" #include "hashes.h" #include "weak_hash.h" diff --git a/src/wordlist.c b/src/wordlist.c index 2e73bc6c6..28e0d23d9 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" @@ -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);