[Src/C#] BananaHook - Simple abstracted API hooking library menu

User Tag List

Results 1 to 3 of 3
  1. #1
    Bananenbrot's Avatar Contributor
    Reputation
    153
    Join Date
    Nov 2009
    Posts
    384
    Thanks G/R
    1/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Src/C#] BananaHook - Simple abstracted API hooking library

    Hi,

    just wanted to contribute some code and release the pain of everyone who ever wanted to dynamically generate an interceptor func for a given Delegate.

    Basically, detouring a function is like
    Code:
    [UnmanagedFunctionPointer(CallingConvention.StdCall)]
    public delegate int EndSceneDelegate(IntPtr devicePointer);
    
    ...
    
    EndSceneDelegate d = Marshal.GetDelegateForFunctionPointer(new IntPtr(0x1234), typeof(EndSceneDelegate));
    var notifier = new ReflectionDetourNotifier((t, h) => new RetnHook(new InProcessMemory(), t, h), d);
    notifier.DetourCalled += (s, e) => { foreach (var p in e.Parameters) Console.WriteLine(p.ToString()); };
    notifier.Hook.Apply();
    It boils down to just pass in a Delegate to an unmanaged function and then receiving event notifications.
    For anyone who's wondering of those factory funcs passed in to the constructor... read about TDD.

    Actually the chosen names are really bad... so a short legend for those concepts (or at least how I use them):
    Hooking is the interception of control flow with a given function with the same signature. It does not necessarily call or simulate the behavior of the original.
    A detour is a special hook that returns control flow to the original function after doing its work (a redirection).
    A detour notifier is just a little extension to the detour concept, which defines 'doing its work' as firing up an event. Through the use of this event model, one can intercept multiple functions, which may even differ in signature, with one generic event handler.
    E.g.: Decide to detour EndScene or Present based on the used DirectX version and intercept with the same signature agnostic handler.

    Credits go to Apoc's WhiteMagic which is the predecessor of this module.

    http://github.com/Bananenbrot/BananaHook

    v0.1: some refactoring and stuff... added Int3Hook via VEH as an example for extensibility
    Last edited by Bananenbrot; 04-21-2012 at 06:30 AM. Reason: v0.1

    [Src/C#] BananaHook - Simple abstracted API hooking library
  2. #2
    LegacyAX's Avatar Active Member
    Reputation
    21
    Join Date
    Apr 2009
    Posts
    193
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    x3 rep my bro
    MMOEmpire.net CEO (No longer active)

  3. #3
    Seifer's Avatar Site Donator
    Reputation
    129
    Join Date
    Apr 2007
    Posts
    270
    Thanks G/R
    1/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very nice! I'll definitely have fun with this.

Similar Threads

  1. [C#][Source] BlackRain - Simple Object Manager Library
    By Seifer in forum WoW Memory Editing
    Replies: 195
    Last Post: 04-08-2015, 03:02 PM
  2. x64 API Hooking - VC++
    By Master674 in forum WoW Memory Editing
    Replies: 6
    Last Post: 01-18-2012, 11:45 AM
  3. BlackMagic & api hooking
    By roxaz911 in forum WoW Memory Editing
    Replies: 8
    Last Post: 06-04-2009, 09:10 AM
  4. [GUIDE] How to write a simple Keyboard Hook
    By Kekke in forum Programming
    Replies: 5
    Last Post: 02-04-2009, 02:32 AM
  5. View what API functions are hooked by Wow
    By barthen in forum WoW Memory Editing
    Replies: 8
    Last Post: 10-26-2008, 11:25 PM
All times are GMT -5. The time now is 08:44 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search