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