1 /**
2  * Author......: Jens Steube <jens.steube@gmail.com>
3  * License.....: MIT
4  */
5 
6 #ifndef RP_H
7 #define RP_H
8 
9 #define RP_RULE_BUFSIZ  0x100
10 
11 #define RULE_RC_SYNTAX_ERROR  -1
12 #define RULE_RC_REJECT_ERROR  -2
13 
14 #define RULE_OP_MANGLE_NOOP             ':'
15 #define RULE_OP_MANGLE_LREST            'l'
16 #define RULE_OP_MANGLE_UREST            'u'
17 #define RULE_OP_MANGLE_LREST_UFIRST     'c'
18 #define RULE_OP_MANGLE_UREST_LFIRST     'C'
19 #define RULE_OP_MANGLE_TREST            't'
20 #define RULE_OP_MANGLE_TOGGLE_AT        'T'
21 #define RULE_OP_MANGLE_REVERSE          'r'
22 #define RULE_OP_MANGLE_DUPEWORD         'd'
23 #define RULE_OP_MANGLE_DUPEWORD_TIMES   'p'
24 #define RULE_OP_MANGLE_REFLECT          'f'
25 #define RULE_OP_MANGLE_ROTATE_LEFT      '{'
26 #define RULE_OP_MANGLE_ROTATE_RIGHT     '}'
27 #define RULE_OP_MANGLE_APPEND           '$'
28 #define RULE_OP_MANGLE_PREPEND          '^'
29 #define RULE_OP_MANGLE_DELETE_FIRST     '['
30 #define RULE_OP_MANGLE_DELETE_LAST      ']'
31 #define RULE_OP_MANGLE_DELETE_AT        'D'
32 #define RULE_OP_MANGLE_EXTRACT          'x'
33 #define RULE_OP_MANGLE_OMIT             'O'
34 #define RULE_OP_MANGLE_INSERT           'i'
35 #define RULE_OP_MANGLE_OVERSTRIKE       'o'
36 #define RULE_OP_MANGLE_TRUNCATE_AT      '\''
37 #define RULE_OP_MANGLE_REPLACE          's'
38 #define RULE_OP_MANGLE_PURGECHAR        '@'
39 #define RULE_OP_MANGLE_TOGGLECASE_REC   'a'
40 #define RULE_OP_MANGLE_DUPECHAR_FIRST   'z'
41 #define RULE_OP_MANGLE_DUPECHAR_LAST    'Z'
42 #define RULE_OP_MANGLE_DUPECHAR_ALL     'q'
43 #define RULE_OP_MANGLE_EXTRACT_MEMORY   'X'
44 #define RULE_OP_MANGLE_APPEND_MEMORY    '4'
45 #define RULE_OP_MANGLE_PREPEND_MEMORY   '6'
46 
47 #define RULE_OP_MEMORIZE_WORD           'M'
48 
49 #define RULE_OP_REJECT_LESS             '<'
50 #define RULE_OP_REJECT_GREATER          '>'
51 #define RULE_OP_REJECT_CONTAIN          '!'
52 #define RULE_OP_REJECT_NOT_CONTAIN      '/'
53 #define RULE_OP_REJECT_EQUAL_FIRST      '('
54 #define RULE_OP_REJECT_EQUAL_LAST       ')'
55 #define RULE_OP_REJECT_EQUAL_AT         '='
56 #define RULE_OP_REJECT_CONTAINS         '%'
57 #define RULE_OP_REJECT_MEMORY           'Q'
58 
59 /* hashcat only */
60 #define RULE_OP_MANGLE_SWITCH_FIRST     'k'
61 #define RULE_OP_MANGLE_SWITCH_LAST      'K'
62 #define RULE_OP_MANGLE_SWITCH_AT        '*'
63 #define RULE_OP_MANGLE_CHR_SHIFTL       'L'
64 #define RULE_OP_MANGLE_CHR_SHIFTR       'R'
65 #define RULE_OP_MANGLE_CHR_INCR         '+'
66 #define RULE_OP_MANGLE_CHR_DECR         '-'
67 #define RULE_OP_MANGLE_REPLACE_NP1      '.'
68 #define RULE_OP_MANGLE_REPLACE_NM1      ','
69 #define RULE_OP_MANGLE_DUPEBLOCK_FIRST  'y'
70 #define RULE_OP_MANGLE_DUPEBLOCK_LAST   'Y'
71 #define RULE_OP_MANGLE_TITLE            'E'
72 
73 static const char grp_op_nop[] =
74 {
75   RULE_OP_MANGLE_LREST,
76   RULE_OP_MANGLE_UREST,
77   RULE_OP_MANGLE_LREST_UFIRST,
78   RULE_OP_MANGLE_UREST_LFIRST,
79   RULE_OP_MANGLE_TREST,
80   RULE_OP_MANGLE_REVERSE,
81   RULE_OP_MANGLE_DUPEWORD,
82   RULE_OP_MANGLE_REFLECT,
83   RULE_OP_MANGLE_DELETE_FIRST,
84   RULE_OP_MANGLE_DELETE_LAST,
85   RULE_OP_MANGLE_ROTATE_LEFT,
86   RULE_OP_MANGLE_ROTATE_RIGHT,
87   RULE_OP_MANGLE_SWITCH_FIRST,
88   RULE_OP_MANGLE_SWITCH_LAST,
89   RULE_OP_MANGLE_DUPECHAR_ALL,
90   RULE_OP_MANGLE_TITLE,
91   RULE_OP_MANGLE_APPEND_MEMORY,
92   RULE_OP_MANGLE_PREPEND_MEMORY,
93 };
94 
95 static const char grp_op_pos_p0[] =
96 {
97   RULE_OP_MANGLE_TOGGLE_AT,
98   RULE_OP_MANGLE_DELETE_AT,
99   RULE_OP_MANGLE_TRUNCATE_AT,
100   RULE_OP_MANGLE_CHR_INCR,
101   RULE_OP_MANGLE_CHR_DECR,
102   RULE_OP_MANGLE_CHR_SHIFTL,
103   RULE_OP_MANGLE_CHR_SHIFTR,
104   RULE_OP_MANGLE_REPLACE_NP1,
105   RULE_OP_MANGLE_REPLACE_NM1
106 };
107 
108 static const char grp_op_pos_p1[] =
109 {
110   RULE_OP_MANGLE_DUPEWORD_TIMES,
111   RULE_OP_MANGLE_DUPECHAR_FIRST,
112   RULE_OP_MANGLE_DUPECHAR_LAST,
113   RULE_OP_MANGLE_DUPEBLOCK_FIRST,
114   RULE_OP_MANGLE_DUPEBLOCK_LAST
115 };
116 
117 static const char grp_op_chr[] =
118 {
119   RULE_OP_MANGLE_APPEND,
120   RULE_OP_MANGLE_PREPEND,
121   RULE_OP_MANGLE_PURGECHAR
122 };
123 
124 static const char grp_op_chr_chr[] =
125 {
126   RULE_OP_MANGLE_REPLACE
127 };
128 
129 static const char grp_op_pos_chr[] =
130 {
131   RULE_OP_MANGLE_INSERT,
132   RULE_OP_MANGLE_OVERSTRIKE
133 };
134 
135 static const char grp_op_pos_pos0[] =
136 {
137   RULE_OP_MANGLE_SWITCH_AT
138 };
139 
140 static const char grp_op_pos_pos1[] =
141 {
142   RULE_OP_MANGLE_EXTRACT
143 };
144 
145 static const char grp_op_pos1_pos2_pos3[] =
146 {
147   RULE_OP_MANGLE_EXTRACT_MEMORY
148 };
149 
150 static const char grp_pos[] =
151 {
152   '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B'
153 };
154 
155 bool class_num   (char c);
156 bool class_lower (char c);
157 bool class_upper (char c);
158 bool class_alpha (char c);
159 
160 int generate_random_rule (char rule_buf[RP_RULE_BUFSIZ], uint32_t rp_gen_func_min, uint32_t rp_gen_func_max);
161 
162 int apply_rule (char *rule, int rule_len, char in[BLOCK_SIZE], int in_len, char out[BLOCK_SIZE]);
163 
164 #endif /* RP_H */
165