Files
git.stella-ops.org/src/BinaryIndex/__Libraries/StellaOps.BinaryIndex.Decompiler/DecompilerServiceCollectionExtensions.cs

54 lines
1.8 KiB
C#

// Copyright (c) StellaOps. All rights reserved.
// Licensed under BUSL-1.1. See LICENSE in the project root.
using Microsoft.Extensions.DependencyInjection;
namespace StellaOps.BinaryIndex.Decompiler;
/// <summary>
/// Extension methods for registering decompiler services.
/// </summary>
public static class DecompilerServiceCollectionExtensions
{
/// <summary>
/// Adds decompiler services to the service collection.
/// </summary>
/// <param name="services">The service collection.</param>
/// <returns>The service collection for chaining.</returns>
public static IServiceCollection AddDecompilerServices(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);
// Register parser
services.AddSingleton<IDecompiledCodeParser, DecompiledCodeParser>();
// Register comparison engine
services.AddSingleton<IAstComparisonEngine, AstComparisonEngine>();
// Register normalizer
services.AddSingleton<ICodeNormalizer, CodeNormalizer>();
// Register decompiler service
services.AddScoped<IDecompilerService, GhidraDecompilerAdapter>();
return services;
}
/// <summary>
/// Adds decompiler services with custom options.
/// </summary>
/// <param name="services">The service collection.</param>
/// <param name="configureOptions">Action to configure decompiler options.</param>
/// <returns>The service collection for chaining.</returns>
public static IServiceCollection AddDecompilerServices(
this IServiceCollection services,
Action<DecompilerOptions> configureOptions)
{
ArgumentNullException.ThrowIfNull(services);
ArgumentNullException.ThrowIfNull(configureOptions);
services.Configure(configureOptions);
return services.AddDecompilerServices();
}
}