private HookHandle AddOutInternal(InstructionOutHookCallback callback, Instruction instruction, ulong begin, ulong end, object userToken) { var wrapper = new uc_cb_insn_out((uc, port, size, value, user_data) => { Debug.Assert(uc == Emulator.Handle); callback(Emulator, port, size, value, userToken); }); return(AddInternal(wrapper, begin, end, instruction)); }
/// <summary> /// Adds a <see cref="InstructionOutHookCallback"/> 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="InstructionOutHookCallback"/> 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(InstructionOutHookCallback callback, Instruction instruction, ulong begin, ulong end, object userToken) { Emulator.ThrowIfDisposed(); if (callback == null) { throw new ArgumentNullException(nameof(callback)); } return(AddOutInternal(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="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)); }
private HookHandle AddOutInternal(InstructionOutHookCallback callback, Instruction instruction, ulong begin, ulong end, object userToken) { var wrapper = new uc_cb_insn_out((uc, port, size, value, user_data) => { Debug.Assert(uc == Emulator.Bindings.UCHandle); callback(Emulator, port, size, value, userToken); }); var ptr = Marshal.GetFunctionPointerForDelegate(wrapper); return(AddInternal(ptr, begin, end, instruction)); }