Giter VIP home page Giter VIP logo

winhookupp's Introduction

winhookupp

License

A cpp multi-method API internal/external Hooking library for x86/x86-64 Windows.

Supported hooking methods

Hook implementation supports both internal and external(TODO) hooking.

  • VEH hook: Trigger exception with page guard violation, then intercept the exception with our VehHandler and change instruction pointer to detoured function.
  • Trampoline hook: Modifies opcode to jmp to hook and allocates a trampoline for jmp back.
  • INT3VEH hook: Alike VEH hook, except that exception is triggered by patching the first byte of target function to 0xCC(int 3)
  • VMT: Find the right disp to target virtual method through disassembling vcall thunk bytes or traversing vtable, then patch vtable of a class to detoured function. (Warning: My Current implementation of vmt hook will probably not work if the target class has multiple inheritance. eg. class Derived : public Base1, public Base2;)
  • IAT: TODO

Download this project

git clone [email protected]:leo4048111/winhookupp.git --recurse-submodules

Building

  • Installed Visual Studio
  • Generate solution with tests
cmake . -G "Visual Studio 17 2022" -A [win32/x64]
  • Generate solution library only
cmake . -G "Visual Studio 17 2022" -A [win32/x64] -DBUILD_TESTS=OFF

Usage

  • Example trampoline hooking(Interfaces of hooking methods are the same):
// include header for a hooking method
#include "trampoline.h"

int main(int argc, char** argv) {
    using namespace WINHOOKUPP_NM;

    // define a hook instance
    Trampoline tramp;
    // enabling hooking
    LPVOID origin; // a pointer to original target function(nullptr if calling original target is not possible after hooking)
    tramp.Enable(&TargetFunction, &YourDetouredFunction, &origin);

    // calling the target function, your detoured function should be called instead
    TargetFunction(...);

    // calling the original function
    if(origin != nullptr) {
        decltype(TargetFunction)* pOrigin = reinterpret_cast<decltype(TargetFunction)*>(origin);
        pOrigin(...);
    }

    // disabling hooking(note that hook will be automatically disabled if the hook instance is deconstructed)
    tramp.Disable();
}
  • To enable external hooking interfaces, define WINHOOKUPP_EXTERNAL_USAGE before including winhookupp headers(External hooks haven't been thoroughly tested yet, use with caution)
#define WINHOOKUPP_EXTERNAL_USAGE
#include "trampoline.h"

int main(int argc, char** argv) {
    using namespace WINHOOKUPP_NM;
    // To enable remote hooks, you need to pass in a handle to remote process
    HANDLE hProc = ...;
    Tramp tramp;
    tramp.EnableEx(hProc, &TargetFunction, &YourDetouredFunction, &origin);

    ...
}
  • See example and unit-tests for more detailed usages.

Credits

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.