private HookHandle AddInternal(MemoryHookType type, MemoryHookCallback callback, ulong begin, ulong end, object userToken) { var wrapper = new uc_cb_hookmem((uc, _type, addr, size, value, user_data) => { Debug.Assert(uc == Emulator.Handle); callback(Emulator, (MemoryType)_type, addr, size, value, userToken); }); return(Add((UnicornHookType)type, wrapper, begin, end)); }
/// <summary> /// Adds a <see cref="MemoryHookCallback"/> to the <see cref="Emulator"/> with the specified <see cref="MemoryHookType"/> 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="MemoryHookType"/>.</param> /// <param name="callback"><see cref="MemoryHookCallback"/> 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"/> > <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(MemoryHookType type, MemoryHookCallback callback, ulong begin, ulong end, object userToken) { Emulator.ThrowIfDisposed(); if (callback == null) { throw new ArgumentNullException(nameof(callback)); } return(AddInternal(type, callback, begin, end, userToken)); }
/// <summary> /// Adds a <see cref="MemoryHookCallback"/> to the <see cref="Emulator"/> with the specified <see cref="MemoryHookType"/> and user token which /// is called anytime the hook is triggered. /// </summary> /// /// <param name="type">Type of <see cref="MemoryHookType"/>.</param> /// <param name="callback"><see cref="MemoryHookCallback"/> 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(MemoryHookType type, MemoryHookCallback callback, object userToken) { Emulator.CheckDisposed(); if (callback == null) { throw new ArgumentNullException(nameof(callback)); } return(AddInternal(type, callback, 1, 0, userToken)); }
private HookHandle AddInternal(MemoryHookType type, MemoryHookCallback callback, ulong begin, ulong end, object userToken) { var wrapper = new uc_cb_hookmem((uc, _type, addr, size, value, user_data) => { Debug.Assert(uc == Emulator.Bindings.UCHandle); callback(Emulator, (MemoryType)_type, addr, size, value, userToken); }); var ptr = Marshal.GetFunctionPointerForDelegate(wrapper); return(Add((Bindings.HookType)type, ptr, begin, end)); }