dynamic - Conditionally replacing a C function at runtime -
is possible conditionally replace function @ runtime in c (in particular, function in dynamically loaded library)?
i know can use ld_preload or make function of same name, such as:
// silly example intercepting exit typedef void (*exit_func)(int code); void exit(int code) { exit_func orig_exit = (exit_func)dlsym(rtld_next, "exit"); nslog(@"exit called code %d!!!!", code); orig_exit(code); }
however, possible conditionally replace function, @ runtime, after program has loaded , running?
if(some_condition) { swap_impementations(exit, my_exit); }
edit: similar is possible swap c functions? specifically, trying intercept call function different library loaded operating system.
what means that, example, intercept exit() function stdlib, call exit() anywhere call implementation instead of original, example above, except controllable @ runtime.
there have been suggestions of hooking call overwriting original jump instruction, hoping doesn't require stomping on executable memory, perhaps there call in dynamic linker "re-link" function after program starts , point somewhere else?
use function pointer purpose.
Comments
Post a Comment