This is the mail archive of the binutils@sourceware.org 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]
Other format: [Raw text]

Re: PATCH: Dump additonal info for PE-COFF


On Mon, Mar 19, 2007 at 06:44:26PM -0400, Christopher Faylor wrote:
> On Mon, Mar 19, 2007 at 01:50:35PM -0700, H. J. Lu wrote:
> >Some of PE-COFF info aren't displayed by "objdump -p". This patch adds
> >them.
> 
> I think I can approve this.  Please do apply it.  I'd like to see that
> added info as I often have to resort to other tools to see it.
> 

This is the patch I checked in.

Thanks.


H.J.
---
bfd/

2003-03-19  H.J. Lu  <hongjiu.lu@intel.com>

	* peXXigen.c (_bfd_XXi_swap_aouthdr_in): Store Magic,
	MajorLinkerVersion, MinorLinkerVersion, SizeOfCode,
	SizeOfInitializedData, SizeOfUninitializedData,
	AddressOfEntryPoint, BaseOfCode and BaseOfData in internal
	extra PE a.out header.
	(IMAGE_NT_OPTIONAL_HDR_MAGIC): Defined as 0x10b if not defined.
	(IMAGE_NT_OPTIONAL_HDR64_MAGIC): Defined as 0x20b if not
	defined.
	(IMAGE_NT_OPTIONAL_HDRROM_MAGIC): Defined as 0x107 if not
	defined.
	(_bfd_XX_print_private_bfd_data_common): Also print Magic,
	MajorLinkerVersion, MinorLinkerVersion, SizeOfCode,
	SizeOfInitializedData, SizeOfUninitializedData,
	AddressOfEntryPoint, BaseOfCode and BaseOfData from internal
	extra PE a.out header.

include/coff/

2003-03-19  H.J. Lu  <hongjiu.lu@intel.com>

	* internal.h (internal_extra_pe_aouthdr): Add Magic,
	MajorLinkerVersion, MinorLinkerVersion, SizeOfCode,
	SizeOfInitializedData, SizeOfUninitializedData,
	AddressOfEntryPoint, BaseOfCode and BaseOfData.

--- binutils/bfd/peXXigen.c.peinfo	2007-03-18 15:00:28.000000000 -0700
+++ binutils/bfd/peXXigen.c	2007-03-19 15:22:17.000000000 -0700
@@ -388,10 +388,11 @@ _bfd_XXi_swap_aouthdr_in (bfd * abfd,
 			  void * aouthdr_ext1,
 			  void * aouthdr_int1)
 {
-  struct internal_extra_pe_aouthdr *a;
-  PEAOUTHDR * src = (PEAOUTHDR *) (aouthdr_ext1);
+  PEAOUTHDR * src = (PEAOUTHDR *) aouthdr_ext1;
   AOUTHDR * aouthdr_ext = (AOUTHDR *) aouthdr_ext1;
-  struct internal_aouthdr *aouthdr_int = (struct internal_aouthdr *)aouthdr_int1;
+  struct internal_aouthdr *aouthdr_int
+    = (struct internal_aouthdr *) aouthdr_int1;
+  struct internal_extra_pe_aouthdr *a = &aouthdr_int->pe;
 
   aouthdr_int->magic = H_GET_16 (abfd, aouthdr_ext->magic);
   aouthdr_int->vstamp = H_GET_16 (abfd, aouthdr_ext->vstamp);
@@ -405,9 +406,17 @@ _bfd_XXi_swap_aouthdr_in (bfd * abfd,
   /* PE32+ does not have data_start/BaseOfData member!  */
   aouthdr_int->data_start =
     GET_AOUTHDR_DATA_START (abfd, aouthdr_ext->data_start);
+  a->BaseOfData = aouthdr_int->data_start;
 #endif
 
-  a = &aouthdr_int->pe;
+  a->Magic = aouthdr_int->magic;
+  a->MajorLinkerVersion = H_GET_8 (abfd, aouthdr_ext->vstamp);
+  a->MinorLinkerVersion = H_GET_8 (abfd, aouthdr_ext->vstamp + 1);
+  a->SizeOfCode = aouthdr_int->tsize ;
+  a->SizeOfInitializedData = aouthdr_int->dsize ;
+  a->SizeOfUninitializedData = aouthdr_int->bsize ;
+  a->AddressOfEntryPoint = aouthdr_int->entry;
+  a->BaseOfCode = aouthdr_int->text_start;
   a->ImageBase = GET_OPTHDR_IMAGE_BASE (abfd, src->ImageBase);
   a->SectionAlignment = H_GET_32 (abfd, src->SectionAlignment);
   a->FileAlignment = H_GET_32 (abfd, src->FileAlignment);
@@ -1808,6 +1817,7 @@ _bfd_XX_print_private_bfd_data_common (b
   pe_data_type *pe = pe_data (abfd);
   struct internal_extra_pe_aouthdr *i = &pe->pe_opthdr;
   const char *subsystem_name = NULL;
+  const char *name;
 
   /* The MS dumpbin program reportedly ands with 0xff0f before
      printing the characteristics field.  Not sure why.  No reason to
@@ -1833,6 +1843,52 @@ _bfd_XX_print_private_bfd_data_common (b
     time_t t = pe->coff.timestamp;
     fprintf (file, "\nTime/Date\t\t%s", ctime (&t));
   }
+
+#ifndef IMAGE_NT_OPTIONAL_HDR_MAGIC
+# define IMAGE_NT_OPTIONAL_HDR_MAGIC 0x10b
+#endif
+#ifndef IMAGE_NT_OPTIONAL_HDR64_MAGIC
+# define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
+#endif
+#ifndef IMAGE_NT_OPTIONAL_HDRROM_MAGIC
+# define IMAGE_NT_OPTIONAL_HDRROM_MAGIC 0x107
+#endif
+
+  switch (i->Magic)
+    {
+    case IMAGE_NT_OPTIONAL_HDR_MAGIC:
+      name = "PE32";
+      break;
+    case IMAGE_NT_OPTIONAL_HDR64_MAGIC:
+      name = "PE32+";
+      break;
+    case IMAGE_NT_OPTIONAL_HDRROM_MAGIC:
+      name = "ROM";
+      break;
+    default:
+      name = NULL;
+      break;
+    }
+  fprintf (file, "Magic\t\t\t%04x", i->Magic);
+  if (name)
+    fprintf (file, "\t(%s)",name);
+  fprintf (file, "\nMajorLinkerVersion\t%d\n", i->MajorLinkerVersion);
+  fprintf (file, "MinorLinkerVersion\t%d\n", i->MinorLinkerVersion);
+  fprintf (file, "SizeOfCode\t\t%08lx\n", i->SizeOfCode);
+  fprintf (file, "SizeOfInitializedData\t%08lx\n",
+	   i->SizeOfInitializedData);
+  fprintf (file, "SizeOfUninitializedData\t%08lx\n",
+	   i->SizeOfUninitializedData);
+  fprintf (file, "AddressOfEntryPoint\t");
+  fprintf_vma (file, i->AddressOfEntryPoint);
+  fprintf (file, "\nBaseOfCode\t\t");
+  fprintf_vma (file, i->BaseOfCode);
+#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64)
+  /* PE32+ does not have BaseOfData member!  */
+  fprintf (file, "\nBaseOfData\t\t");
+  fprintf_vma (file, i->BaseOfData);
+#endif
+
   fprintf (file, "\nImageBase\t\t");
   fprintf_vma (file, i->ImageBase);
   fprintf (file, "\nSectionAlignment\t");
--- binutils/include/coff/internal.h.peinfo	2006-12-05 11:27:59.000000000 -0800
+++ binutils/include/coff/internal.h	2007-03-19 12:41:20.000000000 -0700
@@ -138,6 +138,28 @@ typedef struct _IMAGE_DATA_DIRECTORY 
 
 struct internal_extra_pe_aouthdr 
 {
+  /* FIXME: The following entries are in AOUTHDR.  But they aren't
+     available internally in bfd.  We add them here so that objdump
+     can dump them.  */
+  /* The state of the image file  */
+  short Magic;
+  /* Linker major version number */
+  char MajorLinkerVersion;
+  /* Linker minor version number  */
+  char MinorLinkerVersion;	
+  /* Total size of all code sections  */
+  long SizeOfCode;
+  /* Total size of all initialized data sections  */
+  long SizeOfInitializedData;
+  /* Total size of all uninitialized data sections  */
+  long SizeOfUninitializedData;
+  /* Address of entry point relative to image base.  */
+  bfd_vma AddressOfEntryPoint;
+  /* Address of the first code section relative to image base.  */
+  bfd_vma BaseOfCode;
+  /* Address of the first data section relative to image base.  */
+  bfd_vma BaseOfData;
+ 
   /* PE stuff  */
   bfd_vma ImageBase;		/* address of specific location in memory that
 				   file is located, NT default 0x10000 */


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