Section Readers

After the section data is received through the GetData() function call, the data can be manipulated. There are special sections that provide information in predefined forms. The ELFIO library processes these sections. The library provides a set of section readers that understand these predefined formats and how to process their data. The ELFIO.h header file currently defines the types of readers as:

    enum ReaderType {
        ELFI_STRING,     // Strings reader
        ELFI_SYMBOL,     // Symbol table reader
        ELFI_RELOCATION, // Relocation table reader
        ELFI_NOTE,       // Notes reader
        ELFI_DYNAMIC,    // Dynamic section reader
        ELFI_HASH        // Hash

How to use the symbol table reader will be demonstated in the following example:

First, get the symbol section:

    const IELFISection* pSec = pReader->GetSection( ''.symtab'' );

Second, create a symbol section reader:

    IELFISymbolTable* pSymTbl = 0;
    pReader->CreateSectionReader( IELFI::ELFI_SYMBOL,
                                  (void**)&pSymTbl );

And finally, use the section reader to process all entries (print operations are omitted):

    std::string   name;
    Elf32_Addr    value;
    Elf32_Word    size;
    unsigned char bind;
    unsigned char type;
    Elf32_Half    section;
    int nSymNo = pSymTbl->GetSymbolNum();
    if ( 0 < nSymNo ) {
        for ( int i = 0; i < nSymNo; ++i ) {
            pSymTbl->GetSymbol( i, name, value, size,
                                bind, type, section );