void restoreMethodBodies()
        {
            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);
            }
        }
Ejemplo n.º 2
0
        void restoreMethodBodies()
        {
            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);
            }
        }