Class ElfRelocationHandler

java.lang.Object
ghidra.app.util.bin.format.elf.relocation.ElfRelocationHandler
All Implemented Interfaces:
ExtensionPoint

public abstract class ElfRelocationHandler extends Object implements ExtensionPoint
ElfRelocationHandler provides the base class for processor specific ELF relocation handlers.
  • Field Details

    • GOT_BLOCK_NAME

      public static final String GOT_BLOCK_NAME
      Fabricated Global Offset Table (GOT) name/prefix to be used when processing an object module and a GOT must be fabricated to allow relocation processing.
      See Also:
  • Constructor Details

    • ElfRelocationHandler

      public ElfRelocationHandler()
  • Method Details

    • canRelocate

      public abstract boolean canRelocate(ElfHeader elf)
    • getRelrRelocationType

      public int getRelrRelocationType()
      Get the architecture-specific relative relocation type which should be applied to RELR relocations. The default implementation returns 0 which indicates RELR is unsupported.
      Returns:
      RELR relocation type
    • createRelocationContext

      public ElfRelocationContext createRelocationContext(ElfLoadHelper loadHelper, Map<ElfSymbol,Address> symbolMap)
      Relocation context for a specific Elf image and relocation table. The relocation context is used to process relocations and manage any data required to process relocations.
      Parameters:
      loadHelper - Elf load helper
      symbolMap - Elf symbol placement map
      Returns:
      relocation context or null if unsupported
    • relocate

      public abstract RelocationResult relocate(ElfRelocationContext elfRelocationContext, ElfRelocation relocation, Address relocationAddress) throws MemoryAccessException, NotFoundException
      Perform relocation fixup
      Parameters:
      elfRelocationContext - relocation context
      relocation - ELF relocation
      relocationAddress - relocation target address (fixup location)
      Returns:
      applied relocation result (conveys status and applied byte-length)
      Throws:
      MemoryAccessException - memory access failure
      NotFoundException - required relocation data not found
    • applyComponentOffsetPointer

      public static void applyComponentOffsetPointer(Program program, Address addr, long componentOffset)
      Apply a pointer-typedef with a specified component-offset if specified address is not contained within an execute block.
      Parameters:
      program - program
      addr - address where data should be applied
      componentOffset - component offset
    • warnExternalOffsetRelocation

      public static void warnExternalOffsetRelocation(Program program, Address relocationAddress, Address symbolAddr, String symbolName, long adjustment, MessageLog log)
      Determine if symbolAddr is contained within the EXTERNAL block with a non-zero adjustment. If so, relocationAddress will be marked with a EXTERNAL Data Elf Relocation with pointer-offset warning or error bookmark. Bookmark and logged message will be conveyed as an error if relocationAddress resides within an executable memory block. NOTE: This method should only be invoked when the symbol offset will be adjusted with a non-zero value (i.e., addend).
      Parameters:
      program - program
      relocationAddress - relocation address to be bookmarked if EXTERNAL block relocation
      symbolAddr - symbol address correspondng to relocation (may be null)
      symbolName - symbol name (may not be null if symbolAddr is not null)
      adjustment - relocation symbol offset adjustment/addend
      log - import log
    • markAsUnhandled

      public static void markAsUnhandled(Program program, Address relocationAddress, long type, long symbolIndex, String symbolName, MessageLog log)
      Generate error log entry and bookmark at relocationAddress indicating an unhandled relocation.
      Parameters:
      program - program
      relocationAddress - relocation address to be bookmarked
      type - relocation type
      symbolIndex - associated symbol index within symbol table
      symbolName - associated symbol name
      log - import log
    • markAsUnsupportedRelr

      public static void markAsUnsupportedRelr(Program program, Address relocationAddress)
      Generate error log entry and bookmark at relocationAddress indicating an unsupported RELR relocation.
      Parameters:
      program - program
      relocationAddress - relocation address to be bookmarked
    • markAsUninitializedMemory

      public static void markAsUninitializedMemory(Program program, Address relocationAddress, long type, long symbolIndex, String symbolName, MessageLog log)
      Generate error log entry and bookmark at relocationAddress where import failed to transition block to initialized while processing relocation.
      Parameters:
      program - program
      relocationAddress - relocation address to be bookmarked
      type - relocation type
      symbolIndex - associated symbol index within symbol table
      symbolName - associated symbol name
      log - import log
    • markAsError

      public static void markAsError(Program program, Address relocationAddress, long type, String symbolName, String msg, MessageLog log)
      Generate error log entry and bookmark at relocationAddress where import failed to be applied.
      Parameters:
      program - program
      relocationAddress - relocation address to be bookmarked
      type - relocation type
      symbolName - associated symbol name
      msg - error messge
      log - import log
    • markAsError

      public static void markAsError(Program program, Address relocationAddress, String type, String symbolName, String msg, MessageLog log)
      Generate error log entry and bookmark at relocationAddress where import failed to be applied.
      Parameters:
      program - program
      relocationAddress - relocation address to be bookmarked
      type - relocation type
      symbolName - associated symbol name
      msg - additional error message
      log - import log
    • markAsWarning

      public static void markAsWarning(Program program, Address relocationAddress, String type, String msg, MessageLog log)
      Generate warning log entry and bookmark at relocationAddress where import issue occurred.
      Parameters:
      program - program
      relocationAddress - relocation address to be bookmarked
      type - relocation type
      msg - message associated with warning
      log - import log
    • markAsWarning

      public static void markAsWarning(Program program, Address relocationAddress, String type, String symbolName, long symbolIndex, String msg, MessageLog log)
      Generate warning log entry and bookmark at relocationAddress where import issue occurred.
      Parameters:
      program - program
      relocationAddress - relocation address to be bookmarked
      type - relocation type
      symbolName - symbol name
      symbolIndex - symbol index
      msg - message associated with warning
      log - import log