Improve objdump's display of PE header information.

PR 31953
This commit is contained in:
Pali Roh?r 2024-07-23 08:52:21 +01:00 committed by Nick Clifton
parent 85402ee9ed
commit 91b999864f
4 changed files with 75 additions and 30 deletions

View File

@ -492,7 +492,7 @@ _bfd_XXi_swap_aouthdr_in (bfd * abfd,
a->MinorImageVersion = H_GET_16 (abfd, src->MinorImageVersion);
a->MajorSubsystemVersion = H_GET_16 (abfd, src->MajorSubsystemVersion);
a->MinorSubsystemVersion = H_GET_16 (abfd, src->MinorSubsystemVersion);
a->Reserved1 = H_GET_32 (abfd, src->Reserved1);
a->Win32Version = H_GET_32 (abfd, src->Win32Version);
a->SizeOfImage = H_GET_32 (abfd, src->SizeOfImage);
a->SizeOfHeaders = H_GET_32 (abfd, src->SizeOfHeaders);
a->CheckSum = H_GET_32 (abfd, src->CheckSum);
@ -755,7 +755,7 @@ _bfd_XXi_swap_aouthdr_out (bfd * abfd, void * in, void * out)
aouthdr_out->MajorSubsystemVersion);
H_PUT_16 (abfd, extra->MinorSubsystemVersion,
aouthdr_out->MinorSubsystemVersion);
H_PUT_32 (abfd, extra->Reserved1, aouthdr_out->Reserved1);
H_PUT_32 (abfd, extra->Win32Version, aouthdr_out->Win32Version);
H_PUT_32 (abfd, extra->SizeOfImage, aouthdr_out->SizeOfImage);
H_PUT_32 (abfd, extra->SizeOfHeaders, aouthdr_out->SizeOfHeaders);
H_PUT_32 (abfd, extra->CheckSum, aouthdr_out->CheckSum);
@ -2849,7 +2849,7 @@ _bfd_XX_print_private_bfd_data_common (bfd * abfd, void * vfile)
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, "Win32Version\t\t%08x\n", i->Reserved1);
fprintf (file, "Win32Version\t\t%08x\n", i->Win32Version);
fprintf (file, "SizeOfImage\t\t%08x\n", i->SizeOfImage);
fprintf (file, "SizeOfHeaders\t\t%08x\n", i->SizeOfHeaders);
fprintf (file, "CheckSum\t\t%08x\n", i->CheckSum);

View File

@ -227,6 +227,17 @@ pe_filter (bfd *abfd)
return bfd_get_flavour (abfd) == bfd_target_coff_flavour;
}
/* Return string representation of the platform id
stored in upper 2 bits of Win32Version field. */
static const char *
pe_platform_id_str (unsigned int platform_id)
{
static const char *const platform_id_str_table[4] =
{ "WinNT", "WinCE", "Win32s", "Win9x" };
return platform_id_str_table[platform_id & 0x3];
}
/* Display the list of name (from TABLE) for FLAGS, using comma to
separate them. A name is displayed if FLAGS & VAL is not 0. */
@ -424,8 +435,10 @@ dump_pe_file_header (bfd * abfd,
printf (_("Magic:\t\t\t\t%x\t\t- %s\n"), data,
data == 0x020b ? "PE32+" : _("Unknown"));
printf (_("Version:\t\t\t%x\n"),
(int) bfd_h_get_16 (abfd, xhdr.standard.vstamp));
printf (_("Linker Version:\t\t\t%x\t\t- %u.%02u\n"),
(int) bfd_h_get_16 (abfd, xhdr.standard.vstamp),
(int) (bfd_h_get_16 (abfd, xhdr.standard.vstamp) & 0xff),
(int) (bfd_h_get_16 (abfd, xhdr.standard.vstamp) >> 8));
printf (_("Text Size:\t\t\t%#lx\n"),
(long) bfd_h_get_32 (abfd, xhdr.standard.tsize));
@ -448,18 +461,33 @@ dump_pe_file_header (bfd * abfd,
(long) bfd_h_get_32 (abfd, xhdr.SectionAlignment));
printf (_("File Alignment:\t\t\t%#lx\n"),
(long) bfd_h_get_32 (abfd, xhdr.FileAlignment));
printf (_("Major OS Version:\t\t%d\n"),
(int) bfd_h_get_16 (abfd, xhdr.MajorOperatingSystemVersion));
printf (_("Minor OS ersion:\t\t%d\n"),
(int) bfd_h_get_16 (abfd, xhdr.MinorOperatingSystemVersion));
printf (_("Major Image Version:\t\t%d\n"),
(int) bfd_h_get_16 (abfd, xhdr.MajorImageVersion));
printf (_("Minor Image Version:\t\t%d\n"),
printf (_("Image Version:\t\t\t%lx\t\t- %u.%02u\n"),
(long) bfd_h_get_32 (abfd, xhdr.MajorImageVersion),
(int) bfd_h_get_16 (abfd, xhdr.MajorImageVersion),
(int) bfd_h_get_16 (abfd, xhdr.MinorImageVersion));
printf (_("Major Subsystem Version:\t%d\n"),
(int) bfd_h_get_16 (abfd, xhdr.MajorSubsystemVersion));
printf (_("Minor Subsystem Version:\t%d\n"),
printf (_("Minimal Subsystem Version:\t%lx\t\t- %u.%02u\n"),
(long) bfd_h_get_32 (abfd, xhdr.MajorSubsystemVersion),
(int) bfd_h_get_16 (abfd, xhdr.MajorSubsystemVersion),
(int) bfd_h_get_16 (abfd, xhdr.MinorSubsystemVersion));
printf (_("Minimal OS Version:\t\t%lx\t\t- %u.%02u\n"),
(long) bfd_h_get_32 (abfd, xhdr.MajorOperatingSystemVersion),
(int) bfd_h_get_16 (abfd, xhdr.MajorOperatingSystemVersion),
(int) bfd_h_get_16 (abfd, xhdr.MinorOperatingSystemVersion));
printf (_("Overwrite OS Version:\t\t%lx\t\t- "),
(long) bfd_h_get_32 (abfd, xhdr.Win32Version));
if (bfd_h_get_32 (abfd, xhdr.Win32Version) == 0)
printf (_("(default)\n"));
else
printf (_("%u.%02u (build %u, platform %s)\n"),
((int) (bfd_h_get_32 (abfd, xhdr.Win32Version) & 0xff)),
((int) ((bfd_h_get_32 (abfd, xhdr.Win32Version) >> 8) & 0xff)),
((int) ((bfd_h_get_32 (abfd, xhdr.Win32Version) >> 16) & 0x3fff)),
pe_platform_id_str ((bfd_h_get_32 (abfd, xhdr.Win32Version) >> 30) & 0x3));
printf (_("Size Of Image:\t\t\t%#lx\n"),
(long) bfd_h_get_32 (abfd, xhdr.SizeOfImage));
printf (_("Size Of Headers:\t\t%#lx\n"),
@ -509,8 +537,10 @@ dump_pe_file_header (bfd * abfd,
printf (_("Magic:\t\t\t\t%x\t\t- %s\n"), data,
data == 0x010b ? "PE32" : _("Unknown"));
printf (_("Version:\t\t\t%x\n"),
(int) bfd_h_get_16 (abfd, xhdr.standard.vstamp));
printf (_("Linker Version:\t\t\t%x\t\t- %u.%02u\n"),
(int) bfd_h_get_16 (abfd, xhdr.standard.vstamp),
(int) (bfd_h_get_16 (abfd, xhdr.standard.vstamp) & 0xff),
(int) (bfd_h_get_16 (abfd, xhdr.standard.vstamp) >> 8));
printf (_("Text Size:\t\t\t%#lx\n"),
(long) bfd_h_get_32 (abfd, xhdr.standard.tsize));
@ -544,18 +574,33 @@ dump_pe_file_header (bfd * abfd,
(long) bfd_h_get_32 (abfd, xhdr.SectionAlignment));
printf (_("File Alignment:\t\t\t%#lx\n"),
(long) bfd_h_get_32 (abfd, xhdr.FileAlignment));
printf (_("Major OS Version:\t\t%d\n"),
(int) bfd_h_get_16 (abfd, xhdr.MajorOperatingSystemVersion));
printf (_("Minor OS ersion:\t\t%d\n"),
(int) bfd_h_get_16 (abfd, xhdr.MinorOperatingSystemVersion));
printf (_("Major Image Version:\t\t%d\n"),
(int) bfd_h_get_16 (abfd, xhdr.MajorImageVersion));
printf (_("Minor Image Version:\t\t%d\n"),
printf (_("Image Version:\t\t\t%lx\t\t- %u.%02u\n"),
(long) bfd_h_get_32 (abfd, xhdr.MajorImageVersion),
(int) bfd_h_get_16 (abfd, xhdr.MajorImageVersion),
(int) bfd_h_get_16 (abfd, xhdr.MinorImageVersion));
printf (_("Major Subsystem Version:\t%d\n"),
(int) bfd_h_get_16 (abfd, xhdr.MajorSubsystemVersion));
printf (_("Minor Subsystem Version:\t%d\n"),
printf (_("Minimal Subsystem Version:\t%lx\t\t- %u.%02u\n"),
(long) bfd_h_get_32 (abfd, xhdr.MajorSubsystemVersion),
(int) bfd_h_get_16 (abfd, xhdr.MajorSubsystemVersion),
(int) bfd_h_get_16 (abfd, xhdr.MinorSubsystemVersion));
printf (_("Minimal OS Version:\t\t%lx\t\t- %u.%02u\n"),
(long) bfd_h_get_32 (abfd, xhdr.MajorOperatingSystemVersion),
(int) bfd_h_get_16 (abfd, xhdr.MajorOperatingSystemVersion),
(int) bfd_h_get_16 (abfd, xhdr.MinorOperatingSystemVersion));
printf (_("Overwrite OS Version:\t\t%lx\t\t- "),
(long) bfd_h_get_32 (abfd, xhdr.Win32Version));
if (bfd_h_get_32 (abfd, xhdr.Win32Version) == 0)
printf (_("(default)\n"));
else
printf (_("%u.%02u (build %u, platform %s)\n"),
((int) (bfd_h_get_32 (abfd, xhdr.Win32Version) & 0xff)),
((int) ((bfd_h_get_32 (abfd, xhdr.Win32Version) >> 8) & 0xff)),
((int) ((bfd_h_get_32 (abfd, xhdr.Win32Version) >> 16) & 0x3fff)),
pe_platform_id_str ((bfd_h_get_32 (abfd, xhdr.Win32Version) >> 30) & 0x3));
printf (_("Size Of Image:\t\t\t%#lx\n"),
(long) bfd_h_get_32 (abfd, xhdr.SizeOfImage));
printf (_("Size Of Headers:\t\t%#lx\n"),

View File

@ -215,7 +215,7 @@ struct internal_extra_pe_aouthdr
short MinorImageVersion; /* exe or dll being created, default to 0. */
short MajorSubsystemVersion; /* Minimum subsystem version required to */
short MinorSubsystemVersion; /* run exe; default to 3.1. */
uint32_t Reserved1; /* Seems to be 0. */
uint32_t Win32Version; /* Set to 0. */
uint32_t SizeOfImage; /* Size of memory to allocate for prog. */
uint32_t SizeOfHeaders; /* Size of PE header and section table. */
uint32_t CheckSum; /* Set to 0. */

View File

@ -264,7 +264,7 @@ typedef struct
char MinorImageVersion[2];
char MajorSubsystemVersion[2];
char MinorSubsystemVersion[2];
char Reserved1[4];
char Win32Version[4];
char SizeOfImage[4];
char SizeOfHeaders[4];
char CheckSum[4];
@ -303,7 +303,7 @@ typedef struct
char MinorImageVersion[2];
char MajorSubsystemVersion[2];
char MinorSubsystemVersion[2];
char Reserved1[4];
char Win32Version[4];
char SizeOfImage[4];
char SizeOfHeaders[4];
char CheckSum[4];