From 4a598af78c6997f8430a03153fabcfeb45a9ec66 Mon Sep 17 00:00:00 2001 From: Nikolai Lifanov Date: Tue, 5 Jul 2016 14:58:28 -0400 Subject: [PATCH 01/11] add FreeBSD Makefile target --- src/Makefile | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Makefile b/src/Makefile index cf445900f..a36bf348d 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 @@ -63,7 +63,7 @@ FIND := find INSTALL := install RM := rm SED := sed -ifeq ($(UNAME),Darwin) +ifeq ($(UNAME),Darwin,FreeBSD) SED := gsed endif @@ -126,6 +126,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 ## From 61efadb6843269e8274ac31f03358bcbbc894e2b Mon Sep 17 00:00:00 2001 From: Nikolai Lifanov Date: Tue, 5 Jul 2016 14:59:46 -0400 Subject: [PATCH 02/11] make native build play well with external build systems --- src/Makefile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Makefile b/src/Makefile index a36bf348d..15a205fb6 100644 --- a/src/Makefile +++ b/src/Makefile @@ -58,13 +58,14 @@ OPENCL_HEADERS_KHRONOS := deps/OpenCL-Headers ## Native compiler paths ## -CC := gcc -FIND := find -INSTALL := install -RM := rm -SED := sed +CC ?= gcc +FIND ?= find +INSTALL ?= install +RM ?= rm ifeq ($(UNAME),Darwin,FreeBSD) -SED := gsed +SED ?= gsed +else +SED ?= sed endif ## From dd66aba33fac8559404cc9c66fff261fb4b74a32 Mon Sep 17 00:00:00 2001 From: Nikolai Lifanov Date: Tue, 5 Jul 2016 15:09:40 -0400 Subject: [PATCH 03/11] Revert "make native build play well with external build systems" This reverts commit 61efadb6843269e8274ac31f03358bcbbc894e2b. --- src/Makefile | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Makefile b/src/Makefile index 15a205fb6..a36bf348d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -58,14 +58,13 @@ OPENCL_HEADERS_KHRONOS := deps/OpenCL-Headers ## Native compiler paths ## -CC ?= gcc -FIND ?= find -INSTALL ?= install -RM ?= rm +CC := gcc +FIND := find +INSTALL := install +RM := rm +SED := sed ifeq ($(UNAME),Darwin,FreeBSD) -SED ?= gsed -else -SED ?= sed +SED := gsed endif ## From a2663fb93a7ddfe045f4c9a761dcb21d17b7c26e Mon Sep 17 00:00:00 2001 From: Nikolai Lifanov Date: Tue, 5 Jul 2016 15:12:05 -0400 Subject: [PATCH 04/11] include the right cl.h on FreeBSD --- include/ext_OpenCL.h | 4 ++++ 1 file changed, 4 insertions(+) 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 *); From f1960ec73c074fb7d4d4c00ecbb3f418f1b972db Mon Sep 17 00:00:00 2001 From: Nikolai Lifanov Date: Tue, 5 Jul 2016 15:14:11 -0400 Subject: [PATCH 05/11] use native compiler on FreeBSD --- src/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index a36bf348d..b6730b847 100644 --- a/src/Makefile +++ b/src/Makefile @@ -63,7 +63,11 @@ FIND := find INSTALL := install RM := rm SED := sed -ifeq ($(UNAME),Darwin,FreeBSD) +ifeq ($(UNAME),Darwin) +SED := gsed +endif +ifeq ($(UNAME),FreeBSD) +CC := cc SED := gsed endif From 3d3d212595ff210fb7de20a935418b69015bb31e Mon Sep 17 00:00:00 2001 From: Nikolai Lifanov Date: Tue, 5 Jul 2016 15:16:24 -0400 Subject: [PATCH 06/11] FreeBSD also needs stdio.h --- src/shared.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared.c b/src/shared.c index 85d4435b5..30f1f811d 100644 --- a/src/shared.c +++ b/src/shared.c @@ -6,7 +6,7 @@ * License.....: MIT */ -#ifdef DARWIN +#if defined(DARWIN) || defined(__FreeBSD__) #include #endif From 883bc202db41392700622bb2b70e79686c851005 Mon Sep 17 00:00:00 2001 From: Nikolai Lifanov Date: Tue, 5 Jul 2016 15:43:03 -0400 Subject: [PATCH 07/11] implement get_exec_path for FreeBSD --- src/shared.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/shared.c b/src/shared.c index 30f1f811d..c2e7db874 100644 --- a/src/shared.c +++ b/src/shared.c @@ -4371,6 +4371,20 @@ 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; + + size_t size = sizeof(exec_path); + + const int len = sysctl(mib, 4, exec_path, &size, NULL, 0); + #else #error Your Operating System is not supported or detected #endif From c2bcdbebcb9d3a974cd171f69792c2e611343744 Mon Sep 17 00:00:00 2001 From: Nikolai Lifanov Date: Wed, 6 Jul 2016 08:24:09 -0400 Subject: [PATCH 08/11] implement thread affinity for FreeBSD --- src/shared.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/shared.c b/src/shared.c index c2e7db874..e972b7d55 100644 --- a/src/shared.c +++ b/src/shared.c @@ -6,8 +6,13 @@ * License.....: MIT */ -#if defined(DARWIN) || defined(__FreeBSD__) +#ifdef DARWIN +#include +#endif + +#ifdef __FreeBSD__ #include +#include #endif #include @@ -4537,6 +4542,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); @@ -4584,6 +4592,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); From 1a3b6106010f5dc0a1c2b9e3a6adf460460146b4 Mon Sep 17 00:00:00 2001 From: Nikolai Lifanov Date: Wed, 6 Jul 2016 08:42:53 -0400 Subject: [PATCH 09/11] add tty handling for FreeBSD --- include/common.h | 5 +++++ src/shared.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) 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/src/shared.c b/src/shared.c index e972b7d55..5033dae70 100644 --- a/src/shared.c +++ b/src/shared.c @@ -2387,7 +2387,7 @@ int tty_fix() } #endif -#ifdef DARWIN +#if defined(DARWIN) || defined(__FreeBSD__) static struct termios savemodes; static int havemodes = 0; From 54ebe1fe2309552d03a661b9dd56877e12558a1e Mon Sep 17 00:00:00 2001 From: Nikolai Lifanov Date: Wed, 6 Jul 2016 10:20:46 -0400 Subject: [PATCH 10/11] fix get_path_exe: not sure what I was thinking --- src/shared.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/shared.c b/src/shared.c index 5033dae70..5372561e7 100644 --- a/src/shared.c +++ b/src/shared.c @@ -4386,9 +4386,12 @@ char *get_exec_path () mib[2] = KERN_PROC_PATHNAME; mib[3] = -1; - size_t size = sizeof(exec_path); + char tmp[32] = { 0 }; + + size_t size = exec_path_len; + sysctl(mib, 4, exec_path, &size, NULL, 0); - const int 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 From 6e04a52e53ce2392390ae4c04d215fd447d1720a Mon Sep 17 00:00:00 2001 From: Nikolai Lifanov Date: Wed, 6 Jul 2016 10:33:46 -0400 Subject: [PATCH 11/11] enable path resolution on FreeBSD --- src/hashcat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hashcat.c b/src/hashcat.c index 1a704304d..9c5782d34 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);