LIEF: Library to Instrument Executable Formats Version 0.16.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/iterators.hpp"
20
21namespace LIEF {
22namespace MachO {
23class Binary;
24class DyldInfo;
25class DyldChainedFixups;
26
28 public iterator_facade_base<BindingInfoIterator,
29 std::random_access_iterator_tag,
30 const BindingInfo&,
31 std::ptrdiff_t,
32 const BindingInfo*,
33 const BindingInfo&
34 >
35{
36 public:
37 enum class ORIGIN : uint8_t {
38 NONE = 0,
39 DYLD,
42 };
43
47
48 BindingInfoIterator(const DyldInfo& dyld_info, size_t pos) :
49 pos_(pos),
50 origin_(ORIGIN::DYLD),
51 dyld_info_(&dyld_info)
52 {}
53
54 BindingInfoIterator(const DyldChainedFixups& fixups, size_t pos) :
55 pos_(pos),
56 origin_(ORIGIN::CHAINED_FIXUPS),
57 chained_fixups_(&fixups)
58 {}
59
60 BindingInfoIterator(const Binary& binary, size_t pos) :
61 pos_(pos),
62 origin_(ORIGIN::INDIRECT),
63 binary_(&binary)
64 {}
65
66 bool operator<(const BindingInfoIterator& rhs) const {
67 return pos_ < rhs.pos_;
68 }
69
70 std::ptrdiff_t operator-(const BindingInfoIterator& R) const {
71 return pos_ - R.pos_;
72 }
73
74 BindingInfoIterator& operator+=(std::ptrdiff_t n) {
75 pos_ += n;
76 return *this;
77 }
78
79 BindingInfoIterator& operator-=(std::ptrdiff_t n) {
80 pos_ -= n;
81 return *this;
82 }
83
84 friend bool operator==(const BindingInfoIterator& LHS, const BindingInfoIterator& RHS) {
85 return LHS.pos_ == RHS.pos_;
86 }
87
88 const BindingInfo& operator*() const;
89
90 private:
91 BindingInfoIterator() = default;
92 size_t pos_ = 0;
93 ORIGIN origin_ = ORIGIN::NONE;
94 union {
95 const DyldInfo* dyld_info_ = nullptr;
98 };
99
100};
101
102}
103}
104#endif
105
Class which represents a MachO binary.
Definition MachO/Binary.hpp:83
Definition BindingInfoIterator.hpp:35
BindingInfoIterator(BindingInfoIterator &&)=default
BindingInfoIterator(const DyldChainedFixups &fixups, size_t pos)
Definition BindingInfoIterator.hpp:54
BindingInfoIterator(const DyldInfo &dyld_info, size_t pos)
Definition BindingInfoIterator.hpp:48
BindingInfoIterator(const Binary &binary, size_t pos)
Definition BindingInfoIterator.hpp:60
bool operator<(const BindingInfoIterator &rhs) const
Definition BindingInfoIterator.hpp:66
friend bool operator==(const BindingInfoIterator &LHS, const BindingInfoIterator &RHS)
Definition BindingInfoIterator.hpp:84
BindingInfoIterator & operator+=(std::ptrdiff_t n)
Definition BindingInfoIterator.hpp:74
const DyldChainedFixups * chained_fixups_
Definition BindingInfoIterator.hpp:96
BindingInfoIterator & operator-=(std::ptrdiff_t n)
Definition BindingInfoIterator.hpp:79
BindingInfoIterator(const BindingInfoIterator &)=default
const Binary * binary_
Definition BindingInfoIterator.hpp:97
const BindingInfo & operator*() const
const DyldInfo * dyld_info_
Definition BindingInfoIterator.hpp:95
ORIGIN
Definition BindingInfoIterator.hpp:37
std::ptrdiff_t operator-(const BindingInfoIterator &R) const
Definition BindingInfoIterator.hpp:70
Class that provides an interface over a binding operation.
Definition BindingInfo.hpp:38
Class that represents the LC_DYLD_CHAINED_FIXUPS command.
Definition DyldChainedFixups.hpp:48
Class that represents the LC_DYLD_INFO and LC_DYLD_INFO_ONLY commands.
Definition DyldInfo.hpp:50
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition iterators.hpp:590
LIEF namespace.
Definition Abstract/Binary.hpp:32