diff --git a/include/common.h b/include/common.h index d13f4d290..fc87b012c 100644 --- a/include/common.h +++ b/include/common.h @@ -23,6 +23,7 @@ #define _GNU_SOURCE #define _FILE_OFFSET_BITS 64 +#define _LARGEFILE64_SOURCE #define NOMINMAX 1 diff --git a/include/shared.h b/include/shared.h index a5291e284..c217e1359 100644 --- a/include/shared.h +++ b/include/shared.h @@ -31,4 +31,7 @@ void setup_environment_variables (void); void setup_umask (void); void setup_seeding (const bool rp_gen_seed_chgd, const u32 rp_gen_seed); +int hc_stat (const char *pathname, hc_stat_t *buf); +int hc_fstat (int fd, hc_stat_t *buf); + #endif // _SHARED_H diff --git a/include/types.h b/include/types.h index 1246d8887..52240c468 100644 --- a/include/types.h +++ b/include/types.h @@ -15,6 +15,7 @@ #include #include #include +#include #if defined (_WIN) #include @@ -61,15 +62,11 @@ typedef pthread_mutex_t hc_thread_mutex_t; // stat #if defined (_POSIX) -typedef struct stat hc_stat; +typedef struct stat hc_stat_t; #endif #if defined (_WIN) -#if defined (_MSC_VER) -typedef struct _stat64 hc_stat; -#else -typedef struct stat64 hc_stat; -#endif +typedef struct _stat64 hc_stat_t; #endif // enums @@ -1119,13 +1116,7 @@ typedef struct dictstat { u64 cnt; - #if defined (_POSIX) - struct stat stat; - #endif - - #if defined (_WIN) - struct __stat64 stat; - #endif + hc_stat_t stat; } dictstat_t; @@ -1635,13 +1626,7 @@ typedef struct cache_hit { char *dictfile; - #if defined (_POSIX) - struct stat stat; - #endif - - #if defined (_WIN) - struct __stat64 stat; - #endif + hc_stat_t stat; u64 cached_cnt; u64 keyspace; diff --git a/src/affinity.c b/src/affinity.c index 7f141a4f3..db9c97aa8 100644 --- a/src/affinity.c +++ b/src/affinity.c @@ -3,10 +3,6 @@ * License.....: MIT */ -#if defined (__APPLE__) -#include -#endif - #include "common.h" #include "types.h" #include "memory.h" diff --git a/src/combinator.c b/src/combinator.c index ae2a4d6a8..2e52573ac 100644 --- a/src/combinator.c +++ b/src/combinator.c @@ -8,6 +8,7 @@ #include "event.h" #include "memory.h" #include "combinator.h" +#include "shared.h" #include "wordlist.h" int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) @@ -48,7 +49,7 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) FILE *fp1 = NULL; FILE *fp2 = NULL; - struct stat tmp_stat; + hc_stat_t tmp_stat; if ((fp1 = fopen (dictfile1, "rb")) == NULL) { @@ -57,7 +58,7 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } - if (stat (dictfile1, &tmp_stat) == -1) + if (hc_stat (dictfile1, &tmp_stat) == -1) { event_log_error (hashcat_ctx, "%s: %s", dictfile1, strerror (errno)); @@ -84,7 +85,7 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } - if (stat (dictfile2, &tmp_stat) == -1) + if (hc_stat (dictfile2, &tmp_stat) == -1) { event_log_error (hashcat_ctx, "%s: %s", dictfile2, strerror (errno)); diff --git a/src/folder.c b/src/folder.c index 6b7c19e1e..6c8903e1b 100644 --- a/src/folder.c +++ b/src/folder.c @@ -3,10 +3,6 @@ * License.....: MIT */ -#if defined (__APPLE__) -#include -#endif - #include "common.h" #include "types.h" #include "memory.h" diff --git a/src/hashcat.c b/src/hashcat.c index bde41d8f7..b2a1e7b39 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -3,10 +3,6 @@ * License.....: MIT */ -#if defined (__APPLE__) -#include -#endif // __APPLE__ - #include "common.h" // basic tools diff --git a/src/hashes.c b/src/hashes.c index bb11dfaa3..6cd5d161f 100644 --- a/src/hashes.c +++ b/src/hashes.c @@ -21,6 +21,7 @@ #include "potfile.h" #include "rp.h" #include "rp_kernel_on_cpu.h" +#include "shared.h" #include "thread.h" #include "timer.h" @@ -446,9 +447,9 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) if ((user_options->benchmark == false) && (user_options->stdout_flag == false)) { - struct stat f; + hc_stat_t f; - hashlist_mode = (stat (hash_or_file, &f) == 0) ? HL_MODE_FILE : HL_MODE_ARG; + hashlist_mode = (hc_stat (hash_or_file, &f) == 0) ? HL_MODE_FILE : HL_MODE_ARG; if (hashconfig->opts_type & OPTS_TYPE_BINARY_HASHFILE) { @@ -463,9 +464,9 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) { if (hashconfig->hash_mode == 2500) { - struct stat st; + hc_stat_t st; - if (stat (hashes->hashfile, &st) == -1) + if (hc_stat (hashes->hashfile, &st) == -1) { event_log_error (hashcat_ctx, "%s: %s", hashes->hashfile, strerror (errno)); diff --git a/src/induct.c b/src/induct.c index bfd646ee5..5e99b552d 100644 --- a/src/induct.c +++ b/src/induct.c @@ -8,6 +8,7 @@ #include "memory.h" #include "event.h" #include "folder.h" +#include "shared.h" #include "induct.h" static int sort_by_mtime (const void *p1, const void *p2) @@ -15,8 +16,8 @@ static int sort_by_mtime (const void *p1, const void *p2) const char **f1 = (const char **) p1; const char **f2 = (const char **) p2; - struct stat s1; stat (*f1, &s1); - struct stat s2; stat (*f2, &s2); + hc_stat_t s1; hc_stat (*f1, &s1); + hc_stat_t s2; hc_stat (*f2, &s2); return s2.st_mtime - s1.st_mtime; } @@ -115,9 +116,9 @@ void induct_ctx_cleanup (hashcat_ctx_t *hashcat_ctx) for (int file_pos = 0; file_pos < induct_ctx->induction_dictionaries_cnt; file_pos++) { - struct stat induct_stat; + hc_stat_t induct_stat; - if (stat (induct_ctx->induction_dictionaries[file_pos], &induct_stat) == 0) + if (hc_stat (induct_ctx->induction_dictionaries[file_pos], &induct_stat) == 0) { unlink (induct_ctx->induction_dictionaries[file_pos]); } diff --git a/src/interface.c b/src/interface.c index 8a7ad757a..be54d70f5 100644 --- a/src/interface.c +++ b/src/interface.c @@ -3,10 +3,6 @@ * License.....: MIT */ -#if defined (__APPLE__) -#include -#endif - #include "common.h" #include "types.h" #include "bitops.h" diff --git a/src/logfile.c b/src/logfile.c index f1d8bbf7e..44a289c6e 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -3,10 +3,6 @@ * License.....: MIT */ -#if defined (__APPLE__) -#include -#endif - #include "common.h" #include "types.h" #include "memory.h" diff --git a/src/main.c b/src/main.c index 57d3a8614..573752a8b 100644 --- a/src/main.c +++ b/src/main.c @@ -3,11 +3,12 @@ * License.....: MIT */ +#include "common.h" + #include #include #include -#include "common.h" #include "types.h" #include "user_options.h" #include "usage.h" diff --git a/src/main_shared.c b/src/main_shared.c index 8cc0e7b59..b45087479 100644 --- a/src/main_shared.c +++ b/src/main_shared.c @@ -3,10 +3,11 @@ * License.....: MIT */ +#include "common.h" + #include #include -#include "common.h" #include "types.h" #include "memory.h" #include "user_options.h" diff --git a/src/mpsp.c b/src/mpsp.c index 08b41222f..2ccbbe4a4 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -3,10 +3,6 @@ * License.....: MIT */ -#if defined (__APPLE__) -#include -#endif - #include "common.h" #include "types.h" #include "memory.h" @@ -16,6 +12,7 @@ #include "filehandling.h" #include "interface.h" #include "opencl.h" +#include "shared.h" #include "mpsp.h" static const char DEF_MASK[] = "?1?2?2?2?2?2?2?3?3?3?3?d?d?d?d"; @@ -579,9 +576,9 @@ static int sp_setup_tbl (hashcat_ctx_t *hashcat_ctx) char *shared_dir = folder_config->shared_dir; - char *hcstat = user_options->markov_hcstat; - u32 disable = user_options->markov_disable; - u32 classic = user_options->markov_classic; + char *hcstat = user_options->markov_hcstat; + u32 disable = user_options->markov_disable; + u32 classic = user_options->markov_classic; hcstat_table_t *root_table_buf = mask_ctx->root_table_buf; hcstat_table_t *markov_table_buf = mask_ctx->markov_table_buf; @@ -1161,9 +1158,9 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) { char *arg = user_options_extra->hc_workv[0]; - struct stat file_stat; + hc_stat_t file_stat; - if (stat (arg, &file_stat) == -1) + if (hc_stat (arg, &file_stat) == -1) { const int rc = mask_append (hashcat_ctx, arg); @@ -1177,7 +1174,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) { arg = user_options_extra->hc_workv[i]; - if (stat (arg, &file_stat) == -1) + if (hc_stat (arg, &file_stat) == -1) { event_log_error (hashcat_ctx, "%s: %s", arg, strerror (errno)); @@ -1249,9 +1246,9 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) // mod - struct stat file_stat; + hc_stat_t file_stat; - if (stat (arg, &file_stat) == -1) + if (hc_stat (arg, &file_stat) == -1) { const int rc = mask_append (hashcat_ctx, arg); @@ -1307,9 +1304,9 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) // mod - struct stat file_stat; + hc_stat_t file_stat; - if (stat (arg, &file_stat) == -1) + if (hc_stat (arg, &file_stat) == -1) { const int rc = mask_append (hashcat_ctx, arg); diff --git a/src/opencl.c b/src/opencl.c index 3ea5de76a..1f9598955 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -217,11 +217,9 @@ static int read_kernel_binary (hashcat_ctx_t *hashcat_ctx, const char *kernel_fi if (fp != NULL) { - struct stat st; + hc_stat_t st; - memset (&st, 0, sizeof (st)); - - stat (kernel_file, &st); + hc_stat (kernel_file, &st); char *buf = (char *) hcmalloc (hashcat_ctx, st.st_size + 1); VERIFY_PTR (buf); @@ -3471,9 +3469,9 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) generate_source_kernel_filename (hashconfig->attack_exec, user_options_extra->attack_kern, hashconfig->kern_type, folder_config->shared_dir, source_file); - struct stat sst; + hc_stat_t sst; - if (stat (source_file, &sst) == -1) + if (hc_stat (source_file, &sst) == -1) { event_log_error (hashcat_ctx, "%s: %s", source_file, strerror (errno)); @@ -3490,9 +3488,9 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) int cached = 1; - struct stat cst; + hc_stat_t cst; - if ((stat (cached_file, &cst) == -1) || cst.st_size == 0) + if ((hc_stat (cached_file, &cst) == -1) || cst.st_size == 0) { cached = 0; } @@ -3679,9 +3677,9 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) generate_source_kernel_mp_filename (hashconfig->opti_type, hashconfig->opts_type, folder_config->shared_dir, source_file); - struct stat sst; + hc_stat_t sst; - if (stat (source_file, &sst) == -1) + if (hc_stat (source_file, &sst) == -1) { event_log_error (hashcat_ctx, "%s: %s", source_file, strerror (errno)); @@ -3698,9 +3696,9 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) int cached = 1; - struct stat cst; + hc_stat_t cst; - if (stat (cached_file, &cst) == -1) + if (hc_stat (cached_file, &cst) == -1) { cached = 0; } @@ -3821,9 +3819,9 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) generate_source_kernel_amp_filename (user_options_extra->attack_kern, folder_config->shared_dir, source_file); - struct stat sst; + hc_stat_t sst; - if (stat (source_file, &sst) == -1) + if (hc_stat (source_file, &sst) == -1) { event_log_error (hashcat_ctx, "%s: %s", source_file, strerror (errno)); @@ -3840,9 +3838,9 @@ int opencl_session_begin (hashcat_ctx_t *hashcat_ctx) int cached = 1; - struct stat cst; + hc_stat_t cst; - if (stat (cached_file, &cst) == -1) + if (hc_stat (cached_file, &cst) == -1) { cached = 0; } diff --git a/src/outfile.c b/src/outfile.c index 1a9f499b4..c24874342 100644 --- a/src/outfile.c +++ b/src/outfile.c @@ -14,6 +14,7 @@ #include "rp.h" #include "rp_kernel_on_cpu.h" #include "opencl.h" +#include "shared.h" #include "outfile.h" int build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u32 *plain_buf, int *out_len) @@ -449,20 +450,14 @@ int outfile_and_hashfile (hashcat_ctx_t *hashcat_ctx) if (outfile == NULL) return 0; - hc_stat tmpstat_outfile; - hc_stat tmpstat_hashfile; + hc_stat_t tmpstat_outfile; + hc_stat_t tmpstat_hashfile; FILE *tmp_outfile_fp = fopen (outfile, "r"); if (tmp_outfile_fp) { - #if defined (_POSIX) - fstat (fileno (tmp_outfile_fp), &tmpstat_outfile); - #endif - - #if defined (_WIN) - _fstat64 (fileno (tmp_outfile_fp), &tmpstat_outfile); - #endif + hc_fstat (fileno (tmp_outfile_fp), &tmpstat_outfile); fclose (tmp_outfile_fp); } @@ -471,13 +466,7 @@ int outfile_and_hashfile (hashcat_ctx_t *hashcat_ctx) if (tmp_hashfile_fp) { - #if defined (_POSIX) - fstat (fileno (tmp_hashfile_fp), &tmpstat_hashfile); - #endif - - #if defined (_WIN) - _fstat64 (fileno (tmp_hashfile_fp), &tmpstat_hashfile); - #endif + hc_fstat (fileno (tmp_hashfile_fp), &tmpstat_hashfile); fclose (tmp_hashfile_fp); } @@ -506,7 +495,7 @@ int outfile_and_hashfile (hashcat_ctx_t *hashcat_ctx) tmpstat_hashfile.st_blocks = 0; #endif - if (memcmp (&tmpstat_outfile, &tmpstat_hashfile, sizeof (hc_stat)) == 0) + if (memcmp (&tmpstat_outfile, &tmpstat_hashfile, sizeof (hc_stat_t)) == 0) { event_log_error (hashcat_ctx, "Hashfile and Outfile are not allowed to point to the same file"); diff --git a/src/outfile_check.c b/src/outfile_check.c index 8b74f87aa..80e01e29e 100644 --- a/src/outfile_check.c +++ b/src/outfile_check.c @@ -65,9 +65,9 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx) if (check_left == 0) { - struct stat outfile_check_stat; + hc_stat_t outfile_check_stat; - if (stat (root_directory, &outfile_check_stat) == 0) + if (hc_stat (root_directory, &outfile_check_stat) == 0) { u32 is_dir = S_ISDIR (outfile_check_stat.st_mode); @@ -95,9 +95,9 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx) { if (strcmp (out_info[j].file_name, out_info_new[i].file_name) == 0) { - struct stat outfile_stat; + hc_stat_t outfile_stat; - if (stat (out_info_new[i].file_name, &outfile_stat) == 0) + if (hc_stat (out_info_new[i].file_name, &outfile_stat) == 0) { if (outfile_stat.st_ctime == out_info[j].ctime) { @@ -128,15 +128,9 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx) { //hc_thread_mutex_lock (status_ctx->mux_display); - hc_stat outfile_stat; + hc_stat_t outfile_stat; - #if defined (_POSIX) - fstat (fileno (fp), &outfile_stat); - #endif - - #if defined (_WIN) - _fstat64 (fileno (fp), &outfile_stat); - #endif + hc_fstat (fileno (fp), &outfile_stat); if (outfile_stat.st_ctime > out_info[j].ctime) { @@ -353,9 +347,9 @@ int outcheck_ctx_init (hashcat_ctx_t *hashcat_ctx) outcheck_ctx->root_directory = user_options->outfile_check_dir; } - struct stat outfile_check_stat; + hc_stat_t outfile_check_stat; - if (stat (outcheck_ctx->root_directory, &outfile_check_stat) == 0) + if (hc_stat (outcheck_ctx->root_directory, &outfile_check_stat) == 0) { const u32 is_dir = S_ISDIR (outfile_check_stat.st_mode); diff --git a/src/restore.c b/src/restore.c index ac681604f..211700083 100644 --- a/src/restore.c +++ b/src/restore.c @@ -8,6 +8,7 @@ #include "memory.h" #include "event.h" #include "user_options.h" +#include "shared.h" #include "restore.h" #if defined (_WIN) @@ -288,9 +289,9 @@ int cycle_restore (hashcat_ctx_t *hashcat_ctx) if (rc_write_restore == -1) return -1; - struct stat st; + hc_stat_t st; - if (stat (eff_restore_file, &st) == 0) + if (hc_stat (eff_restore_file, &st) == 0) { if (unlink (eff_restore_file)) { diff --git a/src/rp.c b/src/rp.c index 9049fcd84..6c430d6ac 100644 --- a/src/rp.c +++ b/src/rp.c @@ -3,10 +3,6 @@ * License.....: MIT */ -#if defined (__APPLE__) -#include -#endif - #include "common.h" #include "types.h" #include "memory.h" diff --git a/src/rp_cpu.c b/src/rp_cpu.c index 533026936..77dc8a238 100644 --- a/src/rp_cpu.c +++ b/src/rp_cpu.c @@ -3,10 +3,6 @@ * License.....: MIT */ -#if defined (__APPLE__) -#include -#endif - #include "common.h" #include "types.h" #include "rp.h" diff --git a/src/shared.c b/src/shared.c index fb89e7ac6..c3aab7145 100644 --- a/src/shared.c +++ b/src/shared.c @@ -99,6 +99,30 @@ void naive_escape (char *s, size_t s_max, const char key_char, const char escape strncpy (s, s_escaped, s_max - 1); } +#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) +{ + return stat64 (pathname, buf); +} + +int hc_fstat (int fd, hc_stat_t *buf) +{ + return fstat64 (fd, buf); +} +#endif + void hc_sleep_msec (const u32 msec) { #if defined (_WIN) diff --git a/src/straight.c b/src/straight.c index cf28d4d0a..d1d5134a4 100644 --- a/src/straight.c +++ b/src/straight.c @@ -3,10 +3,6 @@ * License.....: MIT */ -#if defined (__APPLE__) -#include -#endif - #include "common.h" #include "types.h" #include "memory.h" @@ -272,9 +268,9 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) { char *l0_filename = user_options_extra->hc_workv[i]; - struct stat l0_stat; + hc_stat_t l0_stat; - if (stat (l0_filename, &l0_stat) == -1) + if (hc_stat (l0_filename, &l0_stat) == -1) { event_log_error (hashcat_ctx, "%s: %s", l0_filename, strerror (errno)); @@ -295,9 +291,9 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) { char *l1_filename = dictionary_files[d]; - struct stat l1_stat; + hc_stat_t l1_stat; - if (stat (l1_filename, &l1_stat) == -1) + if (hc_stat (l1_filename, &l1_stat) == -1) { event_log_error (hashcat_ctx, "%s: %s", l1_filename, strerror (errno)); @@ -345,9 +341,9 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) { char *l0_filename = user_options_extra->hc_workv[i]; - struct stat l0_stat; + hc_stat_t l0_stat; - if (stat (l0_filename, &l0_stat) == -1) + if (hc_stat (l0_filename, &l0_stat) == -1) { event_log_error (hashcat_ctx, "%s: %s", l0_filename, strerror (errno)); @@ -368,9 +364,9 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) { char *l1_filename = dictionary_files[d]; - struct stat l1_stat; + hc_stat_t l1_stat; - if (stat (l1_filename, &l1_stat) == -1) + if (hc_stat (l1_filename, &l1_stat) == -1) { event_log_error (hashcat_ctx, "%s: %s", l1_filename, strerror (errno)); @@ -409,9 +405,9 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) { char *l0_filename = user_options_extra->hc_workv[i]; - struct stat l0_stat; + hc_stat_t l0_stat; - if (stat (l0_filename, &l0_stat) == -1) + if (hc_stat (l0_filename, &l0_stat) == -1) { event_log_error (hashcat_ctx, "%s: %s", l0_filename, strerror (errno)); @@ -432,9 +428,9 @@ int straight_ctx_init (hashcat_ctx_t *hashcat_ctx) { char *l1_filename = dictionary_files[d]; - struct stat l1_stat; + hc_stat_t l1_stat; - if (stat (l1_filename, &l1_stat) == -1) + if (hc_stat (l1_filename, &l1_stat) == -1) { event_log_error (hashcat_ctx, "%s: %s", l1_filename, strerror (errno)); diff --git a/src/wordlist.c b/src/wordlist.c index 63aad658b..c56dd28f2 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -11,6 +11,7 @@ #include "dictstat.h" #include "thread.h" #include "rp_cpu.h" +#include "shared.h" #include "wordlist.h" u32 convert_from_hex (hashcat_ctx_t *hashcat_ctx, char *line_buf, const u32 line_len) @@ -283,13 +284,7 @@ u64 count_words (hashcat_ctx_t *hashcat_ctx, FILE *fd, const char *dictfile) d.cnt = 0; - #if defined (_POSIX) - fstat (fileno (fd), &d.stat); - #endif - - #if defined (_WIN) - _fstat64 (fileno (fd), &d.stat); - #endif + hc_fstat (fileno (fd), &d.stat); d.stat.st_mode = 0; d.stat.st_nlink = 0;