diff --git a/.gitignore b/.gitignore index 054a2fe17..1565b6a31 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ modules/*.so obj/*.o obj/*.a include/CL +tools/luks_tests diff --git a/docs/credits.txt b/docs/credits.txt index e1e0e6437..bd21d35d7 100644 --- a/docs/credits.txt +++ b/docs/credits.txt @@ -18,13 +18,20 @@ Philipp "philsmd" Schmidt (@philsmd) Gabriele "matrix" Gristina (@gm4tr1x) +* gzip wordlists feature +* SHA-224 kernel module + optimizations +* Some AES OpenCL kernel module optimizations +* OpenCL Info feature * Apple macOS port * Hardware monitor initial code base * Test suite initial code base * Makefiles initial code base * Multithreading initial code base +* MultiGPU initial code base * Benchmarks initial code base * Offline OpenCL Kernel Compiler support +* SHA-512 initial code base +* Some MD5 and SHA1 OpenCL optimizations Jean-Christophe "Fist0urs" Delaunay (@Fist0urs) diff --git a/include/filehandling.h b/include/filehandling.h index 0b430284a..ac1a48ea0 100644 --- a/include/filehandling.h +++ b/include/filehandling.h @@ -10,9 +10,9 @@ #include #include -u64 count_lines (FILE *fd); +u64 count_lines (HCFILE *fp); -size_t fgetl (FILE *fp, char *line_buf); +size_t fgetl (HCFILE *fp, char *line_buf); size_t superchop_with_length (char *buf, const size_t len); diff --git a/include/hlfmt.h b/include/hlfmt.h index 05d94d76e..ddd8e88b3 100644 --- a/include/hlfmt.h +++ b/include/hlfmt.h @@ -15,6 +15,6 @@ const char *strhlfmt (const u32 hashfile_format); void hlfmt_hash (hashcat_ctx_t *hashcat_ctx, u32 hashfile_format, char *line_buf, const int line_len, char **hashbuf_pos, int *hashbuf_len); void hlfmt_user (hashcat_ctx_t *hashcat_ctx, u32 hashfile_format, char *line_buf, const int line_len, char **userbuf_pos, int *userbuf_len); -u32 hlfmt_detect (hashcat_ctx_t *hashcat_ctx, FILE *fp, u32 max_check); +u32 hlfmt_detect (hashcat_ctx_t *hashcat_ctx, HCFILE *fp, u32 max_check); #endif // _HLFMT_H 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 a85f19490..e9cfd95ca 100644 --- a/include/shared.h +++ b/include/shared.h @@ -14,6 +14,7 @@ #include #include #include +#include "zlib.h" #if defined (_WIN) #include // needed for select() @@ -61,8 +62,26 @@ bool hc_string_is_digit (const char *s); void hc_string_trim_trailing (char *s); void hc_string_trim_leading (char *s); -size_t hc_fread (void *ptr, size_t size, size_t nmemb, FILE *stream); -size_t hc_fwrite (const void *ptr, size_t size, size_t nmemb, FILE *stream); +#if defined (__CYGWIN__) +int _wopen(const char *path, int oflag, ...); +#endif + +bool hc_fopen (HCFILE *fp, const char *path, char *mode); +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); +int hc_fseek (HCFILE *fp, off_t offset, int whence); +void hc_rewind (HCFILE *fp); +off_t hc_ftell (HCFILE *fp); +int hc_fgetc (HCFILE *fp); +int hc_fileno (HCFILE *fp); +int hc_feof (HCFILE *fp); +void hc_fflush (HCFILE *fp); +void hc_fclose (HCFILE *fp); +int hc_fputc (int c, HCFILE *fp); +char *hc_fgets (char *buf, int len, HCFILE *fp); +size_t hc_fwrite (void *ptr, size_t size, size_t nmemb, HCFILE *fp); +size_t hc_fread (void *ptr, size_t size, size_t nmemb, HCFILE *fp); bool hc_same_files (char *file1, char *file2); diff --git a/include/slow_candidates.h b/include/slow_candidates.h index 92f743d20..c3d16d4b8 100644 --- a/include/slow_candidates.h +++ b/include/slow_candidates.h @@ -10,7 +10,7 @@ typedef struct extra_info_straight { u64 pos; - FILE *fp; + HCFILE fp; u64 rule_pos_prev; u64 rule_pos; @@ -27,8 +27,8 @@ typedef struct extra_info_combi { u64 pos; - FILE *base_fp; - FILE *combs_fp; + HCFILE base_fp; + HCFILE combs_fp; u64 comb_pos_prev; u64 comb_pos; diff --git a/include/types.h b/include/types.h index f7b254bfa..6452f859f 100644 --- a/include/types.h +++ b/include/types.h @@ -17,6 +17,7 @@ #include #include #include +#include "zlib.h" #if defined (_WIN) #define WINICONV_CONST @@ -988,6 +989,19 @@ typedef struct link_speed } link_speed_t; +// handling gzip files + +typedef struct hc_fp +{ + int fd; + FILE *pfp; + gzFile gfp; + + bool is_gzip; + char *mode; + const char *path; +} HCFILE; + #include "ext_nvrtc.h" #include "ext_cuda.h" #include "ext_OpenCL.h" @@ -1147,12 +1161,12 @@ typedef struct hc_device_param u32 *brain_link_out_buf; #endif - char *scratch_buf; + char *scratch_buf; - FILE *combs_fp; - pw_t *combs_buf; + HCFILE combs_fp; + pw_t *combs_buf; - void *hooks_buf; + void *hooks_buf; pw_idx_t *pws_idx; u32 *pws_comp; @@ -1541,11 +1555,12 @@ typedef aes_context_t aes_ctx; typedef struct debugfile_ctx { - bool enabled; + HCFILE fp; - FILE *fp; - char *filename; - u32 mode; + bool enabled; + + char *filename; + u32 mode; } debugfile_ctx_t; @@ -1586,11 +1601,12 @@ typedef struct dictstat_ctx typedef struct loopback_ctx { - bool enabled; - bool unused; + HCFILE fp; - FILE *fp; - char *filename; + bool enabled; + bool unused; + + char *filename; } loopback_ctx_t; @@ -1603,12 +1619,12 @@ typedef struct mf typedef struct outfile_ctx { - char *filename; + HCFILE fp; - FILE *fp; + u32 outfile_format; + bool outfile_autohex; - u32 outfile_format; - bool outfile_autohex; + char *filename; } outfile_ctx_t; @@ -1623,9 +1639,10 @@ typedef struct pot typedef struct potfile_ctx { + HCFILE fp; + bool enabled; - FILE *fp; char *filename; u8 *out_buf; // allocates [HCBUFSIZ_LARGE]; @@ -1707,10 +1724,10 @@ typedef struct pidfile_ctx typedef struct out { - FILE *fp; + HCFILE fp; - char buf[HCBUFSIZ_SMALL]; - int len; + char buf[HCBUFSIZ_SMALL]; + int len; } out_t; diff --git a/include/wordlist.h b/include/wordlist.h index 8ee61ab88..987e8bb67 100644 --- a/include/wordlist.h +++ b/include/wordlist.h @@ -19,9 +19,10 @@ void get_next_word_lm (char *buf, u64 sz, u64 *len, u64 *off); void get_next_word_uc (char *buf, u64 sz, u64 *len, u64 *off); void get_next_word_std (char *buf, u64 sz, u64 *len, u64 *off); -void get_next_word (hashcat_ctx_t *hashcat_ctx, FILE *fd, char **out_buf, u32 *out_len); -int load_segment (hashcat_ctx_t *hashcat_ctx, FILE *fd); -int count_words (hashcat_ctx_t *hashcat_ctx, FILE *fd, const char *dictfile, u64 *result); +void get_next_word (hashcat_ctx_t *hashcat_ctx, HCFILE *fp, char **out_buf, u32 *out_len); +int load_segment (hashcat_ctx_t *hashcat_ctx, HCFILE *fp); +int count_words (hashcat_ctx_t *hashcat_ctx, HCFILE *fp, const char *dictfile, u64 *result); + int wl_data_init (hashcat_ctx_t *hashcat_ctx); void wl_data_destroy (hashcat_ctx_t *hashcat_ctx); diff --git a/src/Makefile b/src/Makefile index 8d0854e2a..89a16dbda 100644 --- a/src/Makefile +++ b/src/Makefile @@ -179,6 +179,7 @@ endif ## because ZLIB ifeq ($(USE_SYSTEM_ZLIB),0) CFLAGS_ZLIB += -Wno-implicit-fallthrough +CFLAGS_ZLIB += -Wno-implicit-function-declaration endif ifeq ($(DEBUG),0) @@ -318,7 +319,7 @@ WIN_OBJS += $(foreach OBJ,$(OBJS_LZMA),obj/$(OBJ).WIN.o) endif ifeq ($(USE_SYSTEM_ZLIB),0) -OBJS_ZLIB := adler32 crc32 zutil inftrees inffast inflate +OBJS_ZLIB := adler32 crc32 deflate inflate inffast inftrees trees gzread gzwrite gzclose zutil gzlib NATIVE_OBJS += $(foreach OBJ,$(OBJS_ZLIB),obj/$(OBJ).NATIVE.o) LINUX_OBJS += $(foreach OBJ,$(OBJS_ZLIB),obj/$(OBJ).LINUX.o) @@ -344,6 +345,7 @@ default: $(HASHCAT_FRONTEND) modules clean: $(RM) -f $(HASHCAT_FRONTEND) $(RM) -f $(HASHCAT_LIBRARY) + $(RM) -rf modules/*.dSYM $(RM) -f modules/*.dll $(RM) -f modules/*.so $(RM) -f obj/*.o diff --git a/src/backend.c b/src/backend.c index ceb3070a3..5a912abdf 100644 --- a/src/backend.c +++ b/src/backend.c @@ -156,7 +156,7 @@ static int ocl_check_dri (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx) // Now the problem is only with AMDGPU-PRO, not with oldschool AMD driver - char buf[HCBUFSIZ_TINY]; + char buf[HCBUFSIZ_TINY] = { 0 }; const ssize_t len = readlink (drm_card0_driver_path, buf, HCBUFSIZ_TINY - 1); @@ -440,28 +440,30 @@ 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) { - FILE *fp = fopen (kernel_file, "rb"); + HCFILE fp; - if (fp != NULL) + if (hc_fopen (&fp, kernel_file, "rb") == true) { struct stat st; if (stat (kernel_file, &st)) { - fclose (fp); + hc_fclose (&fp); return false; } #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); + char *buf = (char *) hcmalloc (klen + 1 + EXTRASZ); - fclose (fp); + size_t num_read = hc_fread (buf, sizeof (char), klen, &fp); - if (num_read != (size_t) st.st_size) + hc_fclose (&fp); + + if (num_read != (size_t) klen) { event_log_error (hashcat_ctx, "%s: %s", kernel_file, strerror (errno)); @@ -470,7 +472,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 +482,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; } @@ -503,29 +505,29 @@ static bool write_kernel_binary (hashcat_ctx_t *hashcat_ctx, char *kernel_file, { if (binary_size > 0) { - FILE *fp = fopen (kernel_file, "wb"); + HCFILE fp; - if (fp == NULL) + if (hc_fopen (&fp, kernel_file, "wb") == false) { event_log_error (hashcat_ctx, "%s: %s", kernel_file, strerror (errno)); return false; } - if (lock_file (fp) == -1) + if (hc_lockfile (&fp) == -1) { - fclose (fp); + hc_fclose (&fp); event_log_error (hashcat_ctx, "%s: %s", kernel_file, strerror (errno)); return false; } - hc_fwrite (binary, sizeof (char), binary_size, fp); + hc_fwrite (binary, sizeof (char), binary_size, &fp); - fflush (fp); + hc_fflush (&fp); - fclose (fp); + hc_fclose (&fp); } return true; @@ -4375,7 +4377,7 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co device_param->kernel_params_buf32[31] = salt_buf->digests_cnt; device_param->kernel_params_buf32[32] = salt_buf->digests_offset; - FILE *combs_fp = device_param->combs_fp; + HCFILE *combs_fp = &device_param->combs_fp; if (user_options->slow_candidates == true) { @@ -4384,7 +4386,7 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co { if ((user_options->attack_mode == ATTACK_MODE_COMBI) || (((hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL) == 0) && (user_options->attack_mode == ATTACK_MODE_HYBRID2))) { - rewind (combs_fp); + hc_rewind (combs_fp); } } @@ -4478,7 +4480,7 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co while (i < innerloop_left) { - if (feof (combs_fp)) break; + if (hc_feof (combs_fp)) break; size_t line_len = fgetl (combs_fp, line_buf); @@ -4643,7 +4645,7 @@ int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, co while (i < innerloop_left) { - if (feof (combs_fp)) break; + if (hc_feof (combs_fp)) break; size_t line_len = fgetl (combs_fp, line_buf); diff --git a/src/brain.c b/src/brain.c index 77b7af712..1bba33a5e 100644 --- a/src/brain.c +++ b/src/brain.c @@ -539,16 +539,18 @@ u64 brain_compute_attack_wordlist (const char *filename) char buf[FBUFSZ]; - FILE *fd = fopen (filename, "rb"); + HCFILE fp; - while (!feof (fd)) + hc_fopen (&fp, filename, "rb"); + + while (!hc_feof (&fp)) { - const size_t nread = fread (buf, 1, FBUFSZ, fd); + const size_t nread = hc_fread (buf, 1, FBUFSZ, &fp); XXH64_update (state, buf, nread); } - fclose (fd); + hc_fclose (&fp); const u64 hash = XXH64_digest (state); @@ -609,25 +611,25 @@ u32 brain_auth_challenge (void) static const char *urandom = "/dev/urandom"; - FILE *fd = fopen (urandom, "rb"); + HCFILE fp; - if (fd == NULL) + if (hc_fopen (&fp, urandom, "rb") == false) { brain_logging (stderr, 0, "%s: %s\n", urandom, strerror (errno)); return val; } - if (fread (&val, sizeof (val), 1, fd) != 1) + if (hc_fread (&val, sizeof (val), 1, &fp) != 1) { brain_logging (stderr, 0, "%s: %s\n", urandom, strerror (errno)); - fclose (fd); + hc_fclose (&fp); return val; } - fclose (fd); + hc_fclose (&fp); #endif @@ -1595,9 +1597,9 @@ bool brain_server_read_hash_dump (brain_server_db_hash_t *brain_server_db_hash, return false; } - FILE *fd = fopen (file, "rb"); + HCFILE fp; - if (fd == NULL) + if (hc_fopen (&fp, file, "rb") == false) { brain_logging (stderr, 0, "%s: %s\n", file, strerror (errno)); @@ -1611,18 +1613,18 @@ bool brain_server_read_hash_dump (brain_server_db_hash_t *brain_server_db_hash, { brain_logging (stderr, 0, "%s\n", MSG_ENOMEM); - fclose (fd); + hc_fclose (&fp); return false; } - const size_t nread = fread (brain_server_db_hash->long_buf, sizeof (brain_server_hash_long_t), temp_cnt, fd); + const size_t nread = hc_fread (brain_server_db_hash->long_buf, sizeof (brain_server_hash_long_t), temp_cnt, &fp); if (nread != (size_t) temp_cnt) { brain_logging (stderr, 0, "%s: only %" PRIu64 " bytes read\n", file, (u64) nread * sizeof (brain_server_hash_long_t)); - fclose (fd); + hc_fclose (&fp); return false; } @@ -1631,7 +1633,7 @@ bool brain_server_read_hash_dump (brain_server_db_hash_t *brain_server_db_hash, brain_server_db_hash->write_hashes = false; - fclose (fd); + hc_fclose (&fp); } const double ms = hc_timer_get (timer_dump); @@ -1651,9 +1653,9 @@ bool brain_server_write_hash_dump (brain_server_db_hash_t *brain_server_db_hash, // write to file - FILE *fd = fopen (file, "wb"); + HCFILE fp; - if (fd == NULL) + if (hc_fopen (&fp, file, "wb") == false) { brain_logging (stderr, 0, "%s: %s\n", file, strerror (errno)); @@ -1661,18 +1663,18 @@ bool brain_server_write_hash_dump (brain_server_db_hash_t *brain_server_db_hash, } else { - const size_t nwrite = fwrite (brain_server_db_hash->long_buf, sizeof (brain_server_hash_long_t), brain_server_db_hash->long_cnt, fd); + 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) { brain_logging (stderr, 0, "%s: only %" PRIu64 " bytes written\n", file, (u64) nwrite * sizeof (brain_server_hash_long_t)); - fclose (fd); + hc_fclose (&fp); return false; } - fclose (fd); + hc_fclose (&fp); brain_server_db_hash->write_hashes = false; } @@ -1794,9 +1796,9 @@ bool brain_server_read_attack_dump (brain_server_db_attack_t *brain_server_db_at return false; } - FILE *fd = fopen (file, "rb"); + HCFILE fp; - if (fd == NULL) + if (hc_fopen (&fp, file, "rb") == false) { brain_logging (stderr, 0, "%s: %s\n", file, strerror (errno)); @@ -1810,18 +1812,18 @@ bool brain_server_read_attack_dump (brain_server_db_attack_t *brain_server_db_at { brain_logging (stderr, 0, "%s\n", MSG_ENOMEM); - fclose (fd); + hc_fclose (&fp); return false; } - const size_t nread = fread (brain_server_db_attack->long_buf, sizeof (brain_server_attack_long_t), temp_cnt, fd); + const size_t nread = hc_fread (brain_server_db_attack->long_buf, sizeof (brain_server_attack_long_t), temp_cnt, &fp); if (nread != (size_t) temp_cnt) { brain_logging (stderr, 0, "%s: only %" PRIu64 " bytes read\n", file, (u64) nread * sizeof (brain_server_attack_long_t)); - fclose (fd); + hc_fclose (&fp); return false; } @@ -1830,7 +1832,7 @@ bool brain_server_read_attack_dump (brain_server_db_attack_t *brain_server_db_at brain_server_db_attack->write_attacks = false; - fclose (fd); + hc_fclose (&fp); } const double ms = hc_timer_get (timer_dump); @@ -1850,9 +1852,9 @@ bool brain_server_write_attack_dump (brain_server_db_attack_t *brain_server_db_a // write to file - FILE *fd = fopen (file, "wb"); + HCFILE fp; - if (fd == NULL) + if (hc_fopen (&fp, file, "wb") == false) { brain_logging (stderr, 0, "%s: %s\n", file, strerror (errno)); @@ -1862,18 +1864,18 @@ bool brain_server_write_attack_dump (brain_server_db_attack_t *brain_server_db_a { // storing should not include reserved attacks only finished - const size_t nwrite = fwrite (brain_server_db_attack->long_buf, sizeof (brain_server_attack_long_t), brain_server_db_attack->long_cnt, fd); + 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); if (nwrite != (size_t) brain_server_db_attack->long_cnt) { brain_logging (stderr, 0, "%s: only %" PRIu64 " bytes written\n", file, (u64) nwrite * sizeof (brain_server_attack_long_t)); - fclose (fd); + hc_fclose (&fp); return false; } - fclose (fd); + hc_fclose (&fp); brain_server_db_attack->write_attacks = false; } diff --git a/src/combinator.c b/src/combinator.c index a8fd4f3ef..bb4efb322 100644 --- a/src/combinator.c +++ b/src/combinator.c @@ -60,21 +60,21 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } - FILE *fp1 = NULL; - FILE *fp2 = NULL; + HCFILE fp1; + HCFILE fp2; - if ((fp1 = fopen (dictfile1, "rb")) == NULL) + if (hc_fopen (&fp1, dictfile1, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", dictfile1, strerror (errno)); return -1; } - if ((fp2 = fopen (dictfile2, "rb")) == NULL) + if (hc_fopen (&fp2, dictfile2, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", dictfile2, strerror (errno)); - fclose (fp1); + hc_fclose (&fp1); return -1; } @@ -83,14 +83,14 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) u64 words1_cnt = 0; - const int rc1 = count_words (hashcat_ctx, fp1, dictfile1, &words1_cnt); + const int rc1 = count_words (hashcat_ctx, &fp1, dictfile1, &words1_cnt); if (rc1 == -1) { event_log_error (hashcat_ctx, "Integer overflow detected in keyspace of wordlist: %s", dictfile1); - fclose (fp1); - fclose (fp2); + hc_fclose (&fp1); + hc_fclose (&fp2); return -1; } @@ -99,8 +99,8 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) { event_log_error (hashcat_ctx, "%s: empty file.", dictfile1); - fclose (fp1); - fclose (fp2); + hc_fclose (&fp1); + hc_fclose (&fp2); return -1; } @@ -109,10 +109,10 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) u64 words2_cnt = 0; - const int rc2 = count_words (hashcat_ctx, fp2, dictfile2, &words2_cnt); + const int rc2 = count_words (hashcat_ctx, &fp2, dictfile2, &words2_cnt); - fclose (fp1); - fclose (fp2); + hc_fclose (&fp1); + hc_fclose (&fp2); if (rc2 == -1) { @@ -163,21 +163,21 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } - FILE *fp1 = NULL; - FILE *fp2 = NULL; + HCFILE fp1; + HCFILE fp2; - if ((fp1 = fopen (dictfile1, "rb")) == NULL) + if (hc_fopen (&fp1, dictfile1, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", dictfile1, strerror (errno)); return -1; } - if ((fp2 = fopen (dictfile2, "rb")) == NULL) + if (hc_fopen (&fp2, dictfile2, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", dictfile2, strerror (errno)); - fclose (fp1); + hc_fclose (&fp1); return -1; } @@ -186,14 +186,14 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) u64 words1_cnt = 0; - const int rc1 = count_words (hashcat_ctx, fp1, dictfile1, &words1_cnt); + const int rc1 = count_words (hashcat_ctx, &fp1, dictfile1, &words1_cnt); if (rc1 == -1) { event_log_error (hashcat_ctx, "Integer overflow detected in keyspace of wordlist: %s", dictfile1); - fclose (fp1); - fclose (fp2); + hc_fclose (&fp1); + hc_fclose (&fp2); return -1; } @@ -202,8 +202,8 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) { event_log_error (hashcat_ctx, "%s: empty file.", dictfile1); - fclose (fp1); - fclose (fp2); + hc_fclose (&fp1); + hc_fclose (&fp2); return -1; } @@ -212,10 +212,10 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) u64 words2_cnt = 0; - const int rc2 = count_words (hashcat_ctx, fp2, dictfile2, &words2_cnt); + const int rc2 = count_words (hashcat_ctx, &fp2, dictfile2, &words2_cnt); - fclose (fp1); - fclose (fp2); + hc_fclose (&fp1); + hc_fclose (&fp2); if (rc2 == -1) { @@ -294,21 +294,21 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } - FILE *fp1 = NULL; - FILE *fp2 = NULL; + HCFILE fp1; + HCFILE fp2; - if ((fp1 = fopen (dictfile1, "rb")) == NULL) + if (hc_fopen (&fp1, dictfile1, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", dictfile1, strerror (errno)); return -1; } - if ((fp2 = fopen (dictfile2, "rb")) == NULL) + if (hc_fopen (&fp2, dictfile2, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", dictfile2, strerror (errno)); - fclose (fp1); + hc_fclose (&fp1); return -1; } @@ -317,14 +317,14 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) u64 words1_cnt = 0; - const int rc1 = count_words (hashcat_ctx, fp1, dictfile1, &words1_cnt); + const int rc1 = count_words (hashcat_ctx, &fp1, dictfile1, &words1_cnt); if (rc1 == -1) { event_log_error (hashcat_ctx, "Integer overflow detected in keyspace of wordlist: %s", dictfile1); - fclose (fp1); - fclose (fp2); + hc_fclose (&fp1); + hc_fclose (&fp2); return -1; } @@ -333,8 +333,8 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) { event_log_error (hashcat_ctx, "%s: empty file.", dictfile1); - fclose (fp1); - fclose (fp2); + hc_fclose (&fp1); + hc_fclose (&fp2); return -1; } @@ -343,10 +343,10 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) u64 words2_cnt = 0; - const int rc2 = count_words (hashcat_ctx, fp2, dictfile2, &words2_cnt); + const int rc2 = count_words (hashcat_ctx, &fp2, dictfile2, &words2_cnt); - fclose (fp1); - fclose (fp2); + hc_fclose (&fp1); + hc_fclose (&fp2); if (rc2 == -1) { @@ -387,9 +387,9 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) return -1; } - FILE *fp = NULL; + HCFILE fp; - if ((fp = fopen (dictfile, "rb")) == NULL) + if (hc_fopen (&fp, dictfile, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", dictfile, strerror (errno)); @@ -400,19 +400,17 @@ int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx) u64 words_cnt = 0; - const int rc = count_words (hashcat_ctx, fp, dictfile, &words_cnt); + const int rc = count_words (hashcat_ctx, &fp, dictfile, &words_cnt); + + hc_fclose (&fp); if (rc == -1) { event_log_error (hashcat_ctx, "Integer overflow detected in keyspace of wordlist: %s", dictfile); - fclose (fp); - return -1; } - fclose (fp); - combinator_ctx->combs_cnt = words_cnt; combinator_ctx->combs_mode = COMBINATOR_MODE_BASE_LEFT; } diff --git a/src/cpu_crc32.c b/src/cpu_crc32.c index 2f5450640..e2d0d75d4 100644 --- a/src/cpu_crc32.c +++ b/src/cpu_crc32.c @@ -92,15 +92,17 @@ int cpu_crc32 (const char *filename, u8 keytab[64]) { u32 crc = ~0u; - FILE *fd = fopen (filename, "rb"); + HCFILE fp; + + hc_fopen (&fp, filename, "rb"); #define MAX_KEY_SIZE (1024 * 1024) u8 *buf = (u8 *) hcmalloc (MAX_KEY_SIZE + 1); - size_t nread = hc_fread (buf, sizeof (u8), MAX_KEY_SIZE, fd); + size_t nread = hc_fread (buf, sizeof (u8), MAX_KEY_SIZE, &fp); - fclose (fd); + hc_fclose (&fp); size_t kpos = 0; diff --git a/src/debugfile.c b/src/debugfile.c index 5e0a62bbe..839dcba35 100644 --- a/src/debugfile.c +++ b/src/debugfile.c @@ -37,18 +37,18 @@ static void debugfile_format_plain (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ if (needs_hexify == 1) { - fprintf (debugfile_ctx->fp, "$HEX["); + hc_fprintf (&debugfile_ctx->fp, "$HEX["); for (u32 i = 0; i < plain_len; i++) { - fprintf (debugfile_ctx->fp, "%02x", plain_ptr[i]); + hc_fprintf (&debugfile_ctx->fp, "%02x", plain_ptr[i]); } - fprintf (debugfile_ctx->fp, "]"); + hc_fprintf (&debugfile_ctx->fp, "]"); } else { - hc_fwrite (plain_ptr, plain_len, 1, debugfile_ctx->fp); + hc_fwrite ((void *)plain_ptr, plain_len, 1, &debugfile_ctx->fp); } } @@ -64,19 +64,19 @@ void debugfile_write_append (hashcat_ctx_t *hashcat_ctx, const u8 *rule_buf, con { debugfile_format_plain (hashcat_ctx, orig_plain_ptr, orig_plain_len); - if ((debug_mode == 3) || (debug_mode == 4)) fputc (':', debugfile_ctx->fp); + if ((debug_mode == 3) || (debug_mode == 4)) hc_fputc (':', &debugfile_ctx->fp); } - hc_fwrite (rule_buf, rule_len, 1, debugfile_ctx->fp); + hc_fwrite ((void *)rule_buf, rule_len, 1, &debugfile_ctx->fp); if (debug_mode == 4) { - fputc (':', debugfile_ctx->fp); + hc_fputc (':', &debugfile_ctx->fp); debugfile_format_plain (hashcat_ctx, mod_plain_ptr, mod_plain_len); } - hc_fwrite (EOL, strlen (EOL), 1, debugfile_ctx->fp); + hc_fwrite (EOL, strlen (EOL), 1, &debugfile_ctx->fp); } int debugfile_init (hashcat_ctx_t *hashcat_ctx) @@ -107,29 +107,27 @@ int debugfile_init (hashcat_ctx_t *hashcat_ctx) if (debugfile_ctx->filename) { - FILE *fp = fopen (debugfile_ctx->filename, "ab"); - - if (fp == NULL) + if (hc_fopen (&debugfile_ctx->fp, debugfile_ctx->filename, "ab") == false) { event_log_error (hashcat_ctx, "Could not open --debug-file file for writing."); return -1; } - if (lock_file (fp) == -1) + if (hc_lockfile (&debugfile_ctx->fp) == -1) { - fclose (fp); + hc_fclose (&debugfile_ctx->fp); event_log_error (hashcat_ctx, "%s: %s", debugfile_ctx->filename, strerror (errno)); return -1; } - - debugfile_ctx->fp = fp; } else { - debugfile_ctx->fp = stdout; + debugfile_ctx->fp.is_gzip = false; + debugfile_ctx->fp.pfp = stdout; + debugfile_ctx->fp.fd = fileno (stdout); } return 0; @@ -143,7 +141,7 @@ void debugfile_destroy (hashcat_ctx_t *hashcat_ctx) if (debugfile_ctx->filename) { - fclose (debugfile_ctx->fp); + hc_fclose (&debugfile_ctx->fp); } memset (debugfile_ctx, 0, sizeof (debugfile_ctx_t)); diff --git a/src/dictstat.c b/src/dictstat.c index 7ee0e4297..caab3deea 100644 --- a/src/dictstat.c +++ b/src/dictstat.c @@ -96,9 +96,9 @@ void dictstat_read (hashcat_ctx_t *hashcat_ctx) if (hashconfig->dictstat_disable == true) return; - FILE *fp = fopen (dictstat_ctx->filename, "rb"); + HCFILE fp; - if (fp == NULL) + if (hc_fopen (&fp, dictstat_ctx->filename, "rb") == false) { // first run, file does not exist, do not error out @@ -110,14 +110,14 @@ void dictstat_read (hashcat_ctx_t *hashcat_ctx) u64 v; u64 z; - const size_t nread1 = hc_fread (&v, sizeof (u64), 1, fp); - const size_t nread2 = hc_fread (&z, sizeof (u64), 1, fp); + const size_t nread1 = hc_fread (&v, sizeof (u64), 1, &fp); + const size_t nread2 = hc_fread (&z, sizeof (u64), 1, &fp); if ((nread1 != 1) || (nread2 != 1)) { event_log_error (hashcat_ctx, "%s: Invalid header", dictstat_ctx->filename); - fclose (fp); + hc_fclose (&fp); return; } @@ -129,7 +129,7 @@ void dictstat_read (hashcat_ctx_t *hashcat_ctx) { event_log_error (hashcat_ctx, "%s: Invalid header, ignoring content", dictstat_ctx->filename); - fclose (fp); + hc_fclose (&fp); return; } @@ -138,7 +138,7 @@ void dictstat_read (hashcat_ctx_t *hashcat_ctx) { event_log_error (hashcat_ctx, "%s: Invalid header, ignoring content", dictstat_ctx->filename); - fclose (fp); + hc_fclose (&fp); return; } @@ -147,18 +147,18 @@ void dictstat_read (hashcat_ctx_t *hashcat_ctx) { event_log_warning (hashcat_ctx, "%s: Outdated header version, ignoring content", dictstat_ctx->filename); - fclose (fp); + hc_fclose (&fp); return; } // parse data - while (!feof (fp)) + while (!hc_feof (&fp)) { dictstat_t d; - const size_t nread = hc_fread (&d, sizeof (dictstat_t), 1, fp); + const size_t nread = hc_fread (&d, sizeof (dictstat_t), 1, &fp); if (nread == 0) continue; @@ -172,7 +172,7 @@ void dictstat_read (hashcat_ctx_t *hashcat_ctx) } } - fclose (fp); + hc_fclose (&fp); } int dictstat_write (hashcat_ctx_t *hashcat_ctx) @@ -184,18 +184,18 @@ int dictstat_write (hashcat_ctx_t *hashcat_ctx) if (hashconfig->dictstat_disable == true) return 0; - FILE *fp = fopen (dictstat_ctx->filename, "wb"); + HCFILE fp; - if (fp == NULL) + if (hc_fopen (&fp, dictstat_ctx->filename, "wb") == false) { event_log_error (hashcat_ctx, "%s: %s", dictstat_ctx->filename, strerror (errno)); return -1; } - if (lock_file (fp) == -1) + if (hc_lockfile (&fp) == -1) { - fclose (fp); + hc_fclose (&fp); event_log_error (hashcat_ctx, "%s: %s", dictstat_ctx->filename, strerror (errno)); @@ -210,14 +210,14 @@ int dictstat_write (hashcat_ctx_t *hashcat_ctx) v = byte_swap_64 (v); z = byte_swap_64 (z); - hc_fwrite (&v, sizeof (u64), 1, fp); - hc_fwrite (&z, sizeof (u64), 1, fp); + hc_fwrite (&v, sizeof (u64), 1, &fp); + hc_fwrite (&z, sizeof (u64), 1, &fp); // data - hc_fwrite (dictstat_ctx->base, sizeof (dictstat_t), dictstat_ctx->cnt, fp); + hc_fwrite (dictstat_ctx->base, sizeof (dictstat_t), dictstat_ctx->cnt, &fp); - fclose (fp); + hc_fclose (&fp); return 0; } diff --git a/src/dispatch.c b/src/dispatch.c index 6f841124a..1b197e5f7 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -427,21 +427,17 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) { char *dictfile = straight_ctx->dict; - FILE *fp = fopen (dictfile, "rb"); + extra_info_straight_t extra_info_straight; - if (fp == NULL) + memset (&extra_info_straight, 0, sizeof (extra_info_straight)); + + if (hc_fopen (&extra_info_straight.fp, dictfile, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", dictfile, strerror (errno)); return -1; } - extra_info_straight_t extra_info_straight; - - memset (&extra_info_straight, 0, sizeof (extra_info_straight)); - - extra_info_straight.fp = fp; - hashcat_ctx_t *hashcat_ctx_tmp = (hashcat_ctx_t *) hcmalloc (sizeof (hashcat_ctx_t)); memcpy (hashcat_ctx_tmp, hashcat_ctx, sizeof (hashcat_ctx_t)); // yes we actually want to copy these pointers @@ -452,7 +448,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (rc_wl_data_init == -1) { - fclose (fp); + hc_fclose (&extra_info_straight.fp); hcfree (hashcat_ctx_tmp->wl_data); @@ -663,7 +659,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (CL_rc == -1) { - fclose (fp); + hc_fclose (&extra_info_straight.fp); hcfree (hashcat_ctx_tmp->wl_data); @@ -676,7 +672,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (CL_rc == -1) { - fclose (fp); + hc_fclose (&extra_info_straight.fp); hcfree (hashcat_ctx_tmp->wl_data); @@ -721,7 +717,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (words_fin == 0) break; } - fclose (fp); + hc_fclose (&extra_info_straight.fp); wl_data_destroy (hashcat_ctx_tmp); @@ -747,30 +743,26 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) combs_file = combinator_ctx->dict1; } - FILE *base_fp = fopen (base_file, "rb"); + extra_info_combi_t extra_info_combi; - if (base_fp == NULL) + memset (&extra_info_combi, 0, sizeof (extra_info_combi)); + + if (hc_fopen (&extra_info_combi.base_fp, base_file, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", base_file, strerror (errno)); return -1; } - FILE *combs_fp = fopen (combs_file, "rb"); - - if (combs_fp == NULL) + if (hc_fopen (&extra_info_combi.combs_fp, combs_file, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", combs_file, strerror (errno)); + hc_fclose (&extra_info_combi.base_fp); + return -1; } - extra_info_combi_t extra_info_combi; - - memset (&extra_info_combi, 0, sizeof (extra_info_combi)); - - extra_info_combi.base_fp = base_fp; - extra_info_combi.combs_fp = combs_fp; extra_info_combi.scratch_buf = device_param->scratch_buf; hashcat_ctx_t *hashcat_ctx_tmp = (hashcat_ctx_t *) hcmalloc (sizeof (hashcat_ctx_t)); @@ -783,12 +775,10 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (rc_wl_data_init == -1) { - fclose (combs_fp); - - fclose (base_fp); + hc_fclose (&extra_info_combi.base_fp); + hc_fclose (&extra_info_combi.combs_fp); hcfree (hashcat_ctx_tmp->wl_data); - hcfree (hashcat_ctx_tmp); return -1; @@ -996,12 +986,10 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (CL_rc == -1) { - fclose (combs_fp); - - fclose (base_fp); + hc_fclose (&extra_info_combi.base_fp); + hc_fclose (&extra_info_combi.combs_fp); hcfree (hashcat_ctx_tmp->wl_data); - hcfree (hashcat_ctx_tmp); return -1; @@ -1011,12 +999,10 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (CL_rc == -1) { - fclose (combs_fp); - - fclose (base_fp); + hc_fclose (&extra_info_combi.base_fp); + hc_fclose (&extra_info_combi.combs_fp); hcfree (hashcat_ctx_tmp->wl_data); - hcfree (hashcat_ctx_tmp); return -1; @@ -1058,14 +1044,12 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (words_fin == 0) break; } - fclose (combs_fp); - - fclose (base_fp); + hc_fclose (&extra_info_combi.base_fp); + hc_fclose (&extra_info_combi.combs_fp); wl_data_destroy (hashcat_ctx_tmp); hcfree (hashcat_ctx_tmp->wl_data); - hcfree (hashcat_ctx_tmp); } else if (attack_mode == ATTACK_MODE_BF) @@ -1322,16 +1306,12 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) { char *dictfile = straight_ctx->dict; - FILE *combs_fp = fopen (dictfile, "rb"); - - if (combs_fp == NULL) + if (hc_fopen (&device_param->combs_fp, dictfile, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", dictfile, strerror (errno)); return -1; } - - device_param->combs_fp = combs_fp; } while (status_ctx->run_thread_level1 == true) @@ -1388,37 +1368,29 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) { const char *dictfilec = combinator_ctx->dict2; - FILE *combs_fp = fopen (dictfilec, "rb"); - - if (combs_fp == NULL) + if (hc_fopen (&device_param->combs_fp, dictfilec, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", combinator_ctx->dict2, strerror (errno)); return -1; } - - device_param->combs_fp = combs_fp; } else if (combs_mode == COMBINATOR_MODE_BASE_RIGHT) { const char *dictfilec = combinator_ctx->dict1; - FILE *combs_fp = fopen (dictfilec, "rb"); - - if (combs_fp == NULL) + if (hc_fopen (&device_param->combs_fp, dictfilec, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", dictfilec, strerror (errno)); return -1; } - - device_param->combs_fp = combs_fp; } } - FILE *fd = fopen (dictfile, "rb"); + HCFILE fp; - if (fd == NULL) + if (hc_fopen (&fp, dictfile, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", dictfile, strerror (errno)); @@ -1435,9 +1407,9 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (rc_wl_data_init == -1) { - if (attack_mode == ATTACK_MODE_COMBI) fclose (device_param->combs_fp); + if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (&device_param->combs_fp); - fclose (fd); + hc_fclose (&fp); hcfree (hashcat_ctx_tmp->wl_data); @@ -1476,11 +1448,11 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) char rule_buf_out[RP_PASSWORD_SIZE]; - for ( ; words_cur < words_off; words_cur++) get_next_word (hashcat_ctx_tmp, fd, &line_buf, &line_len); + for ( ; words_cur < words_off; words_cur++) get_next_word (hashcat_ctx_tmp, &fp, &line_buf, &line_len); for ( ; words_cur < words_fin; words_cur++) { - get_next_word (hashcat_ctx_tmp, fd, &line_buf, &line_len); + get_next_word (hashcat_ctx_tmp, &fp, &line_buf, &line_len); line_len = (u32) convert_from_hex (hashcat_ctx, line_buf, line_len); @@ -1567,9 +1539,9 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (CL_rc == -1) { - if (attack_mode == ATTACK_MODE_COMBI) fclose (device_param->combs_fp); + if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (&device_param->combs_fp); - fclose (fd); + hc_fclose (&fp); hcfree (hashcat_ctx_tmp->wl_data); @@ -1582,9 +1554,9 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (CL_rc == -1) { - if (attack_mode == ATTACK_MODE_COMBI) fclose (device_param->combs_fp); + if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (&device_param->combs_fp); - fclose (fd); + hc_fclose (&fp); hcfree (hashcat_ctx_tmp->wl_data); @@ -1638,9 +1610,9 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (words_fin == 0) break; } - if (attack_mode == ATTACK_MODE_COMBI) fclose (device_param->combs_fp); + if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (&device_param->combs_fp); - fclose (fd); + hc_fclose (&fp); wl_data_destroy (hashcat_ctx_tmp); diff --git a/src/filehandling.c b/src/filehandling.c index 06867abea..ae39c1a06 100644 --- a/src/filehandling.c +++ b/src/filehandling.c @@ -9,7 +9,7 @@ #include "shared.h" #include "filehandling.h" -u64 count_lines (FILE *fd) +u64 count_lines (HCFILE *fp) { u64 cnt = 0; @@ -17,9 +17,9 @@ u64 count_lines (FILE *fd) char prev = '\n'; - while (!feof (fd)) + while (!hc_feof (fp)) { - size_t nread = hc_fread (buf, sizeof (char), HCBUFSIZ_LARGE, fd); + size_t nread = hc_fread (buf, sizeof (char), HCBUFSIZ_LARGE, fp); if (nread < 1) continue; @@ -38,13 +38,13 @@ u64 count_lines (FILE *fd) return cnt; } -size_t fgetl (FILE *fp, char *line_buf) +size_t fgetl (HCFILE *fp, char *line_buf) { size_t line_len = 0; - while (!feof (fp)) + while (!hc_feof (fp)) { - const int c = fgetc (fp); + const int c = hc_fgetc (fp); if (c == EOF) break; diff --git a/src/hashes.c b/src/hashes.c index 72b9aad69..1a72d0adf 100644 --- a/src/hashes.c +++ b/src/hashes.c @@ -184,9 +184,9 @@ int save_hash (hashcat_ctx_t *hashcat_ctx) char separator = hashconfig->separator; - FILE *fp = fopen (new_hashfile, "wb"); + HCFILE fp; - if (fp == NULL) + if (hc_fopen (&fp, new_hashfile, "wb") == false) { event_log_error (hashcat_ctx, "%s: %s", new_hashfile, strerror (errno)); @@ -196,9 +196,9 @@ int save_hash (hashcat_ctx_t *hashcat_ctx) return -1; } - if (lock_file (fp) == -1) + if (hc_lockfile (&fp) == -1) { - fclose (fp); + hc_fclose (&fp); event_log_error (hashcat_ctx, "%s: %s", new_hashfile, strerror (errno)); @@ -228,7 +228,7 @@ int save_hash (hashcat_ctx_t *hashcat_ctx) const int binary_len = module_ctx->module_hash_binary_save (hashes, salt_pos, digest_pos, &binary_buf); - hc_fwrite (binary_buf, binary_len, 1, fp); + hc_fwrite (binary_buf, binary_len, 1, &fp); hcfree (binary_buf); } @@ -240,25 +240,25 @@ int save_hash (hashcat_ctx_t *hashcat_ctx) u32 i; - for (i = 0; i < user->user_len; i++) fputc (user->user_name[i], fp); + for (i = 0; i < user->user_len; i++) hc_fputc (user->user_name[i], &fp); - fputc (separator, fp); + hc_fputc (separator, &fp); } const int out_len = hash_encode (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf, HCBUFSIZ_LARGE, salt_pos, digest_pos); out_buf[out_len] = 0; - fprintf (fp, "%s" EOL, out_buf); + hc_fprintf (&fp, "%s" EOL, out_buf); } } } hcfree (out_buf); - fflush (fp); + hc_fflush (&fp); - fclose (fp); + hc_fclose (&fp); unlink (old_hashfile); @@ -431,14 +431,14 @@ void check_hash (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, pl // if enabled, update also the loopback file - if (loopback_ctx->fp != NULL) + if (loopback_ctx->fp.pfp != NULL) { loopback_write_append (hashcat_ctx, plain_ptr, plain_len); } // if enabled, update also the (rule) debug file - if (debugfile_ctx->fp != NULL) + if (debugfile_ctx->fp.pfp != NULL) { // the next check implies that: // - (user_options->attack_mode == ATTACK_MODE_STRAIGHT) @@ -674,9 +674,9 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) } else if (hashlist_mode == HL_MODE_FILE_PLAIN) { - FILE *fp = NULL; + HCFILE fp; - if ((fp = fopen (hashfile, "rb")) == NULL) + if (hc_fopen (&fp, hashfile, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", hashfile, strerror (errno)); @@ -685,33 +685,31 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) EVENT_DATA (EVENT_HASHLIST_COUNT_LINES_PRE, hashfile, strlen (hashfile)); - hashes_avail = count_lines (fp); + hashes_avail = count_lines (&fp); EVENT_DATA (EVENT_HASHLIST_COUNT_LINES_POST, hashfile, strlen (hashfile)); - rewind (fp); + hc_rewind (&fp); if (hashes_avail == 0) { event_log_error (hashcat_ctx, "hashfile is empty or corrupt."); - fclose (fp); + hc_fclose (&fp); return -1; } - hashlist_format = hlfmt_detect (hashcat_ctx, fp, 100); // 100 = max numbers to "scan". could be hashes_avail, too + hashlist_format = hlfmt_detect (hashcat_ctx, &fp, 100); // 100 = max numbers to "scan". could be hashes_avail, too + + hc_fclose (&fp); if ((user_options->remove == true) && (hashlist_format != HLFMT_HASHCAT)) { event_log_error (hashcat_ctx, "Use of --remove is not supported in native hashfile-format mode."); - fclose (fp); - return -1; } - - fclose (fp); } else if (hashlist_mode == HL_MODE_FILE_BINARY) { @@ -996,9 +994,9 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) } else if (hashlist_mode == HL_MODE_FILE_PLAIN) { - FILE *fp; + HCFILE fp; - if ((fp = fopen (hashfile, "rb")) == NULL) + if (hc_fopen (&fp, hashfile, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", hashfile, strerror (errno)); @@ -1012,11 +1010,11 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) time_t prev = 0; time_t now = 0; - while (!feof (fp)) + while (!hc_feof (&fp)) { line_num++; - const size_t line_len = fgetl (fp, line_buf); + const size_t line_len = fgetl (&fp, line_buf); if (line_len == 0) continue; @@ -1237,7 +1235,7 @@ int hashes_init_stage1 (hashcat_ctx_t *hashcat_ctx) hcfree (line_buf); - fclose (fp); + hc_fclose (&fp); } else if (hashlist_mode == HL_MODE_FILE_BINARY) { @@ -1792,7 +1790,9 @@ int hashes_init_selftest (hashcat_ctx_t *hashcat_ctx) hc_asprintf (&tmpfile_bin, "%s/selftest.hash", folder_config->session_dir); - FILE *fp = fopen (tmpfile_bin, "wb"); + HCFILE fp; + + hc_fopen (&fp, tmpfile_bin, "wb"); const size_t st_hash_len = strlen (hashconfig->st_hash); @@ -1800,10 +1800,10 @@ int hashes_init_selftest (hashcat_ctx_t *hashcat_ctx) { const u8 c = hex_to_u8 ((const u8 *) hashconfig->st_hash + i); - fputc (c, fp); + hc_fputc (c, &fp); } - fclose (fp); + hc_fclose (&fp); parser_status = module_ctx->module_hash_decode (hashconfig, hash.digest, hash.salt, hash.esalt, hash.hook_salt, hash.hash_info, tmpfile_bin, strlen (tmpfile_bin)); diff --git a/src/hlfmt.c b/src/hlfmt.c index 8bfbd69ca..c049f24fc 100644 --- a/src/hlfmt.c +++ b/src/hlfmt.c @@ -8,6 +8,7 @@ #include "memory.h" #include "filehandling.h" #include "hlfmt.h" +#include "shared.h" static const char *HLFMT_TEXT_HASHCAT = "native hashcat"; static const char *HLFMT_TEXT_PWDUMP = "pwdump"; @@ -333,7 +334,7 @@ void hlfmt_user (hashcat_ctx_t *hashcat_ctx, u32 hashfile_format, char *line_buf } } -u32 hlfmt_detect (hashcat_ctx_t *hashcat_ctx, FILE *fp, u32 max_check) +u32 hlfmt_detect (hashcat_ctx_t *hashcat_ctx, HCFILE *fp, u32 max_check) { const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; @@ -347,7 +348,7 @@ u32 hlfmt_detect (hashcat_ctx_t *hashcat_ctx, FILE *fp, u32 max_check) char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); - while (!feof (fp)) + while (!hc_feof (fp)) { const size_t line_len = fgetl (fp, line_buf); diff --git a/src/hwmon.c b/src/hwmon.c index 2bce94a3d..512f60b61 100644 --- a/src/hwmon.c +++ b/src/hwmon.c @@ -110,9 +110,9 @@ static int hm_SYSFS_get_fan_speed_current (hashcat_ctx_t *hashcat_ctx, const int hcfree (syspath); - FILE *fd_cur = fopen (path_cur, "r"); + HCFILE fp_cur; - if (fd_cur == NULL) + if (hc_fopen (&fp_cur, path_cur, "r") == false) { event_log_error (hashcat_ctx, "%s: %s", path_cur, strerror (errno)); @@ -124,9 +124,9 @@ static int hm_SYSFS_get_fan_speed_current (hashcat_ctx_t *hashcat_ctx, const int int pwm1_cur = 0; - if (fscanf (fd_cur, "%d", &pwm1_cur) != 1) + if (hc_fscanf (&fp_cur, "%d", &pwm1_cur) != 1) { - fclose (fd_cur); + hc_fclose (&fp_cur); event_log_error (hashcat_ctx, "%s: unexpected data.", path_cur); @@ -136,11 +136,11 @@ static int hm_SYSFS_get_fan_speed_current (hashcat_ctx_t *hashcat_ctx, const int return -1; } - fclose (fd_cur); + hc_fclose (&fp_cur); - FILE *fd_max = fopen (path_max, "r"); + HCFILE fp_max; - if (fd_max == NULL) + if (hc_fopen (&fp_max, path_max, "r") == false) { event_log_error (hashcat_ctx, "%s: %s", path_max, strerror (errno)); @@ -152,9 +152,9 @@ static int hm_SYSFS_get_fan_speed_current (hashcat_ctx_t *hashcat_ctx, const int int pwm1_max = 0; - if (fscanf (fd_max, "%d", &pwm1_max) != 1) + if (hc_fscanf (&fp_max, "%d", &pwm1_max) != 1) { - fclose (fd_max); + hc_fclose (&fp_max); event_log_error (hashcat_ctx, "%s: unexpected data.", path_max); @@ -164,7 +164,7 @@ static int hm_SYSFS_get_fan_speed_current (hashcat_ctx_t *hashcat_ctx, const int return -1; } - fclose (fd_max); + hc_fclose (&fp_max); if (pwm1_max == 0) { @@ -200,9 +200,9 @@ static int hm_SYSFS_get_temperature_current (hashcat_ctx_t *hashcat_ctx, const i hcfree (syspath); - FILE *fd = fopen (path, "r"); + HCFILE fp; - if (fd == NULL) + if (hc_fopen (&fp, path, "r") == false) { event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno)); @@ -213,9 +213,9 @@ static int hm_SYSFS_get_temperature_current (hashcat_ctx_t *hashcat_ctx, const i int temperature = 0; - if (fscanf (fd, "%d", &temperature) != 1) + if (hc_fscanf (&fp, "%d", &temperature) != 1) { - fclose (fd); + hc_fclose (&fp); event_log_error (hashcat_ctx, "%s: unexpected data.", path); @@ -224,7 +224,7 @@ static int hm_SYSFS_get_temperature_current (hashcat_ctx_t *hashcat_ctx, const i return -1; } - fclose (fd); + hc_fclose (&fp); *val = temperature / 1000; @@ -245,9 +245,9 @@ static int hm_SYSFS_get_pp_dpm_sclk (hashcat_ctx_t *hashcat_ctx, const int backe hcfree (syspath); - FILE *fd = fopen (path, "r"); + HCFILE fp; - if (fd == NULL) + if (hc_fopen (&fp, path, "r") == false) { event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno)); @@ -258,11 +258,11 @@ static int hm_SYSFS_get_pp_dpm_sclk (hashcat_ctx_t *hashcat_ctx, const int backe int clockfreq = 0; - while (!feof (fd)) + while (!hc_feof (&fp)) { - char buf[HCBUFSIZ_TINY]; + char buf[HCBUFSIZ_TINY] = { 0 }; - char *ptr = fgets (buf, sizeof (buf), fd); + char *ptr = hc_fgets (buf, sizeof (buf), &fp); if (ptr == NULL) continue; @@ -279,7 +279,7 @@ static int hm_SYSFS_get_pp_dpm_sclk (hashcat_ctx_t *hashcat_ctx, const int backe if (rc == 2) break; } - fclose (fd); + hc_fclose (&fp); *val = clockfreq; @@ -300,9 +300,9 @@ static int hm_SYSFS_get_pp_dpm_mclk (hashcat_ctx_t *hashcat_ctx, const int backe hcfree (syspath); - FILE *fd = fopen (path, "r"); + HCFILE fp; - if (fd == NULL) + if (hc_fopen (&fp, path, "r") == false) { event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno)); @@ -313,11 +313,11 @@ static int hm_SYSFS_get_pp_dpm_mclk (hashcat_ctx_t *hashcat_ctx, const int backe int clockfreq = 0; - while (!feof (fd)) + while (!hc_feof (&fp)) { char buf[HCBUFSIZ_TINY]; - char *ptr = fgets (buf, sizeof (buf), fd); + char *ptr = hc_fgets (buf, sizeof (buf), &fp); if (ptr == NULL) continue; @@ -334,7 +334,7 @@ static int hm_SYSFS_get_pp_dpm_mclk (hashcat_ctx_t *hashcat_ctx, const int backe if (rc == 2) break; } - fclose (fd); + hc_fclose (&fp); *val = clockfreq; @@ -355,9 +355,9 @@ static int hm_SYSFS_get_pp_dpm_pcie (hashcat_ctx_t *hashcat_ctx, const int backe hcfree (syspath); - FILE *fd = fopen (path, "r"); + HCFILE fp; - if (fd == NULL) + if (hc_fopen (&fp, path, "r") == false) { event_log_error (hashcat_ctx, "%s: %s", path, strerror (errno)); @@ -368,11 +368,11 @@ static int hm_SYSFS_get_pp_dpm_pcie (hashcat_ctx_t *hashcat_ctx, const int backe int lanes = 0; - while (!feof (fd)) + while (!hc_feof (&fp)) { char buf[HCBUFSIZ_TINY]; - char *ptr = fgets (buf, sizeof (buf), fd); + char *ptr = hc_fgets (buf, sizeof (buf), &fp); if (ptr == NULL) continue; @@ -390,7 +390,7 @@ static int hm_SYSFS_get_pp_dpm_pcie (hashcat_ctx_t *hashcat_ctx, const int backe if (rc == 3) break; } - fclose (fd); + hc_fclose (&fp); *val = lanes; @@ -460,9 +460,9 @@ static int nvml_init (hashcat_ctx_t *hashcat_ctx) if (!nvml->lib) { - FILE *nvml_lib = fopen ("/proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/NVIDIA Corporation/Global/NVSMI/NVSMIPATH", "rb"); + HCFILE nvml_lib; - if (nvml_lib == NULL) + if (hc_fopen (&nvml_lib, "/proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/NVIDIA Corporation/Global/NVSMI/NVSMIPATH", "rb") == false) { //if (user_options->quiet == false) // event_log_error (hashcat_ctx, "NVML library load failed: %m. Proceeding without NVML HWMon enabled."); @@ -474,9 +474,9 @@ static int nvml_init (hashcat_ctx_t *hashcat_ctx) nvml_winpath = (char *) hcmalloc (100); - hc_fread (nvml_winpath, 100, 1, nvml_lib); + hc_fread (nvml_winpath, 100, 1, &nvml_lib); - fclose (nvml_lib); + hc_fclose (&nvml_lib); ssize_t size = cygwin_conv_path (CCP_WIN_A_TO_POSIX | CCP_PROC_CYGDRIVE, nvml_winpath, NULL, 0); diff --git a/src/keyboard_layout.c b/src/keyboard_layout.c index 24778e1ba..2e6927557 100644 --- a/src/keyboard_layout.c +++ b/src/keyboard_layout.c @@ -22,15 +22,15 @@ bool initialize_keyboard_layout_mapping (const char *filename, keyboard_layout_m { char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); - FILE *fp = fopen (filename, "r"); + HCFILE fp; - if (fp == NULL) return false; + if (hc_fopen (&fp, filename, "r") == false) return false; int maps_cnt = 0; - while (!feof (fp)) + while (!hc_feof (&fp)) { - const size_t line_len = fgetl (fp, line_buf); + const size_t line_len = fgetl (&fp, line_buf); if (line_len == 0) continue; @@ -52,7 +52,7 @@ bool initialize_keyboard_layout_mapping (const char *filename, keyboard_layout_m if (rc_tokenizer != PARSER_OK) { - fclose (fp); + hc_fclose (&fp); free (line_buf); @@ -67,7 +67,7 @@ bool initialize_keyboard_layout_mapping (const char *filename, keyboard_layout_m if (maps_cnt == 256) { - fclose (fp); + hc_fclose (&fp); free (line_buf); @@ -79,7 +79,7 @@ bool initialize_keyboard_layout_mapping (const char *filename, keyboard_layout_m *keyboard_layout_mapping_cnt = maps_cnt; - fclose (fp); + hc_fclose (&fp); free (line_buf); diff --git a/src/locking.c b/src/locking.c index 756bb1abc..411a02178 100644 --- a/src/locking.c +++ b/src/locking.c @@ -6,11 +6,14 @@ #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 == NULL) return -1; + struct flock lock; memset (&lock, 0, sizeof (struct flock)); @@ -18,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; } @@ -26,32 +29,31 @@ int lock_file (FILE *fp) return 0; } -int unlock_file (FILE *fp) +int hc_unlockfile (HCFILE *fp) { + if (fp == NULL) return -1; + struct flock lock; memset (&lock, 0, sizeof (struct flock)); lock.l_type = F_UNLCK; - if (fcntl (fileno (fp), F_SETLK, &lock)) - { - return -1; - } + if (fcntl (hc_fileno (fp), F_SETLK, &lock)) return -1; return 0; } #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 e0626f3f6..29f342a4b 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -43,30 +43,30 @@ void logfile_append (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...) if (logfile_ctx->enabled == false) return; - FILE *fp = fopen (logfile_ctx->logfile, "ab"); + HCFILE fp; - if (fp == NULL) + if (hc_fopen (&fp, logfile_ctx->logfile, "ab") == false) { event_log_error (hashcat_ctx, "%s: %s", logfile_ctx->logfile, strerror (errno)); return; } - lock_file (fp); + hc_lockfile (&fp); va_list ap; va_start (ap, fmt); - vfprintf (fp, fmt, ap); + hc_vfprintf (&fp, fmt, ap); va_end (ap); - hc_fwrite (EOL, strlen (EOL), 1, fp); + hc_fwrite (EOL, strlen (EOL), 1, &fp); - fflush (fp); + hc_fflush (&fp); - fclose (fp); + hc_fclose (&fp); } int logfile_init (hashcat_ctx_t *hashcat_ctx) diff --git a/src/loopback.c b/src/loopback.c index 057c1e456..d289a70c1 100644 --- a/src/loopback.c +++ b/src/loopback.c @@ -38,18 +38,18 @@ static void loopback_format_plain (hashcat_ctx_t *hashcat_ctx, const u8 *plain_p if (needs_hexify == 1) { - fprintf (loopback_ctx->fp, "$HEX["); + hc_fprintf (&loopback_ctx->fp, "$HEX["); for (u32 i = 0; i < plain_len; i++) { - fprintf (loopback_ctx->fp, "%02x", plain_ptr[i]); + hc_fprintf (&loopback_ctx->fp, "%02x", plain_ptr[i]); } - fprintf (loopback_ctx->fp, "]"); + hc_fprintf (&loopback_ctx->fp, "]"); } else { - hc_fwrite (plain_ptr, plain_len, 1, loopback_ctx->fp); + hc_fwrite ((void *)plain_ptr, plain_len, 1, &loopback_ctx->fp); } } @@ -73,7 +73,7 @@ int loopback_init (hashcat_ctx_t *hashcat_ctx) if (user_options->version == true) return 0; loopback_ctx->enabled = true; - loopback_ctx->fp = NULL; + loopback_ctx->fp.pfp = NULL; loopback_ctx->filename = (char *) hcmalloc (HCBUFSIZ_TINY); return 0; @@ -105,17 +105,13 @@ int loopback_write_open (hashcat_ctx_t *hashcat_ctx) hc_asprintf (&loopback_ctx->filename, "%s/%s.%d_%u", induct_ctx->root_directory, LOOPBACK_FILE, (int) now, random_num); - FILE *fp = fopen (loopback_ctx->filename, "ab"); - - if (fp == NULL) + if (hc_fopen (&loopback_ctx->fp, loopback_ctx->filename, "ab") == false) { event_log_error (hashcat_ctx, "%s: %s", loopback_ctx->filename, strerror (errno)); return -1; } - loopback_ctx->fp = fp; - loopback_ctx->unused = true; return 0; @@ -138,9 +134,9 @@ void loopback_write_close (hashcat_ctx_t *hashcat_ctx) if (loopback_ctx->enabled == false) return; - if (loopback_ctx->fp == NULL) return; + if (loopback_ctx->fp.pfp == NULL) return; - fclose (loopback_ctx->fp); + hc_fclose (&loopback_ctx->fp); if (loopback_ctx->unused == true) { @@ -154,17 +150,15 @@ void loopback_write_append (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ptr, con if (loopback_ctx->enabled == false) return; - FILE *fp = loopback_ctx->fp; - loopback_format_plain (hashcat_ctx, plain_ptr, plain_len); - lock_file (fp); + hc_lockfile (&loopback_ctx->fp); - hc_fwrite (EOL, strlen (EOL), 1, fp); + hc_fwrite (EOL, strlen (EOL), 1, &loopback_ctx->fp); - fflush (fp); + hc_fflush (&loopback_ctx->fp); - if (unlock_file (fp)) + if (hc_unlockfile (&loopback_ctx->fp)) { event_log_error (hashcat_ctx, "%s: Failed to unlock file", loopback_ctx->filename); } diff --git a/src/main.c b/src/main.c index c5a684f1e..d3822b449 100644 --- a/src/main.c +++ b/src/main.c @@ -34,10 +34,7 @@ static void main_log_clear_line (MAYBE_UNUSED const size_t prev_len, MAYBE_UNUSE fputc ('\r', fp); - for (size_t i = 0; i < prev_len; i++) - { - fputc (' ', fp); - } + for (size_t i = 0; i < prev_len; i++) fputc (' ', fp); fputc ('\r', fp); @@ -60,10 +57,7 @@ static void main_log (hashcat_ctx_t *hashcat_ctx, FILE *fp, const int loglevel) const size_t prev_len = event_ctx->prev_len; - if (prev_len) - { - main_log_clear_line (prev_len, fp); - } + if (prev_len) main_log_clear_line (prev_len, fp); if (msg_newline == true) { @@ -100,16 +94,16 @@ static void main_log (hashcat_ctx_t *hashcat_ctx, FILE *fp, const int loglevel) #else switch (loglevel) { - case LOGLEVEL_INFO: break; - case LOGLEVEL_WARNING: hc_fwrite ("\033[33m", 5, 1, fp); break; - case LOGLEVEL_ERROR: hc_fwrite ("\033[31m", 5, 1, fp); break; - case LOGLEVEL_ADVICE: hc_fwrite ("\033[33m", 5, 1, fp); break; + case LOGLEVEL_INFO: break; + case LOGLEVEL_WARNING: fwrite ("\033[33m", 5, 1, fp); break; + case LOGLEVEL_ERROR: fwrite ("\033[31m", 5, 1, fp); break; + case LOGLEVEL_ADVICE: fwrite ("\033[33m", 5, 1, fp); break; } #endif // finally, print - hc_fwrite (msg_buf, msg_len, 1, fp); + fwrite (msg_buf, msg_len, 1, fp); // color stuff post @@ -124,10 +118,10 @@ static void main_log (hashcat_ctx_t *hashcat_ctx, FILE *fp, const int loglevel) #else switch (loglevel) { - case LOGLEVEL_INFO: break; - case LOGLEVEL_WARNING: hc_fwrite ("\033[0m", 4, 1, fp); break; - case LOGLEVEL_ERROR: hc_fwrite ("\033[0m", 4, 1, fp); break; - case LOGLEVEL_ADVICE: hc_fwrite ("\033[0m", 4, 1, fp); break; + case LOGLEVEL_INFO: break; + case LOGLEVEL_WARNING: fwrite ("\033[0m", 4, 1, fp); break; + case LOGLEVEL_ERROR: fwrite ("\033[0m", 4, 1, fp); break; + case LOGLEVEL_ADVICE: fwrite ("\033[0m", 4, 1, fp); break; } #endif @@ -135,13 +129,13 @@ static void main_log (hashcat_ctx_t *hashcat_ctx, FILE *fp, const int loglevel) if (msg_newline == true) { - hc_fwrite (EOL, strlen (EOL), 1, fp); + fwrite (EOL, strlen (EOL), 1, fp); // on error, add another newline if (loglevel == LOGLEVEL_ERROR) { - hc_fwrite (EOL, strlen (EOL), 1, fp); + fwrite (EOL, strlen (EOL), 1, fp); } } @@ -333,15 +327,15 @@ static void main_cracker_hash_cracked (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, user_options_t *user_options = hashcat_ctx->user_options; user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; - if (outfile_ctx->fp != NULL) return; // cracked hash was not written to an outfile + if (outfile_ctx->fp.pfp != NULL) return; // cracked hash was not written to an outfile if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { if (outfile_ctx->filename == NULL) if (user_options->quiet == false) clear_prompt (hashcat_ctx); } - hc_fwrite (buf, len, 1, stdout); - hc_fwrite (EOL, strlen (EOL), 1, stdout); + fwrite (buf, len, 1, stdout); + fwrite (EOL, strlen (EOL), 1, stdout); if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { @@ -384,20 +378,20 @@ static void main_potfile_hash_show (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAY { outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; - if (outfile_ctx->fp != NULL) return; // cracked hash was not written to an outfile + if (outfile_ctx->fp.pfp != NULL) return; // cracked hash was not written to an outfile - hc_fwrite (buf, len, 1, stdout); - hc_fwrite (EOL, strlen (EOL), 1, stdout); + fwrite (buf, len, 1, stdout); + fwrite (EOL, strlen (EOL), 1, stdout); } static void main_potfile_hash_left (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) { outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; - if (outfile_ctx->fp != NULL) return; // cracked hash was not written to an outfile + if (outfile_ctx->fp.pfp != NULL) return; // cracked hash was not written to an outfile - hc_fwrite (buf, len, 1, stdout); - hc_fwrite (EOL, strlen (EOL), 1, stdout); + fwrite (buf, len, 1, stdout); + fwrite (EOL, strlen (EOL), 1, stdout); } static void main_potfile_num_cracked (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) diff --git a/src/modules/module_02500.c b/src/modules/module_02500.c index 066fe55e9..8907f8677 100644 --- a/src/modules/module_02500.c +++ b/src/modules/module_02500.c @@ -374,15 +374,15 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE int hashes_cnt = 0; - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return -1; + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return -1; char *in = (char *) hcmalloc (sizeof (hccapx_t)); - while (!feof (fp)) + while (!hc_feof (&fp)) { - const size_t nread = hc_fread (in, sizeof (hccapx_t), 1, fp); + const size_t nread = hc_fread (in, sizeof (hccapx_t), 1, &fp); if (nread == 0) break; @@ -458,7 +458,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE hcfree (in); - fclose (fp); + hc_fclose (&fp); return hashes_cnt; } diff --git a/src/modules/module_02501.c b/src/modules/module_02501.c index a4a6087cd..a7ce17b04 100644 --- a/src/modules/module_02501.c +++ b/src/modules/module_02501.c @@ -349,15 +349,15 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE int hashes_cnt = 0; - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return -1; + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return -1; char *in = (char *) hcmalloc (sizeof (hccapx_t)); - while (!feof (fp)) + while (!hc_feof (&fp)) { - const size_t nread = hc_fread (in, sizeof (hccapx_t), 1, fp); + const size_t nread = hc_fread (in, sizeof (hccapx_t), 1, &fp); if (nread == 0) break; @@ -433,7 +433,7 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE hcfree (in); - fclose (fp); + hc_fclose (&fp); return hashes_cnt; } diff --git a/src/modules/module_05200.c b/src/modules/module_05200.c index 4786fa276..7c50b5d47 100644 --- a/src/modules/module_05200.c +++ b/src/modules/module_05200.c @@ -93,17 +93,17 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE if (line_len == 0) return (PARSER_HASH_LENGTH); - FILE *fp = fopen ((const char *) line_buf, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, (const char *) line_buf, "rb") == false) return (PARSER_HASH_FILE); psafe3_t in; memset (&in, 0, sizeof (psafe3_t)); - const size_t n = hc_fread (&in, sizeof (psafe3_t), 1, fp); + const size_t n = hc_fread (&in, sizeof (psafe3_t), 1, &fp); - fclose (fp); + hc_fclose (&fp); if (n != 1) return (PARSER_PSAFE3_FILE_SIZE); diff --git a/src/modules/module_06211.c b/src/modules/module_06211.c index cda6ab359..8f2be8897 100644 --- a/src/modules/module_06211.c +++ b/src/modules/module_06211.c @@ -146,17 +146,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define TC_HEADER_SIZE 512 char *in = (char *) hcmalloc (TC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != TC_HEADER_SIZE) return (PARSER_TC_FILE_SIZE); diff --git a/src/modules/module_06212.c b/src/modules/module_06212.c index 8f4cae1a5..bfc9d05d8 100644 --- a/src/modules/module_06212.c +++ b/src/modules/module_06212.c @@ -146,17 +146,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define TC_HEADER_SIZE 512 char *in = (char *) hcmalloc (TC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != TC_HEADER_SIZE) return (PARSER_TC_FILE_SIZE); diff --git a/src/modules/module_06213.c b/src/modules/module_06213.c index 6283d863d..1b09d8607 100644 --- a/src/modules/module_06213.c +++ b/src/modules/module_06213.c @@ -144,17 +144,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define TC_HEADER_SIZE 512 char *in = (char *) hcmalloc (TC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != TC_HEADER_SIZE) return (PARSER_TC_FILE_SIZE); diff --git a/src/modules/module_06221.c b/src/modules/module_06221.c index e6e812e01..6d43ffe3c 100644 --- a/src/modules/module_06221.c +++ b/src/modules/module_06221.c @@ -144,17 +144,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define TC_HEADER_SIZE 512 char *in = (char *) hcmalloc (TC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != TC_HEADER_SIZE) return (PARSER_TC_FILE_SIZE); diff --git a/src/modules/module_06222.c b/src/modules/module_06222.c index 3da847cd7..b0ae40989 100644 --- a/src/modules/module_06222.c +++ b/src/modules/module_06222.c @@ -144,17 +144,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define TC_HEADER_SIZE 512 char *in = (char *) hcmalloc (TC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != TC_HEADER_SIZE) return (PARSER_TC_FILE_SIZE); diff --git a/src/modules/module_06223.c b/src/modules/module_06223.c index 512ee2df8..ee3c1f5ed 100644 --- a/src/modules/module_06223.c +++ b/src/modules/module_06223.c @@ -144,17 +144,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define TC_HEADER_SIZE 512 char *in = (char *) hcmalloc (TC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != TC_HEADER_SIZE) return (PARSER_TC_FILE_SIZE); diff --git a/src/modules/module_06231.c b/src/modules/module_06231.c index 9af349d22..e01fd7300 100644 --- a/src/modules/module_06231.c +++ b/src/modules/module_06231.c @@ -146,17 +146,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define TC_HEADER_SIZE 512 char *in = (char *) hcmalloc (TC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != TC_HEADER_SIZE) return (PARSER_TC_FILE_SIZE); diff --git a/src/modules/module_06232.c b/src/modules/module_06232.c index 324656885..b8a404670 100644 --- a/src/modules/module_06232.c +++ b/src/modules/module_06232.c @@ -146,17 +146,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define TC_HEADER_SIZE 512 char *in = (char *) hcmalloc (TC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != TC_HEADER_SIZE) return (PARSER_TC_FILE_SIZE); diff --git a/src/modules/module_06233.c b/src/modules/module_06233.c index 2446ba43d..499f0714a 100644 --- a/src/modules/module_06233.c +++ b/src/modules/module_06233.c @@ -146,17 +146,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define TC_HEADER_SIZE 512 char *in = (char *) hcmalloc (TC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != TC_HEADER_SIZE) return (PARSER_TC_FILE_SIZE); diff --git a/src/modules/module_06241.c b/src/modules/module_06241.c index 1acf83e2b..09c3e8ec7 100644 --- a/src/modules/module_06241.c +++ b/src/modules/module_06241.c @@ -158,17 +158,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define TC_HEADER_SIZE 512 char *in = (char *) hcmalloc (TC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != TC_HEADER_SIZE) return (PARSER_TC_FILE_SIZE); diff --git a/src/modules/module_06242.c b/src/modules/module_06242.c index df9f4d311..20a239fd0 100644 --- a/src/modules/module_06242.c +++ b/src/modules/module_06242.c @@ -158,17 +158,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define TC_HEADER_SIZE 512 char *in = (char *) hcmalloc (TC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != TC_HEADER_SIZE) return (PARSER_TC_FILE_SIZE); diff --git a/src/modules/module_06243.c b/src/modules/module_06243.c index d822d0313..baa540b0c 100644 --- a/src/modules/module_06243.c +++ b/src/modules/module_06243.c @@ -158,17 +158,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define TC_HEADER_SIZE 512 char *in = (char *) hcmalloc (TC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, TC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != TC_HEADER_SIZE) return (PARSER_TC_FILE_SIZE); diff --git a/src/modules/module_09000.c b/src/modules/module_09000.c index abfe03071..b69166668 100644 --- a/src/modules/module_09000.c +++ b/src/modules/module_09000.c @@ -156,17 +156,17 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE if (line_len == 0) return (PARSER_HASH_LENGTH); - FILE *fp = fopen ((const char *) line_buf, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, (const char *) line_buf, "rb") == false) return (PARSER_HASH_FILE); psafe2_hdr buf; memset (&buf, 0, sizeof (psafe2_hdr)); - const size_t n = hc_fread (&buf, sizeof (psafe2_hdr), 1, fp); + const size_t n = hc_fread (&buf, sizeof (psafe2_hdr), 1, &fp); - fclose (fp); + hc_fclose (&fp); if (n != 1) return (PARSER_PSAFE2_FILE_SIZE); diff --git a/src/modules/module_13711.c b/src/modules/module_13711.c index c40bb931e..87852ec44 100644 --- a/src/modules/module_13711.c +++ b/src/modules/module_13711.c @@ -172,17 +172,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13712.c b/src/modules/module_13712.c index 281991446..c8179fb71 100644 --- a/src/modules/module_13712.c +++ b/src/modules/module_13712.c @@ -172,17 +172,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13713.c b/src/modules/module_13713.c index 1932c3e30..062378441 100644 --- a/src/modules/module_13713.c +++ b/src/modules/module_13713.c @@ -172,17 +172,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13721.c b/src/modules/module_13721.c index bfd0d8bde..fba2cc96d 100644 --- a/src/modules/module_13721.c +++ b/src/modules/module_13721.c @@ -170,17 +170,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13722.c b/src/modules/module_13722.c index 537d2461f..7e8257b77 100644 --- a/src/modules/module_13722.c +++ b/src/modules/module_13722.c @@ -170,17 +170,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13723.c b/src/modules/module_13723.c index 3d13c9094..5b9c5cb94 100644 --- a/src/modules/module_13723.c +++ b/src/modules/module_13723.c @@ -170,17 +170,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13731.c b/src/modules/module_13731.c index 3fcd893b9..3afff8644 100644 --- a/src/modules/module_13731.c +++ b/src/modules/module_13731.c @@ -172,17 +172,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13732.c b/src/modules/module_13732.c index ccf993163..965776e9e 100644 --- a/src/modules/module_13732.c +++ b/src/modules/module_13732.c @@ -172,17 +172,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13733.c b/src/modules/module_13733.c index 0300eaa29..3a7d0bbbb 100644 --- a/src/modules/module_13733.c +++ b/src/modules/module_13733.c @@ -172,17 +172,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13741.c b/src/modules/module_13741.c index 4c1256b51..45fa7d48c 100644 --- a/src/modules/module_13741.c +++ b/src/modules/module_13741.c @@ -173,17 +173,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13742.c b/src/modules/module_13742.c index ca30e757d..eda71240c 100644 --- a/src/modules/module_13742.c +++ b/src/modules/module_13742.c @@ -173,17 +173,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13743.c b/src/modules/module_13743.c index fc92900f2..fb3b75f0f 100644 --- a/src/modules/module_13743.c +++ b/src/modules/module_13743.c @@ -173,17 +173,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13751.c b/src/modules/module_13751.c index 1b2031365..dae3c2d94 100644 --- a/src/modules/module_13751.c +++ b/src/modules/module_13751.c @@ -172,17 +172,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13752.c b/src/modules/module_13752.c index f86cabfe6..9f847766b 100644 --- a/src/modules/module_13752.c +++ b/src/modules/module_13752.c @@ -172,17 +172,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13753.c b/src/modules/module_13753.c index 68bb3c34d..8113f044c 100644 --- a/src/modules/module_13753.c +++ b/src/modules/module_13753.c @@ -172,17 +172,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13761.c b/src/modules/module_13761.c index 0114f8f29..5fc1a1376 100644 --- a/src/modules/module_13761.c +++ b/src/modules/module_13761.c @@ -173,17 +173,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13762.c b/src/modules/module_13762.c index 79ddf5c1f..b0da01aa7 100644 --- a/src/modules/module_13762.c +++ b/src/modules/module_13762.c @@ -173,17 +173,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13763.c b/src/modules/module_13763.c index cebeb8d89..09fb93505 100644 --- a/src/modules/module_13763.c +++ b/src/modules/module_13763.c @@ -173,17 +173,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13771.c b/src/modules/module_13771.c index 32107bcd4..f788981ef 100644 --- a/src/modules/module_13771.c +++ b/src/modules/module_13771.c @@ -176,17 +176,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13772.c b/src/modules/module_13772.c index 5c3bcbd17..e52ee2725 100644 --- a/src/modules/module_13772.c +++ b/src/modules/module_13772.c @@ -176,17 +176,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_13773.c b/src/modules/module_13773.c index a03df7c33..20634ebe4 100644 --- a/src/modules/module_13773.c +++ b/src/modules/module_13773.c @@ -176,17 +176,17 @@ int module_hash_binary_parse (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE { // note: if module_hash_binary_parse exists, then module_hash_decode is not called - FILE *fp = fopen (hashes->hashfile, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, hashes->hashfile, "rb") == false) return (PARSER_HASH_FILE); #define VC_HEADER_SIZE 512 char *in = (char *) hcmalloc (VC_HEADER_SIZE); - const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, fp); + const size_t n = hc_fread (in, 1, VC_HEADER_SIZE, &fp); - fclose (fp); + hc_fclose (&fp); if (n != VC_HEADER_SIZE) return (PARSER_VC_FILE_SIZE); diff --git a/src/modules/module_14600.c b/src/modules/module_14600.c index 3d30341ac..9b8fcc357 100644 --- a/src/modules/module_14600.c +++ b/src/modules/module_14600.c @@ -351,17 +351,17 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE if (line_len == 0) return (PARSER_HASH_LENGTH); - FILE *fp = fopen ((const char *) line_buf, "rb"); + HCFILE fp; - if (fp == NULL) return (PARSER_HASH_FILE); + if (hc_fopen (&fp, (const char *) line_buf, "rb") == false) return (PARSER_HASH_FILE); struct luks_phdr hdr; - const size_t nread = hc_fread (&hdr, sizeof (hdr), 1, fp); + const size_t nread = hc_fread (&hdr, sizeof (hdr), 1, &fp); if (nread != 1) { - fclose (fp); + hc_fclose (&fp); return (PARSER_LUKS_FILE_SIZE); } @@ -385,14 +385,14 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE if (memcmp (hdr.magic, luks_magic, LUKS_MAGIC_L) != 0) { - fclose (fp); + hc_fclose (&fp); return (PARSER_LUKS_MAGIC); } if (byte_swap_16 (hdr.version) != 1) { - fclose (fp); + hc_fclose (&fp); return (PARSER_LUKS_VERSION); } @@ -411,7 +411,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE } else { - fclose (fp); + hc_fclose (&fp); return (PARSER_LUKS_CIPHER_TYPE); } @@ -438,7 +438,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE } else { - fclose (fp); + hc_fclose (&fp); return (PARSER_LUKS_CIPHER_MODE); } @@ -465,7 +465,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE } else { - fclose (fp); + hc_fclose (&fp); return (PARSER_LUKS_HASH_TYPE); } @@ -486,7 +486,7 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE } else { - fclose (fp); + hc_fclose (&fp); return (PARSER_LUKS_KEY_SIZE); } @@ -498,14 +498,14 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE if (active != LUKS_KEY_ENABLED) { - fclose (fp); + hc_fclose (&fp); return (PARSER_LUKS_KEY_DISABLED); } if (stripes != LUKS_STRIPES) { - fclose (fp); + hc_fclose (&fp); return (PARSER_LUKS_KEY_STRIPES); } @@ -533,20 +533,20 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u32 keyMaterialOffset = byte_swap_32 (hdr.keyblock[keyslot_idx].keyMaterialOffset); - const int rc_seek1 = fseeko (fp, keyMaterialOffset * 512, SEEK_SET); + const int rc_seek1 = hc_fseek (&fp, keyMaterialOffset * 512, SEEK_SET); if (rc_seek1 == -1) { - fclose (fp); + hc_fclose (&fp); return (PARSER_LUKS_FILE_SIZE); } - const size_t nread2 = hc_fread (luks->af_src_buf, keyBytes, stripes, fp); + const size_t nread2 = hc_fread (luks->af_src_buf, keyBytes, stripes, &fp); if (nread2 != stripes) { - fclose (fp); + hc_fclose (&fp); return (PARSER_LUKS_FILE_SIZE); } @@ -555,27 +555,27 @@ int module_hash_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, MAYBE_UNUSE const u32 payloadOffset = byte_swap_32 (hdr.payloadOffset); - const int rc_seek2 = fseeko (fp, payloadOffset * 512, SEEK_SET); + const int rc_seek2 = hc_fseek (&fp, payloadOffset * 512, SEEK_SET); if (rc_seek2 == -1) { - fclose (fp); + hc_fclose (&fp); return (PARSER_LUKS_FILE_SIZE); } - const size_t nread3 = hc_fread (luks->ct_buf, sizeof (u32), 128, fp); + const size_t nread3 = hc_fread (luks->ct_buf, sizeof (u32), 128, &fp); if (nread3 != 128) { - fclose (fp); + hc_fclose (&fp); return (PARSER_LUKS_FILE_SIZE); } // that should be it, close the fp - fclose (fp); + hc_fclose (&fp); return (PARSER_OK); } diff --git a/src/mpsp.c b/src/mpsp.c index c3a54e47d..f6d81a6aa 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -582,9 +582,9 @@ static void mp_setup_sys (cs_t *mp_sys) static int mp_setup_usr (hashcat_ctx_t *hashcat_ctx, cs_t *mp_sys, cs_t *mp_usr, const char *buf, const u32 userindex) { - FILE *fp = fopen (buf, "rb"); + HCFILE fp; - if (fp == NULL) // feof() in case if file is empty + if (hc_fopen (&fp, buf, "rb") == false) { const int rc = mp_expand (hashcat_ctx, buf, strlen (buf), mp_sys, mp_usr, userindex, 1); @@ -594,18 +594,18 @@ static int mp_setup_usr (hashcat_ctx_t *hashcat_ctx, cs_t *mp_sys, cs_t *mp_usr, { char mp_file[1024]; - const size_t nread = hc_fread (mp_file, 1, sizeof (mp_file) - 1, fp); + const size_t nread = hc_fread (mp_file, 1, sizeof (mp_file) - 1, &fp); - if (!feof (fp)) + if (!hc_feof (&fp)) { event_log_error (hashcat_ctx, "%s: Custom charset file is too large.", buf); - fclose (fp); + hc_fclose (&fp); return -1; } - fclose (fp); + hc_fclose (&fp); if (nread == 0) { @@ -710,9 +710,9 @@ static int sp_setup_tbl (hashcat_ctx_t *hashcat_ctx) return -1; } - FILE *fd = fopen (hcstat, "rb"); + HCFILE fp; - if (fd == NULL) + if (hc_fopen (&fp, hcstat, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", hcstat, strerror (errno)); @@ -721,20 +721,20 @@ static int sp_setup_tbl (hashcat_ctx_t *hashcat_ctx) u8 *inbuf = (u8 *) hcmalloc (s.st_size); - SizeT inlen = (SizeT) hc_fread (inbuf, 1, s.st_size, fd); + SizeT inlen = (SizeT) hc_fread (inbuf, 1, s.st_size, &fp); if (inlen != (SizeT) s.st_size) { event_log_error (hashcat_ctx, "%s: Could not read data.", hcstat); - fclose (fd); + hc_fclose (&fp); hcfree (inbuf); return -1; } - fclose (fd); + hc_fclose (&fp); u8 *outbuf = (u8 *) hcmalloc (SP_FILESZ); @@ -1460,9 +1460,9 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (hc_path_is_file (arg) == true) { - FILE *mask_fp = fopen (arg, "r"); + HCFILE mask_fp; - if (mask_fp == NULL) + if (hc_fopen (&mask_fp, arg, "r") == false) { event_log_error (hashcat_ctx, "%s: %s", arg, strerror (errno)); @@ -1471,9 +1471,9 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); - while (!feof (mask_fp)) + while (!hc_feof (&mask_fp)) { - const size_t line_len = fgetl (mask_fp, line_buf); + const size_t line_len = fgetl (&mask_fp, line_buf); if (line_len == 0) continue; @@ -1496,7 +1496,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (rc == -1) { - fclose (mask_fp); + hc_fclose (&mask_fp); return -1; } @@ -1504,7 +1504,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) hcfree (line_buf); - fclose (mask_fp); + hc_fclose (&mask_fp); } else { @@ -1553,9 +1553,9 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) { mask_ctx->mask_from_file = true; - FILE *mask_fp = fopen (arg, "r"); + HCFILE mask_fp; - if (mask_fp == NULL) + if (hc_fopen (&mask_fp, arg, "r") == false) { event_log_error (hashcat_ctx, "%s: %s", arg, strerror (errno)); @@ -1564,9 +1564,9 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); - while (!feof (mask_fp)) + while (!hc_feof (&mask_fp)) { - const size_t line_len = fgetl (mask_fp, line_buf); + const size_t line_len = fgetl (&mask_fp, line_buf); if (line_len == 0) continue; @@ -1589,7 +1589,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (rc == -1) { - fclose (mask_fp); + hc_fclose (&mask_fp); return -1; } @@ -1597,7 +1597,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) hcfree (line_buf); - fclose (mask_fp); + hc_fclose (&mask_fp); } else { @@ -1627,9 +1627,9 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) { mask_ctx->mask_from_file = true; - FILE *mask_fp = fopen (arg, "r"); + HCFILE mask_fp; - if (mask_fp == NULL) + if (hc_fopen (&mask_fp, arg, "r") == false) { event_log_error (hashcat_ctx, "%s: %s", arg, strerror (errno)); @@ -1638,9 +1638,9 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); - while (!feof (mask_fp)) + while (!hc_feof (&mask_fp)) { - const size_t line_len = fgetl (mask_fp, line_buf); + const size_t line_len = fgetl (&mask_fp, line_buf); if (line_len == 0) continue; @@ -1663,7 +1663,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) if (rc == -1) { - fclose (mask_fp); + hc_fclose (&mask_fp); return -1; } @@ -1671,7 +1671,7 @@ int mask_ctx_init (hashcat_ctx_t *hashcat_ctx) hcfree (line_buf); - fclose (mask_fp); + hc_fclose (&mask_fp); } else { diff --git a/src/outfile.c b/src/outfile.c index 06e5c80ed..ecb5a7d36 100644 --- a/src/outfile.c +++ b/src/outfile.c @@ -369,7 +369,7 @@ int outfile_init (hashcat_ctx_t *hashcat_ctx) outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; user_options_t *user_options = hashcat_ctx->user_options; - outfile_ctx->fp = NULL; + outfile_ctx->fp.pfp = NULL; outfile_ctx->filename = user_options->outfile; outfile_ctx->outfile_format = user_options->outfile_format; outfile_ctx->outfile_autohex = user_options->outfile_autohex; @@ -390,26 +390,22 @@ int outfile_write_open (hashcat_ctx_t *hashcat_ctx) if (outfile_ctx->filename == NULL) return 0; - FILE *fp = fopen (outfile_ctx->filename, "ab"); - - if (fp == NULL) + if (hc_fopen (&outfile_ctx->fp, outfile_ctx->filename, "ab") == false) { event_log_error (hashcat_ctx, "%s: %s", outfile_ctx->filename, strerror (errno)); return -1; } - if (lock_file (fp) == -1) + if (hc_lockfile (&outfile_ctx->fp) == -1) { - fclose (fp); + hc_fclose (&outfile_ctx->fp); event_log_error (hashcat_ctx, "%s: %s", outfile_ctx->filename, strerror (errno)); return -1; } - outfile_ctx->fp = fp; - return 0; } @@ -417,16 +413,16 @@ void outfile_write_close (hashcat_ctx_t *hashcat_ctx) { outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; - if (outfile_ctx->fp == NULL) return; + if (outfile_ctx->fp.pfp == NULL) return; - fclose (outfile_ctx->fp); + hc_fclose (&outfile_ctx->fp); } int outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const int out_len, const unsigned char *plain_ptr, const u32 plain_len, const u64 crackpos, const unsigned char *username, const u32 user_len, char tmp_buf[HCBUFSIZ_LARGE]) { const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - const outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; const user_options_t *user_options = hashcat_ctx->user_options; + outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx; const u32 outfile_format = (hashconfig->opts_type & OPTS_TYPE_PT_ALWAYS_HEXIFY) ? 5 : outfile_ctx->outfile_format; @@ -527,10 +523,10 @@ int outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const int ou tmp_buf[tmp_len] = 0; - if (outfile_ctx->fp != NULL) + if (outfile_ctx->fp.pfp != NULL) { - hc_fwrite (tmp_buf, tmp_len, 1, outfile_ctx->fp); - hc_fwrite (EOL, strlen (EOL), 1, outfile_ctx->fp); + hc_fwrite (tmp_buf, tmp_len, 1, &outfile_ctx->fp); + hc_fwrite (EOL, strlen (EOL), 1, &outfile_ctx->fp); } return tmp_len; diff --git a/src/outfile_check.c b/src/outfile_check.c index db15049c0..c67b9429c 100644 --- a/src/outfile_check.c +++ b/src/outfile_check.c @@ -155,17 +155,17 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx) for (int j = 0; j < out_cnt; j++) { - FILE *fp = fopen (out_info[j].file_name, "rb"); + HCFILE fp; - if (fp == NULL) continue; + if (hc_fopen (&fp, out_info[j].file_name, "rb") == false) continue; //hc_thread_mutex_lock (status_ctx->mux_display); struct stat outfile_stat; - if (fstat (fileno (fp), &outfile_stat)) + if (fstat (hc_fileno (&fp), &outfile_stat)) { - fclose (fp); + hc_fclose (&fp); continue; } @@ -176,16 +176,16 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx) out_info[j].seek = 0; } - fseeko (fp, out_info[j].seek, SEEK_SET); + hc_fseek (&fp, out_info[j].seek, SEEK_SET); char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); // large portion of the following code is the same as in potfile_remove_parse // maybe subject of a future optimization - while (!feof (fp)) + while (!hc_feof (&fp)) { - size_t line_len = fgetl (fp, line_buf); + size_t line_len = fgetl (&fp, line_buf); if (line_len == 0) continue; @@ -307,11 +307,11 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx) hcfree (line_buf); - out_info[j].seek = ftello (fp); + out_info[j].seek = hc_ftell (&fp); //hc_thread_mutex_unlock (status_ctx->mux_display); - fclose (fp); + hc_fclose (&fp); if (status_ctx->shutdown_inner == true) break; } diff --git a/src/pidfile.c b/src/pidfile.c index a366d48ae..7da26fa70 100644 --- a/src/pidfile.c +++ b/src/pidfile.c @@ -16,15 +16,15 @@ static int check_running_process (hashcat_ctx_t *hashcat_ctx) char *pidfile_filename = pidfile_ctx->filename; - FILE *fp = fopen (pidfile_filename, "rb"); + HCFILE fp; - if (fp == NULL) return 0; + if (hc_fopen (&fp, pidfile_filename, "rb") == false) return 0; pidfile_data_t *pd = (pidfile_data_t *) hcmalloc (sizeof (pidfile_data_t)); - const size_t nread = hc_fread (pd, sizeof (pidfile_data_t), 1, fp); + const size_t nread = hc_fread (pd, sizeof (pidfile_data_t), 1, &fp); - fclose (fp); + hc_fclose (&fp); if (nread != 1) { @@ -153,20 +153,20 @@ static int write_pidfile (hashcat_ctx_t *hashcat_ctx) char *pidfile_filename = pidfile_ctx->filename; - FILE *fp = fopen (pidfile_filename, "wb"); + HCFILE fp; - if (fp == NULL) + if (hc_fopen (&fp, pidfile_filename, "wb") == false) { event_log_error (hashcat_ctx, "%s: %s", pidfile_filename, strerror (errno)); return -1; } - hc_fwrite (pd, sizeof (pidfile_data_t), 1, fp); + hc_fwrite (pd, sizeof (pidfile_data_t), 1, &fp); - fflush (fp); + hc_fflush (&fp); - fclose (fp); + hc_fclose (&fp); return 0; } diff --git a/src/potfile.c b/src/potfile.c index 9516d4ae5..efc552a48 100644 --- a/src/potfile.c +++ b/src/potfile.c @@ -117,14 +117,14 @@ int potfile_init (hashcat_ctx_t *hashcat_ctx) if (user_options->potfile_path == NULL) { - potfile_ctx->fp = NULL; + potfile_ctx->fp.pfp = NULL; hc_asprintf (&potfile_ctx->filename, "%s/hashcat.potfile", folder_config->profile_dir); } else { potfile_ctx->filename = hcstrdup (user_options->potfile_path); - potfile_ctx->fp = NULL; + potfile_ctx->fp.pfp = NULL; } // starting from here, we should allocate some scratch buffer for later use @@ -181,9 +181,7 @@ int potfile_read_open (hashcat_ctx_t *hashcat_ctx) if (potfile_ctx->enabled == false) return 0; - potfile_ctx->fp = fopen (potfile_ctx->filename, "rb"); - - if (potfile_ctx->fp == NULL) + if (hc_fopen (&potfile_ctx->fp, potfile_ctx->filename, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", potfile_ctx->filename, strerror (errno)); @@ -202,9 +200,9 @@ void potfile_read_close (hashcat_ctx_t *hashcat_ctx) if (hashconfig->potfile_disable == true) return; - if (potfile_ctx->fp == NULL) return; + if (potfile_ctx->fp.pfp == NULL) return; - fclose (potfile_ctx->fp); + hc_fclose (&potfile_ctx->fp); } int potfile_write_open (hashcat_ctx_t *hashcat_ctx) @@ -213,17 +211,13 @@ int potfile_write_open (hashcat_ctx_t *hashcat_ctx) if (potfile_ctx->enabled == false) return 0; - FILE *fp = fopen (potfile_ctx->filename, "ab"); - - if (fp == NULL) + if (hc_fopen (&potfile_ctx->fp, potfile_ctx->filename, "ab") == false) { event_log_error (hashcat_ctx, "%s: %s", potfile_ctx->filename, strerror (errno)); return -1; } - potfile_ctx->fp = fp; - return 0; } @@ -236,14 +230,14 @@ void potfile_write_close (hashcat_ctx_t *hashcat_ctx) if (hashconfig->potfile_disable == true) return; - fclose (potfile_ctx->fp); + hc_fclose (&potfile_ctx->fp); } void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const int out_len, u8 *plain_ptr, unsigned int plain_len) { const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; - const potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; const user_options_t *user_options = hashcat_ctx->user_options; + potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; if (potfile_ctx->enabled == false) return; @@ -292,13 +286,13 @@ void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, cons tmp_buf[tmp_len] = 0; - lock_file (potfile_ctx->fp); + hc_lockfile (&potfile_ctx->fp); - fprintf (potfile_ctx->fp, "%s" EOL, tmp_buf); + hc_fprintf (&potfile_ctx->fp, "%s" EOL, tmp_buf); - fflush (potfile_ctx->fp); + hc_fflush (&potfile_ctx->fp); - if (unlock_file (potfile_ctx->fp)) + if (hc_unlockfile (&potfile_ctx->fp)) { event_log_error (hashcat_ctx, "%s: Failed to unlock file.", potfile_ctx->filename); } @@ -327,7 +321,7 @@ void potfile_update_hash (hashcat_ctx_t *hashcat_ctx, hash_t *found, char *line_ // if enabled, update also the loopback file - if (loopback_ctx->fp != NULL) + if (loopback_ctx->fp.pfp != NULL) { loopback_write_append (hashcat_ctx, (u8 *) pw_buf, (unsigned int) pw_len); } @@ -351,7 +345,6 @@ void potfile_update_hashes (hashcat_ctx_t *hashcat_ctx, hash_t *hash_buf, char * search_entry.nodes = &search_node; search_entry.hashconfig = hashconfig; - // the main search function is this: void **found = tfind (&search_entry, (void **) &tree, sort_pot_tree_by_hash); @@ -376,7 +369,7 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx) const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; const hashes_t *hashes = hashcat_ctx->hashes; const module_ctx_t *module_ctx = hashcat_ctx->module_ctx; - const potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; + potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; if (potfile_ctx->enabled == false) return 0; @@ -456,7 +449,6 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx) // to sort by salt and we also need to have the correct order of dgst_pos0...dgst_pos3: new_entry->hashconfig = (hashconfig_t *) hashconfig; // "const hashconfig_t" gives a warning - // the following function searches if the "key" is already present and if not inserts the new entry: void **found = tsearch (new_entry, (void **) &all_hashes_tree, sort_pot_tree_by_hash); @@ -527,9 +519,9 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx) char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); - while (!feof (potfile_ctx->fp)) + while (!hc_feof (&potfile_ctx->fp)) { - size_t line_len = fgetl (potfile_ctx->fp, line_buf); + size_t line_len = fgetl (&potfile_ctx->fp, line_buf); if (line_len == 0) continue; diff --git a/src/restore.c b/src/restore.c index 8f61cc6ae..3800a361b 100644 --- a/src/restore.c +++ b/src/restore.c @@ -54,9 +54,9 @@ static int read_restore (hashcat_ctx_t *hashcat_ctx) char *eff_restore_file = restore_ctx->eff_restore_file; - FILE *fp = fopen (eff_restore_file, "rb"); + HCFILE fp; - if (fp == NULL) + if (hc_fopen (&fp, eff_restore_file, "rb") == false) { event_log_error (hashcat_ctx, "Restore file '%s': %s", eff_restore_file, strerror (errno)); @@ -65,11 +65,11 @@ static int read_restore (hashcat_ctx_t *hashcat_ctx) restore_data_t *rd = restore_ctx->rd; - if (fread (rd, sizeof (restore_data_t), 1, fp) != 1) + if (hc_fread (rd, sizeof (restore_data_t), 1, &fp) != 1) { event_log_error (hashcat_ctx, "Cannot read %s", eff_restore_file); - fclose (fp); + hc_fclose (&fp); return -1; } @@ -80,7 +80,7 @@ static int read_restore (hashcat_ctx_t *hashcat_ctx) { event_log_error (hashcat_ctx, "Unusually low number of arguments (argc) within restore file %s", eff_restore_file); - fclose (fp); + hc_fclose (&fp); return -1; } @@ -89,7 +89,7 @@ static int read_restore (hashcat_ctx_t *hashcat_ctx) { event_log_error (hashcat_ctx, "Unusually high number of arguments (argc) within restore file %s", eff_restore_file); - fclose (fp); + hc_fclose (&fp); return -1; } @@ -100,11 +100,11 @@ static int read_restore (hashcat_ctx_t *hashcat_ctx) for (u32 i = 0; i < rd->argc; i++) { - if (fgets (buf, HCBUFSIZ_LARGE - 1, fp) == NULL) + if (hc_fgets (buf, HCBUFSIZ_LARGE - 1, &fp) == NULL) { event_log_error (hashcat_ctx, "Cannot read %s", eff_restore_file); - fclose (fp); + hc_fclose (&fp); return -1; } @@ -118,7 +118,7 @@ static int read_restore (hashcat_ctx_t *hashcat_ctx) hcfree (buf); - fclose (fp); + hc_fclose (&fp); if (hc_path_exist (rd->cwd) == false) { @@ -203,38 +203,38 @@ static int write_restore (hashcat_ctx_t *hashcat_ctx) char *new_restore_file = restore_ctx->new_restore_file; - FILE *fp = fopen (new_restore_file, "wb"); + HCFILE fp; - if (fp == NULL) + if (hc_fopen (&fp, new_restore_file, "wb") == false) { event_log_error (hashcat_ctx, "%s: %s", new_restore_file, strerror (errno)); return -1; } - if (setvbuf (fp, NULL, _IONBF, 0)) + if (setvbuf (fp.pfp, NULL, _IONBF, 0)) { event_log_error (hashcat_ctx, "setvbuf file '%s': %s", new_restore_file, strerror (errno)); - fclose (fp); + hc_fclose (&fp); return -1; } - hc_fwrite (rd, sizeof (restore_data_t), 1, fp); + hc_fwrite (rd, sizeof (restore_data_t), 1, &fp); for (u32 i = 0; i < rd->argc; i++) { - fprintf (fp, "%s", rd->argv[i]); + hc_fprintf (&fp, "%s", rd->argv[i]); - fputc ('\n', fp); + hc_fputc ('\n', &fp); } - fflush (fp); + hc_fflush (&fp); - fsync (fileno (fp)); + fsync (hc_fileno (&fp)); - fclose (fp); + hc_fclose (&fp); rd->masks_pos = 0; rd->dicts_pos = 0; diff --git a/src/rp.c b/src/rp.c index fbac6e894..716e451bf 100644 --- a/src/rp.c +++ b/src/rp.c @@ -733,11 +733,11 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 char *rp_file = user_options->rp_files[i]; - FILE *fp = NULL; + HCFILE fp; u32 rule_line = 0; - if ((fp = fopen (rp_file, "rb")) == NULL) + if (hc_fopen (&fp, rp_file, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", rp_file, strerror (errno)); @@ -749,9 +749,9 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 return -1; } - while (!feof (fp)) + while (!hc_feof (&fp)) { - rule_len = (u32) fgetl (fp, rule_buf); + rule_len = (u32) fgetl (&fp, rule_buf); rule_line++; @@ -793,7 +793,7 @@ int kernel_rules_load (hashcat_ctx_t *hashcat_ctx, kernel_rule_t **out_buf, u32 kernel_rules_cnt++; } - fclose (fp); + hc_fclose (&fp); all_kernel_rules_cnt[i] = kernel_rules_cnt; all_kernel_rules_buf[i] = kernel_rules_buf; diff --git a/src/shared.c b/src/shared.c index 9d26f1d46..c6becae26 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 @@ -349,13 +350,13 @@ bool hc_path_has_bom (const char *path) { u8 buf[8] = { 0 }; - FILE *fp = fopen (path, "rb"); + HCFILE fp; - if (fp == NULL) return false; + if (hc_fopen (&fp, path, "rb") == false) return false; - const size_t nread = fread (buf, 1, sizeof (buf), fp); + const size_t nread = hc_fread (buf, 1, sizeof (buf), &fp); - fclose (fp); + hc_fclose (&fp); if (nread < 1) return false; @@ -602,14 +603,370 @@ void hc_string_trim_trailing (char *s) s[new_len] = 0; } -size_t hc_fread (void *ptr, size_t size, size_t nmemb, FILE *stream) +#if defined (__CYGWIN__) +// workaround for zlib with cygwin build +int _wopen(const char *path, int oflag, ...) { - return fread (ptr, size, nmemb, stream); + va_list ap; + va_start (ap, oflag); + int r = open (path, oflag, ap); + va_end (ap); + return r; +} +#endif + +bool hc_fopen (HCFILE *fp, const char *path, char *mode) +{ + if (path == NULL || mode == NULL) return false; + + int oflag = -1; + + int fmode = S_IRUSR|S_IWUSR; + + if (strncmp (mode, "a", 1) == 0 || strncmp (mode, "ab", 2) == 0) + { + oflag = O_WRONLY | O_CREAT | O_APPEND; + + #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) + if (strncmp (mode, "ab", 2) == 0) oflag |= O_BINARY; + #endif + } + else if (strncmp (mode, "r", 1) == 0 || strncmp (mode, "rb", 2) == 0) + { + oflag = O_RDONLY; + fmode = -1; + + #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) + if (strncmp (mode, "rb", 2) == 0) oflag |= O_BINARY; + #endif + } + else if (strncmp (mode, "w", 1) == 0 || strncmp (mode, "wb", 2) == 0) + { + oflag = O_WRONLY | O_CREAT | O_TRUNC; + + #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) + if (strncmp (mode, "wb", 2) == 0) oflag |= O_BINARY; + #endif + } + else + { + // ADD more strncmp to handle more "mode" + return false; + } + + fp->pfp = NULL; + fp->is_gzip = false; + + unsigned char check[3] = { 0 }; + + int fd_tmp = open (path, O_RDONLY); + + if (fd_tmp != -1) + { + lseek (fd_tmp, 0, SEEK_SET); + + if (read (fd_tmp, check, sizeof(check)) > 0) + { + if (check[0] == 0x1f && check[1] == 0x8b && check[2] == 0x08) fp->is_gzip = true; + } + + close (fd_tmp); + } + + if (fmode == -1) + { + fp->fd = open (path, oflag); + } + else + { + fp->fd = open (path, oflag, fmode); + } + + if (fp->fd == -1) return false; + + if (fp->is_gzip) + { + if ((fp->gfp = gzdopen (fp->fd, mode)) == NULL) return false; + } + else + { + if ((fp->pfp = fdopen (fp->fd, mode)) == NULL) return false; + } + + fp->path = path; + fp->mode = mode; + + return true; } -size_t hc_fwrite (const void *ptr, size_t size, size_t nmemb, FILE *stream) +size_t hc_fread (void *ptr, size_t size, size_t nmemb, HCFILE *fp) { - return fwrite (ptr, size, nmemb, stream); + size_t n = -1; + + if (fp == NULL) return n; + + if (fp->is_gzip) + { + n = gzfread (ptr, size, nmemb, fp->gfp); + } + else + { + n = fread (ptr, size, nmemb, fp->pfp); + } + + return n; +} + +size_t hc_fwrite (void *ptr, size_t size, size_t nmemb, HCFILE *fp) +{ + size_t n = -1; + + if (fp == NULL) return n; + + if (fp->is_gzip) + { + n = gzfwrite (ptr, size, nmemb, fp->gfp); + } + else + { + n = fwrite (ptr, size, nmemb, fp->pfp); + } + + if (n != nmemb) return -1; + + return n; +} + +int hc_fseek (HCFILE *fp, off_t offset, int whence) +{ + int r = -1; + + if (fp == NULL) return r; + + if (fp->is_gzip) + { + r = gzseek (fp->gfp, (z_off_t) offset, whence); + } + else + { + r = fseeko (fp->pfp, offset, whence); + } + + return r; +} + +void hc_rewind (HCFILE *fp) +{ + if (fp == NULL) return; + + if (fp->is_gzip) + { + gzrewind (fp->gfp); + } + else + { + rewind (fp->pfp); + } +} + +off_t hc_ftell (HCFILE *fp) +{ + off_t n = 0; + + if (fp == NULL) return -1; + + if (fp->is_gzip) + { + n = (off_t) gztell (fp->gfp); + } + else + { + n = ftello (fp->pfp); + } + + return n; +} + +int hc_fputc (int c, HCFILE *fp) +{ + int r = -1; + + if (fp == NULL) return r; + + if (fp->is_gzip) + { + r = gzputc (fp->gfp, c); + } + else + { + r = fputc (c, fp->pfp); + } + + return r; +} + +int hc_fgetc (HCFILE *fp) +{ + int r = -1; + + if (fp == NULL) return r; + + if (fp->is_gzip) + { + r = gzgetc (fp->gfp); + } + else + { + r = fgetc (fp->pfp); + } + + return r; +} + +char *hc_fgets (char *buf, int len, HCFILE *fp) +{ + char *r = NULL; + + if (fp == NULL) return r; + + if (fp->is_gzip) + { + r = gzgets (fp->gfp, buf, len); + } + else + { + r = fgets (buf, len, fp->pfp); + } + + return r; +} + +int hc_vfprintf (HCFILE *fp, const char *format, va_list ap) +{ + int r = -1; + + if (fp == NULL) return r; + + if (fp->is_gzip) + { + r = gzvprintf (fp->gfp, format, ap); + } + else + { + r = vfprintf (fp->pfp, format, ap); + } + + return r; +} + +int hc_fprintf (HCFILE *fp, const char *format, ...) +{ + int r = -1; + + if (fp == NULL) return r; + + va_list ap; + + va_start (ap, format); + + if (fp->is_gzip) + { + r = gzvprintf (fp->gfp, format, ap); + } + else + { + r = vfprintf (fp->pfp, format, ap); + } + + va_end (ap); + + return r; +} + +int hc_fscanf (HCFILE *fp, const char *format, void *ptr) +{ + if (fp == NULL) return -1; + + char *buf = (char *) hcmalloc (HCBUFSIZ_TINY); + + if (buf == NULL) return -1; + + char *b = hc_fgets (buf, HCBUFSIZ_TINY - 1, fp); + + if (b == NULL) + { + hcfree (buf); + + return -1; + } + + sscanf (b, format, (void *) ptr); + + hcfree (buf); + + return 1; +} + +int hc_fileno (HCFILE *fp) +{ + if (fp == NULL) return 1; + + return fp->fd; +} + +int hc_feof (HCFILE *fp) +{ + int r = -1; + + if (fp == NULL) return r; + + if (fp->is_gzip) + { + r = gzeof (fp->gfp); + } + else + { + r = feof (fp->pfp); + } + + return r; +} + +void hc_fflush (HCFILE *fp) +{ + if (fp == NULL) return; + + if (fp->is_gzip) + { + gzflush (fp->gfp, Z_SYNC_FLUSH); + } + else + { + fflush (fp->pfp); + } +} + +void hc_fclose (HCFILE *fp) +{ + if (fp == NULL) return; + + if (fp->is_gzip) + { + gzclose (fp->gfp); + } + else + { + fclose (fp->pfp); + } + + close (fp->fd); + + fp->fd = -1; + fp->pfp = NULL; + fp->is_gzip = false; + + fp->path = NULL; + fp->mode = NULL; } bool hc_same_files (char *file1, char *file2) @@ -621,36 +978,32 @@ bool hc_same_files (char *file1, char *file2) int do_check = 0; - FILE *fp; + HCFILE fp; - fp = fopen (file1, "r"); - - if (fp) + if (hc_fopen (&fp, file1, "r") == true) { - if (fstat (fileno (fp), &tmpstat_file1)) + if (fstat (hc_fileno (&fp), &tmpstat_file1)) { - fclose (fp); + hc_fclose (&fp); return false; } - fclose (fp); + hc_fclose (&fp); do_check++; } - fp = fopen (file2, "r"); - - if (fp) + if (hc_fopen (&fp, file2, "r") == true) { - if (fstat (fileno (fp), &tmpstat_file2)) + if (fstat (hc_fileno (&fp), &tmpstat_file2)) { - fclose (fp); + hc_fclose (&fp); return false; } - fclose (fp); + hc_fclose (&fp); do_check++; } diff --git a/src/slow_candidates.c b/src/slow_candidates.c index 03b4586e7..76b8386f7 100644 --- a/src/slow_candidates.c +++ b/src/slow_candidates.c @@ -13,6 +13,7 @@ #include "mpsp.h" #include "filehandling.h" #include "slow_candidates.h" +#include "shared.h" void slow_candidates_seek (hashcat_ctx_t *hashcat_ctx, void *extra_info, const u64 cur, const u64 end) { @@ -36,7 +37,7 @@ void slow_candidates_seek (hashcat_ctx_t *hashcat_ctx, void *extra_info, const u while (1) { - FILE *fp = extra_info_straight->fp; + HCFILE *fp = &extra_info_straight->fp; get_next_word (hashcat_ctx, fp, &line_buf, &line_len); @@ -75,8 +76,8 @@ void slow_candidates_seek (hashcat_ctx_t *hashcat_ctx, void *extra_info, const u { extra_info_combi_t *extra_info_combi = (extra_info_combi_t *) extra_info; - FILE *base_fp = extra_info_combi->base_fp; - FILE *combs_fp = extra_info_combi->combs_fp; + HCFILE *base_fp = &extra_info_combi->base_fp; + HCFILE *combs_fp = &extra_info_combi->combs_fp; for (u64 i = cur; i < end; i++) { @@ -114,7 +115,7 @@ void slow_candidates_seek (hashcat_ctx_t *hashcat_ctx, void *extra_info, const u extra_info_combi->base_len = line_len; - rewind (combs_fp); + hc_rewind (combs_fp); } char *line_buf = extra_info_combi->scratch_buf; @@ -175,7 +176,7 @@ void slow_candidates_next (hashcat_ctx_t *hashcat_ctx, void *extra_info) while (1) { - FILE *fp = extra_info_straight->fp; + HCFILE *fp = &extra_info_straight->fp; get_next_word (hashcat_ctx, fp, &line_buf, &line_len); @@ -237,8 +238,8 @@ void slow_candidates_next (hashcat_ctx_t *hashcat_ctx, void *extra_info) { extra_info_combi_t *extra_info_combi = (extra_info_combi_t *) extra_info; - FILE *base_fp = extra_info_combi->base_fp; - FILE *combs_fp = extra_info_combi->combs_fp; + HCFILE *base_fp = &extra_info_combi->base_fp; + HCFILE *combs_fp = &extra_info_combi->combs_fp; if ((extra_info_combi->pos % combinator_ctx->combs_cnt) == 0) { @@ -273,7 +274,7 @@ void slow_candidates_next (hashcat_ctx_t *hashcat_ctx, void *extra_info) extra_info_combi->base_len = line_len; - rewind (combs_fp); + hc_rewind (combs_fp); } memcpy (extra_info_combi->out_buf, extra_info_combi->base_buf, extra_info_combi->base_len); diff --git a/src/stdout.c b/src/stdout.c index d3fbcb0c7..f7a4585f1 100644 --- a/src/stdout.c +++ b/src/stdout.c @@ -18,7 +18,7 @@ static void out_flush (out_t *out) { if (out->len == 0) return; - hc_fwrite (out->buf, 1, out->len, out->fp); + hc_fwrite (out->buf, 1, out->len, &out->fp); out->len = 0; } @@ -59,33 +59,33 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx; user_options_t *user_options = hashcat_ctx->user_options; - out_t out; - - out.fp = stdout; - char *filename = outfile_ctx->filename; + out_t out; + if (filename) { - FILE *fp = fopen (filename, "ab"); - - if (fp == NULL) + if (hc_fopen (&out.fp, filename, "ab") == false) { event_log_error (hashcat_ctx, "%s: %s", filename, strerror (errno)); return -1; } - if (lock_file (fp) == -1) + if (hc_lockfile (&out.fp) == -1) { - fclose (fp); + hc_fclose (&out.fp); event_log_error (hashcat_ctx, "%s: %s", filename, strerror (errno)); return -1; } - - out.fp = fp; + } + else + { + out.fp.is_gzip = false; + out.fp.pfp = stdout; + out.fp.fd = fileno (stdout); } out.len = 0; @@ -108,7 +108,7 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, if (rc == -1) { - if (filename) fclose (out.fp); + if (filename) hc_fclose (&out.fp); return -1; } @@ -152,7 +152,7 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, if (rc == -1) { - if (filename) fclose (out.fp); + if (filename) hc_fclose (&out.fp); return -1; } @@ -222,7 +222,7 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, if (rc == -1) { - if (filename) fclose (out.fp); + if (filename) hc_fclose (&out.fp); return -1; } @@ -259,7 +259,7 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, if (rc == -1) { - if (filename) fclose (out.fp); + if (filename) hc_fclose (&out.fp); return -1; } @@ -291,7 +291,7 @@ int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, out_flush (&out); - if (filename) fclose (out.fp); + if (filename) hc_fclose (&out.fp); return 0; } diff --git a/src/straight.c b/src/straight.c index 0581838ec..21d1e0ee7 100644 --- a/src/straight.c +++ b/src/straight.c @@ -70,18 +70,18 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) logfile_sub_var_string ("rulefile", user_options->rp_files[i]); } - FILE *fd = fopen (straight_ctx->dict, "rb"); + HCFILE fp; - if (fd == NULL) + if (hc_fopen (&fp, straight_ctx->dict, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", straight_ctx->dict, strerror (errno)); return -1; } - const int rc = count_words (hashcat_ctx, fd, straight_ctx->dict, &status_ctx->words_cnt); + const int rc = count_words (hashcat_ctx, &fp, straight_ctx->dict, &status_ctx->words_cnt); - fclose (fd); + hc_fclose (&fp); if (rc == -1) { @@ -105,18 +105,18 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_LEFT) { - FILE *fd = fopen (combinator_ctx->dict1, "rb"); + HCFILE fp; - if (fd == NULL) + if (hc_fopen (&fp, combinator_ctx->dict1, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", combinator_ctx->dict1, strerror (errno)); return -1; } - const int rc = count_words (hashcat_ctx, fd, combinator_ctx->dict1, &status_ctx->words_cnt); + const int rc = count_words (hashcat_ctx, &fp, combinator_ctx->dict1, &status_ctx->words_cnt); - fclose (fd); + hc_fclose (&fp); if (rc == -1) { @@ -127,18 +127,18 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) } else if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_RIGHT) { - FILE *fd = fopen (combinator_ctx->dict2, "rb"); + HCFILE fp; - if (fd == NULL) + if (hc_fopen (&fp, combinator_ctx->dict2, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", combinator_ctx->dict2, strerror (errno)); return -1; } - const int rc = count_words (hashcat_ctx, fd, combinator_ctx->dict2, &status_ctx->words_cnt); + const int rc = count_words (hashcat_ctx, &fp, combinator_ctx->dict2, &status_ctx->words_cnt); - fclose (fd); + hc_fclose (&fp); if (rc == -1) { @@ -173,18 +173,18 @@ int straight_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) logfile_sub_string (straight_ctx->dict); logfile_sub_string (mask_ctx->mask); - FILE *fd = fopen (straight_ctx->dict, "rb"); + HCFILE fp; - if (fd == NULL) + if (hc_fopen (&fp, straight_ctx->dict, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", straight_ctx->dict, strerror (errno)); return -1; } - const int rc = count_words (hashcat_ctx, fd, straight_ctx->dict, &status_ctx->words_cnt); + const int rc = count_words (hashcat_ctx, &fp, straight_ctx->dict, &status_ctx->words_cnt); - fclose (fd); + hc_fclose (&fp); if (rc == -1) { diff --git a/src/terminal.c b/src/terminal.c index 1400ae724..5435f61ec 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -977,7 +977,7 @@ void status_display_machine_readable (hashcat_ctx_t *hashcat_ctx) printf ("%d\t", util); } - hc_fwrite (EOL, strlen (EOL), 1, stdout); + fwrite (EOL, strlen (EOL), 1, stdout); fflush (stdout); @@ -1064,7 +1064,7 @@ void status_display_status_json (hashcat_ctx_t *hashcat_ctx) printf (" \"time_start\": %" PRIu64 ",", (u64) status_ctx->runtime_start); printf (" \"estimated_stop\": %" PRIu64 " }", (u64) end); - hc_fwrite (EOL, strlen (EOL), 1, stdout); + fwrite (EOL, strlen (EOL), 1, stdout); fflush (stdout); diff --git a/src/tuningdb.c b/src/tuningdb.c index db88cf57a..248f8d30a 100644 --- a/src/tuningdb.c +++ b/src/tuningdb.c @@ -68,9 +68,9 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) hc_asprintf (&tuning_db_file, "%s/%s", folder_config->shared_dir, TUNING_DB_FILE); - FILE *fp = fopen (tuning_db_file, "rb"); + HCFILE fp; - if (fp == NULL) + if (hc_fopen (&fp, tuning_db_file, "rb") == false) { event_log_error (hashcat_ctx, "%s: %s", tuning_db_file, strerror (errno)); @@ -79,7 +79,7 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) hcfree (tuning_db_file); - const size_t num_lines = count_lines (fp); + const size_t num_lines = count_lines (&fp); // a bit over-allocated @@ -89,15 +89,15 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) tuning_db->entry_buf = (tuning_db_entry_t *) hccalloc (num_lines + 1, sizeof (tuning_db_entry_t)); tuning_db->entry_cnt = 0; - rewind (fp); + hc_rewind (&fp); int line_num = 0; char *buf = (char *) hcmalloc (HCBUFSIZ_LARGE); - while (!feof (fp)) + while (!hc_feof (&fp)) { - char *line_buf = fgets (buf, HCBUFSIZ_LARGE - 1, fp); + char *line_buf = hc_fgets (buf, HCBUFSIZ_LARGE - 1, &fp); if (line_buf == NULL) break; @@ -270,7 +270,7 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx) hcfree (buf); - fclose (fp); + hc_fclose (&fp); // todo: print loaded 'cnt' message diff --git a/src/usage.c b/src/usage.c index ce7769700..57b14bab1 100644 --- a/src/usage.c +++ b/src/usage.c @@ -269,7 +269,7 @@ void usage_mini_print (const char *progname) { printf (USAGE_MINI[i], progname); - hc_fwrite (EOL, strlen (EOL), 1, stdout); + fwrite (EOL, strlen (EOL), 1, stdout); } } @@ -315,7 +315,7 @@ void usage_big_print (hashcat_ctx_t *hashcat_ctx) { printf ("%s", USAGE_BIG_PRE_HASHMODES[i]); - hc_fwrite (EOL, strlen (EOL), 1, stdout); + fwrite (EOL, strlen (EOL), 1, stdout); } //hc_fwrite (EOL, strlen (EOL), 1, stdout); @@ -324,10 +324,10 @@ void usage_big_print (hashcat_ctx_t *hashcat_ctx) { printf ("%7u | %-48s | %s", usage_sort_buf[i].hash_mode, usage_sort_buf[i].hash_name, strhashcategory (usage_sort_buf[i].hash_category)); - hc_fwrite (EOL, strlen (EOL), 1, stdout); + fwrite (EOL, strlen (EOL), 1, stdout); } - hc_fwrite (EOL, strlen (EOL), 1, stdout); + fwrite (EOL, strlen (EOL), 1, stdout); for (int i = 0; i < usage_sort_cnt; i++) { @@ -340,8 +340,8 @@ void usage_big_print (hashcat_ctx_t *hashcat_ctx) { printf ("%s", USAGE_BIG_POST_HASHMODES[i]); - hc_fwrite (EOL, strlen (EOL), 1, stdout); + fwrite (EOL, strlen (EOL), 1, stdout); } - hc_fwrite (EOL, strlen (EOL), 1, stdout); + fwrite (EOL, strlen (EOL), 1, stdout); } diff --git a/src/wordlist.c b/src/wordlist.c index 34b595729..57bd36346 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -47,7 +47,7 @@ size_t convert_from_hex (hashcat_ctx_t *hashcat_ctx, char *line_buf, const size_ return (line_len); } -int load_segment (hashcat_ctx_t *hashcat_ctx, FILE *fd) +int load_segment (hashcat_ctx_t *hashcat_ctx, HCFILE *fp) { wl_data_t *wl_data = hashcat_ctx->wl_data; @@ -55,7 +55,7 @@ int load_segment (hashcat_ctx_t *hashcat_ctx, FILE *fd) wl_data->pos = 0; - wl_data->cnt = hc_fread (wl_data->buf, 1, wl_data->incr - 1000, fd); + wl_data->cnt = hc_fread (wl_data->buf, 1, wl_data->incr - 1000, fp); wl_data->buf[wl_data->cnt] = 0; @@ -63,7 +63,7 @@ int load_segment (hashcat_ctx_t *hashcat_ctx, FILE *fd) if (wl_data->buf[wl_data->cnt - 1] == '\n') return 0; - while (!feof (fd)) + while (!hc_feof (fp)) { if (wl_data->cnt == wl_data->avail) { @@ -72,7 +72,7 @@ int load_segment (hashcat_ctx_t *hashcat_ctx, FILE *fd) wl_data->avail += wl_data->incr; } - const int c = fgetc (fd); + const int c = hc_fgetc (fp); if (c == EOF) break; @@ -170,7 +170,7 @@ void get_next_word_std (char *buf, u64 sz, u64 *len, u64 *off) *len = sz; } -void get_next_word (hashcat_ctx_t *hashcat_ctx, FILE *fd, char **out_buf, u32 *out_len) +void get_next_word (hashcat_ctx_t *hashcat_ctx, HCFILE *fp, char **out_buf, u32 *out_len) { user_options_t *user_options = hashcat_ctx->user_options; user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; @@ -225,16 +225,16 @@ void get_next_word (hashcat_ctx_t *hashcat_ctx, FILE *fd, char **out_buf, u32 *o return; } - if (feof (fd)) + if (hc_feof (fp)) { fprintf (stderr, "BUG feof()!!\n"); return; } - load_segment (hashcat_ctx, fd); + load_segment (hashcat_ctx, fp); - get_next_word (hashcat_ctx, fd, out_buf, out_len); + get_next_word (hashcat_ctx, fp, out_buf, out_len); } void pw_pre_add (hc_device_param_t *device_param, const u8 *pw_buf, const int pw_len, const u8 *base_buf, const int base_len, const int rule_idx) @@ -317,7 +317,7 @@ void pw_add (hc_device_param_t *device_param, const u8 *pw_buf, const int pw_len } } -int count_words (hashcat_ctx_t *hashcat_ctx, FILE *fd, const char *dictfile, u64 *result) +int count_words (hashcat_ctx_t *hashcat_ctx, HCFILE *fp, const char *dictfile, u64 *result) { combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx; hashconfig_t *hashconfig = hashcat_ctx->hashconfig; @@ -333,7 +333,7 @@ int count_words (hashcat_ctx_t *hashcat_ctx, FILE *fd, const char *dictfile, u64 d.cnt = 0; - if (fstat (fileno (fd), &d.stat)) + if (fstat (hc_fileno (fp), &d.stat)) { *result = 0; @@ -425,9 +425,9 @@ int count_words (hashcat_ctx_t *hashcat_ctx, FILE *fd, const char *dictfile, u64 u64 cnt = 0; u64 cnt2 = 0; - while (!feof (fd)) + while (!hc_feof (fp)) { - load_segment (hashcat_ctx, fd); + load_segment (hashcat_ctx, fp); comp += wl_data->cnt;