void report_image_structure(IMG img, int depth){ UINT32 I1 = IMG_Id(img); string I2 = IMG_Name(img); int I3 = IMG_IsMainExecutable( img ); int I4 = IMG_IsStaticExecutable( img ); ADDRINT I5 = IMG_LoadOffset(img); ADDRINT I6 = IMG_LowAddress(img); ADDRINT I7 = IMG_HighAddress(img); ADDRINT I8 = IMG_LoadOffset(img); ADDRINT I9 = IMG_StartAddress(img); ADDRINT I10 = IMG_Entry(img); USIZE I11 = IMG_SizeMapped( img ); IMG_TYPE I12 = IMG_Type(img); char I13[128]; int k ; for ( k = 0; k< depth ; k ++ ) TraceFile << "\t" ; TraceFile << "<IMAGE-LOAD>" << " I1:" << I1 << " I2:" << I2 << " I3:" << I3 << " I4:" << I4 << " I5:" << hex<< I5 << " I6:"<< I6 << " I7:" << I7 << " I8:" << I8 << " I9:"<< I9 << " I10:"<< I10 << " I11:" << I11 ; switch ( I12 ){ case IMG_TYPE_STATIC: strcpy( I13 ,"static" ); break; case IMG_TYPE_SHARED: strcpy( I13 ,"shared" ); break; case IMG_TYPE_INVALID: strcpy( I13 ,"invalid" ); break; case IMG_TYPE_LAST: strcpy( I13 ,"last" ); break; case IMG_TYPE_SHAREDLIB: strcpy( I13 ,"shared-lib" ); break; case IMG_TYPE_RELOCATABLE: strcpy( I13 ,"relocatable" ); break; case IMG_TYPE_DYNAMIC_CODE: strcpy( I13 ,"dynamic-code" ); break; default: strcpy( I13 ,"UNKNOWN" ); break; } TraceFile << " I12:" << I12 << " I13:" << I13 << endl; for( SEC sec = IMG_SecHead(img); SEC_Valid(sec); sec = SEC_Next(sec) ){ report_section_structure( sec, depth + 1 ); } /* */ for (SYM sym = IMG_RegsymHead(img); SYM_Valid(sym); sym = SYM_Next(sym)){ report_sym_structure( sym, depth +1 ); } for ( k = 0; k< depth ; k ++ ) TraceFile << "\t" ; TraceFile << "</IMAGE-LOAD>" << endl; }
// ------------------------------------------------------------- // STool_LibraryIDByAddr // ------------------------------------------------------------- // Return ID of the library of the routine to which the instruction // at address rtnAddr belongs, or STool_INVALID_LIB, if rtnAddr does not belong to // any routine. UINT32 STool_LibraryIDByAddr(ADDRINT rtnAddr){ PIN_LockClient(); const RTN rtn = RTN_FindByAddress(rtnAddr); UINT32 libID; if( RTN_Valid(rtn) ) libID = IMG_Id(SEC_Img(RTN_Sec(rtn))); else libID = STool_INVALID_LIB; PIN_UnlockClient(); return libID; }
VOID ImageLoad (IMG img, VOID *v) { uint32_t id = IMG_Id (img); std::string iname = IMG_Name(img); if (id==1) // this is the first image, extract the path and the name of the executable { string ename, epath; MIAMIU::ExtractNameAndPath(iname, epath, ename); MIAMI::MiamiOptions *mo = MIAMI::mdriver.getProgramOptions(); mo->addExecutableName(ename); mo->addExecutablePath(epath); } // print info about the sections in this image, for debugging // comment out in production runs #if DEBUG_CFG_COUNTS DEBUG_CFG(4, cerr << "Image: " << iname << ", id " << id << hex << " load offser=0x" << IMG_LoadOffset(img) << ", low addr=0x" << IMG_LowAddress(img) << ", high addr=0x" << IMG_HighAddress(img) << ", start addr=0x" << IMG_StartAddress(img) << ", mapped size=0x" << IMG_SizeMapped(img) << dec << ", has the following sections:" << endl; for (SEC sec= IMG_SecHead(img) ; SEC_Valid(sec) ; sec = SEC_Next(sec)) { cerr << "Section " << SEC_Name(sec) << " of type " << SEC_Type(sec) << " at address 0x" << hex << SEC_Address(sec) << " of size 0x" << SEC_Size(sec) << dec << "/" << SEC_Size(sec) << " bytes:" << " valid? " << SEC_Valid(sec) << ", mapped? " << SEC_Mapped(sec) << ", executable? " << SEC_IsExecutable(sec) << ", readable? " << SEC_IsReadable(sec) << ", writable? " << SEC_IsWriteable(sec) << endl; } )
VOID ImageLoad(IMG img, VOID *v) { printf("Loading %s, Image id = %d\n", IMG_Name(img).c_str(), IMG_Id(img)); fflush(stdout); }
// Trace an image unload event static VOID TraceImageUnload(IMG img, VOID *v) { fprintf(trace, "[%2d]- %-40s %2d\n", imageCount--, IMG_Name(img).c_str(), IMG_Id(img)); PrintImageList(); }
// Trace an image load event static VOID TraceImageLoad(IMG img, VOID *v) { fprintf(trace, "[%2d]+ %-40s %2d\n", imageCount++, IMG_Name(img).c_str(), IMG_Id(img)); PrintRTNs(img); PrintImageList(); }
// Print the list of images currently loaded, with some information about each. static VOID PrintImageList() { for (IMG img= APP_ImgHead(); IMG_Valid(img); img = IMG_Next(img)) { ADDRESS_RANGE range = FindImageTextMargin(img); fprintf (trace, " L %-40s %2d [0x%llx:0x%llx] offset 0x%llx %4d RTNs\n", IMG_Name(img).c_str(), (int)IMG_Id(img), (unsigned long long)range._low, (unsigned long long)range._high, (unsigned long long)IMG_LoadOffset(img), CountImageRtns (img)); } }
VOID ImageLoad(IMG img, VOID *v) { printf("Loading %s, Image id = %d\n", IMG_Name(img).c_str(), IMG_Id(img)); //instrument_function(img, "foo", AFUNPTR(record_event0)); instrument_function(img, "foo", AFUNPTR(my_function)); }
// Print the list of images currently loaded, with some information about each. static VOID PrintImageList() { for (IMG img= APP_ImgHead(); IMG_Valid(img); img = IMG_Next(img)) { int nSecs; int nRtns; CountImageSecsAndRtns (img, &nSecs, &nRtns); fprintf (trace, " L %-40s %2d [0x%lx:0x%lx] offset 0x%lx %2d SECs %4d RTNs\n", IMG_Name(img).c_str(), IMG_Id(img), (unsigned long)IMG_LowAddress(img), (unsigned long)IMG_HighAddress(img), (unsigned long)IMG_LoadOffset(img), nSecs, nRtns); } }