Skip to content

Commit

Permalink
support config
Browse files Browse the repository at this point in the history
  • Loading branch information
shaopeng-gh committed Jul 19, 2023
1 parent 60f6f7c commit f7063bc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/BinSkim.Driver/AnalyzeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
4 changes: 2 additions & 2 deletions src/BinSkim.Driver/MultithreadedAnalyzeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
16 changes: 12 additions & 4 deletions src/BinSkim.Sdk/BinaryAnalyzerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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;

Expand Down
14 changes: 13 additions & 1 deletion src/BinaryParsers/BinaryParsersProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public IEnumerable<IOption> GetOptions()
{
return new List<IOption>
{
ComprehensiveBinaryParsing
ComprehensiveBinaryParsing,
IgnorePdbLoadError,
IncludeWixBinaries
}.ToImmutableArray();
}

Expand All @@ -24,5 +26,15 @@ public IEnumerable<IOption> 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<bool> IgnorePdbLoadError { get; } =
new PerLanguageOption<bool>(
"BinaryParsers", nameof(IgnorePdbLoadError), defaultValue: () => false,
"Set this value to 'true' to don't break if we have a 'PdbLoadingException'.");

public static PerLanguageOption<bool> IncludeWixBinaries { get; } =
new PerLanguageOption<bool>(
"BinaryParsers", nameof(IncludeWixBinaries), defaultValue: () => false,
"Set this value to 'true' to include Wix binaries in the analysis.");
}
}

0 comments on commit f7063bc

Please sign in to comment.