⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 relocationtable.cpp

📁 C++写的,提供操作ELF格式文件的API
💻 CPP
字号:
#include <cstdio>
#include <ELFIO.h>

int main( int, char* argv[] )
{
    // Create a ELFI reader
    IELFI* pReader;
    ELFIO::GetInstance()->CreateELFI( &pReader );

    // Initialize it
    char* filename = argv[1];
    pReader->Load( filename );

    // Get .text relocation entry
    // List all sections of the file
    int i;
    int nSecNo = pReader->GetSectionsNum();
    for ( i = 0; i < nSecNo; ++i ) {    // For all sections
        const IELFISection* pSec = pReader->GetSection( i );
        if ( SHT_REL != pSec->GetType() && SHT_RELA != pSec->GetType() ) {
            pSec->Release();
            continue;
        }
        const IELFIRelocationTable* pRel = 0;
        pReader->CreateSectionReader( IELFI::ELFI_RELOCATION, pSec, (void**)&pRel );

        // Print all entries
        Elf32_Addr     offset;
        Elf32_Addr     symbolValue;
        std::string    symbolName;
        unsigned char  type;
        Elf32_Sword    addend;
        Elf32_Sword    calcValue;
        Elf32_Word nNum = pRel->GetEntriesNum();
        if ( 0 < nNum ) {
            std::printf( "\nSection name: %s\n", pSec->GetName().c_str() );
            std::printf( "  Num Type Offset   Addend    Calc   SymValue   SymName\n" );
            for ( Elf32_Word i = 0; i < nNum; ++i ) {
                pRel->GetEntry( i, offset, symbolValue, symbolName,
                                type, addend, calcValue );
                std::printf( "[%4x] %02x %08x %08x %08x %08x %s\n",
                             i, type, offset,
                             addend, calcValue,
                             symbolValue, symbolName.c_str() );
            }
        }

        pSec->Release();
        pRel->Release();
    }

    // Free resources
    pReader->Release();

    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -