本文整理汇总了C++中Symtab::addRegion方法的典型用法代码示例。如果您正苦于以下问题:C++ Symtab::addRegion方法的具体用法?C++ Symtab::addRegion怎么用?C++ Symtab::addRegion使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symtab
的用法示例。
在下文中一共展示了Symtab::addRegion方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makeInitAndFiniIfNeeded
void BinaryEdit::makeInitAndFiniIfNeeded()
{
using namespace Dyninst::SymtabAPI;
Symtab* linkedFile = getAOut()->parse_img()->getObject();
// Disable this for .o's and static binaries
if( linkedFile->isStaticBinary() ||
linkedFile->getObjectType() == obj_RelocatableFile )
{
return;
}
bool foundInit = false;
bool foundFini = false;
vector <Function *> funcs;
if (linkedFile->findFunctionsByName(funcs, "_init")) {
foundInit = true;
}
if (linkedFile->findFunctionsByName(funcs, "_fini")) {
foundFini = true;
}
if( !foundInit )
{
Offset initOffset = linkedFile->getInitOffset();
Region *initsec = linkedFile->findEnclosingRegion(initOffset);
if(!initOffset || !initsec)
{
unsigned char* emptyFunction = NULL;
int emptyFuncSize = 0;
#if defined(arch_x86) || defined(arch_x86_64)
static unsigned char empty_32[] = { 0x55, 0x89, 0xe5, 0xc9, 0xc3 };
static unsigned char empty_64[] = { 0x55, 0x48, 0x89, 0xe5, 0xc9, 0xc3 };
if(linkedFile->getAddressWidth() == 8)
{
emptyFunction = empty_64;
emptyFuncSize = 6;
}
else
{
emptyFunction = empty_32;
emptyFuncSize = 5;
}
#elif defined (arch_power)
static unsigned empty[] = {0x4e800020};
emptyFunction = (unsigned char*) empty;
emptyFuncSize = 4;
#endif //defined(arch_x86) || defined(arch_x86_64)
linkedFile->addRegion(highWaterMark_, (void*)(emptyFunction), emptyFuncSize, ".init.dyninst",
Dyninst::SymtabAPI::Region::RT_TEXT, true);
highWaterMark_ += emptyFuncSize;
lowWaterMark_ += emptyFuncSize;
linkedFile->findRegion(initsec, ".init.dyninst");
assert(initsec);
linkedFile->addSysVDynamic(DT_INIT, initsec->getMemOffset());
startup_printf("%s[%d]: creating .init.dyninst region, region addr 0x%lx\n",
FILE__, __LINE__, initsec->getMemOffset());
}
startup_printf("%s[%d]: ADDING _init at 0x%lx\n", FILE__, __LINE__, initsec->getMemOffset());
Symbol *initSym = new Symbol( "_init",
Symbol::ST_FUNCTION,
Symbol::SL_GLOBAL,
Symbol::SV_DEFAULT,
initsec->getMemOffset(),
linkedFile->getDefaultModule(),
initsec,
UINT_MAX );
linkedFile->addSymbol(initSym);
}
if( !foundFini )
{
Offset finiOffset = linkedFile->getFiniOffset();
Region *finisec = linkedFile->findEnclosingRegion(finiOffset);
if(!finiOffset || !finisec)
{
unsigned char* emptyFunction = NULL;
int emptyFuncSize = 0;
#if defined(arch_x86) || defined(arch_x86_64)
static unsigned char empty_32[] = { 0x55, 0x89, 0xe5, 0xc9, 0xc3 };
static unsigned char empty_64[] = { 0x55, 0x48, 0x89, 0xe5, 0xc9, 0xc3 };
if(linkedFile->getAddressWidth() == 8)
{
emptyFunction = empty_64;
emptyFuncSize = 6;
}
else
{
emptyFunction = empty_32;
emptyFuncSize = 5;
}
#elif defined (arch_power)
static unsigned empty[] = {0x4e800020};
emptyFunction = (unsigned char*) empty;
emptyFuncSize = 4;
#elif defined (arch_aarch64)
static unsigned char empty[] = {
0xfd, 0x7b, 0xbf, 0xa9,
0xfd, 0x03, 0x00, 0x91,
//.........这里部分代码省略.........
示例2: writeFile
//.........这里部分代码省略.........
assert(tracker);
//inst_printf("memory tracker: 0x%lx load=0x%lx size=%d %s\n",
//tracker->get_local_ptr(), tracker->get_address(), tracker->get_size(),
//tracker->alloced ? "[A]" : "");
if (!tracker->alloced) continue;
// Copy whatever is in there into the big buffer, at the appropriate address
assert(tracker->get_address() >= lowWaterMark_);
Address offset = tracker->get_address() - lowWaterMark_;
assert((offset + tracker->get_size()) < highWaterMark_);
void *ptr = (void *)(offset + (Address)newSectionPtr);
memcpy(ptr, tracker->get_local_ptr(), tracker->get_size());
}
// Righto. Now, that includes the old binary - by design -
// so skip it and see what we're talking about size-wise. Which should
// be less than the highWaterMark, so we can double-check.
// Next, make a new section. We have the following parameters:
// Offset vaddr: we get this from Symtab - "first free address with sufficient space"
// std::string name: without reflection, ".dyninstInst"
// unsigned long flags: these are a SymtabAPI abstraction. We're going with text|data because
// we might have both.
// bool loadable: heck yeah...
Region *newSec = NULL;
symObj->findRegion(newSec, ".dyninstInst");
if (newSec) {
// We're re-instrumenting - will fail for now
fprintf(stderr, "ERROR: unable to open/reinstrument previously instrumented binary %s!\n", newFileName.c_str());
return false;
}
symObj->addRegion(lowWaterMark_,
newSectionPtr,
highWaterMark_ - lowWaterMark_,
".dyninstInst",
Region::RT_TEXTDATA,
true);
fprintf(stderr,"Write lowWater : %lx, highWater : %lx\n",lowWaterMark_,highWaterMark_);
symObj->findRegion(newSec, ".dyninstInst");
assert(newSec);
if (mobj == getAOut()) {
// Add dynamic symbol relocations
for (unsigned i=0; i < dependentRelocations.size(); i++) {
Address to = dependentRelocations[i]->getAddress();
Symbol *referring = dependentRelocations[i]->getReferring();
/*
if (!symObj->isStaticBinary() && !symObj->hasReldyn() && !symObj->hasReladyn()) {
Address addr = referring->getOffset();
bool result = writeDataSpace((void *) to, getAddressWidth(), &addr);
assert(result);
continue;
}
*/
// Create the relocationEntry
relocationEntry localRel(to, referring->getMangledName(), referring,
relocationEntry::getGlobalRelType(getAddressWidth(), referring));
/*
if( mobj->isSharedLib() ) {
localRel.setRelAddr(to - mobj->imageOffset());