void RestoreMethodBodies(ISimpleDeobfuscator simpleDeobfuscator) { var methodToOrigMethods = new MethodDefAndDeclaringTypeDict<List<MethodDef>>(); foreach (var t in module.Types) { var types = new List<TypeDef>(AllTypesHelper.Types(new List<TypeDef> { t })); foreach (var type in types) { if (methodsTypes.Find(type)) continue; foreach (var method in type.Methods) { if (method.Name == ".ctor" || method.Name == ".cctor") continue; MethodDef calledMethod; if (!CheckRestoreBody(method, out calledMethod)) continue; if (!CheckSameMethods(method, calledMethod)) continue; if (!methodsTypes.Find(calledMethod.DeclaringType)) continue; if (types.IndexOf(calledMethod.DeclaringType) < 0) continue; var list = methodToOrigMethods.Find(calledMethod); if (list == null) methodToOrigMethods.Add(calledMethod, list = new List<MethodDef>()); list.Add(method); } } } foreach (var calledMethod in methodToOrigMethods.GetKeys()) { var list = methodToOrigMethods.Find(calledMethod); var method = list[0]; Logger.v("Restored method body {0:X8} from method {1:X8}", method.MDToken.ToInt32(), calledMethod.MDToken.ToInt32()); DotNetUtils.CopyBodyFromTo(calledMethod, method); classMethods.Add(calledMethod, method); simpleDeobfuscator.MethodModified(method); } }
void RestoreMethodBodies(ISimpleDeobfuscator simpleDeobfuscator) { var methodToOrigMethods = new MethodDefAndDeclaringTypeDict <List <MethodDef> >(); foreach (var t in module.Types) { var types = new List <TypeDef>(AllTypesHelper.Types(new List <TypeDef> { t })); foreach (var type in types) { if (methodsTypes.Find(type)) { continue; } foreach (var method in type.Methods) { if (method.Name == ".ctor" || method.Name == ".cctor") { continue; } MethodDef calledMethod; if (!CheckRestoreBody(method, out calledMethod)) { continue; } if (!CheckSameMethods(method, calledMethod)) { continue; } if (!methodsTypes.Find(calledMethod.DeclaringType)) { continue; } if (types.IndexOf(calledMethod.DeclaringType) < 0) { continue; } var list = methodToOrigMethods.Find(calledMethod); if (list == null) { methodToOrigMethods.Add(calledMethod, list = new List <MethodDef>()); } list.Add(method); } } } foreach (var calledMethod in methodToOrigMethods.GetKeys()) { var list = methodToOrigMethods.Find(calledMethod); var method = list[0]; Logger.v("Restored method body {0:X8} from method {1:X8}", method.MDToken.ToInt32(), calledMethod.MDToken.ToInt32()); DotNetUtils.CopyBodyFromTo(calledMethod, method); classMethods.Add(calledMethod, method); simpleDeobfuscator.MethodModified(method); } }