LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
DataDirectory.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 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
22#include "LIEF/Object.hpp"
23#include "LIEF/visibility.h"
24
25namespace LIEF {
26namespace PE {
27
28class Builder;
29class Parser;
30class Binary;
31class Section;
32
33namespace details {
34struct pe_data_directory;
35}
36
39
40 friend class Builder;
41 friend class Parser;
42 friend class Binary;
43
44 public:
45 static constexpr size_t DEFAULT_NB = 16;
46
47 enum class TYPES: uint32_t {
48 EXPORT_TABLE = 0,
49 IMPORT_TABLE,
50 RESOURCE_TABLE,
51 EXCEPTION_TABLE,
52 CERTIFICATE_TABLE,
53 BASE_RELOCATION_TABLE,
54 DEBUG_DIR,
55 ARCHITECTURE,
56 GLOBAL_PTR,
57 TLS_TABLE,
58 LOAD_CONFIG_TABLE,
59 BOUND_IMPORT,
60 IAT,
61 DELAY_IMPORT_DESCRIPTOR,
62 CLR_RUNTIME_HEADER,
63 RESERVED,
64
65 UNKNOWN,
66 };
67 DataDirectory() = default;
69 type_{type}
70 {}
71
72 DataDirectory(const details::pe_data_directory& header, TYPES type);
73
74 DataDirectory(const DataDirectory& other) = default;
75 DataDirectory& operator=(const DataDirectory& other) = default;
76
77 DataDirectory(DataDirectory&& other) noexcept = default;
78 DataDirectory& operator=(DataDirectory&& other) noexcept = default;
79
80 ~DataDirectory() override = default;
81
84 uint32_t RVA() const {
85 return rva_;
86 }
87
89 uint32_t size() const {
90 return size_;
91 }
92
95 bool has_section() const {
96 return section_ != nullptr;
97 }
98
101 return section_;
102 }
103 const Section* section() const {
104 return section_;
105 }
106
108 TYPES type() const {
109 return type_;
110 }
111
112 void size(uint32_t size) {
113 size_ = size;
114 }
115
116 void RVA(uint32_t rva) {
117 rva_ = rva;
118 }
119
120 void accept(Visitor& visitor) const override;
121
122 LIEF_API friend std::ostream& operator<<(std::ostream& os, const DataDirectory& entry);
123
124 private:
125 uint32_t rva_ = 0;
126 uint32_t size_ = 0;
127 TYPES type_ = TYPES::UNKNOWN;
128 Section* section_ = nullptr;
129};
130
132
133}
134}
135
136#endif /* LIEF_PE_DATADIRECTORY_H */
Definition Object.hpp:25
Class which represents a PE binary This is the main interface to manage and modify a PE executable.
Definition PE/Binary.hpp:52
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:45
Class that represents a PE data directory entry.
Definition DataDirectory.hpp:38
const Section * section() const
Definition DataDirectory.hpp:103
DataDirectory(TYPES type)
Definition DataDirectory.hpp:68
uint32_t RVA() const
The relative virtual address of the content of this data directory.
Definition DataDirectory.hpp:84
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 Cection.
Definition DataDirectory.hpp:95
void accept(Visitor &visitor) const override
void RVA(uint32_t rva)
Definition DataDirectory.hpp:116
void size(uint32_t size)
Definition DataDirectory.hpp:112
DataDirectory(const DataDirectory &other)=default
TYPES type() const
Type of the data directory.
Definition DataDirectory.hpp:108
TYPES
Definition DataDirectory.hpp:47
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:100
uint32_t size() const
The size of the content.
Definition DataDirectory.hpp:89
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:47
Class which represents a PE section.
Definition PE/Section.hpp:40
Definition Visitor.hpp:224
const char * to_string(DataDirectory::TYPES e)
LIEF namespace.
Definition Abstract/Binary.hpp:32
#define LIEF_API
Definition visibility.h:41