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

# Class MachoRelocation

java.lang.Object
ghidra.app.util.bin.format.macho.relocation.MachoRelocation

public class MachoRelocation extends Object
A representation of a single Mach-O relocation that the `MachoRelocationHandler` will use to perform the relocation. In Mach-O, some relocations may be "paired," so an instance of this class may contain 2 `RelocationInfo`s.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MachoRelocation(Program program, MachHeader machoHeader, Address relocationAddress, RelocationInfo relocationInfo)`
  Creates a new unpaired `MachoRelocation` object
  `MachoRelocation(Program program, MachHeader machoHeader, Address relocationAddress, RelocationInfo relocationInfo, RelocationInfo relocationInfoExtra)`
  Creates a new paired `MachoRelocation` object

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Program`
  `getProgram()`
  Gets the `Program` associated with this relocation
  `Address`
  `getRelocationAddress()`
  Gets the `Address` the relocation takes place at
  `RelocationInfo`
  `getRelocationInfo()`
  Gets the lower-level `RelocationInfo` that describes the relocation
  `RelocationInfo`
  `getRelocationInfoExtra()`
  Gets the lower-level `RelocationInfo` that describes the second part of the paired relocation.
  `Address`
  `getTargetAddress()`
  Gets the `Address` of the relocation target
  `Address`
  `getTargetAddressExtra()`
  Gets the `Address` of the extra relocation target
  `String`
  `getTargetDescription()`
  Gets a short description of the target of the relocation
  `boolean`
  `requiresRelocation()`
  Checks to see if this relocation requires work to be done on it.
  `String`
  `toString()`

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

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

- ## Constructor Details

  - ### MachoRelocation

    public MachoRelocation(Program program, MachHeader machoHeader, Address relocationAddress, RelocationInfo relocationInfo)
    Creates a new unpaired `MachoRelocation` object
    Parameters:
      `program` - The program
      `machoHeader` - The Mach-O header
      `relocationAddress` - The `Address` the relocation takes place at
      `relocationInfo` - The lower-level `RelocationInfo` that describes the relocation

  - ### MachoRelocation

    public MachoRelocation(Program program, MachHeader machoHeader, Address relocationAddress, RelocationInfo relocationInfo, RelocationInfo relocationInfoExtra)
    Creates a new paired `MachoRelocation` object
    Parameters:
      `program` - The program
      `machoHeader` - The Mach-O header
      `relocationAddress` - The `Address` the relocation takes place at
      `relocationInfo` - The lower-level `RelocationInfo` that describes the first part of the relocation
      `relocationInfoExtra` - The lower-level `RelocationInfo` that describes the second part of the relocation

- ## Method Details

  - ### getProgram

    public Program getProgram()
    Gets the `Program` associated with this relocation
    Returns:
      The `Program` associated with this relocation

  - ### getRelocationAddress

    public Address getRelocationAddress()
    Gets the `Address` the relocation takes place at
    Returns:
      The `Address` the relocation takes place at

  - ### getRelocationInfo

    public RelocationInfo getRelocationInfo()
    Gets the lower-level `RelocationInfo` that describes the relocation
    Returns:
      The lower-level `RelocationInfo` that describes the relocation

  - ### getRelocationInfoExtra

    public RelocationInfo getRelocationInfoExtra()
    Gets the lower-level `RelocationInfo` that describes the second part of the paired relocation. This could be null if the relocation is not paired.
    Returns:
      The lower-level `RelocationInfo` that describes the second part of the paired relocation, or null if the relocation is not paired

  - ### getTargetAddress

    public Address getTargetAddress() throws RelocationException
    Gets the `Address` of the relocation target
    Returns:
      The `Address` of the relocation target
    Throws:
      `RelocationException` - If the `Address` of the relocation target could not be found

  - ### getTargetAddressExtra

    public Address getTargetAddressExtra() throws RelocationException
    Gets the `Address` of the extra relocation target
    Returns:
      The `Address` of the extra relocation target
    Throws:
      `RelocationException` - If the `Address` of the extra relocation target could not be found (of if there wasn't an extra relocation target).

  - ### requiresRelocation

    public boolean requiresRelocation()
    Checks to see if this relocation requires work to be done on it. Since our `loader` does not allow non-default image bases, it is unnecessary to perform relocations under certain conditions.
    Returns:
      True if relocation steps are needed; otherwise, false

  - ### getTargetDescription

    public String getTargetDescription()
    Gets a short description of the target of the relocation
    Returns:
      A short description of the target of the relocation

  - ### toString

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