public static List <MemoryBasicInformation> LoadRegions(SafeMemoryHandle processHandle, IntPtr startAddress, IntPtr endAddress, MemoryAllocationState memoryAllocationState = MemoryAllocationState.MEM_COMMIT, MemoryProtectionType memoryProtectionType = MemoryProtectionType.PAGE_ACCESSIBLE) { List <MemoryBasicInformation> regions = new List <MemoryBasicInformation>(); if (startAddress == endAddress) { return(regions); } if (endAddress == IntPtr.Zero) { endAddress = new IntPtr(0x7fffffffffff); } IntPtr seek = startAddress; do { MemoryBasicInformation region = Native.Query(processHandle, seek, MarshalType <MemoryBasicInformation> .Size); if ((region.State & memoryAllocationState) != 0 && (region.Protect & memoryProtectionType) != 0) { regions.Add(region); } seek = IntPtr.Add(region.BaseAddress, region.RegionSize.ToInt32()); }while (seek.ToInt64() < endAddress.ToInt64()); return(regions); }
internal static extern IntPtr VirtualAllocEx(SafeMemoryHandle hProcess, [Optional] IntPtr lpAddress, int nSize, MemoryAllocationState dwAllocationType, MemoryProtectionType dwProtect);
internal static extern IntPtr VirtualAlloc([Optional] IntPtr lpAddress, int nSize, MemoryAllocationState dwAllocationType, MemoryProtectionType dwProtect);