function address in libc?

Allan Jiang picture Allan Jiang · Mar 8, 2013 · Viewed 8.3k times · Source


I am trying to obtain the address (in hex) of function exit() provided in libc, but I am not sure where and how to find it.
Anyone knows the way to find it please share some idea. Thank you!

Answer

user4815162342 picture user4815162342 · Mar 8, 2013

If you need the address of the exit function already present in your process, see answers by Grijesh and others. But if you need to resolve the libc exit function by name, for example because libc's exit has been shadowed by another library, you can obtain it with dlsym:

#define _GNU_SOURCE     /* for RTLD_NEXT */
#include <dlfcn.h>
/* ... */
void (*exit_addr)(int) = dlsym(RTLD_NEXT, "exit");

For dlsym to resolve, you'll need to link with -ldl.