From cb1fe251de1ef65df7244caa67344643402074dd Mon Sep 17 00:00:00 2001 From: jsteube Date: Fri, 11 Aug 2017 22:58:37 +0200 Subject: [PATCH] Add missing functions to pure kernel rule engine --- OpenCL/inc_rp.cl | 346 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 328 insertions(+), 18 deletions(-) diff --git a/OpenCL/inc_rp.cl b/OpenCL/inc_rp.cl index 798e61ab2..441f443bd 100644 --- a/OpenCL/inc_rp.cl +++ b/OpenCL/inc_rp.cl @@ -243,6 +243,294 @@ int mangle_extract (const u8 p0, const u8 p1, u8 *buf, const int len) return (p1); } +int mangle_omit (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + if (p0 >= len) return (len); + + if ((p0 + p1) > len) return (len); + + for (int pos = p0; pos < len - p1; pos++) + { + buf[pos] = buf[pos + p1]; + } + + for (int pos = len - p1; pos < len; pos++) + { + buf[pos] = 0; + } + + return (len - p1); +} + +int mangle_insert (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + if (p0 >= len + 1) return (len); + + const int out_len = len + 1; + + if (out_len >= RP_PASSWORD_SIZE) return (len); + + for (int pos = len - 1; pos > p0 - 1; pos--) + { + buf[pos + 1] = buf[pos]; + } + + buf[p0] = p1; + + return (out_len); +} + +int mangle_overstrike (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + if (p0 >= len) return (len); + + buf[p0] = p1; + + return (len); +} + +int mangle_truncate_at (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + if (p0 >= len) return (len); + + for (int pos = p0; pos < len; pos++) + { + buf[pos] = 0; + } + + return (p0); +} + +int mangle_replace (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + for (int pos = 0; pos < len; pos++) + { + if (buf[pos] != p0) continue; + + buf[pos] = p1; + } + + return (len); +} + +int mangle_purgechar (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + int out_len = 0; + + for (int pos = 0; pos < len; pos++) + { + if (buf[pos] == p0) continue; + + buf[out_len] = buf[pos]; + + out_len++; + } + + for (int pos = out_len; pos < len; pos++) + { + buf[pos] = 0; + } + + return (out_len); +} + +int mangle_dupechar_first (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + const int out_len = len + p0; + + if (out_len >= RP_PASSWORD_SIZE) return (len); + + const u8 c = buf[0]; + + for (int i = 0; i < p0; i++) + { + mangle_prepend (c, 0, buf, len + i); + } + + return (out_len); +} + +int mangle_dupechar_last (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + const int out_len = len + p0; + + if (out_len >= RP_PASSWORD_SIZE) return (len); + + const u8 c = buf[len - 1]; + + for (int i = 0; i < p0; i++) + { + mangle_append (c, 0, buf, len + i); + } + + return (out_len); +} + +int mangle_dupechar_all (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + const int out_len = len + len; + + if (out_len >= RP_PASSWORD_SIZE) return (len); + + for (int pos = len - 1; pos >= 0; pos--) + { + int new_pos = pos * 2; + + buf[new_pos] = buf[pos]; + + buf[new_pos + 1] = buf[pos]; + } + + return (out_len); +} + +int mangle_switch_first (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + if (len < 2) return (len); + + mangle_switch (buf, 0, 1); + + return (len); +} + +int mangle_switch_last (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + if (len < 2) return (len); + + mangle_switch (buf, len - 2, len - 1); + + return (len); +} + +int mangle_switch_at (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + if (p0 >= len) return (len); + if (p1 >= len) return (len); + + mangle_switch (buf, p0, p1); + + return (len); +} + +int mangle_chr_shiftl (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + if (p0 >= len) return (len); + + buf[p0] <<= 1; + + return (len); +} + +int mangle_chr_shiftr (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + if (p0 >= len) return (len); + + buf[p0] >>= 1; + + return (len); +} + +int mangle_chr_incr (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + if (p0 >= len) return (len); + + buf[p0]++; + + return (len); +} + +int mangle_chr_decr (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + if (p0 >= len) return (len); + + buf[p0]--; + + return (len); +} + +int mangle_replace_np1 (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + if ((p0 + 1) >= len) return (len); + + buf[p0] = buf[p0 + 1]; + + return (len); +} + +int mangle_replace_nm1 (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + if (p0 == 0) return (len); + + if (p0 >= len) return (len); + + buf[p0] = buf[p0 - 1]; + + return (len); +} + +int mangle_dupeblock_first (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + if (p0 >= len) return (len); + + const int out_len = len + p0; + + if (out_len >= RP_PASSWORD_SIZE) return (len); + + for (int i = 0; i < p0; i++) + { + const u8 c = buf[i * 2]; + + mangle_insert (i, c, buf, len + i); + } + + return (out_len); +} + +int mangle_dupeblock_last (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + if (p0 >= len) return (len); + + const int out_len = len + p0; + + if (out_len >= RP_PASSWORD_SIZE) return (len); + + for (int i = 0; i < p0; i++) + { + const u8 c = buf[len - p0 + i]; + + mangle_append (c, 0, buf, len + i); + } + + return (out_len); +} + +int mangle_title_sep (const u8 p0, const u8 p1, u8 *buf, const int len) +{ + int upper_next = 1; + + for (int pos = 0; pos < len; pos++) + { + if (buf[pos] == p0) + { + upper_next = 1; + + continue; + } + + if (upper_next) + { + upper_next = 0; + + upper_at (buf, pos); + } + else + { + lower_at (buf, pos); + } + } + + return (len); +} int apply_rule (const u32 name, const u8 p0, const u8 p1, u8 *buf, const int in_len) { @@ -250,24 +538,46 @@ int apply_rule (const u32 name, const u8 p0, const u8 p1, u8 *buf, const int in_ switch (name) { - case RULE_OP_MANGLE_LREST: out_len = mangle_lrest (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_LREST_UFIRST: out_len = mangle_lrest_ufirst (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_UREST: out_len = mangle_urest (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_UREST_LFIRST: out_len = mangle_urest_lfirst (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_TREST: out_len = mangle_trest (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_TOGGLE_AT: out_len = mangle_toggle_at (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_REVERSE: out_len = mangle_reverse (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_DUPEWORD: out_len = mangle_dupeword (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_DUPEWORD_TIMES: out_len = mangle_dupeword_times (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_REFLECT: out_len = mangle_reflect (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_APPEND: out_len = mangle_append (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_PREPEND: out_len = mangle_prepend (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_ROTATE_LEFT: out_len = mangle_rotate_left (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_ROTATE_RIGHT: out_len = mangle_rotate_right (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_DELETE_FIRST: out_len = mangle_delete_first (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_DELETE_LAST: out_len = mangle_delete_last (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_DELETE_AT: out_len = mangle_delete_at (p0, p1, buf, out_len); break; - case RULE_OP_MANGLE_EXTRACT: out_len = mangle_extract (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_LREST: out_len = mangle_lrest (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_LREST_UFIRST: out_len = mangle_lrest_ufirst (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_UREST: out_len = mangle_urest (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_UREST_LFIRST: out_len = mangle_urest_lfirst (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_TREST: out_len = mangle_trest (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_TOGGLE_AT: out_len = mangle_toggle_at (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_REVERSE: out_len = mangle_reverse (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_DUPEWORD: out_len = mangle_dupeword (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_DUPEWORD_TIMES: out_len = mangle_dupeword_times (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_REFLECT: out_len = mangle_reflect (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_APPEND: out_len = mangle_append (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_PREPEND: out_len = mangle_prepend (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_ROTATE_LEFT: out_len = mangle_rotate_left (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_ROTATE_RIGHT: out_len = mangle_rotate_right (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_DELETE_FIRST: out_len = mangle_delete_first (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_DELETE_LAST: out_len = mangle_delete_last (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_DELETE_AT: out_len = mangle_delete_at (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_EXTRACT: out_len = mangle_extract (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_OMIT: out_len = mangle_omit (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_INSERT: out_len = mangle_insert (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_OVERSTRIKE: out_len = mangle_overstrike (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_TRUNCATE_AT: out_len = mangle_truncate_at (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_REPLACE: out_len = mangle_replace (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_PURGECHAR: out_len = mangle_purgechar (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_DUPECHAR_FIRST: out_len = mangle_dupechar_first (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_DUPECHAR_LAST: out_len = mangle_dupechar_last (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_DUPECHAR_ALL: out_len = mangle_dupechar_all (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_SWITCH_FIRST: out_len = mangle_switch_first (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_SWITCH_LAST: out_len = mangle_switch_last (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_SWITCH_AT: out_len = mangle_switch_at (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_CHR_SHIFTL: out_len = mangle_chr_shiftl (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_CHR_SHIFTR: out_len = mangle_chr_shiftr (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_CHR_INCR: out_len = mangle_chr_incr (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_CHR_DECR: out_len = mangle_chr_decr (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_REPLACE_NP1: out_len = mangle_replace_np1 (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_REPLACE_NM1: out_len = mangle_replace_nm1 (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_DUPEBLOCK_FIRST: out_len = mangle_dupeblock_first (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_DUPEBLOCK_LAST: out_len = mangle_dupeblock_last (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_TITLE_SEP: out_len = mangle_title_sep (p0, p1, buf, out_len); break; + case RULE_OP_MANGLE_TITLE: out_len = mangle_title_sep (' ', p1, buf, out_len); break; } return out_len;