Add method to remove classes with no base type

This commit is contained in:
de4dot 2012-02-12 11:35:18 +01:00
parent 18cd71ecdc
commit 80d338637e

View File

@ -180,10 +180,14 @@ namespace de4dot.code.deobfuscators {
restoreBaseType();
}
static bool isTypeWithInvalidBaseType(TypeDefinition moduleType, TypeDefinition type) {
return type.BaseType == null && !type.IsInterface && type != moduleType;
}
void restoreBaseType() {
var moduleType = DotNetUtils.getModuleType(module);
foreach (var type in module.GetTypes()) {
if (type.BaseType != null || type.IsInterface || type == moduleType)
if (!isTypeWithInvalidBaseType(moduleType, type))
continue;
Log.v("Adding System.Object as base type: {0} ({1:X8})",
Utils.removeNewlines(type),
@ -192,6 +196,15 @@ namespace de4dot.code.deobfuscators {
}
}
protected void removeTypesWithInvalidBaseTypes() {
var moduleType = DotNetUtils.getModuleType(module);
foreach (var type in module.GetTypes()) {
if (!isTypeWithInvalidBaseType(moduleType, type))
continue;
addTypeToBeRemoved(type, "Invalid type with no base type (anti-reflection)");
}
}
public virtual IEnumerable<string> getStringDecrypterMethods() {
return new List<string>();
}