Set fanspeed to automatic on shutdown
[hashcat.git] / src / shared.c
index 292e886..d78b27c 100644 (file)
@@ -3402,11 +3402,17 @@ int hm_get_throttle_with_device_id (const uint device_id)
     if (hm_NVML_nvmlDeviceGetCurrentClocksThrottleReasons   (data.hm_nvml, 1, data.hm_device[device_id].nvml, &clocksThrottleReasons)    != NVML_SUCCESS) return -1;
     if (hm_NVML_nvmlDeviceGetSupportedClocksThrottleReasons (data.hm_nvml, 1, data.hm_device[device_id].nvml, &supportedThrottleReasons) != NVML_SUCCESS) return -1;
 
-    clocksThrottleReasons &= supportedThrottleReasons;
-
+    clocksThrottleReasons &=  supportedThrottleReasons;
+    clocksThrottleReasons &= ~nvmlClocksThrottleReasonGpuIdle;
+    clocksThrottleReasons &= ~nvmlClocksThrottleReasonApplicationsClocksSetting;
     clocksThrottleReasons &= ~nvmlClocksThrottleReasonUnknown;
 
-    return (clocksThrottleReasons > 0);
+    if (data.kernel_power_final)
+    {
+      clocksThrottleReasons &= ~nvmlClocksThrottleReasonHwSlowdown;
+    }
+
+    return (clocksThrottleReasons != nvmlClocksThrottleReasonNone);
   }
 
   return -1;
@@ -3418,33 +3424,51 @@ int hm_set_fanspeed_with_device_id_adl (const uint device_id, const int fanspeed
   {
     if (data.hm_adl)
     {
-      if (data.hm_device[device_id].od_version == 5)
+      if (fanpolicy == 1)
       {
-        ADLFanSpeedValue lpFanSpeedValue;
+        if (data.hm_device[device_id].od_version == 5)
+        {
+          ADLFanSpeedValue lpFanSpeedValue;
 
-        memset (&lpFanSpeedValue, 0, sizeof (lpFanSpeedValue));
+          memset (&lpFanSpeedValue, 0, sizeof (lpFanSpeedValue));
 
-        lpFanSpeedValue.iSize      = sizeof (lpFanSpeedValue);
-        lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
-        lpFanSpeedValue.iFlags     = (fanpolicy == 1) ? ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED : 0;
-        lpFanSpeedValue.iFanSpeed  = fanspeed;
+          lpFanSpeedValue.iSize      = sizeof (lpFanSpeedValue);
+          lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
+          lpFanSpeedValue.iFlags     = ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED;
+          lpFanSpeedValue.iFanSpeed  = fanspeed;
 
-        if (hm_ADL_Overdrive5_FanSpeed_Set (data.hm_adl, data.hm_device[device_id].adl, 0, &lpFanSpeedValue) != ADL_OK) return -1;
+          if (hm_ADL_Overdrive5_FanSpeed_Set (data.hm_adl, data.hm_device[device_id].adl, 0, &lpFanSpeedValue) != ADL_OK) return -1;
 
-        return 0;
-      }
-      else // od_version == 6
-      {
-        ADLOD6FanSpeedValue fan_speed_value;
+          return 0;
+        }
+        else // od_version == 6
+        {
+          ADLOD6FanSpeedValue fan_speed_value;
 
-        memset (&fan_speed_value, 0, sizeof (fan_speed_value));
+          memset (&fan_speed_value, 0, sizeof (fan_speed_value));
 
-        fan_speed_value.iSpeedType = ADL_OD6_FANSPEED_TYPE_PERCENT;
-        fan_speed_value.iFanSpeed  = fanspeed;
+          fan_speed_value.iSpeedType = ADL_OD6_FANSPEED_TYPE_PERCENT;
+          fan_speed_value.iFanSpeed  = fanspeed;
 
-        if (hm_ADL_Overdrive6_FanSpeed_Set (data.hm_adl, data.hm_device[device_id].adl, &fan_speed_value) != ADL_OK) return -1;
+          if (hm_ADL_Overdrive6_FanSpeed_Set (data.hm_adl, data.hm_device[device_id].adl, &fan_speed_value) != ADL_OK) return -1;
 
-        return 0;
+          return 0;
+        }
+      }
+      else
+      {
+        if (data.hm_device[device_id].od_version == 5)
+        {
+          if (hm_ADL_Overdrive5_FanSpeedToDefault_Set (data.hm_adl, data.hm_device[device_id].adl, 0) != ADL_OK) return -1;
+
+          return 0;
+        }
+        else // od_version == 6
+        {
+          if (hm_ADL_Overdrive6_FanSpeed_Reset (data.hm_adl, data.hm_device[device_id].adl) != ADL_OK) return -1;
+
+          return 0;
+        }
       }
     }
   }
@@ -9206,20 +9230,62 @@ void stop_at_checkpoint ()
 
 void myabort ()
 {
-  if (data.devices_status == STATUS_INIT)     return;
-  if (data.devices_status == STATUS_STARTING) return;
+  //if (data.devices_status == STATUS_INIT)     return;
+  //if (data.devices_status == STATUS_STARTING) return;
 
   data.devices_status = STATUS_ABORTED;
 }
 
 void myquit ()
 {
-  if (data.devices_status == STATUS_INIT)     return;
-  if (data.devices_status == STATUS_STARTING) return;
+  //if (data.devices_status == STATUS_INIT)     return;
+  //if (data.devices_status == STATUS_STARTING) return;
 
   data.devices_status = STATUS_QUIT;
 }
 
+void naive_replace (char *s, const u8 key_char, const u8 replace_char)
+{
+  const size_t len = strlen (s);
+
+  for (size_t in = 0; in < len; in++)
+  {
+    const u8 c = s[in];
+
+    if (c == key_char)
+    {
+      s[in] = replace_char;
+    }
+  }
+}
+
+void naive_escape (char *s, size_t s_max, const u8 key_char, const u8 escape_char)
+{
+  char s_escaped[1024] = { 0 };
+
+  size_t s_escaped_max = sizeof (s_escaped);
+
+  const size_t len = strlen (s);
+
+  for (size_t in = 0, out = 0; in < len; in++, out++)
+  {
+    const u8 c = s[in];
+
+    if (c == key_char)
+    {
+      s_escaped[out] = escape_char;
+
+      out++;
+    }
+
+    if (out == s_escaped_max - 2) break;
+
+    s_escaped[out] = c;
+  }
+
+  strncpy (s, s_escaped, s_max - 1);
+}
+
 void load_kernel (const char *kernel_file, int num_devices, size_t *kernel_lengths, const u8 **kernel_sources)
 {
   FILE *fp = fopen (kernel_file, "rb");
@@ -20727,8 +20793,6 @@ void status_display ();
 
 void *thread_keypress (void *p)
 {
-  int benchmark = *((int *) p);
-
   uint quiet = data.quiet;
 
   tty_break();
@@ -20810,8 +20874,6 @@ void *thread_keypress (void *p)
 
         log_info ("");
 
-        if (benchmark == 1) break;
-
         stop_at_checkpoint ();
 
         log_info ("");
@@ -20825,14 +20887,7 @@ void *thread_keypress (void *p)
 
         log_info ("");
 
-        if (benchmark == 1)
-        {
-          myquit ();
-        }
-        else
-        {
-          myabort ();
-        }
+        myabort ();
 
         break;
     }