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.
63 lines
2.0 KiB
C#
63 lines
2.0 KiB
C#
using System.Diagnostics;
|
|
using Process = System.Diagnostics.Process;
|
|
using WhiteMagic.Execution;
|
|
using WhiteMagic.Hooking;
|
|
|
|
namespace WhiteMagic;
|
|
|
|
/// <summary>
|
|
/// High-level entry point for a WhiteMagic session. Opens a process, exposes the
|
|
/// memory reader, execution tiers, hooking managers, and the <see cref="RemotePointer"/>
|
|
/// indexer.
|
|
/// </summary>
|
|
public sealed class Magic : IDisposable
|
|
{
|
|
/// <summary>The underlying memory reader for this session.</summary>
|
|
public MemoryBase Memory { get; }
|
|
|
|
/// <summary>Out-of-process execution via <c>CreateRemoteThread</c>.</summary>
|
|
public RemoteThreadExecutor RemoteThread { get; }
|
|
|
|
/// <summary>Named byte-patch manager.</summary>
|
|
public PatchManager PatchManager => Memory.PatchManager;
|
|
|
|
/// <summary>Inline-detour manager (in-process only).</summary>
|
|
public DetourManager DetourManager => Memory.DetourManager;
|
|
|
|
private Magic(MemoryBase memory)
|
|
{
|
|
Memory = memory;
|
|
RemoteThread = new RemoteThreadExecutor(memory);
|
|
}
|
|
|
|
/// <summary>Opens an external process for reading, writing, and execution.</summary>
|
|
public static Magic Open(System.Diagnostics.Process process)
|
|
{
|
|
return new Magic(new ExternalReader(process));
|
|
}
|
|
|
|
/// <summary>Creates an in-process session for the current process.</summary>
|
|
public static Magic OpenInProcess()
|
|
{
|
|
return new Magic(new InProcessReader());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a main-thread pump that hooks the per-frame function at
|
|
/// <paramref name="frameAddress"/>.
|
|
/// </summary>
|
|
public MainThreadPump CreateMainThreadPump(IntPtr frameAddress)
|
|
{
|
|
return new MainThreadPump(DetourManager, frameAddress);
|
|
}
|
|
|
|
/// <summary>Returns a <see cref="RemotePointer"/> at <paramref name="address"/>.</summary>
|
|
public RemotePointer this[IntPtr address] => new RemotePointer(Memory, address);
|
|
|
|
/// <inheritdoc />
|
|
public void Dispose()
|
|
{
|
|
Memory.Dispose();
|
|
}
|
|
}
|