当前位置: 首页>>代码示例>>C++>>正文


C++ BinaryFile::SymbolByAddress方法代码示例

本文整理汇总了C++中BinaryFile::SymbolByAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryFile::SymbolByAddress方法的具体用法?C++ BinaryFile::SymbolByAddress怎么用?C++ BinaryFile::SymbolByAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryFile的用法示例。


在下文中一共展示了BinaryFile::SymbolByAddress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testWinLoad

/*==============================================================================
 * FUNCTION:        LoaderTest::testWinLoad
 * OVERVIEW:        Test loading Windows programs
 *============================================================================*/
void LoaderTest::testWinLoad ()
{
    std::ostringstream ost;

#if 0 /* FIXME: these tests should use non-proprietary programs */
    // Load Windows program calc.exe
    BinaryFileFactory bff;
    BinaryFile* pBF = bff.Load(CALC_WINDOWS);
    CPPUNIT_ASSERT(pBF != NULL);
    int n;
    SectionInfo* si;
    n = pBF->GetNumSections();
    ost << "Number of sections = " << std::dec << n << "\r\n";
    for (int i=0; i < n; i++)
        {
            si = pBF->GetSectionInfo(i);
            ost << si->pSectionName << "\t";
        }

    // Note: the string below needs to have embedded tabs. Edit with caution!
    std::string expected("Number of sections = 5\r\n"
                         ".text	.rdata	.data	.rsrc	.reloc	");
    std::string actual(ost.str());
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    ADDRESS addr = pBF->GetMainEntryPoint();
    CPPUNIT_ASSERT(addr != NO_ADDRESS);

    // Test symbol table (imports)
    const char* s = pBF->SymbolByAddress(0x1292060U);
    if (s == 0)
        actual = "<not found>";
    else
        actual = std::string(s);
    expected = std::string("SetEvent");
    CPPUNIT_ASSERT_EQUAL(expected, actual);

    ADDRESS a = pBF->GetAddressByName("SetEvent");
    ADDRESS expectedAddr = 0x1292060;
    CPPUNIT_ASSERT_EQUAL(expectedAddr, a);
    pBF->UnLoad();
    bff.UnLoad();

    // Test loading the "new style" exes, as found in winXP etc
    pBF = bff.Load(CALC_WINXP);
    CPPUNIT_ASSERT(pBF != NULL);
    addr = pBF->GetMainEntryPoint();
    std::ostringstream ost1;
    ost1 << std::hex << addr;
    actual = ost1.str();
    expected = "1001f51";
    CPPUNIT_ASSERT_EQUAL(expected, actual);
    pBF->UnLoad();
    bff.UnLoad();

    // Test loading the calc.exe found in Windows 2000 (more NT based)
    pBF = bff.Load(CALC_WIN2000);
    CPPUNIT_ASSERT(pBF != NULL);
    expected = "1001680";
    addr = pBF->GetMainEntryPoint();
    std::ostringstream ost2;
    ost2 << std::hex << addr;
    actual = ost2.str();
    CPPUNIT_ASSERT_EQUAL(expected, actual);
    pBF->UnLoad();
    bff.UnLoad();

    // Test loading the lpq.exe program - console mode PE file
    pBF = bff.Load(LPQ_WINDOWS);
    CPPUNIT_ASSERT(pBF != NULL);
    addr = pBF->GetMainEntryPoint();
    std::ostringstream ost3;
    ost3 << std::hex << addr;
    actual = ost3.str();
    expected = "18c1000";
    CPPUNIT_ASSERT_EQUAL(expected, actual);
    pBF->UnLoad();
    bff.UnLoad();
#endif

    // Borland
    BinaryFileFactory bff;
    BinaryFile* pBF = bff.Load(SWITCH_BORLAND);
    CPPUNIT_ASSERT(pBF != NULL);
    ADDRESS addr = pBF->GetMainEntryPoint();
    std::ostringstream ost4;
    ost4 << std::hex << addr;
    std::string actual(ost4.str());
    std::string expected("401150");
    CPPUNIT_ASSERT_EQUAL(expected, actual);
    pBF->UnLoad();
    bff.UnLoad();
}
开发者ID:JFreaker,项目名称:boomerang,代码行数:97,代码来源:LoaderTest.cpp


注:本文中的BinaryFile::SymbolByAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。