LIEF: Library to Instrument Executable Formats Version
Loading...
Searching...
No Matches
BindingInfo.hpp
1/* Copyright 2017 - 2023 R. Thomas
2 * Copyright 2017 - 2023 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
20#include "LIEF/visibility.h"
21#include "LIEF/types.hpp"
22#include "LIEF/Object.hpp"
23
24#include "LIEF/MachO/enums.hpp"
25
26namespace LIEF {
27namespace MachO {
28class DylibCommand;
29class SegmentCommand;
30class Symbol;
31class BinaryParser;
32
40class LIEF_API BindingInfo : public Object {
41
42 friend class BinaryParser;
43
44 public:
45 enum class TYPES {
46 UNKNOWN = 0,
47 DYLD_INFO,
48 CHAINED,
49 CHAINED_LIST,
50 };
51
53
54 BindingInfo(const BindingInfo& other);
55 void swap(BindingInfo& other);
56
58 bool has_segment() const;
59
62 const SegmentCommand* segment() const;
63 SegmentCommand* segment();
64
66 bool has_library() const;
67
70 const DylibCommand* library() const;
71 DylibCommand* library();
72
74 bool has_symbol() const;
75
78 const Symbol* symbol() const;
79 Symbol* symbol();
80
82 virtual uint64_t address() const;
83 virtual void address(uint64_t addr);
84
85 int32_t library_ordinal() const;
86 void library_ordinal(int32_t ordinal);
87
89 int64_t addend() const;
90 void addend(int64_t addend);
91
92 bool is_weak_import() const;
93 void set_weak_import(bool val = true);
94
97 virtual TYPES type() const = 0;
98
99 ~BindingInfo() override;
100
101 void accept(Visitor& visitor) const override;
102
103 LIEF_API friend std::ostream& operator<<(std::ostream& os, const BindingInfo& binding_info);
104
105 protected:
106 SegmentCommand* segment_ = nullptr;
107 Symbol* symbol_ = nullptr;
108 int32_t library_ordinal_ = 0;
109 int64_t addend_ = 0;
110 bool is_weak_import_ = false;
111 DylibCommand* library_ = nullptr;
112 uint64_t address_ = 0;
113};
114
115}
116}
117#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:40
bool has_symbol() const
Check if a MachO::Symbol is associated with the BindingInfo.
bool has_segment() const
Check if a MachO::SegmentCommand is associated with this binding.
const SegmentCommand * segment() const
The MachO::SegmentCommand associated with the BindingInfo or a nullptr of it is not bind to a Segment...
bool has_library() const
Check if a MachO::DylibCommand is tied with the BindingInfo.
const Symbol * symbol() const
MachO::Symbol associated with the BindingInfo or a nullptr if not present.
TYPES
Definition BindingInfo.hpp:45
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.
const DylibCommand * library() const
MachO::DylibCommand associated with the BindingInfo or a nullptr if not present.
int64_t addend() const
Value added to the segment's virtual address when bound.
Class which represents a library dependency.
Definition DylibCommand.hpp:35
Class which represents a LOAD_COMMAND_TYPES::LC_SEGMENT / LOAD_COMMAND_TYPES::LC_SEGMENT_64 command.
Definition SegmentCommand.hpp:48
Class that represents a Symbol in a Mach-O file.
Definition MachO/Symbol.hpp:49
Definition Object.hpp:25
Definition Visitor.hpp:219
LIEF namespace.
Definition Abstract/Binary.hpp:32