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