mirror of
https://github.com/hashcat/hashcat.git
synced 2024-11-22 08:08:10 +00:00
use XDG_CACHE_HOME for kernels
This commit is contained in:
parent
036247186b
commit
470e844e5d
3
BUILD.md
3
BUILD.md
@ -31,8 +31,7 @@ The install target is linux FHS compatible and can be used like this:
|
||||
$ make install
|
||||
```
|
||||
|
||||
If you install it, cached kernels, session files, restore- and pot-files etc. will go to either $HOME/.hashcat/, if that already exists, otherwise to $XDG_DATA_HOME/hashcat/ or ~/.local/share/hashcat/, if that environment variable is not set.
|
||||
|
||||
If you install it, cached kernels will go to either $HOME/.hashcat/, if that already exists, otherwise to $XDG_CACHE_HOME/hashcat/ or ~/.cache/hashcat/, if that environment variable is not set. Session files, restore- and pot-files etc. will go to either $HOME/.hashcat/, if that already exists, otherwise to $XDG_DATA_HOME/hashcat/ or ~/.local/share/hashcat/, if that environment variable is not set.
|
||||
|
||||
### Building hashcat for Windows (using Windows Subsystem for Linux) ###
|
||||
|
||||
|
@ -140,13 +140,13 @@ int run_copy (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *de
|
||||
int run_cracker (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u64 pws_pos, const u64 pws_cnt);
|
||||
|
||||
void generate_source_kernel_filename (const bool slow_candidates, const u32 attack_exec, const u32 attack_kern, const u32 kern_type, const u32 opti_type, char *shared_dir, char *source_file);
|
||||
void generate_cached_kernel_filename (const bool slow_candidates, const u32 attack_exec, const u32 attack_kern, const u32 kern_type, const u32 opti_type, char *profile_dir, const char *device_name_chksum, char *cached_file);
|
||||
void generate_cached_kernel_filename (const bool slow_candidates, const u32 attack_exec, const u32 attack_kern, const u32 kern_type, const u32 opti_type, char *cache_dir, const char *device_name_chksum, char *cached_file);
|
||||
void generate_source_kernel_shared_filename (char *shared_dir, char *source_file);
|
||||
void generate_cached_kernel_shared_filename (char *profile_dir, const char *device_name_chksum, char *cached_file);
|
||||
void generate_cached_kernel_shared_filename (char *cache_dir, const char *device_name_chksum, char *cached_file);
|
||||
void generate_source_kernel_mp_filename (const u32 opti_type, const u64 opts_type, char *shared_dir, char *source_file);
|
||||
void generate_cached_kernel_mp_filename (const u32 opti_type, const u64 opts_type, char *profile_dir, const char *device_name_chksum, char *cached_file);
|
||||
void generate_cached_kernel_mp_filename (const u32 opti_type, const u64 opts_type, char *cache_dir, const char *device_name_chksum, char *cached_file);
|
||||
void generate_source_kernel_amp_filename (const u32 attack_kern, char *shared_dir, char *source_file);
|
||||
void generate_cached_kernel_amp_filename (const u32 attack_kern, char *profile_dir, const char *device_name_chksum, char *cached_file);
|
||||
void generate_cached_kernel_amp_filename (const u32 attack_kern, char *cache_dir, const char *device_name_chksum, char *cached_file);
|
||||
|
||||
int backend_ctx_init (hashcat_ctx_t *hashcat_ctx);
|
||||
void backend_ctx_destroy (hashcat_ctx_t *hashcat_ctx);
|
||||
|
@ -2130,6 +2130,7 @@ typedef struct folder_config
|
||||
char *cwd;
|
||||
char *install_dir;
|
||||
char *profile_dir;
|
||||
char *cache_dir;
|
||||
char *session_dir;
|
||||
char *shared_dir;
|
||||
char *cpath_real;
|
||||
|
@ -616,7 +616,7 @@ void generate_source_kernel_filename (const bool slow_candidates, const u32 atta
|
||||
}
|
||||
}
|
||||
|
||||
void generate_cached_kernel_filename (const bool slow_candidates, const u32 attack_exec, const u32 attack_kern, const u32 kern_type, const u32 opti_type, char *profile_dir, const char *device_name_chksum, char *cached_file)
|
||||
void generate_cached_kernel_filename (const bool slow_candidates, const u32 attack_exec, const u32 attack_kern, const u32 kern_type, const u32 opti_type, char *cache_dir, const char *device_name_chksum, char *cached_file)
|
||||
{
|
||||
if (opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
|
||||
{
|
||||
@ -624,23 +624,23 @@ void generate_cached_kernel_filename (const bool slow_candidates, const u32 atta
|
||||
{
|
||||
if (slow_candidates == true)
|
||||
{
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-optimized.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (attack_kern == ATTACK_KERN_STRAIGHT)
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-optimized.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
|
||||
else if (attack_kern == ATTACK_KERN_COMBI)
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a1-optimized.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a1-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
|
||||
else if (attack_kern == ATTACK_KERN_BF)
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a3-optimized.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a3-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
|
||||
else if (attack_kern == ATTACK_KERN_NONE)
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-optimized.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d-optimized.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d-optimized.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -649,23 +649,23 @@ void generate_cached_kernel_filename (const bool slow_candidates, const u32 atta
|
||||
{
|
||||
if (slow_candidates == true)
|
||||
{
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-pure.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (attack_kern == ATTACK_KERN_STRAIGHT)
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-pure.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
|
||||
else if (attack_kern == ATTACK_KERN_COMBI)
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a1-pure.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a1-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
|
||||
else if (attack_kern == ATTACK_KERN_BF)
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a3-pure.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a3-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
|
||||
else if (attack_kern == ATTACK_KERN_NONE)
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-pure.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d_a0-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d-pure.%s.kernel", profile_dir, (int) kern_type, device_name_chksum);
|
||||
snprintf (cached_file, 255, "%s/kernels/m%05d-pure.%s.kernel", cache_dir, (int) kern_type, device_name_chksum);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -675,9 +675,9 @@ void generate_source_kernel_shared_filename (char *shared_dir, char *source_file
|
||||
snprintf (source_file, 255, "%s/OpenCL/shared.cl", shared_dir);
|
||||
}
|
||||
|
||||
void generate_cached_kernel_shared_filename (char *profile_dir, const char *device_name_chksum_amp_mp, char *cached_file)
|
||||
void generate_cached_kernel_shared_filename (char *cache_dir, const char *device_name_chksum_amp_mp, char *cached_file)
|
||||
{
|
||||
snprintf (cached_file, 255, "%s/kernels/shared.%s.kernel", profile_dir, device_name_chksum_amp_mp);
|
||||
snprintf (cached_file, 255, "%s/kernels/shared.%s.kernel", cache_dir, device_name_chksum_amp_mp);
|
||||
}
|
||||
|
||||
void generate_source_kernel_mp_filename (const u32 opti_type, const u64 opts_type, char *shared_dir, char *source_file)
|
||||
@ -692,15 +692,15 @@ void generate_source_kernel_mp_filename (const u32 opti_type, const u64 opts_typ
|
||||
}
|
||||
}
|
||||
|
||||
void generate_cached_kernel_mp_filename (const u32 opti_type, const u64 opts_type, char *profile_dir, const char *device_name_chksum_amp_mp, char *cached_file)
|
||||
void generate_cached_kernel_mp_filename (const u32 opti_type, const u64 opts_type, char *cache_dir, const char *device_name_chksum_amp_mp, char *cached_file)
|
||||
{
|
||||
if ((opti_type & OPTI_TYPE_BRUTE_FORCE) && (opts_type & OPTS_TYPE_PT_GENERATE_BE))
|
||||
{
|
||||
snprintf (cached_file, 255, "%s/kernels/markov_be.%s.kernel", profile_dir, device_name_chksum_amp_mp);
|
||||
snprintf (cached_file, 255, "%s/kernels/markov_be.%s.kernel", cache_dir, device_name_chksum_amp_mp);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf (cached_file, 255, "%s/kernels/markov_le.%s.kernel", profile_dir, device_name_chksum_amp_mp);
|
||||
snprintf (cached_file, 255, "%s/kernels/markov_le.%s.kernel", cache_dir, device_name_chksum_amp_mp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -709,9 +709,9 @@ void generate_source_kernel_amp_filename (const u32 attack_kern, char *shared_di
|
||||
snprintf (source_file, 255, "%s/OpenCL/amp_a%u.cl", shared_dir, attack_kern);
|
||||
}
|
||||
|
||||
void generate_cached_kernel_amp_filename (const u32 attack_kern, char *profile_dir, const char *device_name_chksum_amp_mp, char *cached_file)
|
||||
void generate_cached_kernel_amp_filename (const u32 attack_kern, char *cache_dir, const char *device_name_chksum_amp_mp, char *cached_file)
|
||||
{
|
||||
snprintf (cached_file, 255, "%s/kernels/amp_a%u.%s.kernel", profile_dir, attack_kern, device_name_chksum_amp_mp);
|
||||
snprintf (cached_file, 255, "%s/kernels/amp_a%u.%s.kernel", cache_dir, attack_kern, device_name_chksum_amp_mp);
|
||||
}
|
||||
|
||||
// NVRTC
|
||||
@ -8724,7 +8724,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx)
|
||||
|
||||
char cached_file[256] = { 0 };
|
||||
|
||||
generate_cached_kernel_shared_filename (folder_config->profile_dir, device_name_chksum_amp_mp, cached_file);
|
||||
generate_cached_kernel_shared_filename (folder_config->cache_dir, device_name_chksum_amp_mp, cached_file);
|
||||
|
||||
const bool rc_load_kernel = load_kernel (hashcat_ctx, device_param, "shared_kernel", source_file, cached_file, build_options_buf, cache_disable, &device_param->opencl_program_shared, &device_param->cuda_module_shared);
|
||||
|
||||
@ -8904,7 +8904,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx)
|
||||
|
||||
char cached_file[256] = { 0 };
|
||||
|
||||
generate_cached_kernel_filename (user_options->slow_candidates, hashconfig->attack_exec, user_options_extra->attack_kern, kern_type, hashconfig->opti_type, folder_config->profile_dir, device_name_chksum, cached_file);
|
||||
generate_cached_kernel_filename (user_options->slow_candidates, hashconfig->attack_exec, user_options_extra->attack_kern, kern_type, hashconfig->opti_type, folder_config->cache_dir, device_name_chksum, cached_file);
|
||||
|
||||
/**
|
||||
* load kernel
|
||||
@ -8954,7 +8954,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx)
|
||||
|
||||
char cached_file[256] = { 0 };
|
||||
|
||||
generate_cached_kernel_mp_filename (hashconfig->opti_type, hashconfig->opts_type, folder_config->profile_dir, device_name_chksum_amp_mp, cached_file);
|
||||
generate_cached_kernel_mp_filename (hashconfig->opti_type, hashconfig->opts_type, folder_config->cache_dir, device_name_chksum_amp_mp, cached_file);
|
||||
|
||||
const bool rc_load_kernel = load_kernel (hashcat_ctx, device_param, "mp_kernel", source_file, cached_file, build_options_buf, cache_disable, &device_param->opencl_program_mp, &device_param->cuda_module_mp);
|
||||
|
||||
@ -9003,7 +9003,7 @@ int backend_session_begin (hashcat_ctx_t *hashcat_ctx)
|
||||
|
||||
char cached_file[256] = { 0 };
|
||||
|
||||
generate_cached_kernel_amp_filename (user_options_extra->attack_kern, folder_config->profile_dir, device_name_chksum_amp_mp, cached_file);
|
||||
generate_cached_kernel_amp_filename (user_options_extra->attack_kern, folder_config->cache_dir, device_name_chksum_amp_mp, cached_file);
|
||||
|
||||
const bool rc_load_kernel = load_kernel (hashcat_ctx, device_param, "amp_kernel", source_file, cached_file, build_options_buf, cache_disable, &device_param->opencl_program_amp, &device_param->cuda_module_amp);
|
||||
|
||||
|
43
src/folder.c
43
src/folder.c
@ -115,6 +115,31 @@ static void get_profile_dir (char *profile_dir, const char *home_dir)
|
||||
hcfree (data_dir);
|
||||
}
|
||||
|
||||
static void get_cache_dir (char *cache_dir, const char *home_dir)
|
||||
{
|
||||
snprintf (cache_dir, HCBUFSIZ_TINY, "%s/%s", home_dir, DOT_HASHCAT);
|
||||
struct stat st = {0};
|
||||
if (stat (cache_dir, &st) == 0 && S_ISDIR (st.st_mode))
|
||||
return;
|
||||
|
||||
char *xdg_cache_dir = (char *) hcmalloc (HCBUFSIZ_TINY);
|
||||
if (getenv ("XDG_CACHE_HOME"))
|
||||
{
|
||||
strncpy (xdg_cache_dir, getenv ("XDG_CACHE_HOME"), HCBUFSIZ_TINY);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf (xdg_cache_dir, HCBUFSIZ_TINY, "%s/.cache", home_dir);
|
||||
}
|
||||
|
||||
if (access (xdg_cache_dir, R_OK) != -1)
|
||||
{
|
||||
snprintf (cache_dir, HCBUFSIZ_TINY, "%s/hashcat", xdg_cache_dir);
|
||||
}
|
||||
|
||||
hcfree (xdg_cache_dir);
|
||||
}
|
||||
|
||||
static void get_session_dir (char *session_dir, const char *profile_dir)
|
||||
{
|
||||
snprintf (session_dir, HCBUFSIZ_TINY, "%s/%s", profile_dir, SESSIONS_FOLDER);
|
||||
@ -358,6 +383,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
|
||||
get_install_dir (install_dir, resolved_exec_path);
|
||||
|
||||
char *profile_dir = NULL;
|
||||
char *cache_dir = NULL;
|
||||
char *session_dir = NULL;
|
||||
char *shared_dir = NULL;
|
||||
|
||||
@ -373,19 +399,23 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
|
||||
const char *home_dir = pwp->pw_dir;
|
||||
|
||||
profile_dir = (char *) hcmalloc (HCBUFSIZ_TINY);
|
||||
cache_dir = (char *) hcmalloc (HCBUFSIZ_TINY);
|
||||
session_dir = (char *) hcmalloc (HCBUFSIZ_TINY);
|
||||
|
||||
get_profile_dir (profile_dir, home_dir);
|
||||
get_cache_dir (cache_dir, home_dir);
|
||||
get_session_dir (session_dir, profile_dir);
|
||||
|
||||
shared_dir = hcstrdup (shared_folder);
|
||||
|
||||
hc_mkdir (profile_dir, 0700);
|
||||
hc_mkdir (cache_dir, 0700);
|
||||
hc_mkdir (session_dir, 0700);
|
||||
}
|
||||
else
|
||||
{
|
||||
profile_dir = install_dir;
|
||||
cache_dir = install_dir;
|
||||
session_dir = install_dir;
|
||||
shared_dir = install_dir;
|
||||
}
|
||||
@ -400,6 +430,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
|
||||
get_install_dir (install_dir, exec_path);
|
||||
|
||||
char *profile_dir = install_dir;
|
||||
char *cache_dir = install_dir;
|
||||
char *session_dir = install_dir;
|
||||
char *shared_dir = install_dir;
|
||||
|
||||
@ -442,6 +473,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
|
||||
// we prevent double-freeing the same memory address (this happens if e.g. profile_dir == session_dir)
|
||||
|
||||
if (profile_dir == shared_dir) profile_dir = NULL;
|
||||
if (cache_dir == shared_dir) cache_dir = NULL;
|
||||
if (session_dir == shared_dir) session_dir = NULL;
|
||||
|
||||
shared_dir = NULL;
|
||||
@ -450,10 +482,18 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
|
||||
hcfree (profile_dir);
|
||||
|
||||
if (session_dir == profile_dir) session_dir = NULL;
|
||||
if (cache_dir == profile_dir) cache_dir = NULL;
|
||||
|
||||
profile_dir = NULL;
|
||||
|
||||
|
||||
hcfree (cache_dir);
|
||||
|
||||
if (session_dir == cache_dir) session_dir = NULL;
|
||||
|
||||
cache_dir = NULL;
|
||||
|
||||
|
||||
hcfree (session_dir);
|
||||
|
||||
session_dir = NULL;
|
||||
@ -501,7 +541,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
|
||||
|
||||
char *kernels_folder;
|
||||
|
||||
hc_asprintf (&kernels_folder, "%s/kernels", profile_dir);
|
||||
hc_asprintf (&kernels_folder, "%s/kernels", cache_dir);
|
||||
|
||||
hc_mkdir (kernels_folder, 0700);
|
||||
|
||||
@ -514,6 +554,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
|
||||
folder_config->cwd = cwd;
|
||||
folder_config->install_dir = install_dir;
|
||||
folder_config->profile_dir = profile_dir;
|
||||
folder_config->cache_dir = cache_dir;
|
||||
folder_config->session_dir = session_dir;
|
||||
folder_config->shared_dir = shared_dir;
|
||||
folder_config->cpath_real = cpath_real;
|
||||
|
Loading…
Reference in New Issue
Block a user