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.
50 lines
1.8 KiB
C#
50 lines
1.8 KiB
C#
using System.Text;
|
|
|
|
namespace WhiteMagic;
|
|
|
|
/// <summary>
|
|
/// A pointer-relative view over a <see cref="MemoryBase"/>. Obtained through the
|
|
/// high-level facade indexer, it provides read/write/string operations with optional
|
|
/// offsets relative to a base address.
|
|
/// </summary>
|
|
public sealed class RemotePointer
|
|
{
|
|
private readonly MemoryBase _memory;
|
|
|
|
/// <summary>The base address of this view.</summary>
|
|
public IntPtr BaseAddress { get; }
|
|
|
|
internal RemotePointer(MemoryBase memory, IntPtr baseAddress)
|
|
{
|
|
_memory = memory;
|
|
BaseAddress = baseAddress;
|
|
}
|
|
|
|
/// <summary>Reads a value of type <typeparamref name="T"/> at <c>BaseAddress + offset</c>.</summary>
|
|
public T Read<T>(nint offset = 0) where T : struct
|
|
{
|
|
return _memory.Read<T>(BaseAddress + offset);
|
|
}
|
|
|
|
/// <summary>Writes <paramref name="value"/> at <c>BaseAddress + offset</c>.</summary>
|
|
public bool Write<T>(T value, nint offset = 0) where T : struct
|
|
{
|
|
return _memory.Write(BaseAddress + offset, value);
|
|
}
|
|
|
|
/// <summary>Reads a null-terminated string at <c>BaseAddress + offset</c>.</summary>
|
|
public string ReadString(Encoding encoding, int maxLength = 512, nint offset = 0)
|
|
{
|
|
return _memory.ReadString(BaseAddress + offset, encoding ?? Encoding.UTF8, maxLength);
|
|
}
|
|
|
|
/// <summary>Writes a null-terminated string at <c>BaseAddress + offset</c>.</summary>
|
|
public bool WriteString(string value, Encoding encoding, nint offset = 0)
|
|
{
|
|
return _memory.WriteString(BaseAddress + offset, value, encoding ?? Encoding.UTF8);
|
|
}
|
|
|
|
/// <summary>Returns a new <see cref="RemotePointer"/> with the offset added.</summary>
|
|
public RemotePointer this[nint offset] => new RemotePointer(_memory, BaseAddress + offset);
|
|
}
|