* Wrap everything related to *stat() into own functions

* Testwise remove early includes to stdin for OSX, see if they are still required
pull/570/head
jsteube 8 years ago
parent 80b3f52952
commit 93adde9d2f

@ -23,6 +23,7 @@
#define _GNU_SOURCE
#define _FILE_OFFSET_BITS 64
#define _LARGEFILE64_SOURCE
#define NOMINMAX 1

@ -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

@ -15,6 +15,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
#if defined (_WIN)
#include <windows.h>
@ -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;

@ -3,10 +3,6 @@
* License.....: MIT
*/
#if defined (__APPLE__)
#include <stdio.h>
#endif
#include "common.h"
#include "types.h"
#include "memory.h"

@ -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));

@ -3,10 +3,6 @@
* License.....: MIT
*/
#if defined (__APPLE__)
#include <stdio.h>
#endif
#include "common.h"
#include "types.h"
#include "memory.h"

@ -3,10 +3,6 @@
* License.....: MIT
*/
#if defined (__APPLE__)
#include <stdio.h>
#endif // __APPLE__
#include "common.h"
// basic tools

@ -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));

@ -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]);
}

@ -3,10 +3,6 @@
* License.....: MIT
*/
#if defined (__APPLE__)
#include <stdio.h>
#endif
#include "common.h"
#include "types.h"
#include "bitops.h"

@ -3,10 +3,6 @@
* License.....: MIT
*/
#if defined (__APPLE__)
#include <stdio.h>
#endif
#include "common.h"
#include "types.h"
#include "memory.h"

@ -3,11 +3,12 @@
* License.....: MIT
*/
#include "common.h"
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include "common.h"
#include "types.h"
#include "user_options.h"
#include "usage.h"

@ -3,10 +3,11 @@
* License.....: MIT
*/
#include "common.h"
#include <stdio.h>
#include <assert.h>
#include "common.h"
#include "types.h"
#include "memory.h"
#include "user_options.h"

@ -3,10 +3,6 @@
* License.....: MIT
*/
#if defined (__APPLE__)
#include <stdio.h>
#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);

@ -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;
}

@ -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");

@ -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);

@ -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))
{

@ -3,10 +3,6 @@
* License.....: MIT
*/
#if defined (__APPLE__)
#include <stdio.h>
#endif
#include "common.h"
#include "types.h"
#include "memory.h"

@ -3,10 +3,6 @@
* License.....: MIT
*/
#if defined (__APPLE__)
#include <stdio.h>
#endif
#include "common.h"
#include "types.h"
#include "rp.h"

@ -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)

@ -3,10 +3,6 @@
* License.....: MIT
*/
#if defined (__APPLE__)
#include <stdio.h>
#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));

@ -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;

Loading…
Cancel
Save