LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
NoteCommand.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_NOTE_COMMAND_H
17#define LIEF_MACHO_NOTE_COMMAND_H
18#include <algorithm>
19#include <memory>
20#include <ostream>
21#include <string>
22
24#include "LIEF/span.hpp"
25#include "LIEF/visibility.h"
26
28
29
30namespace LIEF::MachO {
31
32namespace details {
33struct note_command;
34}
35
40 public:
41 NoteCommand() = default;
42 NoteCommand(const details::note_command& cmd);
43
44 NoteCommand& operator=(const NoteCommand& copy) = default;
45 NoteCommand(const NoteCommand& copy) = default;
46
47 std::unique_ptr<LoadCommand> clone() const override {
48 return std::make_unique<NoteCommand>(*this);
49 }
50
52 uint64_t note_offset() const {
53 return note_offset_;
54 }
55
57 uint64_t note_size() const {
58 return note_size_;
59 }
60
63 return owner_;
64 }
65
67 return owner_;
68 }
69
71 std::string owner_str() const {
72 const auto end = std::find(owner_.begin(), owner_.end(), '\0');
73 return {owner_.begin(), end};
74 }
75
76 void note_offset(uint64_t offset) {
77 note_offset_ = offset;
78 }
79
80 void note_size(uint64_t size) {
81 note_size_ = size;
82 }
83
84 ~NoteCommand() override = default;
85
86 std::ostream& print(std::ostream& os) const override;
87
88 void accept(Visitor& visitor) const override;
89
90 static bool classof(const LoadCommand* cmd) {
91 return cmd->command() == LoadCommand::TYPE::NOTE;
92 }
93
94 private:
95 std::array<char, 16> owner_;
96 uint64_t note_offset_ = 0;
97 uint64_t note_size_ = 0;
98};
99
100}
101
102#endif
uint32_t size() const
Size of the command (should be greater than sizeof(load_command)).
Definition LoadCommand.hpp:137
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:132
@ NOTE
Definition LoadCommand.hpp:98
std::ostream & print(std::ostream &os) const override
span< char > owner()
Definition NoteCommand.hpp:66
uint64_t note_offset() const
Offset of the data associated with this note.
Definition NoteCommand.hpp:52
void accept(Visitor &visitor) const override
span< const char > owner() const
Owner of the note (e.g. AIR_METALLIB).
Definition NoteCommand.hpp:62
std::unique_ptr< LoadCommand > clone() const override
Definition NoteCommand.hpp:47
std::string owner_str() const
Owner as a zero-terminated string.
Definition NoteCommand.hpp:71
NoteCommand(const details::note_command &cmd)
void note_size(uint64_t size)
Definition NoteCommand.hpp:80
static bool classof(const LoadCommand *cmd)
Definition NoteCommand.hpp:90
uint64_t note_size() const
Size of the data referenced by the note_offset.
Definition NoteCommand.hpp:57
NoteCommand & operator=(const NoteCommand &copy)=default
~NoteCommand() override=default
NoteCommand(const NoteCommand &copy)=default
void note_offset(uint64_t offset)
Definition NoteCommand.hpp:76
Definition Visitor.hpp:212
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
Definition endianness_support.hpp:59
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:45