LIEF: Library to Instrument Executable Formats Version 0.16.0
Loading...
Searching...
No Matches
Instruction.hpp
Go to the documentation of this file.
1/* Copyright 2022 - 2024 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_INST_H
16#define LIEF_ASM_INST_H
17#include "LIEF/visibility.h"
18#include "LIEF/iterators.hpp"
19
20#include <ostream>
21#include <memory>
22#include <string>
23
24namespace LIEF {
25namespace assembly {
26
27namespace details {
28class Instruction;
29class InstructionIt;
30}
34 public:
35 class Iterator final :
36 public iterator_facade_base<Iterator, std::forward_iterator_tag, std::unique_ptr<Instruction>,
37 std::ptrdiff_t, Instruction*, std::unique_ptr<Instruction>>
38 {
39 public:
40 using implementation = details::InstructionIt;
41
42 LIEF_API Iterator(std::unique_ptr<details::InstructionIt> impl);
43 LIEF_API Iterator(const Iterator&);
44 LIEF_API Iterator& operator=(const Iterator&);
45
46 LIEF_API Iterator(Iterator&&) noexcept;
47 LIEF_API Iterator& operator=(Iterator&&) noexcept;
48
49 LIEF_API ~Iterator();
50
51 LIEF_API Iterator& operator++();
52
53 friend LIEF_API bool operator==(const Iterator& LHS, const Iterator& RHS);
54
55 friend bool operator!=(const Iterator& LHS, const Iterator& RHS) {
56 return !(LHS == RHS);
57 }
58
59 LIEF_API std::unique_ptr<Instruction> operator*() const;
60
61 private:
62 std::unique_ptr<details::InstructionIt> impl_;
63 };
64 public:
65 static LIEF_LOCAL std::unique_ptr<Instruction>
68 create(std::unique_ptr<details::Instruction> impl);
69
70 virtual ~Instruction();
71 uint64_t address() const;
74 size_t size() const;
77 const std::vector<uint8_t>& raw() const;
80 std::string mnemonic() const;
83 std::string to_string() const;
86
87 friend LIEF_API std::ostream& operator<<(std::ostream& os, const Instruction& inst) {
88 os << inst.to_string();
89 return os;
90 }
91
92 protected:
93 Instruction(std::unique_ptr<details::Instruction> impl);
94 std::unique_ptr<details::Instruction> impl_;
95};
96}
97}
98#endif
Iterator & operator=(const Iterator &)
std::unique_ptr< Instruction > operator*() const
Iterator(std::unique_ptr< details::InstructionIt > impl)
This class represents an assembly instruction.
Definition Instruction.hpp:33
std::string mnemonic() const
Instruction mnemonic (e.g. br)
std::string to_string() const
Representation of the current instruction in a pretty assembly way.
uint64_t address() const
Address of the instruction.
const std::vector< uint8_t > & raw() const
Raw bytes of the current instruction.
friend std::ostream & operator<<(std::ostream &os, const Instruction &inst)
Definition Instruction.hpp:87
size_t size() const
Size of the instruction in bytes.
Definition Engine.hpp:28
Namespace related to assembly/disassembly support.
Definition Abstract/Binary.hpp:43
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42