From e2ec6548edccdc73b9af68ac8be4ae7ff857219b Mon Sep 17 00:00:00 2001 From: de4dot Date: Wed, 25 Jul 2012 20:43:22 +0200 Subject: [PATCH] Add more ctors and add EmulateConvInstructions prop --- de4dot.code/deobfuscators/ConstantsReader.cs | 41 ++++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/de4dot.code/deobfuscators/ConstantsReader.cs b/de4dot.code/deobfuscators/ConstantsReader.cs index 2a0fcd62..32adf7d3 100644 --- a/de4dot.code/deobfuscators/ConstantsReader.cs +++ b/de4dot.code/deobfuscators/ConstantsReader.cs @@ -28,6 +28,7 @@ namespace de4dot.code.deobfuscators { protected IInstructions instructions; protected IList locals; protected Dictionary localsValues = new Dictionary(); + bool emulateConvInstrs; public interface IInstructions { int Count { get; } @@ -66,12 +67,34 @@ namespace de4dot.code.deobfuscators { } } - public ConstantsReader(IList instrs) { - this.instructions = new ListInstructions(instrs); + public bool EmulateConvInstructions { + get { return emulateConvInstrs; } + set { emulateConvInstrs = value; } } - public ConstantsReader(IList instrs) { - this.instructions = new ListInstrs(instrs); + ConstantsReader(IInstructions instructions) + : this(instructions, true) { + } + + ConstantsReader(IInstructions instructions, bool emulateConvInstrs) { + this.instructions = instructions; + this.emulateConvInstrs = emulateConvInstrs; + } + + public ConstantsReader(IList instrs) + : this(new ListInstructions(instrs)) { + } + + public ConstantsReader(IList instrs, bool emulateConvInstrs) + : this(new ListInstructions(instrs), emulateConvInstrs) { + } + + public ConstantsReader(IList instrs) + : this(new ListInstrs(instrs)) { + } + + public ConstantsReader(IList instrs, bool emulateConvInstrs) + : this(new ListInstrs(instrs), emulateConvInstrs) { } public ConstantsReader(MethodDefinition method) @@ -144,31 +167,33 @@ namespace de4dot.code.deobfuscators { var instr = instructions[index]; switch (instr.OpCode.Code) { case Code.Conv_I1: - if (stack.Count < 1) + if (!emulateConvInstrs || stack.Count < 1) goto done; stack.Push(new ConstantInfo(index, (sbyte)stack.Pop().constant)); break; case Code.Conv_U1: - if (stack.Count < 1) + if (!emulateConvInstrs || stack.Count < 1) goto done; stack.Push(new ConstantInfo(index, (byte)stack.Pop().constant)); break; case Code.Conv_I2: - if (stack.Count < 1) + if (!emulateConvInstrs || stack.Count < 1) goto done; stack.Push(new ConstantInfo(index, (short)stack.Pop().constant)); break; case Code.Conv_U2: - if (stack.Count < 1) + if (!emulateConvInstrs || stack.Count < 1) goto done; stack.Push(new ConstantInfo(index, (ushort)stack.Pop().constant)); break; case Code.Conv_I4: case Code.Conv_U4: + if (!emulateConvInstrs) + goto done; stack.Push(new ConstantInfo(index, stack.Pop().constant)); break;