Package ghidra.app.util.bin.format.macho.commands

# Class LoadCommand

java.lang.Object
ghidra.app.util.bin.format.macho.commands.LoadCommand

All Implemented Interfaces:
  `StructConverter`

Direct Known Subclasses:
  `BuildVersionCommand`, `CorruptLoadCommand`, `DyldInfoCommand`, `DynamicLibraryCommand`, `DynamicLinkerCommand`, `DynamicSymbolTableCommand`, `EncryptedInformationCommand`, `EntryPointCommand`, `FileSetEntryCommand`, `FixedVirtualMemoryFileCommand`, `LinkEditDataCommand`, `LinkerOptionCommand`, `ObsoleteCommand`, `PrebindChecksumCommand`, `PreboundDynamicLibraryCommand`, `RoutinesCommand`, `RunPathCommand`, `SegmentCommand`, `SourceVersionCommand`, `SubClientCommand`, `SubFrameworkCommand`, `SubLibraryCommand`, `SubUmbrellaCommand`, `SymbolTableCommand`, `ThreadCommand`, `TwoLevelHintsCommand`, `UnsupportedLoadCommand`, `UuidCommand`, `VersionMinCommand`

public abstract class LoadCommand extends Object implements StructConverter
Represents a load_command structure

See Also:
  - EXTERNAL_HEADERS/mach-o/loader.h

- ## 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
  `LoadCommand(BinaryReader reader)`
  Creates a new `LoadCommand`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected long`
  `checkCount(long count)`
  Checks to make sure the given count value isn't larger than `Integer.MAX_VALUE`.
  `protected final ProgramFragment`
  `createFragment(FlatProgramAPI api, Address baseAddress, ProgramModule module)`
  `protected final void`
  `createPlateComment(FlatProgramAPI api, Address addr)`
  `protected Address`
  `fileOffsetToAddress(Program program, MachHeader header, long fileOffset, long size)`
  Converts the given Mach-O file offset to an `Address`
  `abstract String`
  `getCommandName()`
  Gets the name of this load command
  `int`
  `getCommandSize()`
  Gets the size of this load command in bytes
  `int`
  `getCommandType()`
  Gets the type of this load command
  `protected String`
  `getContextualName(String source, String additionalDescription)`
  Gets the name of this `LoadCommand` which includes contextual information
  `long`
  `getLinkerDataOffset()`
  Gets the file offset of this load command's "linker data".
  `long`
  `getLinkerDataSize()`
  Gets the file size of this load command's "linker data".
  `long`
  `getStartIndex()`
  Returns the binary start index of this load command
  `void`
  `markup(Program program, MachHeader header, String source, TaskMonitor monitor, MessageLog log)`
  Marks up this `LoadCommand` data with data structures and comments.
  `protected void`
  `markupPlateComment(Program program, Address address, String source, String additionalDescription)`
  Creates a plate comment at the given `Address` based on this `LoadCommand`'s name
  `void`
  `markupRawBinary(MachHeader header, FlatProgramAPI api, Address baseAddress, ProgramModule parentModule, TaskMonitor monitor, MessageLog log)`
  Marks-up this `LoadCommand` with data structures and comments.
  `protected final void`
  `updateMonitor(TaskMonitor monitor)`

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

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

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

  `toDataType`

- ## Constructor Details

  - ### LoadCommand

    public LoadCommand(BinaryReader reader) throws IOException
    Creates a new `LoadCommand`
    Parameters:
      `reader` - A `BinaryReader` that points to the start of the load command
    Throws:
      `IOException` - if there was an IO-related error

- ## Method Details

  - ### getStartIndex

    public long getStartIndex()
    Returns the binary start index of this load command
    Returns:
      the binary start index of this load command

  - ### getCommandType

    public int getCommandType()
    Gets the type of this load command
    Returns:
      The type of this load command

  - ### getCommandSize

    public int getCommandSize()
    Gets the size of this load command in bytes
    Returns:
      The size of this load command in bytes

  - ### getCommandName

    public abstract String getCommandName()
    Gets the name of this load command
    Returns:
      The name of this load command

  - ### getLinkerDataOffset

    public long getLinkerDataOffset()
    Gets the file offset of this load command's "linker data". Not all load commands with data will have linker data. Linker data typically resides in the __LINKEDIT segment.
    Returns:
      The file offset of this load command's "linker data", or 0 if it has no linker data

  - ### getLinkerDataSize

    public long getLinkerDataSize()
    Gets the file size of this load command's "linker data". Not all load commands with data will have linker data. Linker data typically resides in the __LINKEDIT segment.
    Returns:
      The file size of this load command's "linker data", or 0 if it has no linker data

  - ### markup

    public void markup(Program program, MachHeader header, String source, TaskMonitor monitor, MessageLog log) throws CancelledException
    Marks up this `LoadCommand` data with data structures and comments. Assumes the program was imported as a Mach-O.
    Parameters:
      `program` - The `Program` to mark up
      `header` - The Mach-O header
      `source` - A name that represents where the header came from (could be null)
      `monitor` - A cancellable task monitor
      `log` - The log
    Throws:
      `CancelledException` - if the user cancelled the operation

  - ### markupPlateComment

    protected void markupPlateComment(Program program, Address address, String source, String additionalDescription)
    Creates a plate comment at the given `Address` based on this `LoadCommand`'s name
    Parameters:
      `program` - The `Program` to mark up
      `address` - The `Address` to put the comment at
      `source` - An optional string representing the source of the `LoadCommand`. Could be empty or null.
      `additionalDescription` - An optional string representing a sub-description of this `LoadCommand`. Could be empty or null.

  - ### getContextualName

    protected String getContextualName(String source, String additionalDescription)
    Gets the name of this `LoadCommand` which includes contextual information
    Parameters:
      `source` - The source of this `LoadCommand` (could be null or empty)
      `additionalDescription` - Additional information to associate with the `LoadCommand` name
    Returns:
      The name of this `LoadCommand` which includes contextual information

  - ### fileOffsetToAddress

    protected Address fileOffsetToAddress(Program program, MachHeader header, long fileOffset, long size)
    Converts the given Mach-O file offset to an `Address`
    Parameters:
      `program` - The `Program`
      `header` - The Mach-O header
      `fileOffset` - The file offset of the data (0 indicates no data)
      `size` - The size (actual size not important, but 0 will cause null to be returned)
    Returns:
      The converted `Address`, or null if there is no corresponding `Address`

  - ### checkCount

    protected long checkCount(long count) throws IOException
    Checks to make sure the given count value isn't larger than `Integer.MAX_VALUE`.

    Count values are typically `uint32_t`, so we store them as `long`s. But, we usually end up storing the items in an array or `ArrayList`, which can't exceed the size of an `int`.

    Parameters:
      `count` - The count value to check
    Returns:
      The original count value
    Throws:
      `IOException` - if the given count value exceeds `Integer.MAX_VALUE`

  - ### markupRawBinary

    public void markupRawBinary(MachHeader header, FlatProgramAPI api, Address baseAddress, ProgramModule parentModule, TaskMonitor monitor, MessageLog log)
    Marks-up this `LoadCommand` with data structures and comments. Assumes the program was imported as a Raw Binary.
    Parameters:
      `header` - The Mach-O header
      `api` - A `FlatProgramAPI`
      `baseAddress` - The base address of the program
      `parentModule` - The parent `module` to create fragments
      `monitor` - A cancellable task monitor
      `log` - The log
    See Also:
      - `MachoBinaryAnalysisCommand`

  - ### createFragment

    protected final ProgramFragment createFragment(FlatProgramAPI api, Address baseAddress, ProgramModule module) throws Exception
    Throws:
      `Exception`

  - ### createPlateComment

    protected final void createPlateComment(FlatProgramAPI api, Address addr)

  - ### updateMonitor

    protected final void updateMonitor(TaskMonitor monitor)