1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-22 22:58:30 +00:00

Merge pull request #2825 from matrix/hwmon_osx_v2

Add OSX HW Monitor initial support (2021)
This commit is contained in:
Jens Steube 2021-06-20 11:09:35 +02:00 committed by GitHub
commit 7e267b9b37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 653 additions and 21 deletions

View File

@ -22,7 +22,7 @@ Gabriele "matrix" Gristina <matrix@hashcat.net> (@gm4tr1x)
* Compressed wordlist feature
* OpenCL Info feature
* Apple macOS port
* Hardware monitor initial code base
* Hardware monitor initial code base and maintenance
* Test suite initial code base
* Makefile initial code base
* Multithreading initial code base

128
include/ext_iokit.h Normal file
View File

@ -0,0 +1,128 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#ifndef _EXT_IOKIT_H
#define _EXT_IOKIT_H
#if defined(__APPLE__)
#include <IOKit/IOKitLib.h>
// Apple SMC Keys
#define HM_IOKIT_SMC_SENSOR_GRAPHICS_HOT "SGHT"
#define HM_IOKIT_SMC_CPU_PROXIMITY "TC0P"
#define HM_IOKIT_SMC_GPU_PROXIMITY "TG0P"
#define HM_IOKIT_SMC_PECI_GPU "TCGC"
#define KERNEL_INDEX_SMC 2
#define DATATYPE_FPE2 "fpe2"
#define DATATYPE_FLT "flt "
#define DATATYPE_UINT8 "ui8 "
#define DATATYPE_UINT16 "ui16"
#define DATATYPE_UINT32 "ui32"
#define DATATYPE_SP78 "sp78"
typedef enum
{
SMC_CMD_READ_BYTES = 5,
SMC_CMD_WRITE_BYTES = 6,
SMC_CMD_READ_INDEX = 8,
SMC_CMD_READ_KEYINFO = 9,
SMC_CMD_READ_PLIMIT = 11,
SMC_CMD_READ_VERS = 12
} SMCCommands_t;
typedef struct
{
char major;
char minor;
char build;
char reserved[1];
UInt16 release;
} SMCKeyData_vers_t;
typedef struct
{
UInt16 version;
UInt16 length;
UInt32 cpuPLimit;
UInt32 gpuPLimit;
UInt32 memPLimit;
} SMCKeyData_pLimitData_t;
typedef struct
{
UInt32 dataSize;
UInt32 dataType;
char dataAttributes;
} SMCKeyData_keyInfo_t;
typedef char SMCBytes_t[32];
typedef struct
{
UInt32 key;
SMCKeyData_vers_t vers;
SMCKeyData_pLimitData_t pLimitData;
SMCKeyData_keyInfo_t keyInfo;
char result;
char status;
char data8;
UInt32 data32;
SMCBytes_t bytes;
} SMCKeyData_t;
typedef char UInt32Char_t[5];
typedef struct
{
UInt32Char_t key;
UInt32 dataSize;
UInt32Char_t dataType;
SMCBytes_t bytes;
} SMCVal_t;
#endif // __APPLE__
typedef int HM_ADAPTER_IOKIT;
typedef void *IOKIT_LIB;
typedef struct hm_iokit_lib
{
#if defined(__APPLE__)
io_connect_t conn;
#endif // __APPLE__
} hm_iokit_lib_t;
typedef hm_iokit_lib_t IOKIT_PTR;
#if defined(__APPLE__)
UInt32 hm_IOKIT_strtoul (char *str, int size, int base);
void hm_IOKIT_ultostr (char *str, UInt32 val);
kern_return_t hm_IOKIT_SMCOpen (void *hashcat_ctx, io_connect_t *conn);
kern_return_t hm_IOKIT_SMCClose (io_connect_t conn);
kern_return_t hm_IOKIT_SMCCall (int index, SMCKeyData_t *inData, SMCKeyData_t *outData, io_connect_t conn);
kern_return_t hm_IOKIT_SMCReadKey (UInt32Char_t key, SMCVal_t *val, io_connect_t conn);
int hm_IOKIT_SMCGetSensorGraphicHot (void *hashcat_ctx);
int hm_IOKIT_SMCGetTemperature (void *hashcat_ctx, char *key, double *temp);
bool hm_IOKIT_SMCGetFanRPM (char *key, io_connect_t conn, float *ret);
int hm_IOKIT_get_fan_speed_current (void *hashcat_ctx, char *fan_speed_buf);
bool iokit_init (void *hashcat_ctx);
bool iokit_close (void *hashcat_ctx);
#endif // __APPLE__
#endif // _EXT_IOKIT_H

View File

@ -16,6 +16,9 @@ int hm_get_threshold_shutdown_with_devices_idx (hashcat_ctx_t *hashcat_ctx, cons
int hm_get_temperature_with_devices_idx (hashcat_ctx_t *hashcat_ctx, const int backend_device_idx);
int hm_get_fanpolicy_with_devices_idx (hashcat_ctx_t *hashcat_ctx, const int backend_device_idx);
int hm_get_fanspeed_with_devices_idx (hashcat_ctx_t *hashcat_ctx, const int backend_device_idx);
#if defined(__APPLE__)
int hm_get_fanspeed_apple (hashcat_ctx_t *hashcat_ctx, char *fan_speed_buf);
#endif
int hm_get_buslanes_with_devices_idx (hashcat_ctx_t *hashcat_ctx, const int backend_device_idx);
int hm_get_utilization_with_devices_idx (hashcat_ctx_t *hashcat_ctx, const int backend_device_idx);
int hm_get_memoryspeed_with_devices_idx (hashcat_ctx_t *hashcat_ctx, const int backend_device_idx);

View File

@ -98,6 +98,9 @@ char *status_get_brain_link_send_bytes_sec_dev (const hashcat_ctx_t *hash
char *status_get_brain_rx_all (const hashcat_ctx_t *hashcat_ctx);
char *status_get_brain_tx_all (const hashcat_ctx_t *hashcat_ctx);
#endif
#if defined(__APPLE__)
char *status_get_hwmon_fan_dev (const hashcat_ctx_t *hashcat_ctx);
#endif
char *status_get_hwmon_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx);
int status_get_corespeed_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx);
int status_get_memoryspeed_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx);

View File

@ -611,7 +611,11 @@ typedef enum user_options_defaults
DEBUG_MODE = 0,
FORCE = false,
HWMON_DISABLE = false,
#if defined (__APPLE__)
HWMON_TEMP_ABORT = 100,
#else
HWMON_TEMP_ABORT = 90,
#endif
HASH_INFO = false,
HASH_MODE = 0,
HCCAPX_MESSAGE_PAIR = 0,
@ -1589,6 +1593,7 @@ typedef struct backend_ctx
bool need_nvml;
bool need_nvapi;
bool need_sysfs;
bool need_iokit;
int comptime;
@ -1632,6 +1637,7 @@ typedef enum kernel_workload
#include "ext_nvapi.h"
#include "ext_nvml.h"
#include "ext_sysfs.h"
#include "ext_iokit.h"
typedef struct hm_attrs
{
@ -1639,6 +1645,7 @@ typedef struct hm_attrs
HM_ADAPTER_NVML nvml;
HM_ADAPTER_NVAPI nvapi;
HM_ADAPTER_SYSFS sysfs;
HM_ADAPTER_IOKIT iokit;
int od_version;
@ -1663,6 +1670,7 @@ typedef struct hwmon_ctx
void *hm_nvml;
void *hm_nvapi;
void *hm_sysfs;
void *hm_iokit;
hm_attrs_t *hm_device;
@ -2243,6 +2251,9 @@ typedef struct device_info
double exec_msec_dev;
char *speed_sec_dev;
char *guess_candidates_dev;
#if defined(__APPLE__)
char *hwmon_fan_dev;
#endif
char *hwmon_dev;
int corespeed_dev;
int memoryspeed_dev;

View File

@ -315,6 +315,7 @@ endif # FreeBSD
ifeq ($(UNAME),Darwin)
export MACOSX_DEPLOYMENT_TARGET=10.9
CFLAGS_NATIVE := $(CFLAGS)
CFLAGS_NATIVE += -DWITH_HWMON
ifeq ($(shell test $(DARWIN_VERSION) -le 15; echo $$?), 0)
CFLAGS_NATIVE += -DMISSING_CLOCK_GETTIME
@ -322,6 +323,7 @@ endif
LFLAGS_NATIVE := $(LFLAGS)
LFLAGS_NATIVE += -framework OpenCL
LFLAGS_NATIVE += -framework IOKit
LFLAGS_NATIVE += -lpthread
LFLAGS_NATIVE += -liconv
endif # Darwin
@ -363,7 +365,7 @@ EMU_OBJS_ALL += emu_inc_rp emu_inc_rp_optimized
EMU_OBJS_ALL += emu_inc_hash_md4 emu_inc_hash_md5 emu_inc_hash_ripemd160 emu_inc_hash_sha1 emu_inc_hash_sha256 emu_inc_hash_sha384 emu_inc_hash_sha512 emu_inc_hash_streebog256 emu_inc_hash_streebog512 emu_inc_ecc_secp256k1
EMU_OBJS_ALL += emu_inc_cipher_aes emu_inc_cipher_camellia emu_inc_cipher_des emu_inc_cipher_kuznyechik emu_inc_cipher_serpent emu_inc_cipher_twofish
OBJS_ALL := affinity autotune backend benchmark bitmap bitops combinator common convert cpt cpu_crc32 debugfile dictstat dispatch dynloader event ext_ADL ext_cuda ext_nvapi ext_nvml ext_nvrtc ext_OpenCL ext_sysfs ext_lzma filehandling folder hashcat hashes hlfmt hwmon induct interface keyboard_layout locking logfile loopback memory monitor mpsp outfile_check outfile pidfile potfile restore rp rp_cpu selftest slow_candidates shared status stdout straight terminal thread timer tuningdb usage user_options wordlist $(EMU_OBJS_ALL)
OBJS_ALL := affinity autotune backend benchmark bitmap bitops combinator common convert cpt cpu_crc32 debugfile dictstat dispatch dynloader event ext_ADL ext_cuda ext_nvapi ext_nvml ext_nvrtc ext_OpenCL ext_sysfs ext_iokit ext_lzma filehandling folder hashcat hashes hlfmt hwmon induct interface keyboard_layout locking logfile loopback memory monitor mpsp outfile_check outfile pidfile potfile restore rp rp_cpu selftest slow_candidates shared status stdout straight terminal thread timer tuningdb usage user_options wordlist $(EMU_OBJS_ALL)
ifeq ($(ENABLE_BRAIN),1)
OBJS_ALL += brain

View File

@ -5664,6 +5664,7 @@ int backend_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime)
bool need_nvml = false;
bool need_nvapi = false;
bool need_sysfs = false;
bool need_iokit = false;
int backend_devices_idx = 0;
@ -5912,10 +5913,12 @@ int backend_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime)
device_param->skipped = true;
}
#if !defined (__APPLE__)
if ((backend_ctx->opencl_device_types_filter & CL_DEVICE_TYPE_GPU) == 0)
{
device_param->skipped = true;
}
#endif
if ((device_param->opencl_platform_vendor_id == VENDOR_ID_NV) && (device_param->opencl_device_vendor_id == VENDOR_ID_NV))
{
@ -6670,6 +6673,13 @@ int backend_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime)
// vendor specific
#if defined (__APPLE__)
if (device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE)
{
if (device_param->skipped == false) need_iokit = true;
}
#endif
if (device_param->opencl_device_type & CL_DEVICE_TYPE_GPU)
{
if ((device_param->opencl_platform_vendor_id == VENDOR_ID_AMD) && (device_param->opencl_device_vendor_id == VENDOR_ID_AMD))
@ -7344,6 +7354,7 @@ int backend_ctx_devices_init (hashcat_ctx_t *hashcat_ctx, const int comptime)
backend_ctx->need_nvml = need_nvml;
backend_ctx->need_nvapi = need_nvapi;
backend_ctx->need_sysfs = need_sysfs;
backend_ctx->need_iokit = need_iokit;
backend_ctx->comptime = comptime;

305
src/ext_iokit.c Normal file
View File

@ -0,0 +1,305 @@
/**
* Author......: See docs/credits.txt
* License.....: MIT
*/
#include "common.h"
#include "types.h"
#include "memory.h"
#include "shared.h"
#include "event.h"
#include "ext_iokit.h"
#if defined (__APPLE__)
#include <IOKit/IOKitLib.h>
UInt32 hm_IOKIT_strtoul (char *str, int size, int base)
{
int i;
UInt32 total = 0;
for (i = 0; i < size; i++)
{
if (base == 16)
{
total += str[i] << (size - 1 - i) * 8;
}
else
{
total += (unsigned char)(str[i] << (size - 1 - i) * 8);
}
}
return total;
}
void hm_IOKIT_ultostr (char *str, UInt32 val)
{
str[0] = '\0';
sprintf (str, "%c%c%c%c", (unsigned int)(val >> 24), (unsigned int)(val >> 16), (unsigned int)(val >> 8), (unsigned int)(val));
}
kern_return_t hm_IOKIT_SMCOpen (void *hashcat_ctx, io_connect_t *conn)
{
kern_return_t result;
io_iterator_t iterator;
io_object_t device;
CFMutableDictionaryRef matchingDictionary = IOServiceMatching ("AppleSMC");
result = IOServiceGetMatchingServices (kIOMasterPortDefault, matchingDictionary, &iterator);
if (result != kIOReturnSuccess)
{
event_log_error (hashcat_ctx, "IOServiceGetMatchingServices(): %08x", result);
return 1;
}
device = IOIteratorNext (iterator);
IOObjectRelease (iterator);
if (device == 0)
{
event_log_error (hashcat_ctx, "hm_IOKIT_SMCOpen(): no SMC found.");
return 1;
}
result = IOServiceOpen (device, mach_task_self(), 0, conn);
IOObjectRelease (device);
if (result != kIOReturnSuccess)
{
event_log_error (hashcat_ctx, "IOServiceOpen(): %08x", result);
return 1;
}
return kIOReturnSuccess;
}
kern_return_t hm_IOKIT_SMCClose (io_connect_t conn)
{
return IOServiceClose (conn);
}
kern_return_t hm_IOKIT_SMCCall (int index, SMCKeyData_t *inData, SMCKeyData_t *outData, io_connect_t conn)
{
size_t inDataSize = sizeof (SMCKeyData_t);
size_t outDataSize = sizeof (SMCKeyData_t);
#if MAC_OS_X_VERSION_10_5
return IOConnectCallStructMethod (conn, index, inData, inDataSize, outData, &outDataSize);
#else
return IOConnectMethodStructureIStructureO (conn, index, inDataSize, &outDataSize, inData, outData);
#endif
}
kern_return_t hm_IOKIT_SMCReadKey (UInt32Char_t key, SMCVal_t *val, io_connect_t conn)
{
SMCKeyData_t inData;
SMCKeyData_t outData;
memset (&inData, 0, sizeof (SMCKeyData_t));
memset (&outData, 0, sizeof (SMCKeyData_t));
memset (val, 0, sizeof (SMCVal_t));
inData.key = hm_IOKIT_strtoul (key, 4, 16);
inData.data8 = SMC_CMD_READ_KEYINFO;
if (hm_IOKIT_SMCCall (KERNEL_INDEX_SMC, &inData, &outData, conn) != kIOReturnSuccess) return 1;
val->dataSize = outData.keyInfo.dataSize;
hm_IOKIT_ultostr (val->dataType, outData.keyInfo.dataType);
inData.keyInfo.dataSize = val->dataSize;
inData.data8 = SMC_CMD_READ_BYTES;
if (hm_IOKIT_SMCCall (KERNEL_INDEX_SMC, &inData, &outData, conn) != kIOReturnSuccess) return 1;
memcpy(val->bytes, outData.bytes, sizeof(outData.bytes));
return kIOReturnSuccess;
}
int hm_IOKIT_SMCGetSensorGraphicHot (void *hashcat_ctx)
{
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
IOKIT_PTR *iokit = hwmon_ctx->hm_iokit;
SMCVal_t val;
memset (&val, 0, sizeof (SMCVal_t));
if (hm_IOKIT_SMCReadKey (HM_IOKIT_SMC_SENSOR_GRAPHICS_HOT, &val, iokit->conn) == kIOReturnSuccess)
{
int alarm = -1;
if (val.dataSize > 0)
{
if (strcmp(val.dataType, DATATYPE_UINT8) == 0)
{
alarm = hm_IOKIT_strtoul ((char *)val.bytes, val.dataSize, 10);
}
}
return alarm;
}
return -1;
}
int hm_IOKIT_SMCGetTemperature (void *hashcat_ctx, char *key, double *temp)
{
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
IOKIT_PTR *iokit = hwmon_ctx->hm_iokit;
SMCVal_t val;
memset (&val, 0, sizeof (SMCVal_t));
if (hm_IOKIT_SMCReadKey (key, &val, iokit->conn) == kIOReturnSuccess)
{
if (val.dataSize > 0)
{
if (strcmp(val.dataType, DATATYPE_SP78) == 0)
{
// convert sp78 value to temperature
int intValue = val.bytes[0] * 256 + (unsigned char)val.bytes[1];
*temp = (intValue / 256.0);
return 1;
}
}
}
// read failed
*temp = 0.0;
return -1;
}
bool hm_IOKIT_SMCGetFanRPM (char *key, io_connect_t conn, float *ret)
{
SMCVal_t val;
memset (&val, 0, sizeof (SMCVal_t));
if (hm_IOKIT_SMCReadKey (key, &val, conn) == kIOReturnSuccess)
{
if (val.dataSize > 0)
{
if (strcmp(val.dataType, DATATYPE_FLT) == 0)
{
*ret = *(float *) val.bytes;
return true;
}
if (strcmp(val.dataType, DATATYPE_FPE2) == 0)
{
// convert fpe2 value to RPM
*ret = ntohs (*(UInt16*)val.bytes) / 4.0;
return true;
}
}
}
// read failed
*ret = -1.f;
return false;
}
int hm_IOKIT_get_fan_speed_current (void *hashcat_ctx, char *fan_speed_buf)
{
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
IOKIT_PTR *iokit = hwmon_ctx->hm_iokit;
SMCVal_t val;
UInt32Char_t key;
memset (&val, 0, sizeof (SMCVal_t));
if (hm_IOKIT_SMCReadKey ("FNum", &val, iokit->conn) == kIOReturnSuccess)
{
int totalFans = hm_IOKIT_strtoul ((char *)val.bytes, val.dataSize, 10);
if (totalFans <= 0) return -1;
char tmp_buf[16];
for (int i = 0; i < totalFans; i++)
{
int fan_speed = 0;
float actual_speed = 0.0f;
float maximum_speed = 0.0f;
memset (&key, 0, sizeof (UInt32Char_t));
sprintf (key, "F%dAc", i);
hm_IOKIT_SMCGetFanRPM (key, iokit->conn, &actual_speed);
if (actual_speed < 0.f) continue;
memset (&key, 0, sizeof (UInt32Char_t));
sprintf (key, "F%dMx", i);
hm_IOKIT_SMCGetFanRPM (key, iokit->conn, &maximum_speed);
if (maximum_speed < 0.f) continue;
fan_speed = (actual_speed / maximum_speed) * 100.f;
memset (tmp_buf, 0, sizeof (tmp_buf));
snprintf (tmp_buf, sizeof (tmp_buf) - 1, "Fan%d: %d%%, ", i, fan_speed);
strncat (fan_speed_buf, tmp_buf, strlen (tmp_buf));
}
// remove last two bytes
size_t out_len = strlen (fan_speed_buf);
if (out_len > 2) fan_speed_buf[out_len-2] = '\0';
}
return 1;
}
bool iokit_init (void *hashcat_ctx)
{
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
IOKIT_PTR *iokit = hwmon_ctx->hm_iokit;
memset (iokit, 0, sizeof (IOKIT_PTR));
if (hm_IOKIT_SMCOpen (hashcat_ctx, &iokit->conn) == kIOReturnSuccess) return true;
hcfree (hwmon_ctx->hm_iokit);
hwmon_ctx->hm_iokit = NULL;
return false;
}
bool iokit_close (void *hashcat_ctx)
{
hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx;
IOKIT_PTR *iokit = hwmon_ctx->hm_iokit;
hm_IOKIT_SMCClose (iokit->conn);
return true;
}
#endif // __APPLE__

View File

@ -1808,6 +1808,9 @@ int hashcat_get_status (hashcat_ctx_t *hashcat_ctx, hashcat_status_t *hashcat_st
device_info->exec_msec_dev = status_get_exec_msec_dev (hashcat_ctx, device_id);
device_info->speed_sec_dev = status_get_speed_sec_dev (hashcat_ctx, device_id);
device_info->guess_candidates_dev = status_get_guess_candidates_dev (hashcat_ctx, device_id);
#if defined(__APPLE__)
device_info->hwmon_fan_dev = status_get_hwmon_fan_dev (hashcat_ctx);
#endif
device_info->hwmon_dev = status_get_hwmon_dev (hashcat_ctx, device_id);
device_info->corespeed_dev = status_get_corespeed_dev (hashcat_ctx, device_id);
device_info->memoryspeed_dev = status_get_memoryspeed_dev (hashcat_ctx, device_id);

View File

@ -245,7 +245,39 @@ int hm_get_temperature_with_devices_idx (hashcat_ctx_t *hashcat_ctx, const int b
if (backend_ctx->devices_param[backend_device_idx].is_opencl == true)
{
#if defined (__APPLE__)
if (backend_ctx->devices_param[backend_device_idx].opencl_platform_vendor_id == VENDOR_ID_APPLE)
{
if (hwmon_ctx->hm_iokit)
{
double temperature = 0.0;
char *key = NULL;
if ((backend_ctx->devices_param[backend_device_idx].opencl_device_type & CL_DEVICE_TYPE_GPU) == 0) key = HM_IOKIT_SMC_CPU_PROXIMITY;
else
{
key = HM_IOKIT_SMC_GPU_PROXIMITY;
if (backend_ctx->devices_param[backend_device_idx].opencl_device_vendor_id == VENDOR_ID_INTEL_BEIGNET)
{
key = HM_IOKIT_SMC_PECI_GPU;
}
}
if (hm_IOKIT_SMCGetTemperature(hashcat_ctx, key, &temperature) == -1)
{
hwmon_ctx->hm_device[backend_device_idx].temperature_get_supported = false;
return -1;
}
return (int) temperature;
}
}
#else
if ((backend_ctx->devices_param[backend_device_idx].opencl_device_type & CL_DEVICE_TYPE_GPU) == 0) return -1;
#endif
if (backend_ctx->devices_param[backend_device_idx].opencl_device_vendor_id == VENDOR_ID_AMD)
{
@ -386,6 +418,25 @@ int hm_get_fanpolicy_with_devices_idx (hashcat_ctx_t *hashcat_ctx, const int bac
return -1;
}
#if defined(__APPLE__)
int hm_get_fanspeed_apple (hashcat_ctx_t *hashcat_ctx, char *fan_speed_buf)
{
hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx;
if (hwmon_ctx->enabled == false) return -1;
if (hwmon_ctx->hm_iokit)
{
if (hm_IOKIT_get_fan_speed_current (hashcat_ctx, fan_speed_buf) == 0)
{
return 1;
}
}
return -1;
}
#endif
int hm_get_fanspeed_with_devices_idx (hashcat_ctx_t *hashcat_ctx, const int backend_device_idx)
{
hwmon_ctx_t *hwmon_ctx = hashcat_ctx->hwmon_ctx;
@ -987,6 +1038,7 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx)
hm_attrs_t *hm_adapters_nvapi = (hm_attrs_t *) hccalloc (DEVICES_MAX, sizeof (hm_attrs_t));
hm_attrs_t *hm_adapters_nvml = (hm_attrs_t *) hccalloc (DEVICES_MAX, sizeof (hm_attrs_t));
hm_attrs_t *hm_adapters_sysfs = (hm_attrs_t *) hccalloc (DEVICES_MAX, sizeof (hm_attrs_t));
hm_attrs_t *hm_adapters_iokit = (hm_attrs_t *) hccalloc (DEVICES_MAX, sizeof (hm_attrs_t));
#define FREE_ADAPTERS \
do { \
@ -994,6 +1046,7 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx)
hcfree (hm_adapters_nvapi); \
hcfree (hm_adapters_nvml); \
hcfree (hm_adapters_sysfs); \
hcfree (hm_adapters_iokit); \
} while (0)
if (backend_ctx->need_nvml == true)
@ -1053,6 +1106,20 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx)
}
}
#if defined(__APPLE__)
if (backend_ctx->need_iokit == true)
{
hwmon_ctx->hm_iokit = (IOKIT_PTR *) hcmalloc (sizeof (IOKIT_PTR));
if (iokit_init (hashcat_ctx) == false)
{
hcfree (hwmon_ctx->hm_iokit);
hwmon_ctx->hm_iokit = NULL;
}
}
#endif
if (hwmon_ctx->hm_nvml)
{
if (hm_NVML_nvmlInit (hashcat_ctx) == 0)
@ -1283,7 +1350,7 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx)
}
}
if (hwmon_ctx->hm_sysfs)
if (hwmon_ctx->hm_sysfs || hwmon_ctx->hm_iokit)
{
if (true)
{
@ -1291,6 +1358,8 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx)
{
hc_device_param_t *device_param = &backend_ctx->devices_param[backend_devices_idx];
if (device_param->skipped == true) continue;
if (device_param->is_cuda == true)
{
// nothing to do
@ -1300,21 +1369,50 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx)
{
const u32 device_id = device_param->device_id;
if ((device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE) && (hwmon_ctx->hm_iokit))
{
hm_adapters_iokit[device_id].buslanes_get_supported = false;
hm_adapters_iokit[device_id].corespeed_get_supported = false;
hm_adapters_iokit[device_id].fanspeed_get_supported = true;
hm_adapters_iokit[device_id].fanpolicy_get_supported = false;
hm_adapters_iokit[device_id].memoryspeed_get_supported = false;
hm_adapters_iokit[device_id].temperature_get_supported = true;
hm_adapters_iokit[device_id].utilization_get_supported = false;
}
if ((device_param->opencl_device_type & CL_DEVICE_TYPE_GPU) == 0) continue;
hm_adapters_sysfs[device_id].buslanes_get_supported = true;
hm_adapters_sysfs[device_id].corespeed_get_supported = true;
hm_adapters_sysfs[device_id].fanspeed_get_supported = true;
hm_adapters_sysfs[device_id].fanpolicy_get_supported = true;
hm_adapters_sysfs[device_id].memoryspeed_get_supported = true;
hm_adapters_sysfs[device_id].temperature_get_supported = true;
hm_adapters_sysfs[device_id].utilization_get_supported = true;
if (hwmon_ctx->hm_sysfs)
{
hm_adapters_sysfs[device_id].buslanes_get_supported = true;
hm_adapters_sysfs[device_id].corespeed_get_supported = true;
hm_adapters_sysfs[device_id].fanspeed_get_supported = true;
hm_adapters_sysfs[device_id].fanpolicy_get_supported = true;
hm_adapters_sysfs[device_id].memoryspeed_get_supported = true;
hm_adapters_sysfs[device_id].temperature_get_supported = true;
hm_adapters_sysfs[device_id].utilization_get_supported = true;
}
}
}
}
}
if (hwmon_ctx->hm_adl == NULL && hwmon_ctx->hm_nvml == NULL && hwmon_ctx->hm_sysfs == NULL)
#if defined(__APPLE__)
if (backend_ctx->need_iokit == true)
{
hwmon_ctx->hm_iokit = (IOKIT_PTR *) hcmalloc (sizeof (IOKIT_PTR));
if (iokit_init (hashcat_ctx) == false)
{
hcfree (hwmon_ctx->hm_iokit);
hwmon_ctx->hm_iokit = NULL;
}
}
#endif
if (hwmon_ctx->hm_adl == NULL && hwmon_ctx->hm_nvml == NULL && hwmon_ctx->hm_sysfs == NULL && hwmon_ctx->hm_iokit == NULL)
{
FREE_ADAPTERS;
@ -1345,13 +1443,17 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx)
const u32 device_id = device_param->device_id;
hwmon_ctx->hm_device[backend_devices_idx].adl = 0;
hwmon_ctx->hm_device[backend_devices_idx].sysfs = 0;
hwmon_ctx->hm_device[backend_devices_idx].iokit = 0;
hwmon_ctx->hm_device[backend_devices_idx].nvapi = 0;
hwmon_ctx->hm_device[backend_devices_idx].nvml = 0;
hwmon_ctx->hm_device[backend_devices_idx].od_version = 0;
if (device_param->is_cuda == true)
{
hwmon_ctx->hm_device[backend_devices_idx].adl = 0;
hwmon_ctx->hm_device[backend_devices_idx].sysfs = 0;
hwmon_ctx->hm_device[backend_devices_idx].nvapi = hm_adapters_nvapi[device_id].nvapi;
hwmon_ctx->hm_device[backend_devices_idx].nvml = hm_adapters_nvml[device_id].nvml;
hwmon_ctx->hm_device[backend_devices_idx].od_version = 0;
if (hwmon_ctx->hm_nvml)
{
@ -1384,15 +1486,32 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx)
if (device_param->is_opencl == true)
{
#if defined(__APPLE__)
if (device_param->opencl_platform_vendor_id == VENDOR_ID_APPLE)
{
if (hwmon_ctx->hm_iokit)
{
hwmon_ctx->hm_device[backend_devices_idx].iokit = hm_adapters_iokit[device_id].iokit;
hwmon_ctx->hm_device[backend_devices_idx].buslanes_get_supported |= hm_adapters_iokit[device_id].buslanes_get_supported;
hwmon_ctx->hm_device[backend_devices_idx].corespeed_get_supported |= hm_adapters_iokit[device_id].corespeed_get_supported;
hwmon_ctx->hm_device[backend_devices_idx].fanspeed_get_supported |= hm_adapters_iokit[device_id].fanspeed_get_supported;
hwmon_ctx->hm_device[backend_devices_idx].fanpolicy_get_supported |= hm_adapters_iokit[device_id].fanpolicy_get_supported;
hwmon_ctx->hm_device[backend_devices_idx].memoryspeed_get_supported |= hm_adapters_iokit[device_id].memoryspeed_get_supported;
hwmon_ctx->hm_device[backend_devices_idx].temperature_get_supported |= hm_adapters_iokit[device_id].temperature_get_supported;
hwmon_ctx->hm_device[backend_devices_idx].threshold_shutdown_get_supported |= hm_adapters_iokit[device_id].threshold_shutdown_get_supported;
hwmon_ctx->hm_device[backend_devices_idx].threshold_slowdown_get_supported |= hm_adapters_iokit[device_id].threshold_slowdown_get_supported;
hwmon_ctx->hm_device[backend_devices_idx].throttle_get_supported |= hm_adapters_iokit[device_id].throttle_get_supported;
hwmon_ctx->hm_device[backend_devices_idx].utilization_get_supported |= hm_adapters_iokit[device_id].utilization_get_supported;
}
}
#else
if ((device_param->opencl_device_type & CL_DEVICE_TYPE_GPU) == 0) continue;
#endif
if (device_param->opencl_device_vendor_id == VENDOR_ID_AMD)
{
hwmon_ctx->hm_device[backend_devices_idx].adl = hm_adapters_adl[device_id].adl;
hwmon_ctx->hm_device[backend_devices_idx].sysfs = hm_adapters_sysfs[device_id].sysfs; // not used
hwmon_ctx->hm_device[backend_devices_idx].nvapi = 0;
hwmon_ctx->hm_device[backend_devices_idx].nvml = 0;
hwmon_ctx->hm_device[backend_devices_idx].od_version = 0;
hwmon_ctx->hm_device[backend_devices_idx].sysfs = hm_adapters_sysfs[device_id].sysfs;
if (hwmon_ctx->hm_adl)
{
@ -1427,11 +1546,8 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx)
if (device_param->opencl_device_vendor_id == VENDOR_ID_NV)
{
hwmon_ctx->hm_device[backend_devices_idx].adl = 0;
hwmon_ctx->hm_device[backend_devices_idx].sysfs = 0;
hwmon_ctx->hm_device[backend_devices_idx].nvapi = hm_adapters_nvapi[device_id].nvapi;
hwmon_ctx->hm_device[backend_devices_idx].nvml = hm_adapters_nvml[device_id].nvml;
hwmon_ctx->hm_device[backend_devices_idx].od_version = 0;
if (hwmon_ctx->hm_nvml)
{
@ -1517,6 +1633,13 @@ void hwmon_ctx_destroy (hashcat_ctx_t *hashcat_ctx)
sysfs_close (hashcat_ctx);
}
#if defined (__APPLE__)
if (hwmon_ctx->hm_iokit)
{
iokit_close (hashcat_ctx);
}
#endif
// free memory
hcfree (hwmon_ctx->od_clock_mem_status);

View File

@ -130,6 +130,20 @@ static int monitor (hashcat_ctx_t *hashcat_ctx)
myabort (hashcat_ctx);
}
#if defined (__APPLE__)
// experimental feature, check the "Sensor Graphic Hot" sensor through IOKIT/SMC to catch a GPU overtemp alarm
else if (temperature > (int) (user_options->hwmon_temp_abort - 10))
{
if (hm_IOKIT_SMCGetSensorGraphicHot (hashcat_ctx) == 1)
{
event_log_error (hashcat_ctx, "hm_IOKIT_SMCGetSensorGraphicHot(): Sensor Graphics HoT, GPU Overtemp");
EVENT_DATA (EVENT_MONITOR_TEMP_ABORT, &backend_devices_idx, sizeof (int));
myabort (hashcat_ctx);
}
}
#endif
}
for (int backend_devices_idx = 0; backend_devices_idx < backend_ctx->backend_devices_cnt; backend_devices_idx++)

View File

@ -1974,6 +1974,23 @@ char *status_get_brain_link_send_bytes_sec_dev (const hashcat_ctx_t *hashcat_ctx
}
#endif
#if defined(__APPLE__)
char *status_get_hwmon_fan_dev (const hashcat_ctx_t *hashcat_ctx)
{
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
char *fanspeed_str = (char *) hcmalloc (HCBUFSIZ_TINY);
hc_thread_mutex_lock (status_ctx->mux_hwmon);
hm_get_fanspeed_apple ((hashcat_ctx_t *) hashcat_ctx, fanspeed_str);
hc_thread_mutex_unlock (status_ctx->mux_hwmon);
return fanspeed_str;
}
#endif
char *status_get_hwmon_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)
{
const backend_ctx_t *backend_ctx = hashcat_ctx->backend_ctx;

View File

@ -1814,6 +1814,10 @@ void status_display (hashcat_ctx_t *hashcat_ctx)
if (hwmon_ctx->enabled == true)
{
#if defined(__APPLE__)
bool first_dev = true;
#endif
for (int device_id = 0; device_id < hashcat_status->device_info_cnt; device_id++)
{
const device_info_t *device_info = hashcat_status->device_info_buf + device_id;
@ -1824,6 +1828,14 @@ void status_display (hashcat_ctx_t *hashcat_ctx)
if (device_info->hwmon_dev == NULL) continue;
#if defined(__APPLE__)
if (first_dev && strlen (device_info->hwmon_fan_dev) > 0)
{
event_log_info (hashcat_ctx, "Hardware.Mon.SMC.: %s", device_info->hwmon_fan_dev);
first_dev = false;
}
#endif
event_log_info (hashcat_ctx,
"Hardware.Mon.#%d..: %s", device_id + 1,
device_info->hwmon_dev);