LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
ExportInfo.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_MACHO_EXPORT_INFO_COMMAND_H
17#define LIEF_MACHO_EXPORT_INFO_COMMAND_H
18#include <vector>
19#include <ostream>
20#include <cstdint>
21
22#include "LIEF/visibility.h"
23#include "LIEF/enums.hpp"
24#include "LIEF/Object.hpp"
25
26namespace LIEF {
27namespace MachO {
28
29class BinaryParser;
30class Symbol;
31class DylibCommand;
32class Binary;
33
38class LIEF_API ExportInfo : public Object {
39
40 friend class BinaryParser;
41 friend class Binary;
42
43 public:
44 enum class KIND: uint64_t {
45 REGULAR = 0x00u,
48 };
49
50 enum class FLAGS: uint64_t {
52 REEXPORT = 0x08u,
55 };
56
57 using flag_list_t = std::vector<FLAGS>;
58
59 ExportInfo() = default;
60 ExportInfo(uint64_t address, uint64_t flags, uint64_t offset = 0) :
61 node_offset_(offset),
62 flags_(flags),
63 address_(address)
64 {}
65
67 ExportInfo(const ExportInfo& copy);
68 void swap(ExportInfo& other) noexcept;
69
71 uint64_t node_offset() const {
72 return node_offset_;
73 }
74
77 uint64_t flags() const {
78 return flags_;
79 }
80
81 void flags(uint64_t flags) {
82 flags_ = flags;
83 }
84
87
89 bool has(FLAGS flag) const;
90
92 KIND kind() const {
93 static constexpr auto MASK = uint64_t(3);
94 return KIND(flags_ & MASK);
95 }
96
97 uint64_t other() const {
98 return other_;
99 }
100
102 uint64_t address() const {
103 return address_;
104 }
105 void address(uint64_t addr) {
106 address_ = addr;
107 }
108
110 bool has_symbol() const {
111 return symbol() != nullptr;
112 }
113
115 const Symbol* symbol() const {
116 return symbol_;
117 }
119 return symbol_;
120 }
121
125 return alias_;
126 }
127 const Symbol* alias() const {
128 return alias_;
129 }
130
134 return alias_location_;
135 }
137 return alias_location_;
138 }
139
140 ~ExportInfo() override = default;
141
142 void accept(Visitor& visitor) const override;
143
144 LIEF_API friend std::ostream& operator<<(std::ostream& os, const ExportInfo& export_info);
145
146 private:
147 uint64_t node_offset_ = 0;
148 uint64_t flags_ = 0;
149 uint64_t address_ = 0;
150 uint64_t other_ = 0;
151 Symbol* symbol_ = nullptr;
152
153 Symbol* alias_ = nullptr;
154 DylibCommand* alias_location_ = nullptr;
155};
156
159
160}
161}
162
164
165#endif
Class used to parse a single binary (i.e. non-FAT).
Definition BinaryParser.hpp:78
Class which represents a MachO binary.
Definition MachO/Binary.hpp:88
Class which represents a library dependency.
Definition DylibCommand.hpp:34
FLAGS
Definition ExportInfo.hpp:50
@ STATIC_RESOLVER
Definition ExportInfo.hpp:54
@ STUB_AND_RESOLVER
Definition ExportInfo.hpp:53
@ REEXPORT
Definition ExportInfo.hpp:52
@ WEAK_DEFINITION
Definition ExportInfo.hpp:51
void flags(uint64_t flags)
Definition ExportInfo.hpp:81
void accept(Visitor &visitor) const override
~ExportInfo() override=default
bool has_symbol() const
Check if a symbol is associated with this export.
Definition ExportInfo.hpp:110
friend class BinaryParser
Definition ExportInfo.hpp:40
Symbol * symbol()
Definition ExportInfo.hpp:118
void address(uint64_t addr)
Definition ExportInfo.hpp:105
ExportInfo(uint64_t address, uint64_t flags, uint64_t offset=0)
Definition ExportInfo.hpp:60
const Symbol * symbol() const
MachO::Symbol associated with this export or a nullptr if no symbol.
Definition ExportInfo.hpp:115
ExportInfo & operator=(ExportInfo copy)
uint64_t flags() const
Some information (ExportInfo::FLAGS) about the export. (like weak export, reexport,...
Definition ExportInfo.hpp:77
bool has(FLAGS flag) const
Check if the current entry contains the provided ExportInfo::FLAGS.
KIND kind() const
The export's kind (regular, thread local, absolute, ...).
Definition ExportInfo.hpp:92
DylibCommand * alias_library()
If the export is a ExportInfo::FLAGS::REEXPORT, this returns the (optional) library (MachO::DylibComm...
Definition ExportInfo.hpp:133
const DylibCommand * alias_library() const
Definition ExportInfo.hpp:136
friend std::ostream & operator<<(std::ostream &os, const ExportInfo &export_info)
friend class Binary
Definition ExportInfo.hpp:41
std::vector< FLAGS > flag_list_t
Definition ExportInfo.hpp:57
flag_list_t flags_list() const
The export flags() as a list.
uint64_t address() const
The address of the export.
Definition ExportInfo.hpp:102
uint64_t node_offset() const
Original offset in the export Trie.
Definition ExportInfo.hpp:71
ExportInfo(const ExportInfo &copy)
const Symbol * alias() const
Definition ExportInfo.hpp:127
uint64_t other() const
Definition ExportInfo.hpp:97
void swap(ExportInfo &other) noexcept
Symbol * alias()
If the export is a ExportInfo::FLAGS::REEXPORT, this returns the (optional) MachO::Symbol.
Definition ExportInfo.hpp:124
KIND
Definition ExportInfo.hpp:44
@ REGULAR
Definition ExportInfo.hpp:45
@ THREAD_LOCAL_KIND
Definition ExportInfo.hpp:46
@ ABSOLUTE_KIND
Definition ExportInfo.hpp:47
Class that represents a Symbol in a Mach-O file.
Definition MachO/Symbol.hpp:47
Definition Visitor.hpp:210
#define ENABLE_BITMASK_OPERATORS(X)
Definition enums.hpp:24
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
const char * to_string(BuildToolVersion::TOOLS tool)
LIEF namespace.
Definition Abstract/Binary.hpp:40
#define LIEF_API
Definition visibility.h:41