コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
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);
 }