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 - 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;
33class 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
65 ExportInfo& operator=(ExportInfo copy);
66 ExportInfo(const ExportInfo& copy);
67 void swap(ExportInfo& other) noexcept;
68 uint64_t node_offset() const {
71 return node_offset_;
72 }
73 uint64_t flags() const {
77 return flags_;
78 }
79
80 void flags(uint64_t flags) {
81 flags_ = flags;
82 }
83 flag_list_t flags_list() const;
86 bool has(FLAGS flag) const;
89 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 uint64_t address() const {
102 return address_;
103 }
104 void address(uint64_t addr) {
105 address_ = addr;
106 }
107 bool has_symbol() const {
110 return symbol() != nullptr;
111 }
112 const Symbol* symbol() const {
115 return symbol_;
116 }
117 Symbol* symbol() {
118 return symbol_;
119 }
120 Symbol* alias() {
124 return alias_;
125 }
126 const Symbol* alias() const {
127 return alias_;
128 }
129 DylibCommand* alias_library() {
133 return alias_location_;
134 }
135 const DylibCommand* alias_library() const {
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
156LIEF_API const char* to_string(ExportInfo::KIND kind);
157LIEF_API const char* to_string(ExportInfo::FLAGS flags);
158
159}
160}
161
162ENABLE_BITMASK_OPERATORS(LIEF::MachO::ExportInfo::FLAGS);
163
164#endif
Object.hpp
LIEF::MachO::BinaryParser
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:75
LIEF::MachO::Binary
Class which represents a MachO binary.
Definition MachO/Binary.hpp:86
LIEF::MachO::DylibCommand
Class which represents a library dependency.
Definition DylibCommand.hpp:34
LIEF::MachO::ExportInfo
Class that provides an interface over the Dyld export info.
Definition ExportInfo.hpp:38
LIEF::MachO::ExportInfo::FLAGS
FLAGS
Definition ExportInfo.hpp:50
LIEF::MachO::ExportInfo::flags
void flags(uint64_t flags)
Definition ExportInfo.hpp:80
LIEF::MachO::ExportInfo::accept
void accept(Visitor &visitor) const override
LIEF::MachO::ExportInfo::~ExportInfo
~ExportInfo() override=default
LIEF::MachO::ExportInfo::ExportInfo
ExportInfo()=default
LIEF::MachO::ExportInfo::has_symbol
bool has_symbol() const
Check if a symbol is associated with this export.
Definition ExportInfo.hpp:109
LIEF::MachO::ExportInfo::symbol
Symbol * symbol()
Definition ExportInfo.hpp:117
LIEF::MachO::ExportInfo::address
void address(uint64_t addr)
Definition ExportInfo.hpp:104
LIEF::MachO::ExportInfo::ExportInfo
ExportInfo(uint64_t address, uint64_t flags, uint64_t offset=0)
Definition ExportInfo.hpp:59
LIEF::MachO::ExportInfo::symbol
const Symbol * symbol() const
MachO::Symbol associated with this export or a nullptr if no symbol.
Definition ExportInfo.hpp:114
LIEF::MachO::ExportInfo::operator=
ExportInfo & operator=(ExportInfo copy)
LIEF::MachO::ExportInfo::flags
uint64_t flags() const
Some information (ExportInfo::FLAGS) about the export. (like weak export, reexport,...
Definition ExportInfo.hpp:76
LIEF::MachO::ExportInfo::has
bool has(FLAGS flag) const
Check if the current entry contains the provided ExportInfo::FLAGS.
LIEF::MachO::ExportInfo::kind
KIND kind() const
The export's kind (regular, thread local, absolute, ...)
Definition ExportInfo.hpp:91
LIEF::MachO::ExportInfo::alias_library
DylibCommand * alias_library()
If the export is a ExportInfo::FLAGS::REEXPORT, this returns the (optional) library (MachO::DylibComm...
Definition ExportInfo.hpp:132
LIEF::MachO::ExportInfo::alias_library
const DylibCommand * alias_library() const
Definition ExportInfo.hpp:135
LIEF::MachO::ExportInfo::operator<<
friend std::ostream & operator<<(std::ostream &os, const ExportInfo &export_info)
LIEF::MachO::ExportInfo::flags_list
flag_list_t flags_list() const
The export flags() as a list.
LIEF::MachO::ExportInfo::address
uint64_t address() const
The address of the export.
Definition ExportInfo.hpp:101
LIEF::MachO::ExportInfo::node_offset
uint64_t node_offset() const
Original offset in the export Trie.
Definition ExportInfo.hpp:70
LIEF::MachO::ExportInfo::ExportInfo
ExportInfo(const ExportInfo &copy)
LIEF::MachO::ExportInfo::alias
const Symbol * alias() const
Definition ExportInfo.hpp:126
LIEF::MachO::ExportInfo::other
uint64_t other() const
Definition ExportInfo.hpp:96
LIEF::MachO::ExportInfo::swap
void swap(ExportInfo &other) noexcept
LIEF::MachO::ExportInfo::alias
Symbol * alias()
If the export is a ExportInfo::FLAGS::REEXPORT, this returns the (optional) MachO::Symbol.
Definition ExportInfo.hpp:123
LIEF::MachO::ExportInfo::KIND
KIND
Definition ExportInfo.hpp:44
LIEF::MachO::Symbol
Class that represents a Symbol in a Mach-O file.
Definition MachO/Symbol.hpp:47
enums.hpp
ENABLE_BITMASK_OPERATORS
#define ENABLE_BITMASK_OPERATORS(X)
Definition enums.hpp:24
LIEF::MachO
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF::MachO::to_string
const char * to_string(BuildToolVersion::TOOLS tool)
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41