1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-22 08:08:10 +00:00

Prefer _WIN to _POSIX for defines.

Also miscellaneous fixes here and there.
This commit is contained in:
Rosen Penev 2017-02-23 15:55:06 -08:00
parent de186ceda5
commit 4ceb7a1afa
No known key found for this signature in database
GPG Key ID: 8B5A63249D3D4CE7
17 changed files with 82 additions and 101 deletions

View File

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

View File

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

View File

@ -10,19 +10,16 @@
#include <unistd.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)
#include <windows.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 SESSIONS_FOLDER "sessions"

View File

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

View File

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

View File

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

View File

@ -8,12 +8,11 @@
#include <signal.h>
#if defined (_POSIX)
#include <pthread.h>
#include <semaphore.h>
#endif // _POSIX
#if defined (_WIN)
#include <windows.h>
#else
#include <pthread.h>
#include <semaphore.h>
#endif // _WIN
#if defined (_WIN)
@ -27,7 +26,7 @@
#define hc_thread_mutex_init(m) InitializeCriticalSection (&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_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)
typedef LARGE_INTEGER hc_timer_t;
#elif defined (_POSIX)
#else
typedef struct timeval hc_timer_t;
#endif
@ -54,19 +54,17 @@ typedef struct timeval hc_timer_t;
#if defined (_WIN)
typedef HANDLE hc_thread_t;
typedef CRITICAL_SECTION hc_thread_mutex_t;
#elif defined (_POSIX)
#else
typedef pthread_t hc_thread_t;
typedef pthread_mutex_t hc_thread_mutex_t;
#endif
// stat
#if defined (_POSIX)
typedef struct stat hc_stat_t;
#endif
#if defined (_WIN)
typedef struct _stat64 hc_stat_t;
#else
typedef struct stat hc_stat_t;
#endif
// enums
@ -1205,10 +1203,10 @@ typedef struct dictstat_ctx
dictstat_t *base;
#if defined (_POSIX)
size_t cnt;
#else
#if defined (_WIN)
u32 cnt;
#else
size_t cnt;
#endif
} 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;
}
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined (__CYGWIN__)
#if defined (_POSIX)
static const char SLASH[] = "/";

View File

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

View File

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

View File

@ -392,9 +392,9 @@ int ocl_init (hashcat_ctx_t *hashcat_ctx)
memset (ocl, 0, sizeof (OCL_PTR));
#if defined(_WIN)
#if defined (_WIN)
ocl->lib = hc_dlopen ("OpenCL");
#elif defined(__APPLE__)
#elif defined (__APPLE__)
ocl->lib = hc_dlopen ("/System/Library/Frameworks/OpenCL.framework/OpenCL", RTLD_NOW);
#elif defined (__CYGWIN__)
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;
#if defined (_POSIX)
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);
}
#endif
#if defined (_WIN)
if (device_param->timer_speed.QuadPart == 0)
#else
if (device_param->timer_speed.tv_sec == 0)
{
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 defined (_POSIX)
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)
#if defined (_WIN)
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 (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
}
@ -108,10 +108,10 @@ static int init_pidfile (hashcat_ctx_t *hashcat_ctx)
if (rc == -1) return -1;
#if defined (_POSIX)
pd->pid = getpid ();
#elif defined (_WIN)
#if defined (_WIN)
pd->pid = GetCurrentProcessId ();
#else
pd->pid = getpid ();
#endif
return 0;

View File

@ -143,18 +143,6 @@ void hc_asprintf (char **strp, const char *fmt, ...)
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)
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);
}
#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
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);
#if defined (_POSIX)
ptr[pw_len] = '\n';
out->len += pw_len + 1;
#else
#if defined (_WIN)
ptr[pw_len + 0] = '\r';
ptr[pw_len + 1] = '\n';
out->len += pw_len + 2;
#else
ptr[pw_len] = '\n';
out->len += pw_len + 1;
#endif
if (out->len >= BUFSIZ - 100)

View File

@ -351,7 +351,7 @@ int tty_fix()
}
#endif
#if defined(__APPLE__) || defined(__FreeBSD__)
#if defined (__APPLE__) || defined (__FreeBSD__)
static struct termios savemodes;
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));
}
#elif defined(_POSIX)
#else
inline void hc_timer_set (hc_timer_t* a)
{