Exemple #1
0
        private HookHandle AddInternal(BlockHookCallback callback, ulong begin, ulong end, object userToken)
        {
            var wrapper = new uc_cb_hookcode((uc, addr, size, user_data) =>
            {
                Debug.Assert(uc == Emulator.Handle);
                callback(Emulator, addr, size, userToken);
            });

            return(Add(UnicornHookType.Block, wrapper, begin, end));
        }
Exemple #2
0
        /// <summary>
        /// Adds a <see cref="BlockHookCallback"/> 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="BlockHookCallback"/> 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(BlockHookCallback callback, ulong begin, ulong end, object userToken)
        {
            Emulator.CheckDisposed();

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

            return(AddInternal(callback, begin, end, userToken));
        }
Exemple #3
0
        /// <summary>
        /// Adds a <see cref="BlockHookCallback"/> to the <see cref="Emulator"/> with the specified user token which
        /// is called anytime the hook is triggered.
        /// </summary>
        ///
        /// <param name="callback"><see cref="BlockHookCallback"/> 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(BlockHookCallback callback, object userToken)
        {
            Emulator.ThrowIfDisposed();

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

            return(AddInternal(callback, 1, 0, userToken));
        }
Exemple #4
0
        private HookHandle AddInternal(BlockHookCallback callback, ulong begin, ulong end, object userToken)
        {
            var wrapper = new uc_cb_hookcode((uc, addr, size, user_data) =>
            {
                Debug.Assert(uc == Emulator.Bindings.UCHandle);
                callback(Emulator, addr, size, userToken);
            });

            var ptr = Marshal.GetFunctionPointerForDelegate(wrapper);

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