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: 136983 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp2786947vqm; Sun, 27 Aug 2023 05:03:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGq7pM+xRlnnZAph1kiUd6crLNa3DYKfwxaV4umz4b8mHTs163Tj0HXFvyAg3WezHImptCm X-Received: by 2002:a2e:b164:0:b0:2bb:bfa5:b72c with SMTP id a4-20020a2eb164000000b002bbbfa5b72cmr16265509ljm.15.1693137792186; Sun, 27 Aug 2023 05:03:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693137792; cv=none; d=google.com; s=arc-20160816; b=kMCErJU3dPfosxcF/f1r6KI9XxJNP4ZZZzldbOcsTnb6M0bU4KoIJrmZl+NwH5RWoJ 3FC15kxOkTz11geKby8UMS9e4XokbgluER877j4uC5h9tH5ASkNrrUUSqOUv9njXaTi8 5gX7j1moH/5jVD45m/mYABhlv7lon0QdYrjstPxxq3ebrL2ASvR3c4uJgvCfNl0BkzlX lNxvY7tmqefJmyLAuGMuw3i0mlgoacFq6yjIfI7vxPliXfv8Ey9TQgVE/oKsalOcBBVl yXPHy72f1aaiHCrRBAhlsGRZJHX4vLA+UM+t63uPPCjEvC6mwGkGflqIkhJ4IeS9DSXT 1GKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=M5YW8K7h8yevmd/kl9e82sxhL0gsYqOg4S8FIvt00tw=; fh=NLxAvL/bDfPg4AGOtxqvQlND8vazkZrNzKLY8+LAbBY=; b=j3Ye5L1Lt1Nn0aDAmLjw2WOpXQ8co1iLwuDB6FOV8voRSm3solhrbecElrnriKAZb3 ccw1q8h5gZmF2Xz6pMfUcLmQTkDkB/tz1YkzaGOrlQ8G11Q/2Yu/8mKVA/73auOyTEHT HeZS8TMVqF+EidM8T7cpMhX1BRxPBUbOrIeywcBAZ9GMzJ+FFrIoQ/Z8KxI+Z4gCHHWh 4afq0IT2PLqHGwAFiO65c/1e3/OGJouail2PxOlZN17d1jV1vabD21idm0ieeV4i2+Bx qIIDDPsPl277x/FQkTmtMHBZJ8RnLg6NtlvUOVG5/kR9MHT8pQUgQAQ6VA3wxzC3fBXq FN+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=H2RseDmW; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qc12-20020a170906d8ac00b0099b7a166716si3189813ejb.245.2023.08.27.05.03.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Aug 2023 05:03:12 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=H2RseDmW; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D2A9A3858C41 for ; Sun, 27 Aug 2023 12:03:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D2A9A3858C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1693137790; bh=M5YW8K7h8yevmd/kl9e82sxhL0gsYqOg4S8FIvt00tw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=H2RseDmW7qhJkocyiOA5klcc/PNDZJY5KmyF96CuF8kg+U7gpBvfOgFSC8SKWBBhy HM4/vOw5T9nCyMl9k9rTssnmb6ilJ38kVVNtCf749ygIf/4FIQ1jjQtiLH6JATBMoC mXM6eyOi3p2NmhSiJ2t0r104gUze4aC8aafRE5vQ= 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-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+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775383653626412997 X-GMAIL-MSGID: 1775383653626412997 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. */