Package ghidra.app.util.bin.format.coff

# Class CoffFileHeader

java.lang.Object
ghidra.app.util.bin.format.coff.CoffFileHeader

All Implemented Interfaces:
  `StructConverter`

public class CoffFileHeader extends Object implements StructConverter

- ## Field Summary

  ### 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
  `CoffFileHeader(ByteProvider provider)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `short`
  `getFlags()`
  Returns the flags about this COFF.
  `long`
  `getImageBase(boolean isWindowsPlatform)`
  Returns the image base.
  `short`
  `getMachine()`
  `String`
  `getMachineName()`
  Returns the machine name.
  `short`
  `getMagic()`
  Returns the magic COFF file identifier.
  `AoutHeader`
  `getOptionalHeader()`
  Returns the a.out optional header.
  `short`
  `getOptionalHeaderSize()`
  Returns the size in bytes of the optional header.
  `short`
  `getSectionCount()`
  Returns the number of sections in this COFF file.
  `List<CoffSectionHeader>`
  `getSections()`
  Returns the sections in this COFF header.
  `CoffSymbol`
  `getSymbolAtIndex(long index)`
  `List<CoffSymbol>`
  `getSymbols()`
  Returns the symbols in this COFF header.
  `int`
  `getSymbolTableEntries()`
  Returns the number of symbols in the symbol table.
  `int`
  `getSymbolTablePointer()`
  Returns the file offset to the symbol table.
  `short`
  `getTargetID()`
  Returns the specific target id
  `int`
  `getTimestamp()`
  Returns the time stamp of when this file was created.
  `boolean`
  `isValid()`
  Tests if the given `ByteProvider` is a valid `CoffFileHeader`.
  `void`
  `parse(TaskMonitor monitor)`
  Finishes the parsing of this file header.
  `void`
  `parseSectionHeaders()`
  Read just the section headers, not including line numbers and relocations
  `int`
  `sizeof()`
  Returns the size (in bytes) of this COFF file header.
  `DataType`
  `toDataType()`
  Returns a structure datatype representing the contents of the implementor of this interface.

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

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

- ## Constructor Details

  - ### CoffFileHeader

    public CoffFileHeader(ByteProvider provider) throws IOException, CoffException
    Throws:
      `IOException`
      `CoffException`

- ## Method Details

  - ### getMagic

    public short getMagic()
    Returns the magic COFF file identifier.
    Returns:
      the magic COFF file identifier

  - ### getSectionCount

    public short getSectionCount()
    Returns the number of sections in this COFF file.
    Returns:
      the number of sections in this COFF file

  - ### getTimestamp

    public int getTimestamp()
    Returns the time stamp of when this file was created.
    Returns:
      the time stamp of when this file was created

  - ### getSymbolTablePointer

    public int getSymbolTablePointer()
    Returns the file offset to the symbol table.
    Returns:
      the file offset to the symbol table

  - ### getSymbolTableEntries

    public int getSymbolTableEntries()
    Returns the number of symbols in the symbol table.
    Returns:
      the number of symbols in the symbol table

  - ### getOptionalHeaderSize

    public short getOptionalHeaderSize()
    Returns the size in bytes of the optional header. The optional header immediately follows the file header and immediately proceeds the sections headers.
    Returns:
      the size in bytes of the optional header

  - ### getFlags

    public short getFlags()
    Returns the flags about this COFF.
    Returns:
      the flags about this COFF

  - ### getTargetID

    public short getTargetID() throws CoffException
    Returns the specific target id
    Returns:
      the specific target id
    Throws:
      `CoffException`

  - ### getImageBase

    public long getImageBase(boolean isWindowsPlatform)
    Returns the image base.
    Returns:
      the image base

  - ### getMachineName

    public String getMachineName()
    Returns the machine name.
    Returns:
      the machine name

  - ### getMachine

    public short getMachine()

  - ### parseSectionHeaders

    public void parseSectionHeaders() throws IOException
    Read just the section headers, not including line numbers and relocations
    Throws:
      `IOException`

  - ### parse

    public void parse(TaskMonitor monitor) throws IOException
    Finishes the parsing of this file header.
    Parameters:
      `monitor` - the task monitor
    Throws:
      `IOException` - if an i/o error occurs

  - ### getSections

    public List<CoffSectionHeader> getSections()
    Returns the sections in this COFF header.
    Returns:
      the sections in this COFF header

  - ### getSymbols

    public List<CoffSymbol> getSymbols()
    Returns the symbols in this COFF header.
    Returns:
      the symbols in this COFF header

  - ### getSymbolAtIndex

    public CoffSymbol getSymbolAtIndex(long index)

  - ### sizeof

    public int sizeof()
    Returns the size (in bytes) of this COFF file header.
    Returns:
      the size (in bytes) of this COFF file header

  - ### getOptionalHeader

    public AoutHeader getOptionalHeader()
    Returns the a.out optional header. This return value may be null.
    Returns:
      the a.out optional header

  - ### isValid

    public boolean isValid() throws IOException
    Tests if the given `ByteProvider` is a valid `CoffFileHeader`.

    To avoid false positives when the machine type is `CoffMachineType.IMAGE_FILE_MACHINE_UNKNOWN`, we do an additional check on some extra bytes at the beginning of the given `ByteProvider` to make sure the entire file isn't all 0's.

    Returns:
      True if this is a is a valid `CoffFileHeader`; otherwise, false
    Throws:
      `IOException` - if there was an IO-related issue

  - ### toDataType

    public DataType toDataType() throws DuplicateNameException, IOException
    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
      `IOException` - if an IO-related error occurs
    See Also:
      - `StructureDataType`