private static MemoryProtection GetProtection(Memory.MemoryProtection protection) { switch (protection) { case Memory.MemoryProtection.None: return MemoryProtection.NoAccess; case Memory.MemoryProtection.Read: return MemoryProtection.ReadOnly; case Memory.MemoryProtection.ReadAndWrite: return MemoryProtection.ReadWrite; case Memory.MemoryProtection.ReadAndExecute: return MemoryProtection.ExecuteRead; case Memory.MemoryProtection.ReadWriteExecute: return MemoryProtection.ExecuteReadWrite; case Memory.MemoryProtection.Execute: return MemoryProtection.Execute; default: throw new ArgumentException($"Invalid permission \"{protection}\"."); } }
private static MmapProts GetProtection(Memory.MemoryProtection protection) { switch (protection) { case Memory.MemoryProtection.None: return(MmapProts.PROT_NONE); case Memory.MemoryProtection.Read: return(MmapProts.PROT_READ); case Memory.MemoryProtection.ReadAndWrite: return(MmapProts.PROT_READ | MmapProts.PROT_WRITE); case Memory.MemoryProtection.ReadAndExecute: return(MmapProts.PROT_READ | MmapProts.PROT_EXEC); case Memory.MemoryProtection.Execute: return(MmapProts.PROT_EXEC); default: throw new ArgumentException($"Invalid permission \"{protection}\"."); } }
public static bool Reprotect(IntPtr address, IntPtr size, Memory.MemoryProtection protection) { MemoryProtection prot = GetProtection(protection); return(VirtualProtect(address, size, prot, out _)); }
public static bool Reprotect(IntPtr address, ulong size, Memory.MemoryProtection protection) { MmapProts prot = GetProtection(protection); return(Syscall.mprotect(address, size, prot) == 0); }