LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
ExportInfo.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 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,
46 THREAD_LOCAL_KIND = 0x01u,
47 ABSOLUTE_KIND = 0x02u
48 };
49
50 enum class FLAGS: uint64_t {
51 WEAK_DEFINITION = 0x04u,
52 REEXPORT = 0x08u,
53 STUB_AND_RESOLVER = 0x10u
54 };
55
56 using flag_list_t = std::vector<FLAGS>;
57
58 ExportInfo() = default;
59 ExportInfo(uint64_t address, uint64_t flags, uint64_t offset = 0) :
60 node_offset_(offset),
61 flags_(flags),
62 address_(address)
63 {}
64
66 ExportInfo(const ExportInfo& copy);
67 void swap(ExportInfo& other) noexcept;
68
70 uint64_t node_offset() const {
71 return node_offset_;
72 }
73
76 uint64_t flags() const {
77 return flags_;
78 }
79
80 void flags(uint64_t flags) {
81 flags_ = flags;
82 }
83
86
88 bool has(FLAGS flag) const;
89
91 KIND kind() const {
92 static constexpr auto MASK = uint64_t(3);
93 return KIND(flags_ & MASK);
94 }
95
96 uint64_t other() const {
97 return other_;
98 }
99
101 uint64_t address() const {
102 return address_;
103 }
104 void address(uint64_t addr) {
105 address_ = addr;
106 }
107
109 bool has_symbol() const {
110 return symbol() != nullptr;
111 }
112
114 const Symbol* symbol() const {
115 return symbol_;
116 }
118 return symbol_;
119 }
120
124 return alias_;
125 }
126 const Symbol* alias() const {
127 return alias_;
128 }
129
133 return alias_location_;
134 }
136 return alias_location_;
137 }
138
139 ~ExportInfo() override = default;
140
141 void accept(Visitor& visitor) const override;
142
143 LIEF_API friend std::ostream& operator<<(std::ostream& os, const ExportInfo& export_info);
144
145 private:
146 uint64_t node_offset_ = 0;
147 uint64_t flags_ = 0;
148 uint64_t address_ = 0;
149 uint64_t other_ = 0;
150 Symbol* symbol_ = nullptr;
151
152 Symbol* alias_ = nullptr;
153 DylibCommand* alias_location_ = nullptr;
154};
155
158
159}
160}
161
163
164#endif
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:74
Class which represents a MachO binary.
Definition MachO/Binary.hpp:77
Class which represents a library dependency.
Definition DylibCommand.hpp:34
Class that provides an interface over the Dyld export info.
Definition ExportInfo.hpp:38
FLAGS
Definition ExportInfo.hpp:50
void flags(uint64_t flags)
Definition ExportInfo.hpp:80
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:109
Symbol * symbol()
Definition ExportInfo.hpp:117
void address(uint64_t addr)
Definition ExportInfo.hpp:104
ExportInfo(uint64_t address, uint64_t flags, uint64_t offset=0)
Definition ExportInfo.hpp:59
const Symbol * symbol() const
MachO::Symbol associated with this export or a nullptr if no symbol.
Definition ExportInfo.hpp:114
ExportInfo & operator=(ExportInfo copy)
uint64_t flags() const
Some information (ExportInfo::FLAGS) about the export. (like weak export, reexport,...
Definition ExportInfo.hpp:76
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:91
DylibCommand * alias_library()
If the export is a ExportInfo::FLAGS::REEXPORT, this returns the (optional) library (MachO::DylibComm...
Definition ExportInfo.hpp:132
const DylibCommand * alias_library() const
Definition ExportInfo.hpp:135
friend std::ostream & operator<<(std::ostream &os, const ExportInfo &export_info)
std::vector< FLAGS > flag_list_t
Definition ExportInfo.hpp:56
flag_list_t flags_list() const
The export flags() as a list.
uint64_t address() const
The address of the export.
Definition ExportInfo.hpp:101
uint64_t node_offset() const
Original offset in the export Trie.
Definition ExportInfo.hpp:70
ExportInfo(const ExportInfo &copy)
const Symbol * alias() const
Definition ExportInfo.hpp:126
uint64_t other() const
Definition ExportInfo.hpp:96
void swap(ExportInfo &other) noexcept
Symbol * alias()
If the export is a ExportInfo::FLAGS::REEXPORT, this returns the (optional) MachO::Symbol.
Definition ExportInfo.hpp:123
KIND
Definition ExportInfo.hpp:44
Class that represents a Symbol in a Mach-O file.
Definition MachO/Symbol.hpp:47
Definition Object.hpp:25
Definition Visitor.hpp:224
#define ENABLE_BITMASK_OPERATORS(X)
Definition enums.hpp:24
const char * to_string(BuildToolVersion::TOOLS tool)
LIEF namespace.
Definition Abstract/Binary.hpp:32
#define LIEF_API
Definition visibility.h:41