How can I get a list of all the dynamic libraries that is required by an elf binary in linux using C++?
Once I've managed to extract the information (filename?) from the binary I can find the actual file by searching through the PATH, but I haven't been able to find any information regarding extracting unmangled information from the ELF binary.
Thoughts?
Using the ldd Command It outputs the shared libraries required by a program.
You can do this with ldd command: NAME ldd - print shared library dependencies SYNOPSIS ldd [OPTION]... FILE...
The list of required shared objects is stored in the so-called dynamic section of the executable. The rough algorithm of getting the necessary info would be something like this:
ET_EXEC or ET_DYN).e_phoff/e_phnum/e_phentsize), check that they're non-zero and valid.PT_DYNAMIC one. Also remember virtual address -> file offset mappings for the PT_LOAD segments.DT_NEEDED and DT_STRTAB entries.The d_val field of the DT_NEEDED entries is the offset into the DT_STRTAB's string table, which will be the SONAME of the required libraries. Note that since DT_STRTAB entry is the run-time address and not the offset of the string table, you'll need to map it back to a file offset using information stored at step 3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With