GithubHelp home page GithubHelp logo

75f2cc / unihook Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stevemk14ebr/unihook

0.0 1.0 0.0 9.22 MB

Intercept arbitrary functions at run-time, without knowing their typedefs

License: MIT License

C++ 32.60% C 56.41% Objective-C 10.99%

unihook's Introduction

UniHook

Pre-Alpha Source Code, seriously there are issues!! THIS IS A POC. This is an example project on how to use PolyHook to intercept ANY arbitrary function, without knowing it's typedef. It hooks the specified function and calls an "Interupt" function before and after executing the original hooked function. This is useful for cases where someone may wish to time how long a function takes to execute. This relies both on PolyHook,and it's dependancy Capstone (the modified branch in my GitHub).

#How it works:

It allocates a callback at runtime that PolyHook redirects the hooked function to. This callback is filled with assembly at runtime that will handle executing the intercepts, and the original function. This is done by first storing all registers, calling the intercept, and restoring the registers, then it calls the original function, and repeats the register storing and poping before it calls the second interupt and returns to the caller of the hooked function.

Caller->Store Regs->Interupt1->Restore Regs->Original Hooked Func->Store Regs->Interupt2->Restore Regs->Return to Caller

#Project Setup

This demo has 3 core parts

  1. PolyHook for hooking backend
  • PolyHook relies on Capstone for disassembly
  1. UniHook dll which uses polyhook, and then creates runtime callbacks
  2. UniHook loader which injects the UniHook dll, and sends it commands via a shared memory queue/stack system
  • Shared memory synchronization is done through the Shared Memory Mutex object, which uses a WINAPI named mutex, this object can be managed by c++11's locking wrappers such as lock_guard

#LIMITATIONS

  1. No XMM registers or SIMD instructions can be used when compiling in x64, my variation of pusha and popa doesn't restore these.
  2. Possible stack alignment issues may exist when the original function is executed after the first interupt
  3. A heap corruption bug is floating around somewhere

#LICENSE MIT

unihook's People

Contributors

stevemk14ebr avatar

Watchers

James Cloos avatar

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.