Identifying the "main" function
There are times when de-compiling a binary (eg. Ghidra) may not directly reveal the address of the main function. This may happen as a result of a few things:
Stripped symbols: the symbol table was removed, so
mainhas no namemainis invoked indirectly (via__libc_start_mainor via.init_arrayconstructors)
In this section, I will discuss a few techniques to discover the starting address of the main function.
Debugging (GDB)
1. Discover entry address
a. readelf
-lflag: Displays the information contained in the file's segment headers, if it has anyother possible flag names for
-l:--program-headers/--segments
We can view the entry point:
$ readelf -l <bin_file> | grep -i Entry
Entry point 0xxxxb. objdump
--disassemble --disassemble-all: performs disassembly-M/--disassembler-options: pass target specific information to the disassemblerWe pass the value intel, to tells objdump to print assembly in Intel syntax instead of the default AT&T syntax
grep '__libc_start_main'to grep the value __libc_start_main, which represents the initial function called by default that will eventually call the main function
2. Analyse disassembly
Perform
stepiuntil right before the firstcallcommandThis will typically be the __libc_start_main function
The first argument (stored in the rdi register) will be the address of the main function
Ghidra
Look for the "entry" function
Look for
__libc_start_main

The first argument to the __libc_start_main function will be the main function
In the image above, it will be the
FUN_001008a1function
Last updated