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#include <memory>
22
23#include "LIEF/Object.hpp"
24#include "LIEF/visibility.h"
25#include "LIEF/iterators.hpp"
27
28namespace LIEF {
29namespace PE {
30
31class Builder;
32class Parser;
33
34namespace details {
35struct pe_export_directory_table;
36}
37class LIEF_API Export : public Object {
40 friend class Builder;
41 friend class Parser;
42
43 public:
44 using entries_t = std::vector<std::unique_ptr<ExportEntry>>;
45 using it_entries = ref_iterator<entries_t&, ExportEntry*>;
46 using it_const_entries = const_ref_iterator<const entries_t&, const ExportEntry*>;
47
48 Export() = default;
49
50 Export(std::string name, const std::vector<ExportEntry>& entries) :
51 name_(std::move(name))
52 {
53 for (const ExportEntry& E : entries) {
54 add_entry(E);
55 }
56 }
57
58 Export(std::string name) :
59 Export(std::move(name), {})
60 {}
61
62 Export(const details::pe_export_directory_table& header);
63
64 Export(const Export&);
65 Export& operator=(const Export&);
66
67 Export(Export&&) = default;
68 Export& operator=(Export&&) = default;
69
70 ~Export() override = default;
71 uint32_t export_flags() const {
75 return export_flags_;
76 }
77 uint32_t timestamp() const {
80 return timestamp_;
81 }
82 uint16_t major_version() const {
85 return major_version_;
86 }
87 uint16_t minor_version() const {
90 return minor_version_;
91 }
92 uint32_t ordinal_base() const {
95 return ordinal_base_;
96 }
97 const std::string& name() const {
100 return name_;
101 }
102 it_entries entries() {
105 return entries_;
106 }
107
108 it_const_entries entries() const {
109 return entries_;
110 }
111 uint32_t name_rva() const {
114 return name_rva_;
115 }
116 uint32_t export_addr_table_rva() const {
119 return exp_addr_table_rva_;
120 }
121 uint32_t export_addr_table_cnt() const {
124 return exp_addr_table_cnt_;
125 }
126 uint32_t names_addr_table_rva() const {
129 return names_addr_table_rva_;
130 }
131 uint32_t names_addr_table_cnt() const {
134 return names_addr_table_cnt_;
135 }
136 uint32_t ord_addr_table_rva() const {
139 return ord_addr_table_rva_;
140 }
141
142 void export_flags(uint32_t flags) {
143 export_flags_ = flags;
144 }
145
146 void timestamp(uint32_t timestamp) {
147 timestamp_ = timestamp;
148 }
149
150 void major_version(uint16_t major_version) {
151 major_version_ = major_version;
152 }
153
154 void minor_version(uint16_t minor_version) {
155 minor_version_ = minor_version;
156 }
157
158 void ordinal_base(uint32_t ordinal_base) {
159 ordinal_base_ = ordinal_base;
160 }
161
162 void name(std::string name) {
163 name_ = std::move(name);
164 }
165 const ExportEntry* find_entry(const std::string& name) const;
168
169 ExportEntry* find_entry(const std::string& name) {
170 return const_cast<ExportEntry*>(static_cast<const Export*>(this)->find_entry(name));
171 }
172 const ExportEntry* find_entry(uint32_t ordinal) const;
175
176 ExportEntry* find_entry(uint32_t ordinal) {
177 return const_cast<ExportEntry*>(static_cast<const Export*>(this)->find_entry(ordinal));
178 }
179 const ExportEntry* find_entry_at(uint32_t rva) const;
182
183 ExportEntry* find_entry_at(uint32_t rva) {
184 return const_cast<ExportEntry*>(static_cast<const Export*>(this)->find_entry_at(rva));
185 }
186 ExportEntry& add_entry(const ExportEntry& exp);
189
190 ExportEntry& add_entry(std::string name, uint32_t rva) {
191 return add_entry(ExportEntry(std::move(name), rva));
192 }
193 bool remove_entry(const ExportEntry& exp);
196 bool remove_entry(const std::string& name) {
199 if (const ExportEntry* entry = find_entry(name)) {
200 return remove_entry(*entry);
201 }
202 return false;
203 }
204 bool remove_entry(uint32_t rva) {
207 if (const ExportEntry* entry = find_entry_at(rva)) {
208 return remove_entry(*entry);
209 }
210 return false;
211 }
212
213 void accept(Visitor& visitor) const override;
214
215 LIEF_API friend std::ostream& operator<<(std::ostream& os, const Export& exp);
216
217 private:
218 uint32_t export_flags_ = 0;
219 uint32_t name_rva_ = 0;
220 uint32_t timestamp_ = 0;
221 uint16_t major_version_ = 0;
222 uint16_t minor_version_ = 0;
223 uint32_t ordinal_base_ = 0;
224 uint32_t exp_addr_table_rva_ = 0;
225 uint32_t exp_addr_table_cnt_ = 0;
226 uint32_t names_addr_table_rva_ = 0;
227 uint32_t names_addr_table_cnt_ = 0;
228 uint32_t ord_addr_table_rva_ = 0;
229 uint32_t max_ordinal_ = 0;
230 entries_t entries_;
231 std::string name_;
232};
233
234}
235}
236
237#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:39
LIEF::PE::Export::ord_addr_table_rva
uint32_t ord_addr_table_rva() const
RVA to the list of exported ordinals.
Definition Export.hpp:138
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:74
LIEF::PE::Export::operator=
Export & operator=(const Export &)
LIEF::PE::Export::minor_version
void minor_version(uint16_t minor_version)
Definition Export.hpp:154
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:84
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:206
LIEF::PE::Export::minor_version
uint16_t minor_version() const
The minor version number (can be user-defined)
Definition Export.hpp:89
LIEF::PE::Export::Export
Export()=default
LIEF::PE::Export::Export
Export(Export &&)=default
LIEF::PE::Export::Export
Export(const Export &)
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:94
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:162
LIEF::PE::Export::add_entry
ExportEntry & add_entry(std::string name, uint32_t rva)
Definition Export.hpp:190
LIEF::PE::Export::major_version
void major_version(uint16_t major_version)
Definition Export.hpp:150
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(std::string name)
Definition Export.hpp:58
LIEF::PE::Export::entries
it_const_entries entries() const
Definition Export.hpp:108
LIEF::PE::Export::accept
void accept(Visitor &visitor) const override
LIEF::PE::Export::export_flags
void export_flags(uint32_t flags)
Definition Export.hpp:142
LIEF::PE::Export::~Export
~Export() override=default
LIEF::PE::Export::Export
Export(std::string name, const std::vector< ExportEntry > &entries)
Definition Export.hpp:50
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:123
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:113
LIEF::PE::Export::find_entry
ExportEntry * find_entry(const std::string &name)
Definition Export.hpp:169
LIEF::PE::Export::ordinal_base
void ordinal_base(uint32_t ordinal_base)
Definition Export.hpp:158
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:128
LIEF::PE::Export::name
const std::string & name() const
The name of the library exported (e.g. KERNEL32.dll)
Definition Export.hpp:99
LIEF::PE::Export::remove_entry
bool remove_entry(const std::string &name)
Remove the export entry with the given name.
Definition Export.hpp:198
LIEF::PE::Export::entries
it_entries entries()
Iterator over the ExportEntry.
Definition Export.hpp:104
LIEF::PE::Export::timestamp
uint32_t timestamp() const
The time and date that the export data was created.
Definition Export.hpp:79
LIEF::PE::Export::export_addr_table_rva
uint32_t export_addr_table_rva() const
RVA of the export address table.
Definition Export.hpp:118
LIEF::PE::Export::find_entry_at
ExportEntry * find_entry_at(uint32_t rva)
Definition Export.hpp:183
LIEF::PE::Export::timestamp
void timestamp(uint32_t timestamp)
Definition Export.hpp:146
LIEF::PE::Export::find_entry
ExportEntry * find_entry(uint32_t ordinal)
Definition Export.hpp:176
LIEF::PE::Export::names_addr_table_cnt
uint32_t names_addr_table_cnt() const
Number of exports by name.
Definition Export.hpp:133
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:39
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41