public static List<Tuple<long, long>> GetVirtualMemoryAddresses(this Process process) { var result = new List<Tuple<long, long>>(); SYSTEM_INFO sysinfo = new SYSTEM_INFO(); GetSystemInfo(out sysinfo); long address = 0; MEMORY_BASIC_INFORMATION m = new MEMORY_BASIC_INFORMATION(); IntPtr openedProcess = IntPtr.Zero; try { openedProcess = OpenProcess(ProcessAccessFlags.All, false, (int)process.Id); while (address < sysinfo.lpMaximumApplicationAddress.ToInt64()) { try { if (!VirtualQueryEx(openedProcess, new IntPtr(address), out m, (uint)Marshal.SizeOf(m))) continue; } finally { // next address address = m.BaseAddress.ToInt64() + m.RegionSize.ToInt64(); } result.Add(new Tuple<long, long>(m.BaseAddress.ToInt64(), m.RegionSize.ToInt64())); } } finally { if (openedProcess != IntPtr.Zero) CloseHandle(openedProcess); } return result; }
public static extern void GetSystemInfo(out SYSTEM_INFO lpSystemInfo);