LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
PE/Relocation.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2025 R. Thomas
2 * Copyright 2017 - 2025 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_H
17#define LIEF_PE_RELOCATION_H
18#include <vector>
19#include <ostream>
20#include <memory>
21
22#include "LIEF/Object.hpp"
23#include "LIEF/visibility.h"
24#include "LIEF/iterators.hpp"
25
26namespace LIEF {
27class BinaryStream;
28
29namespace PE {
30class Parser;
31class Builder;
32class Binary;
33
34class RelocationEntry;
35
36namespace details {
37struct pe_base_relocation_block;
38}
39class LIEF_API Relocation : public Object {
43 friend class Parser;
44 friend class Builder;
45 friend class Binary;
46
47 public:
48 using entries_t = std::vector<std::unique_ptr<RelocationEntry>>;
49 using it_entries = ref_iterator<entries_t&, RelocationEntry*>;
50 using it_const_entries = const_ref_iterator<const entries_t&, RelocationEntry*>;
51
52 Relocation() = default;
53
54 Relocation(uint32_t base, uint32_t block_size) :
55 Object(),
56 block_size_(block_size),
57 virtual_address_(base)
58 {}
59
60 Relocation(uint32_t base) :
61 Relocation(base, 0)
62 {}
63
64 Relocation(const Relocation& other);
65 Relocation& operator=(Relocation other);
66
67 Relocation(Relocation&&) = default;
68 Relocation& operator=(Relocation&& other) = default;
69
70 Relocation(const details::pe_base_relocation_block& header);
71 ~Relocation() override = default;
72
73 void swap(Relocation& other);
74 uint32_t virtual_address() const {
77 return virtual_address_;
78 }
79 uint32_t block_size() const {
87 return block_size_;
88 }
89 it_const_entries entries() const {
92 return entries_;
93 }
94
95 it_entries entries() {
96 return entries_;
97 }
98
99 void virtual_address(uint32_t virtual_address) {
100 virtual_address_ = virtual_address;
101 }
102
103 void block_size(uint32_t block_size) {
104 block_size_ = block_size;
105 }
106
107 RelocationEntry& add_entry(const RelocationEntry& entry);
108
109 void accept(Visitor& visitor) const override;
110
111 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Relocation& relocation);
112
113
114 using relocations_t = std::vector<std::unique_ptr<Relocation>>;
115
116 LIEF_LOCAL static relocations_t parse(Parser& ctx, BinaryStream& stream);
117
118 private:
119 uint32_t block_size_ = 0;
120 uint32_t virtual_address_ = 0;
121 entries_t entries_;
122};
123
124}
125}
126#endif /* RELOCATION_H */
Object.hpp
LIEF::BinaryStream
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:33
LIEF::PE::Binary
Class which represents a PE binary This is the main interface to manage and modify a PE executable.
Definition PE/Binary.hpp:56
LIEF::PE::Builder
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:45
LIEF::PE::Parser
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:52
LIEF::PE::RelocationEntry
Class which represents an entry of the PE relocation table.
Definition RelocationEntry.hpp:36
LIEF::PE::Relocation
Class which represents the Base Relocation Block We usually find this structure in the ....
Definition PE/Relocation.hpp:42
LIEF::PE::Relocation::operator=
Relocation & operator=(Relocation other)
LIEF::PE::Relocation::entries
it_entries entries()
Definition PE/Relocation.hpp:95
LIEF::PE::Relocation::accept
void accept(Visitor &visitor) const override
LIEF::PE::Relocation::block_size
uint32_t block_size() const
The total number of bytes in the base relocation block.
Definition PE/Relocation.hpp:86
LIEF::PE::Relocation::swap
void swap(Relocation &other)
LIEF::PE::Relocation::parse
static relocations_t parse(Parser &ctx, BinaryStream &stream)
LIEF::PE::Relocation::Relocation
Relocation()=default
LIEF::PE::Relocation::virtual_address
uint32_t virtual_address() const
The RVA for which the offset of the relocation entries (RelocationEntry) is added.
Definition PE/Relocation.hpp:76
LIEF::PE::Relocation::add_entry
RelocationEntry & add_entry(const RelocationEntry &entry)
LIEF::PE::Relocation::Relocation
Relocation(uint32_t base)
Definition PE/Relocation.hpp:60
LIEF::PE::Relocation::virtual_address
void virtual_address(uint32_t virtual_address)
Definition PE/Relocation.hpp:99
LIEF::PE::Relocation::~Relocation
~Relocation() override=default
LIEF::PE::Relocation::entries
it_const_entries entries() const
Iterator over the RelocationEntry.
Definition PE/Relocation.hpp:91
LIEF::PE::Relocation::Relocation
Relocation(const details::pe_base_relocation_block &header)
LIEF::PE::Relocation::Relocation
Relocation(const Relocation &other)
LIEF::PE::Relocation::operator<<
friend std::ostream & operator<<(std::ostream &os, const Relocation &relocation)
LIEF::PE::Relocation::operator=
Relocation & operator=(Relocation &&other)=default
LIEF::PE::Relocation::Relocation
Relocation(Relocation &&)=default
LIEF::PE::Relocation::Relocation
Relocation(uint32_t base, uint32_t block_size)
Definition PE/Relocation.hpp:54
LIEF::PE::Relocation::block_size
void block_size(uint32_t block_size)
Definition PE/Relocation.hpp:103
iterators.hpp
LIEF::PE::details
Definition DataDirectory.hpp:37
LIEF::PE
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41
LIEF_LOCAL
#define LIEF_LOCAL
Definition visibility.h:42