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}
40class 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>>;
50 using it_entries = ref_iterator<entries_t&, RelocationEntry*>;
51 using it_const_entries = const_ref_iterator<const entries_t&, RelocationEntry*>;
52
54 Relocation(uint32_t base, uint32_t block_size);
55 Relocation(uint32_t base);
56
57 Relocation(const Relocation& other);
58 Relocation& operator=(Relocation other);
59
60 Relocation(Relocation&&);
61 Relocation& operator=(Relocation&& other);
62
63 Relocation(const details::pe_base_relocation_block& header);
64 ~Relocation() override;
65
66 void swap(Relocation& other);
67 uint32_t virtual_address() const {
70 return virtual_address_;
71 }
72 uint32_t block_size() const {
80 return block_size_;
81 }
82 it_const_entries entries() const {
85 return entries_;
86 }
87
88 it_entries entries() {
89 return entries_;
90 }
91
92 void virtual_address(uint32_t virtual_address) {
93 virtual_address_ = virtual_address;
94 }
95
96 void block_size(uint32_t block_size) {
97 block_size_ = block_size;
98 }
99
100 RelocationEntry& add_entry(const RelocationEntry& entry);
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
108 LIEF_LOCAL static relocations_t parse(Parser& ctx, BinaryStream& stream);
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 */
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:43
LIEF::PE::Relocation::operator=
Relocation & operator=(Relocation other)
LIEF::PE::Relocation::Relocation
Relocation()
LIEF::PE::Relocation::entries
it_entries entries()
Definition PE/Relocation.hpp:88
LIEF::PE::Relocation::Relocation
Relocation(Relocation &&)
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:79
LIEF::PE::Relocation::swap
void swap(Relocation &other)
LIEF::PE::Relocation::~Relocation
~Relocation() override
LIEF::PE::Relocation::operator=
Relocation & operator=(Relocation &&other)
LIEF::PE::Relocation::parse
static relocations_t parse(Parser &ctx, BinaryStream &stream)
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:69
LIEF::PE::Relocation::add_entry
RelocationEntry & add_entry(const RelocationEntry &entry)
LIEF::PE::Relocation::Relocation
Relocation(uint32_t base)
LIEF::PE::Relocation::virtual_address
void virtual_address(uint32_t virtual_address)
Definition PE/Relocation.hpp:92
LIEF::PE::Relocation::entries
it_const_entries entries() const
Iterator over the RelocationEntry.
Definition PE/Relocation.hpp:84
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::Relocation
Relocation(uint32_t base, uint32_t block_size)
LIEF::PE::Relocation::block_size
void block_size(uint32_t block_size)
Definition PE/Relocation.hpp:96
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