Im writing a script for extracting all the functions (written by user) in a binary.
The following shell script extracts my function names as well as some library functions which start with __
.
readelf -s ./a.out | gawk '
{
if ($4 == "FUNC" && $3 != "0" && $7 == "13" && $8 != "main") {
print "b " $NF; //***Updated
}
}' &> function_names;
Output of function_names file:
b __libc_csu_fini
b PrintDivider
b PrintFooter
b __libc_csu_init
b PrintHeader
I would like to extract only my functions. So how to check whether function name starts with __
or else any other alternatives also highly appreciated.
Update::
@djf solution works fine. What if .c
files which are compiled also may contain a function which starts with __
? In that case, how to differentiate?
_init , _start, _fini
– Recto