diff --git a/include/locking.h b/include/locking.h index d35ea1706..44bb19abc 100644 --- a/include/locking.h +++ b/include/locking.h @@ -13,7 +13,7 @@ #include #include -int lock_file (FILE *fp); -int unlock_file (FILE *fp); +int hc_lockfile (HCFILE *fp); +int hc_unlockfile (HCFILE *fp); #endif // _LOCKING_H diff --git a/include/shared.h b/include/shared.h index e9cfd95ca..34d919838 100644 --- a/include/shared.h +++ b/include/shared.h @@ -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); diff --git a/include/types.h b/include/types.h index 9b7a03357..b918fd7bb 100644 --- a/include/types.h +++ b/include/types.h @@ -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" diff --git a/src/backend.c b/src/backend.c index 80d3d0f21..c69bd3aec 100644 --- a/src/backend.c +++ b/src/backend.c @@ -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; + + 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), st.st_size, &fp); + 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); diff --git a/src/brain.c b/src/brain.c index 7790d4af1..5a1fe9fed 100644 --- a/src/brain.c +++ b/src/brain.c @@ -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); diff --git a/src/combinator.c b/src/combinator.c index bb4efb322..f147b8d48 100644 --- a/src/combinator.c +++ b/src/combinator.c @@ -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)); diff --git a/src/cpu_crc32.c b/src/cpu_crc32.c index e2d0d75d4..72b72e36f 100644 --- a/src/cpu_crc32.c +++ b/src/cpu_crc32.c @@ -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) diff --git a/src/debugfile.c b/src/debugfile.c index a1d1dc643..e81669fca 100644 --- a/src/debugfile.c +++ b/src/debugfile.c @@ -105,20 +105,18 @@ int debugfile_init (hashcat_ctx_t *hashcat_ctx) debugfile_ctx->filename = user_options->debug_file; + HCFILE fp; + if (debugfile_ctx->filename) { - HCFILE fp; - - if (hc_fopen (&fp, debugfile_ctx->filename, "ab") == false) + 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; diff --git a/src/dictstat.c b/src/dictstat.c index d35fb2a41..798f0cb99 100644 --- a/src/dictstat.c +++ b/src/dictstat.c @@ -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); diff --git a/src/dispatch.c b/src/dispatch.c index 418a3b049..87bad7a77 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -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)); diff --git a/src/hashes.c b/src/hashes.c index f97d70277..ad363ee13 100644 --- a/src/hashes.c +++ b/src/hashes.c @@ -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); diff --git a/src/hwmon.c b/src/hwmon.c index 512f60b61..a3e018cfc 100644 --- a/src/hwmon.c +++ b/src/hwmon.c @@ -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."); diff --git a/src/keyboard_layout.c b/src/keyboard_layout.c index 2e6927557..841c51309 100644 --- a/src/keyboard_layout.c +++ b/src/keyboard_layout.c @@ -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; diff --git a/src/locking.c b/src/locking.c index 81c9e327e..5c89d23c8 100644 --- a/src/locking.c +++ b/src/locking.c @@ -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 diff --git a/src/logfile.c b/src/logfile.c index 654ddf9f6..bef206fa2 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -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; diff --git a/src/loopback.c b/src/loopback.c index bd6a4a256..0fc9297f2 100644 --- a/src/loopback.c +++ b/src/loopback.c @@ -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); } diff --git a/src/modules/module_02500.c b/src/modules/module_02500.c index 8907f8677..e7fefb931 100644 --- a/src/modules/module_02500.c +++ b/src/modules/module_02500.c @@ -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)); diff --git a/src/modules/module_02501.c b/src/modules/module_02501.c index a7ce17b04..750a47bfa 100644 --- a/src/modules/module_02501.c +++ b/src/modules/module_02501.c @@ -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)); diff --git a/src/modules/module_05200.c b/src/modules/module_05200.c index 7c50b5d47..c5682cb14 100644 --- a/src/modules/module_05200.c +++ b/src/modules/module_05200.c @@ -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; diff --git a/src/modules/module_06211.c b/src/modules/module_06211.c index 8f2be8897..39ef928fd 100644 --- a/src/modules/module_06211.c +++ b/src/modules/module_06211.c @@ -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 diff --git a/src/modules/module_06212.c b/src/modules/module_06212.c index bfc9d05d8..a5a02cb28 100644 --- a/src/modules/module_06212.c +++ b/src/modules/module_06212.c @@ -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 diff --git a/src/modules/module_06213.c b/src/modules/module_06213.c index 1b09d8607..ea292f65e 100644 --- a/src/modules/module_06213.c +++ b/src/modules/module_06213.c @@ -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 diff --git a/src/modules/module_06221.c b/src/modules/module_06221.c index 6d43ffe3c..fcc0ebb7a 100644 --- a/src/modules/module_06221.c +++ b/src/modules/module_06221.c @@ -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 diff --git a/src/modules/module_06222.c b/src/modules/module_06222.c index b0ae40989..3e6c15e8d 100644 --- a/src/modules/module_06222.c +++ b/src/modules/module_06222.c @@ -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 diff --git a/src/modules/module_06223.c b/src/modules/module_06223.c index ee3c1f5ed..61d7f7930 100644 --- a/src/modules/module_06223.c +++ b/src/modules/module_06223.c @@ -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 diff --git a/src/modules/module_06231.c b/src/modules/module_06231.c index e01fd7300..d08688405 100644 --- a/src/modules/module_06231.c +++ b/src/modules/module_06231.c @@ -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 diff --git a/src/modules/module_06232.c b/src/modules/module_06232.c index b8a404670..ee648e993 100644 --- a/src/modules/module_06232.c +++ b/src/modules/module_06232.c @@ -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 diff --git a/src/modules/module_06233.c b/src/modules/module_06233.c index 499f0714a..ca017e24e 100644 --- a/src/modules/module_06233.c +++ b/src/modules/module_06233.c @@ -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 diff --git a/src/modules/module_06241.c b/src/modules/module_06241.c index 09c3e8ec7..093a43fd0 100644 --- a/src/modules/module_06241.c +++ b/src/modules/module_06241.c @@ -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 diff --git a/src/modules/module_06242.c b/src/modules/module_06242.c index 20a239fd0..27635a09b 100644 --- a/src/modules/module_06242.c +++ b/src/modules/module_06242.c @@ -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 diff --git a/src/modules/module_06243.c b/src/modules/module_06243.c index baa540b0c..608a9c48b 100644 --- a/src/modules/module_06243.c +++ b/src/modules/module_06243.c @@ -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 diff --git a/src/modules/module_09000.c b/src/modules/module_09000.c index b69166668..5a4751a0b 100644 --- a/src/modules/module_09000.c +++ b/src/modules/module_09000.c @@ -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; diff --git a/src/modules/module_13711.c b/src/modules/module_13711.c index 87852ec44..b801781ce 100644 --- a/src/modules/module_13711.c +++ b/src/modules/module_13711.c @@ -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 diff --git a/src/modules/module_13712.c b/src/modules/module_13712.c index c8179fb71..76992723e 100644 --- a/src/modules/module_13712.c +++ b/src/modules/module_13712.c @@ -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 diff --git a/src/modules/module_13713.c b/src/modules/module_13713.c index 062378441..b0415cfb3 100644 --- a/src/modules/module_13713.c +++ b/src/modules/module_13713.c @@ -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 diff --git a/src/modules/module_13721.c b/src/modules/module_13721.c index fba2cc96d..f0e899047 100644 --- a/src/modules/module_13721.c +++ b/src/modules/module_13721.c @@ -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 diff --git a/src/modules/module_13722.c b/src/modules/module_13722.c index 7e8257b77..605612293 100644 --- a/src/modules/module_13722.c +++ b/src/modules/module_13722.c @@ -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 diff --git a/src/modules/module_13723.c b/src/modules/module_13723.c index 5b9c5cb94..345aae7b6 100644 --- a/src/modules/module_13723.c +++ b/src/modules/module_13723.c @@ -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 diff --git a/src/modules/module_13731.c b/src/modules/module_13731.c index 3afff8644..ed3c1ab3d 100644 --- a/src/modules/module_13731.c +++ b/src/modules/module_13731.c @@ -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 diff --git a/src/modules/module_13732.c b/src/modules/module_13732.c index 965776e9e..a5f1bbe74 100644 --- a/src/modules/module_13732.c +++ b/src/modules/module_13732.c @@ -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 diff --git a/src/modules/module_13733.c b/src/modules/module_13733.c index 3a7d0bbbb..9e825d0e1 100644 --- a/src/modules/module_13733.c +++ b/src/modules/module_13733.c @@ -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 diff --git a/src/modules/module_13741.c b/src/modules/module_13741.c index 45fa7d48c..dd47faa6e 100644 --- a/src/modules/module_13741.c +++ b/src/modules/module_13741.c @@ -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 diff --git a/src/modules/module_13742.c b/src/modules/module_13742.c index eda71240c..3c65d12df 100644 --- a/src/modules/module_13742.c +++ b/src/modules/module_13742.c @@ -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 diff --git a/src/modules/module_13743.c b/src/modules/module_13743.c index fb3b75f0f..b36a3f8bf 100644 --- a/src/modules/module_13743.c +++ b/src/modules/module_13743.c @@ -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 diff --git a/src/modules/module_13751.c b/src/modules/module_13751.c index dae3c2d94..c640d1aff 100644 --- a/src/modules/module_13751.c +++ b/src/modules/module_13751.c @@ -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 diff --git a/src/modules/module_13752.c b/src/modules/module_13752.c index 9f847766b..bff6adc63 100644 --- a/src/modules/module_13752.c +++ b/src/modules/module_13752.c @@ -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 diff --git a/src/modules/module_13753.c b/src/modules/module_13753.c index 8113f044c..c03c67c8e 100644 --- a/src/modules/module_13753.c +++ b/src/modules/module_13753.c @@ -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 diff --git a/src/modules/module_13761.c b/src/modules/module_13761.c index 5fc1a1376..e5b80c5a4 100644 --- a/src/modules/module_13761.c +++ b/src/modules/module_13761.c @@ -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 diff --git a/src/modules/module_13762.c b/src/modules/module_13762.c index b0da01aa7..1807fc803 100644 --- a/src/modules/module_13762.c +++ b/src/modules/module_13762.c @@ -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 diff --git a/src/modules/module_13763.c b/src/modules/module_13763.c index 09fb93505..a09cf950e 100644 --- a/src/modules/module_13763.c +++ b/src/modules/module_13763.c @@ -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 diff --git a/src/modules/module_13771.c b/src/modules/module_13771.c index f788981ef..a0a8882d5 100644 --- a/src/modules/module_13771.c +++ b/src/modules/module_13771.c @@ -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 diff --git a/src/modules/module_13772.c b/src/modules/module_13772.c index e52ee2725..ed9f3f060 100644 --- a/src/modules/module_13772.c +++ b/src/modules/module_13772.c @@ -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 diff --git a/src/modules/module_13773.c b/src/modules/module_13773.c index 20634ebe4..eecec3320 100644 --- a/src/modules/module_13773.c +++ b/src/modules/module_13773.c @@ -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 diff --git a/src/modules/module_14600.c b/src/modules/module_14600.c index 9b8fcc357..5532f0d1b 100644 --- a/src/modules/module_14600.c +++ b/src/modules/module_14600.c @@ -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; diff --git a/src/mpsp.c b/src/mpsp.c index f6d81a6aa..e2527653f 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -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)); diff --git a/src/outfile.c b/src/outfile.c index 1224c147d..c3e1d3b24 100644 --- a/src/outfile.c +++ b/src/outfile.c @@ -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); diff --git a/src/outfile_check.c b/src/outfile_check.c index c67b9429c..4879cdc98 100644 --- a/src/outfile_check.c +++ b/src/outfile_check.c @@ -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); diff --git a/src/pidfile.c b/src/pidfile.c index 817aed4e6..866f5cfd4 100644 --- a/src/pidfile.c +++ b/src/pidfile.c @@ -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); diff --git a/src/potfile.c b/src/potfile.c index b3fddc4eb..4eae86d99 100644 --- a/src/potfile.c +++ b/src/potfile.c @@ -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)) { diff --git a/src/restore.c b/src/restore.c index 6e70a993a..e261d2b26 100644 --- a/src/restore.c +++ b/src/restore.c @@ -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)); diff --git a/src/rp.c b/src/rp.c index 716e451bf..74709878c 100644 --- a/src/rp.c +++ b/src/rp.c @@ -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)); diff --git a/src/shared.c b/src/shared.c index 4d7f0cb4b..01da83cf7 100644 --- a/src/shared.c +++ b/src/shared.c @@ -8,6 +8,7 @@ #include "convert.h" #include "shared.h" #include "memory.h" +#include #if defined (__CYGWIN__) #include @@ -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 (!strncmp (mode, "a", 1) || !strncmp (mode, "ab", 2)) + { + oflag = O_WRONLY | O_CREAT | O_APPEND; - if (check[0] == 0x1f && check[1] == 0x8b && check[2] == 0x08) + #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)) { - fclose (fp_tmp); + oflag = O_RDONLY; + fmode = -1; - if (!(fp->gfp = gzopen (path, mode))) return false; + #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; - fp->is_gzip = true; + #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->is_gzip) - { - int rdup = fileno (fopen (fp->path, fp->mode)); - - r = dup (rdup); + if (fp == NULL) return 1; - 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)) { diff --git a/src/stdout.c b/src/stdout.c index fa6b2e241..7ce8e186e 100644 --- a/src/stdout.c +++ b/src/stdout.c @@ -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); diff --git a/src/straight.c b/src/straight.c index 21d1e0ee7..e86f92aa8 100644 --- a/src/straight.c +++ b/src/straight.c @@ -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)); diff --git a/src/tuningdb.c b/src/tuningdb.c index 248f8d30a..94354fad2 100644 --- a/src/tuningdb.c +++ b/src/tuningdb.c @@ -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));