From 9b591c68d3b7df4657727e3e8e729e23ec2b98cc Mon Sep 17 00:00:00 2001 From: de4dot Date: Tue, 29 May 2012 19:14:41 +0200 Subject: [PATCH] Fix CF proxy calls --- de4dot.code/de4dot.code.csproj | 3 + .../CodeFort/CfMethodCallInliner.cs | 43 ++++++ .../deobfuscators/CodeFort/Deobfuscator.cs | 124 ++++++++++++++++++ .../deobfuscators/CodeFort/ProxyCallFixer.cs | 116 ++++++++++++++++ .../deobfuscators/Unknown/Deobfuscator.cs | 2 - de4dot.cui/Program.cs | 1 + 6 files changed, 287 insertions(+), 2 deletions(-) create mode 100644 de4dot.code/deobfuscators/CodeFort/CfMethodCallInliner.cs create mode 100644 de4dot.code/deobfuscators/CodeFort/Deobfuscator.cs create mode 100644 de4dot.code/deobfuscators/CodeFort/ProxyCallFixer.cs diff --git a/de4dot.code/de4dot.code.csproj b/de4dot.code/de4dot.code.csproj index 42ecf34c..bacb2128 100644 --- a/de4dot.code/de4dot.code.csproj +++ b/de4dot.code/de4dot.code.csproj @@ -92,6 +92,9 @@ + + + diff --git a/de4dot.code/deobfuscators/CodeFort/CfMethodCallInliner.cs b/de4dot.code/deobfuscators/CodeFort/CfMethodCallInliner.cs new file mode 100644 index 00000000..4d4ecbe2 --- /dev/null +++ b/de4dot.code/deobfuscators/CodeFort/CfMethodCallInliner.cs @@ -0,0 +1,43 @@ +/* + 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 Mono.Cecil; +using de4dot.blocks; +using de4dot.blocks.cflow; + +namespace de4dot.code.deobfuscators.CodeFort { + class CfMethodCallInliner : MethodCallInliner { + public CfMethodCallInliner() + : base(false) { + } + + protected override bool canInline(MethodDefinition method) { + if (method.GenericParameters.Count > 0) + return false; + if (method == blocks.Method) + return false; + + if (method.IsStatic) + return true; + if (method.IsVirtual) + return false; + return inlineInstanceMethods; + } + } +} diff --git a/de4dot.code/deobfuscators/CodeFort/Deobfuscator.cs b/de4dot.code/deobfuscators/CodeFort/Deobfuscator.cs new file mode 100644 index 00000000..db33f85e --- /dev/null +++ b/de4dot.code/deobfuscators/CodeFort/Deobfuscator.cs @@ -0,0 +1,124 @@ +/* + 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.PE; + +namespace de4dot.code.deobfuscators.CodeFort { + public class DeobfuscatorInfo : DeobfuscatorInfoBase { + public const string THE_NAME = "CodeFort"; + public const string THE_TYPE = "cf"; + const string DEFAULT_REGEX = @"!^[_<>{}$.`-]$&" + DeobfuscatorBase.DEFAULT_VALID_NAME_REGEX; + + public DeobfuscatorInfo() + : base(DEFAULT_REGEX) { + } + + 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