本文整理汇总了C++中BinaryFileFactory类的典型用法代码示例。如果您正苦于以下问题:C++ BinaryFileFactory类的具体用法?C++ BinaryFileFactory怎么用?C++ BinaryFileFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BinaryFileFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testPentiumLoad
/*==============================================================================
* FUNCTION: LoaderTest::testPentiumLoad
* OVERVIEW: Test loading the pentium (Solaris) hello world program
*============================================================================*/
void LoaderTest::testPentiumLoad ()
{
std::ostringstream ost;
// Load Pentium hello world
BinaryFileFactory bff;
BinaryFile* pBF = bff.Load(HELLO_PENTIUM);
CPPUNIT_ASSERT(pBF != NULL);
int n;
SectionInfo* si;
n = pBF->GetNumSections();
ost << "Number of sections = " << std::dec << n << "\r\n\t";
si = pBF->GetSectionInfo(1);
ost << si->pSectionName << "\t";
si = pBF->GetSectionInfo(n-1);
ost << si->pSectionName;
pBF->UnLoad();
// Note: the string below needs to have embedded tabs. Edit with caution!
// (And slightly different string to the sparc test, e.g. rel vs rela)
std::string expected("Number of sections = 34\r\n\t"
".interp .strtab");
CPPUNIT_ASSERT_EQUAL(expected, ost.str());
bff.UnLoad();
}
示例2: testRenameVars
/*==============================================================================
* FUNCTION: CfgTest::testRenameVars
* OVERVIEW: Test the renaming of variables
*============================================================================*/
void CfgTest::testRenameVars ()
{
BinaryFileFactory bff;
BinaryFile* pBF = bff.Load(FRONTIER_PENTIUM);
CPPUNIT_ASSERT(pBF != 0);
Prog* prog = new Prog;
FrontEnd* pFE = new PentiumFrontEnd(pBF, prog, &bff);
Type::clearNamedTypes();
prog->setFrontEnd(pFE);
pFE->decode(prog);
UserProc* pProc = (UserProc*) prog->getProc(0);
Cfg* cfg = pProc->getCFG();
DataFlow* df = pProc->getDataFlow();
// Simplify expressions (e.g. m[ebp + -8] -> m[ebp - 8]
prog->finishDecode();
df->dominators(cfg);
df->placePhiFunctions(pProc);
pProc->numberStatements(); // After placing phi functions!
df->renameBlockVars(pProc, 0, 1); // Block 0, mem depth 1
// MIKE: something missing here?
delete pFE;
}
示例3: Prog
/*==============================================================================
* FUNCTION: ProcTest::testName
* OVERVIEW: Test setting and reading name, constructor, native address
*============================================================================*/
void ProcTest::testName ()
{
Prog* prog = new Prog();
BinaryFile *pBF = new BinaryFileStub();
CPPUNIT_ASSERT(pBF != 0);
std::string nm("default name");
BinaryFileFactory bff;
pBF = bff.Load(HELLO_PENTIUM);
FrontEnd *pFE = new PentiumFrontEnd(pBF, prog, &bff);
CPPUNIT_ASSERT(pFE != 0);
prog->setFrontEnd(pFE);
CPPUNIT_ASSERT(prog);
pFE->readLibraryCatalog(); // Since we are not decoding
m_proc = new UserProc(prog, nm, 20000); // Will print in decimal if error
std::string actual(m_proc->getName());
CPPUNIT_ASSERT_EQUAL(std::string("default name"), actual);
std::string name("printf");
LibProc lp(prog, name, 30000);
actual = lp.getName();
CPPUNIT_ASSERT_EQUAL(name, actual);
ADDRESS a = lp.getNativeAddress();
ADDRESS expected = 30000;
CPPUNIT_ASSERT_EQUAL(expected, a);
a = m_proc->getNativeAddress();
expected = 20000;
CPPUNIT_ASSERT_EQUAL(expected, a);
delete prog;
delete m_proc;
// delete pFE; // No! Deleting the prog deletes the pFE already (which deletes the BinaryFileFactory)
}
示例4: testPalmLoad
/*==============================================================================
* FUNCTION: LoaderTest::testPalmLoad
* OVERVIEW: Test loading the Palm 68328 Starter.prc program
*============================================================================*/
void LoaderTest::testPalmLoad ()
{
std::ostringstream ost;
// Load Palm Starter.prc
BinaryFileFactory bff;
BinaryFile* pBF = bff.Load(STARTER_PALM);
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";
}
pBF->UnLoad();
// Note: the string below needs to have embedded tabs. Edit with caution!
std::string expected("Number of sections = 8\r\n"
"code1 MBAR1000 tFRM1000 Talt1001 "
"data0 code0 tAIN1000 tver1000 ");
CPPUNIT_ASSERT_EQUAL(expected, ost.str());
bff.UnLoad();
}
示例5: testCompound
/*==============================================================================
* FUNCTION: TypeTest::testNotEqual
* OVERVIEW: Test type inequality
*============================================================================*/
void TypeTest::testCompound() {
BinaryFileFactory bff;
BinaryFile *pBF = bff.Load(HELLO_WINDOWS);
FrontEnd *pFE = new PentiumFrontEnd(pBF, new Prog, &bff);
Boomerang::get()->setLogger(new FileLogger()); // May try to output some messages to LOG
pFE->readLibraryCatalog(); // Read definitions
Signature* paintSig = pFE->getLibSignature("BeginPaint");
// Second argument should be an LPPAINTSTRUCT
Type* ty = paintSig->getParamType(1);
const char* p = ty->getCtype();
std::string expected("LPPAINTSTRUCT");
std::string actual(p);
CPPUNIT_ASSERT_EQUAL(expected, actual);
// Get the type pointed to
ty = ty->asPointer()->getPointsTo();
p = ty->getCtype();
expected = "PAINTSTRUCT";
actual = p;
CPPUNIT_ASSERT_EQUAL(expected, actual);
// Offset 8 should have a RECT
Type* subTy = ty->asCompound()->getTypeAtOffset(8*8);
p = subTy->getCtype();
expected = "RECT";
actual = p;
CPPUNIT_ASSERT_EQUAL(expected, actual);
// Name at offset C should be bottom
p = subTy->asCompound()->getNameAtOffset(0x0C*8);
expected = "bottom";
actual = p;
CPPUNIT_ASSERT_EQUAL(expected, actual);
// Now figure out the name at offset 8+C
p = ty->asCompound()->getNameAtOffset((8 + 0x0C)*8);
expected = "rcPaint";
actual = p;
CPPUNIT_ASSERT_EQUAL(expected, actual);
// Also at offset 8
p = ty->asCompound()->getNameAtOffset((8 + 0)*8);
actual = p;
CPPUNIT_ASSERT_EQUAL(expected, actual);
// Also at offset 8+4
p = ty->asCompound()->getNameAtOffset((8 + 4)*8);
actual = p;
CPPUNIT_ASSERT_EQUAL(expected, actual);
// And at offset 8+8
p = ty->asCompound()->getNameAtOffset((8 + 8)*8);
actual = p;
CPPUNIT_ASSERT_EQUAL(expected, actual);
delete pFE;
}
示例6: Binary
/*==============================================================================
* FUNCTION: CfgTest::testPlacePhi2
* OVERVIEW: Test a case where a phi function is not needed
*============================================================================*/
void CfgTest::testPlacePhi2 ()
{
BinaryFileFactory bff;
BinaryFile* pBF = bff.Load(IFTHEN_PENTIUM);
CPPUNIT_ASSERT(pBF != 0);
Prog* prog = new Prog;
FrontEnd* pFE = new PentiumFrontEnd(pBF, prog, &bff);
Type::clearNamedTypes();
prog->setFrontEnd(pFE);
pFE->decode(prog);
UserProc* pProc = (UserProc*) prog->getProc(0);
Cfg* cfg = pProc->getCFG();
DataFlow* df = pProc->getDataFlow();
// Simplify expressions (e.g. m[ebp + -8] -> m[ebp - 8]
prog->finishDecode();
df->dominators(cfg);
df->placePhiFunctions(pProc);
// In this program, x is allocated at [ebp-4], a at [ebp-8], and
// b at [ebp-12]
// We check that A_phi[ m[ebp-8] ] is 4, and that
// A_phi A_phi[ m[ebp-8] ] is null
// (block 4 comes out with n=4)
std::string expected = "4 ";
std::ostringstream actual;
// m[r29 - 8]
Exp* e = new Unary(opMemOf,
new Binary(opMinus,
Location::regOf(29),
new Const(8)));
std::set<int>& s = df->getA_phi(e);
std::set<int>::iterator pp;
for (pp = s.begin(); pp != s.end(); pp++)
actual << *pp << " ";
CPPUNIT_ASSERT_EQUAL(expected, actual.str());
delete e;
expected = "";
std::ostringstream actual2;
// m[r29 - 12]
e = new Unary(opMemOf,
new Binary(opMinus,
Location::regOf(29),
new Const(12)));
std::set<int>& s2 = df->getA_phi(e);
for (pp = s2.begin(); pp != s2.end(); pp++)
actual2 << *pp << " ";
CPPUNIT_ASSERT_EQUAL(expected, actual2.str());
delete e;
delete pFE;
}
示例7: Load
FrontEnd* FrontEnd::Load(const char *fname, Prog* prog) {
BinaryFileFactory* pbff = new BinaryFileFactory;
if (pbff == NULL) return NULL;
std::cout<<"in frontend::load pBF =bff->load\n";
BinaryFile *pBF = pbff->Load(fname);
std::cout<< fname << "\n";
if(ASS_FILE)prog->m_path=fname;//donbinhvn: remember path for later processing
if (pBF == NULL) return NULL;
return instantiate(pBF, prog, pbff);
}
示例8: testIsCompare
/*==============================================================================
* FUNCTION: RtlTest::testIsCompare
* OVERVIEW: Test the isCompare function
*============================================================================*/
void RtlTest::testIsCompare ()
{
BinaryFileFactory bff;
BinaryFile *pBF = bff.Load(SWITCH_SPARC);
CPPUNIT_ASSERT(pBF != 0);
CPPUNIT_ASSERT(pBF->GetMachine() == MACHINE_SPARC);
Prog* prog = new Prog;
FrontEnd *pFE = new SparcFrontEnd(pBF, prog, &bff);
prog->setFrontEnd(pFE);
// Decode second instruction: "sub %i0, 2, %o1"
int iReg;
Exp* eOperand = NULL;
DecodeResult inst = pFE->decodeInstruction(0x10910);
CPPUNIT_ASSERT(inst.rtl != NULL);
CPPUNIT_ASSERT(inst.rtl->isCompare(iReg, eOperand) == false);
// Decode fifth instruction: "cmp %o1, 5"
inst = pFE->decodeInstruction(0x1091c);
CPPUNIT_ASSERT(inst.rtl != NULL);
CPPUNIT_ASSERT(inst.rtl->isCompare(iReg, eOperand) == true);
CPPUNIT_ASSERT_EQUAL(9, iReg);
std::string expected("5");
std::ostringstream ost1;
eOperand->print(ost1);
std::string actual(ost1.str());
CPPUNIT_ASSERT_EQUAL(expected, actual);
pBF->UnLoad();
delete pBF;
delete pFE;
pBF = bff.Load(SWITCH_PENT);
CPPUNIT_ASSERT(pBF != 0);
CPPUNIT_ASSERT(pBF->GetMachine() == MACHINE_PENTIUM);
pFE = new PentiumFrontEnd(pBF, prog, &bff);
prog->setFrontEnd(pFE);
// Decode fifth instruction: "cmp $0x5,%eax"
inst = pFE->decodeInstruction(0x80488fb);
CPPUNIT_ASSERT(inst.rtl != NULL);
CPPUNIT_ASSERT(inst.rtl->isCompare(iReg, eOperand) == true);
CPPUNIT_ASSERT_EQUAL(24, iReg);
std::ostringstream ost2;
eOperand->print(ost2);
actual = ost2.str();
CPPUNIT_ASSERT_EQUAL(expected, actual);
// Decode instruction: "add $0x4,%esp"
inst = pFE->decodeInstruction(0x804890c);
CPPUNIT_ASSERT(inst.rtl != NULL);
CPPUNIT_ASSERT(inst.rtl->isCompare(iReg, eOperand) == false);
pBF->UnLoad();
delete pFE;
}
示例9: testSemiDominators
void CfgTest::testSemiDominators ()
{
BinaryFileFactory bff;
BinaryFile* pBF = bff.Load(SEMI_PENTIUM);
CPPUNIT_ASSERT(pBF != 0);
Prog* prog = new Prog;
FrontEnd* pFE = new PentiumFrontEnd(pBF, prog, &bff);
Type::clearNamedTypes();
prog->setFrontEnd(pFE);
pFE->decode(prog);
bool gotMain;
ADDRESS addr = pFE->getMainEntryPoint(gotMain);
CPPUNIT_ASSERT (addr != NO_ADDRESS);
UserProc* pProc = (UserProc*) prog->getProc(0);
Cfg* cfg = pProc->getCFG();
DataFlow* df = pProc->getDataFlow();
df->dominators(cfg);
// Find BB "L (6)" (as per Appel, Figure 19.8).
BB_IT it;
PBB bb = cfg->getFirstBB(it);
while (bb && bb->getLowAddr() != SEMI_L)
{
bb = cfg->getNextBB(it);
}
CPPUNIT_ASSERT(bb);
int nL = df->pbbToNode(bb);
// The dominator for L should be B, where the semi dominator is D
// (book says F)
unsigned actual_dom = (unsigned)df->nodeToBB(df->getIdom(nL))->getLowAddr();
unsigned actual_semi = (unsigned)df->nodeToBB(df->getSemi(nL))->getLowAddr();
CPPUNIT_ASSERT_EQUAL((unsigned)SEMI_B, actual_dom);
CPPUNIT_ASSERT_EQUAL((unsigned)SEMI_D, actual_semi);
// Check the final dominator frontier as well; should be M and B
std::ostringstream expected, actual;
//expected << std::hex << SEMI_M << " " << SEMI_B << " ";
expected << std::hex << SEMI_B << " " << SEMI_M << " ";
std::set<int>::iterator ii;
std::set<int>& DFset = df->getDF(nL);
for (ii=DFset.begin(); ii != DFset.end(); ii++)
actual << std::hex << (unsigned)df->nodeToBB(*ii)->getLowAddr() << " ";
CPPUNIT_ASSERT_EQUAL(expected.str(), actual.str());
delete pFE;
}
示例10: expected
/*==============================================================================
* FUNCTION: FrontPentTest::test1
* OVERVIEW: Test decoding some pentium instructions
*============================================================================*/
void FrontPentTest::test1 ()
{
std::ostringstream ost;
BinaryFileFactory bff;
BinaryFile *pBF = bff.Load(HELLO_PENT);
if (pBF == NULL)
pBF = new BinaryFileStub();
CPPUNIT_ASSERT(pBF != 0);
CPPUNIT_ASSERT(pBF->GetMachine() == MACHINE_PENTIUM);
Prog* prog = new Prog;
FrontEnd *pFE = new PentiumFrontEnd(pBF, prog, &bff);
prog->setFrontEnd(pFE);
bool gotMain;
ADDRESS addr = pFE->getMainEntryPoint(gotMain);
CPPUNIT_ASSERT (addr != NO_ADDRESS);
// Decode first instruction
DecodeResult inst = pFE->decodeInstruction(addr);
inst.rtl->print(ost);
std::string expected(
"08048328 0 *32* m[r28 - 4] := r29\n"
" 0 *32* r28 := r28 - 4\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(ost.str()));
std::ostringstream o2;
addr += inst.numBytes;
inst = pFE->decodeInstruction(addr);
inst.rtl->print(o2);
expected = std::string("08048329 0 *32* r29 := r28\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o2.str()));
std::ostringstream o3;
addr = 0x804833b;
inst = pFE->decodeInstruction(addr);
inst.rtl->print(o3);
expected = std::string(
"0804833b 0 *32* m[r28 - 4] := 0x80483fc\n"
" 0 *32* r28 := r28 - 4\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o3.str()));
delete pFE;
// delete pBF;
}
示例11: testName
/*==============================================================================
* FUNCTION: ProgTest::testName
* OVERVIEW: Test setting and reading name
*============================================================================*/
void ProgTest::testName ()
{
BinaryFileFactory bff;
BinaryFile *pBF = bff.Load(HELLO_PENTIUM); // Don't actually use it
Prog* prog = new Prog();
FrontEnd *pFE = new PentiumFrontEnd(pBF, prog, &bff);
// We need a Prog object with a pBF (for getEarlyParamExp())
prog->setFrontEnd(pFE);
std::string actual(prog->getName());
std::string expected(HELLO_PENTIUM);
CPPUNIT_ASSERT_EQUAL(expected, actual);
std::string name("Happy prog");
prog->setName(name.c_str());
actual = prog->getName();
CPPUNIT_ASSERT_EQUAL(name, actual);
delete pFE;
}
示例12: BinaryFileStub
void FrontSparcTest::test2() {
DecodeResult inst;
std::string expected;
BinaryFileFactory bff;
BinaryFile *pBF = bff.Load(HELLO_SPARC);
if (pBF == NULL)
pBF = new BinaryFileStub(); // fallback on stub
CPPUNIT_ASSERT(pBF != 0);
CPPUNIT_ASSERT(pBF->GetMachine() == MACHINE_SPARC);
Prog* prog = new Prog;
FrontEnd *pFE = new SparcFrontEnd(pBF, prog, &bff);
prog->setFrontEnd(pFE);
std::ostringstream o1;
inst = pFE->decodeInstruction(0x10690);
inst.rtl->print(o1);
// This call is to out of range of the program's text limits (to the Program Linkage Table (PLT), calling printf)
// This is quite normal.
expected = std::string("00010690 0 CALL printf(\n"
" )\n"
" Reaching definitions: \n"
" Live variables: \n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o1.str()));
std::ostringstream o2;
inst = pFE->decodeInstruction(0x10694);
inst.rtl->print(o2);
expected = std::string("00010694\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o2.str()));
std::ostringstream o3;
inst = pFE->decodeInstruction(0x10698);
inst.rtl->print(o3);
expected = std::string("00010698 0 *32* r8 := 0\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o3.str()));
std::ostringstream o4;
inst = pFE->decodeInstruction(0x1069c);
inst.rtl->print(o4);
expected = std::string("0001069c 0 *32* r24 := r8\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o4.str()));
delete pFE;
// delete pBF;
}
示例13: testBranch
void FrontPentTest::testBranch()
{
DecodeResult inst;
std::string expected;
BinaryFileFactory bff;
BinaryFile *pBF = bff.Load(BRANCH_PENT);
if (pBF == NULL)
pBF = new BinaryFileStub();
CPPUNIT_ASSERT(pBF != 0);
CPPUNIT_ASSERT(pBF->GetMachine() == MACHINE_PENTIUM);
Prog* prog = new Prog;
FrontEnd *pFE = new PentiumFrontEnd(pBF, prog, &bff);
prog->setFrontEnd(pFE);
// jne
std::ostringstream o1;
inst = pFE->decodeInstruction(0x8048979);
inst.rtl->print(o1);
expected = std::string("08048979 0 BRANCH 0x8048988, condition "
"not equals\n"
"High level: %flags\n");
CPPUNIT_ASSERT_EQUAL(expected, o1.str());
// jg
std::ostringstream o2;
inst = pFE->decodeInstruction(0x80489c1);
inst.rtl->print(o2);
expected = std::string(
"080489c1 0 BRANCH 0x80489d5, condition signed greater\n"
"High level: %flags\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o2.str()));
// jbe
std::ostringstream o3;
inst = pFE->decodeInstruction(0x8048a1b);
inst.rtl->print(o3);
expected = std::string(
"08048a1b 0 BRANCH 0x8048a2a, condition unsigned less or equals\n"
"High level: %flags\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o3.str()));
delete pFE;
// delete pBF;
}
示例14: testBranch
void FrontSparcTest::testBranch() {
DecodeResult inst;
std::string expected;
BinaryFileFactory bff;
BinaryFile *pBF = bff.Load(BRANCH_SPARC);
if (pBF == NULL)
pBF = new BinaryFileStub(); // fallback on stub
CPPUNIT_ASSERT(pBF != 0);
CPPUNIT_ASSERT(pBF->GetMachine() == MACHINE_SPARC);
Prog* prog = new Prog;
FrontEnd *pFE = new SparcFrontEnd(pBF, prog, &bff);
prog->setFrontEnd(pFE);
// bne
std::ostringstream o1;
inst = pFE->decodeInstruction(0x10ab0);
inst.rtl->print(o1);
expected = std::string(
"00010ab0 0 BRANCH 0x10ac8, condition not equals\n"
"High level: %flags\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o1.str()));
// bg
std::ostringstream o2;
inst = pFE->decodeInstruction(0x10af8);
inst.rtl->print(o2);
expected = std::string("00010af8 0 BRANCH 0x10b10, condition "
"signed greater\n"
"High level: %flags\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o2.str()));
// bleu
std::ostringstream o3;
inst = pFE->decodeInstruction(0x10b44);
inst.rtl->print(o3);
expected = std::string(
"00010b44 0 BRANCH 0x10b54, condition unsigned less or equals\n"
"High level: %flags\n");
CPPUNIT_ASSERT_EQUAL(expected, std::string(o3.str()));
delete pFE;
// delete pBF;
}
示例15: testDominators
void CfgTest::testDominators ()
{
BinaryFileFactory bff;
BinaryFile *pBF = bff.Load(FRONTIER_PENTIUM);
CPPUNIT_ASSERT(pBF != 0);
Prog* prog = new Prog;
FrontEnd *pFE = new PentiumFrontEnd(pBF, prog, &bff);
Type::clearNamedTypes();
prog->setFrontEnd(pFE);
pFE->decode(prog);
bool gotMain;
ADDRESS addr = pFE->getMainEntryPoint(gotMain);
CPPUNIT_ASSERT (addr != NO_ADDRESS);
UserProc* pProc = (UserProc*) prog->getProc(0);
Cfg* cfg = pProc->getCFG();
DataFlow* df = pProc->getDataFlow();
df->dominators(cfg);
// Find BB "5" (as per Appel, Figure 19.5).
BB_IT it;
PBB bb = cfg->getFirstBB(it);
while (bb && bb->getLowAddr() != FRONTIER_FIVE)
{
bb = cfg->getNextBB(it);
}
CPPUNIT_ASSERT(bb);
std::ostringstream expected, actual;
//expected << std::hex << FRONTIER_FIVE << " " << FRONTIER_THIRTEEN << " " << FRONTIER_TWELVE << " " <<
// FRONTIER_FOUR << " ";
expected << std::hex << FRONTIER_THIRTEEN << " " << FRONTIER_FOUR << " " << FRONTIER_TWELVE << " " <<
FRONTIER_FIVE << " ";
int n5 = df->pbbToNode(bb);
std::set<int>::iterator ii;
std::set<int>& DFset = df->getDF(n5);
for (ii=DFset.begin(); ii != DFset.end(); ii++)
actual << std::hex << (unsigned)df->nodeToBB(*ii)->getLowAddr() << " ";
CPPUNIT_ASSERT_EQUAL(expected.str(), actual.str());
pBF->UnLoad();
delete pFE;
}