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

Rewrite hc_fopen to better handling file descriptor locking/unlocking functions, saving kernels binary from plain to gzip format

This commit is contained in:
Gabriele Gristina 2019-07-01 01:30:24 +02:00
parent 28a04d80b1
commit 5679ca3344
65 changed files with 237 additions and 201 deletions

View File

@ -13,7 +13,7 @@
#include <errno.h>
#include <fcntl.h>
int lock_file (FILE *fp);
int unlock_file (FILE *fp);
int hc_lockfile (HCFILE *fp);
int hc_unlockfile (HCFILE *fp);
#endif // _LOCKING_H

View File

@ -66,7 +66,7 @@ void hc_string_trim_leading (char *s);
int _wopen(const char *path, int oflag, ...);
#endif
bool hc_fopen (HCFILE *fp, const char *path, char *mode);
bool hc_fopen (HCFILE *fp, const char *path, char *mode, int file_format);
int hc_fscanf (HCFILE *fp, const char *format, void *ptr);
int hc_fprintf (HCFILE *fp, const char *format, ...);
int hc_vfprintf (HCFILE *fp, const char *format, va_list ap);

View File

@ -993,6 +993,7 @@ typedef struct link_speed
typedef struct hc_fp
{
int fd;
FILE *pfp;
gzFile gfp;
@ -1001,6 +1002,13 @@ typedef struct hc_fp
const char *path;
} HCFILE;
typedef enum hcfile_format
{
HCFILE_FORMAT_PLAIN = 0,
HCFILE_FORMAT_GZIP = 1,
} hcfile_format_t;
#include "ext_nvrtc.h"
#include "ext_cuda.h"
#include "ext_OpenCL.h"

View File

@ -441,8 +441,9 @@ static bool opencl_test_instruction (hashcat_ctx_t *hashcat_ctx, cl_context cont
static bool read_kernel_binary (hashcat_ctx_t *hashcat_ctx, const char *kernel_file, size_t *kernel_lengths, char **kernel_sources, const bool force_recompile)
{
HCFILE fp;
bool is_gzip = false;
if (hc_fopen (&fp, kernel_file, "rb") != false)
if (hc_fopen (&fp, kernel_file, "rb", false) != false)
{
struct stat st;
@ -453,15 +454,23 @@ static bool read_kernel_binary (hashcat_ctx_t *hashcat_ctx, const char *kernel_f
return false;
}
is_gzip = fp.is_gzip;
#define EXTRASZ 100
char *buf = (char *) hcmalloc (st.st_size + 1 + EXTRASZ);
size_t klen = st.st_size;
size_t num_read = hc_fread (buf, sizeof (char), st.st_size, &fp);
if (is_gzip) klen *= 10; // must be >= of uncompress len
char *buf = (char *) hcmalloc (klen + 1 + EXTRASZ);
size_t num_read = hc_fread (buf, sizeof (char), klen, &fp);
hc_fclose (&fp);
if (num_read != (size_t) st.st_size)
if (is_gzip && klen > num_read) klen = num_read;
if (num_read != (size_t) klen)
{
event_log_error (hashcat_ctx, "%s: %s", kernel_file, strerror (errno));
@ -470,7 +479,7 @@ static bool read_kernel_binary (hashcat_ctx_t *hashcat_ctx, const char *kernel_f
return false;
}
buf[st.st_size] = 0;
buf[klen] = 0;
if (force_recompile == true)
{
@ -480,12 +489,12 @@ static bool read_kernel_binary (hashcat_ctx_t *hashcat_ctx, const char *kernel_f
time_t tlog = time (NULL);
const int extra_len = snprintf (buf + st.st_size, EXTRASZ, "\n//%u\n", (u32) tlog);
const int extra_len = snprintf (buf + klen, EXTRASZ, "\n//%u\n", (u32) tlog);
st.st_size += extra_len;
klen += extra_len;
}
kernel_lengths[0] = (size_t) st.st_size;
kernel_lengths[0] = (size_t) klen;
kernel_sources[0] = buf;
}
@ -505,16 +514,15 @@ static bool write_kernel_binary (hashcat_ctx_t *hashcat_ctx, char *kernel_file,
{
HCFILE fp;
if (hc_fopen (&fp, kernel_file, "wb") == false)
// change HCFILE_FORMAT_GZIP to HCFILE_FORMAT_PLAIN to write kernel binary uncompressed
if (hc_fopen (&fp, kernel_file, "wb", HCFILE_FORMAT_GZIP) == false)
{
event_log_error (hashcat_ctx, "%s: %s", kernel_file, strerror (errno));
return false;
}
fp.is_gzip = false;
if (lock_file (fp.pfp) == -1)
if (hc_lockfile (&fp) == -1)
{
hc_fclose (&fp);

View File

@ -541,7 +541,7 @@ u64 brain_compute_attack_wordlist (const char *filename)
HCFILE fp;
hc_fopen (&fp, filename, "rb");
hc_fopen (&fp, filename, "rb", false);
while (!hc_feof (&fp))
{
@ -613,7 +613,7 @@ u32 brain_auth_challenge (void)
HCFILE fp;
if (hc_fopen (&fp, urandom, "rb") == false)
if (hc_fopen (&fp, urandom, "rb", HCFILE_FORMAT_PLAIN) == false)
{
brain_logging (stderr, 0, "%s: %s\n", urandom, strerror (errno));
@ -1599,7 +1599,7 @@ bool brain_server_read_hash_dump (brain_server_db_hash_t *brain_server_db_hash,
HCFILE fp;
if (hc_fopen (&fp, file, "rb") == false)
if (hc_fopen (&fp, file, "rb", HCFILE_FORMAT_PLAIN) == false)
{
brain_logging (stderr, 0, "%s: %s\n", file, strerror (errno));
@ -1655,7 +1655,7 @@ bool brain_server_write_hash_dump (brain_server_db_hash_t *brain_server_db_hash,
HCFILE fp;
if (hc_fopen (&fp, file, "wb") == false)
if (hc_fopen (&fp, file, "wb", HCFILE_FORMAT_PLAIN) == false)
{
brain_logging (stderr, 0, "%s: %s\n", file, strerror (errno));
@ -1663,8 +1663,6 @@ bool brain_server_write_hash_dump (brain_server_db_hash_t *brain_server_db_hash,
}
else
{
fp.is_gzip = false;
const size_t nwrite = hc_fwrite (brain_server_db_hash->long_buf, sizeof (brain_server_hash_long_t), brain_server_db_hash->long_cnt, &fp);
if (nwrite != (size_t) brain_server_db_hash->long_cnt)
@ -1800,7 +1798,7 @@ bool brain_server_read_attack_dump (brain_server_db_attack_t *brain_server_db_at
HCFILE fp;
if (hc_fopen (&fp, file, "rb") == false)
if (hc_fopen (&fp, file, "rb", HCFILE_FORMAT_PLAIN) == false)
{
brain_logging (stderr, 0, "%s: %s\n", file, strerror (errno));
@ -1856,7 +1854,7 @@ bool brain_server_write_attack_dump (brain_server_db_attack_t *brain_server_db_a
HCFILE fp;
if (hc_fopen (&fp, file, "wb") == false)
if (hc_fopen (&fp, file, "wb", HCFILE_FORMAT_PLAIN) == false)
{
brain_logging (stderr, 0, "%s: %s\n", file, strerror (errno));
@ -1864,8 +1862,6 @@ bool brain_server_write_attack_dump (brain_server_db_attack_t *brain_server_db_a
}
else
{
fp.is_gzip = false;
// storing should not include reserved attacks only finished
const size_t nwrite = hc_fwrite (brain_server_db_attack->long_buf, sizeof (brain_server_attack_long_t), brain_server_db_attack->long_cnt, &fp);

View File

@ -63,14 +63,14 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx)
HCFILE fp1;
HCFILE fp2;
if (hc_fopen (&fp1, dictfile1, "rb") == false)
if (hc_fopen (&fp1, dictfile1, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", dictfile1, strerror (errno));
return -1;
}
if (hc_fopen (&fp2, dictfile2, "rb") == false)
if (hc_fopen (&fp2, dictfile2, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", dictfile2, strerror (errno));
@ -166,14 +166,14 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx)
HCFILE fp1;
HCFILE fp2;
if (hc_fopen (&fp1, dictfile1, "rb") == false)
if (hc_fopen (&fp1, dictfile1, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", dictfile1, strerror (errno));
return -1;
}
if (hc_fopen (&fp2, dictfile2, "rb") == false)
if (hc_fopen (&fp2, dictfile2, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", dictfile2, strerror (errno));
@ -297,14 +297,14 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx)
HCFILE fp1;
HCFILE fp2;
if (hc_fopen (&fp1, dictfile1, "rb") == false)
if (hc_fopen (&fp1, dictfile1, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", dictfile1, strerror (errno));
return -1;
}
if (hc_fopen (&fp2, dictfile2, "rb") == false)
if (hc_fopen (&fp2, dictfile2, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", dictfile2, strerror (errno));
@ -389,7 +389,7 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx)
HCFILE fp;
if (hc_fopen (&fp, dictfile, "rb") == false)
if (hc_fopen (&fp, dictfile, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", dictfile, strerror (errno));

View File

@ -94,7 +94,7 @@ int cpu_crc32 (const char *filename, u8 keytab[64])
HCFILE fp;
hc_fopen (&fp, filename, "rb");
hc_fopen (&fp, filename, "rb", HCFILE_FORMAT_PLAIN);
#define MAX_KEY_SIZE (1024 * 1024)

View File

@ -105,20 +105,18 @@ int debugfile_init (hashcat_ctx_t *hashcat_ctx)
debugfile_ctx->filename = user_options->debug_file;
if (debugfile_ctx->filename)
{
HCFILE fp;
if (hc_fopen (&fp, debugfile_ctx->filename, "ab") == false)
if (debugfile_ctx->filename)
{
if (hc_fopen (&fp, debugfile_ctx->filename, "ab", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "Could not open --debug-file file for writing.");
return -1;
}
fp.is_gzip = false;
if (lock_file (fp.pfp) == -1)
if (hc_lockfile (&fp) == -1)
{
hc_fclose (&fp);
@ -131,11 +129,11 @@ int debugfile_init (hashcat_ctx_t *hashcat_ctx)
}
else
{
HCFILE fp_tmp;
fp_tmp.is_gzip = false;
fp_tmp.pfp = stdout;
fp.is_gzip = false;
fp.pfp = stdout;
fp.fd = fileno (stdout);
debugfile_ctx->fp = &fp_tmp;
debugfile_ctx->fp = &fp;
}
return 0;

View File

@ -98,7 +98,7 @@ void dictstat_read (hashcat_ctx_t *hashcat_ctx)
HCFILE fp;
if (hc_fopen (&fp, dictstat_ctx->filename, "rb") == false)
if (hc_fopen (&fp, dictstat_ctx->filename, "rb", HCFILE_FORMAT_PLAIN) == false)
{
// first run, file does not exist, do not error out
@ -186,16 +186,14 @@ int dictstat_write (hashcat_ctx_t *hashcat_ctx)
HCFILE fp;
if (hc_fopen (&fp, dictstat_ctx->filename, "wb") == false)
if (hc_fopen (&fp, dictstat_ctx->filename, "wb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", dictstat_ctx->filename, strerror (errno));
return -1;
}
fp.is_gzip = false;
if (lock_file (fp.pfp) == -1)
if (hc_lockfile (&fp) == -1)
{
hc_fclose (&fp);

View File

@ -429,7 +429,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
HCFILE fp;
if (hc_fopen (&fp, dictfile, "rb") == false)
if (hc_fopen (&fp, dictfile, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", dictfile, strerror (errno));
@ -749,7 +749,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
HCFILE base_fp;
if (hc_fopen (&base_fp, base_file, "rb") == false)
if (hc_fopen (&base_fp, base_file, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", base_file, strerror (errno));
@ -758,7 +758,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
HCFILE combs_fp;
if (hc_fopen (&combs_fp, combs_file, "rb") == false)
if (hc_fopen (&combs_fp, combs_file, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", combs_file, strerror (errno));
@ -1324,7 +1324,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
HCFILE combs_fp;
if (hc_fopen (&combs_fp, dictfile, "rb") == false)
if (hc_fopen (&combs_fp, dictfile, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", dictfile, strerror (errno));
@ -1390,7 +1390,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
HCFILE combs_fp;
if (hc_fopen (&combs_fp, dictfilec, "rb") == false)
if (hc_fopen (&combs_fp, dictfilec, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", combinator_ctx->dict2, strerror (errno));
@ -1405,7 +1405,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
HCFILE combs_fp;
if (hc_fopen (&combs_fp, dictfilec, "rb") == false)
if (hc_fopen (&combs_fp, dictfilec, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", dictfilec, strerror (errno));
@ -1418,7 +1418,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param)
HCFILE fp;
if (hc_fopen (&fp, dictfile, "rb") == false)
if (hc_fopen (&fp, dictfile, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", dictfile, strerror (errno));

View File

@ -186,7 +186,7 @@ int save_hash (hashcat_ctx_t *hashcat_ctx)
HCFILE fp;
if (hc_fopen (&fp, new_hashfile, "wb") == false)
if (hc_fopen (&fp, new_hashfile, "wb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", new_hashfile, strerror (errno));
@ -196,9 +196,7 @@ int save_hash (hashcat_ctx_t *hashcat_ctx)
return -1;
}
fp.is_gzip = false;
if (lock_file (fp.pfp) == -1)
if (hc_lockfile (&fp) == -1)
{
hc_fclose (&fp);
@ -678,7 +676,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
{
HCFILE fp;
if (hc_fopen (&fp, hashfile, "rb") == false)
if (hc_fopen (&fp, hashfile, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", hashfile, strerror (errno));
@ -998,7 +996,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx)
{
HCFILE fp;
if (hc_fopen (&fp, hashfile, "rb") == false)
if (hc_fopen (&fp, hashfile, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", hashfile, strerror (errno));
@ -1794,9 +1792,7 @@ int hashes_init_selftest (hashcat_ctx_t *hashcat_ctx)
HCFILE fp;
hc_fopen (&fp, tmpfile_bin, "wb");
fp.is_gzip = false;
hc_fopen (&fp, tmpfile_bin, "wb", false);
const size_t st_hash_len = strlen (hashconfig->st_hash);

View File

@ -112,7 +112,7 @@ static int hm_SYSFS_get_fan_speed_current (hashcat_ctx_t *hashcat_ctx, const int
HCFILE fp_cur;
if (hc_fopen (&fp_cur, path_cur, "r") == false)
if (hc_fopen (&fp_cur, path_cur, "r", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", path_cur, strerror (errno));
@ -140,7 +140,7 @@ static int hm_SYSFS_get_fan_speed_current (hashcat_ctx_t *hashcat_ctx, const int
HCFILE fp_max;
if (hc_fopen (&fp_max, path_max, "r") == false)
if (hc_fopen (&fp_max, path_max, "r", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", path_max, strerror (errno));
@ -202,7 +202,7 @@ static int hm_SYSFS_get_temperature_current (hashcat_ctx_t *hashcat_ctx, const i
HCFILE fp;
if (hc_fopen (&fp, path, "r") == false)
if (hc_fopen (&fp, path, "r", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno));
@ -247,7 +247,7 @@ static int hm_SYSFS_get_pp_dpm_sclk (hashcat_ctx_t *hashcat_ctx, const int backe
HCFILE fp;
if (hc_fopen (&fp, path, "r") == false)
if (hc_fopen (&fp, path, "r", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno));
@ -302,7 +302,7 @@ static int hm_SYSFS_get_pp_dpm_mclk (hashcat_ctx_t *hashcat_ctx, const int backe
HCFILE fp;
if (hc_fopen (&fp, path, "r") == false)
if (hc_fopen (&fp, path, "r", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno));
@ -357,7 +357,7 @@ static int hm_SYSFS_get_pp_dpm_pcie (hashcat_ctx_t *hashcat_ctx, const int backe
HCFILE fp;
if (hc_fopen (&fp, path, "r") == false)
if (hc_fopen (&fp, path, "r", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno));
@ -462,7 +462,7 @@ static int nvml_init (hashcat_ctx_t *hashcat_ctx)
{
HCFILE nvml_lib;
if (hc_fopen (&nvml_lib, "/proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/NVIDIA Corporation/Global/NVSMI/NVSMIPATH", "rb") == false)
if (hc_fopen (&nvml_lib, "/proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/NVIDIA Corporation/Global/NVSMI/NVSMIPATH", "rb", HCFILE_FORMAT_PLAIN) == false)
{
//if (user_options->quiet == false)
// event_log_error (hashcat_ctx, "NVML library load failed: %m. Proceeding without NVML HWMon enabled.");

View File

@ -24,7 +24,7 @@ bool initialize_keyboard_layout_mapping (const char *filename, keyboard_layout_m
HCFILE fp;
if (hc_fopen (&fp, filename, "r") == false) return false;
if (hc_fopen (&fp, filename, "r", HCFILE_FORMAT_PLAIN) == false) return false;
int maps_cnt = 0;

View File

@ -6,10 +6,11 @@
#include "common.h"
#include "types.h"
#include "locking.h"
#include "shared.h"
#if defined (F_SETLKW)
int lock_file (FILE *fp)
int hc_lockfile (HCFILE *fp)
{
if (!fp) return -1;
@ -20,7 +21,7 @@ int lock_file (FILE *fp)
lock.l_type = F_WRLCK;
/* Needs this loop because a signal may interrupt a wait for lock */
while (fcntl (fileno (fp), F_SETLKW, &lock))
while (fcntl (hc_fileno (fp), F_SETLKW, &lock))
{
if (errno != EINTR) return -1;
}
@ -28,7 +29,7 @@ int lock_file (FILE *fp)
return 0;
}
int unlock_file (FILE *fp)
int hc_unlockfile (HCFILE *fp)
{
if (!fp) return -1;
@ -38,7 +39,7 @@ int unlock_file (FILE *fp)
lock.l_type = F_UNLCK;
if (fcntl (fileno (fp), F_SETLK, &lock))
if (fcntl (hc_fileno (fp), F_SETLK, &lock))
{
return -1;
}
@ -48,14 +49,14 @@ int unlock_file (FILE *fp)
#else
int lock_file (MAYBE_UNUSED FILE *fp)
int hc_lockfile (MAYBE_UNUSED HCFILE *fp)
{
// we should put windows specific code here
return 0;
}
int unlock_file (MAYBE_UNUSED FILE *fp)
int hc_unlockfile (MAYBE_UNUSED HCFILE *fp)
{
// we should put windows specific code here

View File

@ -45,16 +45,14 @@ void logfile_append (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...)
HCFILE fp;
if (hc_fopen (&fp, logfile_ctx->logfile, "ab") == false)
if (hc_fopen (&fp, logfile_ctx->logfile, "ab", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", logfile_ctx->logfile, strerror (errno));
return;
}
fp.is_gzip = false;
lock_file (fp.pfp);
hc_lockfile (&fp);
va_list ap;

View File

@ -107,15 +107,13 @@ int loopback_write_open (hashcat_ctx_t *hashcat_ctx)
HCFILE fp;
if (hc_fopen (&fp, loopback_ctx->filename, "ab") == false)
if (hc_fopen (&fp, loopback_ctx->filename, "ab", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", loopback_ctx->filename, strerror (errno));
return -1;
}
fp.is_gzip = false;
loopback_ctx->fp = &fp;
loopback_ctx->unused = true;
@ -160,13 +158,13 @@ void loopback_write_append (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ptr, con
loopback_format_plain (hashcat_ctx, plain_ptr, plain_len);
lock_file (fp->pfp);
hc_lockfile (fp);
hc_fwrite (EOL, strlen (EOL), 1, fp);
hc_fflush (fp);
if (unlock_file (fp->pfp))
if (hc_unlockfile (fp))
{
event_log_error (hashcat_ctx, "%s: Failed to unlock file", loopback_ctx->filename);
}

View File

@ -376,7 +376,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return -1;
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return -1;
char *in = (char *) hcmalloc (sizeof (hccapx_t));

View File

@ -351,7 +351,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return -1;
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return -1;
char *in = (char *) hcmalloc (sizeof (hccapx_t));

View File

@ -95,7 +95,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
HCFILE fp;
if (hc_fopen (&fp, (const char *) line_buf, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, (const char *) line_buf, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
psafe3_t in;

View File

@ -148,7 +148,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define TC_HEADER_SIZE 512

View File

@ -148,7 +148,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define TC_HEADER_SIZE 512

View File

@ -146,7 +146,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define TC_HEADER_SIZE 512

View File

@ -146,7 +146,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define TC_HEADER_SIZE 512

View File

@ -146,7 +146,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define TC_HEADER_SIZE 512

View File

@ -146,7 +146,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define TC_HEADER_SIZE 512

View File

@ -148,7 +148,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define TC_HEADER_SIZE 512

View File

@ -148,7 +148,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define TC_HEADER_SIZE 512

View File

@ -148,7 +148,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define TC_HEADER_SIZE 512

View File

@ -160,7 +160,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define TC_HEADER_SIZE 512

View File

@ -160,7 +160,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define TC_HEADER_SIZE 512

View File

@ -160,7 +160,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define TC_HEADER_SIZE 512

View File

@ -158,7 +158,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
HCFILE fp;
if (hc_fopen (&fp, (const char *) line_buf, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, (const char *) line_buf, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
psafe2_hdr buf;

View File

@ -174,7 +174,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -174,7 +174,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -174,7 +174,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -172,7 +172,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -172,7 +172,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -172,7 +172,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -174,7 +174,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -174,7 +174,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -174,7 +174,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -175,7 +175,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -175,7 +175,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -175,7 +175,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -174,7 +174,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -174,7 +174,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -174,7 +174,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -175,7 +175,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -175,7 +175,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -175,7 +175,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -178,7 +178,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -178,7 +178,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -178,7 +178,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE
HCFILE fp;
if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, hashes->hashfile, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
#define VC_HEADER_SIZE 512

View File

@ -353,7 +353,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE
HCFILE fp;
if (hc_fopen (&fp, (const char *) line_buf, "rb") == false) return (PARSER_HASH_FILE);
if (hc_fopen (&fp, (const char *) line_buf, "rb", HCFILE_FORMAT_PLAIN) == false) return (PARSER_HASH_FILE);
struct luks_phdr hdr;

View File

@ -584,7 +584,7 @@ static int mp_setup_usr (hashcat_ctx_t *hashcat_ctx, cs_t *mp_sys, cs_t *mp_usr,
{
HCFILE fp;
if (hc_fopen (&fp, buf, "rb") == false)
if (hc_fopen (&fp, buf, "rb", HCFILE_FORMAT_PLAIN) == false)
{
const int rc = mp_expand (hashcat_ctx, buf, strlen (buf), mp_sys, mp_usr, userindex, 1);
@ -712,7 +712,7 @@ static int sp_setup_tbl (hashcat_ctx_t *hashcat_ctx)
HCFILE fp;
if (hc_fopen (&fp, hcstat, "rb") == false)
if (hc_fopen (&fp, hcstat, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", hcstat, strerror (errno));
@ -1462,7 +1462,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx)
{
HCFILE mask_fp;
if (hc_fopen (&mask_fp, arg, "r") == false)
if (hc_fopen (&mask_fp, arg, "r", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", arg, strerror (errno));
@ -1555,7 +1555,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx)
HCFILE mask_fp;
if (hc_fopen (&mask_fp, arg, "r") == false)
if (hc_fopen (&mask_fp, arg, "r", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", arg, strerror (errno));
@ -1629,7 +1629,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx)
HCFILE mask_fp;
if (hc_fopen (&mask_fp, arg, "r") == false)
if (hc_fopen (&mask_fp, arg, "r", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", arg, strerror (errno));

View File

@ -392,16 +392,14 @@ int outfile_write_open (hashcat_ctx_t *hashcat_ctx)
HCFILE fp;
if (hc_fopen (&fp, outfile_ctx->filename, "ab") == false)
if (hc_fopen (&fp, outfile_ctx->filename, "ab", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", outfile_ctx->filename, strerror (errno));
return -1;
}
fp.is_gzip = false;
if (lock_file (fp.pfp) == -1)
if (hc_lockfile (&fp) == -1)
{
hc_fclose (&fp);

View File

@ -157,7 +157,7 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx)
{
HCFILE fp;
if (hc_fopen (&fp, out_info[j].file_name, "rb") == false) continue;
if (hc_fopen (&fp, out_info[j].file_name, "rb", HCFILE_FORMAT_PLAIN) == false) continue;
//hc_thread_mutex_lock (status_ctx->mux_display);

View File

@ -18,7 +18,7 @@ static int check_running_process (hashcat_ctx_t *hashcat_ctx)
HCFILE fp;
if (hc_fopen (&fp, pidfile_filename, "rb") == false) return 0;
if (hc_fopen (&fp, pidfile_filename, "rb", HCFILE_FORMAT_PLAIN) == false) return 0;
pidfile_data_t *pd = (pidfile_data_t *) hcmalloc (sizeof (pidfile_data_t));
@ -155,15 +155,13 @@ static int write_pidfile (hashcat_ctx_t *hashcat_ctx)
HCFILE fp;
if (hc_fopen (&fp, pidfile_filename, "wb") == false)
if (hc_fopen (&fp, pidfile_filename, "wb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", pidfile_filename, strerror (errno));
return -1;
}
fp.is_gzip = false;
hc_fwrite (pd, sizeof (pidfile_data_t), 1, &fp);
hc_fflush (&fp);

View File

@ -292,13 +292,18 @@ void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, cons
tmp_buf[tmp_len] = 0;
lock_file (potfile_ctx->fp);
HCFILE fp;
fp.is_gzip = false;
fp.pfp = potfile_ctx->fp;
fp.fd = fileno (fp.pfp);
hc_lockfile (&fp);
fprintf (potfile_ctx->fp, "%s" EOL, tmp_buf);
fflush (potfile_ctx->fp);
if (unlock_file (potfile_ctx->fp))
if (hc_unlockfile (&fp))
{
event_log_error (hashcat_ctx, "%s: Failed to unlock file.", potfile_ctx->filename);
}
@ -529,6 +534,7 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx)
HCFILE fp;
fp.is_gzip = false;
fp.pfp = potfile_ctx->fp;
fp.fd = fileno (fp.pfp);
while (!feof (potfile_ctx->fp))
{

View File

@ -56,7 +56,7 @@ static int read_restore (hashcat_ctx_t *hashcat_ctx)
HCFILE fp;
if (hc_fopen (&fp, eff_restore_file, "rb") == false)
if (hc_fopen (&fp, eff_restore_file, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "Restore file '%s': %s", eff_restore_file, strerror (errno));
@ -205,15 +205,13 @@ static int write_restore (hashcat_ctx_t *hashcat_ctx)
HCFILE fp;
if (hc_fopen (&fp, new_restore_file, "wb") == false)
if (hc_fopen (&fp, new_restore_file, "wb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", new_restore_file, strerror (errno));
return -1;
}
fp.is_gzip = false;
if (setvbuf (fp.pfp, NULL, _IONBF, 0))
{
event_log_error (hashcat_ctx, "setvbuf file '%s': %s", new_restore_file, strerror (errno));

View File

@ -737,7 +737,7 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32
u32 rule_line = 0;
if (hc_fopen (&fp, rp_file, "rb") == false)
if (hc_fopen (&fp, rp_file, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", rp_file, strerror (errno));

View File

@ -8,6 +8,7 @@
#include "convert.h"
#include "shared.h"
#include "memory.h"
#include <errno.h>
#if defined (__CYGWIN__)
#include <sys/cygwin.h>
@ -351,7 +352,7 @@ bool hc_path_has_bom (const char *path)
HCFILE fp;
if (hc_fopen (&fp, path, "rb") == false) return false;
if (hc_fopen (&fp, path, "rb", HCFILE_FORMAT_PLAIN) == false) return false;
const size_t nread = hc_fread (buf, 1, sizeof (buf), &fp);
@ -614,33 +615,76 @@ int _wopen(const char *path, int oflag, ...)
}
#endif
bool hc_fopen (HCFILE *fp, const char *path, char *mode)
bool hc_fopen (HCFILE *fp, const char *path, char *mode, int file_format)
{
unsigned char check[3] = { 0 };
if (!path || !mode) return false;
FILE *fp_tmp = fopen (path, mode);
int oflag = -1;
if (fp_tmp == NULL) return false;
int fmode = S_IRUSR|S_IWUSR;
check[0] = fgetc (fp_tmp);
check[1] = fgetc (fp_tmp);
check[2] = fgetc (fp_tmp);
fp->is_gzip = false;
if (check[0] == 0x1f && check[1] == 0x8b && check[2] == 0x08)
if (!strncmp (mode, "a", 1) || !strncmp (mode, "ab", 2))
{
fclose (fp_tmp);
oflag = O_WRONLY | O_CREAT | O_APPEND;
if (!(fp->gfp = gzopen (path, mode))) return false;
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
if (!strncmp (mode, "ab", 2)) oflag |= O_BINARY;
#endif
}
else if (!strncmp (mode, "r", 1) || !strncmp (mode, "rb", 2))
{
oflag = O_RDONLY;
fmode = -1;
fp->is_gzip = true;
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
if (!strncmp (mode, "rb", 2)) oflag |= O_BINARY;
#endif
}
else if (!strncmp (mode, "w", 1) || !strncmp (mode, "wb", 2))
{
oflag = O_WRONLY | O_CREAT | O_TRUNC;
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
if (!strncmp (mode, "wb", 2)) oflag |= O_BINARY;
#endif
}
else
{
fp->pfp = fp_tmp;
// ADD more strncmp to handle more "mode"
return false;
}
rewind (fp->pfp);
if (file_format == HCFILE_FORMAT_PLAIN)
{
unsigned char check[3] = { 0 };
int fd_tmp = open (path, O_RDONLY);
lseek (fd_tmp, 0, SEEK_SET);
size_t s = read (fd_tmp, check, sizeof(check));
if (s == 3 && (check[0] == 0x1f && check[1] == 0x8b && check[2] == 0x08)) file_format = HCFILE_FORMAT_GZIP;
close (fd_tmp);
}
fp->fd = (fmode == -1) ? open (path, oflag) : open (path, oflag, fmode);
if (fp->fd == -1) return false;
if (file_format == HCFILE_FORMAT_PLAIN)
{
if (!(fp->pfp = fdopen (fp->fd, mode))) return false;
fp->is_gzip = false;
}
else // HCFILE_FORMAT_GZIP
{
if (!(fp->gfp = gzdopen (fp->fd, mode))) return false;
fp->is_gzip = true;
fp->pfp = NULL;
}
fp->path = path;
@ -651,9 +695,9 @@ bool hc_fopen (HCFILE *fp, const char *path, char *mode)
size_t hc_fread (void *ptr, size_t size, size_t nmemb, HCFILE *fp)
{
size_t n = 0;
size_t n = -1;
if (fp == NULL) return -1;
if (fp == NULL) return n;
if (fp->is_gzip)
n = gzfread (ptr, size, nmemb, fp->gfp);
@ -665,9 +709,9 @@ size_t hc_fread (void *ptr, size_t size, size_t nmemb, HCFILE *fp)
size_t hc_fwrite (void *ptr, size_t size, size_t nmemb, HCFILE *fp)
{
size_t n = 0;
size_t n = -1;
if (fp == NULL) return -1;
if (fp == NULL) return n;
if (fp->is_gzip)
n = gzfwrite (ptr, size, nmemb, fp->gfp);
@ -681,9 +725,9 @@ size_t hc_fwrite (void *ptr, size_t size, size_t nmemb, HCFILE *fp)
int hc_fseek (HCFILE *fp, off_t offset, int whence)
{
int r = 0;
int r = -1;
if (fp == NULL) return -1;
if (fp == NULL) return r;
if (fp->is_gzip)
r = gzseek (fp->gfp, (z_off_t) offset, whence);
@ -719,9 +763,9 @@ off_t hc_ftell (HCFILE *fp)
int hc_fputc (int c, HCFILE *fp)
{
int r = 0;
int r = -1;
if (fp == NULL) return -1;
if (fp == NULL) return r;
if (fp->is_gzip)
r = gzputc (fp->gfp, c);
@ -733,9 +777,9 @@ int hc_fputc (int c, HCFILE *fp)
int hc_fgetc (HCFILE *fp)
{
int r = 0;
int r = -1;
if (fp == NULL) return -1;
if (fp == NULL) return r;
if (fp->is_gzip)
r = gzgetc (fp->gfp);
@ -763,7 +807,7 @@ int hc_vfprintf (HCFILE *fp, const char *format, va_list ap)
{
int r = -1;
if (fp == NULL) return -1;
if (fp == NULL) return r;
if (fp->is_gzip)
r = gzvprintf (fp->gfp, format, ap);
@ -775,10 +819,11 @@ int hc_vfprintf (HCFILE *fp, const char *format, va_list ap)
int hc_fprintf (HCFILE *fp, const char *format, ...)
{
va_list ap;
int r = -1;
if (fp == NULL) return -1;
if (fp == NULL) return r;
va_list ap;
va_start (ap, format);
@ -818,29 +863,16 @@ int hc_fscanf (HCFILE *fp, const char *format, void *ptr)
int hc_fileno (HCFILE *fp)
{
int r = -1;
if (fp == NULL) return 1;
if (fp == NULL) return -1;
if (fp->is_gzip)
{
int rdup = fileno (fopen (fp->path, fp->mode));
r = dup (rdup);
close (rdup);
}
else
r = fileno (fp->pfp);
return r;
return fp->fd;
}
int hc_feof (HCFILE *fp)
{
int r = -1;
if (fp == NULL) return -1;
if (fp == NULL) return r;
if (fp->is_gzip)
r = gzeof (fp->gfp);
@ -869,6 +901,9 @@ void hc_fclose (HCFILE *fp)
else
fclose (fp->pfp);
close (fp->fd);
fp->fd = -1;
fp->is_gzip = false;
fp->path = NULL;
@ -886,7 +921,7 @@ bool hc_same_files (char *file1, char *file2)
HCFILE fp;
if (hc_fopen (&fp, file1, "r") == true)
if (hc_fopen (&fp, file1, "r", HCFILE_FORMAT_PLAIN) == true)
{
if (fstat (hc_fileno (&fp), &tmpstat_file1))
{
@ -900,7 +935,7 @@ bool hc_same_files (char *file1, char *file2)
do_check++;
}
if (hc_fopen (&fp, file2, "r") == true)
if (hc_fopen (&fp, file2, "r", HCFILE_FORMAT_PLAIN) == true)
{
if (fstat (hc_fileno (&fp), &tmpstat_file2))
{

View File

@ -73,7 +73,7 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param,
{
HCFILE fp;
if (hc_fopen (&fp, filename, "ab") == false)
if (hc_fopen (&fp, filename, "ab", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", filename, strerror (errno));
@ -82,7 +82,7 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param,
fp.is_gzip = false;
if (lock_file (fp.pfp) == -1)
if (hc_lockfile (&fp) == -1)
{
hc_fclose (&fp);

View File

@ -72,7 +72,7 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx)
HCFILE fp;
if (hc_fopen (&fp, straight_ctx->dict, "rb") == false)
if (hc_fopen (&fp, straight_ctx->dict, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", straight_ctx->dict, strerror (errno));
@ -107,7 +107,7 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx)
{
HCFILE fp;
if (hc_fopen (&fp, combinator_ctx->dict1, "rb") == false)
if (hc_fopen (&fp, combinator_ctx->dict1, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", combinator_ctx->dict1, strerror (errno));
@ -129,7 +129,7 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx)
{
HCFILE fp;
if (hc_fopen (&fp, combinator_ctx->dict2, "rb") == false)
if (hc_fopen (&fp, combinator_ctx->dict2, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", combinator_ctx->dict2, strerror (errno));
@ -175,7 +175,7 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx)
HCFILE fp;
if (hc_fopen (&fp, straight_ctx->dict, "rb") == false)
if (hc_fopen (&fp, straight_ctx->dict, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", straight_ctx->dict, strerror (errno));

View File

@ -70,7 +70,7 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx)
HCFILE fp;
if (hc_fopen (&fp, tuning_db_file, "rb") == false)
if (hc_fopen (&fp, tuning_db_file, "rb", HCFILE_FORMAT_PLAIN) == false)
{
event_log_error (hashcat_ctx, "%s: %s", tuning_db_file, strerror (errno));