Add new rule function '3' to switch the case of the first letter after occurrence N of char X

This commit is contained in:
Jens Steube
2021-08-01 00:04:10 +02:00
parent d4997d1255
commit f4e52ca533
8 changed files with 172 additions and 4 deletions
+17 -4
View File
@@ -71,7 +71,8 @@ static const char grp_op_chr_chr[] =
static const char grp_op_pos_chr[] =
{
RULE_OP_MANGLE_INSERT,
RULE_OP_MANGLE_OVERSTRIKE
RULE_OP_MANGLE_OVERSTRIKE,
RULE_OP_MANGLE_TOGGLE_AT_SEP
};
static const char grp_op_pos_pos0[] =
@@ -444,12 +445,18 @@ int cpu_rule_to_kernel_rule (char *rule_buf, u32 rule_len, kernel_rule_t *rule)
break;
case RULE_OP_MANGLE_TITLE:
SET_NAME (rule, rule_buf[rule_pos]);
SET_NAME (rule, rule_buf[rule_pos]);
break;
case RULE_OP_MANGLE_TITLE_SEP:
SET_NAME (rule, rule_buf[rule_pos]);
SET_P0 (rule, rule_buf[rule_pos]);
SET_NAME (rule, rule_buf[rule_pos]);
SET_P0 (rule, rule_buf[rule_pos]);
break;
case RULE_OP_MANGLE_TOGGLE_AT_SEP:
SET_NAME (rule, rule_buf[rule_pos]);
SET_P0_CONV (rule, rule_buf[rule_pos]);
SET_P1 (rule, rule_buf[rule_pos]);
break;
default:
@@ -675,6 +682,12 @@ int kernel_rule_to_cpu_rule (char *rule_buf, kernel_rule_t *rule)
GET_P0 (rule);
break;
case RULE_OP_MANGLE_TOGGLE_AT_SEP:
rule_buf[rule_pos] = rule_cmd;
GET_P0_CONV (rule);
GET_P1 (rule);
break;
case 0:
if (rule_pos == 0) return -1;
return rule_pos - 1;
+42
View File
@@ -45,6 +45,41 @@ static void MANGLE_SWITCH (char *arr, const int l, const int r)
arr[l] = c;
}
static int mangle_toggle_at_sep (char arr[RP_PASSWORD_SIZE], int arr_len, char c, int upos)
{
int toggle_next = 0;
int occurrence = 0;
int pos;
for (pos = 0; pos < arr_len; pos++)
{
if (arr[pos] == c)
{
if (occurrence == upos)
{
toggle_next = 1;
}
else
{
occurrence++;
}
continue;
}
if (toggle_next == 1)
{
MANGLE_TOGGLE_AT (arr, pos);
break;
}
}
return (arr_len);
}
static int mangle_lrest (char arr[RP_PASSWORD_SIZE], int arr_len)
{
int pos;
@@ -561,6 +596,13 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE],
if (upos < out_len) MANGLE_TOGGLE_AT (out, upos);
break;
case RULE_OP_MANGLE_TOGGLE_AT_SEP:
NEXT_RULEPOS (rule_pos);
NEXT_RPTOI (rule_new, rule_pos, upos);
NEXT_RULEPOS (rule_pos);
out_len = mangle_toggle_at_sep (out, out_len, rule_new[rule_pos], upos);
break;
case RULE_OP_MANGLE_REVERSE:
out_len = mangle_reverse (out, out_len);
break;