Skip to content

Commit 196391b

Browse files
authored
Fixed the indentation as requested and added case v
1 parent 99b868b commit 196391b

1 file changed

Lines changed: 101 additions & 58 deletions

File tree

src/rules.c

Lines changed: 101 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,75 +1450,118 @@ char *rules_apply(char *word_in, char *rule, int split)
14501450
}
14511451
break;
14521452

1453-
case 'H': /*convert the entire password to uppercase hex*/
1453+
case 'H': /*convert the entire password to uppercase hex*/
1454+
{
1455+
char outbuf[RULE_WORD_SIZE * 2];
1456+
int i;
1457+
if (length * 2 >= RULE_WORD_SIZE)
1458+
break;
1459+
for (i = 0; i < length; i++)
1460+
sprintf(&outbuf[i * 2], "%02X", (unsigned char)in[i]);
1461+
strcpy(in, outbuf);
1462+
length *= 2;
1463+
}
1464+
break;
1465+
1466+
case 'B': /* add byte value of X at pos N, bytewise. Format: BNX */
1467+
{
1468+
unsigned int pos;
1469+
unsigned char val;
1470+
POSITION(pos)
1471+
VALUE(val)
1472+
if (pos < length)
14541473
{
1455-
char outbuf[RULE_WORD_SIZE * 2];
1456-
int i;
1457-
if (length * 2 >= RULE_WORD_SIZE)
1458-
break;
1459-
for (i = 0; i < length; i++)
1460-
sprintf(&outbuf[i * 2], "%02X", (unsigned char)in[i]);
1461-
strcpy(in, outbuf);
1462-
length *= 2;
1474+
in[pos] = (unsigned char)(in[pos] + val);
14631475
}
1464-
break;
1465-
1466-
case 'B': /* add byte value of X at pos N, bytewise. Format: BNX */
1476+
}
1477+
break;
1478+
1479+
case 'v':
1480+
if (hc_logic)
14671481
{
1468-
unsigned int pos;
1469-
unsigned char val;
1470-
POSITION(pos)
1471-
VALUE(val)
1472-
if (pos < length)
1482+
/* HC rule: insert char X every N chars */
1483+
unsigned int n, i, out_len = 0;
1484+
char value;
1485+
char *out;
1486+
POSITION(n)
1487+
VALUE(value)
1488+
if (!n)
1489+
break;
1490+
GET_OUT
1491+
for (i = 0; i < length; i++)
14731492
{
1474-
in[pos] = (unsigned char)(in[pos] + val);
1493+
if (out_len >= RULE_WORD_SIZE - 1)
1494+
break;
1495+
out[out_len++] = in[i];
1496+
if (((i + 1) % n) == 0) {
1497+
if (out_len >= RULE_WORD_SIZE - 1)
1498+
break;
1499+
out[out_len++] = value;
1500+
}
14751501
}
1502+
out[out_len] = 0;
1503+
in = out;
1504+
length = out_len;
1505+
break;
1506+
}
1507+
else
1508+
{
1509+
/* original JtR rule */
1510+
char var;
1511+
int a, s; /* may be negative */
1512+
VALUE(var)
1513+
if (var < 'a' || var > 'k')
1514+
goto out_ERROR_POSITION;
1515+
rules_vars['l'] = length;
1516+
POSITION(a)
1517+
POSITION(s)
1518+
rules_vars[ARCH_INDEX(var)] = a - s; /* may be negative */
14761519
}
14771520
break;
14781521

1479-
/* Additional "single crack" mode rules */
1480-
case '1':
1481-
if (split < 0)
1482-
goto out_ERROR_UNALLOWED;
1483-
if (!split)
1484-
REJECT
1485-
if (which)
1486-
memcpy(buffer[2][STAGE],
1487-
in, length + 1);
1488-
else
1489-
strnzcpy(buffer[2][STAGE],
1490-
&word[split],
1491-
RULE_WORD_SIZE);
1522+
/* Additional "single crack" mode rules */
1523+
case '1':
1524+
if (split < 0)
1525+
goto out_ERROR_UNALLOWED;
1526+
if (!split)
1527+
REJECT
1528+
if (which)
1529+
memcpy(buffer[2][STAGE],
1530+
in, length + 1);
1531+
else
1532+
strnzcpy(buffer[2][STAGE],
1533+
&word[split],
1534+
RULE_WORD_SIZE);
1535+
length = split;
1536+
if (length > RULE_WORD_SIZE - 1)
1537+
length = RULE_WORD_SIZE - 1;
1538+
memcpy(in, word, length);
1539+
in[length] = 0;
1540+
which = 1;
1541+
break;
1542+
1543+
case '2':
1544+
if (split < 0)
1545+
goto out_ERROR_UNALLOWED;
1546+
if (!split)
1547+
REJECT
1548+
if (which)
1549+
{
1550+
memcpy(buffer[2][STAGE],
1551+
in, length + 1);
1552+
}
1553+
else
1554+
{
14921555
length = split;
14931556
if (length > RULE_WORD_SIZE - 1)
14941557
length = RULE_WORD_SIZE - 1;
1495-
memcpy(in, word, length);
1496-
in[length] = 0;
1497-
which = 1;
1498-
break;
1499-
1500-
case '2':
1501-
if (split < 0)
1502-
goto out_ERROR_UNALLOWED;
1503-
if (!split)
1504-
REJECT
1505-
if (which)
1506-
{
1507-
memcpy(buffer[2][STAGE],
1508-
in, length + 1);
1509-
}
1510-
else
1511-
{
1512-
length = split;
1513-
if (length > RULE_WORD_SIZE - 1)
1514-
length = RULE_WORD_SIZE - 1;
1515-
strnzcpy(buffer[2][STAGE],
1516-
word, length + 1);
1517-
}
1518-
strnzcpy(in, &word[split], RULE_WORD_SIZE);
1519-
length = strlen(in);
1520-
which = 2;
1521-
break;
1558+
strnzcpy(buffer[2][STAGE],
1559+
word, length + 1);
1560+
}
1561+
strnzcpy(in, &word[split], RULE_WORD_SIZE);
1562+
length = strlen(in);
1563+
which = 2;
1564+
break;
15221565

15231566
case '+':
15241567
if (hc_logic || !which)

0 commit comments

Comments
 (0)