From 0f81a9ecab1208910e67ccee6800983025b417c2 Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Fri, 9 Aug 2024 16:28:51 -0700 Subject: [PATCH 1/7] Refactor relocation loading to use static dicts --- cle/backends/elf/relocation/__init__.py | 63 ++++---- cle/backends/elf/relocation/amd64.py | 56 +++++++- cle/backends/elf/relocation/arm.py | 132 +++++++++++++++++ cle/backends/elf/relocation/arm64.py | 136 ++++++++++++++++++ cle/backends/elf/relocation/arm_cortex_m.py | 54 ------- cle/backends/elf/relocation/armel.py | 58 -------- cle/backends/elf/relocation/armhf.py | 58 -------- cle/backends/elf/relocation/i386.py | 49 +++++++ cle/backends/elf/relocation/mips.py | 99 +++++++++++++ cle/backends/elf/relocation/mips64.py | 36 ----- cle/backends/elf/relocation/ppc.py | 49 ++++++- .../elf/relocation/{pcc64.py => ppc64.py} | 118 ++++++++++++++- cle/backends/elf/relocation/s390x.py | 74 ++++++++++ cle/backends/elf/relocation/sparc.py | 34 ++++- 14 files changed, 765 insertions(+), 251 deletions(-) delete mode 100644 cle/backends/elf/relocation/arm_cortex_m.py delete mode 100644 cle/backends/elf/relocation/armel.py delete mode 100644 cle/backends/elf/relocation/armhf.py delete mode 100644 cle/backends/elf/relocation/mips64.py rename cle/backends/elf/relocation/{pcc64.py => ppc64.py} (57%) diff --git a/cle/backends/elf/relocation/__init__.py b/cle/backends/elf/relocation/__init__.py index d3ca5bb2..aae19835 100644 --- a/cle/backends/elf/relocation/__init__.py +++ b/cle/backends/elf/relocation/__init__.py @@ -1,44 +1,36 @@ from __future__ import annotations -import importlib import logging -import os -from collections import defaultdict -import archinfo +from .amd64 import relocation_table_amd64 +from .arm import relocation_table_arm +from .arm64 import relocation_table_arm64 +from .i386 import relocation_table_i386 +from .mips import relocation_table_mips +from .ppc import relocation_table_ppc +from .ppc64 import relocation_table_ppc64 +from .s390x import relocation_table_s390x +from .sparc import relocation_table_sparc + +ALL_RELOCATIONS = { + "AMD64": relocation_table_amd64, + "ARMCortexM": relocation_table_arm, + "ARM": relocation_table_arm, + "AARCH64": relocation_table_arm64, + "ARMEL": relocation_table_arm, + "ARMHF": relocation_table_arm, + "X86": relocation_table_i386, + "MIPS32": relocation_table_mips, + "MIPS64": relocation_table_mips, + "PPC32": relocation_table_ppc, + "PPC64": relocation_table_ppc64, + "S390X": relocation_table_s390x, + "SPARC": relocation_table_sparc, +} -from cle.backends.relocation import Relocation -ALL_RELOCATIONS = defaultdict(dict) -complaint_log = set() - -path = os.path.dirname(os.path.abspath(__file__)) log = logging.getLogger(name=__name__) - - -def load_relocations(): - for filename in os.listdir(path): - if not filename.endswith(".py"): - continue - if filename == "__init__.py": - continue - - log.debug("Importing ELF relocation module: %s", filename[:-3]) - module = importlib.import_module(f".{filename[:-3]}", "cle.backends.elf.relocation") - - try: - arch_name = module.arch - except AttributeError: - continue - - for item_name in dir(module): - if item_name not in archinfo.defines: - continue - item = getattr(module, item_name) - if not isinstance(item, type) or not issubclass(item, Relocation): - continue - - ALL_RELOCATIONS[arch_name][archinfo.defines[item_name]] = item +complaint_log = set() def get_relocation(arch, r_type): @@ -51,6 +43,3 @@ def get_relocation(arch, r_type): complaint_log.add((arch, r_type)) log.warning("Unknown reloc %d on %s", r_type, arch) return None - - -load_relocations() diff --git a/cle/backends/elf/relocation/amd64.py b/cle/backends/elf/relocation/amd64.py index 26e34fce..d28add10 100644 --- a/cle/backends/elf/relocation/amd64.py +++ b/cle/backends/elf/relocation/amd64.py @@ -1,3 +1,8 @@ +"""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 +""" + from __future__ import annotations from .generic import ( @@ -14,8 +19,6 @@ RelocTruncate32Mixin, ) -arch = "AMD64" - class R_X86_64_64(GenericAbsoluteAddendReloc): pass @@ -79,3 +82,52 @@ class R_X86_64_GOTPCRELX(RelocGOTMixin, RelocTruncate32Mixin, GenericPCRelativeA class R_X86_64_REX_GOTPCRELX(RelocGOTMixin, RelocTruncate32Mixin, GenericPCRelativeAddendReloc): check_sign_extend = True + + +relocation_table_amd64 = { + 1: R_X86_64_64, + 2: R_X86_64_PC32, + # 3: R_X86_64_GOT32, + 4: R_X86_64_PLT32, + 5: R_X86_64_COPY, + 6: R_X86_64_GLOB_DAT, + 7: R_X86_64_JUMP_SLOT, + 8: R_X86_64_RELATIVE, + 9: R_X86_64_GOTPCREL, + 10: R_X86_64_32, + 11: R_X86_64_32S, + # 12: R_X86_64_16, + # 13: R_X86_64_PC16, + # 14: R_X86_64_8, + # 15: R_X86_64_PC8, + 16: R_X86_64_DTPMOD64, + 17: R_X86_64_DTPOFF64, + 18: R_X86_64_TPOFF64, + # 19: R_X86_64_TLSGD, + # 20: R_X86_64_TLSLD, + # 21: R_X86_64_DTPOFF32, + # 22: R_X86_64_GOTTPOFF, + # 23: R_X86_64_TPOFF32, + # 24: R_X86_64_PC64, + # 25: R_X86_64_GOTOFF64, + # 26: R_X86_64_GOTPC32, + # 32: R_X86_64_SIZE32, + # 33: R_X86_64_SIZE64, + # 34: R_X86_64_GOTPC32_TLSDESC, + # 35: R_X86_64_TLSDESC_CALL, + # 36: R_X86_64_TLSDESC, + 37: R_X86_64_IRELATIVE, + # 38: R_X86_64_RELATIVE64, + # 39, 40: Deprecated + 41: R_X86_64_GOTPCRELX, + 42: R_X86_64_REX_GOTPCRELX, + # 43: R_X86_64_CODE_4_GOTPCRELX, + # 44: R_X86_64_CODE_4_GOTTPOFF, + # 45: R_X86_64_CODE_4_GOTPC32_TLSDESC, + # 46: R_X86_64_CODE_5_GOTPCRELX, + # 47: R_X86_64_CODE_5_GOTTPOFF, + # 48: R_X86_64_CODE_5_GOTPC32_TLSDESC, + # 49: R_X86_64_CODE_6_GOTPCRELX, + # 50: R_X86_64_CODE_6_GOTTPOFF, + # 51: R_X86_64_CODE_6_GOTPC32_TLSDESC, +} diff --git a/cle/backends/elf/relocation/arm.py b/cle/backends/elf/relocation/arm.py index 2bbfc4fd..e20d306e 100644 --- a/cle/backends/elf/relocation/arm.py +++ b/cle/backends/elf/relocation/arm.py @@ -1,3 +1,8 @@ +"""Relocation types for ARM. + +Reference: https://github.com/ARM-software/abi-aa/blob/main/aaelf32/aaelf32.rst#relocation-codes +""" + from __future__ import annotations import logging @@ -518,6 +523,133 @@ class R_ARM_GOT_PREL(GenericPCRelativeAddendReloc, RelocTruncate32Mixin, RelocGO """ +relocation_table_arm = { + 1: R_ARM_PC24, + 2: R_ARM_ABS32, + 3: R_ARM_REL32, + # 4: ARM_LDR_PC_G0, + # 5: R_ARM_ABS16, + # 6: R_ARM_ABS12, + # 7: R_ARM_THM_ABS5, + # 8: R_ARM_ABS8, + # 9: R_ARM_SBREL32, + 10: R_ARM_THM_CALL, + # 11: R_ARM_THM_PC8, + # 12: R_ARM_BREL_ADJ, + # 13: R_ARM_TLS_DESC, + # 14: R_ARM_THM_SWI8, + # 15: R_ARM_XPC25, + # 16: R_ARM_THM_XPC22, + 17: R_ARM_TLS_DTPMOD32, + 18: R_ARM_TLS_DTPOFF32, + 19: R_ARM_TLS_TPOFF32, + 20: R_ARM_COPY, + 21: R_ARM_GLOB_DAT, + 22: R_ARM_JUMP_SLOT, + 23: R_ARM_RELATIVE, + # 24: R_ARM_GOTOFF, + # 25: R_ARM_BASE_PREL, + # 26: R_ARM_GOT_BREL, + # 27: R_ARM_PLT32, + 28: R_ARM_CALL, + 29: R_ARM_JUMP24, + 30: R_ARM_THM_JUMP24, + # 31: R_ARM_BASE_ABS, + # 32: R_ARM_ALU_PCREL_7_0, + # 33: R_ARM_ALU_PCREL_15_8, + # 34: R_ARM_ALU_PCREL_23_15, + # 35: R_ARM_LDR_SBREL_11_0_NC, + # 36: R_ARM_ALU_SBREL_19_12_NC, + # 37: R_ARM_ALU_SBREL_27_20_CK, + # 38: R_ARM_TARGET1, + # 39: R_ARM_SBREL31, + # 40: R_ARM_V4BX, + # 41: R_ARM_TARGET2, + 42: R_ARM_PREL31, + 43: R_ARM_MOVW_ABS_NC, + 44: R_ARM_MOVT_ABS, + # 45: R_ARM_MOVW_PREL_NC, + # 46: R_ARM_MOVT_PREL, + 47: R_ARM_THM_MOVW_ABS_NC, + 48: R_ARM_THM_MOVT_ABS, + # 49: R_ARM_THM_MOVW_PREL_NC, + # 50: R_ARM_THM_MOVT_PREL, + 51: R_ARM_THM_JUMP19, + 52: R_ARM_THM_JUMP6, + # 53: R_ARM_THM_ALU_PREL_11_0, + # 54: R_ARM_THM_PC12, + 55: R_ARM_ABS32_NOI, + 56: R_ARM_REL32_NOI, + # 57: R_ARM_ALU_PC_G0_NC, + # 58: R_ARM_ALU_PC_G0, + # 59: R_ARM_ALU_PC_G1_NC, + # 60: R_ARM_ALU_PC_G1, + # 61: R_ARM_ALU_PC_G2, + # 62: R_ARM_LDR_PC_G1, + # 63: R_ARM_LDR_PC_G2, + # 64: R_ARM_LDRS_PC_G0, + # 65: R_ARM_LDRS_PC_G1, + # 66: R_ARM_LDRS_PC_G2, + # 67: R_ARM_LDC_PC_G0, + # 68: R_ARM_LDC_PC_G1, + # 69: R_ARM_LDC_PC_G2, + # 70: R_ARM_ALU_SB_G0_NC, + # 71: R_ARM_ALU_SB_G0, + # 72: R_ARM_ALU_SB_G1_NC, + # 73: R_ARM_ALU_SB_G1, + # 74: R_ARM_ALU_SB_G2, + # 75: R_ARM_LDR_SB_G0, + # 76: R_ARM_LDR_SB_G1, + # 77: R_ARM_LDR_SB_G2, + # 78: R_ARM_LDRS_SB_G0, + # 79: R_ARM_LDRS_SB_G1, + # 80: R_ARM_LDRS_SB_G2, + # 81: R_ARM_LDC_SB_G0, + # 82: R_ARM_LDC_SB_G1, + # 83: R_ARM_LDC_SB_G2, + # 84: R_ARM_MOVW_BREL_NC, + # 85: R_ARM_MOVT_BREL, + # 86: R_ARM_MOVW_BREL, + # 87: R_ARM_THM_MOVW_BREL_NC, + # 88: R_ARM_THM_MOVT_BREL, + # 89: R_ARM_THM_MOVW_BREL, + # 90: R_ARM_TLS_GOTDESC, + # 91: R_ARM_TLS_CALL, + # 92: R_ARM_TLS_DESCSEQ, + # 93: R_ARM_THM_TLS_CALL, + # 94: R_ARM_PLT32_ABS, + # 95: R_ARM_GOT_ABS, + 96: R_ARM_GOT_PREL, + # 97: R_ARM_GOT_BREL12, + # 98: R_ARM_GOTOFF12, + # 99: R_ARM_GOTRELAX, + # 100: R_ARM_GNU_VTENTRY, + # 101: R_ARM_GNU_VTINHERIT, + # 102: R_ARM_JUMP11, + # 103: R_ARM_THM_PC9, + # 104: R_ARM_TLS_GD32, + # 105: R_ARM_TLS_LDM32, + # 106: R_ARM_TLS_LDO32, + # 107: R_ARM_TLS_IE32, + # 108: R_ARM_TLS_LE32, + # 109: R_ARM_TLS_LDO12, + # 110: R_ARM_TLS_LE12, + # 111: R_ARM_TLS_IE12GP, + # 112-127: R_ARM_PRIVATE_ + # 128: R_ARM_ME_TOO, + # 129: R_ARM_THM_TLS_DESCSEQ16, + # 130: R_ARM_THM_TLS_DESCSEQ32, + # 131: R_ARM_THM_GOT_BREL12, + # 132: R_ARM_THM_ALU_ABS_G0_NC, + # 133: R_ARM_THM_ALU_ABS_G1_NC, + # 134: R_ARM_THM_ALU_ABS_G2_NC, + # 135: R_ARM_THM_ALU_ABS_G3, + # 136: R_ARM_THM_BF16, + # 137: R_ARM_THM_BF12, + # 138: R_ARM_THM_BF18, +} + + __all__ = [ "arch", "R_ARM_CALL", diff --git a/cle/backends/elf/relocation/arm64.py b/cle/backends/elf/relocation/arm64.py index ef15576c..ff1d1957 100644 --- a/cle/backends/elf/relocation/arm64.py +++ b/cle/backends/elf/relocation/arm64.py @@ -1,3 +1,8 @@ +"""Relocations for AARCH64 + +Reference: https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst#relocation +""" + from __future__ import annotations import logging @@ -267,3 +272,134 @@ def relocate(self): imm = (self.value & 0b1111_1111_1111) >> 4 self.owner.memory.pack_word(self.relative_addr, instr | (imm << 10), size=4) return True + + +relocation_table_arm64 = { + 257: R_AARCH64_ABS64, + 258: R_AARCH64_COPY, + # 259: R_AARCH64_ABS16, + # 260: R_AARCH64_PREL64, + 261: R_AARCH64_PREL32, + # 262: R_AARCH64_PREL16, + # 263: R_AARCH64_MOVW_UABS_G0, + # 264: R_AARCH64_MOVW_UABS_G0_NC, + # 265: R_AARCH64_MOVW_UABS_G1, + # 266: R_AARCH64_MOVW_UABS_G1_NC, + # 267: R_AARCH64_MOVW_UABS_G2, + # 268: R_AARCH64_MOVW_UABS_G2_NC, + # 269: R_AARCH64_MOVW_UABS_G3, + # 270: R_AARCH64_MOVW_SABS_G0, + # 271: R_AARCH64_MOVW_SABS_G1, + # 272: R_AARCH64_MOVW_SABS_G2, + # 273: R_AARCH64_LD_PREL_LO19, + # 274: R_AARCH64_ADR_PREL_LO21, + 275: R_AARCH64_ADR_PREL_PG_HI21, + # 276: R_AARCH64_ADR_PREL_PG_HI21_NC, + 277: R_AARCH64_ADD_ABS_LO12_NC, + 278: R_AARCH64_LDST8_ABS_LO12_NC, + # 279: R_AARCH64_TSTBR14, + # 280: R_AARCH64_CONDBR19, + 282: R_AARCH64_JUMP26, + 283: R_AARCH64_CALL26, + 284: R_AARCH64_LDST16_ABS_LO12_NC, + 285: R_AARCH64_LDST32_ABS_LO12_NC, + 286: R_AARCH64_LDST64_ABS_LO12_NC, + # 287: R_AARCH64_MOVW_PREL_G0, + # 288: R_AARCH64_MOVW_PREL_G0_NC, + # 289: R_AARCH64_MOVW_PREL_G1, + # 290: R_AARCH64_MOVW_PREL_G1_NC, + # 291: R_AARCH64_MOVW_PREL_G2, + # 292: R_AARCH64_MOVW_PREL_G2_NC, + # 293: R_AARCH64_MOVW_PREL_G3, + 299: R_AARCH64_LDST128_ABS_LO12_NC, + # 300: R_AARCH64_MOVW_GOTOFF_G0, + # 301: R_AARCH64_MOVW_GOTOFF_G0_NC, + # 302: R_AARCH64_MOVW_GOTOFF_G1, + # 303: R_AARCH64_MOVW_GOTOFF_G1_NC, + # 304: R_AARCH64_MOVW_GOTOFF_G2, + # 305: R_AARCH64_MOVW_GOTOFF_G2_NC, + # 306: R_AARCH64_MOVW_GOTOFF_G3, + # 307: R_AARCH64_GOTREL64, + # 308: R_AARCH64_GOTREL32, + # 309: R_AARCH64_GOT_LD_PREL19, + # 310: R_AARCH64_LD64_GOTOFF_LO15, + # 311: R_AARCH64_ADR_GOT_PAGE, + # 312: R_AARCH64_LD64_GOT_LO12_NC, + # 313: R_AARCH64_LD64_GOTPAGE_LO15, + # 314: R_AARCH64_PLT32, + # 315: R_AARCH64_GOTPCREL32, + # 512: R_AARCH64_TLSGD_ADR_PREL21, + # 513: R_AARCH64_TLSGD_ADR_PAGE21, + # 514: R_AARCH64_TLSGD_ADD_LO12_NC, + # 515: R_AARCH64_TLSGD_MOVW_G1, + # 516: R_AARCH64_TLSGD_MOVW_G0_NC, + # 517: R_AARCH64_TLSLD_ADR_PREL21, + # 518: R_AARCH64_TLSLD_ADR_PAGE21, + # 519: R_AARCH64_TLSLD_ADD_LO12_NC, + # 520: R_AARCH64_TLSLD_MOVW_G1, + # 521: R_AARCH64_TLSLD_MOVW_G0_NC, + # 522: R_AARCH64_TLSLD_LD_PREL19, + # 523: R_AARCH64_TLSLD_MOVW_DTPREL_G2, + # 524: R_AARCH64_TLSLD_MOVW_DTPREL_G1, + # 525: R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC, + # 526: R_AARCH64_TLSLD_MOVW_DTPREL_G0, + # 527: R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC, + # 528: R_AARCH64_TLSLD_ADD_DTPREL_HI12, + # 529: R_AARCH64_TLSLD_ADD_DTPREL_LO12, + # 530: R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC, + # 531: R_AARCH64_TLSLD_LDST8_DTPREL_LO12, + # 532: R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC, + # 533: R_AARCH64_TLSLD_LDST16_DTPREL_LO12, + # 534: R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC, + # 535: R_AARCH64_TLSLD_LDST32_DTPREL_LO12, + # 536: R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC, + # 537: R_AARCH64_TLSLD_LDST64_DTPREL_LO12, + # 538: R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC, + # 539: R_AARCH64_TLSIE_MOVW_GOTTPREL_G1, + # 540: R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC, + # 541: R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21, + # 542: R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC, + # 543: R_AARCH64_TLSIE_LD_GOTTPREL_PREL19, + # 544: R_AARCH64_TLSLE_MOVW_TPREL_G2, + # 545: R_AARCH64_TLSLE_MOVW_TPREL_G1, + # 546: R_AARCH64_TLSLE_MOVW_TPREL_G1_NC, + # 547: R_AARCH64_TLSLE_MOVW_TPREL_G0, + # 548: R_AARCH64_TLSLE_MOVW_TPREL_G0_NC, + # 549: R_AARCH64_TLSLE_ADD_TPREL_HI12, + # 550: R_AARCH64_TLSLE_ADD_TPREL_LO12, + # 551: R_AARCH64_TLSLE_ADD_TPREL_LO12_NC, + # 552: R_AARCH64_TLSLE_LDST8_TPREL_LO12, + # 553: R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC, + # 554: R_AARCH64_TLSLE_LDST16_TPREL_LO12, + # 555: R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC, + # 556: R_AARCH64_TLSLE_LDST32_TPREL_LO12, + # 557: R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC, + # 558: R_AARCH64_TLSLE_LDST64_TPREL_LO12, + # 559: R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC, + # 560: R_AARCH64_TLSDESC_LD_PREL19, + # 561: R_AARCH64_TLSDESC_ADR_PREL21, + # 562: R_AARCH64_TLSDESC_ADR_PAGE21, + # 563: R_AARCH64_TLSDESC_LD64_LO12, + # 564: R_AARCH64_TLSDESC_ADD_LO12, + # 565: R_AARCH64_TLSDESC_OFF_G1, + # 566: R_AARCH64_TLSDESC_OFF_G0_NC, + # 567: R_AARCH64_TLSDESC_LDR, + # 568: R_AARCH64_TLSDESC_ADD, + # 569: R_AARCH64_TLSDESC_CALL, + # 570: R_AARCH64_TLSLE_LDST128_TPREL_LO12, + # 571: R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC, + # 572: R_AARCH64_TLSLD_LDST128_DTPREL_LO12, + # 573: R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC, + # 580: R_AARCH64_AUTH_ABS64, + 1024: R_AARCH64_COPY, + 1025: R_AARCH64_GLOB_DAT, + 1026: R_AARCH64_JUMP_SLOT, + 1027: R_AARCH64_RELATIVE, + 1028: R_AARCH64_TLS_DTPMOD, # R_AARCH64_TLS_IMPDEF1 + 1029: R_AARCH64_TLS_DTPREL, # R_AARCH64_TLS_IMPDEF2 + 1030: R_AARCH64_TLS_TPREL, + 1031: R_AARCH64_TLSDESC, + 1032: R_AARCH64_IRELATIVE, + # 1040: R_AARCH64_AUTH_ABS64, + # 1041: R_AARCH64_AUTHELATIVE, +} diff --git a/cle/backends/elf/relocation/arm_cortex_m.py b/cle/backends/elf/relocation/arm_cortex_m.py deleted file mode 100644 index 1d2ddfbc..00000000 --- a/cle/backends/elf/relocation/arm_cortex_m.py +++ /dev/null @@ -1,54 +0,0 @@ -from __future__ import annotations - -from .arm import ( - R_ARM_ABS32, - R_ARM_ABS32_NOI, - R_ARM_CALL, - R_ARM_COPY, - R_ARM_GLOB_DAT, - R_ARM_JUMP24, - R_ARM_JUMP_SLOT, - R_ARM_MOVT_ABS, - R_ARM_MOVW_ABS_NC, - R_ARM_PC24, - R_ARM_PREL31, - R_ARM_REL32, - R_ARM_REL32_NOI, - R_ARM_RELATIVE, - R_ARM_THM_CALL, - R_ARM_THM_JUMP6, - R_ARM_THM_JUMP19, - R_ARM_THM_JUMP24, - R_ARM_THM_MOVT_ABS, - R_ARM_THM_MOVW_ABS_NC, - R_ARM_TLS_DTPOFF32, - R_ARM_TLS_TPOFF32, -) - -arch = "ARMCortexM" - -__all__ = [ - "arch", - "R_ARM_CALL", - "R_ARM_PREL31", - "R_ARM_REL32", - "R_ARM_ABS32", - "R_ARM_MOVW_ABS_NC", - "R_ARM_MOVT_ABS", - "R_ARM_THM_CALL", - "R_ARM_COPY", - "R_ARM_GLOB_DAT", - "R_ARM_JUMP_SLOT", - "R_ARM_RELATIVE", - "R_ARM_ABS32_NOI", - "R_ARM_REL32_NOI", - "R_ARM_TLS_DTPOFF32", - "R_ARM_TLS_TPOFF32", - "R_ARM_JUMP24", - "R_ARM_PC24", - "R_ARM_THM_JUMP24", - "R_ARM_THM_JUMP19", - "R_ARM_THM_JUMP6", - "R_ARM_THM_MOVW_ABS_NC", - "R_ARM_THM_MOVT_ABS", -] diff --git a/cle/backends/elf/relocation/armel.py b/cle/backends/elf/relocation/armel.py deleted file mode 100644 index 0ec6c173..00000000 --- a/cle/backends/elf/relocation/armel.py +++ /dev/null @@ -1,58 +0,0 @@ -from __future__ import annotations - -from .arm import ( - R_ARM_ABS32, - R_ARM_ABS32_NOI, - R_ARM_CALL, - R_ARM_COPY, - R_ARM_GLOB_DAT, - R_ARM_GOT_PREL, - R_ARM_JUMP24, - R_ARM_JUMP_SLOT, - R_ARM_MOVT_ABS, - R_ARM_MOVW_ABS_NC, - R_ARM_PC24, - R_ARM_PREL31, - R_ARM_REL32, - R_ARM_REL32_NOI, - R_ARM_RELATIVE, - R_ARM_THM_CALL, - R_ARM_THM_JUMP6, - R_ARM_THM_JUMP19, - R_ARM_THM_JUMP24, - R_ARM_THM_MOVT_ABS, - R_ARM_THM_MOVW_ABS_NC, - R_ARM_TLS_DTPMOD32, - R_ARM_TLS_DTPOFF32, - R_ARM_TLS_TPOFF32, -) - -arch = "ARMEL" - -__all__ = [ - "arch", - "R_ARM_CALL", - "R_ARM_PREL31", - "R_ARM_REL32", - "R_ARM_ABS32", - "R_ARM_MOVW_ABS_NC", - "R_ARM_MOVT_ABS", - "R_ARM_THM_CALL", - "R_ARM_COPY", - "R_ARM_GLOB_DAT", - "R_ARM_GOT_PREL", - "R_ARM_JUMP_SLOT", - "R_ARM_RELATIVE", - "R_ARM_ABS32_NOI", - "R_ARM_REL32_NOI", - "R_ARM_TLS_DTPMOD32", - "R_ARM_TLS_DTPOFF32", - "R_ARM_TLS_TPOFF32", - "R_ARM_JUMP24", - "R_ARM_PC24", - "R_ARM_THM_JUMP24", - "R_ARM_THM_JUMP19", - "R_ARM_THM_JUMP6", - "R_ARM_THM_MOVW_ABS_NC", - "R_ARM_THM_MOVT_ABS", -] diff --git a/cle/backends/elf/relocation/armhf.py b/cle/backends/elf/relocation/armhf.py deleted file mode 100644 index 89100c8b..00000000 --- a/cle/backends/elf/relocation/armhf.py +++ /dev/null @@ -1,58 +0,0 @@ -from __future__ import annotations - -from .arm import ( - R_ARM_ABS32, - R_ARM_ABS32_NOI, - R_ARM_CALL, - R_ARM_COPY, - R_ARM_GLOB_DAT, - R_ARM_GOT_PREL, - R_ARM_JUMP24, - R_ARM_JUMP_SLOT, - R_ARM_MOVT_ABS, - R_ARM_MOVW_ABS_NC, - R_ARM_PC24, - R_ARM_PREL31, - R_ARM_REL32, - R_ARM_REL32_NOI, - R_ARM_RELATIVE, - R_ARM_THM_CALL, - R_ARM_THM_JUMP6, - R_ARM_THM_JUMP19, - R_ARM_THM_JUMP24, - R_ARM_THM_MOVT_ABS, - R_ARM_THM_MOVW_ABS_NC, - R_ARM_TLS_DTPMOD32, - R_ARM_TLS_DTPOFF32, - R_ARM_TLS_TPOFF32, -) - -arch = "ARMHF" - -__all__ = [ - "arch", - "R_ARM_CALL", - "R_ARM_PREL31", - "R_ARM_REL32", - "R_ARM_ABS32", - "R_ARM_MOVW_ABS_NC", - "R_ARM_MOVT_ABS", - "R_ARM_THM_CALL", - "R_ARM_COPY", - "R_ARM_GLOB_DAT", - "R_ARM_GOT_PREL", - "R_ARM_JUMP_SLOT", - "R_ARM_RELATIVE", - "R_ARM_ABS32_NOI", - "R_ARM_REL32_NOI", - "R_ARM_TLS_DTPMOD32", - "R_ARM_TLS_DTPOFF32", - "R_ARM_TLS_TPOFF32", - "R_ARM_JUMP24", - "R_ARM_PC24", - "R_ARM_THM_JUMP24", - "R_ARM_THM_JUMP19", - "R_ARM_THM_JUMP6", - "R_ARM_THM_MOVW_ABS_NC", - "R_ARM_THM_MOVT_ABS", -] diff --git a/cle/backends/elf/relocation/i386.py b/cle/backends/elf/relocation/i386.py index 2c385738..36ced228 100644 --- a/cle/backends/elf/relocation/i386.py +++ b/cle/backends/elf/relocation/i386.py @@ -1,3 +1,8 @@ +"""Relocation types for i386. + +Reference: https://github.com/hjl-tools/x86-psABI/wiki/intel386-psABI-1.1.pdf page 36 +""" + from __future__ import annotations from .generic import ( @@ -110,3 +115,47 @@ class R_386_GOTPC(GenericPCRelativeAddendReloc, RelocGOTMixin): Field: word32 Calculation: GOT + A - P """ + + +relocation_table_i386 = { + 1: R_386_32, + 2: R_386_PC32, + # 3: R_386_GOT32, + 4: R_386_PLT32, + 5: R_386_COPY, + 6: R_386_GLOB_DAT, + 7: R_386_JMP_SLOT, + 8: R_386_RELATIVE, + # 9: R_386_GOTOFF, + 10: R_386_GOTPC, + 14: R_386_TLS_TPOFF, + # 15: R_386_TLS_IE, + # 16: R_386_TLS_GOTIE, + # 17: R_386_TLS_LE, + # 18: R_386_TLS_GD, + # 19: R_386_TLS_LDM, + # 20: R_386_16, + # 21: R_386_PC16, + # 22: R_386_8, + # 23: R_386_PC8, + # 24: R_386_TLS_GD_32, + # 25: R_386_TLS_GD_PUSH, + # 26: R_386_TLS_GD_CALL, + # 27: R_386_TLS_GD_POP, + # 28: R_386_TLS_LDM_32, + # 29: R_386_TLS_LDM_PUSH, + # 30: R_386_TLS_LDM_CALL, + # 31: R_386_TLS_LDM_POP, + # 32: R_386_TLS_LDO_32, + # 33: R_386_TLS_IE_32, + # 34: R_386_TLS_LE_32, + 35: R_386_TLS_DTPMOD32, + 36: R_386_TLS_DTPOFF32, + # 37: R_386_TLS_TPOFF32, + # 38: R_386_SIZE32, + # 39: R_386_TLS_GOTDESC, + # 40: R_386_TLS_DESC_CALL, + # 41: R_386_TLS_DESC, + 42: R_386_IRELATIVE, + # 43: R_386_GOT32X, +} diff --git a/cle/backends/elf/relocation/mips.py b/cle/backends/elf/relocation/mips.py index 9d85ad21..43c8bee8 100644 --- a/cle/backends/elf/relocation/mips.py +++ b/cle/backends/elf/relocation/mips.py @@ -1,8 +1,19 @@ +"""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. +""" + from __future__ import annotations from .generic import ( GenericAbsoluteAddendReloc, GenericAbsoluteReloc, + GenericCopyReloc, GenericRelativeReloc, GenericTLSDoffsetReloc, GenericTLSModIdReloc, @@ -56,3 +67,91 @@ def relocate(self): self.owner.memory.pack_word(self.dest_addr, self.value & 0xFFFF, size=2) return True + + +class R_MIPS_64(GenericAbsoluteAddendReloc): + pass + + +class R_MIPS_COPY(GenericCopyReloc): + pass + + +class R_MIPS_TLS_DTPMOD64(GenericTLSModIdReloc): + pass + + +class R_MIPS_TLS_DTPREL64(GenericTLSDoffsetReloc): + pass + + +class R_MIPS_TLS_TPREL64(GenericTLSOffsetReloc): + pass + + +relocation_table_mips = { + # 1: R_MIPS_16, + 2: R_MIPS_32, + 3: R_MIPS_REL32, + # 4: R_MIPS_26, + 5: R_MIPS_HI16, + 6: R_MIPS_LO16, + # 7: R_MIPS_GPREL16, + # 8: R_MIPS_LITERAL, + # 9: R_MIPS_GOT16, + # 10: R_MIPS_PC16, + # 11: R_MIPS_CALL16, + # 12: R_MIPS_GPREL32, + # 13: R_MIPS_UNUSED1, + # 14: R_MIPS_UNUSED2, + # 15: R_MIPS_UNUSED3, + # 16: R_MIPS_SHIFT5, + # 17: R_MIPS_SHIFT6, + 18: R_MIPS_64, + # 19: R_MIPS_GOT_DISP, + # 20: R_MIPS_GOT_PAGE, + # 21: R_MIPS_GOT_OFST, + # 22: R_MIPS_GOT_HI16, + # 23: R_MIPS_GOT_LO16, + # 24: R_MIPS_SUB, + # 25: R_MIPS_INSERT_A, + # 26: R_MIPS_INSERT_B, + # 27: R_MIPS_DELETE, + # 28: R_MIPS_HIGHER, + # 29: R_MIPS_HIGHEST, + # 30: R_MIPS_CALL_HI16, + # 31: R_MIPS_CALL_LO16, + # 32: R_MIPS_SCN_DISP, + # 33: R_MIPS_REL16, + # 34: R_MIPS_ADD_IMMEDIATE, + # 35: R_MIPS_PJUMP, + # 36: R_MIPS_RELGOT, + # 37: R_MIPS_JALR, + 38: R_MIPS_TLS_DTPMOD32, + 39: R_MIPS_TLS_DTPREL32, + 40: R_MIPS_TLS_DTPMOD64, + 41: R_MIPS_TLS_DTPREL64, + # 42: R_MIPS_TLS_GD, + # 43: R_MIPS_TLS_LDM, + # 44: R_MIPS_TLS_DTPREL_HI16, + # 45: R_MIPS_TLS_DTPREL_LO16, + # 46: R_MIPS_TLS_GOTTPREL, + 47: R_MIPS_TLS_TPREL32, + 48: R_MIPS_TLS_TPREL64, + # 49: R_MIPS_TLS_TPREL_HI16, + # 50: R_MIPS_TLS_TPREL_LO16, + 51: R_MIPS_GLOB_DAT, + # 60: R_MIPS_PC21_S2, + # 61: R_MIPS_PC26_S2, + # 62: R_MIPS_PC18_S3, + # 63: R_MIPS_PC19_S2, + # 64: R_MIPS_PCHI16, + # 65: R_MIPS_PCLO16, + 126: R_MIPS_COPY, + 127: R_MIPS_JUMP_SLOT, + # 248: R_MIPS_PC32, + # 249: R_MIPS_EH, + # 250: R_MIPS_GNU_REL16_S2, + # 253: R_MIPS_GNU_VTINHERIT, + # 254: R_MIPS_GNU_VTENTRY, +} diff --git a/cle/backends/elf/relocation/mips64.py b/cle/backends/elf/relocation/mips64.py deleted file mode 100644 index 1a80e96b..00000000 --- a/cle/backends/elf/relocation/mips64.py +++ /dev/null @@ -1,36 +0,0 @@ -from __future__ import annotations - -from .generic import ( - GenericAbsoluteAddendReloc, - GenericCopyReloc, - GenericRelativeReloc, - GenericTLSDoffsetReloc, - GenericTLSModIdReloc, - GenericTLSOffsetReloc, -) - -arch = "MIPS64" - - -class R_MIPS_64(GenericAbsoluteAddendReloc): - pass - - -class R_MIPS_REL32(GenericRelativeReloc): - pass - - -class R_MIPS_COPY(GenericCopyReloc): - pass - - -class R_MIPS_TLS_DTPMOD64(GenericTLSModIdReloc): - pass - - -class R_MIPS_TLS_DTPREL64(GenericTLSDoffsetReloc): - pass - - -class R_MIPS_TLS_TPREL64(GenericTLSOffsetReloc): - pass diff --git a/cle/backends/elf/relocation/ppc.py b/cle/backends/elf/relocation/ppc.py index 4c1a7dc1..21a75b8f 100644 --- a/cle/backends/elf/relocation/ppc.py +++ b/cle/backends/elf/relocation/ppc.py @@ -1,3 +1,8 @@ +"""Relocation types for PowerPC 32-bit architecture. + +Reference: http://refspecs.linux-foundation.org/elf/elfspec_ppc.pdf page 4-18 +""" + from __future__ import annotations import logging @@ -16,9 +21,6 @@ log = logging.getLogger(name=__name__) arch = "PPC32" -# Reference: System V Application Binary Interface, PowerPC Processor Supplement -# http://refspecs.linux-foundation.org/elf/elfspec_ppc.pdf - # PPC constants/masks to be used in relocations PPC_WORD32 = 0xFFFFFFFF @@ -434,3 +436,44 @@ class R_PPC_DTPREL32(GenericTLSDoffsetReloc): class R_PPC_TPREL32(GenericTLSOffsetReloc): pass + + +relocation_table_ppc = { + 1: R_PPC_ADDR32, + 2: R_PPC_ADDR24, + 3: R_PPC_ADDR16, + 4: R_PPC_ADDR16_LO, + 5: R_PPC_ADDR16_HI, + 6: R_PPC_ADDR16_HA, + 7: R_PPC_ADDR14, + 8: R_PPC_ADDR14_BRTAKEN, + 9: R_PPC_ADDR14_BRNTAKEN, + 10: R_PPC_REL24, + 11: R_PPC_REL14, + 12: R_PPC_REL14_BRTAKEN, + 13: R_PPC_REL14_BRNTAKEN, + # 14: R_PPC_GOT16, + # 15: R_PPC_GOT16_LO, + # 16: R_PPC_GOT16_HI, + # 17: R_PPC_GOT16_HA, + # 18: R_PPC_PLTREL24, + 19: R_PPC_COPY, + 20: R_PPC_GLOB_DAT, + 21: R_PPC_JMP_SLOT, + 22: R_PPC_RELATIVE, + # 23: R_PPC_LOCAL24PC, + 24: R_PPC_UADDR32, + 25: R_PPC_UADDR16, + 26: R_PPC_REL32, + # 27: R_PPC_PLT32, + # 28: R_PPC_PLTREL32, + # 29: R_PPC_PLT16_LO, + # 30: R_PPC_PLT16_HI, + # 31: R_PPC_PLT16_HA, + # 32: R_PPC_SDAREL16, + 33: R_PPC_SECTOFF, + 34: R_PPC_SECTOFF_LO, + 35: R_PPC_SECTOFF_HI, + 36: R_PPC_SECTOFF_HA, + 37: R_PPC_ADDR30, +} diff --git a/cle/backends/elf/relocation/pcc64.py b/cle/backends/elf/relocation/ppc64.py similarity index 57% rename from cle/backends/elf/relocation/pcc64.py rename to cle/backends/elf/relocation/ppc64.py index 12b07d52..076faa26 100644 --- a/cle/backends/elf/relocation/pcc64.py +++ b/cle/backends/elf/relocation/ppc64.py @@ -1,3 +1,8 @@ +"""Relocation types for PPC64. + +Reference: http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.pdf pages 57-59 +""" + from __future__ import annotations import logging @@ -15,7 +20,6 @@ log = logging.getLogger(name=__name__) -# http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.pdf arch = "PPC64" @@ -172,3 +176,115 @@ def value(self): log.warning(".TOC. value not found") return 0 return self.owner.ppc64_initial_rtoc + + +relocation_table_ppc64 = { + # 1: R_PPC64_ADDR32, + # 2: R_PPC64_ADDR24, + # 3: R_PPC64_ADDR16, + # 4: R_PPC64_ADDR16_LO, + # 5: R_PPC64_ADDR16_HI, + # 6: R_PPC64_ADDR16_HA, + # 7: R_PPC64_ADDR14, + # 8: R_PPC64_ADDR14_BRTAKEN, + # 9: R_PPC64_ADDR14_BRNTAKEN, + 10: R_PPC64_REL24, + # 11: R_PPC64_REL14, + # 12: R_PPC64_REL14_BRTAKEN, + # 13: R_PPC64_REL14_BRNTAKEN, + # 14: R_PPC64_GOT16, + # 15: R_PPC64_GOT16_LO, + # 16: R_PPC64_GOT16_HI, + # 17: R_PPC64_GOT16_HA, + # No 18 in doc + # 19: R_PPC64_COPY, + 20: R_PPC64_GLOB_DAT, + 21: R_PPC64_JMP_SLOT, + 22: R_PPC64_RELATIVE, + # No 23 in doc + # 24: R_PPC64_UADDR32, + # 25: R_PPC64_UADDR16, + # 26: R_PPC64_REL32, + # 27: R_PPC64_PLT32, + # 28: R_PPC64_PLTREL32, + # 29: R_PPC64_PLT16_LO, + # 30: R_PPC64_PLT16_HI, + # 31: R_PPC64_PLT16_HA, + # No 32 in doc + # 33: R_PPC64_SECTOFF, + # 34: R_PPC64_SECTOFF_LO, + # 35: R_PPC64_SECTOFF_HI, + # 36: R_PPC64_SECTOFF_HA, + # 37: R_PPC64_ADDR30, + 38: R_PPC64_ADDR64, + # 39: R_PPC64_ADDR16_HIGHER, + # 40: R_PPC64_ADDR16_HIGHERA, + # 41: R_PPC64_ADDR16_HIGHEST, + # 42: R_PPC64_ADDR16_HIGHESTA, + # 43: R_PPC64_UADDR64, + # 44: R_PPC64_REL64, + # 45: R_PPC64_PLT64, + # 46: R_PPC64_PLTREL64, + # 47: R_PPC64_TOC16, + 48: R_PPC64_TOC16_LO, + 49: R_PPC64_TOC16_HI, + 50: R_PPC64_TOC16_HA, + 51: R_PPC64_TOC, + # 52: R_PPC64_PLTGOT16, + # 53: R_PPC64_PLTGOT16_LO, + # 54: R_PPC64_PLTGOT16_HI, + # 55: R_PPC64_PLTGOT16_HA, + # 56: R_PPC64_ADDR16_DS, + # 57: R_PPC64_ADDR16_LO_DS, + # 58: R_PPC64_GOT16_DS, + # 59: R_PPC64_GOT16_LO_DS, + # 60: R_PPC64_PLT16_LO_DS, + # 61: R_PPC64_SECTOFF_DS, + # 62: R_PPC64_SECTOFF_LO_DS, + # 63: R_PPC64_TOC16_DS, + # 64: R_PPC64_TOC16_LO_DS, + # 65: R_PPC64_PLTGOT16_DS, + # 66: R_PPC64_PLTGOT16_LO_DS, + # 67: R_PPC64_TLS, + 68: R_PPC64_DTPMOD64, + # 69: R_PPC64_TPREL16, + # 70: R_PPC64_TPREL16_LO, + # 71: R_PPC64_TPREL16_HI, + # 72: R_PPC64_TPREL16_HA, + 73: R_PPC64_TPREL64, + # 74: R_PPC64_DTPREL16, + # 75: R_PPC64_DTPREL16_LO, + # 76: R_PPC64_DTPREL16_HI, + # 77: R_PPC64_DTPREL16_HA, + 78: R_PPC64_DTPREL64, + # 79: R_PPC64_GOT_TLSGD16, + # 80: R_PPC64_GOT_TLSGD16_LO, + # 81: R_PPC64_GOT_TLSGD16_HI, + # 82: R_PPC64_GOT_TLSGD16_HA, + # 83: R_PPC64_GOT_TLSLD16, + # 84: R_PPC64_GOT_TLSLD16_LO, + # 85: R_PPC64_GOT_TLSLD16_HI, + # 86: R_PPC64_GOT_TLSLD16_HA, + # 87: R_PPC64_GOT_TPREL16_DS, + # 88: R_PPC64_GOT_TPREL16_LO_DS, + # 89: R_PPC64_GOT_TPREL16_HI, + # 90: R_PPC64_GOT_TPREL16_HA, + # 91: R_PPC64_GOT_DTPREL16_DS, + # 92: R_PPC64_GOT_DTPREL16_LO_DS, + # 93: R_PPC64_GOT_DTPREL16_HI, + # 94: R_PPC64_GOT_DTPREL16_HA, + # 95: R_PPC64_TPREL16_DS, + # 96: R_PPC64_TPREL16_LO_DS, + # 97: R_PPC64_TPREL16_HIGHER, + # 98: R_PPC64_TPREL16_HIGHERA, + # 99: R_PPC64_TPREL16_HIGHEST, + # 100: R_PPC64_TPREL16_HIGHESTA, + # 101: R_PPC64_DTPREL16_DS, + # 102: R_PPC64_DTPREL16_LO_DS, + # 103: R_PPC64_DTPREL16_HIGHER, + # 104: R_PPC64_DTPREL16_HIGHERA, + # 105: R_PPC64_DTPREL16_HIGHEST, + # 106: R_PPC64_DTPREL16_HIGHESTA, + # Not in spec + 248: R_PPC64_IRELATIVE, +} diff --git a/cle/backends/elf/relocation/s390x.py b/cle/backends/elf/relocation/s390x.py index 4a86dea4..ec102960 100644 --- a/cle/backends/elf/relocation/s390x.py +++ b/cle/backends/elf/relocation/s390x.py @@ -1,3 +1,8 @@ +"""Relocation types for the S390X architecture. + +Reference: https://github.com/IBM/s390x-abi/releases/download/v1.6.1/lzsabi_s390x.pdf pages 51-52 +""" + from __future__ import annotations from .generic import ( @@ -38,3 +43,72 @@ class R_390_IRELATIVE(GenericIRelativeReloc): class R_390_COPY(GenericCopyReloc): pass + + +relocation_table_s390x = { + # 1: R_390_8, + # 2: R_390_12, + # 3: R_390_16, + # 4: R_390_32, + # 5: R_390_PC32, + # 6: R_390_GOT12, + # 7: R_390_GOT32, + # 8: R_390_PLT32, + 9: R_390_COPY, + 10: R_390_GLOB_DAT, + 11: R_390_JMP_SLOT, + 12: R_390_RELATIVE, + # 13: R_390_GOTOFF32, + # 14: R_390_GOTPC, + # 15: R_390_GOT16, + # 16: R_390_PC16, + # 17: R_390_PC16DBL, + # 18: R_390_PLT16DBL, + # 19: R_390_PC32DBL, + # 20: R_390_PLT32DBL, + # 21: R_390_GOTPCDBL, + 22: R_390_64, + # 23: R_390_PC64, + # 24: R_390_GOT64, + # 25: R_390_PLT64, + # 26: R_390_GOTENT, + # 27: R_390_GOTOFF16, + # 28: R_390_GOTOFF64, + # 29: R_390_GOTPLT12, + # 30: R_390_GOTPLT16, + # 31: R_390_GOTPLT32, + # 32: R_390_GOTPLT64, + # 33: R_390_GOTPLTENT, + # 34: R_390_PLTOFF16, + # 35: R_390_PLTOFF32, + # 36: R_390_PLTOFF64, + # 37: R_390_TLS_LOAD, + # 38: R_390_TLS_GDCALL, + # 39: R_390_TLS_LDCALL, + # No 40 in doc + # 41: R_390_TLS_GD64, + # 42: R_390_TLS_GOTIE12, + # No 43 in doc + # 44: R_390_TLS_GOTIE64, + # No 45 in doc + # 46: R_390_TLS_LDM64, + # No 47 in doc + # 48: R_390_TLS_IE64, + # 49: R_390_TLS_IEENT, + # No 50 in doc + # 51: R_390_TLS_LE64, + # No 52 in doc + # 53: R_390_TLS_LDO64, + # 54: R_390_TLS_DTPMOD, + # 55: R_390_TLS_DTPOFF, + 56: R_390_TLS_TPOFF, + # 57: R_390_20, + # 58: R_390_GOT20, + # 59: R_390_GOTPLT20, + # 60: R_390_TLS_GOTIE20, + 61: R_390_IRELATIVE, + # 62: R_390_PC12DBL, + # 63: R_390_PLT12DBL, + # 64: R_390_PC24DBL, + # 65: R_390_PLT24DBL, +} diff --git a/cle/backends/elf/relocation/sparc.py b/cle/backends/elf/relocation/sparc.py index 59069fa0..32fbcf57 100644 --- a/cle/backends/elf/relocation/sparc.py +++ b/cle/backends/elf/relocation/sparc.py @@ -1,11 +1,14 @@ +"""Relocations for SPARC + +Reference: https://sparc.org/wp-content/uploads/2014/01/psABI3rd.pdf.gz page 4-4 +""" + from __future__ import annotations from .elfreloc import ELFReloc arch = "sparc:BE:32:default" -# Check The SPARC Architecture Manual for field definitions. - class R_SPARC_HI22(ELFReloc): """ @@ -50,3 +53,30 @@ def value(self): instr_bytes = self.owner.memory.load(self.relative_addr, 4) instr = int.from_bytes(instr_bytes, byteorder="big") return instr & 0xFFFFE000 | result & 0x1FFF + + +relocation_table_sparc = { + # 1: R_SPARC_8, + # 2: R_SPARC_16, + # 3: R_SPARC_32, + # 4: R_SPARC_DISP8, + # 5: R_SPARC_DISP16, + # 6: R_SPARC_DISP32, + 7: R_SPARC_WDISP30, + # 8: R_SPARC_WDISP22, + 9: R_SPARC_HI22, + # 10: R_SPARC_22, + # 11: R_SPARC_13, + 12: R_SPARC_LO10, + # 13: R_SPARC_GOT10, + # 14: R_SPARC_GOT13, + # 15: R_SPARC_GOT22, + # 16: R_SPARC_PC10, + # 17: R_SPARC_PC22, + # 18: R_SPARC_WPLT30, + # 19: R_SPARC_COPY, + # 20: R_SPARC_GLOB_DAT, + # 21: R_SPARC_JMP_SLOT, + # 22: R_SPARC_RELATIVE, + # 23: R_SPARC_UA32, +} From 0ee19f70991db258caf333d64c1040d2a46eada3 Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Fri, 9 Aug 2024 16:39:38 -0700 Subject: [PATCH 2/7] Add __all__, remove arch --- cle/backends/elf/relocation/__init__.py | 2 +- cle/backends/elf/relocation/amd64.py | 2 ++ cle/backends/elf/relocation/arm.py | 32 +------------------------ cle/backends/elf/relocation/arm64.py | 5 ++-- cle/backends/elf/relocation/i386.py | 4 ++-- cle/backends/elf/relocation/mips.py | 4 ++-- cle/backends/elf/relocation/ppc.py | 3 ++- cle/backends/elf/relocation/ppc64.py | 4 ++-- cle/backends/elf/relocation/s390x.py | 4 ++-- cle/backends/elf/relocation/sparc.py | 4 ++-- 10 files changed, 18 insertions(+), 46 deletions(-) diff --git a/cle/backends/elf/relocation/__init__.py b/cle/backends/elf/relocation/__init__.py index aae19835..d25203b5 100644 --- a/cle/backends/elf/relocation/__init__.py +++ b/cle/backends/elf/relocation/__init__.py @@ -25,7 +25,7 @@ "PPC32": relocation_table_ppc, "PPC64": relocation_table_ppc64, "S390X": relocation_table_s390x, - "SPARC": relocation_table_sparc, + "sparc:BE:32:default": relocation_table_sparc, } diff --git a/cle/backends/elf/relocation/amd64.py b/cle/backends/elf/relocation/amd64.py index d28add10..bde6f6ce 100644 --- a/cle/backends/elf/relocation/amd64.py +++ b/cle/backends/elf/relocation/amd64.py @@ -131,3 +131,5 @@ class R_X86_64_REX_GOTPCRELX(RelocGOTMixin, RelocTruncate32Mixin, GenericPCRelat # 50: R_X86_64_CODE_6_GOTTPOFF, # 51: R_X86_64_CODE_6_GOTPC32_TLSDESC, } + +__all__ = ("relocation_table_amd64",) diff --git a/cle/backends/elf/relocation/arm.py b/cle/backends/elf/relocation/arm.py index e20d306e..f62c1a75 100644 --- a/cle/backends/elf/relocation/arm.py +++ b/cle/backends/elf/relocation/arm.py @@ -24,10 +24,6 @@ ) log = logging.getLogger(name=__name__) -arch = "ARM" - -# Reference: "ELF for the ARM Architecture ABI r2.10" -# http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044e/IHI0044E_aaelf.pdf def _applyReloc(inst, result, mask=0xFFFFFFFF): @@ -650,30 +646,4 @@ class R_ARM_GOT_PREL(GenericPCRelativeAddendReloc, RelocTruncate32Mixin, RelocGO } -__all__ = [ - "arch", - "R_ARM_CALL", - "R_ARM_PREL31", - "R_ARM_REL32", - "R_ARM_ABS32", - "R_ARM_MOVW_ABS_NC", - "R_ARM_MOVT_ABS", - "R_ARM_THM_CALL", - "R_ARM_COPY", - "R_ARM_GLOB_DAT", - "R_ARM_JUMP_SLOT", - "R_ARM_RELATIVE", - "R_ARM_ABS32_NOI", - "R_ARM_REL32_NOI", - "R_ARM_TLS_DTPMOD32", - "R_ARM_TLS_DTPOFF32", - "R_ARM_TLS_TPOFF32", - "R_ARM_JUMP24", - "R_ARM_PC24", - "R_ARM_THM_JUMP24", - "R_ARM_THM_JUMP19", - "R_ARM_THM_JUMP6", - "R_ARM_THM_MOVW_ABS_NC", - "R_ARM_THM_MOVT_ABS", - "R_ARM_GOT_PREL", -] +__all__ = ("relocation_table_arm",) diff --git a/cle/backends/elf/relocation/arm64.py b/cle/backends/elf/relocation/arm64.py index ff1d1957..c3558215 100644 --- a/cle/backends/elf/relocation/arm64.py +++ b/cle/backends/elf/relocation/arm64.py @@ -23,9 +23,6 @@ log = logging.getLogger(name=__name__) -# https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst -arch = "AARCH64" - class R_AARCH64_ABS64(GenericAbsoluteAddendReloc): pass @@ -403,3 +400,5 @@ def relocate(self): # 1040: R_AARCH64_AUTH_ABS64, # 1041: R_AARCH64_AUTHELATIVE, } + +__all__ = ("relocation_table_arm64",) diff --git a/cle/backends/elf/relocation/i386.py b/cle/backends/elf/relocation/i386.py index 36ced228..09918cab 100644 --- a/cle/backends/elf/relocation/i386.py +++ b/cle/backends/elf/relocation/i386.py @@ -18,8 +18,6 @@ RelocGOTMixin, ) -arch = "X86" - class R_386_32(GenericAbsoluteAddendReloc): """ @@ -159,3 +157,5 @@ class R_386_GOTPC(GenericPCRelativeAddendReloc, RelocGOTMixin): 42: R_386_IRELATIVE, # 43: R_386_GOT32X, } + +__all__ = ("relocation_table_i386",) diff --git a/cle/backends/elf/relocation/mips.py b/cle/backends/elf/relocation/mips.py index 43c8bee8..ac961109 100644 --- a/cle/backends/elf/relocation/mips.py +++ b/cle/backends/elf/relocation/mips.py @@ -20,8 +20,6 @@ GenericTLSOffsetReloc, ) -arch = "MIPS32" - class R_MIPS_32(GenericAbsoluteAddendReloc): pass @@ -155,3 +153,5 @@ class R_MIPS_TLS_TPREL64(GenericTLSOffsetReloc): # 253: R_MIPS_GNU_VTINHERIT, # 254: R_MIPS_GNU_VTENTRY, } + +__all__ = ("relocation_table_mips",) diff --git a/cle/backends/elf/relocation/ppc.py b/cle/backends/elf/relocation/ppc.py index 21a75b8f..34b3da2e 100644 --- a/cle/backends/elf/relocation/ppc.py +++ b/cle/backends/elf/relocation/ppc.py @@ -19,7 +19,6 @@ ) log = logging.getLogger(name=__name__) -arch = "PPC32" # PPC constants/masks to be used in relocations @@ -477,3 +476,5 @@ class R_PPC_TPREL32(GenericTLSOffsetReloc): 36: R_PPC_SECTOFF_HA, 37: R_PPC_ADDR30, } + +__all__ = ("relocation_table_ppc",) diff --git a/cle/backends/elf/relocation/ppc64.py b/cle/backends/elf/relocation/ppc64.py index 076faa26..9727e07b 100644 --- a/cle/backends/elf/relocation/ppc64.py +++ b/cle/backends/elf/relocation/ppc64.py @@ -20,8 +20,6 @@ log = logging.getLogger(name=__name__) -arch = "PPC64" - class R_PPC64_JMP_SLOT(ELFReloc): def relocate(self): @@ -288,3 +286,5 @@ def value(self): # Not in spec 248: R_PPC64_IRELATIVE, } + +__all__ = ("relocation_table_ppc64",) diff --git a/cle/backends/elf/relocation/s390x.py b/cle/backends/elf/relocation/s390x.py index ec102960..44f87532 100644 --- a/cle/backends/elf/relocation/s390x.py +++ b/cle/backends/elf/relocation/s390x.py @@ -14,8 +14,6 @@ GenericTLSOffsetReloc, ) -arch = "S390X" - class R_390_GLOB_DAT(GenericJumpslotReloc): pass @@ -112,3 +110,5 @@ class R_390_COPY(GenericCopyReloc): # 64: R_390_PC24DBL, # 65: R_390_PLT24DBL, } + +__all__ = ("relocation_table_s390x",) diff --git a/cle/backends/elf/relocation/sparc.py b/cle/backends/elf/relocation/sparc.py index 32fbcf57..70447ba6 100644 --- a/cle/backends/elf/relocation/sparc.py +++ b/cle/backends/elf/relocation/sparc.py @@ -7,8 +7,6 @@ from .elfreloc import ELFReloc -arch = "sparc:BE:32:default" - class R_SPARC_HI22(ELFReloc): """ @@ -80,3 +78,5 @@ def value(self): # 22: R_SPARC_RELATIVE, # 23: R_SPARC_UA32, } + +__all__ = ("relocation_table_sparc",) From 9743dac69c9606e94545ef7e2c61e38cac854f5c Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Fri, 9 Aug 2024 16:56:47 -0700 Subject: [PATCH 3/7] Disable pylint missing-class-docstring in some relocation files --- cle/backends/elf/relocation/mips.py | 2 ++ cle/backends/elf/relocation/ppc64.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/cle/backends/elf/relocation/mips.py b/cle/backends/elf/relocation/mips.py index ac961109..2f72fb3d 100644 --- a/cle/backends/elf/relocation/mips.py +++ b/cle/backends/elf/relocation/mips.py @@ -20,6 +20,8 @@ GenericTLSOffsetReloc, ) +# pylint: disable=missing-class-docstring + class R_MIPS_32(GenericAbsoluteAddendReloc): pass diff --git a/cle/backends/elf/relocation/ppc64.py b/cle/backends/elf/relocation/ppc64.py index 9727e07b..01a58fd0 100644 --- a/cle/backends/elf/relocation/ppc64.py +++ b/cle/backends/elf/relocation/ppc64.py @@ -20,6 +20,8 @@ log = logging.getLogger(name=__name__) +# pylint: disable=missing-class-docstring + class R_PPC64_JMP_SLOT(ELFReloc): def relocate(self): From de98db2b76a3001e8c0b2246a2c43ec1b18193ae Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Fri, 9 Aug 2024 17:06:59 -0700 Subject: [PATCH 4/7] Add PPC TLS relocations --- cle/backends/elf/relocation/ppc.py | 37 ++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/cle/backends/elf/relocation/ppc.py b/cle/backends/elf/relocation/ppc.py index 34b3da2e..75dcfe1f 100644 --- a/cle/backends/elf/relocation/ppc.py +++ b/cle/backends/elf/relocation/ppc.py @@ -1,6 +1,9 @@ """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. """ from __future__ import annotations @@ -66,7 +69,7 @@ def value(self): return result -class R_PPC_ADDR16_LO(ELFReloc): # pylint: disable=undefined-variable +class R_PPC_ADDR16_LO(ELFReloc): """ Relocation Type: 0x4 Calculation: #lo(S + A) @@ -183,7 +186,7 @@ def value(self): return result -class R_PPC_REL24(ELFReloc): # pylint: disable=undefined-variable +class R_PPC_REL24(ELFReloc): """ Relocation Type: 0xa Calculation: (S + A - P) >> 2 @@ -475,6 +478,36 @@ class R_PPC_TPREL32(GenericTLSOffsetReloc): 35: R_PPC_SECTOFF_HI, 36: R_PPC_SECTOFF_HA, 37: R_PPC_ADDR30, + # 67: R_PPC_TLS, + 68: R_PPC_DTPMOD32, + # 69: R_PPC_TPREL16, + # 70: R_PPC_TPREL16_LO, + # 71: R_PPC_TPREL16_HI, + # 72: R_PPC_TPREL16_HA, + 73: R_PPC_TPREL32, + # 74: R_PPC_DTPREL16, + # 75: R_PPC_DTPREL16_LO, + # 76: R_PPC_DTPREL16_HI, + # 77: R_PPC_DTPREL16_HA, + 78: R_PPC_DTPREL32, + # 79: R_PPC_GOT_TLSGD16, + # 80: R_PPC_GOT_TLSGD16_LO, + # 81: R_PPC_GOT_TLSGD16_HI, + # 82: R_PPC_GOT_TLSGD16_HA, + # 83: R_PPC_GOT_TLSLD16, + # 84: R_PPC_GOT_TLSLD16_LO, + # 85: R_PPC_GOT_TLSLD16_HI, + # 86: R_PPC_GOT_TLSLD16_HA, + # 87: R_PPC_GOT_TPREL16, + # 88: R_PPC_GOT_TPREL16_LO, + # 89: R_PPC_GOT_TPREL16_HI, + # 90: R_PPC_GOT_TPREL16_HA, + # 91: R_PPC_GOT_DTPREL16, + # 92: R_PPC_GOT_DTPREL16_LO, + # 93: R_PPC_GOT_DTPREL16_HI, + # 94: R_PPC_GOT_DTPREL16_HA, + # 95: R_PPC_TLSGD, + # 96: R_PPC_TLSLD, } __all__ = ("relocation_table_ppc",) From b310961a5a5566216ca7d90d8644a5f5e742a83d Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Fri, 9 Aug 2024 17:13:26 -0700 Subject: [PATCH 5/7] Update docs --- docs/api/relocations.rst | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/api/relocations.rst b/docs/api/relocations.rst index a5f47948..d3c40110 100644 --- a/docs/api/relocations.rst +++ b/docs/api/relocations.rst @@ -1,25 +1,21 @@ Relocations ----------- -CLE's loader implements program relocation data on a plugin basis. -If you would like to add more relocation implementations, do so by subclassing the ``Relocation`` class and overriding any relevant methods or properties. -Put your subclasses in a module in the ``relocations`` subpackage of the appropraite backend package. -The name of the subclass will be used to determine when to use it! +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, uncomment the appropriate line in the relocations_table dict at the bottom of the file. Look at the existing versions for details. .. automodule:: cle.backends.relocation .. automodule:: cle.backends.elf.relocation .. automodule:: cle.backends.elf.relocation.elfreloc -.. automodule:: cle.backends.elf.relocation.mips64 .. automodule:: cle.backends.elf.relocation.generic .. automodule:: cle.backends.elf.relocation.ppc -.. automodule:: cle.backends.elf.relocation.armhf -.. automodule:: cle.backends.elf.relocation.pcc64 +.. automodule:: cle.backends.elf.relocation.ppc64 .. automodule:: cle.backends.elf.relocation.i386 .. automodule:: cle.backends.elf.relocation.amd64 .. automodule:: cle.backends.elf.relocation.mips .. automodule:: cle.backends.elf.relocation.arm -.. automodule:: cle.backends.elf.relocation.arm_cortex_m .. automodule:: cle.backends.elf.relocation.arm64 .. automodule:: cle.backends.elf.relocation.s390x .. automodule:: cle.backends.pe.relocation From 09b85e9a99a1ded445eda5452f8d1ea21e82e382 Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Fri, 9 Aug 2024 17:35:32 -0700 Subject: [PATCH 6/7] Apply same treatment to pe relocs --- cle/backends/pe/relocation/__init__.py | 49 +++++++------------------- cle/backends/pe/relocation/amd64.py | 31 ---------------- cle/backends/pe/relocation/arm.py | 35 ++++-------------- cle/backends/pe/relocation/generic.py | 9 +++++ cle/backends/pe/relocation/i386.py | 31 ---------------- cle/backends/pe/relocation/mips.py | 35 ++++-------------- cle/backends/pe/relocation/riscv.py | 38 +++++--------------- docs/api/relocations.rst | 4 +-- 8 files changed, 45 insertions(+), 187 deletions(-) delete mode 100644 cle/backends/pe/relocation/amd64.py delete mode 100644 cle/backends/pe/relocation/i386.py diff --git a/cle/backends/pe/relocation/__init__.py b/cle/backends/pe/relocation/__init__.py index d4138499..f80a361e 100644 --- a/cle/backends/pe/relocation/__init__.py +++ b/cle/backends/pe/relocation/__init__.py @@ -1,44 +1,22 @@ from __future__ import annotations -import importlib import logging -import os -from collections import defaultdict -import archinfo +from .arm import relocation_table_arm +from .generic import relocation_table_generic +from .mips import relocation_table_mips +from .riscv import relocation_table_riscv -from cle.backends.relocation import Relocation +ALL_RELOCATIONS = { + "AMD64": relocation_table_generic, + "arm": relocation_table_generic | relocation_table_arm, + "X86": relocation_table_generic, + "mips": relocation_table_generic | relocation_table_mips, + "RISCV": relocation_table_generic | relocation_table_riscv, +} -ALL_RELOCATIONS = defaultdict(dict) -complaint_log = set() - -path = os.path.dirname(os.path.abspath(__file__)) log = logging.getLogger(name=__name__) - - -def load_relocations(): - for filename in os.listdir(path): - if not filename.endswith(".py"): - continue - if filename == "__init__.py": - continue - - log.debug("Importing PE relocation module: %s", filename[:-3]) - module = importlib.import_module(f".{filename[:-3]}", "cle.backends.pe.relocation") - - try: - arch_name = module.arch - except AttributeError: - continue - - for item_name in dir(module): - if item_name not in archinfo.defines: - continue - item = getattr(module, item_name) - if not isinstance(item, type) or not issubclass(item, Relocation): - continue - - ALL_RELOCATIONS[arch_name][archinfo.defines[item_name]] = item +complaint_log = set() def get_relocation(arch, r_type): @@ -51,6 +29,3 @@ def get_relocation(arch, r_type): complaint_log.add((arch, r_type)) log.warning("Unknown reloc %d on %s", r_type, arch) return None - - -load_relocations() diff --git a/cle/backends/pe/relocation/amd64.py b/cle/backends/pe/relocation/amd64.py deleted file mode 100644 index 59f03986..00000000 --- a/cle/backends/pe/relocation/amd64.py +++ /dev/null @@ -1,31 +0,0 @@ -from __future__ import annotations - -from .generic import ( - IMAGE_REL_BASED_DIR64, - IMAGE_REL_BASED_HIGH, - IMAGE_REL_BASED_HIGHADJ, - IMAGE_REL_BASED_HIGHLOW, - IMAGE_REL_BASED_LOW, -) - -arch = "AMD64" - - -class IMAGE_REL_BASED_HIGHADJ(IMAGE_REL_BASED_HIGHADJ): - pass - - -class IMAGE_REL_BASED_DIR64(IMAGE_REL_BASED_DIR64): - pass - - -class IMAGE_REL_BASED_HIGHLOW(IMAGE_REL_BASED_HIGHLOW): - pass - - -class IMAGE_REL_BASED_HIGH(IMAGE_REL_BASED_HIGH): - pass - - -class IMAGE_REL_BASED_LOW(IMAGE_REL_BASED_LOW): - pass diff --git a/cle/backends/pe/relocation/arm.py b/cle/backends/pe/relocation/arm.py index 0419048c..9da364a1 100644 --- a/cle/backends/pe/relocation/arm.py +++ b/cle/backends/pe/relocation/arm.py @@ -1,40 +1,19 @@ from __future__ import annotations -from .generic import ( - IMAGE_REL_BASED_DIR64, - IMAGE_REL_BASED_HIGH, - IMAGE_REL_BASED_HIGHADJ, - IMAGE_REL_BASED_HIGHLOW, - IMAGE_REL_BASED_LOW, -) from .pereloc import PEReloc -arch = "arm" - -class IMAGE_REL_BASED_HIGHADJ(IMAGE_REL_BASED_HIGHADJ): - pass - - -class IMAGE_REL_BASED_DIR64(IMAGE_REL_BASED_DIR64): - pass - - -class IMAGE_REL_BASED_HIGHLOW(IMAGE_REL_BASED_HIGHLOW): - pass - - -class IMAGE_REL_BASED_HIGH(IMAGE_REL_BASED_HIGH): +class IMAGE_REL_BASED_ARM_MOV32(PEReloc): pass -class IMAGE_REL_BASED_LOW(IMAGE_REL_BASED_LOW): +class IMAGE_REL_BASED_THUMB_MOV32(PEReloc): pass -class IMAGE_REL_BASED_ARM_MOV32(PEReloc): - pass - +relocation_table_arm = { + 5: IMAGE_REL_BASED_ARM_MOV32, + 7: IMAGE_REL_BASED_THUMB_MOV32, +} -class IMAGE_REL_BASED_THUMB_MOV32(PEReloc): - pass +__all__ = ('relocation_table_arm',) diff --git a/cle/backends/pe/relocation/generic.py b/cle/backends/pe/relocation/generic.py index 645df396..bde57a3f 100644 --- a/cle/backends/pe/relocation/generic.py +++ b/cle/backends/pe/relocation/generic.py @@ -101,3 +101,12 @@ def value(self): adjusted_value = rebased_value & 0x0000FFFF adjusted_bytes = struct.pack(" Date: Sat, 10 Aug 2024 00:35:46 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- cle/backends/pe/relocation/arm.py | 2 +- cle/backends/pe/relocation/mips.py | 2 +- cle/backends/pe/relocation/riscv.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cle/backends/pe/relocation/arm.py b/cle/backends/pe/relocation/arm.py index 9da364a1..edb04687 100644 --- a/cle/backends/pe/relocation/arm.py +++ b/cle/backends/pe/relocation/arm.py @@ -16,4 +16,4 @@ class IMAGE_REL_BASED_THUMB_MOV32(PEReloc): 7: IMAGE_REL_BASED_THUMB_MOV32, } -__all__ = ('relocation_table_arm',) +__all__ = ("relocation_table_arm",) diff --git a/cle/backends/pe/relocation/mips.py b/cle/backends/pe/relocation/mips.py index 0a35df79..dd6c2b2e 100644 --- a/cle/backends/pe/relocation/mips.py +++ b/cle/backends/pe/relocation/mips.py @@ -16,4 +16,4 @@ class IMAGE_REL_BASED_MIPS_JMPADDR16(PEReloc): 9: IMAGE_REL_BASED_MIPS_JMPADDR16, } -__all__ = ('relocation_table_mips',) +__all__ = ("relocation_table_mips",) diff --git a/cle/backends/pe/relocation/riscv.py b/cle/backends/pe/relocation/riscv.py index bd5f0249..52b3d52d 100644 --- a/cle/backends/pe/relocation/riscv.py +++ b/cle/backends/pe/relocation/riscv.py @@ -21,4 +21,4 @@ class IMAGE_REL_BASED_RISCV_LOW12S(PEReloc): 8: IMAGE_REL_BASED_RISCV_LOW12S, } -__all__ = ('relocation_table_riscv',) +__all__ = ("relocation_table_riscv",)