LIEF: Library to Instrument Executable Formats
Version 1.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
install
linux
x86_64
sdk
static
include
LIEF
asm
ebpf
ebpf/Operand.hpp
Go to the documentation of this file.
1
/* Copyright 2022 - 2026 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_ASM_EBPF_OPERAND_H
16
#define LIEF_ASM_EBPF_OPERAND_H
17
#include "
LIEF/visibility.h
"
18
#include "
LIEF/compiler_attributes.hpp
"
19
#include "
LIEF/iterators.hpp
"
20
21
#include <memory>
22
#include <string>
23
#include <cassert>
24
25
#include <ostream>
26
27
namespace
LIEF
{
28
namespace
assembly
{
29
namespace
ebpf
{
30
31
namespace
details
{
32
class
Operand
;
33
class
OperandIt;
34
}
35
37
class
LIEF_API
Operand {
38
public
:
40
class
Iterator
final
41
:
public
iterator_facade_base
<Iterator, std::forward_iterator_tag, Operand,
42
std::ptrdiff_t, const Operand*, const Operand&> {
43
public
:
44
using
implementation
= details::OperandIt;
45
using
iterator_facade_base::operator++;
46
47
LIEF_API
Iterator
();
48
49
LIEF_API
Iterator
(std::unique_ptr<details::OperandIt> impl);
50
LIEF_API
Iterator
(
const
Iterator
&);
51
LIEF_API
Iterator
&
operator=
(
const
Iterator
&);
52
53
LIEF_API
Iterator
(
Iterator
&&) noexcept;
54
LIEF_API
Iterator
& operator=(
Iterator
&&) noexcept;
55
56
LIEF_API
~
Iterator
();
57
58
// NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
59
LIEF_API
Iterator
& operator++()
LIEF_LIFETIMEBOUND
;
60
61
friend
LIEF_API
bool
operator==(const
Iterator
& LHS, const
Iterator
& RHS);
62
63
friend
bool
operator!=(const
Iterator
& LHS, const
Iterator
& RHS) {
64
return
!(LHS == RHS);
65
}
66
67
LIEF_API
const
Operand&
operator*
() const
LIEF_LIFETIMEBOUND
;
68
69
// NOLINTNEXTLINE(bugprone-derived-method-shadowing-base-method)
70
LIEF_API
const Operand* operator->() const
LIEF_LIFETIMEBOUND
;
71
74
LIEF_API
std::unique_ptr<Operand>
yield
();
75
76
private:
77
void
load() const;
78
79
std::unique_ptr<
details
::OperandIt> impl_;
80
mutable std::unique_ptr<Operand> cached_;
81
};
82
84
std::
string
to_string
() const;
85
94
template<class T>
95
const T*
as
() const
LIEF_LIFETIMEBOUND
{
96
static_assert
(std::is_base_of<Operand, T>::value,
97
"Require Operand inheritance"
);
98
if
(T::classof(
this
)) {
99
return
static_cast<
const
T*
>
(
this
);
100
}
101
return
nullptr
;
102
}
103
104
virtual
~Operand
();
105
107
static
LIEF_LOCAL
std::unique_ptr<Operand>
108
create(std::unique_ptr<details::Operand> impl);
109
111
LIEF_LOCAL
const
details::Operand& impl() const
LIEF_LIFETIMEBOUND
{
112
assert(impl_ !=
nullptr
);
113
return
*impl_;
114
}
115
117
LIEF_LOCAL
details::Operand& impl()
LIEF_LIFETIMEBOUND
{
118
assert(impl_ !=
nullptr
);
119
return
*impl_;
120
}
121
122
friend
LIEF_API
std::ostream&
operator<<
(std::ostream& os,
const
Operand& op) {
123
os << op.
to_string
();
124
return
os;
125
}
126
127
protected
:
128
LIEF_LOCAL
Operand
(std::unique_ptr<details::Operand> impl);
129
std::unique_ptr<details::Operand> impl_;
130
};
131
132
}
133
}
134
}
135
136
#endif
LIEF::assembly::ebpf::Operand::Iterator::operator=
Iterator & operator=(const Iterator &)
LIEF::assembly::ebpf::Operand::Iterator::operator*
const Operand & operator*() const
LIEF::assembly::ebpf::Operand::Iterator::implementation
details::OperandIt implementation
Definition
ebpf/Operand.hpp:44
LIEF::assembly::ebpf::Operand::Iterator::Iterator
Iterator(Iterator &&) noexcept
LIEF::assembly::ebpf::Operand::Iterator::Iterator
Iterator()
LIEF::assembly::ebpf::Operand::Iterator::Iterator
Iterator(std::unique_ptr< details::OperandIt > impl)
LIEF::assembly::ebpf::Operand::Iterator::Iterator
Iterator(const Iterator &)
LIEF::assembly::ebpf::Operand::Iterator::yield
std::unique_ptr< Operand > yield()
Transfer ownership of the operand at the current position to the caller. Returns nullptr if the itera...
LIEF::assembly::ebpf::Operand
This class represents an operand for an eBPF instruction.
Definition
ebpf/Operand.hpp:37
LIEF::assembly::ebpf::Operand::as
const T * as() const
This function can be used to down cast an Operand instance:
Definition
ebpf/Operand.hpp:95
LIEF::assembly::ebpf::Operand::operator<<
friend std::ostream & operator<<(std::ostream &os, const Operand &op)
Definition
ebpf/Operand.hpp:122
LIEF::assembly::ebpf::Operand::to_string
std::string to_string() const
Pretty representation of the operand.
LIEF::assembly::ebpf::Operand::~Operand
virtual ~Operand()
LIEF::iterator_facade_base
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
Definition
iterators.hpp:750
compiler_attributes.hpp
LIEF_LIFETIMEBOUND
#define LIEF_LIFETIMEBOUND
Definition
compiler_attributes.hpp:72
iterators.hpp
LIEF::assembly::ebpf::details
Definition
ebpf/Operand.hpp:31
LIEF::assembly::ebpf
eBPF architecture-related namespace
Definition
ebpf/Instruction.hpp:28
LIEF::assembly
Namespace related to assembly/disassembly support.
Definition
Abstract/Binary.hpp:48
LIEF
LIEF namespace.
Definition
Abstract/Binary.hpp:41
visibility.h
LIEF_API
#define LIEF_API
Definition
visibility.h:45
LIEF_LOCAL
#define LIEF_LOCAL
Definition
visibility.h:46
Generated by
1.18.0