/// <summary> /// Allocate virtual memory in a process. /// </summary> /// <param name="process">The process to allocate in.</param> /// <param name="base_address">Optional base address, if 0 will automatically select a base.</param> /// <param name="region_size">The region size to allocate.</param> /// <param name="allocation_type">The type of allocation.</param> /// <param name="protect">The allocation protection.</param> /// <returns>The address of the allocated region.</returns> /// <exception cref="NtException">Thrown on error.</exception> public static long AllocateMemory(SafeKernelObjectHandle process, long base_address, long region_size, MemoryAllocationType allocation_type, MemoryAllocationProtect protect) { IntPtr base_address_ptr = new IntPtr(base_address); IntPtr region_size_ptr = new IntPtr(region_size); NtSystemCalls.NtAllocateVirtualMemory(process, ref base_address_ptr, IntPtr.Zero, ref region_size_ptr, allocation_type, protect).ToNtException(); return(base_address_ptr.ToInt64()); }
/// <summary> /// Allocate virtual memory in a process. /// </summary> /// <param name="process">The process to allocate in.</param> /// <param name="base_address">Optional base address, if 0 will automatically select a base.</param> /// <param name="region_size">The region size to allocate.</param> /// <param name="allocation_type">The type of allocation.</param> /// <param name="protect">The allocation protection.</param> /// <param name="throw_on_error">True to throw on error.</param> /// <returns>The address of the allocated region.</returns> /// <exception cref="NtException">Thrown on error.</exception> public static NtResult <long> AllocateMemory(SafeKernelObjectHandle process, long base_address, long region_size, MemoryAllocationType allocation_type, MemoryAllocationProtect protect, bool throw_on_error) { IntPtr base_address_ptr = new IntPtr(base_address); IntPtr region_size_ptr = new IntPtr(region_size); return(NtSystemCalls.NtAllocateVirtualMemory(process, ref base_address_ptr, IntPtr.Zero, ref region_size_ptr, allocation_type, protect) .CreateResult(throw_on_error, () => base_address_ptr.ToInt64())); }