Class ElfRelocationContext<H extends ElfRelocationHandler>
java.lang.Object
ghidra.app.util.bin.format.elf.relocation.ElfRelocationContext<H>
- Type Parameters:
H
- ELF relocation handler class
ElfRelocationContext
provides a relocation handler context related
to the processing of entries contained within a specific relocation table.-
Field Summary
Modifier and TypeFieldDescriptionprotected final H
protected final ElfLoadHelper
protected final Program
protected ElfRelocationTable
protected ElfSymbolTable
-
Constructor Summary
ModifierConstructorDescriptionprotected
ElfRelocationContext
(H handler, ElfLoadHelper loadHelper, Map<ElfSymbol, Address> symbolMap) Relocation context for a specific Elf image and relocation table -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
Dispose relocation context when processing of corresponding relocation table is complete.void
Invoked at end of relocation processing for current relocation table.boolean
Determine if addend data must be extractedfinal ElfHeader
long
Returns the appropriate .got section using the DT_PLTGOT value defined in the .dynamic section.long
Get image base addressable word adjustment value to be applied to any pre-linked address values such as those contained with the dynamic table.final ElfLoadAdapter
final ElfLoadHelper
final MessageLog
getLog()
final Program
getRelocationAddress
(Address baseAddress, long relocOffset) Get relocation addressstatic ElfRelocationContext
<?> getRelocationContext
(ElfLoadHelper loadHelper, Map<ElfSymbol, Address> symbolMap) Get a relocation context for a specfic Elf image and relocation tableint
Get the RELR relocation type associated with the underlying relocation handler.final ElfSymbol
getSymbol
(int symbolIndex) Get the Elf symbol which corresponds to the specified index.getSymbolAddress
(ElfSymbol symbol) Get the program address at which the specified Elf symbol was placed.final String
getSymbolName
(int symbolIndex) Get the ELF symbol name which corresponds to the specified index.long
getSymbolValue
(ElfSymbol symbol) Get the adjusted symbol value based upon its placement within the program.final boolean
final boolean
final void
markRelocationError
(Address relocationAddress, int typeId, int symbolIndex, String symbolName, String msg) Generate relocation error log entry and bookmark.protected RelocationResult
processRelocation
(ElfRelocation relocation, ElfSymbol elfSymbol, Address relocationAddress) Process a relocation from the relocation table which corresponds to this context after preliminary checks have been performed and ELF symbol resolved.final RelocationResult
processRelocation
(ElfRelocation relocation, Address relocationAddress) Process a relocation from the relocation table which corresponds to this context.void
startRelocationTableProcessing
(ElfRelocationTable relocTable) Invoked at start of relocation processing for specified table.
-
Field Details
-
handler
-
loadHelper
-
symbolMap
-
program
-
relocationTable
-
symbolTable
-
-
Constructor Details
-
ElfRelocationContext
protected ElfRelocationContext(H handler, ElfLoadHelper loadHelper, Map<ElfSymbol, Address> symbolMap) Relocation context for a specific Elf image and relocation table- Parameters:
handler
- relocation handler or null if not availableloadHelper
- the elf load helpersymbolMap
- Elf symbol placement map
-
-
Method Details
-
startRelocationTableProcessing
Invoked at start of relocation processing for specified table. The methodendRelocationTableProcessing()
will be invoked after last relocation is processed.- Parameters:
relocTable
- relocation table
-
endRelocationTableProcessing
public void endRelocationTableProcessing()Invoked at end of relocation processing for current relocation table. SeestartRelocationTableProcessing(ElfRelocationTable)
. -
processRelocation
public final RelocationResult processRelocation(ElfRelocation relocation, Address relocationAddress) Process a relocation from the relocation table which corresponds to this context. All relocation entries will be processed in the order they appear within the table.- Parameters:
relocation
- relocation to be processedrelocationAddress
- relocation address where it should be applied- Returns:
- applied relocation result
-
processRelocation
protected RelocationResult processRelocation(ElfRelocation relocation, ElfSymbol elfSymbol, Address relocationAddress) throws MemoryAccessException, NotFoundException Process a relocation from the relocation table which corresponds to this context after preliminary checks have been performed and ELF symbol resolved. All relocation entries will be processed in the order they appear within the table.- Parameters:
relocation
- relocation to be processedelfSymbol
- resolved ELF symbol (not null)relocationAddress
- relocation address where it should be applied- Returns:
- applied relocation result
- Throws:
MemoryAccessException
- if a memory access error occursNotFoundException
- NOTE: use of this exception is deprecated and should not be thrown
-
markRelocationError
public final void markRelocationError(Address relocationAddress, int typeId, int symbolIndex, String symbolName, String msg) Generate relocation error log entry and bookmark.- Parameters:
relocationAddress
- relocation addresstypeId
- relocation type ID value (will get mapped toElfRelocationType.name()
if possible).symbolIndex
- associated symbol index within symbol table (-1 to ignore)symbolName
- relocation symbol name or null if unknownmsg
- error message
-
getRelrRelocationType
public int getRelrRelocationType()Get the RELR relocation type associated with the underlying relocation handler.- Returns:
- RELR relocation type or 0 if not supported
-
getRelocationContext
public static ElfRelocationContext<?> getRelocationContext(ElfLoadHelper loadHelper, Map<ElfSymbol, Address> symbolMap) Get a relocation context for a specfic Elf image and relocation table- Parameters:
loadHelper
- Elf load helpersymbolMap
- Elf symbol placement map- Returns:
- relocation context object. A generic context will be returned if a custom one is not defined.
-
hasRelocationHandler
public final boolean hasRelocationHandler()- Returns:
- true if a relocation handler was found
-
getImageBaseWordAdjustmentOffset
public long getImageBaseWordAdjustmentOffset()Get image base addressable word adjustment value to be applied to any pre-linked address values such as those contained with the dynamic table. (Applies to default address space only)- Returns:
- image base adjustment value
-
extractAddend
public boolean extractAddend()Determine if addend data must be extracted- Returns:
- true if relocation does not provide addend data and it must be extracted from relocation target if appropriate
-
getProgram
-
isBigEndian
public final boolean isBigEndian() -
getElfHeader
-
getLoadHelper
-
getLoadAdapter
-
getLog
-
getSymbol
Get the Elf symbol which corresponds to the specified index. Each relocation table may correspond to a specific symbol table to which the specified symbolIndex will be applied. In the absense of a corresponding symbol table index 0 will return a special null symbol.- Parameters:
symbolIndex
- symbol index- Returns:
- Elf symbol which corresponds to symbol index or null if out of range
-
getSymbolName
Get the ELF symbol name which corresponds to the specified index.- Parameters:
symbolIndex
- symbol index- Returns:
- symbol name which corresponds to symbol index or null if out of range
-
getSymbolAddress
Get the program address at which the specified Elf symbol was placed.- Parameters:
symbol
- Elf symbol- Returns:
- program address
-
getSymbolValue
Get the adjusted symbol value based upon its placement within the program. This value may differ from symbol.getValue() and will reflect the addressable unit/word offset of it program address.- Parameters:
symbol
- Elf symbol- Returns:
- adjusted Elf symbol value or 0 if symbol mapping not found
-
getGOTValue
Returns the appropriate .got section using the DT_PLTGOT value defined in the .dynamic section. If no such dynamic value defined, the symbol offset for _GLOBAL_OFFSET_TABLE_ will be used, otherwise a NotFoundException will be thrown.- Returns:
- the .got section address offset
- Throws:
NotFoundException
- if the dynamic DT_PLTGOT not defined and _GLOBAL_OFFSET_TABLE_ symbol not defined
-
dispose
public void dispose()Dispose relocation context when processing of corresponding relocation table is complete. Instance should be disposed to allow all program changes to be flushed prior to processing a subsequent relocation table. -
getRelocationAddress
Get relocation address- Parameters:
baseAddress
- base addressrelocOffset
- relocation offset relative to baseAddress- Returns:
- relocation address
-