subhook-master

所属分类:游戏
开发工具:Visual C++
文件大小:16KB
下载次数:0
上传日期:2018-06-18 04:28:53
上 传 者xiao ni
说明:  hook library ,easy use

文件列表:
.editorconfig (183, 2018-04-11)
.travis.yml (427, 2018-04-11)
CMakeLists.txt (1913, 2018-04-11)
appveyor.yml (205, 2018-04-11)
subhook.c (2178, 2018-04-11)
subhook.h (6512, 2018-04-11)
subhook_private.h (1805, 2018-04-11)
subhook_unix.c (1708, 2018-04-11)
subhook_windows.c (1591, 2018-04-11)
subhook_x86.c (14114, 2018-04-11)
test (0, 2018-04-11)
test\CMakeLists.txt (2230, 2018-04-11)
test\asm_test.c (1269, 2018-04-11)
test\foo_32.asm (1166, 2018-04-11)
test\foo_64.asm (129, 2018-04-11)
test\test.c (1297, 2018-04-11)

[![Build Status][build_status]][build] [![Build Status - Windows][build_status_win]][build_win] SubHook is a super-simple hooking library for C/C++ that works on Linux and Windows. It currently supports x86 and x86-***. Examples -------- In the following examples `foo` is some function or a function pointer that takes a single argument of type `int` and uses the same calling convention as `my_foo` (depends on compiler). ### Basic usage ```c #include #include subhook_t foo_hook; void my_foo(int x) { /* Remove the hook so that you can call the original function. */ subhook_remove(foo_hook); printf("foo(%d) called\n", x); foo(x); /* Install the hook back to intercept further calls. */ subhook_install(foo_hook); } int main() { /* Create a hook that will redirect all foo() calls to to my_foo(). */ foo_hook = subhook_new((void *)foo, (void *)my_foo, 0); /* Install it. */ subhook_install(foo_hook); foo(123); /* Remove the hook and free memory when you're done. */ subhook_remove(foo_hook); subhook_free(foo_hook); } ``` ### Trampolines Using trampolines allows you to jump to the original code without removing and re-installing hooks every time your function gets called. ```c typedef void (*foo_func)(int x); void my_foo(int x) { printf("foo(%d) called\n", x); /* Call foo() via trampoline. */ ((foo_func)subhook_get_trampoline(foo_hook))(x); } int main() { /* Same code as in previous example. */ } ``` Please note that subhook has a very simple length disassmebler engine (LDE) that works only with most common prologue instructions like push, mov, call, etc. When it encounters an unknown instruction subhook_get_trampoline() will return NULL. ### C++ ```c++ #include #include subhook::Hook foo_hook; subhook::Hook foo_hook_tr; typedef void (*foo_func)(int x); void my_foo(int x) { // ScopedHookRemove removes the specified hook and automatically re-installs // it when the objectt goes out of scope (thanks to C++ destructors). subhook::ScopedHookRemove remove(&foo_hook); std::cout << "foo(" << x << ") called" << std::endl; foo(x + 1); } void my_foo_tr(int x) { std::cout << "foo(" << x << ") called" << std::endl; // Call the original function via trampoline. ((foo_func)foo_hook_tr.GetTrampoline())(x + 1); } int main() { foo_hook.Install((void *)foo, (void *)my_foo); foo_hook_tr.Install((void *)foo, (void *)my_foo_tr); } ``` License ------- Licensed under the 2-clause BSD license. [build]: https://travis-ci.org/Zeex/subhook [build_status]: https://travis-ci.org/Zeex/subhook.svg?branch=master [build_win]: https://ci.appveyor.com/project/Zeex/subhook/branch/master [build_status_win]: https://ci.appveyor.com/api/projects/status/q5sp0p8ahuqfh8e4/branch/master?svg=true

近期下载者

相关文件


收藏者