LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
DataDirectory.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 * Copyright 2017 - 2026 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_DATADIRECTORY_H
17#define LIEF_PE_DATADIRECTORY_H
18
19#include <cstdint>
20#include <ostream>
21#include <memory>
22
23#include "LIEF/Object.hpp"
24#include "LIEF/visibility.h"
25#include "LIEF/span.hpp"
26
27namespace LIEF {
28class SpanStream;
29
30namespace PE {
31
32class Builder;
33class Parser;
34class Binary;
35class Section;
36
37namespace details {
38struct pe_data_directory;
39}
40
43
44 friend class Builder;
45 friend class Parser;
46 friend class Binary;
47
48 public:
49 static constexpr size_t DEFAULT_NB = 16;
50
51 enum class TYPES : uint32_t {
52 EXPORT_TABLE = 0,
53 IMPORT_TABLE,
54 RESOURCE_TABLE,
55 EXCEPTION_TABLE,
56 CERTIFICATE_TABLE,
57 BASE_RELOCATION_TABLE,
58 DEBUG_DIR,
59 ARCHITECTURE,
60 GLOBAL_PTR,
61 TLS_TABLE,
62 LOAD_CONFIG_TABLE,
63 BOUND_IMPORT,
64 IAT,
65 DELAY_IMPORT_DESCRIPTOR,
66 CLR_RUNTIME_HEADER,
67 RESERVED,
68
69 UNKNOWN,
70 };
71 DataDirectory() = default;
73 type_{type} {}
74
75 DataDirectory(const details::pe_data_directory& header, TYPES type);
76
77 DataDirectory(const DataDirectory& other) = default;
78 DataDirectory& operator=(const DataDirectory& other) = default;
79
80 DataDirectory(DataDirectory&& other) noexcept = default;
81 DataDirectory& operator=(DataDirectory&& other) noexcept = default;
82
83 ~DataDirectory() override = default;
84
87 uint32_t RVA() const {
88 return rva_;
89 }
90
92 uint32_t size() const {
93 return size_;
94 }
95
98 bool has_section() const {
99 return section_ != nullptr;
100 }
101
104 return const_cast<DataDirectory*>(this)->content();
105 }
106
108
111 return section_;
112 }
113
114 const Section* section() const {
115 return section_;
116 }
117
119 TYPES type() const {
120 return type_;
121 }
122
123 void size(uint32_t size) {
124 size_ = size;
125 }
126
127 void RVA(uint32_t rva) {
128 rva_ = rva;
129 }
130
131 void accept(Visitor& visitor) const override;
132
133 LIEF_API friend std::ostream& operator<<(std::ostream& os,
134 const DataDirectory& entry);
135
138 std::unique_ptr<SpanStream> stream(bool sized = true) const;
139
140 private:
141 uint32_t rva_ = 0;
142 uint32_t size_ = 0;
143 TYPES type_ = TYPES::UNKNOWN;
144 Section* section_ = nullptr;
145};
146
148
149}
150}
151
152#endif /* LIEF_PE_DATADIRECTORY_H */
Class which represents a PE binary This is the main interface to manage and modify a PE executable.
Definition PE/Binary.hpp:56
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:45
const Section * section() const
Definition DataDirectory.hpp:114
span< uint8_t > content()
DataDirectory(TYPES type)
Definition DataDirectory.hpp:72
uint32_t RVA() const
The relative virtual address of the content of this data directory.
Definition DataDirectory.hpp:87
static constexpr size_t DEFAULT_NB
Definition DataDirectory.hpp:49
DataDirectory & operator=(DataDirectory &&other) noexcept=default
DataDirectory(const details::pe_data_directory &header, TYPES type)
~DataDirectory() override=default
DataDirectory(DataDirectory &&other) noexcept=default
bool has_section() const
Check if the content of this data directory is associated with a PE Section.
Definition DataDirectory.hpp:98
friend class Builder
Definition DataDirectory.hpp:44
void accept(Visitor &visitor) const override
void RVA(uint32_t rva)
Definition DataDirectory.hpp:127
span< const uint8_t > content() const
Raw content (bytes) referenced by this data directory.
Definition DataDirectory.hpp:103
friend class Binary
Definition DataDirectory.hpp:46
void size(uint32_t size)
Definition DataDirectory.hpp:123
DataDirectory(const DataDirectory &other)=default
friend class Parser
Definition DataDirectory.hpp:45
TYPES type() const
Type of the data directory.
Definition DataDirectory.hpp:119
TYPES
Definition DataDirectory.hpp:51
@ UNKNOWN
Definition DataDirectory.hpp:69
DataDirectory & operator=(const DataDirectory &other)=default
friend std::ostream & operator<<(std::ostream &os, const DataDirectory &entry)
Section * section()
Section associated with the DataDirectory.
Definition DataDirectory.hpp:110
uint32_t size() const
The size of the content.
Definition DataDirectory.hpp:92
Main interface to parse PE binaries. In particular, the static Parser::parse functions should be used...
Definition PE/Parser.hpp:52
Class which represents a PE section.
Definition PE/Section.hpp:46
Definition SpanStream.hpp:32
Definition Visitor.hpp:212
Definition DataDirectory.hpp:37
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
const char * to_string(CODE_PAGES e)
LIEF namespace.
Definition Abstract/Binary.hpp:40
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:43
#define LIEF_LOCAL
Definition visibility.h:44