コード例 #1
0
 private InstructionTreeNode GetInstructionTree(MethodDefinition parentMethod, Instruction instruction, MethodReference calledMethod)
 {
     try
     {
         var rootNode = new InstructionTreeNode();
         MethodArgumentInstructionParser.GetParameterInstructionTree(parentMethod, calledMethod, instruction, rootNode);
         return(rootNode);
     }
     catch (Exception ex)
     {
         _logOutput.LogAnalysis("ERROR " + parentMethod.FullName + " instruction" + instruction.ToString() + " Error-> " + ex);
         return(null);
     }
 }
コード例 #2
0
        public static string GetFromInstanceOwnerKey(Instruction instruction, ObjectType objectType, MethodDefinition parentMethod)
        {
            if (objectType == ObjectType.NotDefined || objectType == ObjectType.ReturnValue || objectType == ObjectType.InlineString ||
                objectType == ObjectType.None || objectType == ObjectType.LocalVariable || objectType == ObjectType.InlineNumber)
            {
                return(null);
            }

            // for argument we use the key of the method
            if (objectType == ObjectType.Argument)
            {
                return(parentMethod.GetKey());
            }

            Instruction priorInstruction = null;

            if (objectType == ObjectType.Method)
            {
                MethodDefinition methodDef = null;
                var resolved = ResolveService.TryResolve((MethodReference)instruction.Operand, out methodDef);
                if (!resolved)
                {
                    return(null);
                }
                else if (methodDef.IsStatic || methodDef.Name.Equals(".ctor"))
                {
                    return(parentMethod.GetKey());
                }
                else if (methodDef.GetOwnerKey().Equals(parentMethod.GetOwnerKey()))
                {
                    return(methodDef.GetOwnerKey());
                }

                priorInstruction = MethodArgumentInstructionParser.GetPriorInstruction(parentMethod, methodDef, instruction);
            }
            else if (objectType == ObjectType.Field)
            {
                var fieldReference = (FieldReference)instruction.Operand;
                if (fieldReference.DeclaringType.FullName.Equals(parentMethod.DeclaringType.FullName))
                {
                    return(null);
                }

                priorInstruction = instruction.Previous;
            }
            else
            {
                return(null);
                //MethodDefinition methodDef = null;
                //var resolved = ResolveService.TryResolve((MethodReference)instruction.Operand, out methodDef);
                //if (methodDef.IsStatic || methodDef.Name.Equals(".ctor"))
                //    return parentMethod.GetKey();

                //if (methodDef.GetOwnerKey().Equals(parentMethod.GetOwnerKey()))
                //    return methodDef.GetOwnerKey();

                //priorInstruction = instruction.Previous;
            }

            if (priorInstruction == null)
            {
                return(null);
            }

            var ownerObjectType = GetFromObjectType(priorInstruction);

            if (!IsSupportedObject(ownerObjectType))
            {
                return(null);
            }

            var ownerInstanceKey = GetObjectKey(priorInstruction, ownerObjectType, parentMethod);

            return(ownerInstanceKey);
        }