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='')
address: int

Base address of the region.

size: int

Region size in bytes.

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} with Protect (PAGE_* bitmask) and Type (MEM_PRIVATE / MEM_IMAGE / MEM_MAPPED).

  • Linux β€” small struct with Privileges (bytes like rwxp / rwxs).

  • macOS β€” struct with Protection (VM_PROT_* bitmask) and Shared.

is_readable: bool

True when the region can be read.

is_writable: bool

True when the region can be written.

is_executable: bool

True when the region contains executable code.

is_shared: bool

True when the region is a shared/file-backed mapping.

path: str

Best-effort path of the file backing the region, or "" when unknown. Linux exposes this directly from /proc/<pid>/maps; Windows and macOS would need extra syscalls and report "".

MemoryRegionSnapshot

class MemoryRegionSnapshot

A pre-sorted snapshot of memory regions returned by snapshot_memory_regions(). Behaves exactly like a plain list[MemoryRegion] β€” the only purpose of the subclass is to let the scanning helpers detect via isinstance that the input is already sorted by address and skip the per-call sorted(...) step.

Slicing or filtering with a list comprehension drops the MemoryRegionSnapshot type (you get a plain list). The scan helpers re-sort defensively whenever the input is not a MemoryRegionSnapshot, 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