LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
RelocationEntry.hpp
Go to the documentation of this file.
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
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;
32class 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 uint64_t address() const override;
87
88 void address(uint64_t address) override;
89 size_t size() const override;
92
93 void size(size_t size) override;
94 uint16_t data() const;
99 uint16_t position() const {
102 return position_;
103 }
104 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
Relocation.hpp
Object.hpp
Header.hpp
LIEF::PE::RelocationEntry
Class which represents an entry of the PE relocation table.
Definition RelocationEntry.hpp:36
LIEF::PE::RelocationEntry::address
void address(uint64_t address) override
LIEF::PE::RelocationEntry::operator=
RelocationEntry & operator=(RelocationEntry other)
LIEF::PE::RelocationEntry::swap
void swap(RelocationEntry &other)
LIEF::PE::RelocationEntry::size
size_t size() const override
The size of the relocatable pointer.
LIEF::PE::RelocationEntry::size
void size(size_t size) override
LIEF::PE::RelocationEntry::position
uint16_t position() const
Offset relative to Relocation::virtual_address where the relocation occurs.
Definition RelocationEntry.hpp:101
LIEF::PE::RelocationEntry::RelocationEntry
RelocationEntry()=default
LIEF::PE::RelocationEntry::data
void data(uint16_t data)
LIEF::PE::RelocationEntry::data
uint16_t data() const
Raw data of the relocation:
LIEF::PE::RelocationEntry::RelocationEntry
RelocationEntry(uint16_t position, BASE_TYPES type)
LIEF::PE::RelocationEntry::address
uint64_t address() const override
The address of the relocation.
LIEF::PE::RelocationEntry::operator<<
friend std::ostream & operator<<(std::ostream &os, const RelocationEntry &entry)
LIEF::PE::RelocationEntry::accept
void accept(Visitor &visitor) const override
Method so that the visitor can visit us.
LIEF::PE::RelocationEntry::RelocationEntry
RelocationEntry(const RelocationEntry &other)
LIEF::PE::RelocationEntry::position
void position(uint16_t position)
Definition RelocationEntry.hpp:112
LIEF::PE::RelocationEntry::~RelocationEntry
~RelocationEntry() override=default
LIEF::PE::RelocationEntry::BASE_TYPES
BASE_TYPES
Definition RelocationEntry.hpp:43
LIEF::PE::RelocationEntry::from_raw
static RelocationEntry from_raw(Header::MACHINE_TYPES arch, uint16_t raw)
Definition RelocationEntry.hpp:72
LIEF::PE::RelocationEntry::type
void type(BASE_TYPES type)
Definition RelocationEntry.hpp:116
LIEF::PE::RelocationEntry::type
BASE_TYPES type() const
Type of the relocation.
Definition RelocationEntry.hpp:106
LIEF::PE::Relocation
Class which represents the Base Relocation Block We usually find this structure in the ....
Definition PE/Relocation.hpp:37
LIEF::PE
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF::PE::to_string
const char * to_string(DataDirectory::TYPES e)
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41