diff --git a/src/Dotx64Managed/API/Memory.cs b/src/Dotx64Managed/API/Memory.cs index 66917f0..0957072 100644 --- a/src/Dotx64Managed/API/Memory.cs +++ b/src/Dotx64Managed/API/Memory.cs @@ -7,6 +7,7 @@ public static partial class Memory [Flags] public enum Protection { + Invalid = 0, NoAccess = 0x01, ReadOnly = 0x02, ReadWrite = 0x04, @@ -91,6 +92,14 @@ public static nuint GetBase(ulong address) return GetBase((nuint)address); } + /// + /// Gets the protection of the memory, if the cache is used this is the last queried page info. + /// It is normally safe to use the cache for performance, when the cache is used the internal + /// API will not use a syscall to determine the protection. + /// + /// Address of the page to query + /// If this is true it will use the last queried page information + /// In case of failure the result is Protection.Invalid otherwise actual protection public static Protection GetProtection(nuint address, bool useCache) { return (Protection)Native.Memory.GetProtection(address, useCache); @@ -100,6 +109,18 @@ public static Protection GetProtection(ulong address, bool useCache) return GetProtection((nuint)address, useCache); } + /// + /// Sets a new protection on the specified address, the address will be aligned to page + /// boundaries and sets the entire page which is by 4 KiB. This may split up + /// an existing range from the memory map. + /// Internally the size will be always aligned to a minimum of a single page, if the size + /// spans more than two pages then both pages will be modified. + /// This will also update the cached protection info + /// + /// Address of the page + /// New protection + /// The size of the range + /// True on success public static bool SetProtection(nuint address, Protection protect, int size) { return Native.Memory.SetProtection(address, (UInt32)protect, size);