/// <summary>
        /// Adds a <see cref="InterruptHookCallback"/> to the <see cref="Emulator"/> with the specified user token which
        /// is called when the hook is triggered within the specified start address and end address.
        /// </summary>
        ///
        /// <param name="callback"><see cref="InterruptHookCallback"/> 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"/> &gt; <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="Bindings.Error.Ok"/>.</exception>
        /// <exception cref="ObjectDisposedException"><see cref="Emulator"/> instance is disposed.</exception>
        public HookHandle Add(InterruptHookCallback callback, ulong begin, ulong end, object userToken)
        {
            Emulator.CheckDisposed();

            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            return(AddInternal(callback, begin, end, 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="Bindings.Error.Ok"/>.</exception>
        /// <exception cref="ObjectDisposedException"><see cref="Emulator"/> instance is disposed.</exception>
        public HookHandle Add(CodeHookCallback callback, object userToken)
        {
            Emulator.CheckDisposed();

            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            return(AddInternal(callback, 1, 0, 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="Bindings.Error.Ok"/>.</exception>
        /// <exception cref="ObjectDisposedException"><see cref="Emulator"/> instance is disposed.</exception>
        public HookHandle Add(InstructionOutHookCallback callback, Instruction instruction, object userToken)
        {
            Emulator.CheckDisposed();

            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            return(AddOutInternal(callback, instruction, 1, 0, userToken));
        }
Beispiel #4
0
        /// <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="Bindings.Error.Ok"/>.</exception>
        /// <exception cref="ObjectDisposedException"><see cref="Emulator"/> instance is disposed.</exception>
        public HookHandle Add(MemoryEventHookType type, MemoryEventHookCallback callback, object userToken)
        {
            Emulator.CheckDisposed();

            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback));
            }

            return(AddEventInternal(type, callback, 1, 0, userToken));
        }
Beispiel #5
0
        /// <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="Bindings.Error.Ok"/>.</exception>
        /// <exception cref="ObjectDisposedException"><see cref="Emulator"/> instance is disposed.</exception>
        public void Map(ulong address, int size, MemoryPermissions permissions)
        {
            _emulator.CheckDisposed();

            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.MemMap(address, size, permissions);
        }