public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Re: PE header copyright issue
       [not found] <CA+jjjYR7LDUkO8-Q08V9eC9_dQsTPgPn+dD4E7eyc1VY4B9=Qg@mail.gmail.com>
@ 2023-12-17 18:14 ` Hans-Peter Nilsson
  2023-12-17 21:20   ` Joshua Hudson
  0 siblings, 1 reply; 2+ messages in thread
From: Hans-Peter Nilsson @ 2023-12-17 18:14 UTC (permalink / raw)
  To: Joshua Hudson; +Cc: bug-binutils, binutils

On Fri, 15 Dec 2023, Joshua Hudson wrote:

> 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.

Wow.

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

Good.

> 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>

<patch elided>

Could you please add the assembly source too?

Even if only as comments next to the corresponding byte-wise 
contents of default_dos_message[] would be nice.

brgds, H-P
PS. binutils@sourceware.org address is the preferred address.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: PE header copyright issue
  2023-12-17 18:14 ` PE header copyright issue Hans-Peter Nilsson
@ 2023-12-17 21:20   ` Joshua Hudson
  0 siblings, 0 replies; 2+ messages in thread
From: Joshua Hudson @ 2023-12-17 21:20 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: bug-binutils, binutils

Hans-Peter Nilsson <hp@bitrange.com> wrote:
> Could you please add the assembly source too?
>
> Even if only as comments next to the corresponding byte-wise
> contents of default_dos_message[] would be nice.

Done.

I thought about it, and a block comment right next to the hex blob is
indeed the right way.
You're not setting up a build environment for it unless you want to
take additional build dependencies.

I'm going to be out for two weeks and not able to make any further code changes.

joshua@nova:/tmp$ 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,19 @@ 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 };
     /* mov dx, message
        mov ah, 9 ; Out string
        int 21h
        mov ax, 4c01h ; exit process, code 1
        int 21h
message: */
+    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+cu7b7uWgHSsbDwFAmV/Y/8ACgkQb7uWgHSs
bDyq/wf/UpGm5rEuLhiITeILpRigytZCHyYP5njqgB9Q9x9JTyFGOOOfYJFcVjEc
OKzGZjlvsxVyuzQO6+b14PtXvDfCofJFjUnVm6ucCH8mhVMTuyZttZ+fFRRTx3GS
9cRzX2LyZQU/c9RWDpc7Diy+MlQvGGLIC8DtV+oR/nCtaN3zvMptWalCXHipSfVG
J6QFURQ2uJ3MtbgrQZ2t41nKkoCH04GDd01vn725KYqKIMGoYr91fEdmrHNy/rpb
oo6dX7HqXTUr5/lowkuHHFnKJW0m8wjfdxYy5rQTebnG7gWU7OtCI/+bVEKwLa9F
VLyzCdoB0NDAZzHH+n5b0NqPwspyxA==
=AFq0
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-12-17 21:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CA+jjjYR7LDUkO8-Q08V9eC9_dQsTPgPn+dD4E7eyc1VY4B9=Qg@mail.gmail.com>
2023-12-17 18:14 ` PE header copyright issue Hans-Peter Nilsson
2023-12-17 21:20   ` Joshua Hudson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).