bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

PE header copyright issue


From: Joshua Hudson
Subject: PE header copyright issue
Date: Fri, 15 Dec 2023 16:15:51 -0800

I started looking into EFI64 development for reasons, and discovered
something totally unexpected. The Debian grub64 loader and shim both
start with some ancient MS-owned code, and the code is obviously the
same stupid MS owned code that MS uses in their build tools since
forever, and we can tell this because of an ancient bad bit of code
writing in it. I researched the provenance of the 16 bit code and
found what I expected; it was blindly imported by the original
development of binutils-pe32 output target by looking at the output of
the MS linker without understanding it.

I re-developed the stub 16 bit code, and prepared a patch to replace
the MS own code with my own.

I tested this by placing it after the 64 byte header lifted from
debian grub EFI, resulting in a 117 byte binary (trailing zeros were
eaten by the build pathway), and ran it in Dosbox to verify the error
message appears as expected.

Patch signed off by Joshua Hudson <joshudson@gmail.com>

$ gpg --clearsign --not-dash-escaped < binutilspe16.patch
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
NotDashEscaped: You need gpg to verify this message

diff --git a/bfd/peicode.h b/bfd/peicode.h
index e16bfc25437..3d253a45f4f 100644
--- a/bfd/peicode.h
+++ b/bfd/peicode.h
@@ -258,16 +258,13 @@ coff_swap_scnhdr_in (bfd * abfd, void * ext, void * in)
 static bool
 pe_mkobject (bfd * abfd)
 {
-  /* Some x86 code followed by an ascii string.  */
+  /* DOS error message emitter followed by message */
   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 };
+    0xba, 0x0c, 0x01, 0xb4, 0x09, 0xcd, 0x21, 0xb8,
+    0x01, 0x4c, 0xcd, 0x21, "This",
+    " program cannot ",
+    "be run in DOS mo",
+    "de.\x0d\x0a$" };

   pe_data_type *pe = bfd_zalloc (abfd, sizeof (*pe));
   abfd->tdata.pe_obj_data = pe;
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCgAdFiEEzQMuEig2Xhk0+cu7b7uWgHSsbDwFAmV8614ACgkQb7uWgHSs
bDxlPgf/WNlQsCN+lVpaq74FYgC2qGk2HTAywNHurlKWaEgguSmiMCWK/Ma9osyw
NJ3O7W09UN1YVHt35LC6THItvK+R0gmXNRUd6gmOQh98c4mYLW958ctN8X2ILhND
80OnOMGe6ERloJAOlP/WstiqGk6Isz0Wh3gvQNFkkH9VglJVSjqgIW9aj+vKoGY4
sbfuuiYae/hpKdY1G9vGAVgmAJK1uW3CJmx55rwDq7QSTde2kfzLoWaufu96QBUR
PR0YyodAoa5CSPgQPs+Wud/lQ/1qJo4IwGisyN7Zgt9uVGF41pYK+DGiSgfHZnsM
r/X/XWUeT2TeNtVSUEqUyrcDtq7lNg==
=AXHa
-----END PGP SIGNATURE-----



reply via email to

[Prev in Thread] Current Thread [Next in Thread]