diff --git a/docs/changes.txt b/docs/changes.txt index 6aa303afa..8c7317968 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -69,6 +69,8 @@ - General: Update C standard from c99 to gnu99 - Hash Parser: Improved salt-length checks for generic hash modes +- HCdict File: Renamed file from hashcat.hcdict to hashcat.hcdict2 and add header because versions are incompatible +- HCstat File: Renamed file from hashcat.hcstat to hashcat.hcstat2 and add header because versions are incompatible - HCstat File: Add code to read LZMA compressed hashcat.hcstat2 - HCstat File: Add hcstat2 support to enable masks of length up to 256, also adds a filetype header - OpenCL Kernels: Added code generator for most of the switch_* functions and replaced existing code diff --git a/include/dictstat.h b/include/dictstat.h index fc092c67f..5d059889e 100644 --- a/include/dictstat.h +++ b/include/dictstat.h @@ -15,7 +15,10 @@ #include #include -#define MAX_DICTSTAT 10000 +#define MAX_DICTSTAT 100000 + +#define DICTSTAT_FILENAME "hashcat.dictstat2" +#define DICTSTAT_VERSION (0x6863646963740000 | 0x0002) int sort_by_dictstat (const void *s1, const void *s2); diff --git a/src/dictstat.c b/src/dictstat.c index bc5ab6763..39b321f0b 100644 --- a/src/dictstat.c +++ b/src/dictstat.c @@ -6,6 +6,7 @@ #include "common.h" #include "types.h" #include "memory.h" +#include "bitops.h" #include "event.h" #include "dictstat.h" #include "locking.h" @@ -54,7 +55,7 @@ int dictstat_init (hashcat_ctx_t *hashcat_ctx) dictstat_ctx->base = (dictstat_t *) hccalloc (MAX_DICTSTAT, sizeof (dictstat_t)); dictstat_ctx->cnt = 0; - hc_asprintf (&dictstat_ctx->filename, "%s/hashcat.dictstat", folder_config->profile_dir); + hc_asprintf (&dictstat_ctx->filename, "%s/%s", folder_config->profile_dir, DICTSTAT_FILENAME); return 0; } @@ -86,6 +87,40 @@ void dictstat_read (hashcat_ctx_t *hashcat_ctx) return; } + // parse header + + 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); + + if ((nread1 != 1) || (nread2 != 1)) + { + event_log_error (hashcat_ctx, "%s: Invalid header", dictstat_ctx->filename); + + return; + } + + v = byte_swap_64 (v); + z = byte_swap_64 (z); + + if (v != DICTSTAT_VERSION) + { + event_log_error (hashcat_ctx, "%s: Invalid header", dictstat_ctx->filename); + + return; + } + + if (z != 0) + { + event_log_error (hashcat_ctx, "%s: Invalid header", dictstat_ctx->filename); + + return; + } + + // parse data + while (!feof (fp)) { dictstat_t d; @@ -131,6 +166,19 @@ int dictstat_write (hashcat_ctx_t *hashcat_ctx) return -1; } + // header + + u64 v = DICTSTAT_VERSION; + u64 z = 0; + + v = byte_swap_64 (v); + z = byte_swap_64 (z); + + 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); fclose (fp);