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