Esempio n. 1
0
 public InterProceduralReturnInfo(DependencyPTGDomain state)
 {
     this.State         = state;
     this.InputColumns  = new HashSet <TraceableColumn>();
     this.OutputColumns = new HashSet <TraceableColumn>();
     // this.PTG = ptg;
 }
Esempio n. 2
0
        public IEnumerable <TraceableTable> GetTraceablesFromYieldReturn(DependencyPTGDomain state)
        {
            var thisVariable = state.PTG.Roots.Where(v => v.Name == "this").Single();
            var currentField = GetCurrentFieldFromClausure();
            var traceables   = state.GetHeapTraceables(thisVariable, currentField).OfType <TraceableTable>();

            return(traceables);
        }
Esempio n. 3
0
        private DependencyPTGDomain BindCallerCallee(InterProceduralCallInfo callInfo, out VariableRangeDomain initializedRanges)
        {
            initializedRanges = new VariableRangeDomain();

            var calleeDepDomain = new DependencyPTGDomain();

            calleeDepDomain.Dependencies.IsTop = callInfo.CallerState.Dependencies.IsTop;
            // Bind parameters with arguments
            var body = MethodBodyProvider.Instance.GetBody(callInfo.Callee);

            for (int i = 0; i < body.Parameters.Count(); i++)
            {
                var arg = callInfo.CallArguments[i];

                var param = body.Parameters[i];

                arg   = AdaptIsReference(arg);
                param = AdaptIsReference(param);

                if (callInfo.CallerState.HasTraceables(arg))
                {
                    calleeDepDomain.AssignTraceables(param, callInfo.CallerState.GetTraceables(arg));
                }
                if (callInfo.CallerState.HasOutputTraceables(arg))
                {
                    calleeDepDomain.AddOutputTraceables(param, callInfo.CallerState.GetOutputTraceables(arg));
                }
                if (callInfo.CallerState.HasOutputControlTraceables(arg))
                {
                    calleeDepDomain.AddOutputControlTraceables(param, callInfo.CallerState.GetOutputControlTraceables(arg));
                }

                initializedRanges.AssignValue(param, callInfo.VariableRanges.GetValue(arg));

                // DIEGODIEGO: Do I need this?
                callInfo.ScopeData.PropagateCopy(arg, param);
            }
            calleeDepDomain.Dependencies.A1_Escaping = callInfo.CallerState.Dependencies.A1_Escaping;

            calleeDepDomain.Dependencies.A2_References = callInfo.CallerState.Dependencies.A2_References;

            calleeDepDomain.Dependencies.A3_Fields        = callInfo.CallerState.Dependencies.A3_Fields;
            calleeDepDomain.Dependencies.ControlVariables = callInfo.CallerState.Dependencies.ControlVariables;
            //calleeDepDomain.Dependencies.ControlTraceables = callInfo.CallerState.Dependencies.ControlTraceables;

            //calleeDepDomain.Dependencies.A1_Escaping.UnionWith(callInfo.CallerState.Dependencies.A1_Escaping);
            //calleeDepDomain.Dependencies.A3_Clousures.UnionWith(callInfo.CallerState.Dependencies.A3_Clousures);
            return(calleeDepDomain);
        }
        private DependencyPTGDomain BindCallerCallee(InterProceduralCallInfo callInfo)
        {
            var calleeDepDomain = new DependencyPTGDomain();

            calleeDepDomain.Dependencies.IsTop = callInfo.CallerState.Dependencies.IsTop;
            // Bind parameters with arguments
            for (int i = 0; i < callInfo.CallArguments.Count(); i++)
            {
                var arg   = callInfo.CallArguments[i];
                var param = callInfo.Callee.Body.Parameters[i];

                arg   = AdaptIsReference(arg);
                param = AdaptIsReference(param);

                if (callInfo.CallerState.HasTraceables(arg))
                {
                    calleeDepDomain.AssignTraceables(param, callInfo.CallerState.GetTraceables(arg));
                }
                if (callInfo.CallerState.HasOutputTraceables(arg))
                {
                    calleeDepDomain.AddOutputTraceables(param, callInfo.CallerState.GetOutputTraceables(arg));
                }
                if (callInfo.CallerState.HasOutputControlTraceables(arg))
                {
                    calleeDepDomain.AddOutputControlTraceables(param, callInfo.CallerState.GetOutputControlTraceables(arg));
                }
            }
            calleeDepDomain.Dependencies.A1_Escaping = callInfo.CallerState.Dependencies.A1_Escaping;

            calleeDepDomain.Dependencies.A2_References = callInfo.CallerState.Dependencies.A2_References;

            calleeDepDomain.Dependencies.A3_Fields        = callInfo.CallerState.Dependencies.A3_Fields;
            calleeDepDomain.Dependencies.ControlVariables = callInfo.CallerState.Dependencies.ControlVariables;
            //calleeDepDomain.Dependencies.A1_Escaping.UnionWith(callInfo.CallerState.Dependencies.A1_Escaping);
            //calleeDepDomain.Dependencies.A3_Clousures.UnionWith(callInfo.CallerState.Dependencies.A3_Clousures);
            return(calleeDepDomain);
        }
 public InterProceduralReturnInfo(DependencyPTGDomain state)
 {
     this.State = state;
     // this.PTG = ptg;
 }
Esempio n. 6
0
        private static void WriteResultToSarifLog(string inputPath, StreamWriter outputStream, SarifLog log, MethodDefinition moveNextMethod, DependencyPTGDomain depAnalysisResult,
                                                  SongTaoDependencyAnalysis dependencyAnalysis, IDictionary <string, ClassDefinition> processorMap)
        {
            var results = new List <Result>();

            var escapes = depAnalysisResult.Dependencies.A1_Escaping.Select(traceable => traceable.ToString());

            var inputUses      = new HashSet <Traceable>();
            var outputModifies = new HashSet <Traceable>();

            if (!depAnalysisResult.IsTop)
            {
                if (depAnalysisResult.Dependencies.A4_Ouput.Any())
                {
                    var outColumnMap        = new MapSet <TraceableColumn, Traceable>();
                    var outColumnControlMap = new MapSet <TraceableColumn, Traceable>();
                    foreach (var outColum in depAnalysisResult.Dependencies.A4_Ouput.Keys)
                    {
                        var outColumns = depAnalysisResult.GetTraceables(outColum).OfType <TraceableColumn>()
                                         .Where(t => t.TableKind == ProtectedRowKind.Output);
                        foreach (var column in outColumns)
                        {
                            if (!outColumnMap.ContainsKey(column))
                            {
                                outColumnMap.AddRange(column, depAnalysisResult.Dependencies.A4_Ouput[outColum]);
                            }
                            else
                            {
                                outColumnMap.AddRange(column, outColumnMap[column].Union(depAnalysisResult.Dependencies.A4_Ouput[outColum]));
                            }
                            if (!outColumnControlMap.ContainsKey(column))
                            {
                                outColumnControlMap.AddRange(column, depAnalysisResult.Dependencies.A4_Ouput_Control[outColum]);
                            }
                            else
                            {
                                outColumnControlMap.AddRange(column, outColumnControlMap[column].Union(depAnalysisResult.Dependencies.A4_Ouput_Control[outColum]));
                            }
                        }
                    }

                    foreach (var entryOutput in outColumnMap)
                    {
                        var result = new Result();
                        result.Id = "SingleColumn";
                        var column         = entryOutput.Key;
                        var columnString   = column.ToString();
                        var dependsOn      = entryOutput.Value;
                        var controlDepends = new HashSet <Traceable>();

                        result.SetProperty("column", columnString);
                        result.SetProperty("data depends", dependsOn.Select(traceable => traceable.ToString()));

                        if (outColumnControlMap.ContainsKey(column))
                        {
                            var controlDependsOn = outColumnControlMap[column];
                            result.SetProperty("control depends", controlDependsOn.Select(traceable => traceable.ToString()));
                        }
                        else
                        {
                            result.SetProperty("control depends", new string[] { });
                        }
                        result.SetProperty("escapes", escapes);
                        results.Add(result);

                        inputUses.AddRange(dependsOn.Where(t => t.TableKind == ProtectedRowKind.Input));
                        outputModifies.Add(column);
                    }


                    //foreach (var outColum in depAnalysisResult.Dependencies.A4_Ouput.Keys)
                    //{
                    //    //var outColumns = depAnalysisResult.Dependencies.A2_Variables[outColum].OfType<TraceableColumn>()
                    //    //                                            .Where(t => t.TableKind == ProtectedRowKind.Output);
                    //    var outColumns = depAnalysisResult.GetTraceables(outColum).OfType<TraceableColumn>()
                    //                                                .Where(t => t.TableKind == ProtectedRowKind.Output);

                    //    foreach (var column in outColumns)
                    //    {
                    //        var result = new Result();
                    //        result.Id = "SingleColumn";
                    //        var columnString = column.ToString();
                    //        var dependsOn = depAnalysisResult.Dependencies.A4_Ouput[outColum];

                    //        //dependsOn.AddRange(traceables);
                    //        result.SetProperty("column", columnString);
                    //        result.SetProperty("data depends", dependsOn.Select(traceable => traceable.ToString()));
                    //        if (depAnalysisResult.Dependencies.A4_Ouput_Control.ContainsKey(outColum))
                    //        {
                    //            var controlDependsOn = depAnalysisResult.Dependencies.A4_Ouput_Control[outColum];
                    //            result.SetProperty("control depends", controlDependsOn.Where(t => !(t is Other)).Select(traceable => traceable.ToString()));
                    //            inputUses.AddRange(controlDependsOn.Where(t => t.TableKind == ProtectedRowKind.Input));
                    //        }
                    //        else
                    //        {
                    //            result.SetProperty("control depends", new string[] { });
                    //        }
                    //        result.SetProperty("escapes", escapes);
                    //        results.Add(result);

                    //        inputUses.AddRange(dependsOn.Where(t => t.TableKind == ProtectedRowKind.Input));
                    //        outputModifies.Add(column);
                    //    }
                    //}
                }
                else
                {
                    var result = new Result();
                    result.Id = "SingleColumn";
                    result.SetProperty("column", "_EMPTY_");
                    result.SetProperty("escapes", escapes);
                    results.Add(result);
                }
                var resultSummary = new Result();
                resultSummary.Id = "Summary";

                //var inputsString = inputUses.OfType<TraceableColumn>().Select(t => t.ToString());
                //var outputsString = outputModifies.OfType<TraceableColumn>().Select(t => t.ToString());
                //result2.SetProperty("Inputs", inputsString);
                //result2.SetProperty("Outputs", outputsString);

                var inputsString  = dependencyAnalysis.InputColumns.Select(t => t.ToString());
                var outputsString = dependencyAnalysis.OutputColumns.Select(t => t.ToString());
                resultSummary.SetProperty("Inputs", inputsString);
                resultSummary.SetProperty("Outputs", outputsString);

                var inputSchemaString  = InputSchema.Columns.Select(t => t.ToString());
                var outputSchemaString = OutputSchema.Columns.Select(t => t.ToString());

                resultSummary.SetProperty("SchemaInputs", inputSchemaString);
                resultSummary.SetProperty("SchemaOutputs", outputSchemaString);
                results.Add(resultSummary);

                if (outputStream != null)
                {
                    outputStream.WriteLine("Class: [{0}] {1}", moveNextMethod.ContainingType.FullPathName(), moveNextMethod.ToSignatureString());
                    if (depAnalysisResult.IsTop)
                    {
                        outputStream.WriteLine("Analysis returns TOP");
                    }
                    outputStream.WriteLine("Inputs: {0}", String.Join(", ", inputsString));
                    outputStream.WriteLine("Outputs: {0}", String.Join(", ", outputsString));
                }
            }
            else
            {
                var result = new Result();
                result.Id = "SingleColumn";
                result.SetProperty("column", "_TOP_");
                result.SetProperty("depends", "_TOP_");
                results.Add(result);
                var resultEmpty = new Result();
                resultEmpty.Id = "Summary";
                resultEmpty.SetProperty("Inputs", "_TOP_");
                resultEmpty.SetProperty("Outputs", "_TOP_");
                resultEmpty.SetProperty("SchemaInputs", "_TOP_");
                resultEmpty.SetProperty("SchemaOutputs", "_TOP_");
                results.Add(resultEmpty);
            }


            var id = String.Format("[{0}] {1}", moveNextMethod.ContainingType.FullPathName(), moveNextMethod.ToSignatureString());

            // Very clumsy way to find the process number and the processor name from the MoveNext method.
            // But it is the process number and processor name that allow us to link these results to the information
            // in the XML file that describes the job.
            // Climb the containing type chain from the MoveNext method until we find the entry in the dictionary whose
            // value matches one of the classes.
            var done = false;

            foreach (var kv in processorMap)
            {
                if (done)
                {
                    break;
                }
                var c = moveNextMethod.ContainingType as ClassDefinition;
                while (c != null)
                {
                    if (kv.Value == c)
                    {
                        id   = kv.Value.Name + "|" + kv.Key;
                        done = true;
                        break;
                    }
                    c = c.ContainingType as ClassDefinition;
                }
            }

            AddRunToSarifOutput(log, inputPath, id, results);
        }