/* * -------------------------------- * Change Permission Implementation * -------------------------------- */ /* Implementation */ /// <inheritdoc /> public Kernel32.Kernel32.MEM_PROTECTION ChangePermission(IntPtr memoryAddress, int size, Kernel32.Kernel32.MEM_PROTECTION newPermissions) { bool result = Kernel32.Kernel32.VirtualProtectEx(_processHandle, memoryAddress, (UIntPtr)size, newPermissions, out Kernel32.Kernel32.MEM_PROTECTION oldPermissions); if (!result) { throw new MemoryPermissionException($"Unable to change permissions for the following memory address {memoryAddress.ToString("X")} of size {size} and permission {newPermissions.ToString()}"); } return(oldPermissions); }
[ExcludeFromCodeCoverage] // Wrapper that simply lets pass with base element calculated with functions tested elsewhere, no logic. public static Kernel32.Kernel32.MEM_PROTECTION ChangePermission <T>(this IMemory memory, IntPtr memoryAddress, ref T baseElement, Kernel32.Kernel32.MEM_PROTECTION newPermissions, bool marshalElement = false) => memory.ChangePermission(memoryAddress, Struct.GetSize <T>(marshalElement), newPermissions);