LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
ExportEntry.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_ENTRY_H
17#define LIEF_PE_EXPORT_ENTRY_H
18
19#include <string>
20#include <ostream>
21
22#include "LIEF/Object.hpp"
23#include "LIEF/visibility.h"
25
26namespace LIEF {
27namespace PE {
28
29class Builder;
30class Parser;
31class LIEF_API ExportEntry : public LIEF::Symbol {
34
35 friend class Builder;
36 friend class Parser;
37
38 public:
39 struct LIEF_API forward_information_t {
40 std::string library;
41 std::string function;
42
43 operator bool() const {
44 return !library.empty() || !function.empty();
45 }
46
47 std::string key() const {
48 return library + '.' + function;
49 }
50
51 LIEF_API friend std::ostream& operator<<(std::ostream& os, 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,
60 uint16_t ordinal, uint32_t function_rva) :
61 function_rva_{function_rva},
62 ordinal_{ordinal},
63 address_{address},
64 is_extern_{is_extern}
65 {}
66
67 ExportEntry(std::string name, uint32_t rva) :
68 LIEF::Symbol(std::move(name)),
69 address_(rva)
70 {}
71
72 ExportEntry(const ExportEntry&) = default;
73 ExportEntry& operator=(const ExportEntry&) = default;
74
75 ExportEntry(ExportEntry&&) = default;
76 ExportEntry& operator=(ExportEntry&&) = default;
77
78 ~ExportEntry() override = default;
79 std::string demangled_name() const;
83 uint16_t ordinal() const {
89 return ordinal_;
90 }
91 uint32_t address() const {
97 return address_;
98 }
99
100 bool is_extern() const {
101 return is_extern_;
102 }
103
104 bool is_forwarded() const {
105 return forward_info_;
106 }
107
108 forward_information_t forward_information() const {
109 return is_forwarded() ? forward_info_ : forward_information_t{};
110 }
111
112 uint32_t function_rva() const {
113 return function_rva_;
114 }
115
116 void ordinal(uint16_t ordinal) {
117 ordinal_ = ordinal;
118 }
119
120 void address(uint32_t address) {
121 address_ = address;
122 }
123
124 void is_extern(bool is_extern) {
125 is_extern_ = is_extern;
126 }
127
128 uint64_t value() const override {
129 return address();
130 }
131
132 void value(uint64_t value) override {
133 address(static_cast<uint32_t>(value));
134 }
135
136 void set_forward_info(std::string lib, std::string function) {
137 forward_info_.library = std::move(lib);
138 forward_info_.function = std::move(function);
139 }
140
141 void accept(Visitor& visitor) const override;
142
143
144 LIEF_API friend std::ostream& operator<<(std::ostream& os, const ExportEntry& exportEntry);
145
146 private:
147 uint32_t function_rva_ = 0;
148 uint16_t ordinal_ = 0;
149 uint32_t address_ = 0;
150 bool is_extern_ = false;
151
152 forward_information_t forward_info_;
153
154};
155
156}
157}
158
159#endif /* PE_EXPORTENTRY_H */
Symbol.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::ExportEntry
Class which represents a PE Export entry (cf. PE::Export)
Definition ExportEntry.hpp:33
LIEF::PE::ExportEntry::operator=
ExportEntry & operator=(const ExportEntry &)=default
LIEF::PE::ExportEntry::ExportEntry
ExportEntry(ExportEntry &&)=default
LIEF::PE::ExportEntry::operator<<
friend std::ostream & operator<<(std::ostream &os, const ExportEntry &exportEntry)
LIEF::PE::ExportEntry::is_forwarded
bool is_forwarded() const
Definition ExportEntry.hpp:104
LIEF::PE::ExportEntry::value
uint64_t value() const override
Definition ExportEntry.hpp:128
LIEF::PE::ExportEntry::operator=
ExportEntry & operator=(ExportEntry &&)=default
LIEF::PE::ExportEntry::is_extern
bool is_extern() const
Definition ExportEntry.hpp:100
LIEF::PE::ExportEntry::address
uint32_t address() const
Address of the current exported function in the DLL.
Definition ExportEntry.hpp:96
LIEF::PE::ExportEntry::value
void value(uint64_t value) override
Definition ExportEntry.hpp:132
LIEF::PE::ExportEntry::is_extern
void is_extern(bool is_extern)
Definition ExportEntry.hpp:124
LIEF::PE::ExportEntry::accept
void accept(Visitor &visitor) const override
LIEF::PE::ExportEntry::ExportEntry
ExportEntry(std::string name, uint32_t rva)
Definition ExportEntry.hpp:67
LIEF::PE::ExportEntry::ExportEntry
ExportEntry(uint32_t address, bool is_extern, uint16_t ordinal, uint32_t function_rva)
Definition ExportEntry.hpp:59
LIEF::PE::ExportEntry::set_forward_info
void set_forward_info(std::string lib, std::string function)
Definition ExportEntry.hpp:136
LIEF::PE::ExportEntry::ExportEntry
ExportEntry(const ExportEntry &)=default
LIEF::PE::ExportEntry::~ExportEntry
~ExportEntry() override=default
LIEF::PE::ExportEntry::ordinal
uint16_t ordinal() const
Ordinal value associated with this exported entry.
Definition ExportEntry.hpp:88
LIEF::PE::ExportEntry::function_rva
uint32_t function_rva() const
Definition ExportEntry.hpp:112
LIEF::PE::ExportEntry::ExportEntry
ExportEntry()=default
LIEF::PE::ExportEntry::forward_information
forward_information_t forward_information() const
Definition ExportEntry.hpp:108
LIEF::PE::ExportEntry::ordinal
void ordinal(uint16_t ordinal)
Definition ExportEntry.hpp:116
LIEF::PE::ExportEntry::address
void address(uint32_t address)
Definition ExportEntry.hpp:120
LIEF::PE::ExportEntry::demangled_name
std::string demangled_name() const
Demangled representation of the symbol or an empty string if it can't be demangled.
LIEF::PE::Parser
Main interface to parse PE binaries. In particular the static functions: Parser::parse should be used...
Definition PE/Parser.hpp:52
LIEF::PE
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF::PE::IMPHASH_MODE::LIEF
@ LIEF
Definition PE/utils.hpp:35
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
LIEF::PE::ExportEntry::forward_information_t::operator<<
friend std::ostream & operator<<(std::ostream &os, const forward_information_t &info)
Definition ExportEntry.hpp:51
LIEF::PE::ExportEntry::forward_information_t::key
std::string key() const
Definition ExportEntry.hpp:47
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41