/// <summary> /// Changes the protection on a region of committed pages in the virtual address space of a specified process. /// </summary> /// <param name="processHandle"></param> /// <param name="address"></param> /// <param name="size"></param> /// <param name="newProtect"></param> /// <returns>Returns the previous memory access protection.</returns> public static MemoryProtect VirtualProtectEx(IntPtr processHandle, UIntPtr address, uint size, MemoryProtect newProtect) { MemoryProtect oldProtect = new MemoryProtect(); if (!UnmanagedVirtualProtectEx(processHandle, address, size, newProtect, ref oldProtect)) { throw new Win32Exception(); } return(oldProtect); }
internal static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr address, UIntPtr size, AllocationType allocationType, MemoryProtect protect);
private static extern bool UnmanagedVirtualProtectEx(IntPtr hProcess, UIntPtr lpAddress, uint dwSize, MemoryProtect flNewProtect, ref MemoryProtect lpflOldProtect);
static extern UIntPtr UnmanagedVirtualAllocEx(IntPtr hProcess, UIntPtr lpAddress, uint dwSize, MemoryAllocationType flAllocationType, MemoryProtect flProtect);
/// <summary> /// Changes the protection on a region of committed pages in the virtual address space of a specified process. /// </summary> /// <param name="processHandle"></param> /// <param name="address"></param> /// <param name="size"></param> /// <param name="newProtect"></param> /// <returns>Returns the previous memory access protection.</returns> public static MemoryProtect VirtualProtectEx(IntPtr processHandle, UIntPtr address, uint size, MemoryProtect newProtect) { MemoryProtect oldProtect = new MemoryProtect(); if (!UnmanagedVirtualProtectEx(processHandle, address, size, newProtect, ref oldProtect)) { throw new Win32Exception(); } return oldProtect; }
/// <summary> /// Reserves or commits a region of memory within the virtual address space of a specified process. /// The function initializes the memory it allocates to zero, unless MEM_RESET is used. /// </summary> /// <param name="processHandle"></param> /// <param name="address"></param> /// <param name="size"></param> /// <param name="type"></param> /// <param name="protect"></param> /// <returns></returns> public static UIntPtr VirtualAllocEx(IntPtr processHandle, UIntPtr address, uint size, MemoryAllocationType type, MemoryProtect protect) { UIntPtr addr = UnmanagedVirtualAllocEx(processHandle, address, size, type, protect); if (addr == UIntPtr.Zero) { throw new Win32Exception(); } return addr; }
/// <summary> /// Reserves or commits a region of memory within the virtual address space of a specified process. /// The function initializes the memory it allocates to zero, unless MEM_RESET is used. /// </summary> /// <param name="processHandle"></param> /// <param name="address"></param> /// <param name="size"></param> /// <param name="type"></param> /// <param name="protect"></param> /// <returns></returns> public static UIntPtr VirtualAllocEx(IntPtr processHandle, UIntPtr address, uint size, MemoryAllocationType type, MemoryProtect protect) { UIntPtr addr = UnmanagedVirtualAllocEx(processHandle, address, size, type, protect); if (addr == UIntPtr.Zero) { throw new Win32Exception(); } return(addr); }
public static extern IntPtr VirtualAllocEx( IntPtr hProcess, IntPtr lpAddress, uint dwSize, MemoryState flAllocationType, MemoryProtect flProtect);