예제 #1
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.Handle);
                return(callback(Emulator, (MemoryType)_type, addr, size, value, userToken));
            });

            return(Add((UnicornHookType)type, wrapper, begin, end));
        }
예제 #2
0
        /// <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));
        }
예제 #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));
        }
예제 #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));
        }
예제 #5
0
        public Hook AddHook(MemoryEventHookType type, MemoryEventHook callback, ulong address = 1, ulong end = 0)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            if ((type & ~MemoryEventHookType.All) != 0)
            {
                throw new ArgumentOutOfRangeException("type", "unsupported memory event hook type");
            }

            var wrapper = new Native.uc_cb_eventmem_t(
                (uc, t, a, s, v, ud) => callback((TType)this, t, a, s, v));

            return(this.AddHook((HookType)type, wrapper, address, end));
        }