Function address in libc?


I am trying to get the address (in hexadecimal form) of the exit() ) function provided in libc, but I'm not sure where and how to find it.
Anyone know how to find it, please share some idea. Thanks!

+8
c linux libc
source share
5 answers

If you need the address of the exit function already present in your process, see the answers from Grijesh and others. But if you need to enable the libc exit function by name, for example, because libc exit was obscured by another library, you can get it with dlsym :

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

To enable dlsym , you need to associate with -ldl .

+9
source share

I think this will work:

 printf("%p", (void*)exit); 

IEEE Std 1003.1 2004 Edition:

"%p" argument must be a pointer to void . The pointer value is converted to a sequence of printable characters in accordance with the implementation.

+6
source share

The address of any function is simply its name (without parentheses). You will need #include <stdlib.h> . To set an initialized pointer:

 void (*p)(int) = exit; 
+5
source share

You can use gdb as follows:

 gdb ./yourprogram break main run print exit $1 = {<text variable, no debug info>} 0xb7e4b7f0 <exit> here is exit() address----------------^ 
+3
source share
 printf("%p", exit); 

You will need to enable stdio.h for printf and stdlib.h for output. This creates a pointer to a function to exit and print. A.

+1
source share

All Articles