Skip to content

Commit

Permalink
Merge pull request #1 from LuanDevecchi/master
Browse files Browse the repository at this point in the history
Counter public tools - by LuanDevecchi
  • Loading branch information
XenocodeRCE authored Jun 1, 2018
2 parents 4d083f5 + e32531e commit 029aea2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
2 changes: 2 additions & 0 deletions Confuser.Protections/Constants/ReferenceReplacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ static void ReplaceNormal(MethodDef method, List<Tuple<Instruction, uint, IMetho
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));
}
}

Expand Down
54 changes: 31 additions & 23 deletions Confuser.Runtime/Constant.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Text;
using System.Reflection;

namespace Confuser.Runtime {
internal static class Constant {
Expand Down Expand Up @@ -40,31 +41,38 @@ static void Initialize() {
}

static T Get<T>(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<int>());
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<int>());
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);
}
}

Expand Down

0 comments on commit 029aea2

Please sign in to comment.