Fix m 60 a 0 by making modified variable non-const
[hashcat.git] / src / rp_kernel_on_cpu.c
index 3cc869c..8c8a7ec 100644 (file)
@@ -21,7 +21,7 @@ static u32 generate_cmask (u32 buf)
 
 static void truncate_right (u32 w0[4], u32 w1[4], const u32 len)
 {
-  const u32 tmp = (1 << ((len % 4) * 8)) - 1;
+  const u32 tmp = (1u << ((len % 4) * 8)) - 1;
 
   switch (len / 4)
   {
@@ -74,7 +74,7 @@ static void truncate_right (u32 w0[4], u32 w1[4], const u32 len)
 
 static void truncate_left (u32 w0[4], u32 w1[4], const u32 len)
 {
-  const u32 tmp = ~((1 << ((len % 4) * 8)) - 1);
+  const u32 tmp = ~((1u << ((len % 4) * 8)) - 1);
 
   switch (len / 4)
   {
@@ -1322,7 +1322,7 @@ static u32 rule_op_mangle_delete_last (const u32 p0, const u32 p1, u32 buf0[4],
 
   const u32 in_len1 = in_len - 1;
 
-  const u32 tmp = (1 << ((in_len1 & 3) * 8)) - 1;
+  const u32 tmp = (1u << ((in_len1 & 3) * 8)) - 1;
 
   switch (in_len1 / 4)
   {
@@ -1350,7 +1350,7 @@ static u32 rule_op_mangle_delete_at (const u32 p0, const u32 p1, u32 buf0[4], u3
 
   lshift_block (buf0, buf1, tib40, tib41);
 
-  const u32 ml = (1 << ((p0 & 3) * 8)) - 1;
+  const u32 ml = (1u << ((p0 & 3) * 8)) - 1;
   const u32 mr = ~ml;
 
   switch (p0 / 4)
@@ -1451,7 +1451,7 @@ static u32 rule_op_mangle_omit (const u32 p0, const u32 p1, u32 buf0[4], u32 buf
 
   lshift_block_N (buf0, buf1, tib40, tib41, p1);
 
-  const u32 ml = (1 << ((p0 & 3) * 8)) - 1;
+  const u32 ml = (1u << ((p0 & 3) * 8)) - 1;
   const u32 mr = ~ml;
 
   switch (p0 / 4)
@@ -1530,7 +1530,7 @@ static u32 rule_op_mangle_insert (const u32 p0, const u32 p1, u32 buf0[4], u32 b
 
   const u32 p1n = p1 << ((p0 & 3) * 8);
 
-  const u32 ml = (1 << ((p0 & 3) * 8)) - 1;
+  const u32 ml = (1u << ((p0 & 3) * 8)) - 1;
 
   const u32 mr = 0xffffff00 << ((p0 & 3) * 8);
 
@@ -1663,13 +1663,48 @@ static u32 rule_op_mangle_replace (const u32 p0, const u32 p1, u32 buf0[4], u32
   return 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 u32 rule_op_mangle_togglecase_rec (const u32 p0, const u32 p1, u32 buf0[4], u32 buf1[4], const u32 in_len)
 {
   // TODO
@@ -2638,7 +2673,7 @@ u32 apply_rule (const u32 name, const u32 p0, const u32 p1, u32 buf0[4], u32 buf
     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;