1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-26 09:58:16 +00:00

Move folder specific functions into their own source file

This commit is contained in:
jsteube 2016-09-06 18:23:26 +02:00
parent 176fcb56b1
commit c3fe5b40b1
6 changed files with 139 additions and 115 deletions

25
include/folder.h Normal file
View File

@ -0,0 +1,25 @@
/**
* Authors.....: Jens Steube <jens.steube@gmail.com>
* License.....: MIT
*/
#pragma once
#include <stdio.h>
#include <unistd.h>
#ifdef _POSIX
#include <sys/types.h>
#endif
#ifdef _WIN
#include <windows.h>
#endif
#define DOT_HASHCAT ".hashcat"
#define SESSIONS_FOLDER "sessions"
char *get_exec_path (void);
char *get_install_dir (const char *progname);
char *get_profile_dir (const char *homedir);
char *get_session_dir (const char *profile_dir);

View File

@ -124,11 +124,6 @@ static const char ST_0010[] = "Autotuning";
* functions
*/
char *get_exec_path (void);
char *get_install_dir (const char *progname);
char *get_profile_dir (const char *homedir);
char *get_session_dir (const char *profile_dir);
uint count_lines (FILE *fd);
void *rulefind (const void *key, void *base, int nmemb, size_t size, int (*compar) (const void *, const void *));

View File

@ -165,7 +165,7 @@ LFLAGS_CROSS_WIN := -lpsapi
## Objects
##
NATIVE_OBJS := obj/bitops.NATIVE.o obj/convert.NATIVE.o obj/cpu_aes.NATIVE.o obj/cpu_crc32.NATIVE.o obj/cpu_des.NATIVE.o obj/cpu_md5.NATIVE.o obj/cpu_sha1.NATIVE.o obj/cpu_sha256.NATIVE.o obj/data.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/hwmon.NATIVE.o obj/interface.NATIVE.o obj/logfile.NATIVE.o obj/logging.NATIVE.o obj/memory.NATIVE.o obj/mpsp.NATIVE.o obj/rp_cpu.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o obj/shared.NATIVE.o obj/terminal.NATIVE.o obj/usage.NATIVE.o
NATIVE_OBJS := obj/folder.NATIVE.o obj/bitops.NATIVE.o obj/convert.NATIVE.o obj/cpu_aes.NATIVE.o obj/cpu_crc32.NATIVE.o obj/cpu_des.NATIVE.o obj/cpu_md5.NATIVE.o obj/cpu_sha1.NATIVE.o obj/cpu_sha256.NATIVE.o obj/data.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/hwmon.NATIVE.o obj/interface.NATIVE.o obj/logfile.NATIVE.o obj/logging.NATIVE.o obj/memory.NATIVE.o obj/mpsp.NATIVE.o obj/rp_cpu.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o obj/shared.NATIVE.o obj/terminal.NATIVE.o obj/usage.NATIVE.o
ifeq ($(UNAME),Linux)
NATIVE_OBJS += obj/ext_ADL.NATIVE.o
@ -174,8 +174,8 @@ NATIVE_OBJS += obj/ext_nvml.NATIVE.o
NATIVE_OBJS += obj/ext_xnvctrl.NATIVE.o
endif
LINUX_32_OBJS := obj/bitops.LINUX.32.o obj/convert.LINUX.32.o obj/cpu_aes.LINUX.32.o obj/cpu_crc32.LINUX.32.o obj/cpu_des.LINUX.32.o obj/cpu_md5.LINUX.32.o obj/cpu_sha1.LINUX.32.o obj/cpu_sha256.LINUX.32.o obj/data.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o obj/hwmon.LINUX.32.o obj/interface.LINUX.32.o obj/logfile.LINUX.32.o obj/logging.LINUX.32.o obj/memory.LINUX.32.o obj/mpsp.LINUX.32.o obj/rp_cpu.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/shared.LINUX.32.o obj/terminal.LINUX.32.o obj/usage.LINUX.32.o
LINUX_64_OBJS := obj/bitops.LINUX.64.o obj/convert.LINUX.64.o obj/cpu_aes.LINUX.64.o obj/cpu_crc32.LINUX.64.o obj/cpu_des.LINUX.64.o obj/cpu_md5.LINUX.64.o obj/cpu_sha1.LINUX.64.o obj/cpu_sha256.LINUX.64.o obj/data.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o obj/hwmon.LINUX.64.o obj/interface.LINUX.64.o obj/logfile.LINUX.64.o obj/logging.LINUX.64.o obj/memory.LINUX.64.o obj/mpsp.LINUX.64.o obj/rp_cpu.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/shared.LINUX.64.o obj/terminal.LINUX.64.o obj/usage.LINUX.64.o
LINUX_32_OBJS := obj/folder.LINUX.32.o obj/bitops.LINUX.32.o obj/convert.LINUX.32.o obj/cpu_aes.LINUX.32.o obj/cpu_crc32.LINUX.32.o obj/cpu_des.LINUX.32.o obj/cpu_md5.LINUX.32.o obj/cpu_sha1.LINUX.32.o obj/cpu_sha256.LINUX.32.o obj/data.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o obj/hwmon.LINUX.32.o obj/interface.LINUX.32.o obj/logfile.LINUX.32.o obj/logging.LINUX.32.o obj/memory.LINUX.32.o obj/mpsp.LINUX.32.o obj/rp_cpu.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/shared.LINUX.32.o obj/terminal.LINUX.32.o obj/usage.LINUX.32.o
LINUX_64_OBJS := obj/folder.LINUX.64.o obj/bitops.LINUX.64.o obj/convert.LINUX.64.o obj/cpu_aes.LINUX.64.o obj/cpu_crc32.LINUX.64.o obj/cpu_des.LINUX.64.o obj/cpu_md5.LINUX.64.o obj/cpu_sha1.LINUX.64.o obj/cpu_sha256.LINUX.64.o obj/data.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o obj/hwmon.LINUX.64.o obj/interface.LINUX.64.o obj/logfile.LINUX.64.o obj/logging.LINUX.64.o obj/memory.LINUX.64.o obj/mpsp.LINUX.64.o obj/rp_cpu.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/shared.LINUX.64.o obj/terminal.LINUX.64.o obj/usage.LINUX.64.o
# Windows CRT file globbing:
@ -185,8 +185,8 @@ CRT_GLOB_INCLUDE_FOLDER := $(dir $(lastword $(MAKEFILE_LIST)))
include $(CRT_GLOB_INCLUDE_FOLDER)/win_file_globbing.mk
WIN_32_OBJS := obj/bitops.WIN.32.o obj/convert.WIN.32.o obj/cpu_aes.WIN.32.o obj/cpu_crc32.WIN.32.o obj/cpu_des.WIN.32.o obj/cpu_md5.WIN.32.o obj/cpu_sha1.WIN.32.o obj/cpu_sha256.WIN.32.o obj/data.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/ext_xnvctrl.WIN.32.o obj/hwmon.WIN.32.o obj/interface.WIN.32.o obj/logfile.WIN.32.o obj/logging.WIN.32.o obj/memory.WIN.32.o obj/mpsp.WIN.32.o obj/rp_cpu.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/shared.WIN.32.o obj/terminal.WIN.32.o obj/usage.WIN.32.o $(CRT_GLOB_32)
WIN_64_OBJS := obj/bitops.WIN.64.o obj/convert.WIN.64.o obj/cpu_aes.WIN.64.o obj/cpu_crc32.WIN.64.o obj/cpu_des.WIN.64.o obj/cpu_md5.WIN.64.o obj/cpu_sha1.WIN.64.o obj/cpu_sha256.WIN.64.o obj/data.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/ext_xnvctrl.WIN.64.o obj/hwmon.WIN.64.o obj/interface.WIN.64.o obj/logfile.WIN.64.o obj/logging.WIN.64.o obj/memory.WIN.64.o obj/mpsp.WIN.64.o obj/rp_cpu.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/shared.WIN.64.o obj/terminal.WIN.64.o obj/usage.WIN.64.o $(CRT_GLOB_64)
WIN_32_OBJS := obj/folder.WIN.32.o obj/bitops.WIN.32.o obj/convert.WIN.32.o obj/cpu_aes.WIN.32.o obj/cpu_crc32.WIN.32.o obj/cpu_des.WIN.32.o obj/cpu_md5.WIN.32.o obj/cpu_sha1.WIN.32.o obj/cpu_sha256.WIN.32.o obj/data.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/ext_xnvctrl.WIN.32.o obj/hwmon.WIN.32.o obj/interface.WIN.32.o obj/logfile.WIN.32.o obj/logging.WIN.32.o obj/memory.WIN.32.o obj/mpsp.WIN.32.o obj/rp_cpu.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/shared.WIN.32.o obj/terminal.WIN.32.o obj/usage.WIN.32.o $(CRT_GLOB_32)
WIN_64_OBJS := obj/folder.WIN.64.o obj/bitops.WIN.64.o obj/convert.WIN.64.o obj/cpu_aes.WIN.64.o obj/cpu_crc32.WIN.64.o obj/cpu_des.WIN.64.o obj/cpu_md5.WIN.64.o obj/cpu_sha1.WIN.64.o obj/cpu_sha256.WIN.64.o obj/data.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/ext_xnvctrl.WIN.64.o obj/hwmon.WIN.64.o obj/interface.WIN.64.o obj/logfile.WIN.64.o obj/logging.WIN.64.o obj/memory.WIN.64.o obj/mpsp.WIN.64.o obj/rp_cpu.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/shared.WIN.64.o obj/terminal.WIN.64.o obj/usage.WIN.64.o $(CRT_GLOB_64)
##
## Targets: Global

108
src/folder.c Normal file
View File

@ -0,0 +1,108 @@
/**
* Authors.....: Jens Steube <jens.steube@gmail.com>
* License.....: MIT
*/
#include "common.h"
#include "memory.h"
#include "folder.h"
char *get_exec_path ()
{
int exec_path_len = 1024;
char *exec_path = (char *) mymalloc (exec_path_len);
#ifdef __linux__
char tmp[32] = { 0 };
snprintf (tmp, sizeof (tmp) - 1, "/proc/%d/exe", getpid ());
const int len = readlink (tmp, exec_path, exec_path_len - 1);
#elif WIN
const int len = GetModuleFileName (NULL, exec_path, exec_path_len - 1);
#elif __APPLE__
uint size = exec_path_len;
if (_NSGetExecutablePath (exec_path, &size) != 0)
{
log_error("! executable path buffer too small\n");
exit (-1);
}
const int len = strlen (exec_path);
#elif __FreeBSD__
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
exec_path[len] = 0;
return exec_path;
}
char *get_install_dir (const char *progname)
{
char *install_dir = mystrdup (progname);
char *last_slash = NULL;
if ((last_slash = strrchr (install_dir, '/')) != NULL)
{
*last_slash = 0;
}
else if ((last_slash = strrchr (install_dir, '\\')) != NULL)
{
*last_slash = 0;
}
else
{
install_dir[0] = '.';
install_dir[1] = 0;
}
return (install_dir);
}
char *get_profile_dir (const char *homedir)
{
size_t len = strlen (homedir) + 1 + strlen (DOT_HASHCAT) + 1;
char *profile_dir = (char *) mymalloc (len + 1);
snprintf (profile_dir, len, "%s/%s", homedir, DOT_HASHCAT);
return profile_dir;
}
char *get_session_dir (const char *profile_dir)
{
size_t len = strlen (profile_dir) + 1 + strlen (SESSIONS_FOLDER) + 1;
char *session_dir = (char *) mymalloc (len + 1);
snprintf (session_dir, len, "%s/%s", profile_dir, SESSIONS_FOLDER);
return session_dir;
}

View File

@ -10,6 +10,7 @@
#include "types_int.h"
#include "bitops.h"
#include "memory.h"
#include "folder.h"
#include "convert.h"
#include "logging.h"
#include "logfile.h"

View File

@ -77,111 +77,6 @@ void fsync (int fd)
* mixed shared functions
*/
char *get_exec_path ()
{
int exec_path_len = 1024;
char *exec_path = (char *) mymalloc (exec_path_len);
#ifdef __linux__
char tmp[32] = { 0 };
snprintf (tmp, sizeof (tmp) - 1, "/proc/%d/exe", getpid ());
const int len = readlink (tmp, exec_path, exec_path_len - 1);
#elif WIN
const int len = GetModuleFileName (NULL, exec_path, exec_path_len - 1);
#elif __APPLE__
uint size = exec_path_len;
if (_NSGetExecutablePath (exec_path, &size) != 0)
{
log_error("! executable path buffer too small\n");
exit (-1);
}
const int len = strlen (exec_path);
#elif __FreeBSD__
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
exec_path[len] = 0;
return exec_path;
}
char *get_install_dir (const char *progname)
{
char *install_dir = mystrdup (progname);
char *last_slash = NULL;
if ((last_slash = strrchr (install_dir, '/')) != NULL)
{
*last_slash = 0;
}
else if ((last_slash = strrchr (install_dir, '\\')) != NULL)
{
*last_slash = 0;
}
else
{
install_dir[0] = '.';
install_dir[1] = 0;
}
return (install_dir);
}
char *get_profile_dir (const char *homedir)
{
#define DOT_HASHCAT ".hashcat"
size_t len = strlen (homedir) + 1 + strlen (DOT_HASHCAT) + 1;
char *profile_dir = (char *) mymalloc (len + 1);
snprintf (profile_dir, len, "%s/%s", homedir, DOT_HASHCAT);
return profile_dir;
}
char *get_session_dir (const char *profile_dir)
{
#define SESSIONS_FOLDER "sessions"
size_t len = strlen (profile_dir) + 1 + strlen (SESSIONS_FOLDER) + 1;
char *session_dir = (char *) mymalloc (len + 1);
snprintf (session_dir, len, "%s/%s", profile_dir, SESSIONS_FOLDER);
return session_dir;
}
uint count_lines (FILE *fd)
{
uint cnt = 0;