LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
Export.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_EXPORT_H
17#define LIEF_PE_EXPORT_H
18
19#include <ostream>
20#include <string>
21
22#include "LIEF/Object.hpp"
23#include "LIEF/visibility.h"
24#include "LIEF/iterators.hpp"
26
27namespace LIEF {
28namespace PE {
29
30class Builder;
31class Parser;
32
33namespace details {
34struct pe_export_directory_table;
35}
36class LIEF_API Export : public Object {
39 friend class Builder;
40 friend class Parser;
41
42 public:
43 using entries_t = std::vector<ExportEntry>;
44 using it_entries = ref_iterator<entries_t&>;
45 using it_const_entries = const_ref_iterator<const entries_t&>;
46
47 Export() = default;
48
49 Export(std::string name, const entries_t& entries) :
50 name_(std::move(name))
51 {
52 for (const ExportEntry& E : entries) {
53 add_entry(E);
54 }
55 }
56
57 Export(std::string name) :
58 Export(std::move(name), {})
59 {}
60
61 Export(const details::pe_export_directory_table& header);
62
63 Export(const Export&) = default;
64 Export& operator=(const Export&) = default;
65
66 Export(Export&&) = default;
67 Export& operator=(Export&&) = default;
68
69 ~Export() override = default;
70 uint32_t export_flags() const {
74 return export_flags_;
75 }
76 uint32_t timestamp() const {
79 return timestamp_;
80 }
81 uint16_t major_version() const {
84 return major_version_;
85 }
86 uint16_t minor_version() const {
89 return minor_version_;
90 }
91 uint32_t ordinal_base() const {
94 return ordinal_base_;
95 }
96 const std::string& name() const {
99 return name_;
100 }
101 it_entries entries() {
104 return entries_;
105 }
106
107 it_const_entries entries() const {
108 return entries_;
109 }
110 uint32_t name_rva() const {
113 return name_rva_;
114 }
115 uint32_t export_addr_table_rva() const {
118 return exp_addr_table_rva_;
119 }
120 uint32_t export_addr_table_cnt() const {
123 return exp_addr_table_cnt_;
124 }
125 uint32_t names_addr_table_rva() const {
128 return names_addr_table_rva_;
129 }
130 uint32_t names_addr_table_cnt() const {
133 return names_addr_table_cnt_;
134 }
135 uint32_t ord_addr_table_rva() const {
138 return ord_addr_table_rva_;
139 }
140
141 void export_flags(uint32_t flags) {
142 export_flags_ = flags;
143 }
144
145 void timestamp(uint32_t timestamp) {
146 timestamp_ = timestamp;
147 }
148
149 void major_version(uint16_t major_version) {
150 major_version_ = major_version;
151 }
152
153 void minor_version(uint16_t minor_version) {
154 minor_version_ = minor_version;
155 }
156
157 void ordinal_base(uint32_t ordinal_base) {
158 ordinal_base_ = ordinal_base;
159 }
160
161 void name(std::string name) {
162 name_ = std::move(name);
163 }
164 const ExportEntry* find_entry(const std::string& name) const;
167
168 ExportEntry* find_entry(const std::string& name) {
169 return const_cast<ExportEntry*>(static_cast<const Export*>(this)->find_entry(name));
170 }
171 const ExportEntry* find_entry(uint32_t ordinal) const;
174
175 ExportEntry* find_entry(uint32_t ordinal) {
176 return const_cast<ExportEntry*>(static_cast<const Export*>(this)->find_entry(ordinal));
177 }
178 const ExportEntry* find_entry_at(uint32_t rva) const;
181
182 ExportEntry* find_entry_at(uint32_t rva) {
183 return const_cast<ExportEntry*>(static_cast<const Export*>(this)->find_entry_at(rva));
184 }
185 ExportEntry& add_entry(const ExportEntry& exp);
188
189 ExportEntry& add_entry(std::string name, uint32_t rva) {
190 return add_entry(ExportEntry(std::move(name), rva));
191 }
192 bool remove_entry(const ExportEntry& exp);
195 bool remove_entry(const std::string& name) {
198 if (const ExportEntry* entry = find_entry(name)) {
199 return remove_entry(*entry);
200 }
201 return false;
202 }
203 bool remove_entry(uint32_t rva) {
206 if (const ExportEntry* entry = find_entry_at(rva)) {
207 return remove_entry(*entry);
208 }
209 return false;
210 }
211
212 void accept(Visitor& visitor) const override;
213
214 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Export& exp);
215
216 private:
217 uint32_t export_flags_ = 0;
218 uint32_t name_rva_ = 0;
219 uint32_t timestamp_ = 0;
220 uint16_t major_version_ = 0;
221 uint16_t minor_version_ = 0;
222 uint32_t ordinal_base_ = 0;
223 uint32_t exp_addr_table_rva_ = 0;
224 uint32_t exp_addr_table_cnt_ = 0;
225 uint32_t names_addr_table_rva_ = 0;
226 uint32_t names_addr_table_cnt_ = 0;
227 uint32_t ord_addr_table_rva_ = 0;
228 uint32_t max_ordinal_ = 0;
229 entries_t entries_;
230 std::string name_;
231};
232
233}
234}
235
236#endif /* PE_EXPORT_H */
ExportEntry.hpp
Object.hpp
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::Export
Class which represents a PE Export.
Definition Export.hpp:38
LIEF::PE::Export::ord_addr_table_rva
uint32_t ord_addr_table_rva() const
RVA to the list of exported ordinals.
Definition Export.hpp:137
LIEF::PE::Export::export_flags
uint32_t export_flags() const
According to the PE specifications this value is reserved and should be set to 0.
Definition Export.hpp:73
LIEF::PE::Export::minor_version
void minor_version(uint16_t minor_version)
Definition Export.hpp:153
LIEF::PE::Export::add_entry
ExportEntry & add_entry(const ExportEntry &exp)
Add the given export and return the newly created and added export.
LIEF::PE::Export::major_version
uint16_t major_version() const
The major version number (can be user-defined)
Definition Export.hpp:83
LIEF::PE::Export::operator=
Export & operator=(Export &&)=default
LIEF::PE::Export::remove_entry
bool remove_entry(uint32_t rva)
Remove the export entry with the given RVA.
Definition Export.hpp:205
LIEF::PE::Export::minor_version
uint16_t minor_version() const
The minor version number (can be user-defined)
Definition Export.hpp:88
LIEF::PE::Export::Export
Export()=default
LIEF::PE::Export::Export
Export(Export &&)=default
LIEF::PE::Export::ordinal_base
uint32_t ordinal_base() const
The starting number for the exports. Usually this value is set to 1.
Definition Export.hpp:93
LIEF::PE::Export::find_entry
const ExportEntry * find_entry(const std::string &name) const
Find the export entry with the given name.
LIEF::PE::Export::name
void name(std::string name)
Definition Export.hpp:161
LIEF::PE::Export::add_entry
ExportEntry & add_entry(std::string name, uint32_t rva)
Definition Export.hpp:189
LIEF::PE::Export::major_version
void major_version(uint16_t major_version)
Definition Export.hpp:149
LIEF::PE::Export::Export
Export(const details::pe_export_directory_table &header)
LIEF::PE::Export::find_entry
const ExportEntry * find_entry(uint32_t ordinal) const
Find the export entry with the given ordinal number.
LIEF::PE::Export::Export
Export(const Export &)=default
LIEF::PE::Export::Export
Export(std::string name, const entries_t &entries)
Definition Export.hpp:49
LIEF::PE::Export::Export
Export(std::string name)
Definition Export.hpp:57
LIEF::PE::Export::entries
it_const_entries entries() const
Definition Export.hpp:107
LIEF::PE::Export::accept
void accept(Visitor &visitor) const override
LIEF::PE::Export::export_flags
void export_flags(uint32_t flags)
Definition Export.hpp:141
LIEF::PE::Export::~Export
~Export() override=default
LIEF::PE::Export::operator=
Export & operator=(const Export &)=default
LIEF::PE::Export::export_addr_table_cnt
uint32_t export_addr_table_cnt() const
Number of entries in the export address table.
Definition Export.hpp:122
LIEF::PE::Export::find_entry_at
const ExportEntry * find_entry_at(uint32_t rva) const
Find the export entry at the provided RVA.
LIEF::PE::Export::name_rva
uint32_t name_rva() const
Address of the ASCII DLL's name (RVA)
Definition Export.hpp:112
LIEF::PE::Export::find_entry
ExportEntry * find_entry(const std::string &name)
Definition Export.hpp:168
LIEF::PE::Export::ordinal_base
void ordinal_base(uint32_t ordinal_base)
Definition Export.hpp:157
LIEF::PE::Export::operator<<
friend std::ostream & operator<<(std::ostream &os, const Export &exp)
LIEF::PE::Export::remove_entry
bool remove_entry(const ExportEntry &exp)
Remove the given export entry.
LIEF::PE::Export::names_addr_table_rva
uint32_t names_addr_table_rva() const
RVA to the list of exported names.
Definition Export.hpp:127
LIEF::PE::Export::name
const std::string & name() const
The name of the library exported (e.g. KERNEL32.dll)
Definition Export.hpp:98
LIEF::PE::Export::remove_entry
bool remove_entry(const std::string &name)
Remove the export entry with the given name.
Definition Export.hpp:197
LIEF::PE::Export::entries
it_entries entries()
Iterator over the ExportEntry.
Definition Export.hpp:103
LIEF::PE::Export::timestamp
uint32_t timestamp() const
The time and date that the export data was created.
Definition Export.hpp:78
LIEF::PE::Export::export_addr_table_rva
uint32_t export_addr_table_rva() const
RVA of the export address table.
Definition Export.hpp:117
LIEF::PE::Export::find_entry_at
ExportEntry * find_entry_at(uint32_t rva)
Definition Export.hpp:182
LIEF::PE::Export::timestamp
void timestamp(uint32_t timestamp)
Definition Export.hpp:145
LIEF::PE::Export::find_entry
ExportEntry * find_entry(uint32_t ordinal)
Definition Export.hpp:175
LIEF::PE::Export::names_addr_table_cnt
uint32_t names_addr_table_cnt() const
Number of exports by name.
Definition Export.hpp:132
LIEF::PE::Parser
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:52
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::PE::ACCELERATOR_CODES::E
@ E
Definition AcceleratorCodes.hpp:82
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41