-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add deferred / automatic hooking #31
base: master
Are you sure you want to change the base?
Add deferred / automatic hooking #31
Conversation
- Added the AutoHooks class to manage the installation of hooks. - Includes a private method getInstallFuncs() that returns a reference to a static vector of function pointers. - Includes public methods AddInstallFunc() and InstallHooks(). - AddInstallFunc() adds an installation function to the vector. - InstallHooks() executes all installation functions and clears the vector. - Added the INSTALL_HOOKS macro. - Installs all hooks created with the MAKE_HOOK_AUTO macros. - Added MAKE_HOOK_AUTO macros. - Creates the desired hook and automatically registers it for later installation with the INSTALL_HOOKS macro. - Added the _HOOK_AUTO_INSTALL macro for internal use. - Registers a hook for later installation with the INSTALL_HOOKS macro. - Added the _HOOK_AUTO_INSTALL_ORIG macro for internal use. - Similar to _HOOK_AUTO_INSTALL but uses INSTALL_HOOK_ORIG to install the hook. - Added the make-autohooks.ps1 PowerShell script to automate the generation of autohooks.hpp. - The script creates modified versions of the standard hooks that automatically register to AutoHooks. - Modified the build script to run make-autohooks.ps1 prior to building the project.
1776d29
to
5139e7b
Compare
These were suggested as an alternative which would be placed after hook creation. #define INSTALL_HOOK_ON_DLOPEN(logger_, name_) \
__attribute((constructor)) void Hook_##name_##_Install() { \
INSTALL_HOOK(logger_, name_); \
}
#define INSTALL_HOOK_DIRECT_ON_DLOPEN(logger_, name_, addr_) \
__attribute((constructor)) void Hook_Direct_##name_##_Install() { \
INSTALL_HOOK_DIRECT(logger_, name_, addr_); \
}
#define INSTALL_HOOK_ORIG_ON_DLOPEN(logger_, name_) \
__attribute((constructor)) void Hook_Orig_##name_##_Install() { \
INSTALL_HOOK_ORIG(logger_, name_); \
} These would provide a way to automatically install hooks at library load, however these wouldn't allow the auto hooks to be installed at a specific point in the If someone requires precise installation of hooks, these macros are all optional after all and primarily serve as a convenience as opposed to creating the hooks and installing them all individually, usually inside the
// Create and register a hook to be installed later with `INSTALL_HOOKS();`
MAKE_HOOK_MATCH(MyHook, ...);
HOOK_AUTO_REGISTER(MyHook);
// These can be replaced with a single use of the new macro
MAKE_HOOK_AUTO_MATCH(MyHook, ...); or for the dlopen variant // Create and register a hook that will be immediately installed when the library is loaded.
MAKE_HOOK_MATCH(MyHook, ...);
INSTALL_HOOK_ON_DLOPEN(MyHook);
// These can be replaced with a single use of the new macro
MAKE_HOOK_DLOPEN_MATCH(MyHook, ...);
// Also available...
INSTALL_HOOK_ON_DLOPEN_ORIG(MyHook);
INSTALL_HOOK_ON_DLOPEN_DIRECT(MyHook, addr);
// And if you want to specify the logger used...
INSTALL_HOOK_ON_DLOPEN_LOGGER(myLogger, MyHook);
INSTALL_HOOK_ON_DLOPEN_ORIG_LOGGER(myLogger, MyHook);
INSTALL_HOOK_ON_DLOPEN_DIRECT_LOGGER(myLogger, MyHook, addr); |
398203b
to
d127da5
Compare
d127da5
to
713e1b7
Compare
- Updated to accept input and output file paths as parameters. - Improved error handling to check for the existence of the input file before processing. - Trimmed the extracted macro text for cleaner output. - Converted the file header text into a here-string for better readability and maintainability. - Add comments and slighly refactor for readability. - Output normalized line endings depending on OS
34454be
to
0927257
Compare
This adds convenience macros that mirror those in
logging.hpp
, but with the convenience to be installed on dlopen, or all at once withINSTALL_HOOKS();
at a user-defined location in the code.Added the AutoHooks class to manage the installation of hooks.
Added the INSTALL_HOOKS macro.
Added MAKE_HOOK_AUTO macros.
Added the HOOK_AUTO_REGISTER macro.
Added the HOOK_AUTO_REGISTER_ORIG macro.
Added the make-autohooks.ps1 PowerShell script to automate the generation of autohooks.hpp.
Modified the build script to run make-autohooks.ps1 prior to building the project.