#Error in xdl_iterate_phdr callback

9 messages · Page 1 of 1 (latest)

naive jackal
#

Hello,
I want to write a C++ function that uses the xdl_iterate_phdr API to iterate over the program headers of a shared library (.so) for which I have the handle. The goal is to extract all the functions exported by this library and store them in a std::vector<ExportedFunction>. Each element of this vector will contain the function's name and its memory address.

The ExportedFunction structure I’m using to store this information is defined as follows:

    std::string name;
    void* address;
};```

So I have written a callback but it's seems to struggle when looping in `dyn`:
timber narwhalBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

naive jackal
split dock
# naive jackal Here is the callback

To write a C++ function that uses the xdl_iterate_phdr API to iterate over the program headers of a shared library (.so) and extract all exported functions, you'll need to parse the dynamic section of the library to find the symbol table and the string table.

#

Here's how you can approach it:

Set Up the Callback Function: This function will be called by xdl_iterate_phdr for each program header in the shared library. In this callback, you'll need to find the dynamic section that contains information about the symbols.

Parse the Dynamic Section: You'll loop through the entries in the dynamic section to locate the symbol table (DT_SYMTAB) and the string table (DT_STRTAB).

Extract Symbols: Once you have the symbol table and the corresponding string table, you can extract each symbol and check if it represents a function.

Store Exported Functions: For each function symbol, you'll store its name and address in your std::vector<ExportedFunction>.

naive jackal
#

Looks like chatgpt but ok

#

And for the callback function do you know where can be the problem

#

Btw stop using chatgpt for answers we can all create an openai account if we want

naive jackal
#

Do someone else have a solution ?