aboutsummaryrefslogtreecommitdiff
path: root/include/coff
diff options
context:
space:
mode:
authorZebediah Figura <z.figura12@gmail.com>2018-02-12 13:12:45 +0000
committerNick Clifton <nickc@redhat.com>2018-02-12 13:15:56 +0000
commit830db0485e19000985ccfdbacda4d4d5d62583bb (patch)
treedada7466cb61a68114ec1819770b9e58fe86000d /include/coff
parent7e784da5439adaffebd2041c4abbb8a9c1e396dd (diff)
downloadbinutils-830db0485e19000985ccfdbacda4d4d5d62583bb.zip
binutils-830db0485e19000985ccfdbacda4d4d5d62583bb.tar.gz
binutils-830db0485e19000985ccfdbacda4d4d5d62583bb.tar.bz2
Add support for reading msdos MZ executables.
See email thread starting here: https://www.sourceware.org/ml/binutils/2018-01/msg00001.html include * coff/msdos.h: New header. * coff/pe.h: Move common defines to msdos.h. * coff/powerpc.h: Likewise. bfd * i386msdos.c (msdos_mkobject); New function. (msdos_object_p): New function. (i386_msdos_vec): Use msdos_object_p as the check_format function. * peicode.h: Rename external_PEI_DOS_hdr, DOSMAGIC, and NT_SIGNATURE to external_DOS_hdr, IMAGE_DOS_SIGNATURE, and IMAGE_NT_SIGNATURE. * peXXigen.c: Likewise. * coff-ia64.c: Likewise.
Diffstat (limited to 'include/coff')
-rw-r--r--include/coff/msdos.h57
-rw-r--r--include/coff/pe.h31
-rw-r--r--include/coff/powerpc.h2
3 files changed, 59 insertions, 31 deletions
diff --git a/include/coff/msdos.h b/include/coff/msdos.h
new file mode 100644
index 0000000..cebd957
--- /dev/null
+++ b/include/coff/msdos.h
@@ -0,0 +1,57 @@
+/* msdos.h - MS-DOS and derived executable header information
+
+ Copyright (C) 1999-2018 Free Software Foundation, Inc.
+
+ This file is part of BFD, the Binary File Descriptor library.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
+#ifndef _MSDOS_H
+#define _MSDOS_H
+
+#define IMAGE_DOS_SIGNATURE 0x5a4d /* MZ */
+#define IMAGE_OS2_SIGNATURE 0x454e /* NE */
+#define IMAGE_OS2_SIGNATURE_LE 0x454c /* LE */
+#define IMAGE_OS2_SIGNATURE_LX 0x584c /* LX */
+#define IMAGE_NT_SIGNATURE 0x00004550 /* PE\0\0 */
+
+struct external_DOS_hdr
+{
+ /* DOS header fields - always at offset zero in the EXE file. */
+ char e_magic[2]; /* Magic number. */
+ char e_cblp[2]; /* Bytes on last page of file. */
+ char e_cp[2]; /* Pages in file. */
+ char e_crlc[2]; /* Relocations. */
+ char e_cparhdr[2]; /* Size of header in paragraphs. */
+ char e_minalloc[2]; /* Minimum extra paragraphs needed. */
+ char e_maxalloc[2]; /* Maximum extra paragraphs needed. */
+ char e_ss[2]; /* Initial (relative) SS value. */
+ char e_sp[2]; /* Initial SP value. */
+ char e_csum[2]; /* Checksum. */
+ char e_ip[2]; /* Initial IP value. */
+ char e_cs[2]; /* Initial (relative) CS value. */
+ char e_lfarlc[2]; /* File address of relocation table. */
+ char e_ovno[2]; /* Overlay number. */
+ char e_res[4][2]; /* Reserved words, all 0x0. */
+ char e_oemid[2]; /* OEM identifier. */
+ 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. */
+};
+
+/* The actual DOS header only includes up to the e_ovno field. */
+#define DOS_HDR_SIZE (offsetof (struct external_DOS_hdr, e_res))
+
+#endif /* _MSDOS_H */
diff --git a/include/coff/pe.h b/include/coff/pe.h
index f9035bf..56cc4e2 100644
--- a/include/coff/pe.h
+++ b/include/coff/pe.h
@@ -20,6 +20,8 @@
#ifndef _PE_H
#define _PE_H
+#include "msdos.h"
+
/* NT specific file attributes. */
#define IMAGE_FILE_RELOCS_STRIPPED 0x0001
#define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
@@ -168,40 +170,11 @@
#define IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER 13
#define IMAGE_SUBSYSTEM_XBOX 14
-/* Magic values that are true for all dos/nt implementations. */
-#define DOSMAGIC 0x5a4d
-#define NT_SIGNATURE 0x00004550
-
/* NT allows long filenames, we want to accommodate this.
This may break some of the bfd functions. */
#undef FILNMLEN
#define FILNMLEN 18 /* # characters in a file name. */
-struct external_PEI_DOS_hdr
-{
- /* DOS header fields - always at offset zero in the EXE file. */
- char e_magic[2]; /* Magic number, 0x5a4d. */
- char e_cblp[2]; /* Bytes on last page of file, 0x90. */
- char e_cp[2]; /* Pages in file, 0x3. */
- char e_crlc[2]; /* Relocations, 0x0. */
- char e_cparhdr[2]; /* Size of header in paragraphs, 0x4. */
- char e_minalloc[2]; /* Minimum extra paragraphs needed, 0x0. */
- char e_maxalloc[2]; /* Maximum extra paragraphs needed, 0xFFFF. */
- char e_ss[2]; /* Initial (relative) SS value, 0x0. */
- char e_sp[2]; /* Initial SP value, 0xb8. */
- char e_csum[2]; /* Checksum, 0x0. */
- char e_ip[2]; /* Initial IP value, 0x0. */
- char e_cs[2]; /* Initial (relative) CS value, 0x0. */
- char e_lfarlc[2]; /* File address of relocation table, 0x40. */
- char e_ovno[2]; /* Overlay number, 0x0. */
- char e_res[4][2]; /* Reserved words, all 0x0. */
- char e_oemid[2]; /* OEM identifier (for e_oeminfo), 0x0. */
- 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. */
-};
-
struct external_PEI_IMAGE_hdr
{
char nt_signature[4]; /* Required NT signature, 0x4550. */
diff --git a/include/coff/powerpc.h b/include/coff/powerpc.h
index 37fef42..a5e56fb 100644
--- a/include/coff/powerpc.h
+++ b/include/coff/powerpc.h
@@ -37,8 +37,6 @@
/* extra NT defines */
#define PPCMAGIC 0760 /* peeked on aa PowerPC Windows NT box */
-#define DOSMAGIC 0x5a4d /* from arm.h, i386.h */
-#define NT_SIGNATURE 0x00004550 /* from arm.h, i386.h */
/* from winnt.h */
#define IMAGE_NT_OPTIONAL_HDR_MAGIC 0x10b