Remove the methods types
This commit is contained in:
parent
9a87a2658f
commit
e67ecfdff4
|
@ -148,7 +148,6 @@
|
|||
<Compile Include="deobfuscators\Skater_NET\StringDecrypter.cs" />
|
||||
<Compile Include="deobfuscators\Spices_Net\Deobfuscator.cs" />
|
||||
<Compile Include="deobfuscators\Spices_Net\QclzDecompressor.cs" />
|
||||
<Compile Include="deobfuscators\Spices_Net\SpicesInlinedMethodsFinder.cs" />
|
||||
<Compile Include="deobfuscators\Spices_Net\SpicesMethodCallInliner.cs" />
|
||||
<Compile Include="deobfuscators\Spices_Net\StringDecrypter.cs" />
|
||||
<Compile Include="deobfuscators\StringCounts.cs" />
|
||||
|
|
|
@ -648,7 +648,7 @@ namespace de4dot.code.deobfuscators {
|
|||
addMethodsToBeRemoved(new UnusedMethodsFinder(module, inlinedMethods, getRemovedMethods()).find(), "Inlined method");
|
||||
}
|
||||
|
||||
MethodCollection getRemovedMethods() {
|
||||
protected MethodCollection getRemovedMethods() {
|
||||
var removedMethods = new MethodCollection();
|
||||
removedMethods.add(getMethodsToRemove());
|
||||
removedMethods.addAndNested(getTypesToRemove());
|
||||
|
|
|
@ -167,7 +167,15 @@ namespace de4dot.code.deobfuscators.Spices_Net {
|
|||
void removeInlinedMethods() {
|
||||
if (!options.InlineMethods || !options.RemoveInlinedMethods)
|
||||
return;
|
||||
removeInlinedMethods(new SpicesInlinedMethodsFinder(module, methodCallInliner).find());
|
||||
|
||||
var unusedMethods = new UnusedMethodsFinder(module, methodCallInliner.getInlinedMethods(), getRemovedMethods()).find();
|
||||
var removedTypes = methodCallInliner.getInlinedTypes(unusedMethods);
|
||||
|
||||
addTypesToBeRemoved(removedTypes.getKeys(), "Obfuscator methods type");
|
||||
foreach (var method in unusedMethods) {
|
||||
if (!removedTypes.find(method.DeclaringType))
|
||||
addMethodToBeRemoved(method, "Inlined method");
|
||||
}
|
||||
}
|
||||
|
||||
public override IEnumerable<string> getStringDecrypterMethods() {
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Mono.Cecil;
|
||||
|
||||
namespace de4dot.code.deobfuscators.Spices_Net {
|
||||
class SpicesInlinedMethodsFinder {
|
||||
ModuleDefinition module;
|
||||
SpicesMethodCallInliner methodCallInliner;
|
||||
|
||||
public SpicesInlinedMethodsFinder(ModuleDefinition module, SpicesMethodCallInliner methodCallInliner) {
|
||||
this.module = module;
|
||||
this.methodCallInliner = methodCallInliner;
|
||||
}
|
||||
|
||||
public List<MethodDefinition> find() {
|
||||
var inlinedMethods = new List<MethodDefinition>();
|
||||
|
||||
foreach (var type in module.GetTypes()) {
|
||||
if (!type.IsNested)
|
||||
continue;
|
||||
foreach (var method in type.Methods) {
|
||||
if (methodCallInliner.checkCanInline(method))
|
||||
inlinedMethods.Add(method);
|
||||
}
|
||||
}
|
||||
|
||||
return inlinedMethods;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@
|
|||
along with de4dot. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
using Mono.Cecil.Metadata;
|
||||
|
@ -140,5 +141,35 @@ namespace de4dot.code.deobfuscators.Spices_Net {
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<MethodDefinition> getInlinedMethods() {
|
||||
var list = new List<MethodDefinition>();
|
||||
|
||||
foreach (var type in validTypes.getKeys())
|
||||
list.AddRange(type.Methods);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public TypeDefinitionDict<bool> getInlinedTypes(IEnumerable<MethodDefinition> unusedMethods) {
|
||||
var unused = new MethodDefinitionAndDeclaringTypeDict<bool>();
|
||||
foreach (var method in unusedMethods)
|
||||
unused.add(method, true);
|
||||
|
||||
var types = new TypeDefinitionDict<bool>();
|
||||
foreach (var type in validTypes.getKeys()) {
|
||||
if (checkAllMethodsUnused(unused, type))
|
||||
types.add(type, true);
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
static bool checkAllMethodsUnused(MethodDefinitionAndDeclaringTypeDict<bool> unused, TypeDefinition type) {
|
||||
foreach (var method in type.Methods) {
|
||||
if (!unused.find(method))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user