LIEF: Library to Instrument Executable Formats Version 2.0.0
Loading...
Searching...
No Matches
NoteGnuProperty.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 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_ELF_NOTE_GNU_PROPERTY_H
16#define LIEF_ELF_NOTE_GNU_PROPERTY_H
17
18#include <memory>
19#include <ostream>
20#include <vector>
21
22#include "LIEF/ELF/Note.hpp"
23#include "LIEF/visibility.h"
24
25
26namespace LIEF::ELF {
27
30 public:
34 public:
35 Property() = delete;
36
38 enum class TYPE {
39 UNKNOWN = 0,
40
42 GENERIC,
43
45 AARCH64_FEATURES,
46
48 AARCH64_PAUTH,
49
51 STACK_SIZE,
52
54 NO_COPY_ON_PROTECTED,
55
57 X86_ISA,
58
60 X86_FEATURE,
61
62 NEEDED,
63 };
64
66 TYPE type() const {
67 return type_;
68 }
69
70 virtual void dump(std::ostream& os) const;
71
72 virtual ~Property() = default;
73
74 LIEF_API friend std::ostream& operator<<(std::ostream& os,
75 const Property& prop) {
76 prop.dump(os);
77 return os;
78 }
79
80 protected:
82 type_(type) {}
83 TYPE type_ = TYPE::UNKNOWN;
84 };
85
86 using properties_t = std::vector<std::unique_ptr<NoteGnuProperty::Property>>;
87
88 NoteGnuProperty(ARCH arch, Header::CLASS cls, std::string name, uint32_t type,
89 description_t description, std::string secname,
91 Note(std::move(name), TYPE::GNU_PROPERTY_TYPE_0, type, std::move(description),
92 std::move(secname), endianness),
93 arch_(arch),
94 class_(cls) {}
95
96 std::unique_ptr<Note> clone() const override {
97 return std::unique_ptr<Note>(new NoteGnuProperty(*this));
98 }
99
101 std::unique_ptr<NoteGnuProperty::Property> find(Property::TYPE type) const;
102
105
106 void dump(std::ostream& os) const override;
107
108 void accept(Visitor& visitor) const override;
109
110 static bool classof(const Note* note) {
111 return note->type() == Note::TYPE::GNU_PROPERTY_TYPE_0;
112 }
113
114 ~NoteGnuProperty() override = default;
115
116 LIEF_API friend std::ostream& operator<<(std::ostream& os,
117 const NoteGnuProperty& note) {
118 note.dump(os);
119 return os;
120 }
121
122 protected:
123 ARCH arch_ = ARCH::NONE;
125};
126
128
129}
130
131
132#endif
ELF_DATA
Match the result Elfxx_Ehdr.e_ident[EI_DATA].
Definition ELF/Header.hpp:108
@ LSB
2's complement, little endian
Definition ELF/Header.hpp:110
CLASS
Match the result of Elfxx_Ehdr.e_ident[EI_CLASS].
Definition ELF/Header.hpp:74
@ NONE
Invalid class.
Definition ELF/Header.hpp:75
This class wraps the different properties that can be used in a NT_GNU_PROPERTY_TYPE_0 note.
Definition NoteGnuProperty.hpp:33
friend std::ostream & operator<<(std::ostream &os, const Property &prop)
Definition NoteGnuProperty.hpp:74
TYPE
LIEF's mirror types of the original GNU_PROPERTY_ values.
Definition NoteGnuProperty.hpp:38
TYPE type() const
Return the LIEF's mirror type of the note.
Definition NoteGnuProperty.hpp:66
virtual void dump(std::ostream &os) const
std::vector< std::unique_ptr< NoteGnuProperty::Property > > properties_t
Definition NoteGnuProperty.hpp:86
static bool classof(const Note *note)
Definition NoteGnuProperty.hpp:110
NoteGnuProperty(ARCH arch, Header::CLASS cls, std::string name, uint32_t type, description_t description, std::string secname, Header::ELF_DATA endianness=Header::ELF_DATA::LSB)
Definition NoteGnuProperty.hpp:88
std::unique_ptr< Note > clone() const override
Clone the current note and keep its polymorphic type.
Definition NoteGnuProperty.hpp:96
~NoteGnuProperty() override=default
std::unique_ptr< NoteGnuProperty::Property > find(Property::TYPE type) const
Find the property with the given type or return a nullptr.
void dump(std::ostream &os) const override
void accept(Visitor &visitor) const override
properties_t properties() const
Return the properties as a list of Property.
friend std::ostream & operator<<(std::ostream &os, const NoteGnuProperty &note)
Definition NoteGnuProperty.hpp:116
std::vector< uint8_t > description_t
Container used to handle the description data.
Definition Note.hpp:47
TYPE
LIEF representation of the ELF NT_ values.
Definition Note.hpp:50
@ GNU_PROPERTY_TYPE_0
Match NT_GNU_PROPERTY_TYPE_0: Program property note, as described in "Linux Extensions to the gABI".
Definition Note.hpp:68
TYPE type() const
Return the type of the note. This type does not match the NT_ type value. For accessing the original ...
Definition Note.hpp:206
std::string_view name() const
Return the name of the note (also known as 'owner' ).
Definition Note.hpp:195
Note(const Note &copy)=default
span< const uint8_t > description() const
Return the description associated with the note.
Definition Note.hpp:217
Definition Visitor.hpp:211
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:27
const char * to_string(DynamicEntry::TAG e)
ARCH
Definition ELF/enums.hpp:27
@ NONE
Definition ELF/enums.hpp:28
#define LIEF_API
Definition visibility.h:44