Move method to base class
This commit is contained in:
parent
0d92b37536
commit
15b4cefe89
|
@ -589,5 +589,57 @@ namespace de4dot.code.deobfuscators {
|
|||
var inlinedMethods = InlinedMethodsFinder.find(module);
|
||||
addMethodsToBeRemoved(new UnusedMethodsFinder(module, inlinedMethods).find(), "Inlined method");
|
||||
}
|
||||
|
||||
protected bool isTypeCalled(TypeDefinition decrypterType) {
|
||||
if (decrypterType == null)
|
||||
return false;
|
||||
|
||||
var decrypterMethods = new Dictionary<MethodReferenceAndDeclaringTypeKey, bool>();
|
||||
foreach (var type in TypeDefinition.GetTypes(new List<TypeDefinition> { decrypterType }))
|
||||
addMethods(type, decrypterMethods);
|
||||
|
||||
var removedMethods = new Dictionary<MethodReferenceAndDeclaringTypeKey, bool>();
|
||||
foreach (var method in getMethodsToRemove())
|
||||
removedMethods[new MethodReferenceAndDeclaringTypeKey(method)] = true;
|
||||
foreach (var type in TypeDefinition.GetTypes(getTypesToRemove()))
|
||||
addMethods(type, removedMethods);
|
||||
|
||||
foreach (var type in module.GetTypes()) {
|
||||
foreach (var method in type.Methods) {
|
||||
if (method.Body == null)
|
||||
continue;
|
||||
var key = new MethodReferenceAndDeclaringTypeKey(method);
|
||||
if (decrypterMethods.ContainsKey(key))
|
||||
break; // decrypter type / nested type method
|
||||
if (removedMethods.ContainsKey(key))
|
||||
continue;
|
||||
|
||||
foreach (var instr in method.Body.Instructions) {
|
||||
switch (instr.OpCode.Code) {
|
||||
case Code.Call:
|
||||
case Code.Callvirt:
|
||||
case Code.Newobj:
|
||||
var calledMethod = instr.Operand as MethodReference;
|
||||
if (calledMethod == null)
|
||||
break;
|
||||
key = new MethodReferenceAndDeclaringTypeKey(calledMethod);
|
||||
if (decrypterMethods.ContainsKey(key))
|
||||
return true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void addMethods(TypeDefinition type, Dictionary<MethodReferenceAndDeclaringTypeKey, bool> methods) {
|
||||
foreach (var method in type.Methods)
|
||||
methods[new MethodReferenceAndDeclaringTypeKey(method)] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -581,7 +581,7 @@ namespace de4dot.code.deobfuscators.dotNET_Reactor4 {
|
|||
new TypesRestorer(module).deobfuscate();
|
||||
|
||||
var decrypterType = getDecrypterType();
|
||||
if (canRemoveDecrypterType && isDecrypterTypeCalled(decrypterType))
|
||||
if (canRemoveDecrypterType && isTypeCalled(decrypterType))
|
||||
canRemoveDecrypterType = false;
|
||||
|
||||
if (canRemoveDecrypterType)
|
||||
|
@ -612,57 +612,5 @@ namespace de4dot.code.deobfuscators.dotNET_Reactor4 {
|
|||
return;
|
||||
methodsDecrypter.encryptNativeMethods(builder);
|
||||
}
|
||||
|
||||
bool isDecrypterTypeCalled(TypeDefinition decrypterType) {
|
||||
if (decrypterType == null)
|
||||
return false;
|
||||
|
||||
var decrypterMethods = new Dictionary<MethodReferenceAndDeclaringTypeKey, bool>();
|
||||
foreach (var type in TypeDefinition.GetTypes(new List<TypeDefinition> { decrypterType }))
|
||||
addMethods(type, decrypterMethods);
|
||||
|
||||
var removedMethods = new Dictionary<MethodReferenceAndDeclaringTypeKey, bool>();
|
||||
foreach (var method in getMethodsToRemove())
|
||||
removedMethods[new MethodReferenceAndDeclaringTypeKey(method)] = true;
|
||||
foreach (var type in TypeDefinition.GetTypes(getTypesToRemove()))
|
||||
addMethods(type, removedMethods);
|
||||
|
||||
foreach (var type in module.GetTypes()) {
|
||||
foreach (var method in type.Methods) {
|
||||
if (method.Body == null)
|
||||
continue;
|
||||
var key = new MethodReferenceAndDeclaringTypeKey(method);
|
||||
if (decrypterMethods.ContainsKey(key))
|
||||
break; // decrypter type / nested type method
|
||||
if (removedMethods.ContainsKey(key))
|
||||
continue;
|
||||
|
||||
foreach (var instr in method.Body.Instructions) {
|
||||
switch (instr.OpCode.Code) {
|
||||
case Code.Call:
|
||||
case Code.Callvirt:
|
||||
case Code.Newobj:
|
||||
var calledMethod = instr.Operand as MethodReference;
|
||||
if (calledMethod == null)
|
||||
break;
|
||||
key = new MethodReferenceAndDeclaringTypeKey(calledMethod);
|
||||
if (decrypterMethods.ContainsKey(key))
|
||||
return true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void addMethods(TypeDefinition type, Dictionary<MethodReferenceAndDeclaringTypeKey, bool> methods) {
|
||||
foreach (var method in type.Methods)
|
||||
methods[new MethodReferenceAndDeclaringTypeKey(method)] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user