From f7063bccf85a18528d20d8cf6708450a8f9cfc47 Mon Sep 17 00:00:00 2001 From: Shaopeng Li Date: Tue, 18 Jul 2023 23:38:45 -0700 Subject: [PATCH] support config --- src/BinSkim.Driver/AnalyzeOptions.cs | 4 ++-- .../MultithreadedAnalyzeCommand.cs | 4 ++-- src/BinSkim.Sdk/BinaryAnalyzerContext.cs | 16 ++++++++++++---- src/BinaryParsers/BinaryParsersProperties.cs | 14 +++++++++++++- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/BinSkim.Driver/AnalyzeOptions.cs b/src/BinSkim.Driver/AnalyzeOptions.cs index dc0139328..175486f1b 100644 --- a/src/BinSkim.Driver/AnalyzeOptions.cs +++ b/src/BinSkim.Driver/AnalyzeOptions.cs @@ -51,11 +51,11 @@ public class AnalyzeOptions : AnalyzeOptionsBase [Option( "ignorePdbLoadError", HelpText = "If enabled, BinSkim won't break if we have a 'PdbLoadingException'.")] - public bool IgnorePdbLoadError { get; set; } + public bool? IgnorePdbLoadError { get; set; } [Option( "includeWixBinaries", HelpText = "If enabled, BinSkim will include Wix binaries in the analysis.")] - public bool IncludeWixBinaries { get; set; } + public bool? IncludeWixBinaries { get; set; } } } diff --git a/src/BinSkim.Driver/MultithreadedAnalyzeCommand.cs b/src/BinSkim.Driver/MultithreadedAnalyzeCommand.cs index c1d210522..ad4f2c643 100644 --- a/src/BinSkim.Driver/MultithreadedAnalyzeCommand.cs +++ b/src/BinSkim.Driver/MultithreadedAnalyzeCommand.cs @@ -69,8 +69,8 @@ public override BinaryAnalyzerContext InitializeGlobalContextFromOptions(Analyze // Update context object based on command-line parameters. context.SymbolPath = options.SymbolsPath; - context.IncludeWixBinaries = options.IncludeWixBinaries; - context.IgnorePdbLoadError = options.IgnorePdbLoadError; + context.IncludeWixBinaries = options.IncludeWixBinaries != null ? options.IncludeWixBinaries.Value : context.IncludeWixBinaries; + context.IgnorePdbLoadError = options.IgnorePdbLoadError != null ? options.IgnorePdbLoadError.Value : context.IgnorePdbLoadError; context.LocalSymbolDirectories = options.LocalSymbolDirectories; context.TracePdbLoads = options.Trace.Contains(nameof(Traces.PdbLoad)); diff --git a/src/BinSkim.Sdk/BinaryAnalyzerContext.cs b/src/BinSkim.Sdk/BinaryAnalyzerContext.cs index 2fc54c717..613290e97 100644 --- a/src/BinSkim.Sdk/BinaryAnalyzerContext.cs +++ b/src/BinSkim.Sdk/BinaryAnalyzerContext.cs @@ -42,8 +42,8 @@ public override bool IsValidAnalysisTarget public bool ComprehensiveBinaryParsing { - get { return this.Policy?.GetProperty(BinaryParsersProperties.ComprehensiveBinaryParsing) == true; } - set { this.Policy.SetProperty(BinaryParsersProperties.ComprehensiveBinaryParsing, value); } + get => this.Policy?.GetProperty(BinaryParsersProperties.ComprehensiveBinaryParsing) == true; + set => this.Policy.SetProperty(BinaryParsersProperties.ComprehensiveBinaryParsing, value); } public bool TracePdbLoads { get; set; } @@ -77,9 +77,17 @@ public CompilerDataLogger CompilerDataLogger set { this.Policy.SetProperty(SharedCompilerDataLoggerProperty, value); } } - public bool IgnorePdbLoadError { get; set; } + public bool IgnorePdbLoadError + { + get => this.Policy?.GetProperty(BinaryParsersProperties.IgnorePdbLoadError) == true; + set => this.Policy.SetProperty(BinaryParsersProperties.IgnorePdbLoadError, value); + } - public bool IncludeWixBinaries { get; set; } + public bool IncludeWixBinaries + { + get => this.Policy?.GetProperty(BinaryParsersProperties.IncludeWixBinaries) == true; + set => this.Policy.SetProperty(BinaryParsersProperties.IncludeWixBinaries, value); + } internal bool disposed = false; diff --git a/src/BinaryParsers/BinaryParsersProperties.cs b/src/BinaryParsers/BinaryParsersProperties.cs index b0577a52a..47b90b60a 100644 --- a/src/BinaryParsers/BinaryParsersProperties.cs +++ b/src/BinaryParsers/BinaryParsersProperties.cs @@ -15,7 +15,9 @@ public IEnumerable GetOptions() { return new List { - ComprehensiveBinaryParsing + ComprehensiveBinaryParsing, + IgnorePdbLoadError, + IncludeWixBinaries }.ToImmutableArray(); } @@ -24,5 +26,15 @@ public IEnumerable GetOptions() "BinaryParsers", nameof(ComprehensiveBinaryParsing), defaultValue: () => false, "Set this value to 'true' to aggressively fault in all binary data on scan target load. " + "This is useful to flush out exceptions and other issues in various binary parsers."); + + public static PerLanguageOption IgnorePdbLoadError { get; } = + new PerLanguageOption( + "BinaryParsers", nameof(IgnorePdbLoadError), defaultValue: () => false, + "Set this value to 'true' to don't break if we have a 'PdbLoadingException'."); + + public static PerLanguageOption IncludeWixBinaries { get; } = + new PerLanguageOption( + "BinaryParsers", nameof(IncludeWixBinaries), defaultValue: () => false, + "Set this value to 'true' to include Wix binaries in the analysis."); } }