Relocations¶
CLE’s loader implements program relocations.
If you would like to add support for more relocations, you can do so by subclassing the Relocation
class and overriding any relevant methods or properties.
Then, add or uncomment the appropriate line in the relocations_table dict at the bottom of the file.
Look at the existing versions for details.
- class cle.backends.relocation.Relocation[source]¶
Bases:
object
A representation of a relocation in a binary file. Smart enough to relocate itself.
- Variables:
owner – The binary this relocation was originaly found in, as a cle object
symbol – The Symbol object this relocation refers to
relative_addr – The address in owner this relocation would like to write to
resolvedby – If the symbol this relocation refers to is an import symbol and that import has been resolved, this attribute holds the symbol from a different binary that was used to resolve the import.
resolved – Whether the application of this relocation was successful
- AUTO_HANDLE_NONE = False¶
- property rebased_addr¶
The address in the global memory space this relocation would like to write to
- property linked_addr¶
- property dest_addr¶
- property value¶
- relocate()[source]¶
Applies this relocation. Will make changes to the memory object of the object it came from.
This implementation is a generic version that can be overridden in subclasses.
- property owner_obj¶
- class cle.backends.elf.relocation.elfreloc.ELFReloc[source]¶
Bases:
Relocation
- property addend¶
- property value¶
- class cle.backends.elf.relocation.generic.GenericTLSDoffsetReloc[source]¶
Bases:
ELFReloc
- property value¶
- class cle.backends.elf.relocation.generic.GenericTLSOffsetReloc[source]¶
Bases:
ELFReloc
- AUTO_HANDLE_NONE = True¶
- class cle.backends.elf.relocation.generic.GenericTLSDescriptorReloc[source]¶
Bases:
ELFReloc
- RESOLVER_ADDR: int = NotImplemented¶
- AUTO_HANDLE_NONE = True¶
- class cle.backends.elf.relocation.generic.GenericTLSModIdReloc[source]¶
Bases:
ELFReloc
- AUTO_HANDLE_NONE = True¶
- class cle.backends.elf.relocation.generic.GenericIRelativeReloc[source]¶
Bases:
ELFReloc
- AUTO_HANDLE_NONE = True¶
- class cle.backends.elf.relocation.generic.GenericAbsoluteAddendReloc[source]¶
Bases:
ELFReloc
- property value¶
- class cle.backends.elf.relocation.generic.GenericPCRelativeAddendReloc[source]¶
Bases:
ELFReloc
- property value¶
- class cle.backends.elf.relocation.generic.GenericJumpslotReloc[source]¶
Bases:
ELFReloc
- property value¶
- class cle.backends.elf.relocation.generic.GenericRelativeReloc[source]¶
Bases:
ELFReloc
- AUTO_HANDLE_NONE = True¶
- property value¶
- class cle.backends.elf.relocation.generic.GenericAbsoluteReloc[source]¶
Bases:
ELFReloc
- property value¶
- class cle.backends.elf.relocation.generic.MipsGlobalReloc[source]¶
Bases:
GenericAbsoluteReloc
- class cle.backends.elf.relocation.generic.MipsLocalReloc[source]¶
Bases:
ELFReloc
- AUTO_HANDLE_NONE = True¶
- class cle.backends.elf.relocation.generic.RelocTruncate32Mixin[source]¶
Bases:
object
A mix-in class for relocations that cover a 32-bit field regardless of the architecture’s address word length.
- check_zero_extend = False¶
- check_sign_extend = False¶
- class cle.backends.elf.relocation.generic.RelocGOTMixin[source]¶
Bases:
object
A mix-in class which will cause the symbol to be resolved to a pointer to the symbol instead of the symbol
Relocation types for PowerPC 32-bit architecture.
Reference: http://refspecs.linux-foundation.org/elf/elfspec_ppc.pdf page 4-18
Only relocations 1-37 are described in the document. The rest are from the GNU binutils source code. See include/elf/ppc.h in the binutils source code.
Relocation types for PPC64.
Reference: http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.pdf pages 57-59
Relocation types for i386.
Reference: https://github.com/hjl-tools/x86-psABI/wiki/intel386-psABI-1.1.pdf page 36
Relocations for amd64/x86_64
Reference: https://gitlab.com/x86-psABIs/x86-64-ABI/-/jobs/artifacts/master/raw/x86-64-ABI/abi.pdf?job=build page 73
Relocation types for MIPS 32-bit.
Reference: https://refspecs.linuxfoundation.org/elf/mipsabi.pdf page 4-19
The main document is old and does not contain all the relocation types. I could not find a more recent document, so I had to rely on the source code of GNU binutils for all relocations that are not in the main document. See include/elf/mips.h in the binutils source code.
Relocation types for ARM.
Reference: https://github.com/ARM-software/abi-aa/blob/main/aaelf32/aaelf32.rst#relocation-codes
Relocations for AARCH64
Reference: https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst#relocation
Relocation types for the S390X architecture.
Reference: https://github.com/IBM/s390x-abi/releases/download/v1.6.1/lzsabi_s390x.pdf pages 51-52
- class cle.backends.pe.relocation.pereloc.PEReloc[source]¶
Bases:
Relocation
- AUTO_HANDLE_NONE = True¶
- relocate()[source]¶
Applies this relocation. Will make changes to the memory object of the object it came from.
This implementation is a generic version that can be overridden in subclasses.
- property value¶
- property is_base_reloc¶
These relocations are ignored by the linker if the executable is loaded at its preferred base address. There is no associated symbol with base relocations.
- property is_import¶
- class cle.backends.pe.relocation.generic.DllImport[source]¶
Bases:
PEReloc
There’s nothing special to be done for DLL imports but this class provides a unique name to the relocation type.
- class cle.backends.pe.relocation.generic.IMAGE_REL_BASED_HIGHADJ[source]¶
Bases:
PEReloc
- property value¶
In all the other cases, we can ignore the relocation difference part of the calculation because we simply use to_mva() to get our rebased address. In this case, however, we have to adjust the un-rebased address first.
- class cle.backends.pe.relocation.generic.IMAGE_REL_BASED_HIGHLOW[source]¶
Bases:
PEReloc
- property value¶
- class cle.backends.pe.relocation.generic.IMAGE_REL_BASED_DIR64[source]¶
Bases:
PEReloc
- property value¶
- class cle.backends.pe.relocation.generic.IMAGE_REL_BASED_HIGH[source]¶
Bases:
PEReloc
- property value¶
- class cle.backends.pe.relocation.generic.IMAGE_REL_BASED_LOW[source]¶
Bases:
PEReloc
- property value¶