Fixed a bug where hashcat did not take into account how long it takes to prepare...
[hashcat.git] / src / hashcat.c
index 9d4299e..e0d77ce 100644 (file)
@@ -1387,13 +1387,13 @@ void status_display ()
 
             #ifdef WIN
 
-            __time64_t runtime_left = data.proc_start + data.runtime - runtime_cur;
+            __time64_t runtime_left = data.proc_start + data.runtime + data.prepare_time - runtime_cur;
 
             tmp = _gmtime64 (&runtime_left);
 
             #else
 
-            time_t runtime_left = data.proc_start + data.runtime - runtime_cur;
+            time_t runtime_left = data.proc_start + data.runtime + data.prepare_time - runtime_cur;
 
             tmp = gmtime (&runtime_left);
 
@@ -4692,7 +4692,7 @@ static void *thread_monitor (void *p)
 
       time (&runtime_cur);
 
-      int runtime_left = data.proc_start + data.runtime - runtime_cur;
+      int runtime_left = data.proc_start + data.runtime + data.prepare_time - runtime_cur;
 
       if (runtime_left <= 0)
       {
@@ -6175,6 +6175,10 @@ int main (int argc, char **argv)
 
   data.proc_start = proc_start;
 
+  time_t prepare_start;
+
+  time (&prepare_start);
+
   int    myargc = argc;
   char **myargv = argv;
 
@@ -6563,6 +6567,66 @@ int main (int argc, char **argv)
 
   myfree (exec_path);
 
+  /**
+   * There's alot of problem related to bad support -I parameters when building the kernel.
+   * Each OpenCL runtime handles it slightly different.
+   * The most problematic is with new AMD drivers on Windows, which can not handle quote characters!
+   * The best workaround found so far is to modify the TMP variable (only inside hashcat process) before the runtime is load
+   */
+
+  char cpath[1024] = { 0 };
+
+  #if _WIN
+
+  snprintf (cpath, sizeof (cpath) - 1, "%s\\OpenCL\\", shared_dir);
+
+  char *cpath_real = mymalloc (MAX_PATH);
+
+  if (GetFullPathName (cpath, MAX_PATH, cpath_real, NULL) == 0)
+  {
+    log_error ("ERROR: %s: %s", cpath, "GetFullPathName()");
+
+    return -1;
+  }
+
+  #else
+
+  snprintf (cpath, sizeof (cpath) - 1, "%s/OpenCL/", shared_dir);
+
+  char *cpath_real = mymalloc (PATH_MAX);
+
+  if (realpath (cpath, cpath_real) == NULL)
+  {
+    log_error ("ERROR: %s: %s", cpath, strerror (errno));
+
+    return -1;
+  }
+
+  #endif
+
+  //if (getenv ("TMP") == NULL)
+  if (1)
+  {
+    char tmp[1000];
+
+    snprintf (tmp, sizeof (tmp) - 1, "TMP=%s", cpath_real);
+
+    putenv (tmp);
+  }
+
+  #if _WIN
+
+  naive_replace (cpath_real, '\\', '/');
+
+  // not escaping here, windows using quotes later
+  // naive_escape (cpath_real, PATH_MAX,  ' ', '\\');
+
+  #else
+
+  naive_escape (cpath_real, PATH_MAX,  ' ', '\\');
+
+  #endif
+
   /**
    * kernel cache, we need to make sure folder exist
    */
@@ -16090,46 +16154,19 @@ int main (int argc, char **argv)
        * default building options
        */
 
-      char cpath[1024] = { 0 };
-
-      char build_opts[1024] = { 0 };
-
-      #if _WIN
-
-      snprintf (cpath, sizeof (cpath) - 1, "%s\\OpenCL\\", shared_dir);
-
-      char *cpath_real = mymalloc (MAX_PATH);
-
-      if (GetFullPathName (cpath, MAX_PATH, cpath_real, NULL) == 0)
+      if (chdir (cpath_real) == -1)
       {
-        log_error ("ERROR: %s: %s", cpath, "GetFullPathName()");
+        log_error ("ERROR: %s: %s", cpath_real, strerror (errno));
 
         return -1;
       }
 
-      naive_replace (cpath_real, '\\', '/');
-
-      // not escaping here, windows has quotes
+      char build_opts[1024] = { 0 };
 
+      #if _WIN
       snprintf (build_opts, sizeof (build_opts) - 1, "-I \"%s\"", cpath_real);
-
       #else
-
-      snprintf (cpath, sizeof (cpath) - 1, "%s/OpenCL/", shared_dir);
-
-      char *cpath_real = mymalloc (PATH_MAX);
-
-      if (realpath (cpath, cpath_real) == NULL)
-      {
-        log_error ("ERROR: %s: %s", cpath, strerror (errno));
-
-        return -1;
-      }
-
-      naive_escape (cpath_real, PATH_MAX,  ' ', '\\');
-
       snprintf (build_opts, sizeof (build_opts) - 1, "-I %s", cpath_real);
-
       #endif
 
       // include check
@@ -16157,13 +16194,6 @@ int main (int argc, char **argv)
         "inc_vendor.cl",
       };
 
-      if (chdir (cpath_real) == -1)
-      {
-        log_error ("ERROR: %s: %s", cpath_real, strerror (errno));
-
-        return -1;
-      }
-
       for (int i = 0; i < files_cnt; i++)
       {
         FILE *fd = fopen (files_names[i], "r");
@@ -16189,8 +16219,6 @@ int main (int argc, char **argv)
         fclose (fd);
       }
 
-      myfree (cpath_real);
-
       // we don't have sm_* on vendors not NV but it doesn't matter
 
       char build_opts_new[1024] = { 0 };
@@ -19412,6 +19440,8 @@ int main (int argc, char **argv)
 
         data.runtime_start = runtime_start;
 
+        data.prepare_time += runtime_start - prepare_start;
+
         for (uint device_id = 0; device_id < data.devices_cnt; device_id++)
         {
           hc_device_param_t *device_param = &devices_param[device_id];
@@ -19501,6 +19531,8 @@ int main (int argc, char **argv)
         logfile_sub_uint (runtime_start);
         logfile_sub_uint (runtime_stop);
 
+        time (&prepare_start);
+
         logfile_sub_msg ("STOP");
 
         global_free (subid);