This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: bfd/peigen.c problems and fix



On Thu, 4 May 2000, Alan Modra wrote:

>   Martin Kahlert pointed out that mingw32 is broken, and has been
> for quite a while.  I also managed to get some segv's from objdump -p 
> on pei files.  Since this problem seems to be in some of your code,
> would you mind looking over my fix?

Hi, I still get segmentation faults on NT dll's with your fix. A few
weeks ago I also sent a patch for peigen.c but probably it was too
broken since nobody responded. Below is an improved and cleaned up
version but I'm not a bfd expert and also don't know how MS messes up
with pei from time to time. With this patch objdump -p just works for
every [quite a lot] Win9x and NT exe's and dll's that I tried [only on
Intel].

It's also interesting why objdump gives 'File format not recognized'
for some pei files that were recognized by older versions ...

	Szaka

--- peigen.c.orig	Sat Apr 15 18:33:57 2000
+++ peigen.c	Sun May  7 21:58:27 2000
@@ -973,7 +973,7 @@
   N_ ("Load Configuration Directory"),
   N_ ("Bound Import Directory"),
   N_ ("Import Address Table Directory"),
-  N_ ("Reserved"),
+  N_ ("Delay Import Directory"),
   N_ ("Reserved"),
   N_ ("Reserved")
 };
@@ -1011,46 +1011,36 @@
   pe_data_type *pe = pe_data (abfd);
   struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
 
+  /* look for idata, it can be  buried in some other section  */
+  bfd_vma addr, size;
+
+  addr = extra->DataDirectory[1].VirtualAddress + extra->ImageBase;
   if (section != NULL)
-    {
-      datasize = bfd_section_size (abfd, section);
-      dataoff = 0;
+      size = bfd_section_size (abfd, section);
+  else 
+      size = extra->DataDirectory[1].Size;
 
-      if (datasize == 0)
-	return true;
+  if (addr == 0 || size == 0)
+      return true;
 
-      fprintf (file, _("\nThe import table is the .idata section\n"));
+  for (section = abfd->sections; section != NULL; section = section->next)
+    {
+      if (addr >= section->vma
+ 	      && addr < section->vma + bfd_section_size(abfd,section))
+          break;
     }
-  else
+  if (section == NULL)
     {
-      /* idata buried in some other section: e.g. KERNEL32.DLL.  */
-      bfd_vma addr, size;
-
-      addr = extra->DataDirectory[1].VirtualAddress;
-      size = extra->DataDirectory[1].Size;
+      fprintf (file,
+          _("\nThere is an import table, but the section containing it could not be found\n"));
+      return true;
+    }
 
-      if (addr == 0 || size == 0)
-	return true;
+  fprintf (file, _("\nThere is an import table in %s at 0x%lx\n"),
+       section->name, (unsigned long)addr);
 
-      for (section = abfd->sections; section != NULL; section = section->next)
-	{
-	   if (addr >= section->vma
-	       && addr < section->vma + bfd_section_size(abfd,section))
-	         break;
-	}
-      if (section == NULL)
-	{
-	   fprintf (file,
-		    _("\nThere is an import table, but the section containing it could not be found\n"));
-	   return true;
-	}
-
-      fprintf (file, _("\nThere is an import table in %s at 0x%lx\n"),
-	       section->name, (unsigned long)addr);
-
-      dataoff = addr - section->vma;
-      datasize = size;
-    }
+  dataoff = addr - section->vma;
+  datasize = size;
 
 #ifdef POWERPC_LE_PE
   if (rel_section != 0 && bfd_section_size (abfd, rel_section) != 0)
@@ -1100,7 +1090,7 @@
 #endif
 
   fprintf(file,
-	  _("\nThe Import Tables (interpreted .idata section contents)\n"));
+	  _("\nThe Import Tables (interpreted %s section contents)\n"), section->name);
   fprintf(file,
 	  _(" vma:            Hint    Time      Forward  DLL       First\n"));
   fprintf(file,
@@ -1114,7 +1104,7 @@
   if (! bfd_get_section_contents (abfd, section, (PTR) data, 0, secsize))
     return false;
 
-  adj = - section->vma;
+  adj = - section->vma + extra->ImageBase;
 
   for (i = 0; i < datasize; i += onaline)
     {
@@ -1153,7 +1143,7 @@
       if (hint_addr == 0 && first_thunk == 0)
 	break;
 
-      dll = (char *) data + dll_name - section->vma + dataoff;
+      dll = (char *) data + dll_name + adj;
       fprintf(file, _("\n\tDLL Name: %s\n"), dll);
 
       if (hint_addr != 0)
@@ -1271,7 +1261,7 @@
   bfd_size_type dataoff;
   bfd_size_type i;
 
-  int adj;
+  long adj;
   struct EDT_type
     {
       long export_flags;             /* reserved - should be zero */
@@ -1290,42 +1280,36 @@
   pe_data_type *pe = pe_data (abfd);
   struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
 
+  /* look for edata, it can be buried in some other section */
+  bfd_vma addr, size;
+
+  addr = extra->DataDirectory[0].VirtualAddress + extra->ImageBase;
   if (section != NULL)
-    {
       datasize = bfd_section_size (abfd, section);
-      dataoff = 0;
-      fprintf (file, _("\nThe export table is the .edata section\n"));
-    }
   else
-    {
-      /* edata is buried in some other section: e.g. NTDLL.DLL.  */
-      bfd_vma addr, size;
-
-      addr = extra->DataDirectory[0].VirtualAddress;
       size = extra->DataDirectory[0].Size;
 
-      if (addr == 0 || size == 0)
-	return true;
+  if (addr == 0 || size == 0)
+      return true;
 
-      for (section = abfd->sections; section != NULL; section = section->next)
-	{
-	   if (addr >= section->vma
+  for (section = abfd->sections; section != NULL; section = section->next)
+    {
+      if (addr >= section->vma
 	       && addr < section->vma + bfd_section_size (abfd, section))
-	     break;
-	}
-      if (section == NULL)
-	{
-	   fprintf (file,
-		    _("\nThere is an export table, but the section containing it could not be found\n"));
-	   return true;
-	}
+          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);
+  fprintf (file, _("\nThere is an export table in %s at 0x%lx\n"),
+       section->name, (unsigned long) addr);
 
-      datasize = size;
-      dataoff = addr - section->vma;
-    }
+  datasize = size;
+  dataoff = addr - section->vma;
 
   data = (bfd_byte *) bfd_malloc (datasize);
   if (data == NULL && datasize != 0)
@@ -1348,11 +1332,11 @@
   edt.npt_addr       = bfd_get_32(abfd, data+32);
   edt.ot_addr        = bfd_get_32(abfd, data+36);
 
-  adj = - (section->vma + dataoff);
+  adj = - (section->vma - extra->ImageBase + dataoff);
 
   /* Dump the EDT first first */
   fprintf(file,
-	  _("\nThe Export Tables (interpreted .edata section contents)\n\n"));
+	  _("\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);
@@ -1376,11 +1360,11 @@
 	  _("Number in:\n"));
 
   fprintf(file,
-	  _("\tExport Address Table \t\t%lx\n"),
+	  _("\tExport Address Table \t\t%08lx\n"),
 	  edt.num_functions);
 
   fprintf(file,
-	  _("\t[Name Pointer/Ordinal] Table\t%lu\n"), edt.num_names);
+	  _("\t[Name Pointer/Ordinal] Table\t%08lx\n"), edt.num_names);
 
   fprintf(file,
 	  _("Table Addresses\n"));
@@ -1740,7 +1724,7 @@
   fprintf (file,"MinorImageVersion\t%d\n", i->MinorImageVersion);
   fprintf (file,"MajorSubsystemVersion\t%d\n", i->MajorSubsystemVersion);
   fprintf (file,"MinorSubsystemVersion\t%d\n", i->MinorSubsystemVersion);
-  fprintf (file,"Reserved1\t\t%08lx\n", i->Reserved1);
+  fprintf (file,"Win32 version\t\t%08lx\n", i->Reserved1);
   fprintf (file,"SizeOfImage\t\t%08lx\n", i->SizeOfImage);
   fprintf (file,"SizeOfHeaders\t\t%08lx\n", i->SizeOfHeaders);
   fprintf (file,"CheckSum\t\t%08lx\n", i->CheckSum);



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]