ChangeProtection() публичный статический Метод

Changes the protection on a region of committed pages in the virtual address space of a specified process.
public static ChangeProtection ( SafeMemoryHandle processHandle, IntPtr address, int size, MemoryProtectionFlags protection ) : MemoryProtectionFlags
processHandle Binarysharp.MemoryManagement.Native.SafeMemoryHandle A handle to the process whose memory protection is to be changed.
address System.IntPtr A pointer to the base address of the region of pages whose access protection attributes are to be changed.
size int The size of the region whose access protection attributes are changed, in bytes.
protection MemoryProtectionFlags The memory protection option.
Результат MemoryProtectionFlags
Пример #1
0
 /// <summary>
 ///     Restores the initial protection of the memory.
 /// </summary>
 public virtual void Dispose()
 {
     // Restore the memory protection
     MemoryCore.ChangeProtection(_memorySharp.Handle, BaseAddress, Size, OldProtection);
     // Avoid the finalizer
     GC.SuppressFinalize(this);
 }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MemoryProtection"/> class.
        /// </summary>
        /// <param name="memorySharp">The reference of the <see cref="MemorySharp"/> object.</param>
        /// <param name="baseAddress">The base address of the memory to change the protection.</param>
        /// <param name="size">The size of the memory to change.</param>
        /// <param name="protection">The new protection to apply.</param>
        /// <param name="mustBeDisposed">The resource will be automatically disposed when the finalizer collects the object.</param>
        public MemoryProtection(MemorySharp memorySharp, IntPtr baseAddress, int size, MemoryProtectionFlags protection = MemoryProtectionFlags.ExecuteReadWrite,
                                bool mustBeDisposed = true)
        {
            // Save the parameters
            _memorySharp   = memorySharp;
            BaseAddress    = baseAddress;
            NewProtection  = protection;
            Size           = size;
            MustBeDisposed = mustBeDisposed;

            // Change the memory protection
            OldProtection = MemoryCore.ChangeProtection(_memorySharp.Handle, baseAddress, size, protection);
        }