LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
ObjC/Method.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2025 R. Thomas
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15#ifndef LIEF_OBJC_METHOD_H
16#define LIEF_OBJC_METHOD_H
17#include <LIEF/visibility.h>
18
19#include <cstdint>
20#include <memory>
21#include <string>
22
23namespace LIEF {
24namespace objc {
25
26namespace details {
27class Method;
28class MethodIt;
29}
30class LIEF_API Method {
33 public:
34 class LIEF_API Iterator {
35 public:
36 using iterator_category = std::bidirectional_iterator_tag;
37 using value_type = std::unique_ptr<Method>;
38 using difference_type = std::ptrdiff_t;
39 using pointer = Method*;
40 using reference = std::unique_ptr<Method>&;
41 using implementation = details::MethodIt;
42
43 class LIEF_API PointerProxy {
44 // Inspired from LLVM's iterator_facade_base
45 friend class Iterator;
46 public:
47 pointer operator->() const { return R.get(); }
48
49 private:
50 value_type R;
51
52 template <typename RefT>
53 PointerProxy(RefT &&R) : R(std::forward<RefT>(R)) {} // NOLINT(bugprone-forwarding-reference-overload)
54 };
55
56 Iterator(const Iterator&);
57 Iterator(Iterator&&) noexcept;
58 Iterator(std::unique_ptr<details::MethodIt> impl);
59 ~Iterator();
60
61 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
62
63 friend LIEF_API bool operator!=(const Iterator& LHS, const Iterator& RHS) {
64 return !(LHS == RHS);
65 }
66
67 Iterator& operator++();
68 Iterator& operator--();
69
70 Iterator operator--(int) {
71 Iterator tmp = *static_cast<Iterator*>(this);
72 --*static_cast<Iterator *>(this);
73 return tmp;
74 }
75
76 Iterator operator++(int) {
77 Iterator tmp = *static_cast<Iterator*>(this);
78 ++*static_cast<Iterator *>(this);
79 return tmp;
80 }
81
82 std::unique_ptr<Method> operator*() const;
83
84 PointerProxy operator->() const {
85 return static_cast<const Iterator*>(this)->operator*();
86 }
87
88 private:
89 std::unique_ptr<details::MethodIt> impl_;
90 };
91
92 public:
93 Method(std::unique_ptr<details::Method> impl);
94 std::string name() const;
97 std::string mangled_type() const;
100 uintptr_t address() const;
103 bool is_instance() const;
106
108 private:
109 std::unique_ptr<details::Method> impl_;
110};
111
112}
113}
114#endif
pointer operator->() const
Definition ObjC/Method.hpp:47
Iterator(Iterator &&) noexcept
Iterator(const Iterator &)
std::unique_ptr< Method > operator*() const
Iterator operator++(int)
Definition ObjC/Method.hpp:76
Iterator operator--(int)
Definition ObjC/Method.hpp:70
PointerProxy operator->() const
Definition ObjC/Method.hpp:84
This class represents an Objective-C Method.
Definition ObjC/Method.hpp:32
bool is_instance() const
Whether it's an instance method.
Method(std::unique_ptr< details::Method > impl)
std::string name() const
Name of the method.
std::string mangled_type() const
Prototype of the method in its mangled representation (e.g. @16@0:8)
uintptr_t address() const
Virtual address where this method is implemented in the binary.
Definition ObjC/Class.hpp:32
Namespace related to ObjC metadata.
Definition MachO/Binary.hpp:41
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41