Package ghidra.app.util.bin.format.elf
Class ElfRelocation
java.lang.Object
ghidra.app.util.bin.format.elf.ElfRelocation
- All Implemented Interfaces:
StructConverter
A class to represent the Elf32_Rel and Elf64_Rel data structure.
typedef uint32_t Elf32_Addr;
typedef uint64_t Elf64_Addr;
typedef uint32_t Elf32_Word;
typedef uint64_t Elf64_Xword;
REL entry:
typedef struct {
Elf32_Addr r_offset;
Elf32_Word r_info;
} Elf32_Rel;
typedef struct {
Elf64_Addr r_offset;
Elf64_Xword r_info;
} Elf64_Rel;
RELA entry with addend:
typedef struct {
Elf32_Addr r_offset;
Elf32_Word r_info;
Elf32_Sword r_addend;
} Elf32_Rela;
typedef struct {
Elf64_Addr r_offset; //Address
Elf64_Xword r_info; //Relocation type and symbol index
Elf64_Sxword r_addend; //Addend
} Elf64_Rela;
RELR entry (see SHT_RELR, DT_RELR):
NOTE: Relocation type is data relative and must be specified by appropriate relocation handler
(see ElfRelocationHandler.getRelrRelocationType()
) since it is not contained within the
relocation table which only specifies r_offset for each entry.
NOTE: instantiation relies on the use of a default constructor which must be
implemented by any extension. An extension should implement the methods
initElfRelocation(BinaryReader, ElfHeader, int, boolean)
and/or
initElfRelocation(ElfHeader, int, boolean, long, long, long)
.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionlong
This member specifies the RELA signed-constant addend used to compute the value to be stored into the relocatable field.long
This member gives the location at which to apply the relocation action.int
long
Returns the r_info relocation entry field valuestatic int
getStandardRelocationEntrySize
(boolean is64bit, boolean hasAddend) Get the standard relocation size when one has notbeen specifiedint
Returns the symbol index where the relocation must be made.int
getType()
The type ID value for this relocation NOTE 1: Relocation types are processor-specific (seeAbstractElfRelocationHandler
).boolean
Returns true if this is a RELA entry with addendprotected void
initElfRelocation
(BinaryReader reader, ElfHeader elfHeader, int relocationTableIndex, boolean withAddend) Initialize ELF relocation entry using data from the binary reader's current position.protected void
initElfRelocation
(ElfHeader elfHeader, int relocationTableIndex, boolean withAddend, long offset, long info, long addend) Initialize ELF relocation entry using data provided via the parameters.protected boolean
is32Bit()
void
setType
(long typeId) Set the relocation type ID associated with this relocation.protected int
sizeof()
Returns a structure datatype representing the contents of the implementor of this interface.toString()
-
Field Details
-
R_OFFSET_COMMENT
- See Also:
-
R_INFO_COMMENT
- See Also:
-
R_ADDEND_COMMENT
- See Also:
-
-
Constructor Details
-
ElfRelocation
public ElfRelocation()Instantiate an uninitialized relocation object.NOTE: This method is intended for use by the various factory methods which should generally be used when building-up a relocation table (see
createElfRelocation(BinaryReader, ElfHeader, int, boolean)
andcreateElfRelocation(ElfHeader, int, boolean, long, long, long)
).
-
-
Method Details
-
initElfRelocation
protected void initElfRelocation(BinaryReader reader, ElfHeader elfHeader, int relocationTableIndex, boolean withAddend) throws IOException Initialize ELF relocation entry using data from the binary reader's current position.- Parameters:
reader
- binary reader positioned to the relocation entry data. If null, a representative instance will be generated with all fields set to 0.elfHeader
- ELF headerrelocationTableIndex
- index of relocation within relocation tablewithAddend
- true if if RELA entry with addend, else false- Throws:
IOException
- if an IO or parse error occurs
-
initElfRelocation
protected void initElfRelocation(ElfHeader elfHeader, int relocationTableIndex, boolean withAddend, long offset, long info, long addend) throws IOException Initialize ELF relocation entry using data provided via the parameters.- Parameters:
elfHeader
- ELF headerrelocationTableIndex
- index of relocation within relocation tablewithAddend
- true if if RELA entry with addend, else falseoffset
- The offset for the entry (r_offset)info
- The info value for the entry (r_info)addend
- The signed-addend (r_addend) for the entry (32-bit addends should be signed-extended to 64-bits)- Throws:
IOException
- if an IO or parse error occurs
-
getRelocationIndex
public int getRelocationIndex()- Returns:
- index of relocation within its corresponding relocation table
-
is32Bit
protected boolean is32Bit()- Returns:
- true if processing a 32-bit header, else 64-bit
-
getOffset
public long getOffset()This member gives the location at which to apply the relocation action. For a relocatable file, the value is the byte offset from the beginning of the section to the storage unit affected by the relocation. For an executable file or a shared object, the value is the virtual address of the storage unit affected by the relocation.- Returns:
- the location at which to apply the relocation
-
getSymbolIndex
public int getSymbolIndex()Returns the symbol index where the relocation must be made. A value of 0 is generally returned when no symbol is relavent to the relocation.- Returns:
- the symbol index
-
getType
public int getType()The type ID value for this relocation NOTE 1: Relocation types are processor-specific (seeAbstractElfRelocationHandler
). NOTE 2: A type ID of 0 is returned by default for RELR relocations and must be updated during relocation processing (seesetType(long)
). The appropriate RELR relocation type can be obtained from the appropriateElfRelocationHandler.getRelrRelocationType()
orElfRelocationContext.getRelrRelocationType()
if available.- Returns:
- type ID for this relocation
-
setType
public void setType(long typeId) Set the relocation type ID associated with this relocation. Updating the relocation type is required for RELR relocations.- Parameters:
typeId
- relocation type ID value for this relocation
-
getRelocationInfo
public long getRelocationInfo()Returns the r_info relocation entry field value- Returns:
- r_info value
-
getAddend
public long getAddend()This member specifies the RELA signed-constant addend used to compute the value to be stored into the relocatable field. This value will be 0 for REL entries which do not supply an addend and may rely on an implicit addend stored at the relocation offset. SeehasAddend()
which is true for RELA / Elf_Rela and false for REL / Elf_Rel relocations.- Returns:
- addend as 64-bit signed constant
-
hasAddend
public boolean hasAddend()Returns true if this is a RELA entry with addend- Returns:
- true if this is a RELA entry with addend
-
toDataType
Description copied from interface:StructConverter
Returns a structure datatype representing the contents of the implementor of this interface.For example, given:
class A { int foo; double bar; }
The return value should be a structure data type with two data type components; an INT and a DOUBLE. The structure should contain field names and, if possible, field comments.
- Specified by:
toDataType
in interfaceStructConverter
- Returns:
- returns a structure datatype representing the implementor of this interface
- See Also:
-
getStandardRelocationEntrySize
public static int getStandardRelocationEntrySize(boolean is64bit, boolean hasAddend) Get the standard relocation size when one has notbeen specified- Parameters:
is64bit
- true if ELF 64-bithasAddend
- true if relocation has addend- Returns:
- size of relocation entry
-
toString
-
sizeof
protected int sizeof()
-