Example #1
0
 /// <summary>
 ///     Restores the initial protection of the memory.
 /// </summary>
 public virtual void Dispose()
 {
     // Restore the memory protection
     AMemoryHelper.ChangeProtection(Handle, BaseAddress, Size, OldProtection);
     // Avoid the finalizer
     GC.SuppressFinalize(this);
 }
Example #2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="AMemoryProtection" /> class.
 /// </summary>
 /// <param name="handle">The reference of the <see cref="ASafeMemoryHandle" /> 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 AMemoryProtection(ASafeMemoryHandle handle, IntPtr baseAddress, int size,
                          MemoryProtectionFlags protection = MemoryProtectionFlags.ExecuteReadWrite,
                          bool mustBeDisposed = true)
 {
     // Save the parameters
     Handle         = handle;
     BaseAddress    = baseAddress;
     NewProtection  = protection;
     Size           = size;
     MustBeDisposed = mustBeDisposed;
     // Change the memory protection
     AMemoryHelper.ChangeProtection(Handle, baseAddress, size, protection, out var oldProtection);
     OldProtection = oldProtection;
 }