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); } } } }
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); } }
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); } } } } }
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); } }
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); } } }