Class MachoProgramBuilder

java.lang.Object
ghidra.app.util.opinion.MachoProgramBuilder
Direct Known Subclasses:
DyldCacheProgramBuilder, MachoPrelinkProgramBuilder

public class MachoProgramBuilder extends Object
Builds up a Mach-O Program by parsing the Mach-O headers.
  • Field Details

  • Constructor Details

    • MachoProgramBuilder

      protected MachoProgramBuilder(Program program, ByteProvider provider, FileBytes fileBytes, boolean shouldAddChainedFixupsRelocations, MessageLog log, TaskMonitor monitor)
      Creates a new MachoProgramBuilder based on the given information.
      Parameters:
      program - The Program to build up.
      provider - The ByteProvider that contains the Mach-O's bytes.
      fileBytes - Where the Mach-O's bytes came from.
      shouldAddChainedFixupsRelocations - True if relocations should be added for chained fixups; otherwise, false.
      log - The log.
      monitor - A cancelable task monitor.
  • Method Details

    • buildProgram

      public static void buildProgram(Program program, ByteProvider provider, FileBytes fileBytes, boolean addChainedFixupsRelocations, MessageLog log, TaskMonitor monitor) throws Exception
      Builds up a Mach-O Program.
      Parameters:
      program - The Program to build up.
      provider - The ByteProvider that contains the Mach-O's bytes.
      fileBytes - Where the Mach-O's bytes came from.
      addChainedFixupsRelocations - True if relocations should be added for chained fixups; otherwise, false.
      log - The log.
      monitor - A cancelable task monitor.
      Throws:
      Exception - if a problem occurs.
    • build

      protected void build() throws Exception
      Throws:
      Exception
    • setImageBase

      protected void setImageBase() throws Exception
      Sets the image base
      Throws:
      Exception - if there was a problem setting the image base
    • processEncryption

      protected void processEncryption() throws Exception
      Logs encrypted block ranges
      Throws:
      Exception - if there was a problem detecting the encrypted block ranges
    • processEntryPoint

      protected void processEntryPoint() throws Exception
      Attempts to discover and set the entry point.
      Throws:
      Exception - If there was a problem discovering or setting the entry point.
    • processMemoryBlocks

      protected void processMemoryBlocks(MachHeader header, String source, boolean processSections, boolean allowZeroAddr) throws Exception
      Creates memory blocks for the given header.
      Parameters:
      header - The Mach-O header to process for memory block creation.
      source - A name that represents where the memory blocks came from.
      processSections - True to split segments into their sections.
      allowZeroAddr - True if memory blocks at address 0 should be processed; otherwise, false.
      Throws:
      Exception - If there was a problem processing the memory blocks.
    • fixupProgramTree

      protected void fixupProgramTree() throws Exception
      Fixes up the Program Tree to better visualize the memory blocks that were split into sections
      Throws:
      Exception - if there was a problem fixing up the Program Tree
    • processUnsupportedLoadCommands

      protected void processUnsupportedLoadCommands() throws CancelledException
      Processes LoadCommands that we haven't implemented yet.
      Throws:
      CancelledException - if the operation was cancelled.
    • processExports

      protected boolean processExports(MachHeader header) throws Exception
      Throws:
      Exception
    • processSymbolTables

      protected void processSymbolTables(MachHeader header, boolean processExports) throws Exception
      Throws:
      Exception
    • processIndirectSymbols

      protected void processIndirectSymbols() throws Exception
      The indirect symbols need to be applied across the IMPORT segment. The individual section do not really matter except the number of bytes between each symbol varies based on section.
      Throws:
      Exception - if there is a problem
    • setRelocatableProperty

      protected void setRelocatableProperty()
    • processLibraries

      protected void processLibraries()
    • processProgramDescription

      protected void processProgramDescription()
    • renameObjMsgSendRtpSymbol

      protected void renameObjMsgSendRtpSymbol() throws DuplicateNameException, InvalidInputException
      Throws:
      DuplicateNameException
      InvalidInputException
    • processUndefinedSymbols

      protected void processUndefinedSymbols() throws Exception
      Throws:
      Exception
    • processAbsoluteSymbols

      protected void processAbsoluteSymbols() throws Exception
      Throws:
      Exception
    • processDyldInfo

      protected void processDyldInfo(boolean doClassic)
    • markupHeaders

      protected void markupHeaders(MachHeader header, Address headerAddr) throws Exception
      Throws:
      Exception
    • setupHeaderAddr

      protected Address setupHeaderAddr(Collection<SegmentCommand> segments) throws AddressOverflowException
      Sets up the MachHeader in memory and returns its address. If the header was not intended to reside in memory (like for Mach-O object files}, then this method will create an area in the "OTHER" address space for the header to live in.
      Parameters:
      segments - A Collection of Mach-O segments
      Returns:
      The Address of MachHeader in memory
      Throws:
      AddressOverflowException - if the address lies outside the address space
    • markupSections

      protected void markupSections() throws Exception
      Throws:
      Exception
    • processProgramVars

      protected void processProgramVars()
      See crt.c from opensource.apple.com
    • processSectionRelocations

      protected void processSectionRelocations() throws CancelledException
      Processes the section relocations from all Sections.
      Throws:
      CancelledException - if the operation was cancelled.
    • processExternalRelocations

      protected void processExternalRelocations() throws CancelledException
      Processes the external relocations from all DynamicSymbolTableCommands.
      Throws:
      CancelledException - if the operation was cancelled.
    • processLocalRelocations

      protected void processLocalRelocations() throws CancelledException
      Processes the local relocations from all DynamicSymbolTableCommands.
      Throws:
      CancelledException - if the operation was cancelled.
    • processChainedFixups

      protected List<Address> processChainedFixups() throws Exception
      Fixes up any chained fixups. Relies on the __thread_starts section being present.
      Returns:
      A list of addresses where chained fixups were performed.
      Throws:
      Exception - if there was a problem reading/writing memory.
    • markupChainedFixups

      protected void markupChainedFixups(List<Address> chainedFixups) throws CancelledException
      Markup the given List of chained fixups by creating pointers at their locations, if possible
      Parameters:
      chainedFixups - The List of chained fixups to markup
      Throws:
      CancelledException - if the operation was cancelled