From 2507f627227654db42bde76e979bf27f3ddb78ef Mon Sep 17 00:00:00 2001 From: jsteube Date: Sat, 5 Nov 2016 14:46:00 +0100 Subject: [PATCH] Add hash-mode option OPTS_TYPE_PT_ALWAYS_ASCII to control need_hexify() from interface.c --- include/convert.h | 2 +- include/types.h | 33 +++++++++++++++++---------------- src/convert.c | 24 ++++++++++++++++++++---- src/interface.c | 3 ++- src/outfile.c | 4 ++-- src/potfile.c | 5 +++-- src/status.c | 7 ++++--- 7 files changed, 49 insertions(+), 29 deletions(-) diff --git a/include/convert.h b/include/convert.h index 626bd6bd7..aac06a66f 100644 --- a/include/convert.h +++ b/include/convert.h @@ -8,7 +8,7 @@ #include -bool need_hexify (const u8 *buf, const int len, bool accept_utf8); +bool need_hexify (const u8 *buf, const int len, bool always_ascii); void exec_hexify (const u8 *buf, const int len, u8 *out); bool is_valid_hex_char (const u8 c); diff --git a/include/types.h b/include/types.h index 4783170f9..fe0d2c331 100644 --- a/include/types.h +++ b/include/types.h @@ -344,22 +344,23 @@ typedef enum opts_type OPTS_TYPE_PT_GENERATE_BE = (1 << 9), OPTS_TYPE_PT_NEVERCRACK = (1 << 10), // if we want all possible results OPTS_TYPE_PT_BITSLICE = (1 << 11), - OPTS_TYPE_ST_UNICODE = (1 << 12), - OPTS_TYPE_ST_UPPER = (1 << 13), - OPTS_TYPE_ST_LOWER = (1 << 14), - OPTS_TYPE_ST_ADD01 = (1 << 15), - OPTS_TYPE_ST_ADD02 = (1 << 16), - OPTS_TYPE_ST_ADD80 = (1 << 17), - OPTS_TYPE_ST_ADDBITS14 = (1 << 18), - OPTS_TYPE_ST_ADDBITS15 = (1 << 19), - OPTS_TYPE_ST_GENERATE_LE = (1 << 20), - OPTS_TYPE_ST_GENERATE_BE = (1 << 21), - OPTS_TYPE_ST_HEX = (1 << 22), - OPTS_TYPE_ST_BASE64 = (1 << 23), - OPTS_TYPE_HASH_COPY = (1 << 24), - OPTS_TYPE_HOOK12 = (1 << 25), - OPTS_TYPE_HOOK23 = (1 << 26), - OPTS_TYPE_BINARY_HASHFILE = (1 << 27), + OPTS_TYPE_PT_ALWAYS_ASCII = (1 << 12), + OPTS_TYPE_ST_UNICODE = (1 << 13), + OPTS_TYPE_ST_UPPER = (1 << 14), + OPTS_TYPE_ST_LOWER = (1 << 15), + OPTS_TYPE_ST_ADD01 = (1 << 16), + OPTS_TYPE_ST_ADD02 = (1 << 17), + OPTS_TYPE_ST_ADD80 = (1 << 18), + OPTS_TYPE_ST_ADDBITS14 = (1 << 19), + OPTS_TYPE_ST_ADDBITS15 = (1 << 20), + OPTS_TYPE_ST_GENERATE_LE = (1 << 21), + OPTS_TYPE_ST_GENERATE_BE = (1 << 22), + OPTS_TYPE_ST_HEX = (1 << 23), + OPTS_TYPE_ST_BASE64 = (1 << 24), + OPTS_TYPE_HASH_COPY = (1 << 25), + OPTS_TYPE_HOOK12 = (1 << 26), + OPTS_TYPE_HOOK23 = (1 << 27), + OPTS_TYPE_BINARY_HASHFILE = (1 << 28), } opts_type_t; diff --git a/src/convert.c b/src/convert.c index 57d079bb8..32369a28d 100644 --- a/src/convert.c +++ b/src/convert.c @@ -75,16 +75,32 @@ static bool printable_ascii (const u8 *buf, const int len) return true; } -bool need_hexify (const u8 *buf, const int len, bool accept_utf8) +bool need_hexify (const u8 *buf, const int len, bool always_ascii) { - if (accept_utf8) + if (always_ascii == true) { - return !printable_utf8 (buf, len); + if (printable_ascii (buf, len) == true) + { + return false; + } + else + { + return true; + } } else { - return !printable_ascii (buf, len); + if (printable_utf8 (buf, len) == true) + { + return false; + } + else + { + return true; + } } + + return false; } void exec_hexify (const u8 *buf, const int len, u8 *out) diff --git a/src/interface.c b/src/interface.c index 11af069ec..56dc6441d 100644 --- a/src/interface.c +++ b/src/interface.c @@ -17430,7 +17430,8 @@ int hashconfig_init (hashcat_ctx_t *hashcat_ctx) hashconfig->attack_exec = ATTACK_EXEC_INSIDE_KERNEL; hashconfig->opts_type = OPTS_TYPE_PT_GENERATE_LE | OPTS_TYPE_PT_UPPER - | OPTS_TYPE_PT_BITSLICE; + | OPTS_TYPE_PT_BITSLICE + | OPTS_TYPE_PT_ALWAYS_ASCII; hashconfig->kern_type = KERN_TYPE_LM; hashconfig->dgst_size = DGST_SIZE_4_4; // originally DGST_SIZE_4_2 hashconfig->parse_func = lm_parse_hash; diff --git a/src/outfile.c b/src/outfile.c index 31a6473be..1b9f7e305 100644 --- a/src/outfile.c +++ b/src/outfile.c @@ -367,9 +367,9 @@ int outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const unsign if (outfile_ctx->outfile_format & OUTFILE_FMT_PLAIN) { - bool accept_utf8 = hashcat_ctx->hashconfig->hash_type != HASH_TYPE_LM; + const bool always_ascii = (hashconfig->hash_type & OPTS_TYPE_PT_ALWAYS_ASCII); - if ((user_options->outfile_autohex == true) && (need_hexify (plain_ptr, plain_len, accept_utf8) == true)) + if ((user_options->outfile_autohex == true) && (need_hexify (plain_ptr, plain_len, always_ascii) == true)) { tmp_buf[tmp_len++] = '$'; tmp_buf[tmp_len++] = 'H'; diff --git a/src/potfile.c b/src/potfile.c index bdd005a4c..9fa5c2e62 100644 --- a/src/potfile.c +++ b/src/potfile.c @@ -267,6 +267,7 @@ void potfile_write_close (hashcat_ctx_t *hashcat_ctx) void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, 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; @@ -291,9 +292,9 @@ void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, u8 * if (1) { - bool accept_utf8 = hashcat_ctx->hashconfig->hash_type != HASH_TYPE_LM; + const bool always_ascii = (hashconfig->hash_type & OPTS_TYPE_PT_ALWAYS_ASCII); - if ((user_options->outfile_autohex == true) && (need_hexify (plain_ptr, plain_len, accept_utf8) == true)) + if ((user_options->outfile_autohex == true) && (need_hexify (plain_ptr, plain_len, always_ascii) == true)) { tmp_buf[tmp_len++] = '$'; tmp_buf[tmp_len++] = 'H'; diff --git a/src/status.c b/src/status.c index c20f49885..6ed694bee 100644 --- a/src/status.c +++ b/src/status.c @@ -538,6 +538,7 @@ int status_get_input_mask_length (const hashcat_ctx_t *hashcat_ctx) char *status_get_input_candidates_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id) { + const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; const opencl_ctx_t *opencl_ctx = hashcat_ctx->opencl_ctx; const status_ctx_t *status_ctx = hashcat_ctx->status_ctx; const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; @@ -582,10 +583,10 @@ char *status_get_input_candidates_dev (const hashcat_ctx_t *hashcat_ctx, const i build_plain ((hashcat_ctx_t *) hashcat_ctx, device_param, &plain1, plain_buf1, &plain_len1); build_plain ((hashcat_ctx_t *) hashcat_ctx, device_param, &plain2, plain_buf2, &plain_len2); - bool accept_utf8 = hashcat_ctx->hashconfig->hash_type != HASH_TYPE_LM; + const bool always_ascii = (hashconfig->hash_type & OPTS_TYPE_PT_ALWAYS_ASCII); - const bool need_hex1 = need_hexify (plain_ptr1, plain_len1, accept_utf8); - const bool need_hex2 = need_hexify (plain_ptr2, plain_len2, accept_utf8); + const bool need_hex1 = need_hexify (plain_ptr1, plain_len1, always_ascii); + const bool need_hex2 = need_hexify (plain_ptr2, plain_len2, always_ascii); if ((need_hex1 == true) || (need_hex2 == true)) {