From be0dec621a8b2255acb76cd936ccc4fd7012ec04 Mon Sep 17 00:00:00 2001 From: mhasbini Date: Sun, 14 May 2017 18:50:45 +0300 Subject: [PATCH] Add support for rule position 'p' in host mode --- docs/changes.txt | 1 + docs/rules.txt | 2 +- include/types.h | 1 + src/rp_cpu.c | 34 +++++++++++++++++++++++++++++++--- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 7acfae9e8..2963b1bde 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -14,6 +14,7 @@ - Wordlist encoding: Support added for internal convert from and to user-defined encoding during runtime - Wordlist encoding: Added parameters --encoding-from and --encoding-to to configure wordlist encoding handling - Rules: Support added for rule 'eX' +- Rules: Support added for position 'p' in host mode (using -j or -k) ## ## Improvements diff --git a/docs/rules.txt b/docs/rules.txt index a43186655..4a22a7cd0 100644 --- a/docs/rules.txt +++ b/docs/rules.txt @@ -56,4 +56,4 @@ #define RULE_OP_REJECT_EQUAL_AT '=' // reject plains that do not contain char X at position N #define RULE_OP_REJECT_CONTAINS '%' // reject plains that contain char X less than N times #define RULE_OP_REJECT_MEMORY 'Q' // reject plains that match the plain saved (see M), i.e. if unchanged - +#define RULE_LAST_REJECTED_SAVED_POS 'p' // position of the character last found with '/' or '%' diff --git a/include/types.h b/include/types.h index 570073fc0..f10292615 100644 --- a/include/types.h +++ b/include/types.h @@ -293,6 +293,7 @@ typedef enum rule_functions RULE_OP_REJECT_EQUAL_AT = '=', RULE_OP_REJECT_CONTAINS = '%', RULE_OP_REJECT_MEMORY = 'Q', + RULE_LAST_REJECTED_SAVED_POS = 'p', RULE_OP_MANGLE_SWITCH_FIRST = 'k', RULE_OP_MANGLE_SWITCH_LAST = 'K', diff --git a/src/rp_cpu.c b/src/rp_cpu.c index fac9a35d3..4c02519aa 100644 --- a/src/rp_cpu.c +++ b/src/rp_cpu.c @@ -9,7 +9,18 @@ #include "rp_cpu.h" #define NEXT_RULEPOS(rp) if (++(rp) == rule_len) return (RULE_RC_SYNTAX_ERROR) -#define NEXT_RPTOI(r,rp,up) if (((up) = conv_ctoi ((r)[(rp)])) == -1) return (RULE_RC_SYNTAX_ERROR) +#define NEXT_RPTOI(r,rp,up) if (((up) = conv_pos ((r)[(rp)], pos_mem)) == -1) return (RULE_RC_SYNTAX_ERROR) + +static int conv_pos (const u8 c, const int pos_mem) { + if (c == RULE_LAST_REJECTED_SAVED_POS) + { + return pos_mem; + } + else + { + return conv_ctoi (c); + } +} static void MANGLE_TOGGLE_AT (char *arr, const int pos) { @@ -464,6 +475,7 @@ static int mangle_title_sep (char arr[BLOCK_SIZE], int arr_len, char c) int _old_apply_rule (char *rule, int rule_len, char in[BLOCK_SIZE], int in_len, char out[BLOCK_SIZE]) { char mem[BLOCK_SIZE] = { 0 }; + int pos_mem = -1; if (in == NULL) return (RULE_RC_REJECT_ERROR); @@ -761,7 +773,15 @@ int _old_apply_rule (char *rule, int rule_len, char in[BLOCK_SIZE], int in_len, case RULE_OP_REJECT_NOT_CONTAIN: NEXT_RULEPOS (rule_pos); - if (strchr (out, rule[rule_pos]) == NULL) return (RULE_RC_REJECT_ERROR); + char *match = strchr (out, rule[rule_pos]); + if (match != NULL) + { + pos_mem = (int)(match - out); + } + else + { + return (RULE_RC_REJECT_ERROR); + } break; case RULE_OP_REJECT_EQUAL_FIRST: @@ -787,7 +807,15 @@ int _old_apply_rule (char *rule, int rule_len, char in[BLOCK_SIZE], int in_len, NEXT_RPTOI (rule, rule_pos, upos); if ((upos + 1) > out_len) return (RULE_RC_REJECT_ERROR); NEXT_RULEPOS (rule_pos); - int c; int cnt; for (c = 0, cnt = 0; c < out_len; c++) if (out[c] == rule[rule_pos]) cnt++; + int c; int cnt; + for (c = 0, cnt = 0; c < out_len && cnt < upos; c++) { + if (out[c] == rule[rule_pos]) + { + cnt++; + pos_mem = c; + } + } + if (cnt < upos) return (RULE_RC_REJECT_ERROR); break;