// Copyright (c) StellaOps. All rights reserved. // Licensed under BUSL-1.1. See LICENSE in the project root. namespace StellaOps.BinaryIndex.Disassembly; /// /// Abstraction over binary disassembly engine plugins. /// Each plugin implements this interface to provide disassembly capabilities. /// public interface IDisassemblyPlugin { /// /// Gets the capabilities of this disassembly plugin. /// DisassemblyCapabilities Capabilities { get; } /// /// Loads a binary from a stream and detects format/architecture. /// /// The binary stream to load. /// Optional hint for architecture detection. /// Optional hint for format detection. /// Binary information including format, architecture, and metadata. BinaryInfo LoadBinary(Stream stream, CpuArchitecture? archHint = null, BinaryFormat? formatHint = null); /// /// Loads a binary from a byte array. /// /// The binary data. /// Optional hint for architecture detection. /// Optional hint for format detection. /// Binary information including format, architecture, and metadata. BinaryInfo LoadBinary(ReadOnlySpan bytes, CpuArchitecture? archHint = null, BinaryFormat? formatHint = null); /// /// Gets executable code regions (sections) from the binary. /// /// The loaded binary information. /// Enumerable of code regions. IEnumerable GetCodeRegions(BinaryInfo binary); /// /// Gets symbols (functions) from the binary. /// /// The loaded binary information. /// Enumerable of symbol information. IEnumerable GetSymbols(BinaryInfo binary); /// /// Disassembles a code region to instructions. /// /// The loaded binary information. /// The code region to disassemble. /// Enumerable of disassembled instructions. IEnumerable Disassemble(BinaryInfo binary, CodeRegion region); /// /// Disassembles starting at a specific address for a given length. /// /// The loaded binary information. /// Virtual address to start disassembly. /// Maximum number of bytes to disassemble. /// Enumerable of disassembled instructions. IEnumerable Disassemble(BinaryInfo binary, ulong startAddress, ulong length); /// /// Disassembles a specific symbol/function. /// /// The loaded binary information. /// The symbol to disassemble. /// Enumerable of disassembled instructions. IEnumerable DisassembleSymbol(BinaryInfo binary, SymbolInfo symbol); } /// /// Registry for disassembly plugins. Manages plugin discovery and selection. /// public interface IDisassemblyPluginRegistry { /// /// Gets all registered plugins. /// IReadOnlyList Plugins { get; } /// /// Finds the best plugin for the given architecture and format. /// /// Target CPU architecture. /// Target binary format. /// The best matching plugin, or null if none found. IDisassemblyPlugin? FindPlugin(CpuArchitecture architecture, BinaryFormat format); /// /// Finds all plugins that support the given architecture. /// /// Target CPU architecture. /// All matching plugins ordered by priority. IEnumerable FindPluginsForArchitecture(CpuArchitecture architecture); /// /// Finds all plugins that support the given format. /// /// Target binary format. /// All matching plugins ordered by priority. IEnumerable FindPluginsForFormat(BinaryFormat format); /// /// Gets a plugin by its unique identifier. /// /// The plugin identifier. /// The plugin if found, null otherwise. IDisassemblyPlugin? GetPlugin(string pluginId); } /// /// Facade service for disassembly operations. Automatically selects the best plugin. /// public interface IDisassemblyService { /// /// Loads a binary and automatically selects the best plugin. /// /// The binary stream to load. /// Optional preferred plugin ID. /// Binary information and the plugin used. (BinaryInfo Binary, IDisassemblyPlugin Plugin) LoadBinary(Stream stream, string? preferredPluginId = null); /// /// Loads a binary from bytes and automatically selects the best plugin. /// /// The binary data. /// Optional preferred plugin ID. /// Binary information and the plugin used. (BinaryInfo Binary, IDisassemblyPlugin Plugin) LoadBinary(ReadOnlySpan bytes, string? preferredPluginId = null); /// /// Gets the plugin registry. /// IDisassemblyPluginRegistry Registry { get; } }