Package ghidra.app.util.bin.format.mz

# Class DOSHeader

java.lang.Object
ghidra.app.util.bin.format.mz.OldDOSHeader
ghidra.app.util.bin.format.mz.DOSHeader

All Implemented Interfaces:
  `Writeable`, `StructConverter`

public class DOSHeader extends OldDOSHeader
This class represents the `IMAGE_DOS_HEADER` struct as defined in `winnt.h`.

     typedef struct _IMAGE_DOS_HEADER {      // DOS .EXE header
         WORD   e_magic;                     // Magic number                                                                // MANDATORY
         WORD   e_cblp;                      // Bytes on last page of file
         WORD   e_cp;                        // Pages in file
         WORD   e_crlc;                      // Relocations
         WORD   e_cparhdr;                   // Size of header in paragraphs
         WORD   e_minalloc;                  // Minimum extra paragraphs needed
         WORD   e_maxalloc;                  // Maximum extra paragraphs needed
         WORD   e_ss;                        // Initial (relative) SS value
         WORD   e_sp;                        // Initial SP value
         WORD   e_csum;                      // Checksum
         WORD   e_ip;                        // Initial IP value
         WORD   e_cs;                        // Initial (relative) CS value
         WORD   e_lfarlc;                    // File address of relocation table
         WORD   e_ovno;                      // Overlay number
         WORD   e_res[4];                    // Reserved words
         WORD   e_oemid;                     // OEM identifier (for e_oeminfo)
         WORD   e_oeminfo;                   // OEM information; e_oemid specific
         WORD   e_res2[10];                  // Reserved words                                                      // MANDATORY
         LONG   e_lfanew;                    // File address of new exe header
     } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `NAME`
  The name to use when converting into a structure data type.
  `static final int`
  `SIZEOF_DOS_HEADER`

  ### Fields inherited from class ghidra.app.util.bin.format.mz.OldDOSHeader

  `IMAGE_DOS_SIGNATURE, reader`

  ### Fields inherited from interface ghidra.app.util.bin.StructConverter

  `ASCII, BYTE, DWORD, IBO32, IBO64, POINTER, QWORD, SLEB128, STRING, ULEB128, UTF16, UTF8, VOID, WORD`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DOSHeader(BinaryReader reader)`
  Constructs a new DOS header.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `decrementStub(int start)`
  `int`
  `e_lfanew()`
  Returns the file address of new EXE header.
  `short`
  `e_oemid()`
  Returns the OEM identifier (for e_oeminfo).
  `short`
  `e_oeminfo()`
  Returns the OEM information; e_oemid specific.
  `short[]`
  `e_res()`
  Returns the reserved words.
  `short[]`
  `e_res2()`
  Returns the reserved words (2).
  `String`
  `getName()`
  Helper to override the value of name
  `int`
  `getProgramLen()`
  Returns the length (in bytes) of the DOS program.
  `boolean`
  `hasNewExeHeader()`
  Returns true if a new EXE header exists.
  `boolean`
  `hasPeHeader()`
  Returns true if a PE header exists.
  `protected void`
  `parse()`
  `DataType`
  `toDataType()`
  Returns a structure datatype representing the contents of the implementor of this interface.
  `void`
  `write(RandomAccessFile raf, DataConverter dc)`
  Writes this object to the specified random access file using the data converter to handle endianness.

  ### Methods inherited from class ghidra.app.util.bin.format.mz.OldDOSHeader

  `e_cblp, e_cp, e_cparhdr, e_crlc, e_cs, e_csum, e_ip, e_lfarlc, e_magic, e_maxalloc, e_minalloc, e_ovno, e_sp, e_ss, getProcessorName, isDosSignature`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### NAME

    public static final String NAME
    The name to use when converting into a structure data type.
    See Also:
      - Constant Field Values

  - ### SIZEOF_DOS_HEADER

    public static final int SIZEOF_DOS_HEADER
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### DOSHeader

    public DOSHeader(BinaryReader reader) throws IOException
    Constructs a new DOS header.
    Parameters:
      `reader` - the binary reader
    Throws:
      `IOException` - if there was an IO-related error

- ## Method Details

  - ### e_res

    public short[] e_res()
    Returns the reserved words.
    Returns:
      the reserved words

  - ### e_oemid

    public short e_oemid()
    Returns the OEM identifier (for e_oeminfo).
    Returns:
      the OEM identifier (for e_oeminfo)

  - ### e_oeminfo

    public short e_oeminfo()
    Returns the OEM information; e_oemid specific.
    Returns:
      the OEM information; e_oemid specific

  - ### e_res2

    public short[] e_res2()
    Returns the reserved words (2).
    Returns:
      the reserved words (2)

  - ### e_lfanew

    public int e_lfanew()
    Returns the file address of new EXE header.
    Returns:
      the file address of new EXE header

  - ### hasNewExeHeader

    public boolean hasNewExeHeader()
    Returns true if a new EXE header exists.
    Overrides:
      `hasNewExeHeader` in class `OldDOSHeader`
    Returns:
      true if a new EXE header exists

  - ### hasPeHeader

    public boolean hasPeHeader()
    Returns true if a PE header exists.
    Overrides:
      `hasPeHeader` in class `OldDOSHeader`
    Returns:
      true if a PE header exists

  - ### toDataType

    public DataType toDataType() throws DuplicateNameException
    Description copied from interface: `StructConverter`
    Returns a structure datatype representing the contents of the implementor of this interface.

    For example, given:

         class A {
             int foo;
             double bar;
         }

    The return value should be a structure data type with two data type components; an INT and a DOUBLE. The structure should contain field names and, if possible, field comments.

    Specified by:
      `toDataType` in interface `StructConverter`
    Overrides:
      `toDataType` in class `OldDOSHeader`
    Returns:
      returns a structure datatype representing the implementor of this interface
    Throws:
      `DuplicateNameException` - when a datatype of the same name already exists
    See Also:
      - `StructConverter.toDataType()`

  - ### getName

    public String getName()
    Helper to override the value of name
    Overrides:
      `getName` in class `OldDOSHeader`
    Returns:
      The name of the header

  - ### getProgramLen

    public int getProgramLen()
    Returns the length (in bytes) of the DOS program.

    In other words: `e_lfanew() - SIZEOF_DOS_HEADER`

    Returns:
      the length (in bytes)

  - ### parse

    protected void parse() throws IOException
    Overrides:
      `parse` in class `OldDOSHeader`
    Throws:
      `IOException`

  - ### decrementStub

    public void decrementStub(int start)

  - ### write

    public void write(RandomAccessFile raf, DataConverter dc) throws IOException
    Description copied from interface: `Writeable`
    Writes this object to the specified random access file using the data converter to handle endianness.
    Specified by:
      `write` in interface `Writeable`
    Overrides:
      `write` in class `OldDOSHeader`
    Parameters:
      `raf` - the random access file
      `dc` - the data converter
    Throws:
      `IOException` - if an I/O error occurs
    See Also:
      - `Writeable.write(java.io.RandomAccessFile, ghidra.util.DataConverter)`