From 70bd973cddcf6e922fac2bd1815a304746edae67 Mon Sep 17 00:00:00 2001 From: de4dot Date: Thu, 26 Jul 2012 20:12:12 +0200 Subject: [PATCH] Decrypt Confuser 1.9 encrypted JIT methods --- de4dot.code/de4dot.code.csproj | 3 + .../deobfuscators/Confuser/ConstantsFolder.cs | 68 ++ .../deobfuscators/Confuser/Deobfuscator.cs | 141 ++++ .../Confuser/JitMethodsDecrypter.cs | 792 ++++++++++++++++++ .../deobfuscators/Unknown/Deobfuscator.cs | 13 - de4dot.cui/Program.cs | 1 + 6 files changed, 1005 insertions(+), 13 deletions(-) create mode 100644 de4dot.code/deobfuscators/Confuser/ConstantsFolder.cs create mode 100644 de4dot.code/deobfuscators/Confuser/Deobfuscator.cs create mode 100644 de4dot.code/deobfuscators/Confuser/JitMethodsDecrypter.cs diff --git a/de4dot.code/de4dot.code.csproj b/de4dot.code/de4dot.code.csproj index a3c92e77..7c654b91 100644 --- a/de4dot.code/de4dot.code.csproj +++ b/de4dot.code/de4dot.code.csproj @@ -67,6 +67,9 @@ + + + diff --git a/de4dot.code/deobfuscators/Confuser/ConstantsFolder.cs b/de4dot.code/deobfuscators/Confuser/ConstantsFolder.cs new file mode 100644 index 00000000..9cfc1f5a --- /dev/null +++ b/de4dot.code/deobfuscators/Confuser/ConstantsFolder.cs @@ -0,0 +1,68 @@ +/* + Copyright (C) 2011-2012 de4dot@gmail.com + + This file is part of de4dot. + + de4dot is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + de4dot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with de4dot. If not, see . +*/ + +using System.Collections.Generic; +using Mono.Cecil.Cil; +using de4dot.blocks; +using de4dot.blocks.cflow; + +namespace de4dot.code.deobfuscators.Confuser { + class ConstantsFolder : BlockDeobfuscator { + protected override bool deobfuscate(Block block) { + bool modified = false; + + var instrs = block.Instructions; + var constantsReader = createConstantsReader(instrs); + for (int i = 0; i < instrs.Count; i++) { + int index = 0; + Instruction newInstr = null; + var instr = instrs[i]; + if (constantsReader.isLoadConstant32(instr.Instruction)) { + index = i; + int val; + if (!constantsReader.getInt32(ref index, out val)) + continue; + newInstr = DotNetUtils.createLdci4(val); + } + else if (constantsReader.isLoadConstant64(instr.Instruction)) { + index = i; + long val; + if (!constantsReader.getInt64(ref index, out val)) + continue; + newInstr = Instruction.Create(OpCodes.Ldc_I8, val); + } + + if (newInstr == null || index - i <= 1) + continue; + + block.insert(index++, Instruction.Create(OpCodes.Pop)); + block.insert(index++, newInstr); + i = index - 1; + constantsReader = createConstantsReader(instrs); + modified = true; + } + + return modified; + } + + static ConstantsReader createConstantsReader(IList instrs) { + return new ConstantsReader(instrs, false); + } + } +} diff --git a/de4dot.code/deobfuscators/Confuser/Deobfuscator.cs b/de4dot.code/deobfuscators/Confuser/Deobfuscator.cs new file mode 100644 index 00000000..d5a6b926 --- /dev/null +++ b/de4dot.code/deobfuscators/Confuser/Deobfuscator.cs @@ -0,0 +1,141 @@ +/* + Copyright (C) 2011-2012 de4dot@gmail.com + + This file is part of de4dot. + + de4dot is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + de4dot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with de4dot. If not, see . +*/ + +using System; +using System.Collections.Generic; +using Mono.Cecil; +using Mono.MyStuff; +using de4dot.blocks; +using de4dot.blocks.cflow; +using de4dot.PE; + +namespace de4dot.code.deobfuscators.Confuser { + public class DeobfuscatorInfo : DeobfuscatorInfoBase { + public const string THE_NAME = "Confuser"; + public const string THE_TYPE = "cn"; + + public DeobfuscatorInfo() + : base() { + } + + public override string Name { + get { return THE_NAME; } + } + + public override string Type { + get { return THE_TYPE; } + } + + public override IDeobfuscator createDeobfuscator() { + return new Deobfuscator(new Deobfuscator.Options { + ValidNameRegex = validNameRegex.get(), + }); + } + + protected override IEnumerable