Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,35 @@ char *rules_apply(char *word_in, char *rule, int split)
break;

case 'v': /* assign value to numeric variable */
if (hc_logic)
{
/* HC rule: insert char X every N chars */
unsigned int n, i, out_len = 0;
char value;
char *out;
POSITION(n)
VALUE(value)
if (!n)
break;
GET_OUT
for (i = 0; i < length; i++)
{
if (out_len >= RULE_WORD_SIZE - 1)
break;
out[out_len++] = in[i];
if (((i + 1) % n) == 0) {
if (out_len >= RULE_WORD_SIZE - 1)
break;
out[out_len++] = value;
}
}
out[out_len] = 0;
in = out;
length = out_len;
break;
}
else
{ /*Original JtR rule */
char var;
int a, s; /* may be negative */
VALUE(var)
Expand All @@ -1436,6 +1464,45 @@ char *rules_apply(char *word_in, char *rule, int split)
rules_vars[ARCH_INDEX(var)] = a - s; /* may be negative */
}
break;

Copy link
Copy Markdown
Member

@magnumripper magnumripper Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost good now ;-)

The 'v' seems to work correctly now. But you introduced whitespace violations: Lines, including empty lines, are not allowed to have trailing whitespace.

case 'h': /*convert the entire password to lowercase hex */
{
char outbuf[RULE_WORD_SIZE * 2];
int i;
if (length * 2 >= RULE_WORD_SIZE)
break;
for (i = 0; i < length; i++)
sprintf(&outbuf[i * 2], "%02x", (unsigned char)in[i]);
strcpy(in, outbuf);
length *= 2;
}
break;

case 'H': /*convert the entire password to uppercase hex*/
{
char outbuf[RULE_WORD_SIZE * 2];
int i;
if (length * 2 >= RULE_WORD_SIZE)
break;
for (i = 0; i < length; i++)
sprintf(&outbuf[i * 2], "%02X", (unsigned char)in[i]);
Comment on lines +1485 to +1488
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first line here (and same for 'h') aborts without converting a single letter to hex. I'm not saying it's wrong (we don't have a spec that detailed) and I don't care - I think RULE_WORD_SIZE is pretty large. Just mentioning it.

strcpy(in, outbuf);
length *= 2;
}
break;

case 'B': /* add byte value of X at pos N, bytewise. Format: BNX */
{
unsigned int pos;
unsigned char val;
POSITION(pos)
VALUE(val)
if (pos < length)
{
in[pos] = (unsigned char)(in[pos] + val);
}
Comment on lines +1500 to +1503
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: You don't use brackets for single line branches anywhere else, so maybe drop them here as well.

}
break;

/* Additional "single crack" mode rules */
case '1':
Expand Down