Closed joshop closed 2 years ago
You can call glibc functions if you want to, but it takes some extra steps:
Include stdlib.c
with LIBDL
defined:
#define LIBDL
#include "stdlib.c"
In the init()
function, use dlinit()
/dlopen()
/dlsym()
get the pointer to desired libc function(s), e.g.:
static void *free_ptr; // global
void init(int argc, char **argv, char **envp, void *dynamic)
{
dlinit(dynamic);
void *handle = dlopen("libc.so.6", RTLD_LAZY);
free_ptr = dlsym(handle, "free"); // free() function
...
}
Call the function pointer(s) in your instrumentation using dlcall()
:
dlcall(free_ptr, arg);
Please see the Call Trampoline Dynamic Loading section in the E9Tool User's Guide for more information.
The docs claim that libc can't be used in call instrumentation, and that you need to use the parallel libc for e.g. malloc. If you need to manipulate some memory that the main program needs to be able to deallocate or whatever, that probably wouldn't work. That being said, you could: