public override int Analyze() { using (var outputStream = File.Create(OutputFilePath, bufferSize: 64 << 10 /* 64 KB */)) { using (var writer = new StreamWriter(outputStream)) { foreach (var observedAccess in m_observedAccessMap.OrderBy(kvp => PipGraph.GetPipFromPipId(kvp.Key).SemiStableHash)) { if (TargetPip == null || TargetPip.Value == PipGraph.GetPipFromPipId(observedAccess.Key).SemiStableHash) { writer.WriteLine("{0})", PipGraph.GetPipFromPipId(observedAccess.Key).GetDescription(PipGraph.Context)); writer.WriteLine(" ObservedAccessByPath:{0}", observedAccess.Value.Count); var accesses = SortPaths ? observedAccess.Value.OrderBy(item => item.GetPath(PathTable)) : (IEnumerable <ReportedFileAccess>)observedAccess.Value; foreach (var access in accesses) { writer.WriteLine(" Path = {0}", (access.Path ?? access.ManifestPath.ToString(PathTable)).ToUpperInvariant()); writer.WriteLine(" {0}", access.Describe()); } writer.WriteLine(); } } } } return(0); }
public override int Analyze() { using (var outputStream = File.Create(OutputFilePath, bufferSize: 64 << 10 /* 64 KB */)) { using (var streamWriter = new StreamWriter(outputStream)) using (JsonWriter writer = new JsonTextWriter(streamWriter)) { writer.Formatting = Formatting.Indented; writer.WriteStartArray(); foreach (var observedInputSet in m_observedInputsMap.OrderBy(kvp => PipGraph.GetPipFromPipId(kvp.Key).SemiStableHash)) { writer.WriteStartObject(); writer.WritePropertyName("Pip"); WritePipJson(writer, PipGraph.GetPipFromPipId(observedInputSet.Key), CachedGraph.Context); writer.WritePropertyName("ObservedInputHashesByPath"); writer.WriteStartObject(); foreach (var observedInput in observedInputSet.Value) { foreach (var file in observedInput.OrderBy(item => item.Path.ToString(PathTable))) { writer.WritePropertyName(file.Path.ToString(CachedGraph.Context.PathTable).ToCanonicalizedPath()); writer.WriteStartObject(); WriteJsonProperty(writer, "ContentHash", file.Hash.ToString()); WriteJsonProperty(writer, "Type", file.Type.ToString()); WriteJsonProperty(writer, "DirectoryEnumeration", file.DirectoryEnumeration); WriteJsonProperty(writer, "IsDirectoryPath", file.IsDirectoryPath); WriteJsonProperty(writer, "IsSearchPath", file.IsSearchPath); writer.WriteEndObject(); } } writer.WriteEndObject(); writer.WriteEndObject(); } writer.WriteEndArray(); } } return(0); }
public override int Analyze() { using (var outputStream = File.Create(OutputFilePath, bufferSize: 64 << 10 /* 64 KB */)) { using (var writer = new StreamWriter(outputStream)) { foreach (var processDetouringSet in m_processDetouringsMap.OrderBy(kvp => PipGraph.GetPipFromPipId(kvp.Key).SemiStableHash)) { if (processDetouringSet.Value != null) { foreach (var processDetouring in processDetouringSet.Value) { if (TargetSemiStableHash == 0 || processDetouringSet.Key.Value == TargetSemiStableHash) { writer.WriteLine("{0})", PipGraph.GetPipFromPipId(processDetouringSet.Key).GetDescription(PipGraph.Context)); writer.WriteLine(" ProcessName = {0}", processDetouring.ProcessName); writer.WriteLine(" ProcessId = {0}", processDetouring.ProcessId); writer.WriteLine(" ReportStatus = {0}", processDetouring.ReportStatus); writer.WriteLine(" StartApplicationName = {0}", processDetouring.StartApplicationName); writer.WriteLine(" StartCommandLine = {0}", processDetouring.StartCommandLine); writer.WriteLine(" NeedsInjection = {0}", processDetouring.NeedsInjection); writer.WriteLine(" Job = {0}", processDetouring.Job); writer.WriteLine(" DisableDetours = {0}", processDetouring.DisableDetours); writer.WriteLine(" CreationFlags = {0}", processDetouring.CreationFlags); writer.WriteLine(" Detoured = {0}", processDetouring.Detoured); writer.WriteLine(" Error = {0}", processDetouring.Error); writer.WriteLine(" CreateProcessStatusReturn = {0}", processDetouring.CreateProcessStatusReturn); writer.WriteLine(); } } } } } } return(0); }
/// <inheritdoc/> public override void DependencyViolationReported(DependencyViolationEventData data) { // JavaScript projects are scheduled with allowed undeclared source reads mode on // So any undeclared violation manifests as a write on an undeclared source read if (data.ViolationType != Scheduler.FileMonitoringViolationAnalyzer.DependencyViolationType.WriteInUndeclaredSourceRead) { return; } // Put together the project that reads (without a declaration) - as the key - from all the projects that write - as the value - var reader = (Process)PipGraph.GetPipFromPipId(data.ViolatorPipId); var writer = (Process)PipGraph.GetPipFromPipId(data.RelatedPipId); if (m_missingDependencies.TryGetValue(reader, out var writers)) { writers.Add(writer); } else { m_missingDependencies[reader] = new HashSet <Process> { writer }; } }
public override int Analyze() { Console.WriteLine($"ObservedAccessAnalyzer: Starting analysis of {m_observedAccessMap.Count} observed access map entries at {DateTime.Now}."); int totalAccesses = 0; using (var outputStream = File.Create(OutputFilePath, bufferSize: 64 << 10 /* 64 KB */)) { using (var writer = new StreamWriter(outputStream)) { foreach (var observedAccess in m_observedAccessMap.OrderBy(kvp => PipGraph.GetPipFromPipId(kvp.Key).SemiStableHash)) { if (TargetPip == null || TargetPip.Value == PipGraph.GetPipFromPipId(observedAccess.Key).SemiStableHash) { writer.WriteLine("{0})", PipGraph.GetPipFromPipId(observedAccess.Key).GetDescription(PipGraph.Context)); writer.WriteLine(" ObservedAccessByPath:{0}", observedAccess.Value.Count); var accesses = SortPaths ? observedAccess.Value.OrderBy(item => item.GetPath(PathTable)) : (IEnumerable <ReportedFileAccess>)observedAccess.Value; foreach (var access in accesses) { writer.WriteLine(" Path = {0}", (access.Path ?? access.ManifestPath.ToString(PathTable)).ToCanonicalizedPath()); writer.WriteLine(" {0}", access.Describe()); totalAccesses++; } writer.WriteLine(); } } } } Console.WriteLine($"ObservedAccessAnalyzer: Dumped information on {m_observedAccessMap.Count} observed access map entries and {totalAccesses} total accesses at {DateTime.Now}."); return(0); }
public override int Analyze() { int absentPathCount = 0; int directoryEnumerationCount = 0; int fileContentReadCount = 0; int existingDirectoryCount = 0; Dictionary <AbsolutePath, int> paths = new Dictionary <AbsolutePath, int>(); Dictionary <PathAtom, int> files = new Dictionary <PathAtom, int>(); using (var outputStream = File.Create(OutputFilePath, bufferSize: 64 << 10 /* 64 KB */)) { using (var writer = new StreamWriter(outputStream)) { foreach (var observedInputSet in m_observedInputsMap.OrderBy(kvp => PipGraph.GetPipFromPipId(kvp.Key).SemiStableHash)) { foreach (var observedInput in observedInputSet.Value) { foreach (var file in observedInput.OrderBy(item => item.Path.ToString(PathTable))) { int pathCount = 0; paths.TryGetValue(file.Path, out pathCount); pathCount++; paths[file.Path] = pathCount; int fileCount = 0; var atom = file.Path.GetName(PipGraph.Context.PathTable); files.TryGetValue(atom, out fileCount); fileCount++; files[atom] = fileCount; switch (file.Type) { case ObservedInputType.AbsentPathProbe: absentPathCount++; break; case ObservedInputType.DirectoryEnumeration: directoryEnumerationCount++; break; case ObservedInputType.FileContentRead: fileContentReadCount++; break; case ObservedInputType.ExistingDirectoryProbe: existingDirectoryCount++; break; default: throw new NotImplementedException(); } } } } writer.WriteLine("AbsentPathProbe count: " + absentPathCount); writer.WriteLine("DirectoryEnumeration count: " + directoryEnumerationCount); writer.WriteLine("FileContentRead count: " + fileContentReadCount); writer.WriteLine("existingDirectory count: " + existingDirectoryCount); writer.WriteLine(); writer.WriteLine(); writer.WriteLine("Paths:"); foreach (var item in paths.OrderByDescending(kvp => kvp.Value)) { writer.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0,-10}", item.Value) + item.Key.ToString(CachedGraph.Context.PathTable)); } writer.WriteLine(); writer.WriteLine(); writer.WriteLine("Files:"); foreach (var item in files.OrderByDescending(kvp => kvp.Value)) { writer.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0,-10}", item.Value) + item.Key.ToString(CachedGraph.Context.PathTable.StringTable)); } } } return(0); }
public override int Analyze() { Console.WriteLine($"NOTE: {FilesystemWarning}"); Console.WriteLine($"ExtraDependenciesAnalyzer: Starting analysis of {m_observedAccessMap.Count} observed access map entries at {DateTime.Now}."); var jsonPips = new JArray(); var pathTable = PipGraph.Context.PathTable; var jsonSerializer = new JsonSerializer(); jsonSerializer.Formatting = Formatting.Indented; using (var outputFileStream = File.Create(OutputFilePath, bufferSize: 64 << 10 /* 64 KB */)) using (var outputFileStreamWriter = new StreamWriter(outputFileStream)) using (var jsonTextWriter = new JsonTextWriter(outputFileStreamWriter)) { foreach (var observedAccess in m_observedAccessMap.OrderBy(kvp => PipGraph.GetPipFromPipId(kvp.Key).SemiStableHash)) { var pip = PipGraph.GetPipFromPipId(observedAccess.Key); if (pip.PipType != Pips.Operations.PipType.Process) { continue; } if (TargetPip == null || TargetPip.Value == pip.SemiStableHash) { var jsonPip = new JObject(); jsonPip.Add("Description", pip.GetDescription(PipGraph.Context)); var jsonExtraDeps = new JArray(); var accesses = observedAccess.Value; var processPip = (Pips.Operations.Process)pip; var pipInputFiles = processPip.Dependencies .Select(file => { var filePath = file.Path.ToString(pathTable); return(new KeyValuePair <string, ulong>(filePath, m_filePathIdMap.GetFileId(filePath))); }); var observedFileReads = accesses .Where(access => access.RequestedAccess.HasFlag(RequestedAccess.Read)) .Select(GetAccessPath) .Select(m_filePathIdMap.GetFileId) .ToHashSet(); var extraDependencies = new List <string>(); // extraDependencies = pipInputFiles - observedFileReads foreach (var pipInputFile in pipInputFiles) { if (!observedFileReads.Contains(pipInputFile.Value)) { extraDependencies.Add(pipInputFile.Key); } } extraDependencies.Sort(StringComparer.OrdinalIgnoreCase); foreach (var extraDep in extraDependencies) { jsonExtraDeps.Add(extraDep); } jsonPip.Add("ExtraDeps", jsonExtraDeps); jsonPips.Add(jsonPip); } } jsonSerializer.Serialize(jsonTextWriter, jsonPips); } Console.WriteLine($"ExtraDependenciesAnalyzer: Finished analysis at {DateTime.Now}."); return(0); }
public override int Analyze() { if (ListFilePath != null) { using (var outputStream = File.Create(ListFilePath, bufferSize: 64 << 10 /* 64 KB */)) { using (var writer = new StreamWriter(outputStream)) { foreach (var reportedProcesses in m_reportedProcesses.OrderBy(kvp => PipGraph.GetPipFromPipId(kvp.Key).SemiStableHash)) { var pipDescription = PipGraph.GetPipFromPipId(reportedProcesses.Key).GetDescription(PipGraph.Context); if (reportedProcesses.Value != null) { foreach (var reportedProcess in reportedProcesses.Value) { if (TargetSemiStableHash == 0 || reportedProcesses.Key.Value == TargetSemiStableHash) { writer.WriteLine("{0}", pipDescription); writer.WriteLine(" Path = {0}", reportedProcess.Path); writer.WriteLine(" ProcessId = {0}", reportedProcess.ProcessId); writer.WriteLine(" ParentProcessId = {0}", reportedProcess.ProcessId); writer.WriteLine(" ProcessArgs = {0}", reportedProcess.ProcessArgs); writer.WriteLine(" ExitCode = {0}", reportedProcess.ExitCode); writer.WriteLine(" CreationTime = {0}", reportedProcess.CreationTime); writer.WriteLine(" ExitTime = {0}", reportedProcess.ExitTime); writer.WriteLine(" KernelTime = {0}", reportedProcess.KernelTime); writer.WriteLine(" UserTime = {0}", reportedProcess.UserTime); writer.WriteLine(" Read.Operations = {0}", reportedProcess.IOCounters.ReadCounters.OperationCount); writer.WriteLine(" Read.Bytes = {0}", reportedProcess.IOCounters.ReadCounters.TransferCount); writer.WriteLine(" Write.Operations = {0}", reportedProcess.IOCounters.WriteCounters.OperationCount); writer.WriteLine(" Write.Bytes = {0}", reportedProcess.IOCounters.WriteCounters.TransferCount); writer.WriteLine(" Other.Operations = {0}", reportedProcess.IOCounters.OtherCounters.OperationCount); writer.WriteLine(" Other.Bytes = {0}", reportedProcess.IOCounters.OtherCounters.TransferCount); writer.WriteLine(); } } } } } } } if (SummaryFilePath != null) { using (var outputStream = File.Create(SummaryFilePath, bufferSize: 64 << 10 /* 64 KB */)) { using (var writer = new StreamWriter(outputStream)) { foreach (var pathSummary in m_summaryByPath.OrderBy(kvp => kvp.Key)) { writer.WriteLine("{0}", pathSummary.Key); writer.WriteLine(" PipCount = {0}", pathSummary.Value.Pips.Count()); writer.WriteLine(" Count = {0}", pathSummary.Value.Count); writer.WriteLine(" ZeroExitCodeCount = {0}", pathSummary.Value.ZeroExitCodeCount); writer.WriteLine(" WallClockTime = {0}", pathSummary.Value.WallClockTime); writer.WriteLine(" KernelTime = {0}", pathSummary.Value.KernelTime); writer.WriteLine(" UserTime = {0}", pathSummary.Value.UserTime); writer.WriteLine(); } } } } return(0); }