MemoryRegionο
A single memory region in a target processβs address space.
from PyMemoryEditor import MemoryRegion
MemoryRegion is a @dataclass(frozen=True) yielded by
process.get_memory_regions(). Each instance describes one contiguous block
of memory with its address, size, permissions and backing path.
Fieldsο
- class MemoryRegion(address, size, struct=None, is_readable=False, is_writable=False, is_executable=False, is_shared=False, path='')ο
-
- struct: Anyο
Platform-specific descriptor. Portable code should rely on the boolean fields below instead of poking at this directly. Shape varies:
Windows β
MEMORY_BASIC_INFORMATION_{32,64}withProtect(PAGE_* bitmask) andType(MEM_PRIVATE/MEM_IMAGE/MEM_MAPPED).Linux β small struct with
Privileges(bytes likerwxp/rwxs).macOS β struct with
Protection(VM_PROT_*bitmask) andShared.
Truewhen the region is a shared/file-backed mapping.
MemoryRegionSnapshotο
- class MemoryRegionSnapshotο
A pre-sorted snapshot of memory regions returned by
snapshot_memory_regions(). Behaves exactly like a plainlist[MemoryRegion]β the only purpose of the subclass is to let the scanning helpers detect viaisinstancethat the input is already sorted byaddressand skip the per-callsorted(...)step.Slicing or filtering with a list comprehension drops the
MemoryRegionSnapshottype (you get a plainlist). The scan helpers re-sort defensively whenever the input is not aMemoryRegionSnapshot, so this is safe but slightly slower for very large region maps.
Examplesο
Iterating regionsο
with OpenProcess(process_name="game.exe") as process:
for region in process.get_memory_regions():
print(f"0x{region.address:016X} {region.size:>12,}")
Filtering by permissionο
writable = [r for r in process.get_memory_regions() if r.is_writable]
Building a snapshot for the refine loopο
snapshot = process.snapshot_memory_regions()
assert isinstance(snapshot, MemoryRegionSnapshot)
# Reuse across many scans:
for addr in process.search_by_value(int, value=100, memory_regions=snapshot):
...
See also
Searching memory β uses the snapshot to skip region enumeration on the refine loop.
Utilities API β low-level predicates
is_region_readableetc. for callers that hold a raw platform struct.