LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
ExportEntry.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 * Copyright 2017 - 2026 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;
31
34
35 friend class Builder;
36 friend class Parser;
37
38 public:
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,
52 const forward_information_t& info) {
53 os << info.key();
54 return os;
55 }
56 };
57
58 public:
59 ExportEntry() = default;
60 ExportEntry(uint32_t address, bool is_extern, uint16_t ordinal,
61 uint32_t function_rva) :
62 function_rva_{function_rva},
63 ordinal_{ordinal},
64 address_{address},
65 is_extern_{is_extern} {}
66
67 ExportEntry(std::string name, uint32_t rva) :
68 LIEF::Symbol(std::move(name)),
69 address_(rva) {}
70
71 ExportEntry(const ExportEntry&) = default;
72 ExportEntry& operator=(const ExportEntry&) = default;
73
76
77 ~ExportEntry() override = default;
78
81 std::string demangled_name() const;
82
87 uint16_t ordinal() const {
88 return ordinal_;
89 }
90
95 uint32_t address() const {
96 return address_;
97 }
98
99 bool is_extern() const {
100 return is_extern_;
101 }
102
103 bool is_forwarded() const {
104 return forward_info_;
105 }
106
108 return is_forwarded() ? forward_info_ : forward_information_t{};
109 }
110
111 uint32_t function_rva() const {
112 return function_rva_;
113 }
114
115 void ordinal(uint16_t ordinal) {
116 ordinal_ = ordinal;
117 }
118
119 void address(uint32_t address) {
120 address_ = address;
121 }
122
123 void is_extern(bool is_extern) {
124 is_extern_ = is_extern;
125 }
126
127 uint64_t value() const override {
128 return address();
129 }
130
131 void value(uint64_t value) override {
132 address(static_cast<uint32_t>(value));
133 }
134
135 void set_forward_info(std::string lib, std::string function) {
136 forward_info_.library = std::move(lib);
137 forward_info_.function = std::move(function);
138 }
139
140 void accept(Visitor& visitor) const override;
141
142
143 LIEF_API friend std::ostream& operator<<(std::ostream& os,
144 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#endif /* PE_EXPORTENTRY_H */
Class that is used to rebuild a raw PE binary from a PE::Binary object.
Definition PE/Builder.hpp:45
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:103
uint64_t value() const override
Definition ExportEntry.hpp:127
ExportEntry & operator=(ExportEntry &&)=default
bool is_extern() const
Definition ExportEntry.hpp:99
uint32_t address() const
Address of the current exported function in the DLL.
Definition ExportEntry.hpp:95
void value(uint64_t value) override
Definition ExportEntry.hpp:131
void is_extern(bool is_extern)
Definition ExportEntry.hpp:123
void accept(Visitor &visitor) const override
ExportEntry(std::string name, uint32_t rva)
Definition ExportEntry.hpp:67
ExportEntry(uint32_t address, bool is_extern, uint16_t ordinal, uint32_t function_rva)
Definition ExportEntry.hpp:60
void set_forward_info(std::string lib, std::string function)
Definition ExportEntry.hpp:135
friend class Builder
Definition ExportEntry.hpp:35
ExportEntry(const ExportEntry &)=default
~ExportEntry() override=default
uint16_t ordinal() const
Ordinal value associated with this exported entry.
Definition ExportEntry.hpp:87
uint32_t function_rva() const
Definition ExportEntry.hpp:111
friend class Parser
Definition ExportEntry.hpp:36
forward_information_t forward_information() const
Definition ExportEntry.hpp:107
void ordinal(uint16_t ordinal)
Definition ExportEntry.hpp:115
void address(uint32_t address)
Definition ExportEntry.hpp:119
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:52
This class represents a symbol in an executable format.
Definition Abstract/Symbol.hpp:28
Symbol()=default
virtual const std::string & name() const
Return the symbol's name.
Definition Abstract/Symbol.hpp:54
Definition Visitor.hpp:212
Namespace related to the LIEF's PE module.
Definition Abstract/Header.hpp:32
LIEF namespace.
Definition Abstract/Binary.hpp:40
Definition string.h:155
friend std::ostream & operator<<(std::ostream &os, const forward_information_t &info)
Definition ExportEntry.hpp:51
std::string library
Definition ExportEntry.hpp:40
std::string function
Definition ExportEntry.hpp:41
std::string key() const
Definition ExportEntry.hpp:47
#define LIEF_API
Definition visibility.h:43