/// <summary> /// Maps a memory region for emulation with the specified starting address, size and <see cref="MemoryPermissions"/>. /// </summary> /// <param name="address">Starting address of memory region.</param> /// <param name="size">Size of memory region.</param> /// <param name="permissions">Permissions of memory region.</param> /// /// <exception cref="ArgumentException"><paramref name="address"/> is not aligned with <see cref="PageSize"/>.</exception> /// <exception cref="ArgumentException"><paramref name="size"/> is not a multiple of <see cref="PageSize"/>.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="size"/> is less than 0.</exception> /// <exception cref="UnicornException">Unicorn did not return <see cref="Binds.UnicornError.Ok"/>.</exception> /// <exception cref="ObjectDisposedException"><see cref="Emulator"/> instance is disposed.</exception> public void Map(ulong address, UIntPtr size, MemoryPermissions permissions) { _emulator.ThrowIfDisposed(); if ((address & (ulong)PageSize) != 0) { throw new ArgumentException("Address must be aligned with page size.", nameof(address)); } if ((size.ToUInt64() & PageSize.ToUInt64()) != 0) { throw new ArgumentException("Size must be a multiple of page size.", nameof(size)); } /* * if (size < 0) * throw new ArgumentOutOfRangeException(nameof(size), "Size must be non-negative."); */ if (permissions > MemoryPermissions.All) { throw new ArgumentException("Permissions is invalid.", nameof(permissions)); } _emulator.Bindings.MemMap(_emulator.Handle, address, size, permissions); }
/// <summary> /// Binds to uc_mem_protect /// </summary> /// <param name="address"></param> /// <param name="size"></param> /// <param name="permissions"></param> public void MemProtect(ulong address, int size, MemoryPermissions permissions) { var err = unicorn.uc_mem_protect(_uc, address, size, (int)permissions); if (err != uc_err.UC_ERR_OK) { throw new UnicornException(err); } }
/// <summary> /// Sets permissions for a region of memory with the specified starting address, size and <see cref="MemoryPermissions"/>. /// </summary> /// <param name="address">Starting address of memory region.</param> /// <param name="size">Size of memory region.</param> /// <param name="permissions">Permissions of memory region.</param> /// /// <exception cref="ArgumentException"><paramref name="address"/> is not aligned with <see cref="PageSize"/>.</exception> /// <exception cref="ArgumentException"><paramref name="size"/> is not a multiple of <see cref="PageSize"/>.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="size"/> is less than 0.</exception> /// <exception cref="UnicornException">Unicorn did not return <see cref="Binds.UnicornError.Ok"/>.</exception> /// <exception cref="ObjectDisposedException"><see cref="Emulator"/> instance is disposed.</exception> public void Protect(ulong address, int size, MemoryPermissions permissions) { _emulator.ThrowIfDisposed(); if ((address & (ulong)PageSize) != (ulong)PageSize) { throw new ArgumentException("Address must be aligned with page size.", nameof(address)); } if ((size & PageSize) != PageSize) { throw new ArgumentException("Size must be a multiple of page size.", nameof(size)); } if (size < 0) { throw new ArgumentOutOfRangeException(nameof(size), "Size must be non-negative."); } if (permissions > MemoryPermissions.All) { throw new ArgumentException("Permissions is invalid.", nameof(permissions)); } _emulator.Bindings.MemProtect(_emulator.Handle, address, size, permissions); }
// Wrap the native uc_mem_region structure. internal MemoryRegion(ulong begin, ulong end, MemoryPermissions perms) { _begin = begin; _end = end; _perms = perms; }
public void MemProtect(IntPtr uc, ulong address, int size, MemoryPermissions perms) => ThrowIfError(uc_mem_protect(uc, address, size, (int)perms));
public void MemMapPtr(IntPtr uc, ulong address, UIntPtr size, MemoryPermissions permissions, byte[] ptr) => ThrowIfError(uc_mem_map_ptr(uc, address, size, (uc_prot)permissions, ptr));
public void MemMap(IntPtr uc, ulong address, UIntPtr size, MemoryPermissions perms) => ThrowIfError(uc_mem_map(uc, address, size, (uc_prot)perms));
/// <summary> /// Initializes the Riders SDK as a Reloaded II mod, setting the shared library to be used. /// </summary> public static void Init(IReloadedHooks hooks) { ReloadedHooks = hooks; MemoryPermissions.Change(); }
public void Map(ulong address, ulong size, MemoryPermissions permissions) => Map(address, new UIntPtr(size), permissions);
public void Protect(ulong address, ulong size, MemoryPermissions permissions) => Protect(address, new UIntPtr(size), permissions);