LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
ExportEntry.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LIEF_PE_EXPORT_ENTRY_H
16#define LIEF_PE_EXPORT_ENTRY_H
17
18#include <ostream>
19#include <string>
20
22#include "LIEF/Object.hpp"
23#include "LIEF/visibility.h"
24
25
26namespace LIEF::PE {
27
28class Builder;
29class Parser;
30
33
34 friend class Builder;
35 friend class Parser;
36
37 public:
39 std::string library;
40 std::string function;
41
42 operator bool() const {
43 return !library.empty() || !function.empty();
44 }
45
46 std::string key() const {
47 return library + '.' + function;
48 }
49
50 LIEF_API friend std::ostream& operator<<(std::ostream& os,
51 const forward_information_t& info) {
52 os << info.key();
53 return os;
54 }
55 };
56
57 public:
58 ExportEntry() = default;
59 ExportEntry(uint32_t address, bool is_extern, uint16_t ordinal,
60 uint32_t function_rva) :
61 function_rva_{function_rva},
62 ordinal_{ordinal},
63 address_{address},
64 is_extern_{is_extern} {}
65
66 ExportEntry(std::string name, uint32_t rva) :
67 LIEF::Symbol(std::move(name)),
68 address_(rva) {}
69
70 ExportEntry(const ExportEntry&) = default;
71 ExportEntry& operator=(const ExportEntry&) = default;
72
75
76 ~ExportEntry() override = default;
77
80 std::string demangled_name() const;
81
86 uint16_t ordinal() const {
87 return ordinal_;
88 }
89
94 uint32_t address() const {
95 return address_;
96 }
97
98 bool is_extern() const {
99 return is_extern_;
100 }
101
102 bool is_forwarded() const {
103 return forward_info_;
104 }
105
107 return is_forwarded() ? forward_info_ : forward_information_t{};
108 }
109
110 uint32_t function_rva() const {
111 return function_rva_;
112 }
113
114 void ordinal(uint16_t ordinal) {
115 ordinal_ = ordinal;
116 }
117
118 void address(uint32_t address) {
119 address_ = address;
120 }
121
122 void is_extern(bool is_extern) {
123 is_extern_ = is_extern;
124 }
125
126 uint64_t value() const override {
127 return address();
128 }
129
130 void value(uint64_t value) override {
131 address(uint32_t(value));
132 }
133
134 void set_forward_info(std::string lib, std::string function) {
135 forward_info_.library = std::move(lib);
136 forward_info_.function = std::move(function);
137 }
138
139 void accept(Visitor& visitor) const override;
140
141
142 LIEF_API friend std::ostream& operator<<(std::ostream& os,
143 const ExportEntry& exportEntry);
144
145 private:
146 uint32_t function_rva_ = 0;
147 uint16_t ordinal_ = 0;
148 uint32_t address_ = 0;
149 bool is_extern_ = false;
150
151 forward_information_t forward_info_;
152};
153
154}
155
156
157#endif
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:43
ExportEntry & operator=(const ExportEntry &)=default
ExportEntry(ExportEntry &&)=default
friend std::ostream & operator<<(std::ostream &os, const ExportEntry &exportEntry)
bool is_forwarded() const
Definition ExportEntry.hpp:102
uint64_t value() const override
Symbol's value which is usually the address of the symbol.
Definition ExportEntry.hpp:126
ExportEntry & operator=(ExportEntry &&)=default
bool is_extern() const
Definition ExportEntry.hpp:98
uint32_t address() const
Address of the current exported function in the DLL.
Definition ExportEntry.hpp:94
void value(uint64_t value) override
Definition ExportEntry.hpp:130
void is_extern(bool is_extern)
Definition ExportEntry.hpp:122
void accept(Visitor &visitor) const override
ExportEntry(std::string name, uint32_t rva)
Definition ExportEntry.hpp:66
ExportEntry(uint32_t address, bool is_extern, uint16_t ordinal, uint32_t function_rva)
Definition ExportEntry.hpp:59
void set_forward_info(std::string lib, std::string function)
Definition ExportEntry.hpp:134
friend class Builder
Definition ExportEntry.hpp:34
ExportEntry(const ExportEntry &)=default
~ExportEntry() override=default
uint16_t ordinal() const
Ordinal value associated with this exported entry.
Definition ExportEntry.hpp:86
uint32_t function_rva() const
Definition ExportEntry.hpp:110
friend class Parser
Definition ExportEntry.hpp:35
forward_information_t forward_information() const
Definition ExportEntry.hpp:106
void ordinal(uint16_t ordinal)
Definition ExportEntry.hpp:114
void address(uint32_t address)
Definition ExportEntry.hpp:118
std::string demangled_name() const
Demangled representation of the symbol or an empty string if it can't be demangled.
Main interface to parse PE binaries. In particular, the static Parser::parse functions should be used...
Definition PE/Parser.hpp:53
This class represents a symbol in an executable format.
Definition Abstract/Symbol.hpp:29
Symbol()=default
virtual std::string_view name() const
Return the symbol's name.
Definition Abstract/Symbol.hpp:55
Definition Visitor.hpp:211
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:31
LIEF namespace.
Definition Abstract/Binary.hpp:41
friend std::ostream & operator<<(std::ostream &os, const forward_information_t &info)
Definition ExportEntry.hpp:50
std::string library
Definition ExportEntry.hpp:39
std::string function
Definition ExportEntry.hpp:40
std::string key() const
Definition ExportEntry.hpp:46
#define LIEF_API
Definition visibility.h:44