From patchwork Sun Aug 27 12:02:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 74787 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0BFC73858D3C for ; Sun, 27 Aug 2023 12:03:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0BFC73858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1693137810; bh=M5YW8K7h8yevmd/kl9e82sxhL0gsYqOg4S8FIvt00tw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ClYZCvUvsm3qI7H67MmzLL9itNKeh1aIoxpO5OoyxTnNTUq7iZZONPh3KQXsZ41Cf xy5QdPlvxPLitBRf+0XCu5ZeF3A5LW2QwFjVMmYJgkse4tn4K0n/Xe69JC4LrtS+3i FOZKFdE2XB1dEFDYx34K30N6NMrCf6HL+izhLw78= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id 1E5D63858D33 for ; Sun, 27 Aug 2023 12:03:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1E5D63858D33 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1c0d0bf18d6so18940725ad.0 for ; Sun, 27 Aug 2023 05:03:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693137780; x=1693742580; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=M5YW8K7h8yevmd/kl9e82sxhL0gsYqOg4S8FIvt00tw=; b=c28qDhqOGaHlAmAeCczUvPVlqDrcGNy9un/UAGi66/R9olV0dPDjIBTdI4Zn7yV1MM 51nya952dbAE08KcTHp4DCQbp2xju7g8/QkBzg4T0KOyrDjrUPFdVNvxABuvqT19J55L 5syG9u/6Hlwj0ZmyburaNwqmCbjIF2AJ5GshR6aOjWqV/dmHF4Vx21HWB0wbtJIAcFiX 8uR26WX88KpLHTdijfzRlyJxInUAbzF9YboupS9/CIK4GKyqfW3lecvPVRTI40d0FTe4 QzkRZ29uMcqNHk0Jyy0Nu2SBuSsrT3o4C6B96gT7CiNcpYWR5H0VNhBKKScMo3EvcGsr 8Xrw== X-Gm-Message-State: AOJu0YzoZ3fqTb8EMOFv/GEu12CV5Qv3Eua6x6OE5XJOigISIibekLoz 2pvU0yTbSaDAPzag/Dc0Ja2K3UoOy5NdCQ== X-Google-Smtp-Source: AGHT+IHVtrC1z2jeu3PPjG7RJHWByA3Ahi+pYcgqNr5DtoLiIlwQ70Z2AbjX1103UEJEniY14rHz5w== X-Received: by 2002:a17:90a:420d:b0:268:1d1e:baaf with SMTP id o13-20020a17090a420d00b002681d1ebaafmr22276660pjg.17.1693137780459; Sun, 27 Aug 2023 05:03:00 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:90c2:1583:5bd8:79d5]) by smtp.gmail.com with ESMTPSA id y14-20020a17090a134e00b0025645ce761dsm6703963pjf.35.2023.08.27.05.02.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Aug 2023 05:02:59 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 482CB11423C7; Sun, 27 Aug 2023 21:32:57 +0930 (ACST) Date: Sun, 27 Aug 2023 21:32:57 +0930 To: binutils@sourceware.org Subject: PE dos_message Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3033.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org Sender: "Binutils" 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 contained 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. diff --git a/bfd/libcoff-in.h b/bfd/libcoff-in.h index eacfcb3ec39..b70710895f1 100644 --- a/bfd/libcoff-in.h +++ b/bfd/libcoff-in.h @@ -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; diff --git a/bfd/libcoff.h b/bfd/libcoff.h index ad6138e6e3c..dfe3800ee68 100644 --- a/bfd/libcoff.h +++ b/bfd/libcoff.h @@ -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; diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c index 32433935038..2f2968d48e8 100644 --- a/bfd/peXXigen.c +++ b/bfd/peXXigen.c @@ -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); diff --git a/bfd/peicode.h b/bfd/peicode.h index 1ff13b0313d..72adce1a068 100644 --- a/bfd/peicode.h +++ b/bfd/peicode.h @@ -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; diff --git a/include/coff/internal.h b/include/coff/internal.h index 7a566caa057..f33817e7788 100644 --- a/include/coff/internal.h +++ b/include/coff/internal.h @@ -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 */ }; diff --git a/include/coff/msdos.h b/include/coff/msdos.h index b879e45db92..5f09c76cc2f 100644 --- a/include/coff/msdos.h +++ b/include/coff/msdos.h @@ -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. */ diff --git a/include/coff/pe.h b/include/coff/pe.h index 6b26d533218..7e69e6f77ba 100644 --- a/include/coff/pe.h +++ b/include/coff/pe.h @@ -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. */