Example #1
0
        /// <summary>
        /// Obtain a map from output columns to their input dependencies
        /// </summary>
        /// <param name="outColumnControlMap"></param>
        /// <returns></returns>
        public MapSet <TraceableColumn, Traceable> ComputeOutputDependencies(out MapSet <TraceableColumn, Traceable> outColumnControlMap)
        {
            DependencyPTGDomain depAnalysisResult            = this;
            MapSet <TraceableColumn, Traceable> outColumnMap = new MapSet <TraceableColumn, Traceable>();

            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]));
                    }
                }
            }
            return(outColumnMap);
        }
Example #2
0
        public MapSet <IFieldReference, PTGNode> GetTargets(PTGNode ptgNode)
        {
            //var result = this.edges.Where(kv => kv.Key.Source.Equals(ptgNode)).GroupBy(kv => kv.Key.Field, kv=> kv.Value);
            //return result.ToDictionary( kv => kv.Key, kv => kv.SelectMany(kv => kv.));
            var result = new MapSet <IFieldReference, PTGNode>();

            foreach (var edge in this.edges.Where(kv => kv.Key.Source.Equals(ptgNode)))
            {
                result.AddRange(edge.Key.Field, edge.Value);
            }
            return(result);
        }
Example #3
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);
        }