コード例 #1
0
        public static Dictionary <string, string> getDictionaryOfDependenciesForAssembly_WithNoRecursiveSearch(string assembly)
        {
            var results = new Dictionary <string, string>();

            try
            {
                var assemblyDefinition = CecilUtils.getAssembly(assembly);
                if (assemblyDefinition != null)
                {
                    var modulesInDll = CecilUtils.getModules(assemblyDefinition);
                    if (modulesInDll != null)
                    {
                        foreach (ModuleDefinition module in modulesInDll)
                        {
                            foreach (AssemblyNameReference assemblyNameReference in module.AssemblyReferences)
                            {
                                results.Add(assemblyNameReference.FullName, assemblyNameReference.Name);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                PublicDI.log.error("in getListOfDependenciesForAssembly_WithNoRecursiveSearch: {0}", ex.Message);
            }
            return(results);
        }
コード例 #2
0
        public void calculateDependenciesForAssembly(string dllToProcess) //getDependenciesForAssembly()
        {
            if (false == processedAssemblies.Contains(dllToProcess))      // only handle each dll once
            {
                if (CecilUtils.isDotNetAssembly(dllToProcess, false))
                {
                    processedAssemblies.add(dllToProcess);
                    var assemblyDefinition = CecilUtils.getAssembly(dllToProcess);
                    addAssemblyToDependenciesList(assemblyDefinition.Name.FullName, dllToProcess);
                    var modulesInDll = CecilUtils.getModules(assemblyDefinition);
                    if (modulesInDll != null)
                    {
                        foreach (ModuleDefinition module in modulesInDll)
                        {
                            foreach (AssemblyNameReference assemblyNameReference in module.AssemblyReferences)
                            {
                                //DI.log.info("{0}  -   {1} ", dllToProcess, assemblyNameReference.Name);
                                string mappedNameToTargetDllDirectory =
                                    tryToFindReferencedDllInProvidedReferenceSearchPaths(assemblyNameReference.Name);

                                addAssemblyToDependenciesList(assemblyNameReference.FullName, mappedNameToTargetDllDirectory);

                                // recursively search on each of these dlls since we need to find all dependent dlls
                                calculateDependenciesForAssembly(mappedNameToTargetDllDirectory);
                            }
                        }
                    }
                }
            }
            // log.info("There were {0} assemblyDependencies discovered", assemblyDependencies.Count);
            //return assemblyDependencies;
        }
コード例 #3
0
        public static List <string> findInAssembly_OnCallX_ParameterType(string assemblyToLoad, string methodToFind,
                                                                         int parameterOffset)
        {
            var findings = new List <string>();

            foreach (MethodDefinition methodDefinition in CecilUtils.getMethods(assemblyToLoad))
            {
                for (int i = 0; i < methodDefinition.Body.Instructions.Count; i++)
                {
                    Instruction instruction = methodDefinition.Body.Instructions[i];
                    if (instruction.Operand != null)
                    {
                        if (instruction.Operand.ToString() == methodToFind)
                        {
                            var sourceMethod = (MethodDefinition)instruction.Operand;
                            // DI.log.debug("[{0}] {1} ", instruction.OpCode.Name,

                            var sinkMethod =
                                (MethodDefinition)methodDefinition.Body.Instructions[i - parameterOffset].Operand;
                            // DI.log.debug("-->[{0}] {1} ", instructionWithParameter.OpCode.Name,
                            //               instructionWithParameter.Operand.ToString());
                            // DI.log.debug("{0} -- > {1}", sourceMethod.Name, sinkMethod.Name);
                            //MethodDefinition property = (MethodDefinition)method.Body.Instructions[i - parameterOffset].Operand;
                            findings.Add(String.Format("{0} -- > {1}", sourceMethod.Name, sinkMethod.Name));
                        }
                    }
                }
            }

            return(findings);
        }
コード例 #4
0
ファイル: DI.cs プロジェクト: pusp/o2platform
        public static IAssemblyAnalysis assemblyAnalysis; // = new AssemblyAnalysisImpl();

        #endregion Fields

        #region Constructors

        static DI()
        {
            config = PublicDI.config;
            log = PublicDI.log;
            reflection = new O2FormsReflectionASCX();
            cecilUtils = new CecilUtils();
            monoCecil = new O2MonoCecil();
            assemblyAnalysis = new AssemblyAnalysisImpl();
        }
コード例 #5
0
        public static List <TypeDefinition> getTypesWithAttribute(string assemblyToLoad, string attributeToFinding)
        {
            var typesWithAttribute = new List <TypeDefinition>();

            foreach (TypeDefinition typeDefinition in CecilUtils.getTypes(assemblyToLoad))
            {
                foreach (CustomAttribute customAttribute in typeDefinition.CustomAttributes)
                {
                    if (customAttribute.Constructor.DeclaringType.Name == attributeToFinding)
                    {
                        typesWithAttribute.Add(typeDefinition);
                    }
                }
            }
            return(typesWithAttribute);
        }
コード例 #6
0
        public static List <MethodDefinition> getMethodsWithAttribute(TypeDefinition testFixture, string attributeToFinding)
        {
            var tests = new List <MethodDefinition>();

            foreach (MethodDefinition methodDefinition in CecilUtils.getMethods(testFixture))
            {
                foreach (CustomAttribute customAttribute in methodDefinition.CustomAttributes)
                {
                    if (customAttribute.Constructor.DeclaringType.Name == attributeToFinding)
                    {
                        tests.Add(methodDefinition);
                    }
                }
            }
            return(tests);
        }
コード例 #7
0
 public static MethodDefinition getMethodDefinitionFromMethodInfo(MethodInfo methodInfo, Mono.Cecil.AssemblyDefinition assemblyDefinition)
 {
     foreach (var methodDefinition in CecilUtils.getMethods(assemblyDefinition))
     {
         var functionSignature1 = new FilteredSignature(methodInfo);
         var functionSignature2 = new FilteredSignature(methodDefinition.ToString());
         if (functionSignature1.sSignature == functionSignature2.sSignature)
         {
             return(methodDefinition);
         }
         if (functionSignature1.sFunctionName == functionSignature2.sFunctionName)
         {
         }
     }
     PublicDI.log.error("in getMethodDefinitionFromMethodInfo, could not map MethodInfo: {0}", methodInfo.ToString());
     return(null);
 }