LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
PE/Relocation.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LIEF_PE_RELOCATION_H
16#define LIEF_PE_RELOCATION_H
17#include <cstdint>
18#include <memory>
19#include <ostream>
20#include <vector>
21
22#include "LIEF/Object.hpp"
23#include "LIEF/iterators.hpp"
24#include "LIEF/visibility.h"
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}
39
42class 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>>;
51
53 Relocation(uint32_t base, uint32_t block_size);
54 Relocation(uint32_t base);
55
56 Relocation(const Relocation& other);
58
61
62 Relocation(const details::pe_base_relocation_block& header);
63 ~Relocation() override;
64
65 void swap(Relocation& other);
66
69 uint32_t virtual_address() const {
70 return virtual_address_;
71 }
72
79 uint32_t block_size() const {
80 return block_size_;
81 }
82
85 return entries_;
86 }
87
89 return entries_;
90 }
91
93 virtual_address_ = virtual_address;
94 }
95
96 void block_size(uint32_t block_size) {
97 block_size_ = block_size;
98 }
99
101
102 void accept(Visitor& visitor) const override;
103
104 LIEF_API friend std::ostream& operator<<(std::ostream& os,
105 const Relocation& relocation);
106
107 using relocations_t = std::vector<std::unique_ptr<Relocation>>;
108
110
111 private:
112 uint32_t block_size_ = 0;
113 uint32_t virtual_address_ = 0;
114 entries_t entries_;
115};
116
117}
118}
119#endif
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:34
Class which represents a PE binary This is the main interface to manage and modify a PE executable.
Definition PE/Binary.hpp:58
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:43
Main interface to parse PE binaries. In particular, the static Parser::parse functions should be used...
Definition PE/Parser.hpp:53
Class which represents an entry of the PE relocation table.
Definition RelocationEntry.hpp:36
const_ref_iterator< const entries_t &, RelocationEntry * > it_const_entries
Definition PE/Relocation.hpp:50
Relocation & operator=(Relocation other)
it_entries entries()
Definition PE/Relocation.hpp:88
Relocation(Relocation &&)
void accept(Visitor &visitor) const override
uint32_t block_size() const
The total number of bytes in the base relocation block.
Definition PE/Relocation.hpp:79
void swap(Relocation &other)
ref_iterator< entries_t &, RelocationEntry * > it_entries
Definition PE/Relocation.hpp:49
~Relocation() override
std::vector< std::unique_ptr< Relocation > > relocations_t
Definition PE/Relocation.hpp:107
Relocation & operator=(Relocation &&other)
static relocations_t parse(Parser &ctx, BinaryStream &stream)
uint32_t virtual_address() const
The RVA for which the offset of the relocation entries (RelocationEntry) is added.
Definition PE/Relocation.hpp:69
RelocationEntry & add_entry(const RelocationEntry &entry)
Relocation(uint32_t base)
std::vector< std::unique_ptr< RelocationEntry > > entries_t
Definition PE/Relocation.hpp:48
void virtual_address(uint32_t virtual_address)
Definition PE/Relocation.hpp:92
friend class Builder
Definition PE/Relocation.hpp:44
it_const_entries entries() const
Iterator over the RelocationEntry.
Definition PE/Relocation.hpp:84
Relocation(const details::pe_base_relocation_block &header)
friend class Binary
Definition PE/Relocation.hpp:45
Relocation(const Relocation &other)
friend class Parser
Definition PE/Relocation.hpp:43
friend std::ostream & operator<<(std::ostream &os, const Relocation &relocation)
Relocation(uint32_t base, uint32_t block_size)
void block_size(uint32_t block_size)
Definition PE/Relocation.hpp:96
Definition Visitor.hpp:211
Iterator which returns reference on container's values.
Definition iterators.hpp:120
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition DataDirectory.hpp:37
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:31
LIEF namespace.
Definition Abstract/Binary.hpp:41
ref_iterator< CT, U, typename decay_t< CT >::const_iterator > const_ref_iterator
Iterator which returns a const ref on container's values.
Definition iterators.hpp:385
#define LIEF_API
Definition visibility.h:44
#define LIEF_LOCAL
Definition visibility.h:45