1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-12-25 07:58:19 +00:00

Merge pull request #1130 from neheb/master

Prefer _WIN to _POSIX for defines.
This commit is contained in:
Jens Steube 2017-02-24 06:41:56 +01:00 committed by GitHub
commit ffc678857b
17 changed files with 82 additions and 101 deletions

View File

@ -12,7 +12,6 @@
#define _POSIX #define _POSIX
#elif defined (__WINNT__) #elif defined (__WINNT__)
#define _WIN 1 #define _WIN 1
#define WIN 1
#else #else
#error Your Operating System is not supported or detected #error Your Operating System is not supported or detected
#endif #endif

View File

@ -8,16 +8,14 @@
#include <stdlib.h> #include <stdlib.h>
#if defined (_POSIX) #ifdef _WIN
#include <windows.h>
#else
#include <dlfcn.h> #include <dlfcn.h>
#if defined (__APPLE__) #if defined (__APPLE__)
#include <mach-o/dyld.h> #include <mach-o/dyld.h>
#endif // __APPLE__ #endif // __APPLE__
#endif // _POSIX #endif // _WIN
#ifdef _WIN
#include <windows.h>
#endif
#ifdef _WIN #ifdef _WIN
HMODULE hc_dlopen (LPCSTR lpLibFileName); HMODULE hc_dlopen (LPCSTR lpLibFileName);

View File

@ -10,19 +10,16 @@
#include <unistd.h> #include <unistd.h>
#include <limits.h> #include <limits.h>
#if defined (_POSIX)
#include <sys/types.h>
#include <pwd.h>
#endif
#if defined (__APPLE__)
#include <mach-o/dyld.h>
#endif // __APPLE__
#if defined (_WIN) #if defined (_WIN)
#include <windows.h> #include <windows.h>
#include <direct.h> #include <direct.h>
#endif #else
#include <sys/types.h>
#include <pwd.h>
#if defined (__APPLE__)
#include <mach-o/dyld.h>
#endif // __APPLE__
#endif // _WIN
#define DOT_HASHCAT ".hashcat" #define DOT_HASHCAT ".hashcat"
#define SESSIONS_FOLDER "sessions" #define SESSIONS_FOLDER "sessions"

View File

@ -10,14 +10,12 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#if defined (_POSIX)
#include <sys/types.h>
#include <sys/stat.h>
#endif // _POSIX
#if defined (_WIN) #if defined (_WIN)
#include <windows.h> #include <windows.h>
#include <psapi.h> #include <psapi.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#endif // _WIN #endif // _WIN
int pidfile_ctx_init (hashcat_ctx_t *hashcat_ctx); int pidfile_ctx_init (hashcat_ctx_t *hashcat_ctx);

View File

@ -10,14 +10,12 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#if defined (_POSIX)
#include <sys/types.h>
#include <sys/stat.h>
#endif // _POSIX
#if defined (_WIN) #if defined (_WIN)
#include <windows.h> #include <windows.h>
#include <psapi.h> #include <psapi.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#endif // _WIN #endif // _WIN
#define RESTORE_VERSION_MIN 340 #define RESTORE_VERSION_MIN 340

View File

@ -12,15 +12,13 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#if defined (_POSIX) #if defined (_WIN)
#include <windows.h>
#else
#include <termios.h> #include <termios.h>
#if defined (__APPLE__) #if defined (__APPLE__)
#include <sys/ioctl.h> #include <sys/ioctl.h>
#endif // __APPLE__ #endif // __APPLE__
#endif // _POSIX
#if defined (_WIN)
#include <windows.h>
#endif // _WIN #endif // _WIN
void welcome_screen (hashcat_ctx_t *hashcat_ctx, const char *version_tag); void welcome_screen (hashcat_ctx_t *hashcat_ctx, const char *version_tag);

View File

@ -8,12 +8,11 @@
#include <signal.h> #include <signal.h>
#if defined (_POSIX)
#include <pthread.h>
#include <semaphore.h>
#endif // _POSIX
#if defined (_WIN) #if defined (_WIN)
#include <windows.h> #include <windows.h>
#else
#include <pthread.h>
#include <semaphore.h>
#endif // _WIN #endif // _WIN
#if defined (_WIN) #if defined (_WIN)
@ -27,7 +26,7 @@
#define hc_thread_mutex_init(m) InitializeCriticalSection (&m) #define hc_thread_mutex_init(m) InitializeCriticalSection (&m)
#define hc_thread_mutex_delete(m) DeleteCriticalSection (&m) #define hc_thread_mutex_delete(m) DeleteCriticalSection (&m)
#elif defined (_POSIX) #else
#define hc_thread_create(t,f,a) pthread_create (&t, NULL, f, a) #define hc_thread_create(t,f,a) pthread_create (&t, NULL, f, a)
#define hc_thread_wait(n,a) for (u32 i = 0; i < n; i++) pthread_join ((a)[i], NULL) #define hc_thread_wait(n,a) for (u32 i = 0; i < n; i++) pthread_join ((a)[i], NULL)

View File

@ -41,7 +41,7 @@ typedef uint64_t u64;
#if defined (_WIN) #if defined (_WIN)
typedef LARGE_INTEGER hc_timer_t; typedef LARGE_INTEGER hc_timer_t;
#elif defined (_POSIX) #else
typedef struct timeval hc_timer_t; typedef struct timeval hc_timer_t;
#endif #endif
@ -54,19 +54,17 @@ typedef struct timeval hc_timer_t;
#if defined (_WIN) #if defined (_WIN)
typedef HANDLE hc_thread_t; typedef HANDLE hc_thread_t;
typedef CRITICAL_SECTION hc_thread_mutex_t; typedef CRITICAL_SECTION hc_thread_mutex_t;
#elif defined (_POSIX) #else
typedef pthread_t hc_thread_t; typedef pthread_t hc_thread_t;
typedef pthread_mutex_t hc_thread_mutex_t; typedef pthread_mutex_t hc_thread_mutex_t;
#endif #endif
// stat // stat
#if defined (_POSIX)
typedef struct stat hc_stat_t;
#endif
#if defined (_WIN) #if defined (_WIN)
typedef struct _stat64 hc_stat_t; typedef struct _stat64 hc_stat_t;
#else
typedef struct stat hc_stat_t;
#endif #endif
// enums // enums
@ -1205,10 +1203,10 @@ typedef struct dictstat_ctx
dictstat_t *base; dictstat_t *base;
#if defined (_POSIX) #if defined (_WIN)
size_t cnt;
#else
u32 cnt; u32 cnt;
#else
size_t cnt;
#endif #endif
} dictstat_ctx_t; } dictstat_ctx_t;

View File

@ -304,7 +304,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
return -1; return -1;
} }
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined (__CYGWIN__) #if defined (_POSIX)
static const char SLASH[] = "/"; static const char SLASH[] = "/";

View File

@ -1420,7 +1420,7 @@ static int xnvctrl_init (hashcat_ctx_t *hashcat_ctx)
// unsupport platform? // unsupport platform?
return -1; return -1;
#elif defined (_POSIX) #else
xnvctrl->lib_x11 = dlopen ("libX11.so", RTLD_LAZY); xnvctrl->lib_x11 = dlopen ("libX11.so", RTLD_LAZY);

View File

@ -20,7 +20,7 @@
#include "interface.h" #include "interface.h"
#include "event.h" #include "event.h"
#if defined(__MINGW64__) || defined(__MINGW32__) #if defined (__MINGW64__) || defined (__MINGW32__)
int _dowildcard = -1; int _dowildcard = -1;
#endif #endif

View File

@ -392,9 +392,9 @@ int ocl_init (hashcat_ctx_t *hashcat_ctx)
memset (ocl, 0, sizeof (OCL_PTR)); memset (ocl, 0, sizeof (OCL_PTR));
#if defined(_WIN) #if defined (_WIN)
ocl->lib = hc_dlopen ("OpenCL"); ocl->lib = hc_dlopen ("OpenCL");
#elif defined(__APPLE__) #elif defined (__APPLE__)
ocl->lib = hc_dlopen ("/System/Library/Frameworks/OpenCL.framework/OpenCL", RTLD_NOW); ocl->lib = hc_dlopen ("/System/Library/Frameworks/OpenCL.framework/OpenCL", RTLD_NOW);
#elif defined (__CYGWIN__) #elif defined (__CYGWIN__)
ocl->lib = hc_dlopen ("opencl.dll", RTLD_NOW); ocl->lib = hc_dlopen ("opencl.dll", RTLD_NOW);
@ -1800,15 +1800,13 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co
u32 speed_pos = device_param->speed_pos; u32 speed_pos = device_param->speed_pos;
#if defined (_POSIX) #if defined (_WIN)
if (device_param->timer_speed.tv_sec == 0) if (device_param->timer_speed.QuadPart == 0)
{ {
hc_timer_set (&device_param->timer_speed); hc_timer_set (&device_param->timer_speed);
} }
#endif #else
if (device_param->timer_speed.tv_sec == 0)
#if defined (_WIN)
if (device_param->timer_speed.QuadPart == 0)
{ {
hc_timer_set (&device_param->timer_speed); hc_timer_set (&device_param->timer_speed);
} }

View File

@ -38,26 +38,7 @@ static int check_running_process (hashcat_ctx_t *hashcat_ctx)
if (pd->pid) if (pd->pid)
{ {
#if defined (_POSIX) #if defined (_WIN)
char *pidbin;
hc_asprintf (&pidbin, "/proc/%u/cmdline", pd->pid);
if (hc_path_exist (pidbin) == true)
{
event_log_error (hashcat_ctx, "Already an instance running on pid %u", pd->pid);
hcfree (pd);
hcfree (pidbin);
return -1;
}
hcfree (pidbin);
#elif defined (_WIN)
HANDLE hProcess = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pd->pid); HANDLE hProcess = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pd->pid);
@ -88,6 +69,25 @@ static int check_running_process (hashcat_ctx_t *hashcat_ctx)
hcfree (pidbin); hcfree (pidbin);
hcfree (pidbin2); hcfree (pidbin2);
#else
char *pidbin;
hc_asprintf (&pidbin, "/proc/%u/cmdline", pd->pid);
if (hc_path_exist (pidbin) == true)
{
event_log_error (hashcat_ctx, "Already an instance running on pid %u", pd->pid);
hcfree (pd);
hcfree (pidbin);
return -1;
}
hcfree (pidbin);
#endif #endif
} }
@ -108,10 +108,10 @@ static int init_pidfile (hashcat_ctx_t *hashcat_ctx)
if (rc == -1) return -1; if (rc == -1) return -1;
#if defined (_POSIX) #if defined (_WIN)
pd->pid = getpid ();
#elif defined (_WIN)
pd->pid = GetCurrentProcessId (); pd->pid = GetCurrentProcessId ();
#else
pd->pid = getpid ();
#endif #endif
return 0; return 0;

View File

@ -143,18 +143,6 @@ void hc_asprintf (char **strp, const char *fmt, ...)
va_end (args); va_end (args);
} }
#if defined (_POSIX)
int hc_stat (const char *pathname, hc_stat_t *buf)
{
return stat (pathname, buf);
}
int hc_fstat (int fd, hc_stat_t *buf)
{
return fstat (fd, buf);
}
#endif
#if defined (_WIN) #if defined (_WIN)
int hc_stat (const char *pathname, hc_stat_t *buf) int hc_stat (const char *pathname, hc_stat_t *buf)
{ {
@ -165,6 +153,16 @@ int hc_fstat (int fd, hc_stat_t *buf)
{ {
return fstat64 (fd, buf); return fstat64 (fd, buf);
} }
#else
int hc_stat (const char *pathname, hc_stat_t *buf)
{
return stat (pathname, buf);
}
int hc_fstat (int fd, hc_stat_t *buf)
{
return fstat (fd, buf);
}
#endif #endif
void hc_sleep_msec (const u32 msec) void hc_sleep_msec (const u32 msec)

View File

@ -27,19 +27,19 @@ static void out_push (out_t *out, const u8 *pw_buf, const int pw_len)
memcpy (ptr, pw_buf, pw_len); memcpy (ptr, pw_buf, pw_len);
#if defined (_POSIX) #if defined (_WIN)
ptr[pw_len] = '\n';
out->len += pw_len + 1;
#else
ptr[pw_len + 0] = '\r'; ptr[pw_len + 0] = '\r';
ptr[pw_len + 1] = '\n'; ptr[pw_len + 1] = '\n';
out->len += pw_len + 2; out->len += pw_len + 2;
#else
ptr[pw_len] = '\n';
out->len += pw_len + 1;
#endif #endif
if (out->len >= BUFSIZ - 100) if (out->len >= BUFSIZ - 100)

View File

@ -351,7 +351,7 @@ int tty_fix()
} }
#endif #endif
#if defined(__APPLE__) || defined(__FreeBSD__) #if defined (__APPLE__) || defined (__FreeBSD__)
static struct termios savemodes; static struct termios savemodes;
static int havemodes = 0; static int havemodes = 0;

View File

@ -27,7 +27,7 @@ inline double hc_timer_get (hc_timer_t a)
return (double) ((double) (hr_tmp.QuadPart - a.QuadPart) / (double) (hr_freq.QuadPart / 1000)); return (double) ((double) (hr_tmp.QuadPart - a.QuadPart) / (double) (hr_freq.QuadPart / 1000));
} }
#elif defined(_POSIX) #else
inline void hc_timer_set (hc_timer_t* a) inline void hc_timer_set (hc_timer_t* a)
{ {