From b0c6eee06c2bf3aba2752c3aca1c52e790c3116b Mon Sep 17 00:00:00 2001
From: Gabriele 'matrix' Gristina <gm4tr1x@users.noreply.github.com>
Date: Tue, 6 Sep 2016 22:25:54 +0200
Subject: [PATCH] Fix multiple build issues with OSX

---
 include/folder.h   |  9 ++++++---
 include/shared.h   |  2 ++
 include/terminal.h |  7 ++++++-
 include/types.h    |  5 ++++-
 src/folder.c       | 11 +++++++++++
 src/hashcat.c      |  9 ++++++++-
 src/hwmon.c        |  8 +++++++-
 src/interface.c    | 10 ++++++++--
 src/logfile.c      |  8 +++++++-
 src/logging.c      |  8 +++++++-
 src/mpsp.c         |  8 +++++++-
 src/shared.c       |  4 ++++
 12 files changed, 77 insertions(+), 12 deletions(-)

diff --git a/include/folder.h b/include/folder.h
index 79aef6fba..f1b723a2f 100644
--- a/include/folder.h
+++ b/include/folder.h
@@ -1,16 +1,19 @@
 /**
  * Authors.....: Jens Steube <jens.steube@gmail.com>
+ *               Gabriele Gristina <matrix@hashcat.net>
+ *
  * License.....: MIT
  */
 
-#pragma once
-
 #include <stdio.h>
 #include <unistd.h>
 
 #ifdef _POSIX
 #include <sys/types.h>
-#endif
+#ifdef __APPLE__
+#include <mach-o/dyld.h>
+#endif // __APPLE__
+#endif // _POSIX
 
 #ifdef _WIN
 #include <windows.h>
diff --git a/include/shared.h b/include/shared.h
index d972d65ff..d617b6f3d 100644
--- a/include/shared.h
+++ b/include/shared.h
@@ -27,7 +27,9 @@
 #include <limits.h>
 #include <sys/types.h>
 #include <sys/ioctl.h>
+#ifndef __APPLE__
 #include <sys/sysctl.h>
+#endif // __APPLE__
 #endif // _POSIX
 
 #ifdef __APPLE__
diff --git a/include/terminal.h b/include/terminal.h
index 7a6f3dac2..2cd0a1cf2 100644
--- a/include/terminal.h
+++ b/include/terminal.h
@@ -1,5 +1,7 @@
 /**
- * Author......: Jens Steube <jens.steube@gmail.com>
+ * Authors.....: Jens Steube <jens.steube@gmail.com>
+ *               Gabriele Gristina <matrix@hashcat.net>
+ *
  * License.....: MIT
  */
 
@@ -13,6 +15,9 @@
 
 #ifdef _POSIX
 #include <termios.h>
+#ifdef __APPLE__
+#include <sys/ioctl.h>
+#endif // __APPLE__
 #endif // _POSIX
 
 #ifdef _WIN
diff --git a/include/types.h b/include/types.h
index b0f2a5103..9bb0f83fe 100644
--- a/include/types.h
+++ b/include/types.h
@@ -1,5 +1,7 @@
 /**
- * Author......: Jens Steube <jens.steube@gmail.com>
+ * Authors.....: Jens Steube <jens.steube@gmail.com>
+ *               Gabriele Gristina <matrix@hashcat.net>
+ *
  * License.....: MIT
  */
 
@@ -9,6 +11,7 @@
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <string.h>
 
 #ifdef _WIN
 #define EOL "\r\n"
diff --git a/src/folder.c b/src/folder.c
index e4c1e7518..933ccf9a8 100644
--- a/src/folder.c
+++ b/src/folder.c
@@ -1,12 +1,23 @@
 /**
  * Authors.....: Jens Steube <jens.steube@gmail.com>
+ *               Gabriele Gristina <matrix@hashcat.net>
+ *
  * License.....: MIT
  */
 
+#ifdef __APPLE__
+#include <stdio.h>
+#endif
+
 #include "common.h"
 #include "memory.h"
 #include "folder.h"
 
+#ifdef __APPLE__
+#include "types_int.h"
+#include "logging.h"
+#endif
+
 char *get_exec_path ()
 {
   int exec_path_len = 1024;
diff --git a/src/hashcat.c b/src/hashcat.c
index c2cfc79a3..dc5a8fc3f 100644
--- a/src/hashcat.c
+++ b/src/hashcat.c
@@ -6,6 +6,11 @@
  * License.....: MIT
  */
 
+#ifdef __APPLE__
+#include <stdio.h>
+#include <string.h>
+#endif
+
 #include "common.h"
 #include "types_int.h"
 #include "types.h"
@@ -14101,9 +14106,11 @@ int main (int argc, char **argv)
      */
 
     int need_adl     = 0;
-    int need_nvapi   = 0;
     int need_nvml    = 0;
+    #ifndef __APPLE__
+    int need_nvapi   = 0;
     int need_xnvctrl = 0;
+    #endif
 
     hc_device_param_t *devices_param = (hc_device_param_t *) mycalloc (DEVICES_MAX, sizeof (hc_device_param_t));
 
diff --git a/src/hwmon.c b/src/hwmon.c
index de1fb51f1..4fe4587bf 100644
--- a/src/hwmon.c
+++ b/src/hwmon.c
@@ -1,5 +1,7 @@
 /**
- * Author......: Jens Steube <jens.steube@gmail.com>
+ * Authors.....: Jens Steube <jens.steube@gmail.com>
+ *               Gabriele Gristina <matrix@hashcat.net>
+ *
  * License.....: MIT
  */
 
@@ -19,6 +21,8 @@
 #include "rp_cpu.h"
 #include "data.h"
 
+#ifdef HAVE_HWMON
+
 extern hc_global_data_t data;
 
 int get_adapters_num_adl (void *adl, int *iNumberAdapters)
@@ -858,3 +862,5 @@ int hm_set_fanspeed_with_device_id_xnvctrl (const uint device_id, const int fans
 
   return -1;
 }
+
+#endif // HAVE_HWMON
diff --git a/src/interface.c b/src/interface.c
index 93b8571be..1c76ca549 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -1,8 +1,14 @@
 /**
  * Authors.....: Jens Steube <jens.steube@gmail.com>
+ *               Gabriele Gristina <matrix@hashcat.net>
+ *
  * License.....: MIT
  */
 
+#ifdef __APPLE__
+#include <stdio.h>
+#endif
+
 #include "common.h"
 #include "types_int.h"
 #include "types.h"
@@ -49,7 +55,7 @@ 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_255[] = "Unknown error";
 
 static const char HT_00000[] = "MD5";
@@ -328,7 +334,7 @@ static const char SIGNATURE_SIP_AUTH[]        = "$sip$*";
 static const char SIGNATURE_SSHA1B64_lower[]  = "{ssha}";
 static const char SIGNATURE_SSHA1B64_upper[]  = "{SSHA}";
 static const char SIGNATURE_SYBASEASE[]       = "0xc007";
-static const char SIGNATURE_TRUECRYPT[]       = "TRUE";
+//static const char SIGNATURE_TRUECRYPT[]       = "TRUE";
 static const char SIGNATURE_ZIP2_START[]      = "$zip2$";
 static const char SIGNATURE_ZIP2_STOP[]       = "$/zip2$";
 
diff --git a/src/logfile.c b/src/logfile.c
index 8dd527932..bd881ce53 100644
--- a/src/logfile.c
+++ b/src/logfile.c
@@ -1,8 +1,14 @@
 /**
- * Author......: Jens Steube <jens.steube@gmail.com>
+ * Authors.....: Jens Steube <jens.steube@gmail.com>
+ *               Gabriele Gristina <matrix@hashcat.net>
+ *
  * License.....: MIT
  */
 
+#ifdef __APPLE__
+#include <stdio.h>
+#endif
+
 #include "common.h"
 #include "types_int.h"
 #include "types.h"
diff --git a/src/logging.c b/src/logging.c
index 6d9ac7c69..0c4382303 100644
--- a/src/logging.c
+++ b/src/logging.c
@@ -1,8 +1,14 @@
 /**
- * Author......: Jens Steube <jens.steube@gmail.com>
+ * Authors.....: Jens Steube <jens.steube@gmail.com>
+ *               Gabriele Gristina <matrix@hashcat.net>
+ *
  * License.....: MIT
  */
 
+#ifdef __APPLE__
+#include <stdio.h>
+#endif
+
 #include "common.h"
 #include "logging.h"
 
diff --git a/src/mpsp.c b/src/mpsp.c
index 3ded0f002..fa19aff5c 100644
--- a/src/mpsp.c
+++ b/src/mpsp.c
@@ -1,8 +1,14 @@
 /**
- * Author......: Jens Steube <jens.steube@gmail.com>
+ * Authors.....: Jens Steube <jens.steube@gmail.com>
+ *               Gabriele Gristina <matrix@hashcat.net>
+ *
  * License.....: MIT
  */
 
+#ifdef __APPLE__
+#include <stdio.h>
+#endif
+
 #include "common.h"
 #include "types_int.h"
 #include "types.h"
diff --git a/src/shared.c b/src/shared.c
index a96f02b72..3ce097820 100644
--- a/src/shared.c
+++ b/src/shared.c
@@ -6,6 +6,10 @@
  * License.....: MIT
  */
 
+#ifdef __APPLE__
+#include <stdio.h>
+#endif
+
 #include "common.h"
 #include "types_int.h"
 #include "types.h"