void restoreMethodBodies() { var methodToOrigMethods = new MethodDefinitionAndDeclaringTypeDict<List<MethodDefinition>>(); foreach (var t in module.Types) { var types = new List<TypeDefinition>(TypeDefinition.GetTypes(new List<TypeDefinition> { 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; MethodDefinition 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<MethodDefinition>()); list.Add(method); } } } foreach (var calledMethod in methodToOrigMethods.getKeys()) { var list = methodToOrigMethods.find(calledMethod); var method = list[0]; Log.v("Restored method body {0:X8} from method {1:X8}", method.MetadataToken.ToInt32(), calledMethod.MetadataToken.ToInt32()); DotNetUtils.copyBodyFromTo(calledMethod, method); classMethods.add(calledMethod, method); } }
void restoreMethodBodies() { var methodToOrigMethods = new MethodDefinitionAndDeclaringTypeDict <List <MethodDefinition> >(); foreach (var t in module.Types) { var types = new List <TypeDefinition>(TypeDefinition.GetTypes(new List <TypeDefinition> { 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; } MethodDefinition 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 <MethodDefinition>()); } list.Add(method); } } } foreach (var calledMethod in methodToOrigMethods.getKeys()) { var list = methodToOrigMethods.find(calledMethod); var method = list[0]; Log.v("Restored method body {0:X8} from method {1:X8}", method.MetadataToken.ToInt32(), calledMethod.MetadataToken.ToInt32()); DotNetUtils.copyBodyFromTo(calledMethod, method); classMethods.add(calledMethod, method); } }