本文整理汇总了C++中instruction::Ptr::getControlFlowTarget方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::getControlFlowTarget方法的具体用法?C++ Ptr::getControlFlowTarget怎么用?C++ Ptr::getControlFlowTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类instruction::Ptr
的用法示例。
在下文中一共展示了Ptr::getControlFlowTarget方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getInsn
bool
PatchBlock::containsDynamicCall() {
const ParseAPI::Block::edgelist & out_edges = block_->targets();
ParseAPI::Block::edgelist::const_iterator eit = out_edges.begin();
for( ; eit != out_edges.end(); ++eit) {
if ( ParseAPI::CALL == (*eit)->type() ) {
// see if it's a static call to a bad address
if ((*eit)->sinkEdge()) {
using namespace InstructionAPI;
Instruction::Ptr insn = getInsn(last());
if (insn->readsMemory()) { // memory indirect
return true;
} else { // check for register indirect
set<InstructionAST::Ptr> regs;
Expression::Ptr tExpr = insn->getControlFlowTarget();
if (tExpr)
tExpr->getUses(regs);
for (set<InstructionAST::Ptr>::iterator rit = regs.begin();
rit != regs.end(); rit++)
{
if (RegisterAST::makePC(obj()->co()->cs()->getArch()).getID() !=
boost::dynamic_pointer_cast<RegisterAST>(*rit)->getID())
{
return true;
}
}
}
}
}
}
return false;
}
示例2: d
std::pair<bool, Address> parse_block::callTarget() {
using namespace InstructionAPI;
Offset off = lastInsnOffset();
const unsigned char *ptr = (const unsigned char *)getPtrToInstruction(off);
if (ptr == NULL) return std::make_pair(false, 0);
InstructionDecoder d(ptr, endOffset() - lastInsnOffset(), obj()->cs()->getArch());
Instruction::Ptr insn = d.decode();
// Bind PC to that insn
// We should build a free function to do this...
Expression::Ptr cft = insn->getControlFlowTarget();
if (cft) {
Expression::Ptr pc(new RegisterAST(MachRegister::getPC(obj()->cs()->getArch())));
cft->bind(pc.get(), Result(u64, lastInsnAddr()));
Result res = cft->eval();
if (!res.defined) return std::make_pair(false, 0);
return std::make_pair(true, res.convert<Address>());
}
return std::make_pair(false, 0);
}
示例3: decoder
func_instance *mapped_object::findGlobalDestructorFunc(const std::string &dtorHandler) {
using namespace Dyninst::InstructionAPI;
const pdvector<func_instance *> *funcs = findFuncVectorByMangled(dtorHandler);
if( funcs != NULL ) {
return funcs->at(0);
}
/*
* If the symbol isn't found, try looking for it in a call in the
* .fini section. It is the last call in .fini.
*
* The pattern is:
*
* _fini:
*
* ... some code ...
*
* call dtor_handler
*
* ... prologue ...
*/
Symtab *linkedFile = parse_img()->getObject();
Region *finiRegion = NULL;
if( !linkedFile->findRegion(finiRegion, ".fini") ) {
vector<Dyninst::SymtabAPI::Function *> symFuncs;
if( linkedFile->findFunctionsByName(symFuncs, "_fini") ) {
finiRegion = symFuncs[0]->getRegion();
}else{
logLine("failed to locate .fini Region or _fini function\n");
return NULL;
}
}
if( finiRegion == NULL ) {
logLine("failed to locate .fini Region or _fini function\n");
return NULL;
}
// Search for last call in the function
Address dtorAddress = 0;
unsigned bytesSeen = 0;
const unsigned char *p = reinterpret_cast<const unsigned char *>(finiRegion->getPtrToRawData());
InstructionDecoder decoder(p, finiRegion->getDiskSize(),
parse_img()->codeObject()->cs()->getArch());
Instruction::Ptr lastCall;
Instruction::Ptr curInsn = decoder.decode();
while(curInsn && curInsn->isValid() &&
bytesSeen < finiRegion->getDiskSize())
{
InsnCategory category = curInsn->getCategory();
if( category == c_CallInsn ) {
lastCall = curInsn;
break;
}
bytesSeen += curInsn->size();
curInsn = decoder.decode();
}
if( !lastCall.get() || !lastCall->isValid() ) {
logLine("heuristic for finding global destructor function failed\n");
return NULL;
}
Address callAddress = finiRegion->getMemOffset() + bytesSeen;
RegisterAST thePC = RegisterAST(
Dyninst::MachRegister::getPC(parse_img()->codeObject()->cs()->getArch()));
Expression::Ptr callTarget = lastCall->getControlFlowTarget();
if( !callTarget.get() ) {
logLine("failed to find global destructor function\n");
return NULL;
}
callTarget->bind(&thePC, Result(s64, callAddress));
Result actualTarget = callTarget->eval();
if( actualTarget.defined ) {
dtorAddress = actualTarget.convert<Address>();
}else{
logLine("failed to find global destructor function\n");
return NULL;
}
if( !dtorAddress || !parse_img()->codeObject()->cs()->isValidAddress(dtorAddress) ) {
logLine("invalid address for global destructor function\n");
return NULL;
}
// A targ stub should have been created at the address
func_instance *ret = NULL;
if( (ret = findFuncByEntry(dtorAddress)) == NULL ) {
logLine("unable to find global destructor function\n");
return NULL;
}
inst_printf("%s[%d]: set global destructor address to 0x%lx\n", FILE__, __LINE__,
//.........这里部分代码省略.........