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

# Class SegmentCommand

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

All Implemented Interfaces:
  `StructConverter`

public class SegmentCommand extends LoadCommand
Represents a segment_command and segment_command_64 structure

- ## 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
  `SegmentCommand(BinaryReader reader, boolean is32bit)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `contains(long addr)`
  Returns true if the segment contains the given address
  `static byte[]`
  `create(int magic, String name, long vmAddr, long vmSize, long fileOffset, long fileSize, int maxProt, int initProt, int numSections, int flags)`
  Creates a new segment command byte array
  `String`
  `getCommandName()`
  Gets the name of this load command
  `long`
  `getFileOffset()`
  `long`
  `getFileSize()`
  `int`
  `getFlags()`
  `int`
  `getInitProtection()`
  Returns a octal model value reflecting the segment's initial protection value.
  `int`
  `getMaxProtection()`
  Returns a octal model value reflecting the segment's maximum protection value allowed.
  `int`
  `getNumberOfSections()`
  `Section`
  `getSectionByName(String sectionName)`
  `Section`
  `getSectionContaining(Address address)`
  `List<Section>`
  `getSections()`
  `String`
  `getSegmentName()`
  `long`
  `getVMaddress()`
  `long`
  `getVMsize()`
  `boolean`
  `isAppleProtected()`
  `boolean`
  `isExecute()`
  Returns true if the initial protections include EXECUTE.
  `boolean`
  `isRead()`
  Returns true if the initial protections include READ.
  `boolean`
  `isWrite()`
  Returns true if the initial protections include WRITE.
  `void`
  `markupRawBinary(MachHeader header, FlatProgramAPI api, Address baseAddress, ProgramModule parentModule, TaskMonitor monitor, MessageLog log)`
  Marks-up this `LoadCommand` with data structures and comments.
  `void`
  `setFileOffset(long fileOffset)`
  `void`
  `setFileSize(long fileSize)`
  `void`
  `setSegmentName(String name)`
  `void`
  `setVMaddress(long vmaddr)`
  `void`
  `setVMsize(long vmSize)`
  `static int`
  `size(int magic)`
  Gets the size a segment command would be for the given magic
  `DataType`
  `toDataType()`
  Returns a structure datatype representing the contents of the implementor of this interface.
  `String`
  `toString()`

  ### Methods inherited from class ghidra.app.util.bin.format.macho.commands.LoadCommand

  `createFragment, createPlateComment, fileOffsetToAddress, getCommandSize, getCommandType, getContextualName, getLinkerDataOffset, getLinkerDataSize, getStartIndex, markup, markupPlateComment, setEndian, updateMonitor`

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

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

- ## Constructor Details

  - ### SegmentCommand

    public SegmentCommand(BinaryReader reader, boolean is32bit) throws IOException
    Throws:
      `IOException`

- ## Method Details

  - ### getSections

    public List<Section> getSections()

  - ### getSectionContaining

    public Section getSectionContaining(Address address)

  - ### getSectionByName

    public Section getSectionByName(String sectionName)

  - ### getSegmentName

    public String getSegmentName()

  - ### setSegmentName

    public void setSegmentName(String name)

  - ### getVMaddress

    public long getVMaddress()

  - ### setVMaddress

    public void setVMaddress(long vmaddr)

  - ### getVMsize

    public long getVMsize()

  - ### setVMsize

    public void setVMsize(long vmSize)

  - ### getFileOffset

    public long getFileOffset()

  - ### setFileOffset

    public void setFileOffset(long fileOffset)

  - ### getFileSize

    public long getFileSize()

  - ### setFileSize

    public void setFileSize(long fileSize)

  - ### getMaxProtection

    public int getMaxProtection()
    Returns a octal model value reflecting the segment's maximum protection value allowed. For example:`7 -> 0x111 -> rwx 5 -> 0x101 -> rx`
    Returns:
      the maximum protections of a segment

  - ### getInitProtection

    public int getInitProtection()
    Returns a octal model value reflecting the segment's initial protection value. For example:`7 -> 0x111 -> rwx 5 -> 0x101 -> rx`
    Returns:
      the initial protections of a segment

  - ### isRead

    public boolean isRead()
    Returns true if the initial protections include READ.
    Returns:
      true if the initial protections include READ

  - ### isWrite

    public boolean isWrite()
    Returns true if the initial protections include WRITE.
    Returns:
      true if the initial protections include WRITE

  - ### isExecute

    public boolean isExecute()
    Returns true if the initial protections include EXECUTE.
    Returns:
      true if the initial protections include EXECUTE

  - ### getNumberOfSections

    public int getNumberOfSections()

  - ### getFlags

    public int getFlags()

  - ### isAppleProtected

    public boolean isAppleProtected()

  - ### contains

    public boolean contains(long addr)
    Returns true if the segment contains the given address
    Parameters:
      `addr` - The address to check
    Returns:
      True if the segment contains the given address; otherwise, false

  - ### 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.

    Returns:
      returns a structure datatype representing the implementor of this interface
    Throws:
      `DuplicateNameException` - when a datatype of the same name already exists
      `IOException`
    See Also:
      - `StructureDataType`

  - ### getCommandName

    public String getCommandName()
    Description copied from class: `LoadCommand`
    Gets the name of this load command
    Specified by:
      `getCommandName` in class `LoadCommand`
    Returns:
      The name of this load command

  - ### markupRawBinary

    public void markupRawBinary(MachHeader header, FlatProgramAPI api, Address baseAddress, ProgramModule parentModule, TaskMonitor monitor, MessageLog log)
    Description copied from class: `LoadCommand`
    Marks-up this `LoadCommand` with data structures and comments. Assumes the program was imported as a Raw Binary.
    Overrides:
      `markupRawBinary` in class `LoadCommand`
    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`

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### create

    public static byte[] create(int magic, String name, long vmAddr, long vmSize, long fileOffset, long fileSize, int maxProt, int initProt, int numSections, int flags) throws MachException
    Creates a new segment command byte array
    Parameters:
      `magic` - The magic
      `name` - The name of the segment (must be less than or equal to 16 bytes)
      `vmAddr` - The address of the start of the segment
      `vmSize` - The size of the segment in memory
      `fileOffset` - The file offset of the start of the segment
      `fileSize` - The size of the segment on disk
      `maxProt` - The maximum protections of the segment
      `initProt` - The initial protection of the segment
      `numSections` - The number of sections in the segment
      `flags` - The segment flags
    Returns:
      The new segment in byte array form
    Throws:
      `MachException` - if an invalid magic value was passed in (see `MachConstants`), or if the desired segment name exceeds 16 bytes

  - ### size

    public static int size(int magic) throws MachException
    Gets the size a segment command would be for the given magic
    Parameters:
      `magic` - The magic
    Returns:
      The size in bytes a segment command would be for the given magic
    Throws:
      `MachException` - if an invalid magic value was passed in (see `MachConstants`)