private static File BuildFileCFGAndExtractFileInformation(KeyValuePair<string, XmlDocument> parsedFile) { var traverser = new XmlTraverser (); var metricAnalyzer = new MetricVisitor (); var extractor = new ClassAndFunctionExtractor (); var printer = new ASTPrinter (Console.Out); var cfgcreator = new SuperCFGCreator (); traverser.AddVisitor (extractor); traverser.AddVisitor (metricAnalyzer); traverser.Traverse (parsedFile.Value.FirstChild.NextSibling); cfgcreator.Traverse (parsedFile.Value.FirstChild.NextSibling); var ctlPrep = new CFGCTLPreparation (); ctlPrep.AddSelfLoops (cfgcreator.Graph); File file = new File (parsedFile.Value) { CFG = cfgcreator.Graph, FullPath = parsedFile.Key, Interfaces = extractor.Interfaces.GroupBy (i => i.Name, i => i).ToDictionary (i => i.Key, i => i.ToList ()), Classes = extractor.Classes.GroupBy (c => c.Name, c => c).ToDictionary (c => c.Key, c => c.ToList ()), Closures = extractor.Closures.ToArray (), Functions = extractor.Functions.GroupBy (i => i.Name, i => i).ToDictionary (i => i.Key, i => i.ToList ()) }; return file; }
private static void WPGotoAnalysis(Arguments arguments, Config configuration) { var v = Stopwatch.StartNew(); var folders = Directory.GetDirectories(@"G:\WP"); int counter = 0; var progress = new BikeGuyRidingAnimation(folders.Count()); var locker = new object(); Parallel.ForEach(folders, new ParallelOptions() { MaxDegreeOfParallelism = 7 }, folder => { int myNumber = Interlocked.Increment(ref counter); arguments.Target = Path.Combine(arguments.Target, folder); if (!Directory.Exists(arguments.Target)) return; var projectParser = new ProjectParser(arguments.Target, configuration.PHPSettings); ParseResult parseResult = projectParser.ParseProjectFiles(); foreach (var parsedFile in parseResult.ParsedFiles) { //Console.WriteLine("File: " + parsedFile.Key); var traverser = new XmlTraverser(); var metricVisitor = new MetricVisitor(); traverser.AddVisitor(metricVisitor); traverser.Traverse(parsedFile.Value); if (metricVisitor.Gotos > 0) { lock (locker) { System.IO.File.AppendAllLines(@"C:/pluginDLMessages.txt", new [] { "Goto found in " + parsedFile.Key}); } } } //Console.WriteLine(folder); if ((myNumber % 250) == 0) { Console.WriteLine(myNumber + " plugins scanned.."); } }); Console.WriteLine(v.Elapsed); Environment.Exit(1); }
private static void PrintResults(File file, MetricVisitor metricAnalyzer, TextWriter writer) { writer.WriteLine ("File: " + file.FullPath); writer.WriteLine (" - Total AST nodes: " + metricAnalyzer.TotalNodes); writer.WriteLine (" - Echo statements: " + metricAnalyzer.EchoStatements); writer.WriteLine (" - Sql query strings: " + metricAnalyzer.PotentialSQLQueries); writer.WriteLine (" - Functions: " + file.Functions.Count); foreach (var function in file.Functions.Values) { writer.WriteLine (" - " + function); } writer.WriteLine (" - Classes: " + file.Classes.Count); foreach (var classDef in file.Classes.Values.SelectMany(classDefinition => classDefinition)) { writer.WriteLine (" - " + classDef.Name + " " + classDef.StartLine + " " + classDef.EndLine); writer.WriteLine (" - Methods: " + classDef.Methods.Count); } writer.WriteLine (" - Interfaces: " + file.Interfaces.Count); foreach (var interfaceDef in file.Interfaces.Values.SelectMany(interfaceDef => interfaceDef)) { writer.WriteLine (" - " + interfaceDef.Name + " " + interfaceDef.StartLine + " " + interfaceDef.EndLine); writer.WriteLine (" - Methods: " + interfaceDef.Methods.Count); } writer.WriteLine (" - Closures: " + file.Closures.Length); foreach (var closure in file.Closures) { writer.WriteLine (" - " + closure); } writer.WriteLine (); }
private static File BuildFileCFGAndExtractFileInformation(KeyValuePair<string, XmlDocument> parsedFile) { var traverser = new XmlTraverser(); var metricAnalyzer = new MetricVisitor(); var extractor = new ClassAndFunctionExtractor(); var printer = new ASTPrinter(Console.Out); var cfgcreator = new CFGCreator(); traverser.AddVisitor(extractor); traverser.AddVisitor(metricAnalyzer); traverser.AddVisitor(cfgcreator); //traverser.AddVisitor(printer); traverser.AddVisitors(_components.AstVisitors.ToArray()); traverser.Traverse(parsedFile.Value.FirstChild.NextSibling); foreach (var function in extractor.Functions) { function.File = parsedFile.Key; } foreach (var closure in extractor.Closures) { closure.File = parsedFile.Key; } FunctionsHandler.Instance.CustomFunctions.AddRange(extractor.Functions); foreach (var @class in extractor.Classes) { @class.File = parsedFile.Key; foreach (var method in @class.Methods) { //HACK: This is not a good way to handle this! Should we add a new derived function class called method that includes the class name //-||-: and make a special list for them in the function handler, or is this okay? method.Name = @class.Name + "->" + method.Name; method.File = parsedFile.Key; FunctionsHandler.Instance.CustomFunctions.Add(method); } } //cfgcreator.Graph.VisualizeGraph("graph", Program.Configuration.GraphSettings); var cfgPruner = new CFGPruner(); cfgPruner.Prune(cfgcreator.Graph); //cfgcreator.Graph.VisualizeGraph("graph-pruned", Configuration.GraphSettings); File file = new File(parsedFile.Value) { CFG = cfgcreator.Graph, FullPath = parsedFile.Key, Interfaces = extractor.Interfaces.GroupBy(i => i.Name, i => i).ToDictionary(i => i.Key, i => i.ToList()), Classes = extractor.Classes.GroupBy(c => c.Name, c => c).ToDictionary(c => c.Key, c => c.ToList()), Closures = extractor.Closures.ToArray(), Functions = extractor.Functions.GroupBy(i => i.Name, i => i).ToDictionary(i => i.Key, i => i.ToList()) }; return file; }