本文整理汇总了C++中BPatch_function类的典型用法代码示例。如果您正苦于以下问题:C++ BPatch_function类的具体用法?C++ BPatch_function怎么用?C++ BPatch_function使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BPatch_function类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: replaceFunctionCall
/*
* BPatch_addressSpace::replaceFunctionCall
*
* Replace a function call with a call to a different function. Returns true
* upon success, false upon failure.
*
* point The call site that is to be changed.
* newFunc The function that the call site will now call.
*/
bool BPatch_addressSpace::replaceFunctionCall(BPatch_point &point,
BPatch_function &newFunc)
{
char name[1024];
newFunc.getName(name, 1024);
// Can't make changes to code when mutations are not active.
if (!getMutationsActive())
return false;
assert(point.point && newFunc.lowlevel_func());
/* PatchAPI stuffs */
AddressSpace* addr_space = point.getAS();
DynModifyCallCommand* rep_call = DynModifyCallCommand::create(addr_space,
point.point->block(), newFunc.lowlevel_func(), point.point->func());
addr_space->patcher()->add(rep_call);
/* End of PatchAPI */
if (pendingInsertions == NULL) {
// Trigger it now
bool tmp;
finalizeInsertionSet(false, &tmp);
}
return true;
}
示例2: printCallingSites
static void printCallingSites (int id, int total, char *name, string sharedlibname, BPatch_Vector<BPatch_point *> *vpoints)
{
if (vpoints->size() > 0)
{
unsigned j = 0;
cout << id << " of " << total << " - Calling sites for " << name << " within " << sharedlibname << " (num = " << vpoints->size() << "):" << endl;
while (j < vpoints->size())
{
BPatch_function *called = ((*vpoints)[j])->getCalledFunction();
if (NULL != called)
{
char calledname[1024];
called->getName (calledname, 1024);
cout << j+1 << " Calling " << calledname;
BPatch_procedureLocation loc = ((*vpoints)[j])->getPointType();
if (loc == BPatch_entry)
cout << " (entry)" << endl;
else if (loc == BPatch_exit)
cout << " (exit)" << endl;
else if (loc == BPatch_subroutine)
cout << " (subroutine)" << endl;
else
cout << " (unknown point type)" << endl;
}
else
{
cout << j+1 << " Undetermined " << endl;
}
j++;
}
cout << endl;
}
}
示例3: main
int main (int argc, const char* argv[]) {
BPatch bpatch;
// argv[2] is muttee's file name, will be muttee's argv[0]
BPatch_process *proc = bpatch.processCreate(argv[2], argv + 2);
// Options to tune performance
char *s;
if ((s = getenv("SET_TRAMP_RECURSIVE")) && (strcmp(s, "true") == 0))
bpatch.setTrampRecursive(true);
if ((s = getenv("SET_SAVE_FPR")) && (strcmp(s, "false") == 0))
bpatch.setSaveFPR(false);
BPatch_object *ipa = proc->loadLibrary(argv[1]);
BPatch_image *image = proc->getImage();
std::vector<BPatch_function *> tracepoints, probes;
image->findFunction("do_stuff", tracepoints);
BPatch_function *tracepoint = tracepoints[0];
image->findFunction("tpbench_no_arg", probes);
BPatch_function *probe = probes[0];
std::vector<BPatch_snippet*> args;
BPatch_funcCallExpr call_probe(*probe, args);
proc->insertSnippet(call_probe, (tracepoint->findPoint(BPatch_exit))[0]);
proc->detach(true);
return 0;
}
示例4: prepareCatchupInstr
void instrCodeNode::prepareCatchupInstr(pdvector<instReqNode *> &nodes_for_catchup)
{
if (instrCatchuped()) return;
for (unsigned instIter = 0; instIter < V.instRequests.size(); instIter++)
{
instReqNode *curInstReq = V.instRequests[instIter];
//prepareCatchupInstr_debug(V.instRequests[instIter]);
if (pd_debug_catchup) {
char buf[2048];
BPatch_function *bpf = const_cast<BPatch_function *>(curInstReq->Point()->getFunction());
if (! bpf) {
sprintf(buf, "<bad function> in instReq");
}
else
bpf->getName(buf, 2048);
cerr << " looking at instReq [" << instIter << "], in func: "
<< buf <<endl;
}
BPatchSnippetHandle *sh = curInstReq->snippetHandle();
}
// don't mark catchup as having completed because we don't want to mark
// this until the processMetFocusNode has completed initiating catchup for
// all of the threads
}
示例5: BPatch_variableExpr
//
// findVariable
// scp - a BPatch_point that defines the scope of the current search
// name - name of the variable to find.
//
BPatch_variableExpr *BPatch_image::findVariableInScope(BPatch_point &scp,
const char *name)
{
// Get the function to search for it's local variables.
// XXX - should really use more detailed scoping info here - jkh 6/30/99
BPatch_function *func = const_cast<BPatch_function *> (scp.getFunction());
if (!func) {
pdstring msg = pdstring("point passed to findVariable lacks a function\n address point type passed?");
showErrorCallback(100, msg);
return NULL;
}
BPatch_localVar *lv = func->findLocalVar(name);
if (!lv) {
// look for it in the parameter scope now
lv = func->findLocalParam(name);
}
if (lv) {
// create a local expr with the correct frame offset or absolute
// address if that is what is needed
return new BPatch_variableExpr(proc, (void *) lv->getFrameOffset(),
lv->getRegister(), lv->getType(), lv->getStorageClass(), &scp);
}
// finally check the global scope.
// return findVariable(name);
/* If we have something else to try, don't report errors on this failure. */
bool reportErrors = true;
char mangledName[100];
func->getName( mangledName, 100 );
char * lastScoping = NULL;
if( strrchr( mangledName, ':' ) != NULL ) {
reportErrors = false;
}
BPatch_variableExpr * gsVar = findVariable( name, reportErrors );
if( gsVar == NULL ) {
/* Try finding it with the function's scope prefixed. */
if( (lastScoping = strrchr( mangledName, ':' )) != NULL ) {
* (lastScoping + sizeof(char)) = '\0';
char scopedName[200];
memmove( scopedName, mangledName, strlen( mangledName ) );
memmove( scopedName + strlen( mangledName ), name, strlen( name ) );
scopedName[ strlen( mangledName ) + strlen( name ) ] = '\0';
bperr( "Searching for scoped name '%s'\n", scopedName );
gsVar = findVariable( scopedName );
}
}
return gsVar;
}
示例6: instrumentModule
void instrumentModule(BPatch_module *module)
{
char funcname[BUFFER_STRING_LEN];
instrumentPLTSection(module);
std::vector<BPatch_function *>* functions;
functions = module->getProcedures();
for (unsigned i = 0; i < functions->size(); i++) {
BPatch_function *function = functions->at(i);
function->getName(funcname, BUFFER_STRING_LEN);
instrumentFunction(function);
}
}
示例7: ShowFunctions
static void ShowFunctions (BPatch_image *appImage)
{
BPatch_Vector<BPatch_function *> *vfunctions = appImage->getProcedures (false);
cout << PACKAGE_NAME << ": " << vfunctions->size() << " functions found in binary " << endl;
unsigned i = 0;
while (i < vfunctions->size())
{
char name[1024];
BPatch_function *f = (*vfunctions)[i];
f->getName (name, 1024);
if (VerboseLevel)
{
char mname[1024], tname[1024], modname[1024];
f->getMangledName (mname, 1024);
f->getTypedName (tname, 1024);
f->getModuleName (modname, 1024);
cout << " * " << i+1 << " of " << vfunctions->size() << ", Name: " << name << endl
<< " Mangled Name: " << mname << endl
<< " Typed Name : " << tname << endl
<< " Module name : " << modname << endl
<< " Base address: " << f->getBaseAddr() << endl
<< " Instrumentable? " << (f->isInstrumentable()?"yes":"no") << endl
<< " In shared library? " << (f->isSharedLib()?"yes":"no") << endl
<< " Number of BB: " << getBasicBlocksSize(f) << endl;
if (f->isSharedLib())
{
char sharedlibname[1024];
BPatch_module *mod = f->getModule();
mod->getFullName (sharedlibname, 1024);
cout << " Full library name: " << sharedlibname << endl;
}
cout << endl;
}
else
{
cout << name << endl;
}
i++;
}
}
示例8: mal_printf
/* Invoked for every signal handler function, adjusts the value of the saved
* fault address to its unrelocated counterpart in the CONTEXT structure,
* which contains the PC that is used when execution resumes
*/
void HybridAnalysis::signalHandlerEntryCB2(BPatch_point *point, Address excCtxtAddr)
{
mal_printf("\nAt signalHandlerEntry2(%lx , %lx)\n",
point->getAddress(), (Address)excCtxtAddr);
// calculate the offset of the fault address in the EXCEPTION_RECORD
CONTEXT *cont= (CONTEXT*)excCtxtAddr; //bogus pointer, but I won't write to it
Address pcAddr = excCtxtAddr + (Address)(&(cont->Eip)) - (Address)cont;
// set fault address to the unrelocated address of that instruction
// and save the PC address in the CONTEXT structure so the exit handler
// can read it
BPatch_function *func = point->getFunction();
func->setHandlerFaultAddrAddr((Address)pcAddr,true);
handlerFunctions[(Address)func->getBaseAddr()].faultPCaddr = pcAddr;
}
示例9: revertReplaceFunction
/*
* BPatch_addressSpace::revertReplaceFunction
*
* Undoes a replaceFunction operation
*/
bool BPatch_addressSpace::revertReplaceFunction(BPatch_function &oldFunc)
{
assert(oldFunc.lowlevel_func());
if (!getMutationsActive())
return false;
func_instance *func = oldFunc.lowlevel_func();
func->proc()->revertReplacedFunction(func);
if (pendingInsertions == NULL) {
// Trigger it now
bool tmp;
finalizeInsertionSet(false, &tmp);
}
return true;
}
示例10: replaceFunction
/*
* BPatch_addressSpace::replaceFunction
*
* Replace all calls to function OLDFUNC with calls to NEWFUNC.
* Returns true upon success, false upon failure.
*
* oldFunc The function to replace
* newFunc The replacement function
*/
bool BPatch_addressSpace::replaceFunction(BPatch_function &oldFunc,
BPatch_function &newFunc)
{
assert(oldFunc.lowlevel_func() && newFunc.lowlevel_func());
if (!getMutationsActive())
return false;
// Self replacement is a nop
// We should just test direct equivalence here...
if (oldFunc.lowlevel_func() == newFunc.lowlevel_func()) {
return true;
}
/* PatchAPI stuffs */
AddressSpace* addr_space = oldFunc.lowlevel_func()->proc();
DynReplaceFuncCommand* rep_func = DynReplaceFuncCommand::create(addr_space,
oldFunc.lowlevel_func(), newFunc.lowlevel_func());
addr_space->patcher()->add(rep_func);
/* End of PatchAPI */
if (pendingInsertions == NULL) {
// Trigger it now
bool tmp;
finalizeInsertionSet(false, &tmp);
}
return true;
}
示例11: handleModule
void handleModule(BPatch_module *mod, const char *name)
{
char funcname[BUFFER_STRING_LEN];
// get list of all functions
std::vector<BPatch_function *>* functions;
functions = mod->getProcedures();
// for each function ...
for (unsigned i = 0; i < functions->size(); i++) {
BPatch_function *function = functions->at(i);
function->getName(funcname, BUFFER_STRING_LEN);
printf(" FUNC: %s (%lx)\n", funcname, (unsigned long)function->getBaseAddr());
}
}
示例12: ShowFunctions
static void ShowFunctions (BPatch_image *appImage)
{
BPatch_Vector<BPatch_function *> *vfunctions = appImage->getProcedures (false);
cout << PACKAGE_NAME << ": " << vfunctions->size() << " functions found in binary " << endl;
unsigned i = 0;
while (i < vfunctions->size())
{
char name[1024];
BPatch_function *f = (*vfunctions)[i];
f->getName (name, 1024);
char mname[1024], tname[1024], modname[1024];
f->getMangledName (mname, 1024);
f->getTypedName (tname, 1024);
f->getModuleName (modname, 1024);
cout << " * " << i+1 << " of " << vfunctions->size() << ", Name: " << name << endl
<< " Mangled Name: " << mname << endl
<< " Typed Name : " << tname << endl
<< " Module name : " << modname << endl
<< " Base address: " << f->getBaseAddr() << endl
<< " Instrumentable? " << (f->isInstrumentable()?"yes":"no") << endl
<< " In shared library? " << (f->isSharedLib()?"yes":"no") << endl;
if (f->isSharedLib())
{
//Old Dyninst API < 9.x
//char sharedlibname[1024];
//mod->getFullName (sharedlibname, 1024);
BPatch_module *mod = f->getModule();
string sharedlibname;
sharedlibname = mod->getObject()->name();
cout << " Full library name: " << sharedlibname << endl;
}
cout << endl;
i++;
}
}
示例13: assert
/* If the context of the exception has been changed so that execution
* will resume at a new address, parse and instrument the code at that
* address; then add a springboard at that address if it is not the
* entry point of a function
*/
void HybridAnalysis::signalHandlerExitCB(BPatch_point *point, void *)
{
BPatch_function *func = point->getFunction();
std::map<Dyninst::Address, ExceptionDetails>::iterator diter =
handlerFunctions.find((Address)func->getBaseAddr());
assert(handlerFunctions.end() != diter &&
0 != diter->second.faultPCaddr);
Address pcLoc = diter->second.faultPCaddr;
mal_printf("\nAt signalHandlerExit(%lx)\n", point->getAddress());
// figure out the address the program will resume at by reading
// in the stored CONTEXT structure
Address resumePC;
assert(sizeof(Address) == proc()->getAddressWidth());
proc()->lowlevel_process()->readDataSpace(
(void*)pcLoc, sizeof(resumePC), &resumePC, true);
if (diter->second.isInterrupt) {
resumePC += 1;
}
// parse at the resumePC address, if necessary
vector<BPatch_function *> funcs;
proc()->findFunctionsByAddr((Address)resumePC,funcs);
if (funcs.empty()) {
mal_printf("Program will resume in new function at %lx\n", resumePC);
}
else {
mal_printf("Program will resume at %lx in %d existing functions, "
"will add shared function starting at %lx\n",
resumePC, funcs.size(), resumePC);
}
analyzeNewFunction(point, (Address)resumePC, true, true);
mal_printf("Exception handler exiting at %lx will resume execution at "
"%lx %s[%d]\n",
point->getAddress(), resumePC, FILE__,__LINE__);
}
示例14: Instrumentcall
void Instrumentcall (BPatch_image *appImage, BPatch_process *appProcess)
{
unsigned insertion = 0;
unsigned i = 0;
BPatch_Vector<BPatch_function *> *vfunctions = appImage->getProcedures (true);
cout << vfunctions->size() << " functions found in binary " << endl;
cout << "Parsing functions " << flush;
while (i < vfunctions->size())
{
char name[1024], sharedlibname[1024];
BPatch_function *f = (*vfunctions)[i];
(f->getModule())->getFullName (sharedlibname, 1024);
f->getName (name, 1024);
BPatch_Vector<BPatch_point *> *vpoints = f->findPoint (BPatch_subroutine);
unsigned j = 0;
while (j < vpoints->size())
{
BPatch_function *called = ((*vpoints)[j])->getCalledFunction();
if (NULL != called)
{
char calledname[1024];
called->getName (calledname, 1024);
if (strcmp (calledname, "functionB") == 0)
{
string s = "functionA";
BPatch_function *patch = getRoutine (s, appImage);
if (patch != NULL)
{
bool replaced = appProcess->replaceFunctionCall (*((*vpoints)[j]), *patch);
if (replaced)
cout << "call to functionA has been successfully replaced by a call to functionB" << endl;
else
cout << "call to functionA failed to replace a call to functionB" << endl;
insertion++;
}
}
}
j++;
}
i++;
}
cout << endl;
cout << "insertion = " << insertion << endl;
}
示例15: GenerateSymFile
static void GenerateSymFile (set<string> &ParFunc, set<string> &UserFunc, BPatch_image *appImage, BPatch_addressSpace *appProces)
{
ofstream symfile;
string symname = string(::XML_GetFinalDirectory())+string("/")+string(::XML_GetTracePrefix())+".sym";
symfile.open (symname.c_str());
if (!symfile.good())
{
cerr << "Cannot create the symbolic file" << symname << endl;
return;
}
for (set<string>::iterator iter = ParFunc.begin();
iter != ParFunc.end(); iter++)
{
BPatch_function *f = getRoutine ((*iter).c_str(), appImage);
if (f != NULL)
{
BPatch_Vector< BPatch_statement > lines;
appProces->getSourceLines ((unsigned long) f->getBaseAddr(), lines);
if (lines.size() > 0)
{
symfile << "P " << hex << f->getBaseAddr() << dec << " \"" << *iter
<< "\" \"" << lines[0].fileName() << "\" " << lines[0].lineNumber()
<< endl;
}
else
{
/* this happens if the application was not compiled with -g */
char modname[1024];
f->getModuleName (modname, 1024);
symfile << "P " << hex << f->getBaseAddr() << dec << " \"" << *iter
<< "\" \"" << modname << "\" 0" << endl;
}
}
}
for (set<string>::iterator iter = UserFunc.begin();
iter != UserFunc.end(); iter++)
{
BPatch_function *f = getRoutine ((*iter).c_str(), appImage);
if (f != NULL)
{
BPatch_Vector< BPatch_statement > lines;
appProces->getSourceLines ((unsigned long) f->getBaseAddr(), lines);
if (lines.size() > 0)
{
symfile << "U " << hex << f->getBaseAddr() << dec << " \"" << *iter
<< "\" \"" << lines[0].fileName() << "\" " << lines[0].lineNumber()
<< endl;
}
else
{
/* this happens if the application was not compiled with -g */
char modname[1024];
f->getModuleName (modname, 1024);
symfile << "U " << hex << f->getBaseAddr() << dec << " \"" << *iter
<< "\" \"" << modname << "\" 0" << endl;
}
}
}
map<string, unsigned>::iterator BB_symbols_iter = BB_symbols->begin();
map<string, unsigned>::iterator BB_symbols_end = BB_symbols->end();
while(BB_symbols_iter != BB_symbols_end){
symfile << "b " << BB_symbols_iter->second << " \"" << BB_symbols_iter->first << "\"\n";
BB_symbols_iter++;
}
symfile.close();
}