Fix m 60 a 0 by making modified variable non-const
[hashcat.git] / src / rp_kernel_on_cpu.c
index 3fdf4b8..8c8a7ec 100644 (file)
@@ -4,26 +4,24 @@
  */
 
 #pragma GCC diagnostic ignored "-Wunused-parameter"
-#pragma GCC diagnostic ignored "-Wunused-variable"
-#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
 #pragma GCC diagnostic ignored "-Wunused-function"
 
 #include <rp_kernel_on_cpu.h>
 
-static uint32_t generate_cmask (uint32_t buf)
+static u32 generate_cmask (u32 buf)
 {
-  const uint32_t rmask =  ((buf & 0x40404040) >> 1)
-                       & ~((buf & 0x80808080) >> 2);
+  const u32 rmask =  ((buf & 0x40404040) >> 1)
+                  & ~((buf & 0x80808080) >> 2);
 
-  const uint32_t hmask = (buf & 0x1f1f1f1f) + 0x05050505;
-  const uint32_t lmask = (buf & 0x1f1f1f1f) + 0x1f1f1f1f;
+  const u32 hmask = (buf & 0x1f1f1f1f) + 0x05050505;
+  const u32 lmask = (buf & 0x1f1f1f1f) + 0x1f1f1f1f;
 
   return rmask & ~hmask & lmask;
 }
 
-static void truncate_right (uint32_t w0[4], uint32_t w1[4], const uint len)
+static void truncate_right (u32 w0[4], u32 w1[4], const u32 len)
 {
-  const uint tmp = (1 << ((len % 4) * 8)) - 1;
+  const u32 tmp = (1u << ((len % 4) * 8)) - 1;
 
   switch (len / 4)
   {
@@ -74,9 +72,9 @@ static void truncate_right (uint32_t w0[4], uint32_t w1[4], const uint len)
   }
 }
 
-static void truncate_left (uint32_t w0[4], uint32_t w1[4], const uint len)
+static void truncate_left (u32 w0[4], u32 w1[4], const u32 len)
 {
-  const uint tmp = ~((1 << ((len % 4) * 8)) - 1);
+  const u32 tmp = ~((1u << ((len % 4) * 8)) - 1);
 
   switch (len / 4)
   {
@@ -127,7 +125,7 @@ static void truncate_left (uint32_t w0[4], uint32_t w1[4], const uint len)
   }
 }
 
-static void lshift_block (const uint32_t in0[4], const uint32_t in1[4], uint32_t out0[4], uint32_t out1[4])
+static void lshift_block (const u32 in0[4], const u32 in1[4], u32 out0[4], u32 out1[4])
 {
   out0[0] = in0[0] >>  8 | in0[1] << 24;
   out0[1] = in0[1] >>  8 | in0[2] << 24;
@@ -139,7 +137,7 @@ static void lshift_block (const uint32_t in0[4], const uint32_t in1[4], uint32_t
   out1[3] = in1[3] >>  8;
 }
 
-static void rshift_block (const uint32_t in0[4], const uint32_t in1[4], uint32_t out0[4], uint32_t out1[4])
+static void rshift_block (const u32 in0[4], const u32 in1[4], u32 out0[4], u32 out1[4])
 {
   out1[3] = in1[3] <<  8 | in1[2] >> 24;
   out1[2] = in1[2] <<  8 | in1[1] >> 24;
@@ -151,7 +149,7 @@ static void rshift_block (const uint32_t in0[4], const uint32_t in1[4], uint32_t
   out0[0] = in0[0] <<  8;
 }
 
-static void rshift_block_N (const uint32_t in0[4], const uint32_t in1[4], uint32_t out0[4], uint32_t out1[4], const uint num)
+static void rshift_block_N (const u32 in0[4], const u32 in1[4], u32 out0[4], u32 out1[4], const u32 num)
 {
   switch (num)
   {
@@ -446,7 +444,7 @@ static void rshift_block_N (const uint32_t in0[4], const uint32_t in1[4], uint32
   }
 }
 
-static void lshift_block_N (const uint32_t in0[4], const uint32_t in1[4], uint32_t out0[4], uint32_t out1[4], const uint num)
+static void lshift_block_N (const u32 in0[4], const u32 in1[4], u32 out0[4], u32 out1[4], const u32 num)
 {
   switch (num)
   {
@@ -742,9 +740,9 @@ static void lshift_block_N (const uint32_t in0[4], const uint32_t in1[4], uint32
   }
 }
 
-static void append_block1 (const uint offset, uint32_t dst0[4], uint32_t dst1[4], const uint32_t src_r0)
+static void append_block1 (const u32 offset, u32 dst0[4], u32 dst1[4], const u32 src_r0)
 {
-  uint32_t tmp[2];
+  u32 tmp[2] = { 0 };
 
   switch (offset & 3)
   {
@@ -790,7 +788,7 @@ static void append_block1 (const uint offset, uint32_t dst0[4], uint32_t dst1[4]
   }
 }
 
-static void append_block8 (const uint offset, uint32_t dst0[4], uint32_t dst1[4], const uint32_t src_l0[4], const uint32_t src_l1[4], const uint32_t src_r0[4], const uint32_t src_r1[4])
+static void append_block8 (const u32 offset, u32 dst0[4], u32 dst1[4], const u32 src_l0[4], const u32 src_l1[4], const u32 src_r0[4], const u32 src_r1[4])
 {
   switch (offset)
   {
@@ -1036,12 +1034,12 @@ static void append_block8 (const uint offset, uint32_t dst0[4], uint32_t dst1[4]
   }
 }
 
-static void reverse_block (uint32_t in0[4], uint32_t in1[4], uint32_t out0[4], uint32_t out1[4], const uint len)
+static void reverse_block (u32 in0[4], u32 in1[4], u32 out0[4], u32 out1[4], const u32 len)
 {
   rshift_block_N (in0, in1, out0, out1, 32 - len);
 
-  uint32_t tib40[4];
-  uint32_t tib41[4];
+  u32 tib40[4];
+  u32 tib41[4];
 
   tib40[0] = out1[3];
   tib40[1] = out1[2];
@@ -1062,7 +1060,7 @@ static void reverse_block (uint32_t in0[4], uint32_t in1[4], uint32_t out0[4], u
   out1[3] = swap_workaround (tib41[3]);
 }
 
-static uint rule_op_mangle_lrest (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_lrest (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   buf0[0] |= (generate_cmask (buf0[0]));
   buf0[1] |= (generate_cmask (buf0[1]));
@@ -1076,7 +1074,7 @@ static uint rule_op_mangle_lrest (const uint p0, const uint p1, uint32_t buf0[4]
   return in_len;
 }
 
-static uint rule_op_mangle_urest (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_urest (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   buf0[0] &= ~(generate_cmask (buf0[0]));
   buf0[1] &= ~(generate_cmask (buf0[1]));
@@ -1090,7 +1088,7 @@ static uint rule_op_mangle_urest (const uint p0, const uint p1, uint32_t buf0[4]
   return in_len;
 }
 
-static uint rule_op_mangle_lrest_ufirst (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_lrest_ufirst (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   rule_op_mangle_lrest (p0, p1, buf0, buf1, in_len);
 
@@ -1099,7 +1097,7 @@ static uint rule_op_mangle_lrest_ufirst (const uint p0, const uint p1, uint32_t
   return in_len;
 }
 
-static uint rule_op_mangle_urest_lfirst (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_urest_lfirst (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   rule_op_mangle_urest (p0, p1, buf0, buf1, in_len);
 
@@ -1108,7 +1106,7 @@ static uint rule_op_mangle_urest_lfirst (const uint p0, const uint p1, uint32_t
   return in_len;
 }
 
-static uint rule_op_mangle_trest (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_trest (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   buf0[0] ^= (generate_cmask (buf0[0]));
   buf0[1] ^= (generate_cmask (buf0[1]));
@@ -1122,11 +1120,11 @@ static uint rule_op_mangle_trest (const uint p0, const uint p1, uint32_t buf0[4]
   return in_len;
 }
 
-static uint rule_op_mangle_toggle_at (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_toggle_at (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (p0 >= in_len) return (in_len);
 
-  const uint tmp = 0x20u << ((p0 & 3) * 8);
+  const u32 tmp = 0x20u << ((p0 & 3) * 8);
 
   switch (p0 / 4)
   {
@@ -1143,21 +1141,21 @@ static uint rule_op_mangle_toggle_at (const uint p0, const uint p1, uint32_t buf
   return in_len;
 }
 
-static uint rule_op_mangle_reverse (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_reverse (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   reverse_block (buf0, buf1, buf0, buf1, in_len);
 
   return in_len;
 }
 
-static uint rule_op_mangle_dupeword (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_dupeword (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if ((in_len + in_len) >= 32) return (in_len);
 
-  uint out_len = in_len;
+  u32 out_len = in_len;
 
-  uint32_t tib40[4];
-  uint32_t tib41[4];
+  u32 tib40[4];
+  u32 tib41[4];
 
   tib40[0] = buf0[0];
   tib40[1] = buf0[1];
@@ -1175,14 +1173,14 @@ static uint rule_op_mangle_dupeword (const uint p0, const uint p1, uint32_t buf0
   return out_len;
 }
 
-static uint rule_op_mangle_dupeword_times (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_dupeword_times (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (((in_len * p0) + in_len) >= 32) return (in_len);
 
-  uint out_len = in_len;
+  u32 out_len = in_len;
 
-  uint32_t tib40[4];
-  uint32_t tib41[4];
+  u32 tib40[4];
+  u32 tib41[4];
 
   tib40[0] = buf0[0];
   tib40[1] = buf0[1];
@@ -1193,7 +1191,7 @@ static uint rule_op_mangle_dupeword_times (const uint p0, const uint p1, uint32_
   tib41[2] = buf1[2];
   tib41[3] = buf1[3];
 
-  for (uint i = 0; i < p0; i++)
+  for (u32 i = 0; i < p0; i++)
   {
     append_block8 (out_len, buf0, buf1, buf0, buf1, tib40, tib41);
 
@@ -1203,14 +1201,14 @@ static uint rule_op_mangle_dupeword_times (const uint p0, const uint p1, uint32_
   return out_len;
 }
 
-static uint rule_op_mangle_reflect (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_reflect (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if ((in_len + in_len) >= 32) return (in_len);
 
-  uint out_len = in_len;
+  u32 out_len = in_len;
 
-  uint32_t tib40[4];
-  uint32_t tib41[4];
+  u32 tib40[4];
+  u32 tib41[4];
 
   reverse_block (buf0, buf1, tib40, tib41, out_len);
 
@@ -1221,11 +1219,11 @@ static uint rule_op_mangle_reflect (const uint p0, const uint p1, uint32_t buf0[
   return out_len;
 }
 
-static uint rule_op_mangle_append (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_append (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if ((in_len + 1) >= 32) return (in_len);
 
-  uint out_len = in_len;
+  u32 out_len = in_len;
 
   append_block1 (out_len, buf0, buf1, p0);
 
@@ -1234,11 +1232,11 @@ static uint rule_op_mangle_append (const uint p0, const uint p1, uint32_t buf0[4
   return out_len;
 }
 
-static uint rule_op_mangle_prepend (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_prepend (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if ((in_len + 1) >= 32) return (in_len);
 
-  uint out_len = in_len;
+  u32 out_len = in_len;
 
   rshift_block (buf0, buf1, buf0, buf1);
 
@@ -1249,15 +1247,15 @@ static uint rule_op_mangle_prepend (const uint p0, const uint p1, uint32_t buf0[
   return out_len;
 }
 
-static uint rule_op_mangle_rotate_left (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_rotate_left (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (in_len == 0) return (in_len);
 
-  const uint in_len1 = in_len - 1;
+  const u32 in_len1 = in_len - 1;
 
-  const uint sh = (in_len1 & 3) * 8;
+  const u32 sh = (in_len1 & 3) * 8;
 
-  const uint32_t tmp = (buf0[0] & 0xff) << sh;
+  const u32 tmp = (buf0[0] & 0xff) << sh;
 
   lshift_block (buf0, buf1, buf0, buf1);
 
@@ -1276,15 +1274,15 @@ static uint rule_op_mangle_rotate_left (const uint p0, const uint p1, uint32_t b
   return in_len;
 }
 
-static uint rule_op_mangle_rotate_right (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_rotate_right (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (in_len == 0) return (in_len);
 
-  const uint in_len1 = in_len - 1;
+  const u32 in_len1 = in_len - 1;
 
-  const uint sh = (in_len1 & 3) * 8;
+  const u32 sh = (in_len1 & 3) * 8;
 
-  uint32_t tmp = 0;
+  u32 tmp = 0;
 
   switch (in_len1 / 4)
   {
@@ -1307,24 +1305,24 @@ static uint rule_op_mangle_rotate_right (const uint p0, const uint p1, uint32_t
   return in_len;
 }
 
-static uint rule_op_mangle_delete_first (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_delete_first (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (in_len == 0) return (in_len);
 
-  const uint in_len1 = in_len - 1;
+  const u32 in_len1 = in_len - 1;
 
   lshift_block (buf0, buf1, buf0, buf1);
 
   return in_len1;
 }
 
-static uint rule_op_mangle_delete_last (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_delete_last (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (in_len == 0) return (in_len);
 
-  const uint in_len1 = in_len - 1;
+  const u32 in_len1 = in_len - 1;
 
-  const uint tmp = (1 << ((in_len1 & 3) * 8)) - 1;
+  const u32 tmp = (1u << ((in_len1 & 3) * 8)) - 1;
 
   switch (in_len1 / 4)
   {
@@ -1341,19 +1339,19 @@ static uint rule_op_mangle_delete_last (const uint p0, const uint p1, uint32_t b
   return in_len1;
 }
 
-static uint rule_op_mangle_delete_at (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_delete_at (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (p0 >= in_len) return (in_len);
 
-  uint out_len = in_len;
+  u32 out_len = in_len;
 
-  uint32_t tib40[4];
-  uint32_t tib41[4];
+  u32 tib40[4];
+  u32 tib41[4];
 
   lshift_block (buf0, buf1, tib40, tib41);
 
-  const uint ml = (1 << ((p0 & 3) * 8)) - 1;
-  const uint mr = ~ml;
+  const u32 ml = (1u << ((p0 & 3) * 8)) - 1;
+  const u32 mr = ~ml;
 
   switch (p0 / 4)
   {
@@ -1416,13 +1414,13 @@ static uint rule_op_mangle_delete_at (const uint p0, const uint p1, uint32_t buf
   return out_len;
 }
 
-static uint rule_op_mangle_extract (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_extract (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (p0 >= in_len) return (in_len);
 
   if ((p0 + p1) > in_len) return (in_len);
 
-  uint out_len = p1;
+  u32 out_len = p1;
 
   lshift_block_N (buf0, buf1, buf0, buf1, p0);
 
@@ -1431,16 +1429,16 @@ static uint rule_op_mangle_extract (const uint p0, const uint p1, uint32_t buf0[
   return out_len;
 }
 
-static uint rule_op_mangle_omit (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_omit (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (p0 >= in_len) return (in_len);
 
   if ((p0 + p1) > in_len) return (in_len);
 
-  uint out_len = in_len;
+  u32 out_len = in_len;
 
-  uint32_t tib40[4];
-  uint32_t tib41[4];
+  u32 tib40[4];
+  u32 tib41[4];
 
   tib40[0] = 0;
   tib40[1] = 0;
@@ -1453,8 +1451,8 @@ static uint rule_op_mangle_omit (const uint p0, const uint p1, uint32_t buf0[4],
 
   lshift_block_N (buf0, buf1, tib40, tib41, p1);
 
-  const uint ml = (1 << ((p0 & 3) * 8)) - 1;
-  const uint mr = ~ml;
+  const u32 ml = (1u << ((p0 & 3) * 8)) - 1;
+  const u32 mr = ~ml;
 
   switch (p0 / 4)
   {
@@ -1517,24 +1515,24 @@ static uint rule_op_mangle_omit (const uint p0, const uint p1, uint32_t buf0[4],
   return out_len;
 }
 
-static uint rule_op_mangle_insert (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_insert (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (p0 > in_len) return (in_len);
 
   if ((in_len + 1) >= 32) return (in_len);
 
-  uint out_len = in_len;
+  u32 out_len = in_len;
 
-  uint32_t tib40[4];
-  uint32_t tib41[4];
+  u32 tib40[4];
+  u32 tib41[4];
 
   rshift_block (buf0, buf1, tib40, tib41);
 
-  const uint p1n = p1 << ((p0 & 3) * 8);
+  const u32 p1n = p1 << ((p0 & 3) * 8);
 
-  const uint ml = (1 << ((p0 & 3) * 8)) - 1;
+  const u32 ml = (1u << ((p0 & 3) * 8)) - 1;
 
-  const uint mr = 0xffffff00 << ((p0 & 3) * 8);
+  const u32 mr = 0xffffff00 << ((p0 & 3) * 8);
 
   switch (p0 / 4)
   {
@@ -1589,13 +1587,13 @@ static uint rule_op_mangle_insert (const uint p0, const uint p1, uint32_t buf0[4
   return out_len;
 }
 
-static uint rule_op_mangle_overstrike (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_overstrike (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (p0 >= in_len) return (in_len);
 
-  const uint p1n = p1 << ((p0 & 3) * 8);
+  const u32 p1n = p1 << ((p0 & 3) * 8);
 
-  const uint m = ~(0xffu << ((p0 & 3) * 8));
+  const u32 m = ~(0xffu << ((p0 & 3) * 8));
 
   switch (p0 / 4)
   {
@@ -1612,7 +1610,7 @@ static uint rule_op_mangle_overstrike (const uint p0, const uint p1, uint32_t bu
   return in_len;
 }
 
-static uint rule_op_mangle_truncate_at (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_truncate_at (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (p0 >= in_len) return (in_len);
 
@@ -1621,9 +1619,9 @@ static uint rule_op_mangle_truncate_at (const uint p0, const uint p1, uint32_t b
   return p0;
 }
 
-static uint rule_op_mangle_replace (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_replace (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
-  for (uint i = 0; i < in_len; i++)
+  for (u32 i = 0; i < in_len; i++)
   {
     switch (i)
     {
@@ -1665,26 +1663,63 @@ static uint rule_op_mangle_replace (const uint p0, const uint p1, uint32_t buf0[
   return in_len;
 }
 
-static uint rule_op_mangle_purgechar (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_purgechar (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
-  // TODO
-  return in_len;
+  u32 out_len = 0;
+
+  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];
+
+  u32 buf_out[8] = { 0 };
+
+  u8 *in  = (u8 *) buf_in;
+  u8 *out = (u8 *) buf_out;
+
+  for (u32 pos = 0; pos < in_len; pos++)
+  {
+    if (in[pos] == (u8) p0) continue;
+
+    out[out_len] = in[pos];
+
+    out_len++;
+  }
+
+  buf0[0] = buf_out[0];
+  buf0[1] = buf_out[1];
+  buf0[2] = buf_out[2];
+  buf0[3] = buf_out[3];
+  buf1[0] = buf_out[4];
+  buf1[1] = buf_out[5];
+  buf1[2] = buf_out[6];
+  buf1[3] = buf_out[7];
+
+  return out_len;
 }
 
-static uint rule_op_mangle_togglecase_rec (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+/*
+static u32 rule_op_mangle_togglecase_rec (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   // TODO
   return in_len;
 }
+*/
 
-static uint rule_op_mangle_dupechar_first (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_dupechar_first (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if ( in_len       ==  0) return (in_len);
   if ((in_len + p0) >= 32) return (in_len);
 
-  uint out_len = in_len;
+  u32 out_len = in_len;
 
-  const uint32_t tmp = buf0[0] & 0xFF;
+  const u32 tmp = buf0[0] & 0xFF;
 
   rshift_block_N (buf0, buf1, buf0, buf1, p0);
 
@@ -1864,16 +1899,16 @@ static uint rule_op_mangle_dupechar_first (const uint p0, const uint p1, uint32_
   return out_len;
 }
 
-static uint rule_op_mangle_dupechar_last (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_dupechar_last (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if ( in_len       ==  0) return (in_len);
   if ((in_len + p0) >= 32) return (in_len);
 
-  const uint in_len1 = in_len - 1;
+  const u32 in_len1 = in_len - 1;
 
-  const uint sh = (in_len1 & 3) * 8;
+  const u32 sh = (in_len1 & 3) * 8;
 
-  uint32_t tmp = 0;
+  u32 tmp = 0;
 
   switch (in_len1 / 4)
   {
@@ -1887,9 +1922,9 @@ static uint rule_op_mangle_dupechar_last (const uint p0, const uint p1, uint32_t
     case  7:  tmp = (buf1[3] >> sh) & 0xff; break;
   }
 
-  uint out_len = in_len;
+  u32 out_len = in_len;
 
-  for (uint i = 0; i < p0; i++)
+  for (u32 i = 0; i < p0; i++)
   {
     append_block1 (out_len, buf0, buf1, tmp);
 
@@ -1899,15 +1934,15 @@ static uint rule_op_mangle_dupechar_last (const uint p0, const uint p1, uint32_t
   return out_len;
 }
 
-static uint rule_op_mangle_dupechar_all (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_dupechar_all (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if ( in_len           ==  0) return (in_len);
   if ((in_len + in_len) >= 32) return (in_len);
 
-  uint out_len = in_len;
+  u32 out_len = in_len;
 
-  uint32_t tib40[4];
-  uint32_t tib41[4];
+  u32 tib40[4];
+  u32 tib41[4];
 
   tib40[0] = ((buf0[0] & 0x000000FF) <<  0) | ((buf0[0] & 0x0000FF00) <<  8);
   tib40[1] = ((buf0[0] & 0x00FF0000) >> 16) | ((buf0[0] & 0xFF000000) >>  8);
@@ -1932,7 +1967,7 @@ static uint rule_op_mangle_dupechar_all (const uint p0, const uint p1, uint32_t
   return out_len;
 }
 
-static uint rule_op_mangle_switch_first (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_switch_first (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (in_len < 2) return (in_len);
 
@@ -1941,7 +1976,7 @@ static uint rule_op_mangle_switch_first (const uint p0, const uint p1, uint32_t
   return in_len;
 }
 
-static uint rule_op_mangle_switch_last (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_switch_last (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (in_len < 2) return (in_len);
 
@@ -2026,13 +2061,13 @@ static uint rule_op_mangle_switch_last (const uint p0, const uint p1, uint32_t b
   return in_len;
 }
 
-static uint rule_op_mangle_switch_at (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_switch_at (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (p0 >= in_len) return (in_len);
   if (p1 >= in_len) return (in_len);
 
-  uint32_t tmp0 = 0;
-  uint32_t tmp1 = 0;
+  u32 tmp0 = 0;
+  u32 tmp1 = 0;
 
   switch (p0)
   {
@@ -2273,12 +2308,12 @@ static uint rule_op_mangle_switch_at (const uint p0, const uint p1, uint32_t buf
   return in_len;
 }
 
-static uint rule_op_mangle_chr_shiftl (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_chr_shiftl (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (p0 >= in_len) return (in_len);
 
-  const uint mr = 0xffu << ((p0 & 3) * 8);
-  const uint ml = ~mr;
+  const u32 mr = 0xffu << ((p0 & 3) * 8);
+  const u32 ml = ~mr;
 
   switch (p0 / 4)
   {
@@ -2295,12 +2330,12 @@ static uint rule_op_mangle_chr_shiftl (const uint p0, const uint p1, uint32_t bu
   return in_len;
 }
 
-static uint rule_op_mangle_chr_shiftr (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_chr_shiftr (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (p0 >= in_len) return (in_len);
 
-  const uint mr = 0xffu << ((p0 & 3) * 8);
-  const uint ml = ~mr;
+  const u32 mr = 0xffu << ((p0 & 3) * 8);
+  const u32 ml = ~mr;
 
   switch (p0 / 4)
   {
@@ -2317,14 +2352,14 @@ static uint rule_op_mangle_chr_shiftr (const uint p0, const uint p1, uint32_t bu
   return in_len;
 }
 
-static uint rule_op_mangle_chr_incr (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_chr_incr (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (p0 >= in_len) return (in_len);
 
-  const uint mr = 0xffu << ((p0 & 3) * 8);
-  const uint ml = ~mr;
+  const u32 mr = 0xffu << ((p0 & 3) * 8);
+  const u32 ml = ~mr;
 
-  const uint n = 0x01010101 & mr;
+  const u32 n = 0x01010101 & mr;
 
   switch (p0 / 4)
   {
@@ -2341,14 +2376,14 @@ static uint rule_op_mangle_chr_incr (const uint p0, const uint p1, uint32_t buf0
   return in_len;
 }
 
-static uint rule_op_mangle_chr_decr (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_chr_decr (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (p0 >= in_len) return (in_len);
 
-  const uint mr = 0xffu << ((p0 & 3) * 8);
-  const uint ml = ~mr;
+  const u32 mr = 0xffu << ((p0 & 3) * 8);
+  const u32 ml = ~mr;
 
-  const uint n = 0x01010101 & mr;
+  const u32 n = 0x01010101 & mr;
 
   switch (p0 / 4)
   {
@@ -2365,17 +2400,17 @@ static uint rule_op_mangle_chr_decr (const uint p0, const uint p1, uint32_t buf0
   return in_len;
 }
 
-static uint rule_op_mangle_replace_np1 (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_replace_np1 (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if ((p0 + 1) >= in_len) return (in_len);
 
-  uint32_t tib40[4];
-  uint32_t tib41[4];
+  u32 tib40[4];
+  u32 tib41[4];
 
   lshift_block (buf0, buf1, tib40, tib41);
 
-  const uint mr = 0xffu << ((p0 & 3) * 8);
-  const uint ml = ~mr;
+  const u32 mr = 0xffu << ((p0 & 3) * 8);
+  const u32 ml = ~mr;
 
   switch (p0 / 4)
   {
@@ -2392,19 +2427,19 @@ static uint rule_op_mangle_replace_np1 (const uint p0, const uint p1, uint32_t b
   return in_len;
 }
 
-static uint rule_op_mangle_replace_nm1 (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_replace_nm1 (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (p0 == 0) return (in_len);
 
   if (p0 >= in_len) return (in_len);
 
-  uint32_t tib40[4];
-  uint32_t tib41[4];
+  u32 tib40[4];
+  u32 tib41[4];
 
   rshift_block (buf0, buf1, tib40, tib41);
 
-  const uint mr = 0xffu << ((p0 & 3) * 8);
-  const uint ml = ~mr;
+  const u32 mr = 0xffu << ((p0 & 3) * 8);
+  const u32 ml = ~mr;
 
   switch (p0 / 4)
   {
@@ -2421,16 +2456,16 @@ static uint rule_op_mangle_replace_nm1 (const uint p0, const uint p1, uint32_t b
   return in_len;
 }
 
-static uint rule_op_mangle_dupeblock_first (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_dupeblock_first (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (p0 > in_len) return (in_len);
 
   if ((in_len + p0) >= 32) return (in_len);
 
-  uint out_len = in_len;
+  u32 out_len = in_len;
 
-  uint32_t tib40[4];
-  uint32_t tib41[4];
+  u32 tib40[4];
+  u32 tib41[4];
 
   tib40[0] = buf0[0];
   tib40[1] = buf0[1];
@@ -2459,16 +2494,16 @@ static uint rule_op_mangle_dupeblock_first (const uint p0, const uint p1, uint32
   return out_len;
 }
 
-static uint rule_op_mangle_dupeblock_last (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_dupeblock_last (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   if (p0 > in_len) return (in_len);
 
   if ((in_len + p0) >= 32) return (in_len);
 
-  uint out_len = in_len;
+  u32 out_len = in_len;
 
-  uint32_t tib40[4];
-  uint32_t tib41[4];
+  u32 tib40[4];
+  u32 tib41[4];
 
   rshift_block_N (buf0, buf1, tib40, tib41, p0);
 
@@ -2488,7 +2523,7 @@ static uint rule_op_mangle_dupeblock_last (const uint p0, const uint p1, uint32_
   return out_len;
 }
 
-static uint rule_op_mangle_title (const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+static u32 rule_op_mangle_title (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   buf0[0] |= (generate_cmask (buf0[0]));
   buf0[1] |= (generate_cmask (buf0[1]));
@@ -2501,10 +2536,10 @@ static uint rule_op_mangle_title (const uint p0, const uint p1, uint32_t buf0[4]
 
   buf0[0] &= ~(0x00000020 & generate_cmask (buf0[0]));
 
-  for (uint i = 0; i < in_len; i++)
+  for (u32 i = 0; i < in_len; i++)
   {
-    uint32_t tmp0 = 0;
-    uint32_t tmp1 = 0;
+    u32 tmp0 = 0;
+    u32 tmp1 = 0;
 
     switch (i)
     {
@@ -2609,9 +2644,9 @@ static uint rule_op_mangle_title (const uint p0, const uint p1, uint32_t buf0[4]
   return in_len;
 }
 
-uint apply_rule (const uint name, const uint p0, const uint p1, uint32_t buf0[4], uint32_t buf1[4], const uint in_len)
+u32 apply_rule (const u32 name, const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
-  uint out_len = in_len;
+  u32 out_len = in_len;
 
   switch (name)
   {
@@ -2638,7 +2673,7 @@ uint apply_rule (const uint name, const uint p0, const uint p1, uint32_t buf0[4]
     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_PURGECHAR:        out_len = rule_op_mangle_purgechar        (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_TOGGLECASE_REC:   out_len = rule_op_mangle_togglecase_rec   (p0, p1, buf0, buf1, out_len); break;
     case RULE_OP_MANGLE_DUPECHAR_FIRST:   out_len = rule_op_mangle_dupechar_first   (p0, p1, buf0, buf1, out_len); break;
     case RULE_OP_MANGLE_DUPECHAR_LAST:    out_len = rule_op_mangle_dupechar_last    (p0, p1, buf0, buf1, out_len); break;
@@ -2660,15 +2695,17 @@ uint apply_rule (const uint name, const uint p0, const uint p1, uint32_t buf0[4]
   return out_len;
 }
 
-uint apply_rules (uint *cmds, uint32_t buf0[4], uint32_t buf1[4], const uint len)
+u32 apply_rules (u32 *cmds, u32 buf0[4], u32 buf1[4], const u32 len)
 {
-  uint out_len = len;
+  u32 out_len = len;
 
-  for (; *cmds; cmds++)
+  for (u32 i = 0; cmds[i] != 0; i++)
   {
-    const uint name = (*cmds >>  0) & 0xff;
-    const uint p0   = (*cmds >>  8) & 0xff;
-    const uint p1   = (*cmds >> 16) & 0xff;
+    const u32 cmd = cmds[i];
+
+    const u32 name = (cmd >>  0) & 0xff;
+    const u32 p0   = (cmd >>  8) & 0xff;
+    const u32 p1   = (cmd >> 16) & 0xff;
 
     out_len = apply_rule (name, p0, p1, buf0, buf1, out_len);
   }