ShootBlues.Win32.VirtualProtectEx C# (CSharp) Méthode

VirtualProtectEx() private méthode

private VirtualProtectEx ( IntPtr hProcess, UInt32 lpAddress, uint dwSize, MemoryProtection flNewProtect, MemoryProtection &flOldProtect ) : int
hProcess System.IntPtr
lpAddress System.UInt32
dwSize uint
flNewProtect MemoryProtection
flOldProtect MemoryProtection
Résultat int
        public static extern int VirtualProtectEx(
            IntPtr hProcess, UInt32 lpAddress,
            uint dwSize, MemoryProtection flNewProtect,
            out MemoryProtection flOldProtect
        );

Usage Example

Exemple #1
0
        public void Protect(SafeProcessHandle handle, uint offset, uint size, MemoryProtection newProtect)
        {
            if (Address == IntPtr.Zero)
            {
                throw new ObjectDisposedException("RemoteMemoryRegion");
            }
            if ((offset + size) > (Size))
            {
                throw new ArgumentException("Size too large for region");
            }

            MemoryProtection oldProtect;
            int result = Win32.VirtualProtectEx(
                handle.DangerousGetHandle(),
                (uint)(Address.ToInt64() + offset),
                size, newProtect, out oldProtect
                );

            if (result == 0)
            {
                var error = Win32.GetLastError();
                throw new Exception(String.Format("Protect failed: Error {0:x8}", error));
            }
        }