LIEF: Library to Instrument Executable Formats Version 0.17.0
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}
36class LIEF_API DataDirectory : public Object {
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;
68 DataDirectory(TYPES type) :
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 uint32_t RVA() const {
85 return rva_;
86 }
87 uint32_t size() const {
90 return size_;
91 }
92 bool has_section() const {
96 return section_ != nullptr;
97 }
98 Section* section() {
101 return section_;
102 }
103 const Section* section() const {
104 return section_;
105 }
106 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
131LIEF_API const char* to_string(DataDirectory::TYPES e);
132
133}
134}
135
136#endif /* LIEF_PE_DATADIRECTORY_H */
Object.hpp
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:52
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::DataDirectory
Class that represents a PE data directory entry.
Definition DataDirectory.hpp:38
LIEF::PE::DataDirectory::section
const Section * section() const
Definition DataDirectory.hpp:103
LIEF::PE::DataDirectory::DataDirectory
DataDirectory(TYPES type)
Definition DataDirectory.hpp:68
LIEF::PE::DataDirectory::RVA
uint32_t RVA() const
The relative virtual address of the content of this data directory.
Definition DataDirectory.hpp:84
LIEF::PE::DataDirectory::operator=
DataDirectory & operator=(DataDirectory &&other) noexcept=default
LIEF::PE::DataDirectory::DataDirectory
DataDirectory(const details::pe_data_directory &header, TYPES type)
LIEF::PE::DataDirectory::~DataDirectory
~DataDirectory() override=default
LIEF::PE::DataDirectory::DataDirectory
DataDirectory(DataDirectory &&other) noexcept=default
LIEF::PE::DataDirectory::has_section
bool has_section() const
Check if the content of this data directory is associated with a PE Cection.
Definition DataDirectory.hpp:95
LIEF::PE::DataDirectory::accept
void accept(Visitor &visitor) const override
LIEF::PE::DataDirectory::RVA
void RVA(uint32_t rva)
Definition DataDirectory.hpp:116
LIEF::PE::DataDirectory::DataDirectory
DataDirectory()=default
LIEF::PE::DataDirectory::size
void size(uint32_t size)
Definition DataDirectory.hpp:112
LIEF::PE::DataDirectory::DataDirectory
DataDirectory(const DataDirectory &other)=default
LIEF::PE::DataDirectory::type
TYPES type() const
Type of the data directory.
Definition DataDirectory.hpp:108
LIEF::PE::DataDirectory::TYPES
TYPES
Definition DataDirectory.hpp:47
LIEF::PE::DataDirectory::operator=
DataDirectory & operator=(const DataDirectory &other)=default
LIEF::PE::DataDirectory::operator<<
friend std::ostream & operator<<(std::ostream &os, const DataDirectory &entry)
LIEF::PE::DataDirectory::section
Section * section()
Section associated with the DataDirectory.
Definition DataDirectory.hpp:100
LIEF::PE::DataDirectory::size
uint32_t size() const
The size of the content.
Definition DataDirectory.hpp:89
LIEF::PE::Parser
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:47
LIEF::PE::Section
Class which represents a PE section.
Definition PE/Section.hpp:43
LIEF::PE::details
Definition CodeIntegrity.hpp:26
LIEF::PE
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF::PE::to_string
const char * to_string(DataDirectory::TYPES e)
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41