Exemple #1
0
 public CallInfo(int instructionIndex, MethodDef methodDef, ICollection <MethodDef> cachedOverrides = null)
     : this(instructionIndex, methodDef,
            CreateAssemblyInfo(methodDef),
            methodDef.CreateMethodUniqueSignature(),
            methodDef.IsPublicGlobalVisibility(),
            (cachedOverrides ?? methodDef.FindOverrides()).Select(md => md.CreateMethodUniqueSignature()).ToList())
 {
 }
        public DataFlowAnalysisResult ExecuteForwardInternal(MethodDef method, List <TypeDef> requiredArgumentTypes)
        {
            if (!IsCallStackEmpty)
            {
                throw new Exception("The current call stack must be empty");
            }

            if (result != null)
            {
                throw new Exception("The current result must be null");
            }

            entryPointAssemblyName        = method.DeclaringType.DefinitionAssembly.Name;
            firstExecutionContextCreating = inputTaintedMode;
            result = new DataFlowAnalysisResult(patternCache);

            if (requiredArgumentTypes != null)
            {
                foreach (var type in requiredArgumentTypes)
                {
                    RegisterType(type);
                }
            }

            var summary = GetOrCreateSummary(new MethodCall(
                                                 method.CreateMethodUniqueSignature(),
                                                 method,
                                                 null,
                                                 CallKind.Concrete));

            result.Stat.StoreMemorySize();
            result.Summary = summary;
            var r = result;

            result = null;
            entryPointAssemblyName = null;
            CheckRecursionCache();
            ResetSummaryCache();
            return(r);
        }
Exemple #3
0
        //private readonly SymbolicSlot returnValue;
        //private readonly List<IEffect> effects = new List<IEffect>();

        public Interpreter(MethodDef method)
            : this(new ExecutionContext(ImmutableStack <string> .Empty, method.CreateMethodUniqueSignature(), method, false, false), method)
        {
        }
        public void Apply(Summary summary, SymbolicSlot[] parameters, DataFlowAnalysisResult result,
                          ReturnValueApplyingMode returnValueApplying, string indent = "")
        {
            //return;
            if (summary.IsEmpty)
            {
                return;
            }

            MethodCallCount  += summary.MethodCallCount;
            InstructionCount += summary.InstructionCount;

            Debug.Assert(summary.Arguments.Length == parameters.Length);
            if (summary.Arguments.Length != parameters.Length)
            {
                Console.WriteLine("Skip applying summary!");
                return;
            }

            //Console.WriteLine($"{indent}{summary.Signature} APPLYING...");
            result.Stat.StartSummaryApplying(summary.Signature.ToString());

            // Match
            var context = new SymbolicReference.ApplyingContext(CallStack);

            Static.Match(context, summary.Static);
            for (int i = 0; i < parameters.Length; i++)
            {
                parameters[i].Match(context, summary.Arguments[i]);
            }

            // Apply
            if (enableStaticFields)
            {
                staticEntity.Apply(context, summary.Static, result);
            }

            for (int i = 0; i < parameters.Length; i++)
            {
                parameters[i].Apply(context, summary.Arguments[i], result);
            }

            if (summary.ReturnValue != null)
            {
                var matchedReturnValue = new SymbolicSlot(summary.ReturnValue.GetMatchedValue(context, result));
                switch (returnValueApplying)
                {
                case ReturnValueApplyingMode.Replace:
                    Frame.Pop();
                    Frame.Push(matchedReturnValue);
                    break;

                case ReturnValueApplyingMode.Merge:
                    var returnedSlot = Frame.Pop();
                    Frame.Push(SymbolicSlot.Merge(returnedSlot, matchedReturnValue));
                    break;

                default:
                    throw new NotSupportedException();
                }
            }

            //Console.WriteLine($"Apply({summary.OutScopeMap.Count}): {timer.ElapsedMilliseconds} ms");

/*
 *          Debug.Assert(Static.entities.Length == 1);
 *          foreach (var f in Static.entities[0].fields)
 *          {
 *              if (f.Value.source is ArgumentSource arg)
 *              {
 *                  Debug.Assert(arg.signature == Signature);
 *              }
 *          }
 */

            result.Stat.StopSummaryApplying(method.CreateMethodUniqueSignature().ToString(), summary);
            result.Stat.AppliedSummaryCount++;
        }