internal IntPtr AllocateVirtualMemory <TStructure>() where TStructure : struct { // Allocate a region of virtual memory in the remote process const Enumerations.AllocationType allocationType = Enumerations.AllocationType.Commit | Enumerations.AllocationType.Reserve; var regionAddress = PInvoke.VirtualAllocEx(_processHandle, IntPtr.Zero, Marshal.SizeOf <TStructure>(), allocationType, Enumerations.MemoryProtection.ExecuteReadWrite); if (regionAddress == IntPtr.Zero) { ExceptionHandler.ThrowWin32Exception("Failed to allocate virtual memory in the remote process"); } return(regionAddress); }
internal IntPtr AllocateVirtualMemory(IntPtr baseAddress, int allocationSize) { // Allocate a region of virtual memory in the remote process at the specified address const Enumerations.AllocationType allocationType = Enumerations.AllocationType.Commit | Enumerations.AllocationType.Reserve; var regionAddress = PInvoke.VirtualAllocEx(_processHandle, baseAddress, allocationSize, allocationType, Enumerations.MemoryProtection.ExecuteReadWrite); if (regionAddress == IntPtr.Zero) { ExceptionHandler.ThrowWin32Exception("Failed to allocate virtual memory in the remote process"); } return(regionAddress); }
internal static extern IntPtr VirtualAllocEx(SafeProcessHandle processHandle, IntPtr baseAddress, int allocationSize, Enumerations.AllocationType allocationType, Enumerations.MemoryProtection protectionType);
/// <summary> /// Allocate memory in the remote process /// </summary> /// <param name="hProcess"></param> /// <param name="dwRegionSize"></param> /// <param name="allocationType"></param> /// <param name="protectionFlags"></param> /// <returns></returns> public static IntPtr AllocateVirtualMemory(IntPtr hProcess, int dwRegionSize, Enumerations.AllocationType allocationType, Enumerations.MemoryProtectionFlags protectionFlags) { IntPtr lpAddress = new IntPtr(0); fNtAllocateVirtualMemory(hProcess, &lpAddress, 0, &dwRegionSize, (uint)allocationType, (uint)protectionFlags); return(lpAddress); }
public static extern IntPtr VirtualAlloc(IntPtr lpAddress, int size, Enumerations.AllocationType flAllocationType, Enumerations.MemoryProtectionFlags flProtect);