Ejemplo n.º 1
0
        public static void Reprotect(IntPtr address, ulong size, MemoryPermission permission, bool forView, bool force4KBMap, bool throwOnFail)
        {
            bool result;

            if (OperatingSystem.IsWindows())
            {
                if (forView && force4KBMap)
                {
                    result = MemoryManagementWindows.Reprotect4KB(address, (IntPtr)size, permission, forView);
                }
                else
                {
                    result = MemoryManagementWindows.Reprotect(address, (IntPtr)size, permission, forView);
                }
            }
            else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
            {
                result = MemoryManagementUnix.Reprotect(address, size, permission);
            }
            else
            {
                throw new PlatformNotSupportedException();
            }

            if (!result && throwOnFail)
            {
                throw new MemoryProtectionException(permission);
            }
        }