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]

[szaka@F-Secure.com: [patch] peigen.c fixes]


Any comments on this? 

Thanks.

H.J.
----
----- Forwarded message from Szabolcs Szakacsits <szaka@F-Secure.com> -----

Return-Path: <szaka@F-Secure.com>
Delivered-To: hjl@lucon.org
Date: Sun, 16 Apr 2000 08:54:32 +0200 (MEST)
From: Szabolcs Szakacsits <szaka@F-Secure.com>
To: hjl@lucon.org
Subject: [patch] peigen.c fixes
Message-ID: <Pine.LNX.4.10.10004160843170.832-200000@dfopti127>
Mime-Version: 1.0
Content-Type: text/PLAIN; charset=US-ASCII
Content-Disposition: attachment


Hi,

objdump didn't work at all (seg fault) for Win dll's/exe's for a while
[six months?]. Here are some fixes against binutils-2.9.5.0.35. I
don't think it's the best or the right one but now objdump gives
pretty much the same result on my Linux for every .dll/.exe as dumpbin
on nt.

--- peigen.c.orig	Sat Apr 15 18:33:57 2000
+++ peigen.c	Sun Apr 16 08:30:34 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,33 @@
   pe_data_type *pe = pe_data (abfd);
   struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
 
-  if (section != NULL)
-    {
-      datasize = bfd_section_size (abfd, section);
-      dataoff = 0;
+  /* look for idata, it can be  buried in some other section  */
+  bfd_vma addr, size;
 
-      if (datasize == 0)
-	return true;
+  addr = extra->DataDirectory[1].VirtualAddress + extra->ImageBase;
+  size = extra->DataDirectory[1].Size;
 
-      fprintf (file, _("\nThe import table is the .idata section\n"));
+  if (addr == 0 || size == 0)
+      return true;
+
+  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;
-
-      if (addr == 0 || size == 0)
-	return true;
-
-      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, 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);
+  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 +1087,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 +1101,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 +1140,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 +1258,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 +1277,33 @@
   pe_data_type *pe = pe_data (abfd);
   struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
 
-  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;
+  /* look for edata, it can be buried in some other section */
+  bfd_vma addr, size;
 
-      addr = extra->DataDirectory[0].VirtualAddress;
-      size = extra->DataDirectory[0].Size;
+  addr = extra->DataDirectory[0].VirtualAddress + extra->ImageBase;
+  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 +1326,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;
 
   /* 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);
@@ -1367,7 +1345,7 @@
 	   _("Name \t\t\t\t"));
   fprintf_vma (file, edt.name);
   fprintf (file,
-	   " %s\n", data + edt.name + adj);
+	   " %s\n", data + edt.name + adj - dataoff);
 
   fprintf(file,
 	  _("Ordinal Base \t\t\t%ld\n"), edt.base);
@@ -1376,11 +1354,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"));
@@ -1418,9 +1396,9 @@
   for (i = 0; i < edt.num_functions; ++i)
     {
       bfd_vma eat_member = bfd_get_32 (abfd,
-				       data + edt.eat_addr + (i * 4) + adj);
-      bfd_vma eat_actual = eat_member;
-      bfd_vma edata_start = bfd_get_section_vma (abfd, section);
+				       data + edt.eat_addr + (i * 4) + adj - dataoff);
+      bfd_vma eat_actual = extra->ImageBase + eat_member;
+      bfd_vma edata_start = bfd_get_section_vma (abfd, section) + dataoff;
       bfd_vma edata_end = edata_start + datasize;
 
       if (eat_member == 0)
@@ -1455,14 +1433,14 @@
       bfd_vma name_ptr = bfd_get_32(abfd,
 				    data +
 				    edt.npt_addr
-				    + (i*4) + adj);
+				    + (i*4) + adj - dataoff);
       
-      char *name = (char *) data + name_ptr + adj;
+      char *name = (char *) data + name_ptr + adj - dataoff;
 
       bfd_vma ord = bfd_get_16(abfd,
 				    data +
 				    edt.ot_addr
-				    + (i*2) + adj);
+				    + (i*2) + adj - dataoff);
       fprintf(file,
 	      "\t[%4ld] %s\n", (long) ord, name);
 
@@ -1740,7 +1718,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]