LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
BindingInfoIterator.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2026 R. Thomas
2 * Copyright 2017 - 2026 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&, std::ptrdiff_t,
32 const BindingInfo*, const BindingInfo&> {
33 public:
34 enum class ORIGIN : uint8_t {
35 NONE = 0,
36 DYLD,
37 CHAINED_FIXUPS,
38 INDIRECT,
39 };
40
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 BindingInfoIterator(const DyldChainedFixups& fixups, size_t pos) :
54 pos_(pos),
55 origin_(ORIGIN::CHAINED_FIXUPS),
56 chained_fixups_(&fixups) {}
57
58 BindingInfoIterator(const Binary& binary, size_t pos) :
59 pos_(pos),
60 origin_(ORIGIN::INDIRECT),
61 binary_(&binary) {}
62
63 bool operator<(const BindingInfoIterator& rhs) const {
64 return pos_ < rhs.pos_;
65 }
66
67 std::ptrdiff_t operator-(const BindingInfoIterator& R) const {
68 return pos_ - R.pos_;
69 }
70
71 BindingInfoIterator& operator+=(std::ptrdiff_t n) {
72 pos_ += n;
73 return *this;
74 }
75
76 BindingInfoIterator& operator-=(std::ptrdiff_t n) {
77 pos_ -= n;
78 return *this;
79 }
80
81 friend bool operator==(const BindingInfoIterator& LHS,
82 const BindingInfoIterator& RHS) {
83 return LHS.pos_ == RHS.pos_;
84 }
85
86 const BindingInfo& operator*() const;
87
88 private:
90 size_t pos_ = 0;
91 ORIGIN origin_ = ORIGIN::NONE;
92 union {
93 const DyldInfo* dyld_info_ = nullptr;
96 };
97};
98
99}
100}
101#endif
Class which represents a MachO binary.
Definition MachO/Binary.hpp:88
BindingInfoIterator(BindingInfoIterator &&)=default
BindingInfoIterator(const DyldChainedFixups &fixups, size_t pos)
Definition BindingInfoIterator.hpp:53
BindingInfoIterator & operator=(BindingInfoIterator &&)=default
BindingInfoIterator(const DyldInfo &dyld_info, size_t pos)
Definition BindingInfoIterator.hpp:48
BindingInfoIterator(const Binary &binary, size_t pos)
Definition BindingInfoIterator.hpp:58
bool operator<(const BindingInfoIterator &rhs) const
Definition BindingInfoIterator.hpp:63
friend bool operator==(const BindingInfoIterator &LHS, const BindingInfoIterator &RHS)
Definition BindingInfoIterator.hpp:81
BindingInfoIterator & operator+=(std::ptrdiff_t n)
Definition BindingInfoIterator.hpp:71
const DyldChainedFixups * chained_fixups_
Definition BindingInfoIterator.hpp:94
BindingInfoIterator & operator-=(std::ptrdiff_t n)
Definition BindingInfoIterator.hpp:76
BindingInfoIterator(const BindingInfoIterator &)=default
const Binary * binary_
Definition BindingInfoIterator.hpp:95
const BindingInfo & operator*() const
BindingInfoIterator & operator=(const BindingInfoIterator &)=default
const DyldInfo * dyld_info_
Definition BindingInfoIterator.hpp:93
ORIGIN
Definition BindingInfoIterator.hpp:34
@ NONE
Definition BindingInfoIterator.hpp:35
std::ptrdiff_t operator-(const BindingInfoIterator &R) const
Definition BindingInfoIterator.hpp:67
Class that provides an interface over a binding operation.
Definition BindingInfo.hpp:40
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
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition iterators.hpp:685
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF namespace.
Definition Abstract/Binary.hpp:40
#define LIEF_API
Definition visibility.h:43
#define LIEF_LOCAL
Definition visibility.h:44