/// <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); }
/// <summary> /// Change memory protection in the remote process /// </summary> /// <param name="hProcess"></param> /// <param name="lpAddress"></param> /// <param name="numberOfBytesToProtect"></param> /// <param name="newAccessProtection"></param> /// <param name="oldAccessProtection"></param> /// <returns></returns> public static bool ProtectVirtualMemory(IntPtr hProcess, IntPtr lpAddress, int numberOfBytesToProtect, Enumerations.MemoryProtectionFlags newAccessProtection, out Enumerations.MemoryProtectionFlags oldAccessProtection) { return(fNtProtectVirtualMemory(hProcess, &lpAddress, &numberOfBytesToProtect, newAccessProtection, out oldAccessProtection) == Enumerations.Ntstatus.Success); }
public static extern IntPtr VirtualAlloc(IntPtr lpAddress, int size, Enumerations.AllocationType flAllocationType, Enumerations.MemoryProtectionFlags flProtect);