LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
RelocationEntry.hpp
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 Quarkslab
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef LIEF_PE_RELOCATION_ENTRY_H
17#define LIEF_PE_RELOCATION_ENTRY_H
18
19#include <ostream>
20
21#include "LIEF/Abstract/Relocation.hpp"
22
23#include "LIEF/Object.hpp"
24#include "LIEF/visibility.h"
25
26#include "LIEF/PE/Header.hpp"
27
28namespace LIEF {
29namespace PE {
30
31class Relocation;
32
36class LIEF_API RelocationEntry : public LIEF::Relocation {
37
38 friend class Parser;
39 friend class Builder;
40 friend class PE::Relocation;
41
42 public:
43 enum class BASE_TYPES {
44 UNKNOWN = -1,
45
46 ABS = 0,
47 HIGH = 1,
48 LOW = 2,
49 HIGHLOW = 3,
50 HIGHADJ = 4,
51
52 MIPS_JMPADDR = 5,
53 ARM_MOV32A = 5 + 0x101,
54 ARM_MOV32 = 5 + 0x102,
55 RISCV_HI20 = 5 + 0x103,
56
57 SECTION = 6,
58
59 REL = 7,
60 ARM_MOV32T = 7 + 0x201,
61 THUMB_MOV32 = 7 + 0x202,
62 RISCV_LOW12I = 7 + 0x203,
63
64 RISCV_LOW12S = 8,
65
66 IA64_IMM64 = 9,
67 MIPS_JMPADDR16 = 9 + 0x300,
68
69 DIR64 = 10,
70 HIGH3ADJ = 11,
71 };
72 static RelocationEntry from_raw(Header::MACHINE_TYPES arch, uint16_t raw) {
73 return RelocationEntry(raw, arch);
74 }
75
76 RelocationEntry() = default;
77 RelocationEntry(const RelocationEntry& other);
78 RelocationEntry& operator=(RelocationEntry other);
79
80 RelocationEntry(uint16_t position, BASE_TYPES type);
81 ~RelocationEntry() override = default;
82
83 void swap(RelocationEntry& other);
84
86 uint64_t address() const override;
87
88 void address(uint64_t address) override;
89
91 size_t size() const override;
92
93 void size(size_t size) override;
94
98 uint16_t data() const;
99
101 uint16_t position() const {
102 return position_;
103 }
104
106 BASE_TYPES type() const {
107 return type_;
108 }
109
110 void data(uint16_t data);
111
112 void position(uint16_t position) {
113 position_ = position;
114 }
115
116 void type(BASE_TYPES type) {
117 type_ = type;
118 }
119
120 void accept(Visitor& visitor) const override;
121
122 LIEF_API friend std::ostream& operator<<(std::ostream& os, const RelocationEntry& entry);
123
124 private:
125 RelocationEntry(uint16_t data, Header::MACHINE_TYPES arch);
126
127 uint16_t position_ = 0;
128 BASE_TYPES type_ = BASE_TYPES::ABS;
129 Header::MACHINE_TYPES arch_ = Header::MACHINE_TYPES::UNKNOWN;
130 PE::Relocation* relocation_ = nullptr; // Used to compute some information
131};
132
133LIEF_API const char* to_string(RelocationEntry::BASE_TYPES e);
134
135}
136}
137#endif
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:45
MACHINE_TYPES
Definition PE/Header.hpp:40
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:47
Class which represents an entry of the PE relocation table.
Definition RelocationEntry.hpp:36
size_t size() const override
The size of the relocatable pointer.
uint16_t position() const
Offset relative to Relocation::virtual_address where the relocation occurs.
Definition RelocationEntry.hpp:101
uint16_t data() const
Raw data of the relocation:
uint64_t address() const override
The address of the relocation.
void accept(Visitor &visitor) const override
Method so that the visitor can visit us.
BASE_TYPES type() const
Type of the relocation.
Definition RelocationEntry.hpp:106
Class which represents the Base Relocation Block We usually find this structure in the ....
Definition PE/Relocation.hpp:37
Class which represents an abstracted Relocation.
Definition Abstract/Relocation.hpp:27
Definition Visitor.hpp:219
LIEF namespace.
Definition Abstract/Binary.hpp:32