LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
BindingInfo.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_BINDING_INFO_H
17#define LIEF_MACHO_BINDING_INFO_H
18#include <ostream>
19#include <cstdint>
20
21#include "LIEF/visibility.h"
22#include "LIEF/Object.hpp"
23
24namespace LIEF {
25namespace MachO {
26class DylibCommand;
27class SegmentCommand;
28class Symbol;
29class BinaryParser;
31class LIEF_API BindingInfo : public Object {
40
41 friend class BinaryParser;
42 friend class DyldChainedFixupsCreator;
43
44 public:
45 enum class TYPES {
47 DYLD_INFO,
48 CHAINED,
49 CHAINED_LIST,
50 INDIRECT_SYMBOL,
51 };
52
53 BindingInfo() = default;
54 BindingInfo(const BindingInfo& other);
55 void swap(BindingInfo& other) noexcept;
56 bool has_segment() const {
59 return segment_ != nullptr;
60 }
61 const SegmentCommand* segment() const {
65 return segment_;
66 }
67 SegmentCommand* segment() {
68 return segment_;
69 }
70 bool has_library() const {
73 return library_ != nullptr;
74 }
75 const DylibCommand* library() const {
79 return library_;
80 }
81 DylibCommand* library() {
82 return library_;
83 }
84 bool has_symbol() const {
87 return symbol_ != nullptr;
88 }
89 const Symbol* symbol() const {
93 return symbol_;
94 }
95 Symbol* symbol() {
96 return symbol_;
97 }
98 virtual uint64_t address() const {
101 return address_;
102 }
103
104 virtual void address(uint64_t addr) {
105 address_ = addr;
106 }
107
108 int32_t library_ordinal() const {
109 return library_ordinal_;
110 }
111
112 void library_ordinal(int32_t ordinal) {
113 library_ordinal_ = ordinal;
114 }
115 int64_t addend() const {
118 return addend_;
119 }
120
121 void addend(int64_t addend) {
122 addend_ = addend;
123 }
124
125 bool is_weak_import() const {
126 return is_weak_import_;
127 }
128
129 void set_weak_import(bool val = true) {
130 is_weak_import_ = val;
131 }
132 virtual TYPES type() const = 0;
136
137 ~BindingInfo() override = default;
138
139 void accept(Visitor& visitor) const override;
140
141 template<class T>
142 const T* cast() const {
143 static_assert(std::is_base_of<BindingInfo, T>::value, "Require BindingInfo inheritance");
144 if (T::classof(this)) {
145 return static_cast<const T*>(this);
146 }
147 return nullptr;
148 }
149
150 template<class T>
151 T* cast() {
152 return const_cast<T*>(static_cast<const BindingInfo*>(this)->cast<T>());
153 }
154
155 LIEF_API friend std::ostream& operator<<(std::ostream& os, const BindingInfo& binding_info);
156
157 protected:
158 SegmentCommand* segment_ = nullptr;
159 Symbol* symbol_ = nullptr;
160 int32_t library_ordinal_ = 0;
161 int64_t addend_ = 0;
162 bool is_weak_import_ = false;
163 DylibCommand* library_ = nullptr;
164 uint64_t address_ = 0;
165};
166
167}
168}
169#endif
Object.hpp
LIEF::MachO::BinaryParser
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:75
LIEF::MachO::BindingInfo
Class that provides an interface over a binding operation.
Definition BindingInfo.hpp:39
LIEF::MachO::BindingInfo::library
DylibCommand * library()
Definition BindingInfo.hpp:81
LIEF::MachO::BindingInfo::~BindingInfo
~BindingInfo() override=default
LIEF::MachO::BindingInfo::accept
void accept(Visitor &visitor) const override
LIEF::MachO::BindingInfo::has_symbol
bool has_symbol() const
Check if a MachO::Symbol is associated with the BindingInfo.
Definition BindingInfo.hpp:86
LIEF::MachO::BindingInfo::cast
const T * cast() const
Definition BindingInfo.hpp:142
LIEF::MachO::BindingInfo::symbol
Symbol * symbol()
Definition BindingInfo.hpp:95
LIEF::MachO::BindingInfo::has_segment
bool has_segment() const
Check if a MachO::SegmentCommand is associated with this binding.
Definition BindingInfo.hpp:58
LIEF::MachO::BindingInfo::BindingInfo
BindingInfo()=default
LIEF::MachO::BindingInfo::segment
const SegmentCommand * segment() const
The MachO::SegmentCommand associated with the BindingInfo or a nullptr of it is not bind to a Segment...
Definition BindingInfo.hpp:64
LIEF::MachO::BindingInfo::library_ordinal
int32_t library_ordinal() const
Definition BindingInfo.hpp:108
LIEF::MachO::BindingInfo::BindingInfo
BindingInfo(const BindingInfo &other)
LIEF::MachO::BindingInfo::has_library
bool has_library() const
Check if a MachO::DylibCommand is tied with the BindingInfo.
Definition BindingInfo.hpp:72
LIEF::MachO::BindingInfo::address
virtual void address(uint64_t addr)
Definition BindingInfo.hpp:104
LIEF::MachO::BindingInfo::set_weak_import
void set_weak_import(bool val=true)
Definition BindingInfo.hpp:129
LIEF::MachO::BindingInfo::operator<<
friend std::ostream & operator<<(std::ostream &os, const BindingInfo &binding_info)
LIEF::MachO::BindingInfo::symbol
const Symbol * symbol() const
MachO::Symbol associated with the BindingInfo or a nullptr if not present.
Definition BindingInfo.hpp:92
LIEF::MachO::BindingInfo::library_ordinal
void library_ordinal(int32_t ordinal)
Definition BindingInfo.hpp:112
LIEF::MachO::BindingInfo::cast
T * cast()
Definition BindingInfo.hpp:151
LIEF::MachO::BindingInfo::type
virtual TYPES type() const =0
The type of the binding. This type provides the origin of the binding (LC_DYLD_INFO or LC_DYLD_CHAINE...
LIEF::MachO::BindingInfo::address
virtual uint64_t address() const
Address of the binding.
Definition BindingInfo.hpp:100
LIEF::MachO::BindingInfo::swap
void swap(BindingInfo &other) noexcept
LIEF::MachO::BindingInfo::is_weak_import
bool is_weak_import() const
Definition BindingInfo.hpp:125
LIEF::MachO::BindingInfo::segment
SegmentCommand * segment()
Definition BindingInfo.hpp:67
LIEF::MachO::BindingInfo::library
const DylibCommand * library() const
MachO::DylibCommand associated with the BindingInfo or a nullptr if not present.
Definition BindingInfo.hpp:78
LIEF::MachO::BindingInfo::addend
void addend(int64_t addend)
Definition BindingInfo.hpp:121
LIEF::MachO::BindingInfo::addend
int64_t addend() const
Value added to the segment's virtual address when bound.
Definition BindingInfo.hpp:117
LIEF::MachO::DyldChainedFixupsCreator
Definition DyldChainedFixupsCreator.hpp:41
LIEF::MachO::DylibCommand
Class which represents a library dependency.
Definition DylibCommand.hpp:34
LIEF::MachO::SegmentCommand
Class which represents a LoadCommand::TYPE::SEGMENT / LoadCommand::TYPE::SEGMENT_64 command.
Definition SegmentCommand.hpp:50
LIEF::MachO::Symbol
Class that represents a Symbol in a Mach-O file.
Definition MachO/Symbol.hpp:47
LIEF::MachO
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF::MachO::MACHO_TYPES::UNKNOWN
@ UNKNOWN
Definition MachO/enums.hpp:25
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41