ARchive old spec
This commit is contained in:
@@ -12,6 +12,13 @@ namespace WhiteMagic;
|
||||
/// empty / zero bytes) on invalid or protected addresses instead of crashing
|
||||
/// the host process with an <see cref="AccessViolationException"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This is functionally equivalent to <see cref="ExternalReader"/> opened on the current
|
||||
/// process. It exists as a distinct type because the design (see
|
||||
/// <c>openspec/changes/whitemagic-foundation/design.md</c> D1) treats "injected in-process"
|
||||
/// as a separate mode from "external". The two modes will diverge further once the
|
||||
/// <c>InProcessInvoker</c> delegate-call path lands.
|
||||
/// </remarks>
|
||||
public sealed class InProcessReader : MemoryBase
|
||||
{
|
||||
private readonly SafeMemoryHandle _handle;
|
||||
@@ -35,7 +42,16 @@ public sealed class InProcessReader : MemoryBase
|
||||
$"OpenProcess failed for PID {current.Id}: error {error}");
|
||||
}
|
||||
|
||||
_imageBase = current.MainModule?.BaseAddress ?? IntPtr.Zero;
|
||||
// Process.MainModule rarely throws on the current process, but guard it
|
||||
// nonetheless for parity with ExternalReader.
|
||||
try
|
||||
{
|
||||
_imageBase = current.MainModule?.BaseAddress ?? IntPtr.Zero;
|
||||
}
|
||||
catch (System.ComponentModel.Win32Exception)
|
||||
{
|
||||
_imageBase = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -50,18 +66,7 @@ public sealed class InProcessReader : MemoryBase
|
||||
if (isRelative)
|
||||
address = GetAbsolute(address);
|
||||
|
||||
byte[] buffer = new byte[count];
|
||||
if (!NativeMethods.ReadProcessMemory(_handle, address, buffer, count, out nint bytesRead))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
if ((int)bytesRead != count)
|
||||
{
|
||||
Array.Resize(ref buffer, (int)bytesRead);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
return RpmHelper.ReadBytes(_handle, address, count);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -70,12 +75,7 @@ public sealed class InProcessReader : MemoryBase
|
||||
if (isRelative)
|
||||
address = GetAbsolute(address);
|
||||
|
||||
if (!NativeMethods.WriteProcessMemory(_handle, address, bytes, bytes.Length, out nint written))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (int)written;
|
||||
return RpmHelper.WriteBytes(_handle, address, bytes);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user