From 53f57fb7aefc1ff04d73407683c7d66c0f4dbb88 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Sat, 2 Nov 2024 22:02:18 +0100 Subject: [PATCH] Add support to character class rules --- OpenCL/inc_rp.cl | 85 +++++ OpenCL/inc_rp.h | 115 +++---- OpenCL/inc_rp_optimized.cl | 253 +++++++++++++++ OpenCL/inc_rp_optimized.h | 114 +++---- docs/changes.txt | 2 +- docs/credits.txt | 2 +- docs/rules.txt | 129 ++++---- include/types.h | 128 ++++---- src/rp.c | 120 +++++--- src/rp_cpu.c | 614 ++++++++++++++++++++++++++++++++++--- 10 files changed, 1247 insertions(+), 315 deletions(-) diff --git a/OpenCL/inc_rp.cl b/OpenCL/inc_rp.cl index 59dadb33d..174ac996e 100644 --- a/OpenCL/inc_rp.cl +++ b/OpenCL/inc_rp.cl @@ -577,6 +577,90 @@ DECLSPEC int mangle_replace (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, return (len); } +DECLSPEC int mangle_replace_class_l (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) +{ + for (int pos = 0; pos < len; pos++) + { + if (!is_l (buf[pos])) continue; + + buf[pos] = p1; + } + + return (len); +} + +DECLSPEC int mangle_replace_class_u (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) +{ + for (int pos = 0; pos < len; pos++) + { + if (!is_u (buf[pos])) continue; + + buf[pos] = p1; + } + + return (len); +} + +DECLSPEC int mangle_replace_class_d (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) +{ + for (int pos = 0; pos < len; pos++) + { + if (!is_d (buf[pos])) continue; + + buf[pos] = p1; + } + + return (len); +} + +DECLSPEC int mangle_replace_class_lh (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) +{ + for (int pos = 0; pos < len; pos++) + { + if (!is_lh (buf[pos])) continue; + + buf[pos] = p1; + } + + return (len); +} + +DECLSPEC int mangle_replace_class_uh (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) +{ + for (int pos = 0; pos < len; pos++) + { + if (!is_uh (buf[pos])) continue; + + buf[pos] = p1; + } + + return (len); +} + +DECLSPEC int mangle_replace_class_s (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) +{ + for (int pos = 0; pos < len; pos++) + { + if (!is_s (buf[pos])) continue; + + buf[pos] = p1; + } + + return (len); +} + +DECLSPEC int mangle_replace_class (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) +{ + if (p0 == 'l') return mangle_replace_class_l (p0, p1, buf, len); + else if (p0 == 'u') return mangle_replace_class_u (p0, p1, buf, len); + else if (p0 == 'd') return mangle_replace_class_d (p0, p1, buf, len); + else if (p0 == 'h') return mangle_replace_class_lh (p0, p1, buf, len); + else if (p0 == 'H') return mangle_replace_class_uh (p0, p1, buf, len); + else if (p0 == 's') return mangle_replace_class_s (p0, p1, buf, len); + + return len; +} + DECLSPEC int mangle_purgechar (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len) { int out_len = 0; @@ -965,6 +1049,7 @@ DECLSPEC int apply_rule (const u32 name, MAYBE_UNUSED const u8 p0, MAYBE_UNUSED case RULE_OP_MANGLE_OVERSTRIKE: out_len = mangle_overstrike (p0, p1, (PRIVATE_AS u8 *) buf, out_len); break; case RULE_OP_MANGLE_TRUNCATE_AT: out_len = mangle_truncate_at (p0, p1, (PRIVATE_AS u8 *) buf, out_len); break; case RULE_OP_MANGLE_REPLACE: out_len = mangle_replace (p0, p1, (PRIVATE_AS u8 *) buf, out_len); break; + case RULE_OP_MANGLE_REPLACE_CLASS: out_len = mangle_replace_class (p0, p1, (PRIVATE_AS u8 *) buf, out_len); break; case RULE_OP_MANGLE_PURGECHAR: out_len = mangle_purgechar (p0, p1, (PRIVATE_AS u8 *) buf, out_len); break; case RULE_OP_MANGLE_PURGECHAR_CLASS: out_len = mangle_purgechar_class (p0, p1, (PRIVATE_AS u8 *) buf, out_len); break; case RULE_OP_MANGLE_DUPECHAR_FIRST: out_len = mangle_dupechar_first (p0, p1, (PRIVATE_AS u8 *) buf, out_len); break; diff --git a/OpenCL/inc_rp.h b/OpenCL/inc_rp.h index 301384794..60759966c 100644 --- a/OpenCL/inc_rp.h +++ b/OpenCL/inc_rp.h @@ -14,61 +14,71 @@ #define MAYBE_UNUSED #endif -#define RULE_OP_MANGLE_NOOP ':' -#define RULE_OP_MANGLE_LREST 'l' -#define RULE_OP_MANGLE_UREST 'u' -#define RULE_OP_MANGLE_LREST_UFIRST 'c' -#define RULE_OP_MANGLE_UREST_LFIRST 'C' -#define RULE_OP_MANGLE_TREST 't' -#define RULE_OP_MANGLE_TOGGLE_AT 'T' -#define RULE_OP_MANGLE_TOGGLE_AT_SEP '3' -#define RULE_OP_MANGLE_REVERSE 'r' -#define RULE_OP_MANGLE_DUPEWORD 'd' -#define RULE_OP_MANGLE_DUPEWORD_TIMES 'p' -#define RULE_OP_MANGLE_REFLECT 'f' -#define RULE_OP_MANGLE_ROTATE_LEFT '{' -#define RULE_OP_MANGLE_ROTATE_RIGHT '}' -#define RULE_OP_MANGLE_APPEND '$' -#define RULE_OP_MANGLE_PREPEND '^' -#define RULE_OP_MANGLE_DELETE_FIRST '[' -#define RULE_OP_MANGLE_DELETE_LAST ']' -#define RULE_OP_MANGLE_DELETE_AT 'D' -#define RULE_OP_MANGLE_EXTRACT 'x' -#define RULE_OP_MANGLE_OMIT 'O' -#define RULE_OP_MANGLE_INSERT 'i' -#define RULE_OP_MANGLE_OVERSTRIKE 'o' -#define RULE_OP_MANGLE_TRUNCATE_AT '\'' -#define RULE_OP_MANGLE_REPLACE 's' -#define RULE_OP_MANGLE_PURGECHAR '@' -#define RULE_OP_MANGLE_PURGECHAR_CLASS 0x01 -#define RULE_OP_MANGLE_TOGGLECASE_REC 'a' -#define RULE_OP_MANGLE_DUPECHAR_FIRST 'z' -#define RULE_OP_MANGLE_DUPECHAR_LAST 'Z' -#define RULE_OP_MANGLE_DUPECHAR_ALL 'q' -#define RULE_OP_MANGLE_TITLE_SEP 'e' +#define RULE_OP_MANGLE_NOOP ':' +#define RULE_OP_MANGLE_LREST 'l' +#define RULE_OP_MANGLE_UREST 'u' +#define RULE_OP_MANGLE_LREST_UFIRST 'c' +#define RULE_OP_MANGLE_UREST_LFIRST 'C' +#define RULE_OP_MANGLE_TREST 't' +#define RULE_OP_MANGLE_TOGGLE_AT 'T' +#define RULE_OP_MANGLE_TOGGLE_AT_SEP '3' +#define RULE_OP_MANGLE_REVERSE 'r' +#define RULE_OP_MANGLE_DUPEWORD 'd' +#define RULE_OP_MANGLE_DUPEWORD_TIMES 'p' +#define RULE_OP_MANGLE_REFLECT 'f' +#define RULE_OP_MANGLE_ROTATE_LEFT '{' +#define RULE_OP_MANGLE_ROTATE_RIGHT '}' +#define RULE_OP_MANGLE_APPEND '$' +#define RULE_OP_MANGLE_PREPEND '^' +#define RULE_OP_MANGLE_DELETE_FIRST '[' +#define RULE_OP_MANGLE_DELETE_LAST ']' +#define RULE_OP_MANGLE_DELETE_AT 'D' +#define RULE_OP_MANGLE_EXTRACT 'x' +#define RULE_OP_MANGLE_OMIT 'O' +#define RULE_OP_MANGLE_INSERT 'i' +#define RULE_OP_MANGLE_OVERSTRIKE 'o' +#define RULE_OP_MANGLE_TRUNCATE_AT '\'' +#define RULE_OP_MANGLE_REPLACE 's' +#define RULE_OP_MANGLE_PURGECHAR '@' +#define RULE_OP_MANGLE_TOGGLECASE_REC 'a' +#define RULE_OP_MANGLE_DUPECHAR_FIRST 'z' +#define RULE_OP_MANGLE_DUPECHAR_LAST 'Z' +#define RULE_OP_MANGLE_DUPECHAR_ALL 'q' +#define RULE_OP_MANGLE_TITLE_SEP 'e' -#define RULE_OP_REJECT_LESS '<' -#define RULE_OP_REJECT_GREATER '>' -#define RULE_OP_REJECT_CONTAIN '!' -#define RULE_OP_REJECT_NOT_CONTAIN '/' -#define RULE_OP_REJECT_EQUAL_FIRST '(' -#define RULE_OP_REJECT_EQUAL_LAST ')' -#define RULE_OP_REJECT_EQUAL_AT '=' -#define RULE_OP_REJECT_CONTAINS '%' +#define RULE_OP_REJECT_LESS '<' +#define RULE_OP_REJECT_GREATER '>' +#define RULE_OP_REJECT_CONTAIN '!' +#define RULE_OP_REJECT_NOT_CONTAIN '/' +#define RULE_OP_REJECT_EQUAL_FIRST '(' +#define RULE_OP_REJECT_EQUAL_LAST ')' +#define RULE_OP_REJECT_EQUAL_AT '=' +#define RULE_OP_REJECT_CONTAINS '%' /* hashcat only */ -#define RULE_OP_MANGLE_SWITCH_FIRST 'k' -#define RULE_OP_MANGLE_SWITCH_LAST 'K' -#define RULE_OP_MANGLE_SWITCH_AT '*' -#define RULE_OP_MANGLE_CHR_SHIFTL 'L' -#define RULE_OP_MANGLE_CHR_SHIFTR 'R' -#define RULE_OP_MANGLE_CHR_INCR '+' -#define RULE_OP_MANGLE_CHR_DECR '-' -#define RULE_OP_MANGLE_REPLACE_NP1 '.' -#define RULE_OP_MANGLE_REPLACE_NM1 ',' -#define RULE_OP_MANGLE_DUPEBLOCK_FIRST 'y' -#define RULE_OP_MANGLE_DUPEBLOCK_LAST 'Y' -#define RULE_OP_MANGLE_TITLE 'E' +#define RULE_OP_MANGLE_SWITCH_FIRST 'k' +#define RULE_OP_MANGLE_SWITCH_LAST 'K' +#define RULE_OP_MANGLE_SWITCH_AT '*' +#define RULE_OP_MANGLE_CHR_SHIFTL 'L' +#define RULE_OP_MANGLE_CHR_SHIFTR 'R' +#define RULE_OP_MANGLE_CHR_INCR '+' +#define RULE_OP_MANGLE_CHR_DECR '-' +#define RULE_OP_MANGLE_REPLACE_NP1 '.' +#define RULE_OP_MANGLE_REPLACE_NM1 ',' +#define RULE_OP_MANGLE_DUPEBLOCK_FIRST 'y' +#define RULE_OP_MANGLE_DUPEBLOCK_LAST 'Y' +#define RULE_OP_MANGLE_TITLE 'E' + +/* using character classes */ +#define RULE_OP_MANGLE_REPLACE_CLASS 0x01 +#define RULE_OP_MANGLE_PURGECHAR_CLASS 0x02 +#define RULE_OP_REJECT_CONTAIN_CLASS 0x03 +#define RULE_OP_REJECT_NOT_CONTAIN_CLASS 0x04 +#define RULE_OP_REJECT_EQUAL_FIRST_CLASS 0x05 +#define RULE_OP_REJECT_EQUAL_LAST_CLASS 0x06 +#define RULE_OP_REJECT_EQUAL_AT_CLASS 0x07 +#define RULE_OP_REJECT_CONTAINS_CLASS 0x08 + #define RP_PASSWORD_SIZE 256 @@ -103,6 +113,7 @@ DECLSPEC int mangle_insert (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, DECLSPEC int mangle_overstrike (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len); DECLSPEC int mangle_truncate_at (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len); DECLSPEC int mangle_replace (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len); +DECLSPEC int mangle_replace_class (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len); DECLSPEC int mangle_purgechar (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len); DECLSPEC int mangle_purgechar_class (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len); DECLSPEC int mangle_dupechar_first (MAYBE_UNUSED const u8 p0, MAYBE_UNUSED const u8 p1, PRIVATE_AS u8 *buf, const int len); diff --git a/OpenCL/inc_rp_optimized.cl b/OpenCL/inc_rp_optimized.cl index 95a070dc8..fa7f2b0a2 100644 --- a/OpenCL/inc_rp_optimized.cl +++ b/OpenCL/inc_rp_optimized.cl @@ -1825,6 +1825,258 @@ DECLSPEC HC_INLINE_RP u32 rule_op_mangle_replace (MAYBE_UNUSED const u32 p0, MAY return in_len; } +DECLSPEC HC_INLINE_RP u32 rule_op_mangle_replace_class_l (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len) +{ + u32 buf_in[8]; + + buf_in[0] = buf0[0]; + buf_in[1] = buf0[1]; + buf_in[2] = buf0[2]; + buf_in[3] = buf0[3]; + buf_in[4] = buf1[0]; + buf_in[5] = buf1[1]; + buf_in[6] = buf1[2]; + buf_in[7] = buf1[3]; + + PRIVATE_AS u8 *in = (PRIVATE_AS u8 *) buf_in; + + u32 rn = 0; + + for (u32 pos = 0; pos < in_len; pos++) + { + if (!is_l (in[pos])) continue; + + in[pos] = (u8)p1; + + rn++; + } + + if (rn == 0) return in_len; + + buf0[0] = buf_in[0]; + buf0[1] = buf_in[1]; + buf0[2] = buf_in[2]; + buf0[3] = buf_in[3]; + buf1[0] = buf_in[4]; + buf1[1] = buf_in[5]; + buf1[2] = buf_in[6]; + buf1[3] = buf_in[7]; + + return in_len; +} + +DECLSPEC HC_INLINE_RP u32 rule_op_mangle_replace_class_u (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len) +{ + u32 buf_in[8]; + + buf_in[0] = buf0[0]; + buf_in[1] = buf0[1]; + buf_in[2] = buf0[2]; + buf_in[3] = buf0[3]; + buf_in[4] = buf1[0]; + buf_in[5] = buf1[1]; + buf_in[6] = buf1[2]; + buf_in[7] = buf1[3]; + + PRIVATE_AS u8 *in = (PRIVATE_AS u8 *) buf_in; + + u32 rn = 0; + + for (u32 pos = 0; pos < in_len; pos++) + { + if (!is_u (in[pos])) continue; + + in[pos] = (u8)p1; + + rn++; + } + + if (rn == 0) return in_len; + + buf0[0] = buf_in[0]; + buf0[1] = buf_in[1]; + buf0[2] = buf_in[2]; + buf0[3] = buf_in[3]; + buf1[0] = buf_in[4]; + buf1[1] = buf_in[5]; + buf1[2] = buf_in[6]; + buf1[3] = buf_in[7]; + + return in_len; +} + +DECLSPEC HC_INLINE_RP u32 rule_op_mangle_replace_class_d (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len) +{ + u32 buf_in[8]; + + buf_in[0] = buf0[0]; + buf_in[1] = buf0[1]; + buf_in[2] = buf0[2]; + buf_in[3] = buf0[3]; + buf_in[4] = buf1[0]; + buf_in[5] = buf1[1]; + buf_in[6] = buf1[2]; + buf_in[7] = buf1[3]; + + PRIVATE_AS u8 *in = (PRIVATE_AS u8 *) buf_in; + + u32 rn = 0; + + for (u32 pos = 0; pos < in_len; pos++) + { + if (!is_d (in[pos])) continue; + + in[pos] = (u8)p1; + + rn++; + } + + if (rn == 0) return in_len; + + buf0[0] = buf_in[0]; + buf0[1] = buf_in[1]; + buf0[2] = buf_in[2]; + buf0[3] = buf_in[3]; + buf1[0] = buf_in[4]; + buf1[1] = buf_in[5]; + buf1[2] = buf_in[6]; + buf1[3] = buf_in[7]; + + return in_len; +} + +DECLSPEC HC_INLINE_RP u32 rule_op_mangle_replace_class_lh (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len) +{ + u32 buf_in[8]; + + buf_in[0] = buf0[0]; + buf_in[1] = buf0[1]; + buf_in[2] = buf0[2]; + buf_in[3] = buf0[3]; + buf_in[4] = buf1[0]; + buf_in[5] = buf1[1]; + buf_in[6] = buf1[2]; + buf_in[7] = buf1[3]; + + PRIVATE_AS u8 *in = (PRIVATE_AS u8 *) buf_in; + + u32 rn = 0; + + for (u32 pos = 0; pos < in_len; pos++) + { + if (!is_lh (in[pos])) continue; + + in[pos] = (u8)p1; + + rn++; + } + + if (rn == 0) return in_len; + + buf0[0] = buf_in[0]; + buf0[1] = buf_in[1]; + buf0[2] = buf_in[2]; + buf0[3] = buf_in[3]; + buf1[0] = buf_in[4]; + buf1[1] = buf_in[5]; + buf1[2] = buf_in[6]; + buf1[3] = buf_in[7]; + + return in_len; +} + +DECLSPEC HC_INLINE_RP u32 rule_op_mangle_replace_class_uh (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len) +{ + u32 buf_in[8]; + + buf_in[0] = buf0[0]; + buf_in[1] = buf0[1]; + buf_in[2] = buf0[2]; + buf_in[3] = buf0[3]; + buf_in[4] = buf1[0]; + buf_in[5] = buf1[1]; + buf_in[6] = buf1[2]; + buf_in[7] = buf1[3]; + + PRIVATE_AS u8 *in = (PRIVATE_AS u8 *) buf_in; + + u32 rn = 0; + + for (u32 pos = 0; pos < in_len; pos++) + { + if (!is_uh (in[pos])) continue; + + in[pos] = (u8)p1; + + rn++; + } + + if (rn == 0) return in_len; + + buf0[0] = buf_in[0]; + buf0[1] = buf_in[1]; + buf0[2] = buf_in[2]; + buf0[3] = buf_in[3]; + buf1[0] = buf_in[4]; + buf1[1] = buf_in[5]; + buf1[2] = buf_in[6]; + buf1[3] = buf_in[7]; + + return in_len; +} + +DECLSPEC HC_INLINE_RP u32 rule_op_mangle_replace_class_s (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len) +{ + u32 buf_in[8]; + + buf_in[0] = buf0[0]; + buf_in[1] = buf0[1]; + buf_in[2] = buf0[2]; + buf_in[3] = buf0[3]; + buf_in[4] = buf1[0]; + buf_in[5] = buf1[1]; + buf_in[6] = buf1[2]; + buf_in[7] = buf1[3]; + + PRIVATE_AS u8 *in = (PRIVATE_AS u8 *) buf_in; + + u32 rn = 0; + + for (u32 pos = 0; pos < in_len; pos++) + { + if (!is_s (in[pos])) continue; + + in[pos] = (u8)p1; + + rn++; + } + + if (rn == 0) return in_len; + + buf0[0] = buf_in[0]; + buf0[1] = buf_in[1]; + buf0[2] = buf_in[2]; + buf0[3] = buf_in[3]; + buf1[0] = buf_in[4]; + buf1[1] = buf_in[5]; + buf1[2] = buf_in[6]; + buf1[3] = buf_in[7]; + + return in_len; +} + +DECLSPEC HC_INLINE_RP u32 rule_op_mangle_replace_class (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len) +{ + if ((u8)p0 == 'l') return rule_op_mangle_replace_class_l (p0, p1, buf0, buf1, in_len); + else if ((u8)p0 == 'u') return rule_op_mangle_replace_class_u (p0, p1, buf0, buf1, in_len); + else if ((u8)p0 == 'd') return rule_op_mangle_replace_class_d (p0, p1, buf0, buf1, in_len); + else if ((u8)p0 == 'h') return rule_op_mangle_replace_class_lh (p0, p1, buf0, buf1, in_len); + else if ((u8)p0 == 'H') return rule_op_mangle_replace_class_uh (p0, p1, buf0, buf1, in_len); + else if ((u8)p0 == 's') return rule_op_mangle_replace_class_s (p0, p1, buf0, buf1, in_len); + + return in_len; +} + DECLSPEC HC_INLINE_RP u32 rule_op_mangle_purgechar (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len) { const u32 r0 = search_on_register (buf0[0], p0); @@ -2692,6 +2944,7 @@ DECLSPEC u32 apply_rule_optimized (const u32 name, const u32 p0, const u32 p1, P case RULE_OP_MANGLE_OVERSTRIKE: out_len = rule_op_mangle_overstrike (p0, p1, buf0, buf1, out_len); break; case RULE_OP_MANGLE_TRUNCATE_AT: out_len = rule_op_mangle_truncate_at (p0, p1, buf0, buf1, out_len); break; case RULE_OP_MANGLE_REPLACE: out_len = rule_op_mangle_replace (p0, p1, buf0, buf1, out_len); break; + case RULE_OP_MANGLE_REPLACE_CLASS: out_len = rule_op_mangle_replace_class (p0, p1, buf0, buf1, out_len); break; case RULE_OP_MANGLE_PURGECHAR: out_len = rule_op_mangle_purgechar (p0, p1, buf0, buf1, out_len); break; case RULE_OP_MANGLE_PURGECHAR_CLASS: out_len = rule_op_mangle_purgechar_class (p0, p1, buf0, buf1, out_len); break; //case RULE_OP_MANGLE_TOGGLECASE_REC: out_len = rule_op_mangle_togglecase_rec (p0, p1, buf0, buf1, out_len); break; diff --git a/OpenCL/inc_rp_optimized.h b/OpenCL/inc_rp_optimized.h index 77d9050d4..6aa60162b 100644 --- a/OpenCL/inc_rp_optimized.h +++ b/OpenCL/inc_rp_optimized.h @@ -20,61 +20,70 @@ #define HC_INLINE_RP #endif -#define RULE_OP_MANGLE_NOOP ':' -#define RULE_OP_MANGLE_LREST 'l' -#define RULE_OP_MANGLE_UREST 'u' -#define RULE_OP_MANGLE_LREST_UFIRST 'c' -#define RULE_OP_MANGLE_UREST_LFIRST 'C' -#define RULE_OP_MANGLE_TREST 't' -#define RULE_OP_MANGLE_TOGGLE_AT 'T' -#define RULE_OP_MANGLE_TOGGLE_AT_SEP '3' -#define RULE_OP_MANGLE_REVERSE 'r' -#define RULE_OP_MANGLE_DUPEWORD 'd' -#define RULE_OP_MANGLE_DUPEWORD_TIMES 'p' -#define RULE_OP_MANGLE_REFLECT 'f' -#define RULE_OP_MANGLE_ROTATE_LEFT '{' -#define RULE_OP_MANGLE_ROTATE_RIGHT '}' -#define RULE_OP_MANGLE_APPEND '$' -#define RULE_OP_MANGLE_PREPEND '^' -#define RULE_OP_MANGLE_DELETE_FIRST '[' -#define RULE_OP_MANGLE_DELETE_LAST ']' -#define RULE_OP_MANGLE_DELETE_AT 'D' -#define RULE_OP_MANGLE_EXTRACT 'x' -#define RULE_OP_MANGLE_OMIT 'O' -#define RULE_OP_MANGLE_INSERT 'i' -#define RULE_OP_MANGLE_OVERSTRIKE 'o' -#define RULE_OP_MANGLE_TRUNCATE_AT '\'' -#define RULE_OP_MANGLE_REPLACE 's' -#define RULE_OP_MANGLE_PURGECHAR '@' -#define RULE_OP_MANGLE_PURGECHAR_CLASS 0x01 -#define RULE_OP_MANGLE_TOGGLECASE_REC 'a' -#define RULE_OP_MANGLE_DUPECHAR_FIRST 'z' -#define RULE_OP_MANGLE_DUPECHAR_LAST 'Z' -#define RULE_OP_MANGLE_DUPECHAR_ALL 'q' -#define RULE_OP_MANGLE_TITLE_SEP 'e' +#define RULE_OP_MANGLE_NOOP ':' +#define RULE_OP_MANGLE_LREST 'l' +#define RULE_OP_MANGLE_UREST 'u' +#define RULE_OP_MANGLE_LREST_UFIRST 'c' +#define RULE_OP_MANGLE_UREST_LFIRST 'C' +#define RULE_OP_MANGLE_TREST 't' +#define RULE_OP_MANGLE_TOGGLE_AT 'T' +#define RULE_OP_MANGLE_TOGGLE_AT_SEP '3' +#define RULE_OP_MANGLE_REVERSE 'r' +#define RULE_OP_MANGLE_DUPEWORD 'd' +#define RULE_OP_MANGLE_DUPEWORD_TIMES 'p' +#define RULE_OP_MANGLE_REFLECT 'f' +#define RULE_OP_MANGLE_ROTATE_LEFT '{' +#define RULE_OP_MANGLE_ROTATE_RIGHT '}' +#define RULE_OP_MANGLE_APPEND '$' +#define RULE_OP_MANGLE_PREPEND '^' +#define RULE_OP_MANGLE_DELETE_FIRST '[' +#define RULE_OP_MANGLE_DELETE_LAST ']' +#define RULE_OP_MANGLE_DELETE_AT 'D' +#define RULE_OP_MANGLE_EXTRACT 'x' +#define RULE_OP_MANGLE_OMIT 'O' +#define RULE_OP_MANGLE_INSERT 'i' +#define RULE_OP_MANGLE_OVERSTRIKE 'o' +#define RULE_OP_MANGLE_TRUNCATE_AT '\'' +#define RULE_OP_MANGLE_REPLACE 's' +#define RULE_OP_MANGLE_PURGECHAR '@' +#define RULE_OP_MANGLE_TOGGLECASE_REC 'a' +#define RULE_OP_MANGLE_DUPECHAR_FIRST 'z' +#define RULE_OP_MANGLE_DUPECHAR_LAST 'Z' +#define RULE_OP_MANGLE_DUPECHAR_ALL 'q' +#define RULE_OP_MANGLE_TITLE_SEP 'e' -#define RULE_OP_REJECT_LESS '<' -#define RULE_OP_REJECT_GREATER '>' -#define RULE_OP_REJECT_CONTAIN '!' -#define RULE_OP_REJECT_NOT_CONTAIN '/' -#define RULE_OP_REJECT_EQUAL_FIRST '(' -#define RULE_OP_REJECT_EQUAL_LAST ')' -#define RULE_OP_REJECT_EQUAL_AT '=' -#define RULE_OP_REJECT_CONTAINS '%' +#define RULE_OP_REJECT_LESS '<' +#define RULE_OP_REJECT_GREATER '>' +#define RULE_OP_REJECT_CONTAIN '!' +#define RULE_OP_REJECT_NOT_CONTAIN '/' +#define RULE_OP_REJECT_EQUAL_FIRST '(' +#define RULE_OP_REJECT_EQUAL_LAST ')' +#define RULE_OP_REJECT_EQUAL_AT '=' +#define RULE_OP_REJECT_CONTAINS '%' /* hashcat only */ -#define RULE_OP_MANGLE_SWITCH_FIRST 'k' -#define RULE_OP_MANGLE_SWITCH_LAST 'K' -#define RULE_OP_MANGLE_SWITCH_AT '*' -#define RULE_OP_MANGLE_CHR_SHIFTL 'L' -#define RULE_OP_MANGLE_CHR_SHIFTR 'R' -#define RULE_OP_MANGLE_CHR_INCR '+' -#define RULE_OP_MANGLE_CHR_DECR '-' -#define RULE_OP_MANGLE_REPLACE_NP1 '.' -#define RULE_OP_MANGLE_REPLACE_NM1 ',' -#define RULE_OP_MANGLE_DUPEBLOCK_FIRST 'y' -#define RULE_OP_MANGLE_DUPEBLOCK_LAST 'Y' -#define RULE_OP_MANGLE_TITLE 'E' +#define RULE_OP_MANGLE_SWITCH_FIRST 'k' +#define RULE_OP_MANGLE_SWITCH_LAST 'K' +#define RULE_OP_MANGLE_SWITCH_AT '*' +#define RULE_OP_MANGLE_CHR_SHIFTL 'L' +#define RULE_OP_MANGLE_CHR_SHIFTR 'R' +#define RULE_OP_MANGLE_CHR_INCR '+' +#define RULE_OP_MANGLE_CHR_DECR '-' +#define RULE_OP_MANGLE_REPLACE_NP1 '.' +#define RULE_OP_MANGLE_REPLACE_NM1 ',' +#define RULE_OP_MANGLE_DUPEBLOCK_FIRST 'y' +#define RULE_OP_MANGLE_DUPEBLOCK_LAST 'Y' +#define RULE_OP_MANGLE_TITLE 'E' + +/* using character classes */ +#define RULE_OP_MANGLE_REPLACE_CLASS 0x01 +#define RULE_OP_MANGLE_PURGECHAR_CLASS 0x02 +#define RULE_OP_REJECT_CONTAIN_CLASS 0x03 +#define RULE_OP_REJECT_NOT_CONTAIN_CLASS 0x04 +#define RULE_OP_REJECT_EQUAL_FIRST_CLASS 0x05 +#define RULE_OP_REJECT_EQUAL_LAST_CLASS 0x06 +#define RULE_OP_REJECT_EQUAL_AT_CLASS 0x07 +#define RULE_OP_REJECT_CONTAINS_CLASS 0x08 DECLSPEC u32 generate_cmask_optimized (const u32 value); DECLSPEC void truncate_right_optimized (PRIVATE_AS u32 *buf0, PRIVATE_AS u32 *buf1, const u32 offset); @@ -113,6 +122,7 @@ DECLSPEC HC_INLINE_RP u32 rule_op_mangle_truncate_at (MAYBE_UNUSED const u32 p0, DECLSPEC u32 search_on_register (const u32 in, const u32 p0); DECLSPEC u32 replace_on_register (const u32 in, const u32 r, const u32 p1); DECLSPEC HC_INLINE_RP u32 rule_op_mangle_replace (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len); +DECLSPEC HC_INLINE_RP u32 rule_op_mangle_replace_class (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len); DECLSPEC HC_INLINE_RP u32 rule_op_mangle_purgechar (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len); DECLSPEC HC_INLINE_RP u32 rule_op_mangle_purgechar_class (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len); DECLSPEC HC_INLINE_RP u32 rule_op_mangle_dupechar_first (MAYBE_UNUSED const u32 p0, MAYBE_UNUSED const u32 p1, MAYBE_UNUSED PRIVATE_AS u32 *buf0, MAYBE_UNUSED PRIVATE_AS u32 *buf1, const u32 in_len); diff --git a/docs/changes.txt b/docs/changes.txt index 4ce7293fe..c7ddca2ec 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -133,7 +133,7 @@ - Hardware Monitor: avoid sprintf in src/ext_iokit.c - Help: show supported hash-modes only with -hh - Makefile: prevent make failure with Apple Silicon in case of partial rebuild -- Rules: Extended the Purge (@) rule operation to support Classes +- Rules: Add support to character class rules - Rules: Rename best64.rule to best66.rule and remove the unknown section from it * changes v6.2.5 -> v6.2.6 diff --git a/docs/credits.txt b/docs/credits.txt index b4e437557..95ab83c4e 100644 --- a/docs/credits.txt +++ b/docs/credits.txt @@ -25,7 +25,7 @@ Gabriele "matrix" Gristina (@gm4tr1x) * Apple macOS port * Apple Silicon support * Universal binary on Apple Silicon -* Extended the Purge (@) rule operation to support Classes +* Add support to character class rules * Hardware monitor initial code base and maintenance * Test suite initial code base and maintenance * Makefile initial code base diff --git a/docs/rules.txt b/docs/rules.txt index c1d5950e0..e894acf7f 100644 --- a/docs/rules.txt +++ b/docs/rules.txt @@ -1,61 +1,76 @@ -#define RULE_OP_MANGLE_NOOP ':' // does nothing -#define RULE_OP_MANGLE_LREST 'l' // lower case all chars -#define RULE_OP_MANGLE_UREST 'u' // upper case all chars -#define RULE_OP_MANGLE_LREST_UFIRST 'c' // lower case all chars, upper case 1st -#define RULE_OP_MANGLE_UREST_LFIRST 'C' // upper case all chars, lower case 1st -#define RULE_OP_MANGLE_TREST 't' // switch the case of each char -#define RULE_OP_MANGLE_TOGGLE_AT 'T' // switch the case of each char on pos N -#define RULE_OP_MANGLE_TOGGLE_AT_SEP '3' // switch the case of the first letter after occurrence N of char X -#define RULE_OP_MANGLE_REVERSE 'r' // reverse word -#define RULE_OP_MANGLE_DUPEWORD 'd' // append word to itself -#define RULE_OP_MANGLE_DUPEWORD_TIMES 'p' // append word to itself N times -#define RULE_OP_MANGLE_REFLECT 'f' // reflect word (append reversed word) -#define RULE_OP_MANGLE_ROTATE_LEFT '{' // rotate the word left. ex: hello -> elloh -#define RULE_OP_MANGLE_ROTATE_RIGHT '}' // rotate the word right. ex: hello -> ohell -#define RULE_OP_MANGLE_APPEND '$' // append char X -#define RULE_OP_MANGLE_PREPEND '^' // prepend char X -#define RULE_OP_MANGLE_DELETE_FIRST '[' // delete first char of word -#define RULE_OP_MANGLE_DELETE_LAST ']' // delete last char of word -#define RULE_OP_MANGLE_DELETE_AT 'D' // delete char of word at pos N -#define RULE_OP_MANGLE_EXTRACT 'x' // extract X chars of word at pos N -#define RULE_OP_MANGLE_OMIT 'O' // omit X chars of word at pos N -#define RULE_OP_MANGLE_INSERT 'i' // insert char X at pos N -#define RULE_OP_MANGLE_OVERSTRIKE 'o' // overwrite with char X at pos N -#define RULE_OP_MANGLE_TRUNCATE_AT '\''// cut the word at pos N -#define RULE_OP_MANGLE_REPLACE 's' // replace all chars X with char Y -#define RULE_OP_MANGLE_PURGECHAR '@' // purge all instances of char X (@X) or purge all instances of chars in class X (@?X) -#define RULE_OP_MANGLE_DUPECHAR_FIRST 'z' // prepend first char of word to itself N times. ex: hello -> hhhello -#define RULE_OP_MANGLE_DUPECHAR_LAST 'Z' // append last char of word to itself N times. ex: hello -> hellooo -#define RULE_OP_MANGLE_DUPECHAR_ALL 'q' // duplicate all chars. ex: hello -> hheelllloo -#define RULE_OP_MANGLE_SWITCH_FIRST 'k' // switches the first 2 chars. ex: hello -> ehllo -#define RULE_OP_MANGLE_SWITCH_LAST 'K' // switches the last 2 chars. ex: hello -> helol -#define RULE_OP_MANGLE_SWITCH_AT '*' // switches char at pos N with char at pos M. ex: hello -> holle -#define RULE_OP_MANGLE_CHR_SHIFTL 'L' // bitwise shift left char at pos N. ex: hello0 -> hello` -#define RULE_OP_MANGLE_CHR_SHIFTR 'R' // bitwise shift right char at pos N. ex: hello` -> hello0 -#define RULE_OP_MANGLE_CHR_INCR '+' // bytewise increase at pos N. ex: hello0 -> hello1 -#define RULE_OP_MANGLE_CHR_DECR '-' // bytewise decreate at pos N. ex: hello1 -> hello0 -#define RULE_OP_MANGLE_REPLACE_NP1 '.' // replaces char @ n with value at @ n plus 1 -#define RULE_OP_MANGLE_REPLACE_NM1 ',' // replaces char @ n with value at @ n minus 1 -#define RULE_OP_MANGLE_DUPEBLOCK_FIRST 'y' // duplicates first N chars -#define RULE_OP_MANGLE_DUPEBLOCK_LAST 'Y' // duplicates last N chars -#define RULE_OP_MANGLE_TITLE 'E' // lowercase everything then upper case the first letter and every letter after a space -#define RULE_OP_MANGLE_TITLE_SEP 'e' // lowercase everything then upper case the first letter and every letter after char X +#define RULE_OP_MANGLE_NOOP ':' // does nothing +#define RULE_OP_MANGLE_LREST 'l' // lower case all chars +#define RULE_OP_MANGLE_UREST 'u' // upper case all chars +#define RULE_OP_MANGLE_LREST_UFIRST 'c' // lower case all chars, upper case 1st +#define RULE_OP_MANGLE_UREST_LFIRST 'C' // upper case all chars, lower case 1st +#define RULE_OP_MANGLE_TREST 't' // switch the case of each char +#define RULE_OP_MANGLE_TOGGLE_AT 'T' // switch the case of each char on pos N +#define RULE_OP_MANGLE_TOGGLE_AT_SEP '3' // switch the case of the first letter after occurrence N of char X +#define RULE_OP_MANGLE_REVERSE 'r' // reverse word +#define RULE_OP_MANGLE_DUPEWORD 'd' // append word to itself +#define RULE_OP_MANGLE_DUPEWORD_TIMES 'p' // append word to itself N times +#define RULE_OP_MANGLE_REFLECT 'f' // reflect word (append reversed word) +#define RULE_OP_MANGLE_ROTATE_LEFT '{' // rotate the word left. ex: hello -> elloh +#define RULE_OP_MANGLE_ROTATE_RIGHT '}' // rotate the word right. ex: hello -> ohell +#define RULE_OP_MANGLE_APPEND '$' // append char X +#define RULE_OP_MANGLE_PREPEND '^' // prepend char X +#define RULE_OP_MANGLE_DELETE_FIRST '[' // delete first char of word +#define RULE_OP_MANGLE_DELETE_LAST ']' // delete last char of word +#define RULE_OP_MANGLE_DELETE_AT 'D' // delete char of word at pos N +#define RULE_OP_MANGLE_EXTRACT 'x' // extract X chars of word at pos N +#define RULE_OP_MANGLE_OMIT 'O' // omit X chars of word at pos N +#define RULE_OP_MANGLE_INSERT 'i' // insert char X at pos N +#define RULE_OP_MANGLE_OVERSTRIKE 'o' // overwrite with char X at pos N +#define RULE_OP_MANGLE_TRUNCATE_AT '\'' // cut the word at pos N +#define RULE_OP_MANGLE_REPLACE 's' // replace all chars X with char Y +#define RULE_OP_MANGLE_PURGECHAR '@' // purge all instances of char X +#define RULE_OP_MANGLE_DUPECHAR_FIRST 'z' // prepend first char of word to itself N times. ex: hello -> hhhello +#define RULE_OP_MANGLE_DUPECHAR_LAST 'Z' // append last char of word to itself N times. ex: hello -> hellooo +#define RULE_OP_MANGLE_DUPECHAR_ALL 'q' // duplicate all chars. ex: hello -> hheelllloo +#define RULE_OP_MANGLE_SWITCH_FIRST 'k' // switches the first 2 chars. ex: hello -> ehllo +#define RULE_OP_MANGLE_SWITCH_LAST 'K' // switches the last 2 chars. ex: hello -> helol +#define RULE_OP_MANGLE_SWITCH_AT '*' // switches char at pos N with char at pos M. ex: hello -> holle +#define RULE_OP_MANGLE_CHR_SHIFTL 'L' // bitwise shift left char at pos N. ex: hello0 -> hello` +#define RULE_OP_MANGLE_CHR_SHIFTR 'R' // bitwise shift right char at pos N. ex: hello` -> hello0 +#define RULE_OP_MANGLE_CHR_INCR '+' // bytewise increase at pos N. ex: hello0 -> hello1 +#define RULE_OP_MANGLE_CHR_DECR '-' // bytewise decreate at pos N. ex: hello1 -> hello0 +#define RULE_OP_MANGLE_REPLACE_NP1 '.' // replaces char @ n with value at @ n plus 1 +#define RULE_OP_MANGLE_REPLACE_NM1 ',' // replaces char @ n with value at @ n minus 1 +#define RULE_OP_MANGLE_DUPEBLOCK_FIRST 'y' // duplicates first N chars +#define RULE_OP_MANGLE_DUPEBLOCK_LAST 'Y' // duplicates last N chars +#define RULE_OP_MANGLE_TITLE 'E' // lowercase everything then upper case the first letter and every letter after a space +#define RULE_OP_MANGLE_TITLE_SEP 'e' // lowercase everything then upper case the first letter and every letter after char X /* With -j or -k only */ -#define RULE_OP_MANGLE_EXTRACT_MEMORY 'X' // insert substring delimited by N and M into current word at pos I -#define RULE_OP_MANGLE_APPEND_MEMORY '4' // insert the word saved by 'M' at the end of current word -#define RULE_OP_MANGLE_PREPEND_MEMORY '6' // insert the word saved by 'M' at the beginning of current word -#define RULE_OP_MEMORIZE_WORD 'M' // memorize current word +#define RULE_OP_MANGLE_EXTRACT_MEMORY 'X' // insert substring delimited by N and M into current word at pos I +#define RULE_OP_MANGLE_APPEND_MEMORY '4' // insert the word saved by 'M' at the end of current word +#define RULE_OP_MANGLE_PREPEND_MEMORY '6' // insert the word saved by 'M' at the beginning of current word +#define RULE_OP_MEMORIZE_WORD 'M' // memorize current word -#define RULE_OP_REJECT_LESS '<' // reject plains of length greater than N -#define RULE_OP_REJECT_GREATER '>' // reject plains of length less than N -#define RULE_OP_REJECT_EQUAL '_' // reject plains of length not equal to N -#define RULE_OP_REJECT_CONTAIN '!' // reject plains that contain char X -#define RULE_OP_REJECT_NOT_CONTAIN '/' // reject plains that do not contain char X -#define RULE_OP_REJECT_EQUAL_FIRST '(' // reject plains that do not contain char X at first pos -#define RULE_OP_REJECT_EQUAL_LAST ')' // reject plains that do not contain char X at last pos -#define RULE_OP_REJECT_EQUAL_AT '=' // reject plains that do not contain char X at pos 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' // pos of the char last found with '/' or '%' +#define RULE_OP_REJECT_LESS '<' // reject plains of length greater than N +#define RULE_OP_REJECT_GREATER '>' // reject plains of length less than N +#define RULE_OP_REJECT_EQUAL '_' // reject plains of length not equal to N +#define RULE_OP_REJECT_CONTAIN '!' // reject plains that contain char X +#define RULE_OP_REJECT_NOT_CONTAIN '/' // reject plains that do not contain char X +#define RULE_OP_REJECT_EQUAL_FIRST '(' // reject plains that do not contain char X at first pos +#define RULE_OP_REJECT_EQUAL_LAST ')' // reject plains that do not contain char X at last pos +#define RULE_OP_REJECT_EQUAL_AT '=' // reject plains that do not contain char X at pos 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' // pos of the char last found with '/' or '%' + +/* using character classes */ + +#define RULE_OP_CLASS_BASED '~' +#define RULE_OP_MANGLE_REPLACE_CLASS 0x01 // replace all instances of chars in class C with char Y, ~s?CY +#define RULE_OP_MANGLE_PURGECHAR_CLASS 0x02 // purge all instances of chars in class C, ~@?C + +/* using character classes, with -j or -k only */ + +#define RULE_OP_REJECT_CONTAIN_CLASS 0x03 // reject plains that contain chars in class C, ~!?C +#define RULE_OP_REJECT_NOT_CONTAIN_CLASS 0x04 // reject plains that do not contain chars in class C, ~/?C +#define RULE_OP_REJECT_EQUAL_FIRST_CLASS 0x05 // reject plains that do not contain char in class C at first pos, ~(?C +#define RULE_OP_REJECT_EQUAL_LAST_CLASS 0x06 // reject plains that do not contain char in class C at last pos, ~)?C +#define RULE_OP_REJECT_EQUAL_AT_CLASS 0x07 // reject plains that do not contain char in class C at pos N, ~=N?C +#define RULE_OP_REJECT_CONTAINS_CLASS 0x08 // reject plains that contain char in class C less than N times, ~%N?C diff --git a/include/types.h b/include/types.h index adcb06094..e68e90160 100644 --- a/include/types.h +++ b/include/types.h @@ -305,68 +305,78 @@ typedef enum kern_run_mp typedef enum rule_functions { - RULE_OP_MANGLE_NOOP = ':', - RULE_OP_MANGLE_LREST = 'l', - RULE_OP_MANGLE_UREST = 'u', - RULE_OP_MANGLE_LREST_UFIRST = 'c', - RULE_OP_MANGLE_UREST_LFIRST = 'C', - RULE_OP_MANGLE_TREST = 't', - RULE_OP_MANGLE_TOGGLE_AT = 'T', - RULE_OP_MANGLE_TOGGLE_AT_SEP = '3', - RULE_OP_MANGLE_REVERSE = 'r', - RULE_OP_MANGLE_DUPEWORD = 'd', - RULE_OP_MANGLE_DUPEWORD_TIMES = 'p', - RULE_OP_MANGLE_REFLECT = 'f', - RULE_OP_MANGLE_ROTATE_LEFT = '{', - RULE_OP_MANGLE_ROTATE_RIGHT = '}', - RULE_OP_MANGLE_APPEND = '$', - RULE_OP_MANGLE_PREPEND = '^', - RULE_OP_MANGLE_DELETE_FIRST = '[', - RULE_OP_MANGLE_DELETE_LAST = ']', - RULE_OP_MANGLE_DELETE_AT = 'D', - RULE_OP_MANGLE_EXTRACT = 'x', - RULE_OP_MANGLE_OMIT = 'O', - RULE_OP_MANGLE_INSERT = 'i', - RULE_OP_MANGLE_OVERSTRIKE = 'o', - RULE_OP_MANGLE_TRUNCATE_AT = '\'', - RULE_OP_MANGLE_REPLACE = 's', - RULE_OP_MANGLE_PURGECHAR = '@', - RULE_OP_MANGLE_PURGECHAR_CLASS = 0x01, - RULE_OP_MANGLE_TOGGLECASE_REC = 'a', - RULE_OP_MANGLE_DUPECHAR_FIRST = 'z', - RULE_OP_MANGLE_DUPECHAR_LAST = 'Z', - RULE_OP_MANGLE_DUPECHAR_ALL = 'q', - RULE_OP_MANGLE_EXTRACT_MEMORY = 'X', - RULE_OP_MANGLE_APPEND_MEMORY = '4', - RULE_OP_MANGLE_PREPEND_MEMORY = '6', - RULE_OP_MANGLE_TITLE_SEP = 'e', + RULE_OP_MANGLE_NOOP = ':', + RULE_OP_MANGLE_LREST = 'l', + RULE_OP_MANGLE_UREST = 'u', + RULE_OP_MANGLE_LREST_UFIRST = 'c', + RULE_OP_MANGLE_UREST_LFIRST = 'C', + RULE_OP_MANGLE_TREST = 't', + RULE_OP_MANGLE_TOGGLE_AT = 'T', + RULE_OP_MANGLE_TOGGLE_AT_SEP = '3', + RULE_OP_MANGLE_REVERSE = 'r', + RULE_OP_MANGLE_DUPEWORD = 'd', + RULE_OP_MANGLE_DUPEWORD_TIMES = 'p', + RULE_OP_MANGLE_REFLECT = 'f', + RULE_OP_MANGLE_ROTATE_LEFT = '{', + RULE_OP_MANGLE_ROTATE_RIGHT = '}', + RULE_OP_MANGLE_APPEND = '$', + RULE_OP_MANGLE_PREPEND = '^', + RULE_OP_MANGLE_DELETE_FIRST = '[', + RULE_OP_MANGLE_DELETE_LAST = ']', + RULE_OP_MANGLE_DELETE_AT = 'D', + RULE_OP_MANGLE_EXTRACT = 'x', + RULE_OP_MANGLE_OMIT = 'O', + RULE_OP_MANGLE_INSERT = 'i', + RULE_OP_MANGLE_OVERSTRIKE = 'o', + RULE_OP_MANGLE_TRUNCATE_AT = '\'', + RULE_OP_MANGLE_REPLACE = 's', + RULE_OP_MANGLE_PURGECHAR = '@', + RULE_OP_MANGLE_TOGGLECASE_REC = 'a', + RULE_OP_MANGLE_DUPECHAR_FIRST = 'z', + RULE_OP_MANGLE_DUPECHAR_LAST = 'Z', + RULE_OP_MANGLE_DUPECHAR_ALL = 'q', + RULE_OP_MANGLE_EXTRACT_MEMORY = 'X', + RULE_OP_MANGLE_APPEND_MEMORY = '4', + RULE_OP_MANGLE_PREPEND_MEMORY = '6', + RULE_OP_MANGLE_TITLE_SEP = 'e', - RULE_OP_MEMORIZE_WORD = 'M', + RULE_OP_MEMORIZE_WORD = 'M', - RULE_OP_REJECT_LESS = '<', - RULE_OP_REJECT_GREATER = '>', - RULE_OP_REJECT_EQUAL = '_', - RULE_OP_REJECT_CONTAIN = '!', - RULE_OP_REJECT_NOT_CONTAIN = '/', - RULE_OP_REJECT_EQUAL_FIRST = '(', - RULE_OP_REJECT_EQUAL_LAST = ')', - RULE_OP_REJECT_EQUAL_AT = '=', - RULE_OP_REJECT_CONTAINS = '%', - RULE_OP_REJECT_MEMORY = 'Q', - RULE_LAST_REJECTED_SAVED_POS = 'p', + RULE_OP_REJECT_LESS = '<', + RULE_OP_REJECT_GREATER = '>', + RULE_OP_REJECT_EQUAL = '_', + RULE_OP_REJECT_CONTAIN = '!', + RULE_OP_REJECT_NOT_CONTAIN = '/', + RULE_OP_REJECT_EQUAL_FIRST = '(', + RULE_OP_REJECT_EQUAL_LAST = ')', + 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', - RULE_OP_MANGLE_SWITCH_AT = '*', - RULE_OP_MANGLE_CHR_SHIFTL = 'L', - RULE_OP_MANGLE_CHR_SHIFTR = 'R', - RULE_OP_MANGLE_CHR_INCR = '+', - RULE_OP_MANGLE_CHR_DECR = '-', - RULE_OP_MANGLE_REPLACE_NP1 = '.', - RULE_OP_MANGLE_REPLACE_NM1 = ',', - RULE_OP_MANGLE_DUPEBLOCK_FIRST = 'y', - RULE_OP_MANGLE_DUPEBLOCK_LAST = 'Y', - RULE_OP_MANGLE_TITLE = 'E', + RULE_OP_MANGLE_SWITCH_FIRST = 'k', + RULE_OP_MANGLE_SWITCH_LAST = 'K', + RULE_OP_MANGLE_SWITCH_AT = '*', + RULE_OP_MANGLE_CHR_SHIFTL = 'L', + RULE_OP_MANGLE_CHR_SHIFTR = 'R', + RULE_OP_MANGLE_CHR_INCR = '+', + RULE_OP_MANGLE_CHR_DECR = '-', + RULE_OP_MANGLE_REPLACE_NP1 = '.', + RULE_OP_MANGLE_REPLACE_NM1 = ',', + RULE_OP_MANGLE_DUPEBLOCK_FIRST = 'y', + RULE_OP_MANGLE_DUPEBLOCK_LAST = 'Y', + RULE_OP_MANGLE_TITLE = 'E', + + /* using character classes */ + RULE_OP_CLASS_BASED = '~', + RULE_OP_MANGLE_REPLACE_CLASS = 0x01, + RULE_OP_MANGLE_PURGECHAR_CLASS = 0x02, + RULE_OP_REJECT_CONTAIN_CLASS = 0x03, + RULE_OP_REJECT_NOT_CONTAIN_CLASS = 0x04, + RULE_OP_REJECT_EQUAL_FIRST_CLASS = 0x05, + RULE_OP_REJECT_EQUAL_LAST_CLASS = 0x06, + RULE_OP_REJECT_EQUAL_AT_CLASS = 0x07, + RULE_OP_REJECT_CONTAINS_CLASS = 0x08, } rule_functions_t; diff --git a/src/rp.c b/src/rp.c index a5153cefd..ea987bdc6 100644 --- a/src/rp.c +++ b/src/rp.c @@ -388,42 +388,6 @@ int cpu_rule_to_kernel_rule (char *rule_buf, u32 rule_len, kernel_rule_t *rule) break; case RULE_OP_MANGLE_PURGECHAR: - if ((rule_pos + 1) < rule_len && rule_buf[rule_pos+1] == '?') - { - if ((rule_pos + 2) == rule_len) - { - SET_NAME (rule, rule_buf[rule_pos]); - SET_P0 (rule, rule_buf[rule_pos]); - break; - } - - switch (rule_buf[rule_pos+2]) { - case '\'': - SET_NAME (rule, rule_buf[rule_pos]); - SET_P0 (rule, rule_buf[rule_pos]); - break; - case ' ': - case '?': - SET_NAME (rule, rule_buf[rule_pos]); - SET_P0 (rule, rule_buf[rule_pos]); - INCR_POS; - break; - case 'l': - case 'u': - case 'd': - case 'h': - case 'H': - case 's': - SET_NAME (rule, RULE_OP_MANGLE_PURGECHAR_CLASS); - SET_P0 (rule, rule_buf[rule_pos+1]); - INCR_POS; - break; - default : - return -1; - } - break; - } - SET_NAME (rule, rule_buf[rule_pos]); SET_P0 (rule, rule_buf[rule_pos]); break; @@ -514,6 +478,68 @@ int cpu_rule_to_kernel_rule (char *rule_buf, u32 rule_len, kernel_rule_t *rule) SET_P1 (rule, rule_buf[rule_pos]); break; + case RULE_OP_CLASS_BASED: // ~ + switch (rule_buf[rule_pos+1]) + { + case RULE_OP_MANGLE_REPLACE: // ~s?CY + SET_NAME (rule, RULE_OP_MANGLE_REPLACE_CLASS); + INCR_POS; + INCR_POS; + SET_P0 (rule, rule_buf[rule_pos]); + SET_P1 (rule, rule_buf[rule_pos]); + break; + case RULE_OP_MANGLE_PURGECHAR: // ~@?C + SET_NAME (rule, RULE_OP_MANGLE_PURGECHAR_CLASS); + INCR_POS; + INCR_POS; + SET_P0 (rule, rule_buf[rule_pos]); + break; + /* + case '!': // ~!?C + SET_NAME (rule, RULE_OP_REJECT_CONTAIN_CLASS); + INCR_POS; + INCR_POS; + SET_P0 (rule, rule_buf[rule_pos]); + break; + case '/': // ~/?C + SET_NAME (rule, RULE_OP_REJECT_NOT_CONTAIN_CLASS); + INCR_POS; + INCR_POS; + SET_P0 (rule, rule_buf[rule_pos]); + break; + case '(': // ~(?C + SET_NAME (rule, RULE_OP_REJECT_EQUAL_FIRST_CLASS); + INCR_POS; + INCR_POS; + SET_P0 (rule, rule_buf[rule_pos]); + break; + case '(': // ~)?C + SET_NAME (rule, RULE_OP_REJECT_EQUAL_LAST_CLASS); + INCR_POS; + INCR_POS; + SET_P0 (rule, rule_buf[rule_pos]); + break; + case '=': // ~=N?C + SET_NAME (rule, RULE_OP_REJECT_EQUAL_AT_CLASS); + INCR_POS; + SET_P0 (rule, rule_buf[rule_pos]); + INCR_POS; + SET_P1 (rule, rule_buf[rule_pos]); + break; + case '%': // ~%N?C + SET_NAME (rule, RULE_OP_REJECT_CONTAINS_CLASS); + INCR_POS; + SET_P0 (rule, rule_buf[rule_pos]); + INCR_POS; + SET_P1 (rule, rule_buf[rule_pos]); + break; + */ + default: + return -1; + } + + break; + default: return -1; } @@ -655,13 +681,6 @@ int kernel_rule_to_cpu_rule (char *rule_buf, kernel_rule_t *rule) case RULE_OP_MANGLE_PURGECHAR: rule_buf[rule_pos] = rule_cmd; GET_P0 (rule); - if (rule_buf[rule_pos] == '?') rule_buf[++rule_pos] = '?'; // force @?? - break; - - case RULE_OP_MANGLE_PURGECHAR_CLASS: - rule_buf[rule_pos++] = RULE_OP_MANGLE_PURGECHAR; - rule_buf[rule_pos] = '?'; - GET_P0 (rule); break; case RULE_OP_MANGLE_TOGGLECASE_REC: @@ -750,6 +769,21 @@ int kernel_rule_to_cpu_rule (char *rule_buf, kernel_rule_t *rule) GET_P1 (rule); break; + case RULE_OP_MANGLE_REPLACE_CLASS: + rule_buf[rule_pos++] = RULE_OP_CLASS_BASED; + rule_buf[rule_pos++] = RULE_OP_MANGLE_REPLACE; + rule_buf[rule_pos] = '?'; + GET_P0 (rule); + GET_P1 (rule); + break; + + case RULE_OP_MANGLE_PURGECHAR_CLASS: + rule_buf[rule_pos++] = RULE_OP_CLASS_BASED; + rule_buf[rule_pos++] = RULE_OP_MANGLE_PURGECHAR; + rule_buf[rule_pos] = '?'; + GET_P0 (rule); + break; + case 0: if (rule_pos == 0) return -1; return rule_pos - 1; diff --git a/src/rp_cpu.c b/src/rp_cpu.c index 05d54df3e..f11858e13 100644 --- a/src/rp_cpu.c +++ b/src/rp_cpu.c @@ -329,6 +329,102 @@ static int mangle_replace (char arr[RP_PASSWORD_SIZE], int arr_len, char oldc, c return (arr_len); } +static int mangle_replace_class_l (char arr[RP_PASSWORD_SIZE], int arr_len, char newc) +{ + int arr_pos; + + for (arr_pos = 0; arr_pos < arr_len; arr_pos++) + { + if (!class_lower (arr[arr_pos])) continue; + + arr[arr_pos] = newc; + } + + return (arr_len); +} + +static int mangle_replace_class_u (char arr[RP_PASSWORD_SIZE], int arr_len, char newc) +{ + int arr_pos; + + for (arr_pos = 0; arr_pos < arr_len; arr_pos++) + { + if (!class_upper (arr[arr_pos])) continue; + + arr[arr_pos] = newc; + } + + return (arr_len); +} + +static int mangle_replace_class_d (char arr[RP_PASSWORD_SIZE], int arr_len, char newc) +{ + int arr_pos; + + for (arr_pos = 0; arr_pos < arr_len; arr_pos++) + { + if (!class_num (arr[arr_pos])) continue; + + arr[arr_pos] = newc; + } + + return (arr_len); +} + +static int mangle_replace_class_lh (char arr[RP_PASSWORD_SIZE], int arr_len, char newc) +{ + int arr_pos; + + for (arr_pos = 0; arr_pos < arr_len; arr_pos++) + { + if (!class_lower_hex (arr[arr_pos])) continue; + + arr[arr_pos] = newc; + } + + return (arr_len); +} + +static int mangle_replace_class_uh (char arr[RP_PASSWORD_SIZE], int arr_len, char newc) +{ + int arr_pos; + + for (arr_pos = 0; arr_pos < arr_len; arr_pos++) + { + if (!class_upper_hex (arr[arr_pos])) continue; + + arr[arr_pos] = newc; + } + + return (arr_len); +} + +static int mangle_replace_class_s (char arr[RP_PASSWORD_SIZE], int arr_len, char newc) +{ + int arr_pos; + + for (arr_pos = 0; arr_pos < arr_len; arr_pos++) + { + if (!class_sym (arr[arr_pos])) continue; + + arr[arr_pos] = newc; + } + + return (arr_len); +} + +static int mangle_replace_class (char arr[RP_PASSWORD_SIZE], int arr_len, char oldc, char newc) +{ + if (oldc == 'l') return mangle_replace_class_l (arr, arr_len, newc); + else if (oldc == 'u') return mangle_replace_class_u (arr, arr_len, newc); + else if (oldc == 'd') return mangle_replace_class_d (arr, arr_len, newc); + else if (oldc == 'h') return mangle_replace_class_lh (arr, arr_len, newc); + else if (oldc == 'H') return mangle_replace_class_uh (arr, arr_len, newc); + else if (oldc == 's') return mangle_replace_class_s (arr, arr_len, newc); + + return (arr_len); +} + static int mangle_purgechar (char arr[RP_PASSWORD_SIZE], int arr_len, char c) { int arr_pos; @@ -630,6 +726,236 @@ static int mangle_title_sep (char arr[RP_PASSWORD_SIZE], int arr_len, char c) return (arr_len); } +static bool reject_contain_class_l (char arr[RP_PASSWORD_SIZE], int arr_len, int *pos_mem) +{ + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) + { + if (class_lower (arr[arr_pos])) + { + *pos_mem = arr_pos; + return true; + } + } + + return false; +} + +static bool reject_contain_class_u (char arr[RP_PASSWORD_SIZE], int arr_len, int *pos_mem) +{ + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) + { + if (class_upper (arr[arr_pos])) + { + *pos_mem = arr_pos; + return true; + } + } + + return false; +} + +static bool reject_contain_class_d (char arr[RP_PASSWORD_SIZE], int arr_len, int *pos_mem) +{ + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) + { + if (class_num (arr[arr_pos])) + { + *pos_mem = arr_pos; + return true; + } + } + + return false; +} + +static bool reject_contain_class_lh (char arr[RP_PASSWORD_SIZE], int arr_len, int *pos_mem) +{ + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) + { + if (class_lower_hex (arr[arr_pos])) + { + *pos_mem = arr_pos; + return true; + } + } + + return false; +} + +static bool reject_contain_class_uh (char arr[RP_PASSWORD_SIZE], int arr_len, int *pos_mem) +{ + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) + { + if (class_upper_hex (arr[arr_pos])) + { + *pos_mem = arr_pos; + return true; + } + } + + return false; +} + +static bool reject_contain_class_s (char arr[RP_PASSWORD_SIZE], int arr_len, int *pos_mem) +{ + for (int arr_pos = 0; arr_pos < arr_len; arr_pos++) + { + if (class_sym (arr[arr_pos])) + { + *pos_mem = arr_pos; + return true; + } + } + + return false; +} + +static bool reject_contain_class (char arr[RP_PASSWORD_SIZE], int arr_len, char c, int *pos_mem) +{ + if (c == 'l') return reject_contain_class_l (arr, arr_len, pos_mem); + else if (c == 'u') return reject_contain_class_u (arr, arr_len, pos_mem); + else if (c == 'd') return reject_contain_class_d (arr, arr_len, pos_mem); + else if (c == 'h') return reject_contain_class_lh (arr, arr_len, pos_mem); + else if (c == 'H') return reject_contain_class_uh (arr, arr_len, pos_mem); + else if (c == 's') return reject_contain_class_s (arr, arr_len, pos_mem); + + return false; +} + +static bool reject_contain (char arr[RP_PASSWORD_SIZE], char c, int *pos_mem) +{ + const char *match = strchr (arr, c); + if (match == NULL) return false; + + *pos_mem = (int)(match - arr); + + return true; +} + +static bool reject_contains_class_l (char arr[RP_PASSWORD_SIZE], int arr_len, int upos, int *pos_mem) +{ + int cnt = 0; + + for (int arr_pos = 0; arr_pos < arr_len && cnt < upos; arr_pos++) + { + if (class_lower (arr[arr_pos])) + { + cnt++; + *pos_mem = arr_pos; + } + } + + return (cnt < upos); +} + +static bool reject_contains_class_u (char arr[RP_PASSWORD_SIZE], int arr_len, int upos, int *pos_mem) +{ + int cnt = 0; + + for (int arr_pos = 0; arr_pos < arr_len && cnt < upos; arr_pos++) + { + if (class_upper (arr[arr_pos])) + { + cnt++; + *pos_mem = arr_pos; + } + } + + return (cnt < upos); +} + +static bool reject_contains_class_d (char arr[RP_PASSWORD_SIZE], int arr_len, int upos, int *pos_mem) +{ + int cnt = 0; + + for (int arr_pos = 0; arr_pos < arr_len && cnt < upos; arr_pos++) + { + if (class_num (arr[arr_pos])) + { + cnt++; + *pos_mem = arr_pos; + } + } + + return (cnt < upos); +} + +static bool reject_contains_class_lh (char arr[RP_PASSWORD_SIZE], int arr_len, int upos, int *pos_mem) +{ + int cnt = 0; + + for (int arr_pos = 0; arr_pos < arr_len && cnt < upos; arr_pos++) + { + if (class_lower_hex (arr[arr_pos])) + { + cnt++; + *pos_mem = arr_pos; + } + } + + return (cnt < upos); +} + +static bool reject_contains_class_uh (char arr[RP_PASSWORD_SIZE], int arr_len, int upos, int *pos_mem) +{ + int cnt = 0; + + for (int arr_pos = 0; arr_pos < arr_len && cnt < upos; arr_pos++) + { + if (class_upper_hex (arr[arr_pos])) + { + cnt++; + *pos_mem = arr_pos; + } + } + + return (cnt < upos); +} + +static bool reject_contains_class_s (char arr[RP_PASSWORD_SIZE], int arr_len, int upos, int *pos_mem) +{ + int cnt = 0; + + for (int arr_pos = 0; arr_pos < arr_len && cnt < upos; arr_pos++) + { + if (class_sym (arr[arr_pos])) + { + cnt++; + *pos_mem = arr_pos; + } + } + + return (cnt < upos); +} + +static bool reject_contains_class (char arr[RP_PASSWORD_SIZE], int arr_len, char c, int upos, int *pos_mem) +{ + if (c == 'l') return reject_contains_class_l (arr, arr_len, upos, pos_mem); + else if (c == 'u') return reject_contains_class_u (arr, arr_len, upos, pos_mem); + else if (c == 'd') return reject_contains_class_d (arr, arr_len, upos, pos_mem); + else if (c == 'h') return reject_contains_class_lh (arr, arr_len, upos, pos_mem); + else if (c == 'H') return reject_contains_class_uh (arr, arr_len, upos, pos_mem); + else if (c == 's') return reject_contains_class_s (arr, arr_len, upos, pos_mem); + + return false; +} + +static bool reject_contains (const char arr[RP_PASSWORD_SIZE], int arr_len, char c, int upos, int *pos_mem) +{ + int cnt = 0; + + for (int arr_pos = 0; arr_pos < arr_len && cnt < upos; arr_pos++) + { + if (arr[arr_pos] == c) + { + cnt++; + *pos_mem = arr_pos; + } + } + + return (cnt < upos); +} + int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], int in_len, char out[RP_PASSWORD_SIZE]) { char mem[RP_PASSWORD_SIZE] = { 0 }; @@ -819,33 +1145,6 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], case RULE_OP_MANGLE_PURGECHAR: NEXT_RULEPOS (rule_pos); - - if (rule_new[rule_pos] == '?') - { - if ((rule_pos + 1) == rule_len_new || ((rule_pos + 1) < rule_len_new && rule_new[rule_pos+1] == '\'')) - { - out_len = mangle_purgechar (out, out_len, rule_new[rule_pos]); - break; - } - - NEXT_RULEPOS (rule_pos); - - switch (rule_new[rule_pos]) - { - case ' ': out_len = mangle_purgechar (out, out_len, rule_new[rule_pos-1]); break; - case '?': out_len = mangle_purgechar (out, out_len, rule_new[rule_pos]); break; - case 'l': - case 'u': - case 'd': - case 'h': - case 'H': - case 's': out_len = mangle_purgechar_class (out, out_len, rule_new[rule_pos]); break; - default : HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); - } - - break; - } - out_len = mangle_purgechar (out, out_len, rule_new[rule_pos]); break; @@ -993,22 +1292,12 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], case RULE_OP_REJECT_CONTAIN: NEXT_RULEPOS (rule_pos); - if (strchr (out, rule_new[rule_pos]) != NULL) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + if (reject_contain (out, rule_new[rule_pos], &pos_mem)) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; case RULE_OP_REJECT_NOT_CONTAIN: NEXT_RULEPOS (rule_pos); - { - const char *match = strchr (out, rule_new[rule_pos]); - if (match != NULL) - { - pos_mem = (int)(match - out); - } - else - { - HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); - } - } + if (!reject_contain (out, rule_new[rule_pos], &pos_mem)) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; case RULE_OP_REJECT_EQUAL_FIRST: @@ -1034,23 +1323,248 @@ int _old_apply_rule (const char *rule, int rule_len, char in[RP_PASSWORD_SIZE], NEXT_RPTOI (rule_new, rule_pos, upos); if ((upos + 1) > out_len) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); NEXT_RULEPOS (rule_pos); - int c; int cnt; - for (c = 0, cnt = 0; c < out_len && cnt < upos; c++) - { - if (out[c] == rule_new[rule_pos]) - { - cnt++; - pos_mem = c; - } - } - - if (cnt < upos) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + if (reject_contains (out, out_len, rule_new[rule_pos], upos, &pos_mem)) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; case RULE_OP_REJECT_MEMORY: if ((out_len == mem_len) && (memcmp (out, mem, out_len) == 0)) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); break; + case RULE_OP_CLASS_BASED: + NEXT_RULEPOS (rule_pos); + switch (rule_new[rule_pos]) + { + case RULE_OP_MANGLE_REPLACE: // ~s?CY + NEXT_RULEPOS (rule_pos); + if (rule_new[rule_pos] != '?') HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + + NEXT_RULEPOS (rule_pos); + switch (rule_new[rule_pos]) + { + case '?': + NEXT_RULEPOS (rule_pos); + out_len = mangle_replace (out, out_len, rule_new[rule_pos - 1], rule_new[rule_pos]); + break; + case 'l': + case 'u': + case 'd': + case 'h': + case 'H': + case 's': + NEXT_RULEPOS (rule_pos); + out_len = mangle_replace_class (out, out_len, rule_new[rule_pos - 1], rule_new[rule_pos]); + break; + default : + HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + } + + break; + case RULE_OP_MANGLE_PURGECHAR: // ~@?C + NEXT_RULEPOS (rule_pos); + if (rule_new[rule_pos] != '?') HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + + NEXT_RULEPOS (rule_pos); + switch (rule_new[rule_pos]) + { + case '?': + out_len = mangle_purgechar (out, out_len, rule_new[rule_pos]); + break; + case 'l': + case 'u': + case 'd': + case 'h': + case 'H': + case 's': + out_len = mangle_purgechar_class (out, out_len, rule_new[rule_pos]); + break; + default : + HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + } + + break; + case RULE_OP_REJECT_CONTAIN: // ~!?C + NEXT_RULEPOS (rule_pos); + if (rule_new[rule_pos] != '?') HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + + NEXT_RULEPOS (rule_pos); + switch (rule_new[rule_pos]) + { + case '?': + if (reject_contain (out, rule_new[rule_pos], &pos_mem)) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'l': + case 'u': + case 'd': + case 'h': + case 'H': + case 's': + if (reject_contain_class (out, out_len, rule_new[rule_pos], &pos_mem)) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + default : + HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + } + + break; + case RULE_OP_REJECT_NOT_CONTAIN: // ~/?C + NEXT_RULEPOS (rule_pos); + if (rule_new[rule_pos] != '?') HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + + NEXT_RULEPOS (rule_pos); + switch (rule_new[rule_pos]) + { + case '?': + if (!reject_contain (out, rule_new[rule_pos], &pos_mem)) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'l': + case 'u': + case 'd': + case 'h': + case 'H': + case 's': + if (!reject_contain_class (out, out_len, rule_new[rule_pos], &pos_mem)) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + default : + HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + } + + break; + case RULE_OP_REJECT_EQUAL_FIRST: // ~(?C + NEXT_RULEPOS (rule_pos); + if (rule_new[rule_pos] != '?') HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + + NEXT_RULEPOS (rule_pos); + switch (rule_new[rule_pos]) + { + case '?': + if (out[0] != rule_new[rule_pos]) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'l': + if (!class_lower (out[0])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'u': + if (!class_upper (out[0])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'd': + if (!class_num (out[0])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'h': + if (!class_lower_hex (out[0])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'H': + if (!class_upper_hex (out[0])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 's': + if (!class_sym (out[0])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + default : + HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + } + + break; + case RULE_OP_REJECT_EQUAL_LAST: // ~)?C + NEXT_RULEPOS (rule_pos); + if (rule_new[rule_pos] != '?') HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + + NEXT_RULEPOS (rule_pos); + switch (rule_new[rule_pos]) + { + case '?': + if (out[out_len - 1] != rule_new[rule_pos]) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'l': + if (!class_lower (out[out_len - 1])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'u': + if (!class_upper (out[out_len - 1])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'd': + if (!class_num (out[out_len - 1])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'h': + if (!class_lower_hex (out[out_len - 1])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'H': + if (!class_upper_hex (out[out_len - 1])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 's': + if (!class_sym (out[out_len - 1])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + default : + HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + } + + break; + case RULE_OP_REJECT_EQUAL_AT: // ~=N?C + NEXT_RULEPOS (rule_pos); + NEXT_RPTOI (rule_new, rule_pos, upos); + if ((upos + 1) > out_len) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + + NEXT_RULEPOS (rule_pos); + if (rule_new[rule_pos] != '?') HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + + NEXT_RULEPOS (rule_pos); + switch (rule_new[rule_pos]) + { + case '?': + if (out[upos] != rule_new[rule_pos]) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'l': + if (!class_lower (out[upos])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'u': + if (!class_upper (out[upos])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'd': + if (!class_num (out[upos])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'h': + if (!class_lower_hex (out[upos])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'H': + if (!class_upper_hex (out[upos])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 's': + if (!class_sym (out[upos])) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + default : + HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + } + + break; + case RULE_OP_REJECT_CONTAINS: // ~%N?C + NEXT_RULEPOS (rule_pos); + NEXT_RPTOI (rule_new, rule_pos, upos); + if ((upos + 1) > out_len) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + + NEXT_RULEPOS (rule_pos); + if (rule_new[rule_pos] != '?') HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + + NEXT_RULEPOS (rule_pos); + switch (rule_new[rule_pos]) + { + case '?': + if (reject_contains (out, out_len, rule_new[rule_pos], upos, &pos_mem)) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + case 'l': + case 'u': + case 'd': + case 'h': + case 'H': + case 's': + if (reject_contains_class (out, out_len, rule_new[rule_pos], upos, &pos_mem)) HCFREE_AND_RETURN (RULE_RC_REJECT_ERROR); + break; + default : + HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + } + + break; + + default: + HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); + } + + break; + default: HCFREE_AND_RETURN (RULE_RC_SYNTAX_ERROR); }