From c78b8878d5e1c1304218cce53efcf3a52a1cb772 Mon Sep 17 00:00:00 2001 From: Jens Steube Date: Wed, 9 Oct 2019 19:18:18 +0200 Subject: [PATCH] Fix calculation of mask length for status view in case hex-charset is used --- include/mpsp.h | 2 +- src/mpsp.c | 27 ++++++++++++++++++++++----- src/status.c | 5 +++-- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/include/mpsp.h b/include/mpsp.h index b986d0dc7..da0e6dfc7 100644 --- a/include/mpsp.h +++ b/include/mpsp.h @@ -22,7 +22,7 @@ #define INCR_MASKS 1000 -u32 mp_get_length (const char *mask); +u32 mp_get_length (const char *mask, const u32 opts_type); void sp_exec (u64 ctx, char *pw_buf, cs_t *root_css_buf, cs_t *markov_css_buf, u32 start, u32 stop); diff --git a/src/mpsp.c b/src/mpsp.c index 89510dd9a..f3a7fc344 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -1061,7 +1061,7 @@ static int mask_append (hashcat_ctx_t *hashcat_ctx, const char *mask, const char if (user_options->increment == true) { - const u32 mask_length = mp_get_length (mask); + const u32 mask_length = mp_get_length (mask, hashconfig->opts_type); u32 increment_min = user_options->increment_min; u32 increment_max = user_options->increment_max; @@ -1129,17 +1129,34 @@ static int mask_append (hashcat_ctx_t *hashcat_ctx, const char *mask, const char return 0; } -u32 mp_get_length (const char *mask) +u32 mp_get_length (const char *mask, const u32 opts_type) { + bool ignore_next = false; + u32 len = 0; const size_t mask_len = strlen (mask); for (size_t i = 0; i < mask_len; i++) { - if (mask[i] == '?') i++; + if (ignore_next == true) + { + ignore_next = false; + } + else + { + if (mask[i] == '?') + { + ignore_next = true; + } - len++; + if (opts_type & OPTS_TYPE_PT_HEX) + { + ignore_next = true; + } + + len++; + } } return len; @@ -1260,7 +1277,7 @@ int mask_ctx_update_loop (hashcat_ctx_t *hashcat_ctx) if (user_options->benchmark == true) { - pw_min = mp_get_length (mask_ctx->mask); + pw_min = mp_get_length (mask_ctx->mask, hashconfig->opts_type); pw_max = pw_min; } diff --git a/src/status.c b/src/status.c index 718336f43..26407519e 100644 --- a/src/status.c +++ b/src/status.c @@ -778,13 +778,14 @@ char *status_get_guess_charset (const hashcat_ctx_t *hashcat_ctx) int status_get_guess_mask_length (const hashcat_ctx_t *hashcat_ctx) { - const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; + const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx; if (mask_ctx == NULL) return -1; if (mask_ctx->mask == NULL) return -1; - return mp_get_length (mask_ctx->mask); + return mp_get_length (mask_ctx->mask, hashconfig->opts_type); } char *status_get_guess_candidates_dev (const hashcat_ctx_t *hashcat_ctx, const int backend_devices_idx)