Class DOSHeader

  • All Implemented Interfaces:
    Writeable, StructConverter

    public class DOSHeader
    extends java.lang.Object
    implements StructConverter, Writeable
    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;
     
    • Constructor Summary

      Constructors 
      Constructor Description
      DOSHeader()
      DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static DOSHeader createDOSHeader​(FactoryBundledWithBinaryReader reader)
      Constructs a new DOS header.
      void decrementStub​(int start)  
      short e_cblp()
      Returns the number of bytes on the last page of file.
      short e_cp()
      Returns the number of pages in the file.
      short e_cparhdr()
      Returns the size of header in paragraphs.
      short e_crlc()
      Returns the number of relocations.
      short e_cs()
      Returns the initial (relative) CS value.
      short e_csum()
      Returns the checksum.
      short e_ip()
      Returns the initial IP value.
      int e_lfanew()
      Returns the file address of new EXE header.
      short e_lfarlc()
      Returns the file address of relocation table.
      short e_magic()
      Returns the magic number.
      short e_maxalloc()
      Returns the maximum extra paragraphs needed.
      short e_minalloc()
      Returns the minimum extra paragraphs needed.
      short e_oemid()
      Returns the OEM identifier (for e_oeminfo).
      short e_oeminfo()
      Returns the OEM information; e_oemid specific.
      short e_ovno()
      Returns the overlay number.
      short[] e_res()
      Returns the reserved words.
      short[] e_res2()
      Returns the reserved words (2).
      short e_sp()
      Returns the initial SP value.
      short e_ss()
      Returns the initial (relative) SS value.
      java.lang.String getProcessorName()
      Returns the processor name.
      int getProgramLen()
      Returns the length (in bytes) of the DOS program.
      boolean hasNewExeHeader()
      Returns true if a new EXE header exists.
      boolean isDosSignature()
      Returns true if the DOS magic number is correct
      DataType toDataType()
      Returns a structure datatype representing the contents of the implementor of this interface.
      void write​(java.io.RandomAccessFile raf, DataConverter dc)
      Writes this object to the specified random access file using the data converter to handle endianness.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NAME

        public static final java.lang.String NAME
        The name to use when converting into a structure data type.
        See Also:
        Constant Field Values
    • Constructor Detail

      • DOSHeader

        public DOSHeader()
        DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
    • Method Detail

      • createDOSHeader

        public static DOSHeader createDOSHeader​(FactoryBundledWithBinaryReader reader)
                                         throws java.io.IOException
        Constructs a new DOS header.
        Parameters:
        reader - the binary reader
        Throws:
        java.io.IOException
      • getProcessorName

        public java.lang.String getProcessorName()
        Returns the processor name.
        Returns:
        the processor name
      • e_magic

        public short e_magic()
        Returns the magic number.
        Returns:
        the magic number
      • e_cblp

        public short e_cblp()
        Returns the number of bytes on the last page of file.
        Returns:
        the number of bytes on the last page of the file
      • e_cp

        public short e_cp()
        Returns the number of pages in the file.
        Returns:
        the number of pages in the file
      • e_crlc

        public short e_crlc()
        Returns the number of relocations.
        Returns:
        the number of relocations
      • e_cparhdr

        public short e_cparhdr()
        Returns the size of header in paragraphs.
        Returns:
        the size of header in paragraphs
      • e_minalloc

        public short e_minalloc()
        Returns the minimum extra paragraphs needed.
        Returns:
        the minimum extra paragraphs needed
      • e_maxalloc

        public short e_maxalloc()
        Returns the maximum extra paragraphs needed.
        Returns:
        the maximum extra paragraphs needed
      • e_ss

        public short e_ss()
        Returns the initial (relative) SS value.
        Returns:
        the initial (relative) SS value
      • e_sp

        public short e_sp()
        Returns the initial SP value.
        Returns:
        the initial SP value
      • e_csum

        public short e_csum()
        Returns the checksum.
        Returns:
        the checksum
      • e_ip

        public short e_ip()
        Returns the initial IP value.
        Returns:
        the initial IP value
      • e_cs

        public short e_cs()
        Returns the initial (relative) CS value.
        Returns:
        the initial (relative) CS value
      • e_lfarlc

        public short e_lfarlc()
        Returns the file address of relocation table.
        Returns:
        the file address of relocation table
      • e_ovno

        public short e_ovno()
        Returns the overlay number.
        Returns:
        the overlay number
      • 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.
        Returns:
        true if a new EXE header exists
      • isDosSignature

        public boolean isDosSignature()
        Returns true if the DOS magic number is correct
        Returns:
        true if the DOS magic number is correct
      • 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
        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()
      • 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)
      • decrementStub

        public void decrementStub​(int start)