Files
kbe c40f3fd791 Fix InputSimulator wParam, PeHeaderParser double-parse, and other review issues
Bug fixes:
- InputSimulator: Pass correct button state (MK_LBUTTON/MK_RBUTTON) in wParam for button-down messages instead of 0.
- PeHeaderParser: ParseOptionalHeader now reads only the optional header, not section headers (fixes double-parse waste).
- EntryPoint: Removed useless isPe32Plus branch (AddressOfEntryPoint is at offset 16 in both PE32 and PE32+).
- RemoteWindow: Handle null foreground window case in Activate to avoid calling GetWindowThreadProcessId with HWND 0.
- RemotePointer: Remove dead null-conditional operators (encoding ??) since encoding is non-nullable.

Constants added:
- SystemMethods: MkLButton (0x0001) and MkRButton (0x0002) for mouse button state flags.

Tests: 199 passing, 4 integration/interactive skipped.
2026-07-22 01:28:42 +02:00

51 lines
1.7 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, 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);
}
/// <summary>Returns a new <see cref="RemotePointer"/> with the offset added.</summary>
public RemotePointer this[nint offset] => new RemotePointer(_memory, BaseAddress + offset);
}