示例#1
0
void img_load (IMG img, void *v)
{
	struct event_imload *imevent;
	char buffer[512];
	size_t length;

/*	fprintf(logfp, "load %s off=%08x low=%08x high=%08x start=%08x size=%08x\n",
			IMG_Name(img).c_str(),
			IMG_LoadOffset(img), IMG_LowAddress(img), IMG_HighAddress(img),
			IMG_StartAddress(img), IMG_SizeMapped(img));*/

	imevent = (struct event_imload *)buffer;
	length = IMG_Name(img).length();
	if (length > sizeof(buffer) - sizeof(struct event_imload))
		length = sizeof(buffer) - sizeof(struct event_imload);
	imevent->comm.type = ET_IMLOAD;
	imevent->comm.tid = PIN_ThreadId();
	imevent->struct_size = (int)((char *)imevent->name - (char *)imevent) + length + 1;
	imevent->addr = IMG_LowAddress(img);
	imevent->size = IMG_HighAddress(img) - IMG_LowAddress(img);
	imevent->entry = IMG_Entry(img);
	imevent->ismain = IMG_IsMainExecutable(img);
	memcpy(imevent->name, IMG_Name(img).c_str(), length);
	imevent->name[length] = '\0';
	tb_write((event_common *)imevent, (size_t)imevent->struct_size);

	osdep_iterate_symbols(img, process_symbol, (void *)&img);
	tb_flush(PIN_ThreadId());

	fprintf(logfp, "img+ %08x+%08x %s\n", IMG_StartAddress(img), IMG_SizeMapped(img), IMG_Name(img).c_str());
}
示例#2
0
void img_unload (IMG img, void *v)
{
	char buff[256];
	struct event_imunload *event = (struct event_imunload *)buff;
	int name_len;

	event->comm.type = ET_IMUNLOAD;
	event->comm.tid = PIN_ThreadId();
	event->addr = IMG_StartAddress(img);
	event->size = IMG_SizeMapped(img);
	name_len = IMG_Name(img).length();
	if (name_len > 240)
		name_len = 240;
	event->struct_size = (int)((char *)event->name - (char *)event) + name_len + 1;
	strncpy(event->name, IMG_Name(img).c_str(), name_len);
	event->name[name_len] = '\0';
	tb_write((event_common *)event, (size_t)event->struct_size);

	fprintf(logfp, "img- %08x+%08x %s\n", IMG_StartAddress(img), IMG_SizeMapped(img), IMG_Name(img).c_str());
}
示例#3
0
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;
}
void
ImageSymbolLoader::Instrument
(
    IMG img
)
{
    string  ImageName       = IMG_Name(img);
    string  ImageNameExt    = Basename(ImageName);
    ADDRINT Base            = IMG_StartAddress(img);
    MemRange Module(Base, IMG_SizeMapped(img));

    Symbol::RefreshSymbolByIMG(img);

    cerr << "[pintool] Module " << MemRangeToString(Module) << " "
         << ImageNameExt << " "
         << Symbol::SymbolInfoForModuleAtAddress(Base)
         << endl;
}
示例#5
0
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 PvxHandleModuleLoad(IMG img)
{
	MemoryAddModuleLoadRegion(IMG_StartAddress(img), IMG_SizeMapped(img));
}