diff --git a/AssemblyData/methodsrewriter/MethodsRewriter.cs b/AssemblyData/methodsrewriter/MethodsRewriter.cs index 27e6c949..c1b3e317 100644 --- a/AssemblyData/methodsrewriter/MethodsRewriter.cs +++ b/AssemblyData/methodsrewriter/MethodsRewriter.cs @@ -330,9 +330,9 @@ namespace AssemblyData.methodsrewriter { } static List getParameters(MethodDefinition method) { - int count = method.Parameters.Count + (method.HasThis ? 1 : 0); + int count = method.Parameters.Count + (method.HasImplicitThis ? 1 : 0); var list = new List(count); - if (method.HasThis) + if (method.HasImplicitThis) list.Add(method.DeclaringType); foreach (var argType in method.Parameters) list.Add(argType.ParameterType); diff --git a/blocks/DotNetUtils.cs b/blocks/DotNetUtils.cs index ed18f9e0..bf181c9a 100644 --- a/blocks/DotNetUtils.cs +++ b/blocks/DotNetUtils.cs @@ -674,12 +674,13 @@ namespace de4dot.blocks { pops = 0; var method = (IMethodSignature)instr.Operand; + bool implicitThis = method.HasThis && !method.ExplicitThis; if (hasReturnValue(method) || (instr.OpCode.Code == Code.Newobj && method.HasThis)) pushes++; if (method.HasParameters) pops += method.Parameters.Count; - if (method.HasThis && instr.OpCode.Code != Code.Newobj) + if (implicitThis && instr.OpCode.Code != Code.Newobj) pops++; } @@ -824,20 +825,20 @@ namespace de4dot.blocks { } public static int getArgIndex(MethodReference method, ParameterDefinition arg) { - return getArgIndex(method.HasThis, arg); + return getArgIndex(method.HasImplicitThis, arg); } - public static int getArgIndex(bool hasThis, ParameterDefinition arg) { + public static int getArgIndex(bool implicitThis, ParameterDefinition arg) { if (arg == null) return -1; - if (hasThis) + if (implicitThis) return arg.Index + 1; return arg.Index; } public static List getParameters(MethodReference method) { var args = new List(method.Parameters.Count + 1); - if (method.HasThis) + if (method.HasImplicitThis) args.Add(new ParameterDefinition(method.DeclaringType)); foreach (var arg in method.Parameters) args.Add(arg); @@ -864,7 +865,7 @@ namespace de4dot.blocks { public static List getArgs(MethodReference method) { var args = new List(method.Parameters.Count + 1); - if (method.HasThis) + if (method.HasImplicitThis) args.Add(method.DeclaringType); foreach (var arg in method.Parameters) args.Add(arg.ParameterType); @@ -887,7 +888,7 @@ namespace de4dot.blocks { public static int getArgsCount(MethodReference method) { int count = method.Parameters.Count; - if (method.HasThis) + if (method.HasImplicitThis) count++; return count; } diff --git a/blocks/cflow/BlockCflowDeobfuscator.cs b/blocks/cflow/BlockCflowDeobfuscator.cs index 3569d860..909aff92 100644 --- a/blocks/cflow/BlockCflowDeobfuscator.cs +++ b/blocks/cflow/BlockCflowDeobfuscator.cs @@ -30,7 +30,7 @@ namespace de4dot.blocks.cflow { public void init(Blocks blocks, Block block) { this.blocks = blocks; this.block = block; - instructionEmulator.init(blocks.Method.HasThis, false, blocks.Method.Parameters, blocks.Locals); + instructionEmulator.init(blocks.Method.HasImplicitThis, false, blocks.Method.Parameters, blocks.Locals); } // Returns true if code was updated, false otherwise diff --git a/blocks/cflow/ConstantsFolder.cs b/blocks/cflow/ConstantsFolder.cs index df4b11a0..458c0fd2 100644 --- a/blocks/cflow/ConstantsFolder.cs +++ b/blocks/cflow/ConstantsFolder.cs @@ -39,7 +39,7 @@ namespace de4dot.blocks.cflow { public bool deobfuscate() { bool changed = false; foreach (var block in allBlocks) { - instructionEmulator.init(blocks.Method.HasThis, false, blocks.Method.Parameters, blocks.Locals); + instructionEmulator.init(blocks.Method.HasImplicitThis, false, blocks.Method.Parameters, blocks.Locals); var instrs = block.Instructions; for (int i = 0; i < instrs.Count; i++) { var instr = instrs[i]; diff --git a/blocks/cflow/InstructionEmulator.cs b/blocks/cflow/InstructionEmulator.cs index 42d5907d..b2f7cca0 100644 --- a/blocks/cflow/InstructionEmulator.cs +++ b/blocks/cflow/InstructionEmulator.cs @@ -34,18 +34,18 @@ namespace de4dot.blocks.cflow { public InstructionEmulator() { } - public InstructionEmulator(bool hasThis, bool initLocals, IList parameterDefinitions, IList variableDefinitions) { - init(hasThis, initLocals, parameterDefinitions, variableDefinitions); + public InstructionEmulator(bool implicitThis, bool initLocals, IList parameterDefinitions, IList variableDefinitions) { + init(implicitThis, initLocals, parameterDefinitions, variableDefinitions); } - public void init(bool hasThis, bool initLocals, IList parameterDefinitions, IList variableDefinitions) { + public void init(bool implicitThis, bool initLocals, IList parameterDefinitions, IList variableDefinitions) { this.parameterDefinitions = parameterDefinitions; this.variableDefinitions = variableDefinitions; valueStack.init(); args.Clear(); argBase = 0; - if (hasThis) { + if (implicitThis) { argBase = 1; args.Add(new UnknownValue()); } diff --git a/blocks/cflow/SwitchCflowDeobfuscator.cs b/blocks/cflow/SwitchCflowDeobfuscator.cs index 5b3a3157..ac2c029a 100644 --- a/blocks/cflow/SwitchCflowDeobfuscator.cs +++ b/blocks/cflow/SwitchCflowDeobfuscator.cs @@ -125,7 +125,7 @@ namespace de4dot.blocks.cflow { foreach (var source in new List(block.Sources)) { if (!isBranchBlock(source)) continue; - instructionEmulator.init(blocks.Method.HasThis, false, blocks.Method.Parameters, blocks.Locals); + instructionEmulator.init(blocks.Method.HasImplicitThis, false, blocks.Method.Parameters, blocks.Locals); instructionEmulator.emulate(source.Instructions); var target = getSwitchTarget(switchTargets, switchFallThrough, source, instructionEmulator.pop()); @@ -151,7 +151,7 @@ namespace de4dot.blocks.cflow { foreach (var source in new List(block.Sources)) { if (!isBranchBlock(source)) continue; - instructionEmulator.init(blocks.Method.HasThis, false, blocks.Method.Parameters, blocks.Locals); + instructionEmulator.init(blocks.Method.HasImplicitThis, false, blocks.Method.Parameters, blocks.Locals); instructionEmulator.emulate(source.Instructions); var target = getSwitchTarget(switchTargets, switchFallThrough, source, instructionEmulator.getLocal(switchVariable)); @@ -174,7 +174,7 @@ namespace de4dot.blocks.cflow { foreach (var source in new List(block.Sources)) { if (!isBranchBlock(source)) continue; - instructionEmulator.init(blocks.Method.HasThis, false, blocks.Method.Parameters, blocks.Locals); + instructionEmulator.init(blocks.Method.HasImplicitThis, false, blocks.Method.Parameters, blocks.Locals); instructionEmulator.emulate(source.Instructions); var target = getSwitchTarget(switchTargets, switchFallThrough, source, instructionEmulator.pop()); @@ -245,7 +245,7 @@ namespace de4dot.blocks.cflow { } bool emulateGetTarget(Block switchBlock, out Block target) { - instructionEmulator.init(blocks.Method.HasThis, false, blocks.Method.Parameters, blocks.Locals); + instructionEmulator.init(blocks.Method.HasImplicitThis, false, blocks.Method.Parameters, blocks.Locals); try { instructionEmulator.emulate(switchBlock.Instructions, 0, switchBlock.Instructions.Count - 1); } @@ -259,7 +259,7 @@ namespace de4dot.blocks.cflow { } bool willHaveKnownTarget(Block switchBlock, Block source) { - instructionEmulator.init(blocks.Method.HasThis, false, blocks.Method.Parameters, blocks.Locals); + instructionEmulator.init(blocks.Method.HasImplicitThis, false, blocks.Method.Parameters, blocks.Locals); try { instructionEmulator.emulate(source.Instructions); instructionEmulator.emulate(switchBlock.Instructions, 0, switchBlock.Instructions.Count - 1); diff --git a/de4dot.code/deobfuscators/ArrayFinder.cs b/de4dot.code/deobfuscators/ArrayFinder.cs index 349501a8..935df559 100644 --- a/de4dot.code/deobfuscators/ArrayFinder.cs +++ b/de4dot.code/deobfuscators/ArrayFinder.cs @@ -113,7 +113,7 @@ namespace de4dot.code.deobfuscators { public static Value[] getInitializedArray(int arraySize, MethodDefinition method, ref int newarrIndex, Code stelemOpCode) { var resultValueArray = new Value[arraySize]; - var emulator = new InstructionEmulator(method.HasThis, false, method.Parameters, method.Body.Variables); + var emulator = new InstructionEmulator(method.HasImplicitThis, false, method.Parameters, method.Body.Variables); var theArray = new UnknownValue(); emulator.push(theArray);