From c3c1ab64d8617d9255cab83a341c29d9971eb64d Mon Sep 17 00:00:00 2001 From: de4dot Date: Sun, 29 Jul 2012 13:19:12 +0200 Subject: [PATCH 1/2] Add setDeobfuscator() method --- de4dot.code/ObfuscatedFile.cs | 4 ++++ de4dot.code/deobfuscators/IDeobfuscatedFile.cs | 1 + 2 files changed, 5 insertions(+) diff --git a/de4dot.code/ObfuscatedFile.cs b/de4dot.code/ObfuscatedFile.cs index 33352d89..182eb7a5 100644 --- a/de4dot.code/ObfuscatedFile.cs +++ b/de4dot.code/ObfuscatedFile.cs @@ -771,5 +771,9 @@ namespace de4dot.code { void IDeobfuscatedFile.stringDecryptersAdded() { updateDynamicStringInliner(); } + + void IDeobfuscatedFile.setDeobfuscator(IDeobfuscator deob) { + this.deob = deob; + } } } diff --git a/de4dot.code/deobfuscators/IDeobfuscatedFile.cs b/de4dot.code/deobfuscators/IDeobfuscatedFile.cs index 61a14197..19bf303c 100644 --- a/de4dot.code/deobfuscators/IDeobfuscatedFile.cs +++ b/de4dot.code/deobfuscators/IDeobfuscatedFile.cs @@ -22,5 +22,6 @@ namespace de4dot.code.deobfuscators { IDeobfuscatorContext DeobfuscatorContext { get; } void createAssemblyFile(byte[] data, string assemblyName, string extension); void stringDecryptersAdded(); + void setDeobfuscator(IDeobfuscator deob); } } From c924d84340d506f1474aacd0625f8b1241d01212 Mon Sep 17 00:00:00 2001 From: de4dot Date: Sun, 29 Jul 2012 13:20:35 +0200 Subject: [PATCH 2/2] Add another decrypt() method --- de4dot.code/MethodReturnValueInliner.cs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/de4dot.code/MethodReturnValueInliner.cs b/de4dot.code/MethodReturnValueInliner.cs index 79283943..ace9f23e 100644 --- a/de4dot.code/MethodReturnValueInliner.cs +++ b/de4dot.code/MethodReturnValueInliner.cs @@ -144,7 +144,7 @@ namespace de4dot.code { abstract class MethodReturnValueInliner { protected List callResults; List allBlocks; - Blocks blocks; + MethodDefinition theMethod; VariableValues variableValues; int errors = 0; bool useUnknownArgs = false; @@ -178,7 +178,7 @@ namespace de4dot.code { public abstract bool HasHandlers { get; } protected MethodDefinition Method { - get { return blocks.Method; } + get { return theMethod; } } protected abstract void inlineAllCalls(); @@ -186,13 +186,19 @@ namespace de4dot.code { // Returns null if method is not a method we should inline protected abstract CallResult createCallResult(MethodReference method, GenericInstanceMethod gim, Block block, int callInstrIndex); - public int decrypt(Blocks theBlocks) { + public int decrypt(Blocks blocks) { + if (!HasHandlers) + return 0; + return decrypt(blocks.Method, blocks.MethodBlocks.getAllBlocks()); + } + + public int decrypt(MethodDefinition method, List allBlocks) { if (!HasHandlers) return 0; try { - blocks = theBlocks; + theMethod = method; callResults = new List(); - allBlocks = blocks.MethodBlocks.getAllBlocks(); + this.allBlocks = allBlocks; findAllCallResults(); inlineAllCalls(); @@ -200,16 +206,16 @@ namespace de4dot.code { return callResults.Count; } finally { - blocks = null; + theMethod = null; callResults = null; - allBlocks = null; + this.allBlocks = null; variableValues = null; } } bool getLocalVariableValue(VariableDefinition variable, out object value) { if (variableValues == null) - variableValues = new VariableValues(blocks.Locals, allBlocks); + variableValues = new VariableValues(theMethod.Body.Variables, allBlocks); var val = variableValues.getValue(variable); if (!val.isValid()) { value = null; @@ -333,7 +339,7 @@ namespace de4dot.code { case Code.Ldloc_1: case Code.Ldloc_2: case Code.Ldloc_3: - getLocalVariableValue(Instr.getLocalVar(blocks.Locals, instr), out arg); + getLocalVariableValue(Instr.getLocalVar(theMethod.Body.Variables, instr), out arg); break; case Code.Ldfld: