コード例 #1
0
        private void IndexConcreteMethods(ModuleDefinition module)
        {
            var implementationMethods = DecompilerService.GetConcreteMethods(module);

            foreach (var method in implementationMethods)
            {
                if (ShouldSkip(method))
                {
                    continue;
                }

                var methodNameKey = SignatureKeyService.GetFullMethodSignature(method);
                if (!ImplementationMethodsIndexedByName.ContainsKey(methodNameKey))
                {
                    ImplementationMethodsIndexedByName.Add(methodNameKey, method);
                    ImplementationMethodsList.Add(method);
                    ImplementationMethodsIndexedByTypeName.Add(method.DeclaringType.FullName, method);
                }

                var genericSignature = SignatureKeyService.GetGenericMethodSignature(method);
                if (!string.IsNullOrEmpty(genericSignature))
                {
                    if (!ImplementationMethodsIndexedByGenericSignature.ContainsKey(genericSignature))
                    {
                        ImplementationMethodsIndexedByGenericSignature.Add(genericSignature, method);
                    }
                }
            }
        }
コード例 #2
0
        private void IndexInterfaceMethods(ModuleDefinition module)
        {
            var interfaceMethods = DecompilerService.GetInterfaceMethods(module);

            foreach (var method in interfaceMethods)
            {
                // index by a simplified generic signature if it is a generic interface method
                var genericSignature = SignatureKeyService.GetGenericMethodSignature(method);
                if (!string.IsNullOrEmpty(genericSignature))
                {
                    if (!InterfaceMethodsIndexedByGenericSignature.ContainsKey(genericSignature))
                    {
                        InterfaceMethodsIndexedByGenericSignature.Add(genericSignature, method);
                    }
                }

                // index by the standard method signature
                var methodSignature = SignatureKeyService.GetFullMethodSignature(method);
                if (!InterfaceMethodsIndexedByName.ContainsKey(methodSignature))
                {
                    InterfaceMethodsIndexedByName.Add(methodSignature, method);
                }

                InterfaceMethodsIndexedByTypeName.Add(method.DeclaringType.FullName, method);
                InterfaceMethodsList.Add(method);
            }
        }
コード例 #3
0
ファイル: CallTreeWalker.cs プロジェクト: Vanlightly/Graphode
        private void DoCrossAssemblyWalk(MethodGraph methodGraph, string companyAssembliesPattern, ModuleDefinition module, string moduleMessagee)
        {
            var publicMethods = DecompilerService.GetPublicMethods(companyAssembliesPattern, module)
                                .Where(x => !IsBlackListed(x))
                                .OrderBy(x => x.DeclaringType.Name)
                                .ThenBy(x => x.Name)
                                .ToList();

            int methodCount           = publicMethods.Count;
            var publicMethodsAnalyzed = new HashSet <string>();

            _methodNodeLookup.Clear();

            int methodCounter = 0;

            foreach (var publicMethod in publicMethods)
            {
                methodCounter++;
                _logOutput.LogAnalysis("Method " + methodCounter + " of " + methodCount + " : " + moduleMessagee + " -> " + publicMethod.Name);
                if ((publicMethod.IsGetter || publicMethod.IsSetter) && !IsNoteworthyProperty(publicMethod))
                {
                    continue;
                }

                var signature = SignatureKeyService.GetFullMethodSignature(publicMethod);
                if (_methodIndexer.HasMethod(signature))
                {
                    var unfilteredRootNodes = _methodIndexer.GetMethods(signature);
                    var rootNodes           = unfilteredRootNodes.Where(x => x.HasImplementation() &&
                                                                        (
                                                                            // if it is a public implementation of a different assembly, then'll we'll filter it out here (and analyze it that assembly)
                                                                            (x.ConcreteMethod.IsPublic && x.ConcreteMethod.Module.Name.Equals(module.Name))
                                                                            // if it is a private implementation then analyze it now as we'll miss it when we analyze the public methods of the other assembly
                                                                            || !x.ConcreteMethod.DeclaringType.IsPublic
                                                                        )
                                                                        )
                                              .ToList();

                    foreach (var rootMethod in rootNodes)
                    {
                        if (!AlreadyProcessed(rootMethod.GetMethodDefinition()))
                        {
                            var publicMethodNode = GetMethodNode(methodGraph.GraphType, methodGraph.ApplicationName, rootMethod);
                            var callTreeNode     = new ExploreTreeNode()
                            {
                                FullSignature = signature
                            };
                            CrossAssemblyWalk(methodGraph, publicMethodNode, rootMethod, 1, callTreeNode);
                            CacheNode(rootMethod.GetMethodDefinition(), publicMethodNode);
                            methodGraph.AddMethodNode(publicMethodNode);
                        }
                    }
                }
            }
        }
コード例 #4
0
        private void IndexAbstractMethods(ModuleDefinition module)
        {
            var abstractMethods = DecompilerService.GetAbstractMethods(module);

            foreach (var method in abstractMethods)
            {
                AbstractMethodsIndexedByName.Add(SignatureKeyService.GetFullMethodSignature(method), method);
                AbstractMethodsIndexedByTypeName.Add(method.DeclaringType.FullName, method);
                AbstractMethodsList.Add(method);
            }
        }
コード例 #5
0
ファイル: CallTreeWalker.cs プロジェクト: Vanlightly/Graphode
        private void ContinueDownFullTree(MethodGraph methodGraph, MethodNode parentMethodNode, MethodObject parentMethod, int depth, ExploreTreeNode callTreeNode)
        {
            foreach (var calledMethod in parentMethod.MethodsCalled)
            {
                CheckForResourceCall(methodGraph, calledMethod, parentMethod, parentMethodNode);
                var calledMethodSignature = SignatureKeyService.GetFullMethodSignature(calledMethod.MethodCalled);
                var treeNode = new ExploreTreeNode()
                {
                    FullSignature = calledMethodSignature
                };
                callTreeNode.AddChild(treeNode);

                bool   isGenericAndIndexed = false;
                string genericSignature    = null;
                var    methodIsIndexed     = _methodIndexer.HasMethod(calledMethodSignature);
                if (!methodIsIndexed)
                {
                    genericSignature = SignatureKeyService.GetGenericMethodSignature(calledMethod.MethodCalled);
                    if (!string.IsNullOrEmpty(genericSignature))
                    {
                        isGenericAndIndexed = _methodIndexer.HasMethod(genericSignature);
                    }
                }

                if (methodIsIndexed || isGenericAndIndexed)
                {
                    List <MethodObject> matchingMethodNodes = null;
                    if (methodIsIndexed)
                    {
                        matchingMethodNodes = _methodIndexer.GetMethods(calledMethodSignature);
                    }
                    else if (isGenericAndIndexed)
                    {
                        matchingMethodNodes = _methodIndexer.GetMethods(genericSignature);
                    }

                    foreach (var calledMethodNode in matchingMethodNodes)
                    {
                        var cachedRootNode = GetCachedRootNode(calledMethodNode.GetMethodDefinition());

                        if (cachedRootNode != null) // this is a call to an already analyzed method, we copy over the calls and resource accesses already calculated for this node
                        {
                            cachedRootNode.CopyCallsToNode(parentMethodNode);
                        }
                        else // this is not a call to a previously analyzed method, so we continue down the call tree
                        {
                            PublicInnerAssemblyWalk(methodGraph, parentMethodNode, calledMethodNode, depth + 1, treeNode);
                        }
                    }
                }
            }
        }
コード例 #6
0
ファイル: CallTreeWalker.cs プロジェクト: Vanlightly/Graphode
        private void DoDirectCallWalk(MethodGraph methodGraph, string companyAssembliesPattern, ModuleDefinition module, string moduleMessagee)
        {
            var methods = _methodIndexer.GetAllMethods();

            foreach (var method in methods)
            {
                var methodNode = GetMethodNode(methodGraph.GraphType, methodGraph.ApplicationName, method);

                foreach (var calledMethod in method.MethodsCalled)
                {
                    CheckForResourceCall(methodGraph, calledMethod, method, methodNode);
                    var calledMethodSignature = SignatureKeyService.GetFullMethodSignature(calledMethod.MethodCalled);

                    bool   isGenericAndIndexed = false;
                    string genericSignature    = null;
                    var    methodIsIndexed     = _methodIndexer.HasMethod(calledMethodSignature);
                    if (!methodIsIndexed)
                    {
                        genericSignature = SignatureKeyService.GetGenericMethodSignature(calledMethod.MethodCalled);
                        if (!string.IsNullOrEmpty(genericSignature))
                        {
                            isGenericAndIndexed = _methodIndexer.HasMethod(genericSignature);
                        }
                    }

                    if (methodIsIndexed || isGenericAndIndexed)
                    {
                        List <MethodObject> matchingMethodNodes = null;
                        if (methodIsIndexed)
                        {
                            matchingMethodNodes = _methodIndexer.GetMethods(calledMethodSignature);
                        }
                        else if (isGenericAndIndexed)
                        {
                            matchingMethodNodes = _methodIndexer.GetMethods(genericSignature);
                        }

                        foreach (var calledMethodNode in matchingMethodNodes)
                        {
                            AddDirectCalls(methodGraph, methodNode, calledMethodNode);
                        }
                    }
                }

                methodGraph.AddMethodNode(methodNode);
            }
        }
コード例 #7
0
        public void BuildMethodObjects(string appDomain)
        {
            foreach (var method in ImplementationMethodsList)
            {
                if (ShouldSkip(method))
                {
                    continue;
                }

                var node = new MethodObject();
                node.AppDomain      = appDomain;
                node.ConcreteMethod = method;

                var implementsInterface = FindInterfaceMethod(method, node);
                if (implementsInterface)
                {
                    MethodObjectsIndexedByFullName.Add(SignatureKeyService.GetFullMethodSignature(node.InterfaceMethod), node);
                    var genericSignature = SignatureKeyService.GetGenericMethodSignature(node.InterfaceMethod);
                    if (!string.IsNullOrEmpty(genericSignature))
                    {
                        MethodObjectsIndexedByFullName.Add(genericSignature, node);
                    }
                }

                var implementsAbstractClass = FindAbstractMethod(method, node);
                if (implementsAbstractClass)
                {
                    MethodObjectsIndexedByFullName.Add(SignatureKeyService.GetFullMethodSignature(node.AbstractMethod), node);
                }

                var inheritsFromBaseClass = FindBaseClassMethod(method, node);
                if (inheritsFromBaseClass)
                {
                    MethodObjectsIndexedByFullName.Add(SignatureKeyService.GetFullMethodSignature(node.VirtualMethod), node);
                }

                FindFieldsAndMethods(method, node, true);
                MethodObjectsIndexedByFullName.Add(SignatureKeyService.GetFullMethodSignature(method), node);
                MethodObjectsList.Add(node);
            }

            foreach (var method in InterfaceMethodsList)
            {
                if (!MethodObjectsIndexedByFullName.HasIndex(SignatureKeyService.GetFullMethodSignature(method)))
                {
                    var node = new MethodObject();
                    node.AppDomain       = appDomain;
                    node.InterfaceMethod = method;
                    node.ImplementsType  = ImplementsType.None;

                    MethodObjectsIndexedByFullName.Add(SignatureKeyService.GetFullMethodSignature(method), node);
                }
            }

            foreach (var method in AbstractMethodsList)
            {
                if (!MethodObjectsIndexedByFullName.HasIndex(SignatureKeyService.GetFullMethodSignature(method)))
                {
                    var node = new MethodObject();
                    node.AppDomain      = appDomain;
                    node.AbstractMethod = method;
                    node.ImplementsType = ImplementsType.None;

                    MethodObjectsIndexedByFullName.Add(SignatureKeyService.GetFullMethodSignature(method), node);
                }
            }
        }