protected override void InitializeCore()
        {
            _traversalSequences = ScriptLauncher.LoadTestCases(ScriptResult);

            try
            {
                WriteProbe();
            }
            catch (System.Exception)
            {
                ScannerCli.DisplayCriticalMessageAndExit("Could not create LFI probe. Please run PHPVH as administrator.");
            }

            var path = new DirectoryInfo(Program.Config.WebRoot).Root.ToString();

            watcher                     = new FileSystemWatcher(path);
            watcher.Changed            += watcher_FileSystemEvent;
            watcher.Created            += watcher_FileSystemEvent;
            watcher.Deleted            += watcher_FileSystemEvent;
            watcher.EnableRaisingEvents = true;
        }
Exemple #2
0
        public CodeCoverageTable CalculateCoverage(bool readAnnotations = true)
#endif
        {
            var entryTable = new CodeCoverageTable();

            if (readAnnotations)
            {
                if (!FileReader.Exists())
                {
                    return(entryTable);
                }

                var entries = FileReader.GetLines();

                foreach (var entry in entries)
                {
                    try
                    {
                        var filename = entry.RemoveAtLastIndexOf('_');
                        var id       = int.Parse(entry.SubstringAtLastIndexOf('_', 1));
                        _annotationTable[filename][id].HitCount++;
                    }
#if DEBUG
                    catch (Exception ex)
                    {
                        ScannerCli.DisplayError(ex.ToString());
                    }
#else
                    catch { }
#endif
                }
            }

            Func <Annotation, bool> wasHit = x => x.HitCount > 0;

            lock (_annotationTable)
            {
                var hitBlockCount = (decimal)_annotationTable
                                    .Items
                                    .SelectMany(x => x.Items.Where(wasHit))
                                    .Count();

                var totalBlockCount = _annotationTable
                                      .Items
                                      .SelectMany(x => x.Items)
                                      .Count();

                if (totalBlockCount != 0)
                {
                    entryTable.Total = hitBlockCount / totalBlockCount * 100;
                }

                _annotationTable
                .Items
                .Select(x => new
                {
                    x.Filename,
                    HitBlockCount   = x.Items.Count(wasHit),
                    TotalBlockCount = x.Items.Count,
                    Coverage        = (decimal)x.Items.Count(wasHit) / x.Items.Count * 100,
                })
                .Iter(x => entryTable.Add(x.Filename, x.Coverage));
            }

            entryTable.Plugin = _annotationTable.Plugin;

            return(entryTable);
        }