Binarysharp.MemoryManagement.Memory.MemoryProtection.MemoryProtection C# (CSharp) Method

MemoryProtection() public method

Initializes a new instance of the MemoryProtection class.
public MemoryProtection ( MemorySharp memorySharp, IntPtr baseAddress, int size, MemoryProtectionFlags protection = MemoryProtectionFlags.ExecuteReadWrite, bool mustBeDisposed = true ) : System
memorySharp MemorySharp The reference of the object.
baseAddress System.IntPtr The base address of the memory to change the protection.
size int The size of the memory to change.
protection MemoryProtectionFlags The new protection to apply.
mustBeDisposed bool The resource will be automatically disposed when the finalizer collects the object.
return System
        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);
        }