15#ifndef LIEF_COFF_RELOCATION_H
16#define LIEF_COFF_RELOCATION_H
37 static constexpr uint32_t
I386 = 1 << 17;
38 static constexpr uint32_t
X64 = 1 << 18;
39 static constexpr uint32_t
ARM = 1 << 19;
40 static constexpr uint32_t
ARM64 = 1 << 20;
41 static constexpr uint32_t
MIPS = 1 << 21;
47 enum class TYPE : uint32_t {
48 UNKNOWN = uint32_t(-1),
49 I386_ABSOLUTE =
I386 + 0x0000,
50 I386_DIR16 =
I386 + 0x0001,
51 I386_REL16 =
I386 + 0x0002,
52 I386_DIR32 =
I386 + 0x0006,
53 I386_DIR32NB =
I386 + 0x0007,
54 I386_SEG12 =
I386 + 0x0009,
55 I386_SECTION =
I386 + 0x000A,
56 I386_SECREL =
I386 + 0x000B,
57 I386_TOKEN =
I386 + 0x000C,
58 I386_SECREL7 =
I386 + 0x000D,
59 I386_REL32 =
I386 + 0x0014,
61 AMD64_ABSOLUTE =
X64 + 0x0000,
62 AMD64_ADDR64 =
X64 + 0x0001,
63 AMD64_ADDR32 =
X64 + 0x0002,
64 AMD64_ADDR32NB =
X64 + 0x0003,
65 AMD64_REL32 =
X64 + 0x0004,
66 AMD64_REL32_1 =
X64 + 0x0005,
67 AMD64_REL32_2 =
X64 + 0x0006,
68 AMD64_REL32_3 =
X64 + 0x0007,
69 AMD64_REL32_4 =
X64 + 0x0008,
70 AMD64_REL32_5 =
X64 + 0x0009,
71 AMD64_SECTION =
X64 + 0x000A,
72 AMD64_SECREL =
X64 + 0x000B,
73 AMD64_SECREL7 =
X64 + 0x000C,
74 AMD64_TOKEN =
X64 + 0x000D,
75 AMD64_SREL32 =
X64 + 0x000E,
76 AMD64_PAIR =
X64 + 0x000F,
77 AMD64_SSPAN32 =
X64 + 0x0010,
79 ARM_ABSOLUTE =
ARM + 0x0000,
80 ARM_ADDR32 =
ARM + 0x0001,
81 ARM_ADDR32NB =
ARM + 0x0002,
82 ARM_BRANCH24 =
ARM + 0x0003,
83 ARM_BRANCH11 =
ARM + 0x0004,
84 ARM_TOKEN =
ARM + 0x0005,
85 ARM_BLX24 =
ARM + 0x0008,
86 ARM_BLX11 =
ARM + 0x0009,
87 ARM_REL32 =
ARM + 0x000A,
88 ARM_SECTION =
ARM + 0x000E,
89 ARM_SECREL =
ARM + 0x000F,
90 ARM_MOV32A =
ARM + 0x0010,
91 ARM_MOV32T =
ARM + 0x0011,
92 ARM_BRANCH20T =
ARM + 0x0012,
93 ARM_BRANCH24T =
ARM + 0x0014,
94 ARM_BLX23T =
ARM + 0x0015,
95 ARM_PAIR =
ARM + 0x0016,
97 ARM64_ABSOLUTE =
ARM64 + 0x0000,
99 ARM64_ADDR32NB =
ARM64 + 0x0002,
101 ARM64_PAGEBASE_REL21 =
ARM64 + 0x0004,
103 ARM64_PAGEOFFSET_12A =
ARM64 + 0x0006,
104 ARM64_PAGEOFFSET_12L =
ARM64 + 0x0007,
106 ARM64_SECREL_LOW12A =
ARM64 + 0x0009,
107 ARM64_SECREL_HIGH12A =
ARM64 + 0x000A,
108 ARM64_SECREL_LOW12L =
ARM64 + 0x000B,
128 MIPS_JMPADDR16 =
MIPS + 0x0010,
129 MIPS_REFWORDNB =
MIPS + 0x0022,
135 return (uint16_t)rtype;
141 case Header::MACHINE_TYPES::ARM64:
return TYPE(value +
ARM64);
143 case Header::MACHINE_TYPES::AMD64:
return TYPE(value +
X64);
145 case Header::MACHINE_TYPES::I386:
return TYPE(value +
I386);
147 case Header::MACHINE_TYPES::ARM:
148 case Header::MACHINE_TYPES::ARMNT:
149 case Header::MACHINE_TYPES::THUMB:
return TYPE(value +
ARM);
151 case Header::MACHINE_TYPES::R4000:
return TYPE(value +
MIPS);
200 Relocation() =
default;
201 uint32_t symbol_idx_ = 0;
204 Symbol* symbol_ =
nullptr;
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:34
Definition COFF/Parser.hpp:36
static constexpr uint32_t MIPS
Definition COFF/Relocation.hpp:41
TYPE type() const
Type of the relocation.
Definition COFF/Relocation.hpp:177
Section * section()
Section in which the relocation takes place.
Definition COFF/Relocation.hpp:182
static constexpr uint32_t X64
Definition COFF/Relocation.hpp:38
~Relocation() override=default
TYPE
The different relocation types.
Definition COFF/Relocation.hpp:47
@ UNKNOWN
Definition COFF/Relocation.hpp:48
static constexpr uint32_t ARM
Definition COFF/Relocation.hpp:39
static constexpr uint32_t I386
Definition COFF/Relocation.hpp:37
static constexpr uint32_t ARM64
Definition COFF/Relocation.hpp:40
static std::unique_ptr< Relocation > parse(BinaryStream &stream, Header::MACHINE_TYPES arch)
Create a relocation from the given stream.
static TYPE from_value(uint16_t value, Header::MACHINE_TYPES arch)
Create a relocation type from its raw value and the architecture.
Definition COFF/Relocation.hpp:139
friend std::ostream & operator<<(std::ostream &os, const Relocation &R)
Definition COFF/Relocation.hpp:192
uint32_t symbol_idx() const
Symbol index associated with this relocation.
Definition COFF/Relocation.hpp:163
const Symbol * symbol() const
Definition COFF/Relocation.hpp:172
std::string to_string() const
friend class Parser
Definition COFF/Relocation.hpp:35
Symbol * symbol()
Symbol associated with the relocation (if any).
Definition COFF/Relocation.hpp:168
static uint16_t to_value(TYPE rtype)
Convert a relocation enum type into a 16-bits value.
Definition COFF/Relocation.hpp:134
const Section * section() const
Definition COFF/Relocation.hpp:186
This class represents a COFF section.
Definition COFF/Section.hpp:40
This class represents a COFF symbol.
Definition COFF/Symbol.hpp:36
Class which represents an abstracted Relocation.
Definition Abstract/Relocation.hpp:26
Definition AuxiliarySymbol.hpp:29
const char * to_string(AuxiliarySectionDefinition::COMDAT_SELECTION e)
LIEF namespace.
Definition Abstract/Binary.hpp:41
#define LIEF_API
Definition visibility.h:44