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 <cstdint>
19#include <vector>
20#include <ostream>
21#include <memory>
22
23#include "LIEF/Object.hpp"
24#include "LIEF/visibility.h"
25#include "LIEF/iterators.hpp"
26
27namespace LIEF {
28class BinaryStream;
29
30namespace PE {
31class Parser;
32class Builder;
33class Binary;
34
35class RelocationEntry;
36
37namespace details {
38struct pe_base_relocation_block;
39}
40
43class LIEF_API Relocation : public Object {
44 friend class Parser;
45 friend class Builder;
46 friend class Binary;
47
48 public:
49 using entries_t = std::vector<std::unique_ptr<RelocationEntry>>;
52
54 Relocation(uint32_t base, uint32_t block_size);
55 Relocation(uint32_t base);
56
57 Relocation(const Relocation& other);
59
62
63 Relocation(const details::pe_base_relocation_block& header);
64 ~Relocation() override;
65
66 void swap(Relocation& other);
67
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, const Relocation& relocation);
105
106 using relocations_t = std::vector<std::unique_ptr<Relocation>>;
107
109
110 private:
111 uint32_t block_size_ = 0;
112 uint32_t virtual_address_ = 0;
113 entries_t entries_;
114};
115
116}
117}
118#endif /* RELOCATION_H */
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:33
Class which represents a PE binary This is the main interface to manage and modify a PE executable.
Definition PE/Binary.hpp:57
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:45
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:52
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:51
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:50
~Relocation() override
std::vector< std::unique_ptr< Relocation > > relocations_t
Definition PE/Relocation.hpp:106
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:49
void virtual_address(uint32_t virtual_address)
Definition PE/Relocation.hpp:92
friend class Builder
Definition PE/Relocation.hpp:45
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:46
Relocation(const Relocation &other)
friend class Parser
Definition PE/Relocation.hpp:44
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:210
Iterator which returns reference on container's values.
Definition iterators.hpp:46
Definition DataDirectory.hpp:37
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF namespace.
Definition Abstract/Binary.hpp:40
ref_iterator< CT, U, typename decay_t< CT >::const_iterator > const_ref_iterator
Iterator which return const ref on container's values.
Definition iterators.hpp:257
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42