Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -28,9 +28,166 @@ internal static class BinaryCommandGroup
|
||||
binary.Add(BuildSymbolsCommand(services, verboseOption, cancellationToken));
|
||||
binary.Add(BuildVerifyCommand(services, verboseOption, cancellationToken));
|
||||
|
||||
// Sprint: SPRINT_20251226_014_BINIDX - New binary analysis commands
|
||||
binary.Add(BuildInspectCommand(services, verboseOption, cancellationToken));
|
||||
binary.Add(BuildLookupCommand(services, verboseOption, cancellationToken));
|
||||
binary.Add(BuildFingerprintCommand(services, verboseOption, cancellationToken));
|
||||
|
||||
return binary;
|
||||
}
|
||||
|
||||
// SCANINT-14: stella binary inspect
|
||||
private static Command BuildInspectCommand(
|
||||
IServiceProvider services,
|
||||
Option<bool> verboseOption,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var fileArg = new Argument<string>("file")
|
||||
{
|
||||
Description = "Path to binary file to inspect."
|
||||
};
|
||||
|
||||
var formatOption = new Option<string>("--format", new[] { "-f" })
|
||||
{
|
||||
Description = "Output format: text (default), json."
|
||||
}.SetDefaultValue("text").FromAmong("text", "json");
|
||||
|
||||
var command = new Command("inspect", "Inspect binary identity (Build-ID, hashes, architecture).")
|
||||
{
|
||||
fileArg,
|
||||
formatOption,
|
||||
verboseOption
|
||||
};
|
||||
|
||||
command.SetAction(parseResult =>
|
||||
{
|
||||
var file = parseResult.GetValue(fileArg)!;
|
||||
var format = parseResult.GetValue(formatOption)!;
|
||||
var verbose = parseResult.GetValue(verboseOption);
|
||||
|
||||
return BinaryCommandHandlers.HandleInspectAsync(
|
||||
services,
|
||||
file,
|
||||
format,
|
||||
verbose,
|
||||
cancellationToken);
|
||||
});
|
||||
|
||||
return command;
|
||||
}
|
||||
|
||||
// SCANINT-15: stella binary lookup
|
||||
private static Command BuildLookupCommand(
|
||||
IServiceProvider services,
|
||||
Option<bool> verboseOption,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var buildIdArg = new Argument<string>("build-id")
|
||||
{
|
||||
Description = "GNU Build-ID to look up (hex string)."
|
||||
};
|
||||
|
||||
var distroOption = new Option<string?>("--distro", new[] { "-d" })
|
||||
{
|
||||
Description = "Distribution (debian, ubuntu, alpine, rhel)."
|
||||
};
|
||||
|
||||
var releaseOption = new Option<string?>("--release", new[] { "-r" })
|
||||
{
|
||||
Description = "Distribution release (bookworm, jammy, v3.19)."
|
||||
};
|
||||
|
||||
var formatOption = new Option<string>("--format", new[] { "-f" })
|
||||
{
|
||||
Description = "Output format: text (default), json."
|
||||
}.SetDefaultValue("text").FromAmong("text", "json");
|
||||
|
||||
var command = new Command("lookup", "Look up vulnerabilities by Build-ID.")
|
||||
{
|
||||
buildIdArg,
|
||||
distroOption,
|
||||
releaseOption,
|
||||
formatOption,
|
||||
verboseOption
|
||||
};
|
||||
|
||||
command.SetAction(parseResult =>
|
||||
{
|
||||
var buildId = parseResult.GetValue(buildIdArg)!;
|
||||
var distro = parseResult.GetValue(distroOption);
|
||||
var release = parseResult.GetValue(releaseOption);
|
||||
var format = parseResult.GetValue(formatOption)!;
|
||||
var verbose = parseResult.GetValue(verboseOption);
|
||||
|
||||
return BinaryCommandHandlers.HandleLookupAsync(
|
||||
services,
|
||||
buildId,
|
||||
distro,
|
||||
release,
|
||||
format,
|
||||
verbose,
|
||||
cancellationToken);
|
||||
});
|
||||
|
||||
return command;
|
||||
}
|
||||
|
||||
// SCANINT-16: stella binary fingerprint
|
||||
private static Command BuildFingerprintCommand(
|
||||
IServiceProvider services,
|
||||
Option<bool> verboseOption,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var fileArg = new Argument<string>("file")
|
||||
{
|
||||
Description = "Path to binary file to fingerprint."
|
||||
};
|
||||
|
||||
var algorithmOption = new Option<string>("--algorithm", new[] { "-a" })
|
||||
{
|
||||
Description = "Fingerprint algorithm: combined (default), basic-block, cfg, string-refs."
|
||||
}.SetDefaultValue("combined").FromAmong("combined", "basic-block", "cfg", "string-refs");
|
||||
|
||||
var functionOption = new Option<string?>("--function")
|
||||
{
|
||||
Description = "Specific function to fingerprint."
|
||||
};
|
||||
|
||||
var formatOption = new Option<string>("--format", new[] { "-f" })
|
||||
{
|
||||
Description = "Output format: text (default), json, hex."
|
||||
}.SetDefaultValue("text").FromAmong("text", "json", "hex");
|
||||
|
||||
var command = new Command("fingerprint", "Generate fingerprint for a binary or function.")
|
||||
{
|
||||
fileArg,
|
||||
algorithmOption,
|
||||
functionOption,
|
||||
formatOption,
|
||||
verboseOption
|
||||
};
|
||||
|
||||
command.SetAction(parseResult =>
|
||||
{
|
||||
var file = parseResult.GetValue(fileArg)!;
|
||||
var algorithm = parseResult.GetValue(algorithmOption)!;
|
||||
var function = parseResult.GetValue(functionOption);
|
||||
var format = parseResult.GetValue(formatOption)!;
|
||||
var verbose = parseResult.GetValue(verboseOption);
|
||||
|
||||
return BinaryCommandHandlers.HandleFingerprintAsync(
|
||||
services,
|
||||
file,
|
||||
algorithm,
|
||||
function,
|
||||
format,
|
||||
verbose,
|
||||
cancellationToken);
|
||||
});
|
||||
|
||||
return command;
|
||||
}
|
||||
|
||||
private static Command BuildSubmitCommand(
|
||||
IServiceProvider services,
|
||||
Option<bool> verboseOption,
|
||||
|
||||
Reference in New Issue
Block a user