diff --git a/include/slow_candidates.h b/include/slow_candidates.h index feda93b7a..986ac2996 100644 --- a/include/slow_candidates.h +++ b/include/slow_candidates.h @@ -27,8 +27,8 @@ typedef struct extra_info_combi { u64 pos; - HCFILE *base_fp; - HCFILE *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 a9e562d2f..67c9a4df7 100644 --- a/include/types.h +++ b/include/types.h @@ -1163,7 +1163,7 @@ typedef struct hc_device_param char *scratch_buf; - HCFILE *combs_fp; + HCFILE combs_fp; pw_t *combs_buf; void *hooks_buf; @@ -1639,7 +1639,7 @@ typedef struct potfile_ctx { bool enabled; - FILE *fp; + HCFILE fp; char *filename; u8 *out_buf; // allocates [HCBUFSIZ_LARGE]; diff --git a/src/backend.c b/src/backend.c index c1f7c8cc7..3e924b2bc 100644 --- a/src/backend.c +++ b/src/backend.c @@ -4377,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; - HCFILE *combs_fp = device_param->combs_fp; + HCFILE *combs_fp = &device_param->combs_fp; if (user_options->slow_candidates == true) { diff --git a/src/dispatch.c b/src/dispatch.c index 418a3b049..4a729b381 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -747,30 +747,26 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) combs_file = combinator_ctx->dict1; } - HCFILE base_fp; + extra_info_combi_t extra_info_combi; - if (hc_fopen (&base_fp, base_file, "rb") == false) + 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; } - HCFILE combs_fp; - - if (hc_fopen (&combs_fp, combs_file, "rb") == false) + 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 +779,10 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (rc_wl_data_init == -1) { - hc_fclose (&combs_fp); - - hc_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 +990,10 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (CL_rc == -1) { - hc_fclose (&combs_fp); - - hc_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 +1003,10 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (CL_rc == -1) { - hc_fclose (&combs_fp); - - hc_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 +1048,12 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (words_fin == 0) break; } - hc_fclose (&combs_fp); - - hc_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 +1310,12 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) { char *dictfile = straight_ctx->dict; - HCFILE combs_fp; - - if (hc_fopen (&combs_fp, dictfile, "rb") == false) + 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,31 +1372,23 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) { const char *dictfilec = combinator_ctx->dict2; - HCFILE combs_fp; - - if (hc_fopen (&combs_fp, dictfilec, "rb") == false) + 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; - HCFILE combs_fp; - - if (hc_fopen (&combs_fp, dictfilec, "rb") == false) + 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; } } @@ -1435,7 +1411,7 @@ 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) hc_fclose (device_param->combs_fp); + if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (&device_param->combs_fp); hc_fclose (&fp); @@ -1567,7 +1543,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (CL_rc == -1) { - if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (device_param->combs_fp); + if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (&device_param->combs_fp); hc_fclose (&fp); @@ -1582,7 +1558,7 @@ static int calc (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param) if (CL_rc == -1) { - if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (device_param->combs_fp); + if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (&device_param->combs_fp); hc_fclose (&fp); @@ -1638,7 +1614,7 @@ 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) hc_fclose (device_param->combs_fp); + if (attack_mode == ATTACK_MODE_COMBI) hc_fclose (&device_param->combs_fp); hc_fclose (&fp); diff --git a/src/potfile.c b/src/potfile.c index 4eae86d99..351ce3f97 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,18 +286,13 @@ void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, cons tmp_buf[tmp_len] = 0; - HCFILE fp; - fp.is_gzip = false; - fp.pfp = potfile_ctx->fp; - fp.fd = fileno (fp.pfp); + hc_lockfile (&potfile_ctx->fp); - hc_lockfile (&fp); + hc_fprintf (&potfile_ctx->fp, "%s" EOL, tmp_buf); - fprintf (potfile_ctx->fp, "%s" EOL, tmp_buf); + hc_fflush (&potfile_ctx->fp); - fflush (potfile_ctx->fp); - - if (hc_unlockfile (&fp)) + if (hc_unlockfile (&potfile_ctx->fp)) { event_log_error (hashcat_ctx, "%s: Failed to unlock file.", potfile_ctx->filename); } @@ -380,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; @@ -530,15 +519,9 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx) char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); - // workaround for new fgetl - HCFILE fp; - fp.is_gzip = false; - fp.pfp = potfile_ctx->fp; - fp.fd = fileno (fp.pfp); - - while (!feof (potfile_ctx->fp)) + while (!hc_feof (&potfile_ctx->fp)) { - size_t line_len = fgetl (&fp, line_buf); + size_t line_len = fgetl (&potfile_ctx->fp, line_buf); if (line_len == 0) continue; diff --git a/src/slow_candidates.c b/src/slow_candidates.c index ad6956eef..32d129fa0 100644 --- a/src/slow_candidates.c +++ b/src/slow_candidates.c @@ -76,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; - HCFILE *base_fp = extra_info_combi->base_fp; - HCFILE *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++) { @@ -238,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; - HCFILE *base_fp = extra_info_combi->base_fp; - HCFILE *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) {