Implement core diagnostic memory layer, execution helpers, and high-level facade slices
Implemented: - Core: UTF-16 ReadString boundary/alignment fix, target bitness and process id on MemoryBase - function interception: PatchManager, DetourManager, InstructionAnalyzer, MainThreadDispatcher - Execution: BackgroundTaskExecutor, InProcessInvoker - High-level: Magic facade, RemotePointer, async wrappers - Discovery/external code loading/Window groundwork (PEB/TEB, pattern scanning, raw allocations, DLL external code loading, window/input) Tests: 180 passing, 4 integration/interactive tests skipped.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace WhiteMagic.Hooking;
|
||||
|
||||
/// <summary>
|
||||
/// Manages named inline detours against a <see cref="MemoryBase"/>.
|
||||
/// Detours only work when operating in-process; applying a detour to an
|
||||
/// external target will fail because the hook delegate lives in the host process.
|
||||
/// </summary>
|
||||
public sealed class DetourManager
|
||||
{
|
||||
private readonly MemoryBase _memory;
|
||||
private readonly Dictionary<string, Detour> _detours = new();
|
||||
|
||||
/// <summary>Creates a detour manager bound to the supplied memory reader.</summary>
|
||||
public DetourManager(MemoryBase memory)
|
||||
{
|
||||
_memory = memory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new detour and registers it with the manager.
|
||||
/// The <paramref name="hook"/> delegate's type must match the native signature of
|
||||
/// <paramref name="target"/>.
|
||||
/// </summary>
|
||||
public Detour Create(string name, IntPtr target, Delegate hook)
|
||||
{
|
||||
var detour = new Detour(_memory, name, target, hook);
|
||||
_detours[name] = detour;
|
||||
return detour;
|
||||
}
|
||||
|
||||
/// <summary>Looks up a detour by name.</summary>
|
||||
public Detour? this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
_detours.TryGetValue(name, out Detour? detour);
|
||||
return detour;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>All detours registered in this manager.</summary>
|
||||
public IEnumerable<Detour> All => _detours.Values;
|
||||
|
||||
/// <summary>Removes every applied detour, restoring original bytes.</summary>
|
||||
public void RemoveAll()
|
||||
{
|
||||
foreach (Detour detour in _detours.Values)
|
||||
{
|
||||
detour.Remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user