Beispiel #1
0
        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);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        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);
            }
        }