静态全局变量(在文件范围内)应该可以工作:
static UINT32 foo = 0;
否则,您可以使用INS_AddInstrumentFunction的第二个参数:
int main(int argc, char * argv[])
{
// Initialize pin
if (PIN_Init(argc, argv)) return Usage();
UINT32 foo = 0;
// Register Instruction to be called to instrument instructions
INS_AddInstrumentFunction(Instruction, &foo);
// Register Fini to be called when the application exits
PIN_AddFiniFunction(Fini, 0);
// Start the program, never returns
PIN_StartProgram();
return 0;
}
在您的仪器功能中,还有一些东西:
// Pin calls this function every time a new instruction is encountered
VOID Instruction(INS ins, VOID *v)
{
if(v == NULL)
return;
UINT32 myfoo = *((UINT32*)v); //in c++: myFoo = *reinterptet_cast<UINT32*>(v)
// Insert a call to doSomething before every instruction, no arguments are passed
INS_InsertCall(ins, IPOINT_BEFORE, (AFUNPTR)doSomething, IARG_END);
}