Package ghidra.app.util.bin.format.elf
Class ElfRelocation
- java.lang.Object
-
- ghidra.app.util.bin.format.elf.ElfRelocation
-
- All Implemented Interfaces:
ByteArrayConverter,StructConverter
public class ElfRelocation extends java.lang.Object implements ByteArrayConverter, 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;
-
-
Field Summary
Fields Change Modifier and Type Field Description NEW protected static java.lang.StringR_ADDEND_COMMENTNEW protected static java.lang.StringR_INFO_COMMENTNEW protected static java.lang.StringR_OFFSET_COMMENT
-
Constructor Summary
Constructors Change Constructor Description ElfRelocation()DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
-
Method Summary
All Methods Instance Methods Concrete Methods Change Modifier and Type Method Description longgetAddend()This member specifies a constant addend used to compute the value to be stored into the relocatable field.longgetOffset()This member gives the location at which to apply the relocation action.intgetRelocationIndex()longgetRelocationInfo()Returns the r_info relocation entry field valueintgetSymbolIndex()Returns the symbol index where the relocation must be made.intgetType()The type of relocation to apply.booleanhasAddend()Returns true if this is a RELA entry with addendNEW protected voidinitElfRelocation(FactoryBundledWithBinaryReader reader, ElfHeader elfHeader, int relocationTableIndex, boolean withAddend)Initialize ELF relocation entry using data from the binary reader's current position.NEW protected booleanis32Bit()voidsetOffset(int offset)Sets the relocation offset to the new specified value.voidsetOffset(long offset)Sets the relocation offset to the new specified value.NEW protected intsizeof()byte[]toBytes(DataConverter dc)Returns a byte array representing this implementor of this interface.DataTypetoDataType()Returns a structure datatype representing the contents of the implementor of this interface.java.lang.StringtoString()
-
-
-
Field Detail
-
R_OFFSET_COMMENT NEW
protected static final java.lang.String R_OFFSET_COMMENT
- See Also:
- Constant Field Values
-
R_INFO_COMMENT NEW
protected static final java.lang.String R_INFO_COMMENT
- See Also:
- Constant Field Values
-
R_ADDEND_COMMENT NEW
protected static final java.lang.String R_ADDEND_COMMENT
- See Also:
- Constant Field Values
Constructor Detail
-
ElfRelocation
public ElfRelocation()
DO NOT USE THIS CONSTRUCTOR, USE create*(GenericFactory ...) FACTORY METHODS INSTEAD.
-
-
Method Detail
-
initElfRelocation NEW
protected void initElfRelocation(FactoryBundledWithBinaryReader reader, ElfHeader elfHeader, int relocationTableIndex, boolean withAddend) throws java.io.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:
java.io.IOException
-
getRelocationIndex
public int getRelocationIndex()
- Returns:
- index of relocation within its corresponding relocation table
-
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
-
setOffset
public void setOffset(int offset)
Sets the relocation offset to the new specified value.- Parameters:
offset- the new offset value
-
setOffset
public void setOffset(long offset)
Sets the relocation offset to the new specified value.- Parameters:
offset- the new offset value
-
getSymbolIndex
public int getSymbolIndex()
Returns the symbol index where the relocation must be made.- Returns:
- the symbol index
-
getType
public int getType()
The type of relocation to apply. NOTE: Relocation types are processor-specific.- Returns:
- type of relocation to apply
-
getRelocationInfo
public long getRelocationInfo()
Returns the r_info relocation entry field value- Returns:
- r_info value
-
getAddend
public long getAddend()
This member specifies a 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.- Returns:
- a constant addend
-
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
public DataType toDataType()
Description copied from interface:StructConverterReturns 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:
toDataTypein interfaceStructConverter- Returns:
- returns a structure datatype representing the implementor of this interface
- See Also:
StructureDataType
-
toBytes
public byte[] toBytes(DataConverter dc)
Description copied from interface:ByteArrayConverterReturns a byte array representing this implementor of this interface.- Specified by:
toBytesin interfaceByteArrayConverter- Parameters:
dc- the data converter to use- Returns:
- a byte array representing this object
- See Also:
ByteArrayConverter.toBytes(ghidra.util.DataConverter)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-