diff --git a/include/common.h b/include/common.h index 7f3cf270b..ff9cd4a60 100644 --- a/include/common.h +++ b/include/common.h @@ -52,6 +52,11 @@ #include #endif +#ifdef __FreeBSD__ +#include +#include +#endif + typedef void *OCL_LIB; #ifdef HAVE_HWMON diff --git a/include/ext_OpenCL.h b/include/ext_OpenCL.h index 4ffd56b5c..ae0728592 100644 --- a/include/ext_OpenCL.h +++ b/include/ext_OpenCL.h @@ -27,6 +27,10 @@ // #include // used for CL_DEVICE_TOPOLOGY_AMD but broken for dual GPU #endif +#ifdef __FreeBSD__ +#include +#endif + #include typedef cl_mem (CL_API_CALL *OCL_CLCREATEBUFFER) (cl_context, cl_mem_flags, size_t, void *, cl_int *); diff --git a/src/Makefile b/src/Makefile index cf445900f..b6730b847 100644 --- a/src/Makefile +++ b/src/Makefile @@ -17,7 +17,7 @@ UNAME := $(shell uname -s) # we need to strip the windows version number to be able to build hashcat on cygwin hosts UNAME := $(patsubst CYGWIN_NT-%,CYGWIN_NT-,$(UNAME)) -ifeq (,$(filter $(UNAME),Linux Darwin CYGWIN_NT-)) +ifeq (,$(filter $(UNAME),Linux Darwin CYGWIN_NT- FreeBSD)) $(error "! Your Operating System ($(UNAME)) is not supported by $(PROG_NAME) Makefile") endif @@ -66,6 +66,10 @@ SED := sed ifeq ($(UNAME),Darwin) SED := gsed endif +ifeq ($(UNAME),FreeBSD) +CC := cc +SED := gsed +endif ## ## Cross compiler paths @@ -126,6 +130,13 @@ CFLAGS_NATIVE += -DHAVE_HWMON LFLAGS_NATIVE += $(LDFLAGS) endif # linux +ifeq ($(UNAME),FreeBSD) +CFLAGS_NATIVE := -D_POSIX +CFLAGS_NATIVE += $(CFLAGS) +LFLAGS_NATIVE := -lpthread +LFLAGS_NATIVE += $(LDFLAGS) +endif # freebsd + ## ## Cross compilation target ## diff --git a/src/hashcat.c b/src/hashcat.c index 67714d15d..ca691a979 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -6,7 +6,7 @@ * License.....: MIT */ -#ifdef DARWIN +#if defined(DARWIN) || defined(__FreeBSD__) #include #endif @@ -6171,7 +6171,8 @@ int main (int argc, char **argv) char *exec_path = get_exec_path (); - #if defined(LINUX) || defined(__APPLE__) + + #if defined(LINUX) || defined(__APPLE__) || defined(__FreeBSD__) char *resolved_install_folder = realpath (INSTALL_FOLDER, NULL); char *resolved_exec_path = realpath (exec_path, NULL); @@ -13017,6 +13018,7 @@ int main (int argc, char **argv) // here we have in line_buf: ESSID:MAC1:MAC2 (without the plain) // manipulate salt_buf + memset (line_buf_cpy, 0, HCBUFSIZ); memcpy (line_buf_cpy, line_buf, i); char *mac2_pos = strrchr (line_buf_cpy, ':'); diff --git a/src/shared.c b/src/shared.c index df14f43ab..e7d5dc399 100644 --- a/src/shared.c +++ b/src/shared.c @@ -10,6 +10,11 @@ #include #endif +#ifdef __FreeBSD__ +#include +#include +#endif + #include #include @@ -2382,7 +2387,7 @@ int tty_fix() } #endif -#ifdef DARWIN +#if defined(DARWIN) || defined(__FreeBSD__) static struct termios savemodes; static int havemodes = 0; @@ -4371,6 +4376,23 @@ char *get_exec_path () const int len = strlen (exec_path); + #elif __FreeBSD__ + + #include + + int mib[4]; + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_PATHNAME; + mib[3] = -1; + + char tmp[32] = { 0 }; + + size_t size = exec_path_len; + sysctl(mib, 4, exec_path, &size, NULL, 0); + + const int len = readlink (tmp, exec_path, exec_path_len - 1); + #else #error Your Operating System is not supported or detected #endif @@ -4523,6 +4545,9 @@ void set_cpu_affinity (char *cpu_affinity) { #ifdef _WIN DWORD_PTR aff_mask = 0; + #elif __FreeBSD__ + cpuset_t cpuset; + CPU_ZERO (&cpuset); #elif _POSIX cpu_set_t cpuset; CPU_ZERO (&cpuset); @@ -4570,6 +4595,9 @@ void set_cpu_affinity (char *cpu_affinity) #ifdef _WIN SetProcessAffinityMask (GetCurrentProcess (), aff_mask); SetThreadAffinityMask (GetCurrentThread (), aff_mask); + #elif __FreeBSD__ + pthread_t thread = pthread_self (); + pthread_setaffinity_np (thread, sizeof (cpuset_t), &cpuset); #elif _POSIX pthread_t thread = pthread_self (); pthread_setaffinity_np (thread, sizeof (cpu_set_t), &cpuset);