Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enumerate all ELF sections of all shared objects currently loaded

I am looking for a nice way of enumerating all ELF sections and their addresses of the current binary and all shared objects the current process might have loaded.

I know about the existance of dl_iterate_phdr() which gives me an easy to use list of ELF segments, but I am looking for ELF sections, so it's not the right call for me.

I don't care about portability, as long as it works on Linux with ELF I am happy!

Any hint appreciated!

like image 690
user175104 Avatar asked Feb 01 '12 23:02

user175104


1 Answers

I assume you're trying to programmatically access this information from a C/C++ program. I suspect you should be able to do what you want with the GNU Binary File Descriptor library (BFD), which is used to implement the GNU linker, objdump, etc. (it also has a Wikipedia article). See in particular section 2.6 of the manual, which is all about sections. BFD creates a linked list of "struct bfd_section", accessed through the "sections" member of struct bfd. I think you should be able to open the current binary by using bfd_fopen on argv[0]. BFD ships with binutils.

like image 127
Chiara Coetzee Avatar answered Oct 14 '22 13:10

Chiara Coetzee