我是 pintool 的新手,我想要计算BBL_NumINS < 7
带有特定尾指令(例如间接跳转或间接调用或 ret)的连续基本块的数量。所以我写了这段代码
static UINT32 consecutiveBasicBlockscount = 0;
//------------------------------------------------------------------------------------------
// This function is called before every block
VOID docount()
{
OutFile << "Inc Consecutive Basic Block Counter From " <<consecutiveBasicBlockscount<<"\tto "<<consecutiveBasicBlockscount+1<< endl;
OutFile << "----------------------------------------------------------------------------------------" <<endl;
consecutiveBasicBlockscount += 1;
}
for (BBL bbl = TRACE_BblHead(trace); BBL_Valid(bbl); bbl = BBL_Next(bbl))
{
INS insTail = BBL_InsTail(bbl);
if(INS_IsIndirectBranchOrCall(BBL_InsTail(bbl)))
{
if((!INS_IsCall(insTail) && !INS_HasFallThrough(insTail) && !INS_IsHalt(insTail) && !INS_IsRet(insTail))||(INS_IsCall(insTail) && !INS_HasFallThrough(insTail) && !INS_IsHalt(insTail) && !INS_IsRet(insTail)) || INS_IsRet(insTail))
{
if (BBL_NumIns(bbl) < 7)
{
OutFile << "*****"<< hex << BBL_Address(bbl) <<"*****"<<endl;
for(INS ins = BBL_InsHead(bbl); INS_Valid(ins); ins=INS_Next(ins))
{
OutFile << INS_Disassemble(ins) <<endl;
}
OutFile << "********************************" <<endl;
BBL_InsertCall(bbl, IPOINT_BEFORE, (AFUNPTR)docount, IARG_END);
}
}
}
}
输出文件
----------------------------------------------------------------------------------------
Inc Consecutive BasicBlock Counter From 0 to 1
----------------------------------------------------------------------------------------
*****b6709ba0*****
mov eax, 0xc9
call dword ptr gs:[0x10]
********************************
Inc Consecutive BasicBlock Counter From 1 to 2
----------------------------------------------------------------------------------------
Inc Consecutive BasicBlock Counter From 2 to 3
----------------------------------------------------------------------------------------
Inc Consecutive BasicBlock Counter From 3 to 4
----------------------------------------------------------------------------------------
*****b6709bac*****
ret
********************************
Inc Consecutive BasicBlock Counter From 4 to 5
----------------------------------------------------------------------------------------
我用 Firefox 测试了这个 pintool。为什么当 Counter 为 0、2、3 时引脚不显示基本块?