]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PE dos_message
authorAlan Modra <amodra@gmail.com>
Sun, 27 Aug 2023 11:47:05 +0000 (21:17 +0930)
committerAlan Modra <amodra@gmail.com>
Sun, 27 Aug 2023 11:51:38 +0000 (21:21 +0930)
I was looking at dos_message and wondering why we have H_PUT_32
in _bfd_XXi_only_swap_filehdr_out but no H_GET_32 in pe_bfd_object_p.
On a big-endian machine this would result in scrambling the code and
strings constained in dos_message.  Rather than fix the lack of
H_GET_32 in pe_bfd_object_p, I decided it doesn't make sense to store
dos_message internally as an array of ints.

include/
* coff/internal.h (struct internal_extra_pe_filehdr): Make
dos_message a char array.
* coff/msdos.h (struct external_DOS_hdr): Flatten dos_message.
* coff/pe.h (struct external_PEI_filehdr): Likewise.
bfd/
* libcoff-in.h (struct pe_tdata): Make dos_message a char array.
* libcoff.h: Regenerate.
* peXXigen.c (_bfd_XXi_only_swap_filehdr_out): memcpy dos_message
to output.
* peicode.h (pe_mkobject): Don't memset already zeroed pe_opthdr.
Tidy allocation of tdata.pe_obj_data.  Set up dos_message from..
(default_dos_message): ..this.  New static array.

bfd/libcoff-in.h
bfd/libcoff.h
bfd/peXXigen.c
bfd/peicode.h
include/coff/internal.h
include/coff/msdos.h
include/coff/pe.h

index eacfcb3ec395f2b7b9d7d7d149ddec7e2e957a29..b70710895f15751a1c2eaec6bb6b8dbeee43fbbc 100644 (file)
@@ -147,7 +147,7 @@ typedef struct pe_tdata
   int dll;
   int has_reloc_section;
   int dont_strip_reloc;
-  int dos_message[16];
+  char dos_message[64];
   /* The timestamp to insert into the output file.
      If the timestamp is -1 then the current time is used.  */
   int timestamp;
index ad6138e6e3c12e5ab873aebe05d351cd1cb5ae02..dfe3800ee6847d8fd121f31ca5e1cabbc8083e7a 100644 (file)
@@ -151,7 +151,7 @@ typedef struct pe_tdata
   int dll;
   int has_reloc_section;
   int dont_strip_reloc;
-  int dos_message[16];
+  char dos_message[64];
   /* The timestamp to insert into the output file.
      If the timestamp is -1 then the current time is used.  */
   int timestamp;
index 324339350385e7c647b4553f6ed693cc109250fc..2f2968d48e8cb10c0204cb48ac684eda14322cca 100644 (file)
@@ -890,9 +890,8 @@ _bfd_XXi_only_swap_filehdr_out (bfd * abfd, void * in, void * out)
 
   H_PUT_32 (abfd, filehdr_in->pe.e_lfanew, filehdr_out->e_lfanew);
 
-  for (idx = 0; idx < 16; idx++)
-    H_PUT_32 (abfd, filehdr_in->pe.dos_message[idx],
-             filehdr_out->dos_message[idx]);
+  memcpy (filehdr_out->dos_message, filehdr_in->pe.dos_message,
+         sizeof (filehdr_out->dos_message));
 
   /* Also put in the NT signature.  */
   H_PUT_32 (abfd, filehdr_in->pe.nt_signature, filehdr_out->nt_signature);
index 1ff13b0313dc2a2457596590716c63709c1a4c1e..72adce1a068aa9b94ec55f41e0fa8f35741d133b 100644 (file)
@@ -258,40 +258,28 @@ coff_swap_scnhdr_in (bfd * abfd, void * ext, void * in)
 static bool
 pe_mkobject (bfd * abfd)
 {
-  pe_data_type *pe;
-  size_t amt = sizeof (pe_data_type);
-
-  abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
-
-  if (abfd->tdata.pe_obj_data == 0)
+  /* Some x86 code followed by an ascii string.  */
+  static const char default_dos_message[64] = {
+    0x0e, 0x1f, 0xba, 0x0e, 0x00, 0xb4, 0x09, 0xcd,
+    0x21, 0xb8, 0x01, 0x4c, 0xcd, 0x21, 0x54, 0x68,
+    0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
+    0x61, 0x6d, 0x20, 0x63, 0x61, 0x6e, 0x6e, 0x6f,
+    0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6e,
+    0x20, 0x69, 0x6e, 0x20, 0x44, 0x4f, 0x53, 0x20,
+    0x6d, 0x6f, 0x64, 0x65, 0x2e, 0x0d, 0x0d, 0x0a,
+    0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+
+  pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
+  abfd->tdata.pe_obj_data = pe;
+  if (pe == NULL)
     return false;
 
-  pe = pe_data (abfd);
-
   pe->coff.pe = 1;
 
   /* in_reloc_p is architecture dependent.  */
   pe->in_reloc_p = in_reloc_p;
 
-  /* Default DOS message string.  */
-  pe->dos_message[0]  = 0x0eba1f0e;
-  pe->dos_message[1]  = 0xcd09b400;
-  pe->dos_message[2]  = 0x4c01b821;
-  pe->dos_message[3]  = 0x685421cd;
-  pe->dos_message[4]  = 0x70207369;
-  pe->dos_message[5]  = 0x72676f72;
-  pe->dos_message[6]  = 0x63206d61;
-  pe->dos_message[7]  = 0x6f6e6e61;
-  pe->dos_message[8]  = 0x65622074;
-  pe->dos_message[9]  = 0x6e757220;
-  pe->dos_message[10] = 0x206e6920;
-  pe->dos_message[11] = 0x20534f44;
-  pe->dos_message[12] = 0x65646f6d;
-  pe->dos_message[13] = 0x0a0d0d2e;
-  pe->dos_message[14] = 0x24;
-  pe->dos_message[15] = 0x0;
-
-  memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);
+  memcpy (pe->dos_message, default_dos_message, sizeof (pe->dos_message));
 
   bfd_coff_long_section_names (abfd)
     = coff_backend_info (abfd)->_bfd_coff_long_section_names;
index 7a566caa0576eced82a0488561c5a6d83c702a96..f33817e778839dfc2ada802636ef17df499a831b 100644 (file)
@@ -54,7 +54,7 @@ struct internal_extra_pe_filehdr
   unsigned short e_oeminfo;    /* OEM information; e_oemid specific, 0x0 */
   unsigned short e_res2[10];   /* Reserved words, all 0x0 */
   bfd_vma  e_lfanew;           /* File address of new exe header, 0x80 */
-  unsigned int dos_message[16]; /* Text which always follows DOS header.  */
+  char dos_message[64];                /* Text which always follows DOS header.  */
   bfd_vma  nt_signature;       /* required NT signature, 0x4550 */
 };
 
index b879e45db92a8d04040db8c4465cf379fd0d844a..5f09c76cc2fe4035cb4f7eae5cc1b503bc2cce5b 100644 (file)
@@ -48,7 +48,7 @@ struct external_DOS_hdr
   char e_oeminfo[2];           /* OEM information.  */
   char e_res2[10][2];          /* Reserved words, all 0x0.  */
   char e_lfanew[4];            /* File address of new exe header, usually 0x80.  */
-  char dos_message[16][4];     /* Other stuff, always follow DOS header.  */
+  char dos_message[64];                /* Other stuff, always follow DOS header.  */
 };
 
 /* The actual DOS header only includes up to the e_ovno field.  */
index 6b26d5332184bd6f0e73fb7cfaaa66cc21cd4ccd..7e69e6f77ba3b8f7944ae9673885dc70b54a6c82 100644 (file)
@@ -218,7 +218,7 @@ struct external_PEI_filehdr
   char e_oeminfo[2];           /* OEM information; e_oemid specific, 0x0.  */
   char e_res2[10][2];          /* Reserved words, all 0x0.  */
   char e_lfanew[4];            /* File address of new exe header, usually 0x80.  */
-  char dos_message[16][4];     /* Other stuff, always follow DOS header.  */
+  char dos_message[64];                /* Other stuff, always follow DOS header.  */
 
   /* Note: additional bytes may be inserted before the signature.  Use
    the e_lfanew field to find the actual location of the NT signature.  */