// // This tool prints a trace of image load and unload events // #include <stdio.h> #include <iostream> #include "pin.H" // Pin calls this function every time a new img is loaded // It can instrument the image, but this example merely // counts the number of static instructions in the image VOID ImageLoad(IMG img, VOID *v) { UINT32 count = 0; for (SEC sec = IMG_SecHead(img); SEC_Valid(sec); sec = SEC_Next(sec)) { for (RTN rtn = SEC_RtnHead(sec); RTN_Valid(rtn); rtn = RTN_Next(rtn)) { // Prepare for processing of RTN, an RTN is not broken up into BBLs, // it is merely a sequence of INSs RTN_Open(rtn); for (INS ins = RTN_InsHead(rtn); INS_Valid(ins); ins = INS_Next(ins)) { count++; } // to preserve space, release data associated with RTN after we have processed it RTN_Close(rtn); } } fprintf(stderr, "Image %s has %d instructions\n", IMG_Name(img).c_str(), count); } /* ===================================================================== */ /* Print Help Message */ /* ===================================================================== */ INT32 Usage() { cerr << "This tool prints a log of image load and unload events" << endl; cerr << " along with static instruction counts for each image." << endl; cerr << endl << KNOB_BASE::StringKnobSummary() << endl; return -1; } /* ===================================================================== */ /* Main */ /* ===================================================================== */ int main(int argc, char * argv[]) { // prepare for image instrumentation mode PIN_InitSymbols(); // Initialize pin if (PIN_Init(argc, argv)) return Usage(); // Register ImageLoad to be called when an image is loaded IMG_AddInstrumentFunction(ImageLoad, 0); // Start the program, never returns PIN_StartProgram(); return 0;
이 예시는 instrumentation없이 바이너리를 분석하는 예시인데, image안에 있는 instruction수를 세는 기능을 한다.
'pintool' 카테고리의 다른 글
Replacing a Routine in Probe Mode (0) | 2018.10.02 |
---|---|
Detaching Pin from the Application (0) | 2018.10.02 |
Using the Fast Buffering APIs (0) | 2018.09.28 |
Using TLS (0) | 2018.09.28 |
Instrumenting Threaded Applications (0) | 2018.09.28 |