Move code to DeobUtils

This commit is contained in:
de4dot 2012-04-25 13:21:53 +02:00
parent 2b4fc0a836
commit 4e89d707dc
2 changed files with 27 additions and 14 deletions

View File

@ -18,6 +18,7 @@
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using Mono.Cecil;
@ -206,5 +207,29 @@ namespace de4dot.code.deobfuscators {
}
return -1;
}
public static IEnumerable<MethodDefinition> getInitCctors(ModuleDefinition module, int maxCctors) {
var cctor = DotNetUtils.getModuleTypeCctor(module);
if (cctor != null)
yield return cctor;
var entryPoint = module.EntryPoint;
if (entryPoint != null) {
cctor = DotNetUtils.getMethod(entryPoint.DeclaringType, ".cctor");
if (cctor != null)
yield return cctor;
}
foreach (var type in module.GetTypes()) {
if (type == DotNetUtils.getModuleType(module))
continue;
cctor = DotNetUtils.getMethod(type, ".cctor");
if (cctor == null)
continue;
yield return cctor;
if (!type.IsEnum && --maxCctors <= 0)
break;
}
}
}
}

View File

@ -81,20 +81,8 @@ namespace de4dot.code.deobfuscators.MaxtoCode {
}
public void find() {
if (checkCctor(DotNetUtils.getModuleTypeCctor(module)))
return;
var entryPoint = module.EntryPoint;
if (entryPoint != null && checkCctor(DotNetUtils.getMethod(entryPoint.DeclaringType, ".cctor")))
return;
int checksLeft = 3;
foreach (var type in module.GetTypes()) {
if (type == DotNetUtils.getModuleType(module))
continue;
if (checkCctor(DotNetUtils.getMethod(type, ".cctor")))
return;
if (!type.IsEnum && --checksLeft <= 0)
foreach (var cctor in DeobUtils.getInitCctors(module, 3)) {
if (checkCctor(cctor))
break;
}
}