private HookHandle AddEventInternal(MemoryEventHookType type, MemoryEventHookCallback callback, ulong begin, ulong end, object userToken)
        {
            var wrapper = new uc_cb_eventmem((uc, _type, addr, size, value, user_data) =>
            {
                Debug.Assert(uc == Emulator.Handle);
                return(callback(Emulator, (MemoryType)_type, addr, size, value, userToken));
            });

            return(Add((UnicornHookType)type, wrapper, begin, end));
        }
        /// <summary>
        /// Adds a <see cref="MemoryEventHookCallback"/> to the <see cref="Emulator"/> with the specified <see cref="MemoryEventHookType"/> 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="MemoryEventHookType"/>.</param>
        /// <param name="callback"><see cref="MemoryEventHookCallback"/> 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="Binds.UnicornError.Ok"/>.</exception>
        /// <exception cref="ObjectDisposedException"><see cref="Emulator"/> instance is disposed.</exception>
        public HookHandle Add(MemoryEventHookType type, MemoryEventHookCallback callback, ulong begin, ulong end, object userToken)
        {
            Emulator.ThrowIfDisposed();

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

            return(AddEventInternal(type, callback, begin, end, userToken));
        }
Example #3
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));
        }
Example #4
0
        private HookHandle AddEventInternal(MemoryEventHookType type, MemoryEventHookCallback callback, ulong begin, ulong end, object userToken)
        {
            var wrapper = new uc_cb_eventmem((uc, _type, addr, size, value, user_data) =>
            {
                Debug.Assert(uc == Emulator.Bindings.UCHandle);
                return(callback(Emulator, (MemoryType)_type, addr, size, value, userToken));
            });

            var ptr = Marshal.GetFunctionPointerForDelegate(wrapper);

            return(Add((Bindings.HookType)type, ptr, begin, end));
        }