Add memory-region query, enumeration, and scoped protection

Implements VirtualQueryEx + MEMORY_BASIC_INFORMATION wrappers, the immutable MemoryRegion record, the ProtectionScope disposable helper, and MemoryBase.QueryRegion/EnumerateRegions/ChangeProtection. Closes section 1 of add-thread-region-finder.
This commit is contained in:
kbe
2026-07-22 16:04:15 +02:00
parent e8c84f0ba1
commit f0faca3112
7 changed files with 504 additions and 0 deletions
+58
View File
@@ -156,3 +156,61 @@ public static class ContextFlags
/// <summary>AMD64: control, integer, and segment registers.</summary>
public const uint Amd64Full = Amd64Control | Amd64Integer | Amd64Segments;
}
/// <summary>
/// Values that describe the state of memory pages returned by <c>VirtualQueryEx</c>.
/// </summary>
public enum MemoryState : uint
{
/// <summary>Indicates committed pages for which physical storage has been allocated.</summary>
Commit = 0x1000,
/// <summary>Indicates reserved pages where a range of the virtual address space is reserved without any physical storage being allocated.</summary>
Reserve = 0x2000,
/// <summary>Indicates free pages not accessible to the calling process and available to be allocated.</summary>
Free = 0x10000,
}
/// <summary>
/// Values that describe the type of memory pages returned by <c>VirtualQueryEx</c>.
/// </summary>
public enum MemoryType : uint
{
/// <summary>Indicates that the memory pages within the region are private.</summary>
Private = 0x20000,
/// <summary>Indicates that the memory pages within the region are mapped into the view of a section.</summary>
Mapped = 0x40000,
/// <summary>Indicates that the memory pages within the region are mapped into the view of an image section.</summary>
Image = 0x1000000,
}
/// <summary>
/// Flags used by <c>CreateToolhelp32Snapshot</c> to specify the portions of the system to include in the snapshot.
/// </summary>
[Flags]
public enum SnapshotFlags : uint
{
/// <summary>Enumerate the heap list.</summary>
HeapList = 0x00000001,
/// <summary>Enumerate the process list.</summary>
Process = 0x00000002,
/// <summary>Enumerate the thread list.</summary>
Thread = 0x00000004,
/// <summary>Enumerate the module list.</summary>
Module = 0x00000008,
/// <summary>Enumerate the 32-bit module list for the specified process.</summary>
Module32 = 0x00000010,
/// <summary>Include all processes and threads in the system.</summary>
All = 0x0000001F,
/// <summary>Indicate that the snapshot handle is to be inheritable.</summary>
Inherit = 0x80000000,
}