LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
BindingInfo.hpp
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;
30
38class LIEF_API BindingInfo : public Object {
39
40 friend class BinaryParser;
41
42 public:
43 enum class TYPES {
44 UNKNOWN = 0,
45 DYLD_INFO,
46 CHAINED,
47 CHAINED_LIST,
48 };
49
50 BindingInfo() = default;
51
52 BindingInfo(const BindingInfo& other);
53 void swap(BindingInfo& other) noexcept;
54
56 bool has_segment() const {
57 return segment_ != nullptr;
58 }
59
62 const SegmentCommand* segment() const {
63 return segment_;
64 }
65 SegmentCommand* segment() {
66 return segment_;
67 }
68
70 bool has_library() const {
71 return library_ != nullptr;
72 }
73
76 const DylibCommand* library() const {
77 return library_;
78 }
79 DylibCommand* library() {
80 return library_;
81 }
82
84 bool has_symbol() const {
85 return symbol_ != nullptr;
86 }
87
90 const Symbol* symbol() const {
91 return symbol_;
92 }
93 Symbol* symbol() {
94 return symbol_;
95 }
96
98 virtual uint64_t address() const {
99 return address_;
100 }
101
102 virtual void address(uint64_t addr) {
103 address_ = addr;
104 }
105
106 int32_t library_ordinal() const {
107 return library_ordinal_;
108 }
109
110 void library_ordinal(int32_t ordinal) {
111 library_ordinal_ = ordinal;
112 }
113
115 int64_t addend() const {
116 return addend_;
117 }
118
119 void addend(int64_t addend) {
120 addend_ = addend;
121 }
122
123 bool is_weak_import() const {
124 return is_weak_import_;
125 }
126
127 void set_weak_import(bool val = true) {
128 is_weak_import_ = val;
129 }
130
133 virtual TYPES type() const = 0;
134
135 ~BindingInfo() override = default;
136
137 void accept(Visitor& visitor) const override;
138
139 LIEF_API friend std::ostream& operator<<(std::ostream& os, const BindingInfo& binding_info);
140
141 protected:
142 SegmentCommand* segment_ = nullptr;
143 Symbol* symbol_ = nullptr;
144 int32_t library_ordinal_ = 0;
145 int64_t addend_ = 0;
146 bool is_weak_import_ = false;
147 DylibCommand* library_ = nullptr;
148 uint64_t address_ = 0;
149};
150
151}
152}
153#endif
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:73
Class that provides an interface over a binding operation.
Definition BindingInfo.hpp:38
bool has_symbol() const
Check if a MachO::Symbol is associated with the BindingInfo.
Definition BindingInfo.hpp:84
bool has_segment() const
Check if a MachO::SegmentCommand is associated with this binding.
Definition BindingInfo.hpp:56
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:62
bool has_library() const
Check if a MachO::DylibCommand is tied with the BindingInfo.
Definition BindingInfo.hpp:70
const Symbol * symbol() const
MachO::Symbol associated with the BindingInfo or a nullptr if not present.
Definition BindingInfo.hpp:90
TYPES
Definition BindingInfo.hpp:43
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...
virtual uint64_t address() const
Address of the binding.
Definition BindingInfo.hpp:98
const DylibCommand * library() const
MachO::DylibCommand associated with the BindingInfo or a nullptr if not present.
Definition BindingInfo.hpp:76
int64_t addend() const
Value added to the segment's virtual address when bound.
Definition BindingInfo.hpp:115
Class which represents a library dependency.
Definition DylibCommand.hpp:34
Class which represents a LoadCommand::TYPE::SEGMENT / LoadCommand::TYPE::SEGMENT_64 command.
Definition SegmentCommand.hpp:48
Class that represents a Symbol in a Mach-O file.
Definition MachO/Symbol.hpp:47
Definition Object.hpp:25
Definition Visitor.hpp:219
LIEF namespace.
Definition Abstract/Binary.hpp:32