pexxigen.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,044 行 · 第 1/5 页

C
2,044
字号
      if (hint_addr == 0 && first_thunk == 0)	break;      dll = (char *) data + dll_name - adj;      fprintf (file, _("\n\tDLL Name: %s\n"), dll);      if (hint_addr != 0)	{	  fprintf (file, _("\tvma:  Hint/Ord Member-Name\n"));	  idx = hint_addr - adj;	  for (j = 0; j < datasize; j += 4)	    {	      unsigned long member = bfd_get_32 (abfd, data + idx + j);	      if (member == 0)		break;	      if (member & 0x80000000)		fprintf (file, "\t%04lx\t %4lu", member,			 member & 0x7fffffff);	      else		{		  int ordinal;		  char *member_name;		  ordinal = bfd_get_16 (abfd, data + member - adj);		  member_name = (char *) data + member - adj + 2;		  fprintf (file, "\t%04lx\t %4d  %s",			   member, ordinal, member_name);		}	      /* If the time stamp is not zero, the import address                 table holds actual addresses.  */	      if (time_stamp != 0		  && first_thunk != 0		  && first_thunk != hint_addr)		fprintf (file, "\t%04lx",			 (long) bfd_get_32 (abfd, data + first_thunk - adj + j));	      fprintf (file, "\n");	    }	}      if (hint_addr != first_thunk && time_stamp == 0)	{	  int differ = 0;	  int idx2;	  idx2 = first_thunk - adj;	  for (j = 0; j < datasize; j += 4)	    {	      int ordinal;	      char *member_name;	      bfd_vma hint_member = 0;	      bfd_vma iat_member;	      if (hint_addr != 0)		hint_member = bfd_get_32 (abfd, data + idx + j);	      iat_member = bfd_get_32 (abfd, data + idx2 + j);	      if (hint_addr == 0 && iat_member == 0)		break;	      if (hint_addr == 0 || hint_member != iat_member)		{		  if (differ == 0)		    {		      fprintf (file,			       _("\tThe Import Address Table (difference found)\n"));		      fprintf (file, _("\tvma:  Hint/Ord Member-Name\n"));		      differ = 1;		    }		  if (iat_member == 0)		    {		      fprintf (file,			      _("\t>>> Ran out of IAT members!\n"));		    }		  else		    {		      ordinal = bfd_get_16 (abfd, data + iat_member - adj);		      member_name = (char *) data + iat_member - adj + 2;		      fprintf (file, "\t%04lx\t %4d  %s\n",			      (unsigned long) iat_member,			      ordinal,			      member_name);		    }		}	      if (hint_addr != 0 && hint_member == 0)		break;	    }	  if (differ == 0)	    {	      fprintf (file,		      _("\tThe Import Address Table is identical\n"));	    }	}      fprintf (file, "\n");    }  free (data);  return true;}static booleanpe_print_edata (abfd, vfile)     bfd *abfd;     PTR vfile;{  FILE *file = (FILE *) vfile;  bfd_byte *data;  asection *section;  bfd_size_type datasize = 0;  bfd_size_type dataoff;  bfd_size_type i;  bfd_signed_vma adj;  struct EDT_type {    long export_flags;             /* reserved - should be zero */    long time_stamp;    short major_ver;    short minor_ver;    bfd_vma name;                  /* rva - relative to image base */    long base;                     /* ordinal base */    unsigned long num_functions;   /* Number in the export address table */    unsigned long num_names;       /* Number in the name pointer table */    bfd_vma eat_addr;    /* rva to the export address table */    bfd_vma npt_addr;        /* rva to the Export Name Pointer Table */    bfd_vma ot_addr; /* rva to the Ordinal Table */  } edt;  pe_data_type *pe = pe_data (abfd);  struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;  bfd_vma addr;  addr = extra->DataDirectory[0].VirtualAddress;  if (addr == 0 && extra->DataDirectory[0].Size == 0)    {      /* Maybe the extra header isn't there.  Look for the section.  */      section = bfd_get_section_by_name (abfd, ".edata");      if (section == NULL)	return true;      addr = section->vma;      datasize = bfd_section_size (abfd, section);      if (datasize == 0)	return true;    }  else    {      addr += extra->ImageBase;      for (section = abfd->sections; section != NULL; section = section->next)	{	  datasize = bfd_section_size (abfd, section);	  if (addr >= section->vma && addr < section->vma + datasize)	    break;	}      if (section == NULL)	{	  fprintf (file,		   _("\nThere is an export table, but the section containing it could not be found\n"));	  return true;	}    }  fprintf (file, _("\nThere is an export table in %s at 0x%lx\n"),	   section->name, (unsigned long) addr);  dataoff = addr - section->vma;  datasize -= dataoff;  data = (bfd_byte *) bfd_malloc (datasize);  if (data == NULL)    return false;  if (! bfd_get_section_contents (abfd, section, (PTR) data, dataoff,				  datasize))    return false;  /* Go get Export Directory Table.  */  edt.export_flags   = bfd_get_32 (abfd, data +  0);  edt.time_stamp     = bfd_get_32 (abfd, data +  4);  edt.major_ver      = bfd_get_16 (abfd, data +  8);  edt.minor_ver      = bfd_get_16 (abfd, data + 10);  edt.name           = bfd_get_32 (abfd, data + 12);  edt.base           = bfd_get_32 (abfd, data + 16);  edt.num_functions  = bfd_get_32 (abfd, data + 20);  edt.num_names      = bfd_get_32 (abfd, data + 24);  edt.eat_addr       = bfd_get_32 (abfd, data + 28);  edt.npt_addr       = bfd_get_32 (abfd, data + 32);  edt.ot_addr        = bfd_get_32 (abfd, data + 36);  adj = section->vma - extra->ImageBase + dataoff;  /* Dump the EDT first first */  fprintf (file,	   _("\nThe Export Tables (interpreted %s section contents)\n\n"),	   section->name);  fprintf (file,	   _("Export Flags \t\t\t%lx\n"), (unsigned long) edt.export_flags);  fprintf (file,	   _("Time/Date stamp \t\t%lx\n"), (unsigned long) edt.time_stamp);  fprintf (file,	   _("Major/Minor \t\t\t%d/%d\n"), edt.major_ver, edt.minor_ver);  fprintf (file,	   _("Name \t\t\t\t"));  fprintf_vma (file, edt.name);  fprintf (file,	   " %s\n", data + edt.name - adj);  fprintf (file,	   _("Ordinal Base \t\t\t%ld\n"), edt.base);  fprintf (file,	   _("Number in:\n"));  fprintf (file,	   _("\tExport Address Table \t\t%08lx\n"),	   edt.num_functions);  fprintf (file,	   _("\t[Name Pointer/Ordinal] Table\t%08lx\n"), edt.num_names);  fprintf (file,	   _("Table Addresses\n"));  fprintf (file,	   _("\tExport Address Table \t\t"));  fprintf_vma (file, edt.eat_addr);  fprintf (file, "\n");  fprintf (file,	   _("\tName Pointer Table \t\t"));  fprintf_vma (file, edt.npt_addr);  fprintf (file, "\n");  fprintf (file,	   _("\tOrdinal Table \t\t\t"));  fprintf_vma (file, edt.ot_addr);  fprintf (file, "\n");  /* The next table to find is the Export Address Table. It's basically     a list of pointers that either locate a function in this dll, or     forward the call to another dll. Something like:      typedef union {        long export_rva;        long forwarder_rva;      } export_address_table_entry;  */  fprintf (file,	  _("\nExport Address Table -- Ordinal Base %ld\n"),	  edt.base);  for (i = 0; i < edt.num_functions; ++i)    {      bfd_vma eat_member = bfd_get_32 (abfd,				       data + edt.eat_addr + (i * 4) - adj);      if (eat_member == 0)	continue;      if (eat_member - adj <= datasize)	{	  /* This rva is to a name (forwarding function) in our section.  */	  /* Should locate a function descriptor.  */	  fprintf (file,		   "\t[%4ld] +base[%4ld] %04lx %s -- %s\n",		   (long) i,		   (long) (i + edt.base),		   (unsigned long) eat_member,		   _("Forwarder RVA"),		   data + eat_member - adj);	}      else	{	  /* Should locate a function descriptor in the reldata section.  */	  fprintf (file,		   "\t[%4ld] +base[%4ld] %04lx %s\n",		   (long) i,		   (long) (i + edt.base),		   (unsigned long) eat_member,		   _("Export RVA"));	}    }  /* The Export Name Pointer Table is paired with the Export Ordinal Table.  */  /* Dump them in parallel for clarity.  */  fprintf (file,	   _("\n[Ordinal/Name Pointer] Table\n"));  for (i = 0; i < edt.num_names; ++i)    {      bfd_vma name_ptr = bfd_get_32 (abfd,				    data +				    edt.npt_addr				    + (i*4) - adj);      char *name = (char *) data + name_ptr - adj;      bfd_vma ord = bfd_get_16 (abfd,				    data +				    edt.ot_addr				    + (i*2) - adj);      fprintf (file,	      "\t[%4ld] %s\n", (long) ord, name);    }  free (data);  return true;}/* This really is architecture dependent.  On IA-64, a .pdata entry   consists of three dwords containing relative virtual addresses that   specify the start and end address of the code range the entry   covers and the address of the corresponding unwind info data.  */static booleanpe_print_pdata (abfd, vfile)     bfd *abfd;     PTR vfile;{#ifdef COFF_WITH_pep# define PDATA_ROW_SIZE	(3*8)#else# define PDATA_ROW_SIZE	(5*4)#endif  FILE *file = (FILE *) vfile;  bfd_byte *data = 0;  asection *section = bfd_get_section_by_name (abfd, ".pdata");  bfd_size_type datasize = 0;  bfd_size_type i;  bfd_size_type start, stop;  int onaline = PDATA_ROW_SIZE;  if (section == NULL      || coff_section_data (abfd, section) == NULL      || pei_section_data (abfd, section) == NULL)    return true;  stop = pei_section_data (abfd, section)->virt_size;  if ((stop % onaline) != 0)    fprintf (file,	     _("Warning, .pdata section size (%ld) is not a multiple of %d\n"),	     (long) stop, onaline);  fprintf (file,	   _("\nThe Function Table (interpreted .pdata section contents)\n"));#ifdef COFF_WITH_pep  fprintf (file,	   _(" vma:\t\t\tBegin Address    End Address      Unwind Info\n"));#else  fprintf (file,	   _(" vma:\t\tBegin    End      EH       EH       PrologEnd  Exception\n"));  fprintf (file,	   _("     \t\tAddress  Address  Handler  Data     Address    Mask\n"));#endif  if (bfd_section_size (abfd, section) == 0)    return true;  data = (bfd_byte *) bfd_malloc ((size_t) bfd_section_size (abfd, section));  datasize = bfd_section_size (abfd, section);  if (data == NULL && datasize != 0)    return false;  bfd_get_section_contents (abfd,			    section,			    (PTR) data, 0,			    bfd_section_size (abfd, section));  start = 0;  for (i = start; i < stop; i += onaline)    {      bfd_vma begin_addr;      bfd_vma end_addr;      bfd_vma eh_handler;      bfd_vma eh_data;      bfd_vma prolog_end_addr;      int em_data;      if (i + PDATA_ROW_SIZE > stop)	break;      begin_addr      = GET_PDATA_ENTRY (abfd, data + i     );      end_addr        = GET_PDATA_ENTRY (abfd, data + i +  4);      eh_handler      = GET_PDATA_ENTRY (abfd, data + i +  8);      eh_data         = GET_PDATA_ENTRY (abfd, data + i + 12);      prolog_end_addr = GET_PDATA_ENTRY (abfd, data + i + 16);      if (begin_addr == 0 && end_addr == 0 && eh_handler == 0	  && eh_data == 0 && prolog_end_addr == 0)	{	  /* We are probably into the padding of the section now.  */	  break;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?