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 <string>
20#include <ostream>
21
22#include "LIEF/Abstract/Relocation.hpp"
23
24#include "LIEF/Object.hpp"
25#include "LIEF/visibility.h"
26
27#include "LIEF/PE/Header.hpp"
28
29namespace LIEF {
30namespace PE {
31
32class Relocation;
33
37class LIEF_API RelocationEntry : public LIEF::Relocation {
38
39 friend class Parser;
40 friend class Builder;
41 friend class PE::Relocation;
42
43 public:
44 enum class BASE_TYPES {
45 UNKNOWN = -1,
46
47 ABS = 0,
48 HIGH = 1,
49 LOW = 2,
50 HIGHLOW = 3,
51 HIGHADJ = 4,
52
53 MIPS_JMPADDR = 5,
54 ARM_MOV32A = 5 + 0x101,
55 ARM_MOV32 = 5 + 0x102,
56 RISCV_HI20 = 5 + 0x103,
57
58 SECTION = 6,
59
60 REL = 7,
61 ARM_MOV32T = 7 + 0x201,
62 THUMB_MOV32 = 7 + 0x202,
63 RISCV_LOW12I = 7 + 0x203,
64
65 RISCV_LOW12S = 8,
66
67 IA64_IMM64 = 9,
68 MIPS_JMPADDR16 = 9 + 0x300,
69
70 DIR64 = 10,
71 HIGH3ADJ = 11,
72 };
73 static RelocationEntry from_raw(Header::MACHINE_TYPES arch, uint16_t raw) {
74 return RelocationEntry(raw, arch);
75 }
76
77 RelocationEntry() = default;
78 RelocationEntry(const RelocationEntry& other);
79 RelocationEntry& operator=(RelocationEntry other);
80
81 RelocationEntry(uint16_t position, BASE_TYPES type);
82 ~RelocationEntry() override = default;
83
84 void swap(RelocationEntry& other);
85
87 uint64_t address() const override;
88
89 void address(uint64_t address) override;
90
92 size_t size() const override;
93
94 void size(size_t size) override;
95
99 uint16_t data() const;
100
102 uint16_t position() const {
103 return position_;
104 }
105
107 BASE_TYPES type() const {
108 return type_;
109 }
110
111 void data(uint16_t data);
112
113 void position(uint16_t position) {
114 position_ = position;
115 }
116
117 void type(BASE_TYPES type) {
118 type_ = type;
119 }
120
121 void accept(Visitor& visitor) const override;
122
123 LIEF_API friend std::ostream& operator<<(std::ostream& os, const RelocationEntry& entry);
124
125 private:
126 RelocationEntry(uint16_t data, Header::MACHINE_TYPES arch);
127
128 uint16_t position_ = 0;
129 BASE_TYPES type_ = BASE_TYPES::ABS;
130 Header::MACHINE_TYPES arch_ = Header::MACHINE_TYPES::UNKNOWN;
131 PE::Relocation* relocation_ = nullptr; // Used to compute some information
132};
133
134LIEF_API const char* to_string(RelocationEntry::BASE_TYPES e);
135
136}
137}
138#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:37
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:102
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:107
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