diff --git a/include/ext_iokit.h b/include/ext_iokit.h index b01146b57..089c30240 100644 --- a/include/ext_iokit.h +++ b/include/ext_iokit.h @@ -18,6 +18,7 @@ #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" @@ -119,7 +120,7 @@ kern_return_t hm_IOKIT_SMCReadKey (UInt32Char_t key, SMCVal_t *val, io_connect_t 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, int *fan_speed); +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__ diff --git a/include/hwmon.h b/include/hwmon.h index 7976cd9ac..c758c60ba 100644 --- a/include/hwmon.h +++ b/include/hwmon.h @@ -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); diff --git a/include/status.h b/include/status.h index 5b0bae311..adf16ddf4 100644 --- a/include/status.h +++ b/include/status.h @@ -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); diff --git a/include/types.h b/include/types.h index d85efcb43..05ed728a8 100644 --- a/include/types.h +++ b/include/types.h @@ -2251,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; diff --git a/src/ext_iokit.c b/src/ext_iokit.c index a8a6debce..19ec6c3a6 100644 --- a/src/ext_iokit.c +++ b/src/ext_iokit.c @@ -202,6 +202,13 @@ bool hm_IOKIT_SMCGetFanRPM (char *key, io_connect_t conn, float *ret) { 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 @@ -218,10 +225,8 @@ bool hm_IOKIT_SMCGetFanRPM (char *key, io_connect_t conn, float *ret) return false; } -int hm_IOKIT_get_fan_speed_current (void *hashcat_ctx, int *fan_speed) +int hm_IOKIT_get_fan_speed_current (void *hashcat_ctx, char *fan_speed_buf) { - *fan_speed = 0; - hwmon_ctx_t *hwmon_ctx = ((hashcat_ctx_t *) hashcat_ctx)->hwmon_ctx; IOKIT_PTR *iokit = hwmon_ctx->hm_iokit; @@ -236,8 +241,13 @@ int hm_IOKIT_get_fan_speed_current (void *hashcat_ctx, int *fan_speed) { 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; @@ -251,10 +261,16 @@ int hm_IOKIT_get_fan_speed_current (void *hashcat_ctx, int *fan_speed) hm_IOKIT_SMCGetFanRPM (key, iokit->conn, &maximum_speed); if (maximum_speed < 0.f) continue; - *fan_speed = (actual_speed / maximum_speed) * 100.f; + fan_speed = (actual_speed / maximum_speed) * 100.f; - break; + 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); + fan_speed_buf[out_len-2] = '\0'; } return 1; diff --git a/src/hashcat.c b/src/hashcat.c index 97ee1c725..2d1025c91 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -1806,6 +1806,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); diff --git a/src/hwmon.c b/src/hwmon.c index af9c7acfd..a38c74c27 100644 --- a/src/hwmon.c +++ b/src/hwmon.c @@ -418,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; @@ -446,26 +465,7 @@ int hm_get_fanspeed_with_devices_idx (hashcat_ctx_t *hashcat_ctx, const int back 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) - { - int speed = 0; - - if (hm_IOKIT_get_fan_speed_current (hashcat_ctx, &speed) == -1) - { - hwmon_ctx->hm_device[backend_device_idx].fanspeed_get_supported = false; - - return -1; - } - - return speed; - } - } - #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) { @@ -1117,13 +1117,6 @@ int hwmon_ctx_init (hashcat_ctx_t *hashcat_ctx) hwmon_ctx->hm_iokit = NULL; } - - if (hwmon_ctx->hm_adl) - { - hcfree (hwmon_ctx->hm_iokit); - - hwmon_ctx->hm_iokit = NULL; - } } #endif diff --git a/src/status.c b/src/status.c index 93d4404fe..c3aad4d2c 100644 --- a/src/status.c +++ b/src/status.c @@ -1959,6 +1959,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; diff --git a/src/terminal.c b/src/terminal.c index 848ef20dc..48ae37757 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -1781,6 +1781,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; @@ -1791,6 +1795,14 @@ void status_display (hashcat_ctx_t *hashcat_ctx) if (device_info->hwmon_dev == NULL) continue; + #if defined(__APPLE__) + if (first_dev && device_info->hwmon_fan_dev) + { + 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);