Skip to content

Hooking API

MCMrARM edited this page Sep 17, 2018 · 6 revisions

C API

The launcher provides the following basic C API for hooking:

modloader_hook_t *modloader_hook(void *sym, void *hook, void **orig);
void modloader_destroy_hook(modloader_hook_t *hook);

The modloader_hook function replaces the function given by sym with hook and stores a pointer that lets you call the original function in *orig. All passed arguments must not be NULL. Note that *orig will not exactly be the original function, but instead a trampoline function, but this should be considered an implementation detail. modloader_hook returns a pointer that you can use with modloader_destroy_hook to remove the hook at runtime. In case an error happens, modloader_hook will return NULL. It's possible that the function will modify the orig pointer, even if hooking fails.

The modloader_destroy_hook function removes the hook specified by hook. hook must not be NULL. The implementation will try to remove the hook, however this is not guaranteed to always be the case. The API currently does not provide a way to tell if removing the hook succeeded.

Clone this wiki locally