LIEF: Library to Instrument Executable Formats Version 1.0.0
Loading...
Searching...
No Matches
NoteGnuProperty.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_ELF_NOTE_GNU_PROPERTY_H
17#define LIEF_ELF_NOTE_GNU_PROPERTY_H
18
19#include <vector>
20#include <ostream>
21#include <memory>
22
23#include "LIEF/visibility.h"
24#include "LIEF/ELF/Note.hpp"
25
26namespace LIEF {
27namespace ELF {
28
31 public:
35 public:
36 Property() = delete;
37
39 enum class TYPE {
40 UNKNOWN = 0,
41
43 GENERIC,
44
46 AARCH64_FEATURES,
47
49 AARCH64_PAUTH,
50
52 STACK_SIZE,
53
55 NO_COPY_ON_PROTECTED,
56
58 X86_ISA,
59
61 X86_FEATURE,
62
63 NEEDED,
64 };
65
67 TYPE type() const {
68 return type_;
69 }
70
71 virtual void dump(std::ostream& os) const;
72
73 virtual ~Property() = default;
74
75 LIEF_API friend std::ostream& operator<<(std::ostream& os,
76 const Property& prop) {
77 prop.dump(os);
78 return os;
79 }
80
81 protected:
83 type_(type) {}
84 TYPE type_ = TYPE::UNKNOWN;
85 };
86
87 using properties_t = std::vector<std::unique_ptr<NoteGnuProperty::Property>>;
88
89 NoteGnuProperty(ARCH arch, Header::CLASS cls, std::string name, uint32_t type,
90 description_t description, std::string secname) :
91 Note(std::move(name), TYPE::GNU_PROPERTY_TYPE_0, type, std::move(description),
92 std::move(secname)),
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} // namespace ELF
130} // namespace LIEF
131
132#endif
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:34
friend std::ostream & operator<<(std::ostream &os, const Property &prop)
Definition NoteGnuProperty.hpp:75
TYPE
LIEF's mirror types of the original GNU_PROPERTY_ values.
Definition NoteGnuProperty.hpp:39
TYPE type() const
Return the LIEF's mirror type of the note.
Definition NoteGnuProperty.hpp:67
virtual void dump(std::ostream &os) const
std::vector< std::unique_ptr< NoteGnuProperty::Property > > properties_t
Definition NoteGnuProperty.hpp:87
static bool classof(const Note *note)
Definition NoteGnuProperty.hpp:110
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
NoteGnuProperty(ARCH arch, Header::CLASS cls, std::string name, uint32_t type, description_t description, std::string secname)
Definition NoteGnuProperty.hpp:89
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:46
TYPE
LIEF representation of the ELF NT_ values.
Definition Note.hpp:49
@ GNU_PROPERTY_TYPE_0
Match NT_GNU_PROPERTY_TYPE_0: Program property note, as described in "Linux Extensions to the gABI".
Definition Note.hpp:67
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:204
const std::string & name() const
Return the name of the note (also known as 'owner' ).
Definition Note.hpp:193
Note(const Note &copy)=default
span< const uint8_t > description() const
Return the description associated with the note.
Definition Note.hpp:215
Definition Visitor.hpp:212
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:28
const char * to_string(DynamicEntry::TAG e)
ARCH
Definition ELF/enums.hpp:30
@ NONE
Definition ELF/enums.hpp:31
LIEF namespace.
Definition Abstract/Binary.hpp:40
#define LIEF_API
Definition visibility.h:45