// -----------------------------------------------------------------------------
// IDecompilerAdapter.cs
// Sprint: SPRINT_20260119_006 ML Embeddings Corpus
// Task: MLEM-004 - Decompiled Code Extraction
// Description: Interface for decompiler integration.
// -----------------------------------------------------------------------------
namespace StellaOps.BinaryIndex.ML.Training;
///
/// Adapter for decompiler integration.
///
public interface IDecompilerAdapter
{
///
/// Decompiles a function to C-like code.
///
/// Library name.
/// Library version.
/// Function name.
/// Cancellation token.
/// Decompiled code.
Task DecompileAsync(
string libraryName,
string version,
string functionName,
CancellationToken cancellationToken = default);
///
/// Decompiles raw bytes to C-like code.
///
/// Function bytes.
/// Target architecture.
/// Decompilation options.
/// Cancellation token.
/// Decompiled code.
Task DecompileBytesAsync(
ReadOnlyMemory bytes,
string architecture,
DecompilationOptions? options = null,
CancellationToken cancellationToken = default);
///
/// Normalizes decompiled code for ML input.
///
/// Raw decompiled code.
/// Normalization options.
/// Normalized code.
string Normalize(string code, NormalizationOptions? options = null);
}
///
/// Options for decompilation.
///
public sealed record DecompilationOptions
{
///
/// Gets the decompiler to use.
///
public DecompilerType Decompiler { get; init; } = DecompilerType.Ghidra;
///
/// Gets whether to simplify the output.
///
public bool Simplify { get; init; } = true;
///
/// Gets the timeout for decompilation.
///
public TimeSpan Timeout { get; init; } = TimeSpan.FromSeconds(30);
///
/// Gets the default options.
///
public static DecompilationOptions Default { get; } = new();
}
///
/// Available decompilers.
///
public enum DecompilerType
{
///
/// Ghidra decompiler.
///
Ghidra,
///
/// RetDec decompiler.
///
RetDec,
///
/// Hex-Rays decompiler (IDA Pro).
///
HexRays
}
///
/// Options for code normalization.
///
public sealed record NormalizationOptions
{
///
/// Gets whether to strip comments.
///
public bool StripComments { get; init; } = true;
///
/// Gets whether to normalize variable names.
///
public bool NormalizeVariables { get; init; } = true;
///
/// Gets whether to normalize whitespace.
///
public bool NormalizeWhitespace { get; init; } = true;
///
/// Gets whether to remove type casts.
///
public bool RemoveTypeCasts { get; init; } = false;
///
/// Gets the maximum length.
///
public int MaxLength { get; init; } = 2048;
///
/// Gets the default options.
///
public static NormalizationOptions Default { get; } = new();
}