Class AbstractElfRelocationHandler<T extends ElfRelocationType,C extends ElfRelocationContext<?>>

java.lang.Object
ghidra.app.util.bin.format.elf.relocation.ElfRelocationHandler
ghidra.app.util.bin.format.elf.relocation.AbstractElfRelocationHandler<T,C>
Type Parameters:
T - ELF relocation type enum class
C - ELF relocation context class
All Implemented Interfaces:
ExtensionPoint

public abstract class AbstractElfRelocationHandler<T extends ElfRelocationType,C extends ElfRelocationContext<?>> extends ElfRelocationHandler
ElfRelocationHandler provides the base class for processor specific ELF relocation handlers. Implementations may only specify a public default constructor as they will be identified and instatiated by the ClassSearcher. As such their name must end with "ElfRelocationHandler" (e.g., MyProc_ElfRelocationHandler).
  • Constructor Details

    • AbstractElfRelocationHandler

      protected AbstractElfRelocationHandler(Class<T> relocationEnumClass)
      Abstract constructor for an AbstractElfRelocationHandler.
      Parameters:
      relocationEnumClass - specifies the ElfRelocationType enum which defines all supported relocation types for this relocation handler.
  • Method Details

    • getRelocationType

      public T getRelocationType(int typeId)
      Get the relocation type enum object which corresponds to the specified type ID value.
      Parameters:
      typeId - relocation type ID value
      Returns:
      relocation type enum value or null if type not found or this handler was not constructed with a ElfRelocationType enum class. The returned value may be safely cast to the relocation enum class specified during handler construction.
    • relocate

      protected final RelocationResult relocate(ElfRelocationContext elfRelocationContext, ElfRelocation relocation, Address relocationAddress) throws MemoryAccessException
      Perform relocation fixup.
      Specified by:
      relocate in class ElfRelocationHandler
      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
    • relocate

      protected abstract RelocationResult relocate(C elfRelocationContext, ElfRelocation relocation, T relocationType, Address relocationAddress, ElfSymbol elfSymbol, Address symbolAddr, long symbolValue, String symbolName) throws MemoryAccessException
      Perform relocation fixup.
      NOTE: This method will not be invoked if elfSymbol is null and ElfRelocationContext.processRelocation(ElfRelocation, Address) will report relocation failure.
      NOTE: This method will not be invoked for type == 0/NONE and will be marked as skipped.
      Parameters:
      elfRelocationContext - relocation context
      relocation - ELF relocation
      relocationType - ELF relocation type enum value
      relocationAddress - relocation target address (fixup location)
      elfSymbol - relocation symbol
      symbolAddr - elfSymbol memory address (may be null)
      symbolValue - unadjusted elfSymbol value (0 if no symbol)
      symbolName - elfSymbol name (may be null)
      Returns:
      applied relocation result (conveys status and applied byte-length)
      Throws:
      MemoryAccessException - memory access failure
    • handleUnresolvedSymbol

      protected boolean handleUnresolvedSymbol(ElfRelocationContext<?> elfRelocationContext, ElfRelocation relocation, Address relocationAddress)
      Check for unresolved relocation symbol. If symbol has not been resolved the associated symbol address will be null and the symbol value invalid.
      Parameters:
      elfRelocationContext - relocation context
      relocation - ELF relocation
      relocationAddress - relocation target address (fixup location)
      Returns:
      true if symbol was not resolved else false if symbol was resolved
    • markAsUnsupportedCopy

      protected void markAsUnsupportedCopy(Program program, Address relocationAddress, T relocationType, String symbolName, int symbolIndex, long symbolSize, MessageLog log)
      Generate error log entry and bookmark at relocationAddress indicating an unspportable COPY relocation. A warning is produced for this COPY relocation failure.
      Parameters:
      program - program
      relocationAddress - relocation address to be bookmarked
      relocationType - relocation type
      symbolName - associated symbol name
      symbolIndex - associated symbol index within symbol table
      symbolSize - number of bytes associated with symbol that failed to be copied
      log - import log
    • markAsUndefined

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

      protected void markAsUnhandled(Program program, Address relocationAddress, T relocationType, int 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
      relocationType - relocation type
      symbolIndex - associated symbol index within symbol table
      symbolName - associated symbol name
      log - import log
    • markAsWarning

      protected void markAsWarning(Program program, Address relocationAddress, T relocationType, String symbolName, int symbolIndex, String msg, MessageLog log)
      Generate relocation warning log entry and bookmark at relocationAddress.
      Parameters:
      program - program
      relocationAddress - relocation address to be bookmarked
      relocationType - relocation type
      symbolName - symbol name
      symbolIndex - symbol index (-1 to ignore)
      msg - message associated with warning
      log - import log
    • markAsError

      protected void markAsError(Program program, Address relocationAddress, T relocationType, String symbolName, int symbolIndex, String msg, MessageLog log)
      Generate relocation error log entry and bookmark at relocationAddress.
      Parameters:
      program - program
      relocationAddress - relocation address to be bookmarked
      relocationType - relocation type
      symbolName - associated symbol name
      symbolIndex - symbol index (-1 to ignore)
      msg - additional error message
      log - import log