/// <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> /// Reads the value of the register with specified register ID. /// </summary> /// <param name="registerId">Register ID.</param> /// <returns>Value of register read.</returns> /// <exception cref="UnicornException">Unicorn did not return <see cref="Binds.UnicornError.Ok"/>.</exception> /// <exception cref="ObjectDisposedException"><see cref="Emulator"/> instance is disposed.</exception> public long Read(int registerId) { long value = 0; _emulator.ThrowIfDisposed(); _emulator.RegRead(registerId, ref value); return(value); }
/// <summary> /// Adds a <see cref="MemoryHookCallback"/> to the <see cref="Emulator"/> with the specified <see cref="MemoryHookType"/> and user token which /// is called when the hook is triggered within the specified start address and end address. /// </summary> /// /// <param name="type">Type of <see cref="MemoryHookType"/>.</param> /// <param name="callback"><see cref="MemoryHookCallback"/> to add.</param> /// <param name="begin">Start address of where the hook is effective (inclusive).</param> /// <param name="end">End address of where the hook is effective (inclusive).</param> /// <param name="userToken">Object associated with the callback.</param> /// <returns>A <see cref="HookHandle"/> which represents the hook.</returns> /// /// <remarks> /// If <paramref name="begin"/> > <paramref name="end"/>, the callback is called anytime the hook triggers. /// </remarks> /// /// <exception cref="ArgumentNullException"><paramref name="callback"/> is <c>null</c>.</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 HookHandle Add(MemoryHookType type, MemoryHookCallback callback, ulong begin, ulong end, object userToken) { Emulator.ThrowIfDisposed(); if (callback == null) { throw new ArgumentNullException(nameof(callback)); } return(AddInternal(type, callback, begin, end, userToken)); }
/// <summary> /// Adds a <see cref="MemoryEventHookCallback"/> to the <see cref="Emulator"/> with the specified <see cref="MemoryEventHookType"/> and user token which /// is called anytime the hook is triggered. /// </summary> /// /// <param name="type">Type of <see cref="MemoryEventHookType"/>.</param> /// <param name="callback"><see cref="MemoryEventHookCallback"/> to add.</param> /// <param name="userToken">Object associated with the callback.</param> /// <returns>A <see cref="HookHandle"/> which represents the hook.</returns> /// /// <exception cref="ArgumentNullException"><paramref name="callback"/> is <c>null</c>.</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 HookHandle Add(MemoryEventHookType type, MemoryEventHookCallback callback, object userToken) { Emulator.ThrowIfDisposed(); if (callback == null) { throw new ArgumentNullException(nameof(callback)); } return(AddEventInternal(type, callback, 1, 0, userToken)); }
/// <summary> /// Adds a <see cref="CodeHookCallback"/> to the <see cref="Emulator"/> with the specified user token which /// is called anytime the hook is triggered. /// </summary> /// /// <param name="callback"><see cref="CodeHookCallback"/> to add.</param> /// <param name="userToken">Object associated with the callback.</param> /// <returns>A <see cref="HookHandle"/> which represents the hook.</returns> /// /// <exception cref="ArgumentNullException"><paramref name="callback"/> is <c>null</c>.</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 HookHandle Add(CodeHookCallback callback, object userToken) { Emulator.ThrowIfDisposed(); if (callback == null) { throw new ArgumentNullException(nameof(callback)); } return(AddInternal(callback, 1, 0, userToken)); }
/// <summary> /// Adds a <see cref="InstructionInHookCallback"/> to the <see cref="Emulator"/> with the specified <see cref="Instruction"/> and user token which /// is called when the hook is triggered within the specified start address and end address. /// </summary> /// /// <param name="callback"><see cref="InstructionInHookCallback"/> to add.</param> /// <param name="instruction"><see cref="Instruction"/> to hook.</param> /// <param name="begin">Start address of where the hook is effective (inclusive).</param> /// <param name="end">End address of where the hook is effective (inclusive).</param> /// <param name="userToken">Object associated with the callback.</param> /// <returns>A <see cref="HookHandle"/> which represents the hook.</returns> /// /// <exception cref="ArgumentNullException"><paramref name="callback"/> is <c>null</c>.</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 HookHandle Add(InstructionInHookCallback callback, Instruction instruction, ulong begin, ulong end, object userToken) { Emulator.ThrowIfDisposed(); if (callback == null) { throw new ArgumentNullException(nameof(callback)); } return(AddInInternal(callback, instruction, begin, end, userToken)); }
/// <summary> /// Adds a <see cref="InstructionOutHookCallback"/> to the <see cref="Emulator"/> with the specified <see cref="Instruction"/> and user token which /// is called anytime the hook is triggered. /// </summary> /// /// <param name="callback"><see cref="InstructionOutHookCallback"/> to add.</param> /// <param name="instruction"><see cref="Instruction"/> to hook.</param> /// <param name="userToken">Object associated with the callback.</param> /// <returns>A <see cref="HookHandle"/> which represents the hook.</returns> /// /// <exception cref="ArgumentNullException"><paramref name="callback"/> is <c>null</c>.</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 HookHandle Add(InstructionOutHookCallback callback, Instruction instruction, object userToken) { Emulator.ThrowIfDisposed(); if (callback == null) { throw new ArgumentNullException(nameof(callback)); } return(AddOutInternal(callback, instruction, 1, 0, userToken)); }