Beispiel #1
0
        /// <summary>
        /// Generates the warnings report.
        /// </summary>
        /// <param name="output">The output.</param>
        public void GenerateWarnings(OutputBase output)
        {
            output.Headline("Warnings");
            output.EmptyLine();
            output.CommentLine("Total number of warnings: " + GetNumberOfWarnings());


            if (IsFirstPhaseStarted)
            {
                output.CommentLine("Number of analysis warnings in the first phase: " + (analysisWarnings.Count));
                output.CommentLine("Number of security warnings in the first phase: " + (securityWarnings.Count));
            }
            if (IsSecondPhaseStarted)
            {
                output.CommentLine("Number of warnings in the second phase: " + secondPhaseWarnings.Count);
            }

            if (IsFirstPhaseStarted)
            {
                GenerateWarningsOutput(output, analysisWarnings, "First phase analysis warnings");
                GenerateWarningsOutput(output, securityWarnings, "First phase security warnings");
            }
            if (IsSecondPhaseStarted)
            {
                GenerateWarningsOutput(output, secondPhaseWarnings, "Second phase analysis warnings", true);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Generates the final snapshot text representation.
        /// </summary>
        /// <param name="output">The output.</param>
        public void GenerateFinalSnapshotText(OutputBase output)
        {
            output.Headline("Final snapshot content");
            output.EmptyLine();

            if (programPointGraph != null && programPointGraph.End != null && programPointGraph.End.OutSet != null)
            {
                output.CommentLine("Number of memory locations: " + programPointGraph.End.OutSnapshot.NumMemoryLocations());

                Snapshot snapshot = getSnapshot(programPointGraph.End);
                if (snapshot != null)
                {
                    output.CommentLine("Number of variables: " + snapshot.Structure.Readonly.ReadonlyGlobalContext.ReadonlyVariables.Count);
                    output.CommentLine("Number of control variables: " + snapshot.Structure.Readonly.ReadonlyGlobalContext.ReadonlyControllVariables.Count);
                    output.CommentLine("Number of temporary variables: " + snapshot.Structure.Readonly.ReadonlyGlobalContext.ReadonlyTemporaryVariables.Count);
                    output.CommentLine("Number of arrays: " + snapshot.Structure.Readonly.ArrayDescriptors.Count());
                    output.CommentLine("Number of objects: " + snapshot.Structure.Readonly.ObjectDescriptors.Count());

                    SnapshotTextGenerator generator = new SnapshotTextGenerator(output);
                    generator.GenerateSnapshotText(snapshot);
                }
                else
                {
                    output.EmptyLine();
                    output.ProgramPointInfo("", programPointGraph.End);
                }
            }
            else
            {
                output.Error("End point was not reached");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Generates the warnings output.
        /// </summary>
        /// <typeparam name="T">Type of the warning</typeparam>
        /// <param name="output">The output.</param>
        /// <param name="warnings">The warnings.</param>
        /// <param name="headLine">The head line.</param>
        /// <param name="displayTaintFlows">if set to <c>true</c> the display taint flows.</param>
        public void GenerateWarningsOutput <T>(OutputBase output, IReadOnlyCollection <T> warnings, string headLine, bool displayTaintFlows = false) where T : AnalysisWarning
        {
            output.line();
            output.Headline(headLine);
            if (warnings.Count == 0)
            {
                output.line();
                output.comment("No warnings");
                output.line();
            }
            string fileName = "/";
            bool   dedent   = false;

            foreach (var s in warnings)
            {
                if (fileName != s.FullFileName)
                {
                    if (dedent)
                    {
                        output.Dedent();
                    }
                    output.line();
                    fileName = s.FullFileName;
                    output.head2("File: " + fileName);

                    output.Indent();
                    dedent = true;

                    output.line();
                    output.line();
                }
                output.variableInfoLine(s.ToString());
                output.Indent();
                output.line();
                output.hint("Called from: ");
                output.comment(s.ProgramPoint.OwningPPGraph.Context.ToString());
                if (s is AnalysisTaintWarning && displayTaintFlows)
                {
                    output.line();
                    output.hint("Taint propagation: ");
                    output.Indent();
                    output.line();
                    output.comment(((AnalysisTaintWarning)(object)s).TaintFlow);
                    output.Dedent();
                }
                output.Dedent();

                output.line();
            }

            if (dedent)
            {
                output.Dedent();
            }
            output.line();
        }
Beispiel #4
0
        /// <summary>
        /// Generates the output of the analysis.
        /// </summary>
        /// <param name="output">The output.</param>
        public void GenerateOutput(OutputBase output)
        {
            output.EmptyLine();
            output.Headline("Analysis summary");

            if (Watch != null)
            {
                var ts = Watch.Elapsed;

                output.EmptyLine();
                output.Headline2("Time consumption");
                string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
                output.CommentLine("Weverca analyzer time consumption: " + elapsedTime);

                if (IsFirstPhaseStarted)
                {
                    var ts1 = WatchFirstPhase.Elapsed;
                    elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}", ts1.Hours, ts1.Minutes, ts1.Seconds, ts1.Milliseconds);
                    output.CommentLine("First phase time consumption: " + elapsedTime);
                }
                if (IsSecondPhaseStarted)
                {
                    var ts2 = WatchSecondPhase.Elapsed;
                    elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:000}", ts2.Hours, ts2.Minutes, ts2.Seconds, ts2.Milliseconds);
                    output.CommentLine("Second phase time consumption: " + elapsedTime);
                }
            }

            if (FirstPhaseInitialMemory != 0)
            {
                output.EmptyLine();
                output.Headline2("Memory consumption");
                output.CommentLine(string.Format("Initial memory before the first phase: {0}",
                                                 OutputUtils.GetMemoryText(FirstPhaseInitialMemory)
                                                 ));

                if (IsFirstPhaseStarted)
                {
                    output.CommentLine(string.Format("Memory at the end of the first phase: {0} (diff: {1})",
                                                     OutputUtils.GetMemoryText(FirstPhaseEndMemory),
                                                     OutputUtils.GetMemoryText(FirstPhaseEndMemory - FirstPhaseInitialMemory)
                                                     ));
                }
                if (IsSecondPhaseStarted)
                {
                    output.CommentLine(string.Format("Memory at the end of the second phase: {0} (diff: {1})",
                                                     OutputUtils.GetMemoryText(SecondPhaseEndMemory),
                                                     OutputUtils.GetMemoryText(SecondPhaseEndMemory - FirstPhaseEndMemory)
                                                     ));
                }
            }

            output.EmptyLine();
            output.Headline2("Code statistics");

            if (controlFlowGraph != null)
            {
                List <BasicBlock> basicBlocks = controlFlowGraph.CollectAllBasicBlocks();
                output.CommentLine("The number of basic blocks of code is: " + basicBlocks.Count);
            }

            if (programPointGraph != null)
            {
                var programLines          = new Dictionary <string, HashSet <int> >();
                int numberOfProgramPoints = NumProgramPoints(new HashSet <ProgramPointGraph>(), programLines, programPointGraph);
                int numberOfProgramLines  = NumProgramLines(programLines);

                output.CommentLine("The number of processed lines of code is: " + numberOfProgramLines);
                output.CommentLine("The number of program points in the application is: " + numberOfProgramPoints);

                if (programPointGraph.End.OutSet != null)
                {
                    output.CommentLine("The number of memory locations in final snapshot is: " + programPointGraph.End.OutSnapshot.NumMemoryLocations());
                }
                else
                {
                    output.CommentLine("End program point was not reached");
                }
            }
            else
            {
                output.CommentLine("Program point graph was not built");
            }

            output.EmptyLine();
            output.Headline2("Warnings");
            output.CommentLine("Total number of warnings: " + GetNumberOfWarnings());
            if (IsFirstPhaseStarted)
            {
                output.CommentLine("Number of warnings in the first phase: " + (analysisWarnings.Count + securityWarnings.Count));
            }
            if (IsSecondPhaseStarted)
            {
                output.CommentLine("Number of warnings in the second phase: " + secondPhaseWarnings.Count);
            }
        }