mirror of
https://github.com/hashcat/hashcat.git
synced 2025-07-04 05:42:35 +00:00
Parse maskfiles and escaped ?s properly
Replace the old reversal function with an improved one, that both respects custom charsets in mask files and escaped question marks
This commit is contained in:
parent
7c24f36db0
commit
cbc3470642
50
src/mpsp.c
50
src/mpsp.c
@ -1073,19 +1073,36 @@ static int mask_append_final (hashcat_ctx_t *hashcat_ctx, const char *mask)
|
||||
}
|
||||
|
||||
// ?l?u?d -> ?d?u?l
|
||||
static char* reverseMask (const char *mask) {
|
||||
int length = strlen (mask);
|
||||
static char* reverseMask (const char *mask, const char *prepend)
|
||||
{
|
||||
u32 maskLength = strlen (mask);
|
||||
u32 prependLength = strlen (prepend);
|
||||
|
||||
char *tmp_buf = (char *) hcmalloc (256);
|
||||
|
||||
for (int i = length - 1, j = 0; i >= 0; i--) {
|
||||
if (mask[i] == '\0')
|
||||
continue;
|
||||
if (i != 0 && mask[i - 1] == '?') {
|
||||
tmp_buf[j++] = '?';
|
||||
tmp_buf[j++] = mask[i];
|
||||
i--;
|
||||
} else {
|
||||
tmp_buf[j++] = mask[i];
|
||||
u32 i = 0;
|
||||
|
||||
// Add prepend section to tmp_buf, avoiding reversal
|
||||
if (prependLength != 0)
|
||||
{
|
||||
for (i = 0; i < prependLength ; i++)
|
||||
{
|
||||
tmp_buf[i] = prepend[i];
|
||||
}
|
||||
tmp_buf[i++] = ',';
|
||||
}
|
||||
|
||||
for (u32 j = maskLength - 1; i <= maskLength - 1 ; i++)
|
||||
{
|
||||
if (mask[i] == '?' && mask[i + 1] != '\0')
|
||||
{
|
||||
tmp_buf[j--] = mask[i + 1];
|
||||
tmp_buf[j--] = mask[i];
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp_buf[j--] = mask[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -1130,14 +1147,21 @@ static int mask_append (hashcat_ctx_t *hashcat_ctx, const char *mask, const char
|
||||
|
||||
if (user_options->increment_inverse == true)
|
||||
{
|
||||
if (mp_get_truncated_mask (hashcat_ctx, reverseMask (mask), strlen (mask), increment_len, mask_truncated_next) == -1)
|
||||
if (mp_get_truncated_mask (hashcat_ctx, reverseMask (mask, ""), strlen (mask), increment_len, mask_truncated_next) == -1)
|
||||
{
|
||||
hcfree (mask_truncated);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
mask_truncated = reverseMask (mask_truncated);
|
||||
if (prepend)
|
||||
{
|
||||
mask_truncated = reverseMask (mask_truncated, prepend);
|
||||
}
|
||||
else
|
||||
{
|
||||
mask_truncated = reverseMask (mask_truncated, "");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user