diff --git a/src/BinSkim.Rules/DwarfRules/BA4002.ReportDwarfCompilerData.cs b/src/BinSkim.Rules/DwarfRules/BA4002.ReportDwarfCompilerData.cs index 3f213dc01..a10a65159 100644 --- a/src/BinSkim.Rules/DwarfRules/BA4002.ReportDwarfCompilerData.cs +++ b/src/BinSkim.Rules/DwarfRules/BA4002.ReportDwarfCompilerData.cs @@ -85,7 +85,9 @@ private void PrintCompilerData(BinaryAnalyzerContext context, List kv in records) { - context.CompilerDataLogger.Write(kv.Key, kv.Value); + context.CompilerDataLogger.Write(kv.Key); } } } diff --git a/src/BinSkim.Sdk/CompilerData.cs b/src/BinSkim.Sdk/CompilerData.cs index 1429ea773..2a1f7b120 100644 --- a/src/BinSkim.Sdk/CompilerData.cs +++ b/src/BinSkim.Sdk/CompilerData.cs @@ -8,9 +8,11 @@ public struct CompilerData public string Dialect { get; set; } public string Language { get; set; } public string BinaryType { get; set; } + public string ModuleName { get; set; } public string CommandLine { get; set; } public string FileVersion { get; set; } public string CompilerName { get; set; } + public string ModuleLibrary { get; set; } public string DebuggingFileName { get; set; } public string DebuggingFileGuid { get; set; } public string CompilerBackEndVersion { get; set; } @@ -18,7 +20,7 @@ public struct CompilerData public override string ToString() { - return $"{CompilerName},{CompilerBackEndVersion},{CompilerFrontEndVersion},{FileVersion},{BinaryType},{Language},{DebuggingFileName},{DebuggingFileGuid},{CommandLine},{Dialect}"; + return $"{CompilerName},{CompilerBackEndVersion},{CompilerFrontEndVersion},{FileVersion},{BinaryType},{Language},{DebuggingFileName},{DebuggingFileGuid},{CommandLine},{Dialect},{ModuleName},{(ModuleLibrary == ModuleName ? string.Empty : ModuleLibrary)}"; } } } diff --git a/src/BinSkim.Sdk/CompilerDataLogger.cs b/src/BinSkim.Sdk/CompilerDataLogger.cs index 93d5b97f4..c2c51a830 100644 --- a/src/BinSkim.Sdk/CompilerDataLogger.cs +++ b/src/BinSkim.Sdk/CompilerDataLogger.cs @@ -9,7 +9,6 @@ using Microsoft.ApplicationInsights; using Microsoft.ApplicationInsights.Extensibility; -using Microsoft.CodeAnalysis.BinaryParsers.ProgramDatabase; using Microsoft.CodeAnalysis.Sarif; namespace Microsoft.CodeAnalysis.IL.Sdk @@ -119,10 +118,8 @@ public void PrintHeader() } } - public void Write(CompilerData compilerData, ObjectModuleDetails omDetails) + public void Write(CompilerData compilerData) { - string name = omDetails?.Name; - string library = omDetails?.Library; if (TelemetryEnabled) { string commandLineId = string.Empty; @@ -135,55 +132,11 @@ public void Write(CompilerData compilerData, ObjectModuleDetails omDetails) { "fileVersion", compilerData.FileVersion ?? string.Empty }, { "binaryType", compilerData.BinaryType }, { "language", compilerData.Language }, - { "debuggingFileName", compilerData.DebuggingFileName }, - { "debuggingGuid", compilerData.DebuggingFileGuid }, - { "dialect", compilerData.Dialect }, - { "moduleName", name ?? string.Empty }, - { "moduleLibrary", (name == library ? string.Empty : library) }, - { "sessionId", s_sessionId }, - { "hash", this.sha256 }, - { "error", string.Empty } - }; - - if (!string.IsNullOrWhiteSpace(compilerData.CommandLine)) - { - commandLineId = Guid.NewGuid().ToString(); - properties.Add("commandLineId", commandLineId); - } - - s_telemetryClient.TrackEvent(CompilerEventName, properties: properties); - - if (!string.IsNullOrWhiteSpace(commandLineId)) - { - SendChunkedCommandLine(commandLineId, compilerData.CommandLine); - } - } - else - { - string log = $@"{this.relativeFilePath},{compilerData},,""{name}"",""{(name == library ? string.Empty : library)}"",{this.sha256},"; - Console.WriteLine(log); - } - } - - public void Write(CompilerData compilerData, string file) - { - if (TelemetryEnabled) - { - string commandLineId = string.Empty; - var properties = new Dictionary - { - { "target", this.relativeFilePath }, - { "compilerName", compilerData.CompilerName }, - { "compilerBackEndVersion", compilerData.CompilerBackEndVersion }, - { "compilerFrontEndVersion", compilerData.CompilerFrontEndVersion }, - { "fileVersion", string.Empty }, - { "binaryType", compilerData.BinaryType }, - { "language", compilerData.Language }, { "debuggingFileName", compilerData.DebuggingFileName ?? string.Empty }, { "debuggingGuid", compilerData.DebuggingFileGuid ?? string.Empty }, { "dialect", compilerData.Dialect }, - { "moduleName", file ?? string.Empty }, - { "moduleLibrary", string.Empty }, + { "moduleName", compilerData.ModuleName ?? string.Empty }, + { "moduleLibrary", (compilerData.ModuleName == compilerData.ModuleLibrary ? string.Empty : compilerData.ModuleLibrary ?? string.Empty) }, { "sessionId", s_sessionId }, { "hash", this.sha256 }, { "error", string.Empty } @@ -204,7 +157,7 @@ public void Write(CompilerData compilerData, string file) } else { - string log = $"{this.relativeFilePath},{compilerData},,{file},,{this.sha256},"; + string log = $"{this.relativeFilePath},{compilerData},{this.sha256},"; Console.WriteLine(log); } } diff --git a/src/ReleaseHistory.md b/src/ReleaseHistory.md index c84a4b4c9..5d8750e49 100644 --- a/src/ReleaseHistory.md +++ b/src/ReleaseHistory.md @@ -2,6 +2,7 @@ ## Unreleased +* BUGFIX: Change compiler report rule to report all modules in file. [#476](https://github.com/microsoft/binskim/pull/476) * FEATURE: Add dialects to the reporting rules. [#475](https://github.com/microsoft/binskim/pull/475) * BUGFIX: Fix exception `System.AccessViolationException` caused by trying to read data out of boundary. [#470](https://github.com/microsoft/binskim/pull/470) * BUGFIX: Fix exception handling when PDB cannot be loaded by `IDiaDataSource`. [#461](https://github.com/microsoft/binskim/pull/461)