From e32531e6255bb58fba24422d25a5105330d2b906 Mon Sep 17 00:00:00 2001 From: Luan Devecchi Date: Fri, 1 Jun 2018 08:58:50 -0300 Subject: [PATCH] Counter public tools Counter ConfuserEx Constants decryptor by CodeCracker and ConfuserEx Static decryptor by Cawk --- .../Constants/ReferenceReplacer.cs | 2 + Confuser.Runtime/Constant.cs | 54 +++++++++++-------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/Confuser.Protections/Constants/ReferenceReplacer.cs b/Confuser.Protections/Constants/ReferenceReplacer.cs index ed37dd9..c9271e6 100644 --- a/Confuser.Protections/Constants/ReferenceReplacer.cs +++ b/Confuser.Protections/Constants/ReferenceReplacer.cs @@ -25,6 +25,8 @@ namespace Confuser.Protections.Constants { instr.Item1.OpCode = OpCodes.Ldc_I4; instr.Item1.Operand = (int)instr.Item2; method.Body.Instructions.Insert(i + 1, Instruction.Create(OpCodes.Call, instr.Item3)); + Instruction instr1 = method.Body.Instructions[i + 1]; + method.Body.Instructions.Insert(i + 1, Instruction.Create(OpCodes.Br_S, instr1)); } } diff --git a/Confuser.Runtime/Constant.cs b/Confuser.Runtime/Constant.cs index 510a110..b175551 100644 --- a/Confuser.Runtime/Constant.cs +++ b/Confuser.Runtime/Constant.cs @@ -1,5 +1,6 @@ using System; using System.Text; +using System.Reflection; namespace Confuser.Runtime { internal static class Constant { @@ -40,31 +41,38 @@ namespace Confuser.Runtime { } static T Get(uint id) { - id = (uint)Mutation.Placeholder((int)id); - uint t = id >> 30; + if (Assembly.GetExecutingAssembly() == Assembly.GetCallingAssembly()) + { + id = (uint)Mutation.Placeholder((int)id); + uint t = id >> 30; - T ret = default(T); - id &= 0x3fffffff; - id <<= 2; + T ret = default(T); + id &= 0x3fffffff; + id <<= 2; - if (t == Mutation.KeyI0) { - int l = b[id++] | (b[id++] << 8) | (b[id++] << 16) | (b[id++] << 24); - ret = (T)(object)string.Intern(Encoding.UTF8.GetString(b, (int)id, l)); - } - // NOTE: Assume little-endian - else if (t == Mutation.KeyI1) { - var v = new T[1]; - Buffer.BlockCopy(b, (int)id, v, 0, Mutation.Value()); - ret = v[0]; - } - else if (t == Mutation.KeyI2) { - int s = b[id++] | (b[id++] << 8) | (b[id++] << 16) | (b[id++] << 24); - int l = b[id++] | (b[id++] << 8) | (b[id++] << 16) | (b[id++] << 24); - Array v = Array.CreateInstance(typeof(T).GetElementType(), l); - Buffer.BlockCopy(b, (int)id, v, 0, s - 4); - ret = (T)(object)v; - } - return ret; + if (t == Mutation.KeyI0) + { + int l = b[id++] | (b[id++] << 8) | (b[id++] << 16) | (b[id++] << 24); + ret = (T)(object)string.Intern(Encoding.UTF8.GetString(b, (int)id, l)); + } + // NOTE: Assume little-endian + else if (t == Mutation.KeyI1) + { + var v = new T[1]; + Buffer.BlockCopy(b, (int)id, v, 0, Mutation.Value()); + ret = v[0]; + } + else if (t == Mutation.KeyI2) + { + int s = b[id++] | (b[id++] << 8) | (b[id++] << 16) | (b[id++] << 24); + int l = b[id++] | (b[id++] << 8) | (b[id++] << 16) | (b[id++] << 24); + Array v = Array.CreateInstance(typeof(T).GetElementType(), l); + Buffer.BlockCopy(b, (int)id, v, 0, s - 4); + ret = (T)(object)v; + } + return ret; + } + return default(T); } }