LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
BindingInfoIterator.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_IT_H
17#define LIEF_MACHO_BINDING_INFO_IT_H
18#include "LIEF/visibility.h"
19#include "LIEF/iterators.hpp"
21
22namespace LIEF {
23namespace MachO {
24class Binary;
25class DyldInfo;
27
29 public iterator_facade_base<BindingInfoIterator,
30 std::random_access_iterator_tag,
31 const BindingInfo&,
32 std::ptrdiff_t,
33 const BindingInfo*,
34 const BindingInfo&
35 >
36{
37 public:
38 enum class ORIGIN : uint8_t {
39 NONE = 0,
40 DYLD,
41 CHAINED_FIXUPS,
42 INDIRECT,
43 };
44
45 BindingInfoIterator& operator=(const BindingInfoIterator&) = default;
46 BindingInfoIterator(const BindingInfoIterator&) = default;
47
48 BindingInfoIterator(BindingInfoIterator&&) = default;
49 BindingInfoIterator& operator=(BindingInfoIterator&&) = default;
51
52 BindingInfoIterator(const DyldInfo& dyld_info, size_t pos) :
53 pos_(pos),
54 origin_(ORIGIN::DYLD),
55 dyld_info_(&dyld_info)
56 {}
57
58 BindingInfoIterator(const DyldChainedFixups& fixups, size_t pos) :
59 pos_(pos),
60 origin_(ORIGIN::CHAINED_FIXUPS),
61 chained_fixups_(&fixups)
62 {}
63
64 BindingInfoIterator(const Binary& binary, size_t pos) :
65 pos_(pos),
66 origin_(ORIGIN::INDIRECT),
67 binary_(&binary)
68 {}
69
70 bool operator<(const BindingInfoIterator& rhs) const {
71 return pos_ < rhs.pos_;
72 }
73
74 std::ptrdiff_t operator-(const BindingInfoIterator& R) const {
75 return pos_ - R.pos_;
76 }
77
78 BindingInfoIterator& operator+=(std::ptrdiff_t n) {
79 pos_ += n;
80 return *this;
81 }
82
83 BindingInfoIterator& operator-=(std::ptrdiff_t n) {
84 pos_ -= n;
85 return *this;
86 }
87
88 friend bool operator==(const BindingInfoIterator& LHS, const BindingInfoIterator& RHS) {
89 return LHS.pos_ == RHS.pos_;
90 }
91
92 const BindingInfo& operator*() const;
93
94 private:
95 LIEF_LOCAL BindingInfoIterator() = default;
96 size_t pos_ = 0;
97 ORIGIN origin_ = ORIGIN::NONE;
98 union {
99 const DyldInfo* dyld_info_ = nullptr;
100 const DyldChainedFixups* chained_fixups_;
101 const Binary* binary_;
102 };
103
104};
105
106}
107}
108#endif
109
Class which represents a MachO binary.
Definition MachO/Binary.hpp:86
Definition BindingInfoIterator.hpp:36
BindingInfoIterator(BindingInfoIterator &&)=default
BindingInfoIterator(const DyldChainedFixups &fixups, size_t pos)
Definition BindingInfoIterator.hpp:58
BindingInfoIterator & operator=(BindingInfoIterator &&)=default
BindingInfoIterator(const DyldInfo &dyld_info, size_t pos)
Definition BindingInfoIterator.hpp:52
BindingInfoIterator(const Binary &binary, size_t pos)
Definition BindingInfoIterator.hpp:64
bool operator<(const BindingInfoIterator &rhs) const
Definition BindingInfoIterator.hpp:70
friend bool operator==(const BindingInfoIterator &LHS, const BindingInfoIterator &RHS)
Definition BindingInfoIterator.hpp:88
BindingInfoIterator & operator+=(std::ptrdiff_t n)
Definition BindingInfoIterator.hpp:78
BindingInfoIterator & operator-=(std::ptrdiff_t n)
Definition BindingInfoIterator.hpp:83
BindingInfoIterator(const BindingInfoIterator &)=default
const BindingInfo & operator*() const
BindingInfoIterator & operator=(const BindingInfoIterator &)=default
std::ptrdiff_t operator-(const BindingInfoIterator &R) const
Definition BindingInfoIterator.hpp:74
Class that represents the LC_DYLD_CHAINED_FIXUPS command.
Definition DyldChainedFixups.hpp:49
Class that represents the LC_DYLD_INFO and LC_DYLD_INFO_ONLY commands.
Definition DyldInfo.hpp:50
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42