LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
NoteGnuProperty.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2024 R. Thomas
2 * Copyright 2017 - 2024 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:
32
35 class Property {
36 public:
37
39 enum class TYPE {
40 UNKNOWN = 0,
41 GENERIC,
42 AARCH64_FEATURES,
43 STACK_SIZE,
44 NO_COPY_ON_PROTECTED,
45 X86_ISA,
46 X86_FEATURE,
47 NEEDED,
48 };
49
51 TYPE type() const {
52 return type_;
53 }
54
55 virtual void dump(std::ostream& os) const;
56
57 virtual ~Property() = default;
58
59 LIEF_API friend
60 std::ostream& operator<<(std::ostream& os, const Property& prop) {
61 prop.dump(os);
62 return os;
63 }
64
65 protected:
66 Property() = delete;
67 Property(TYPE type) :
68 type_(type) {}
69 TYPE type_ = TYPE::UNKNOWN;
70 };
71
72 using properties_t = std::vector<std::unique_ptr<NoteGnuProperty::Property>>;
73
74 NoteGnuProperty(ARCH arch, Header::CLASS cls, std::string name,
75 uint32_t type, description_t description,
76 std::string secname) :
77 Note(std::move(name), TYPE::GNU_PROPERTY_TYPE_0, type, std::move(description),
78 std::move(secname)),
79 arch_(arch), class_(cls)
80 {}
81
82 std::unique_ptr<Note> clone() const override {
83 return std::unique_ptr<Note>(new NoteGnuProperty(*this));
84 }
85
87 std::unique_ptr<NoteGnuProperty::Property> find(Property::TYPE type) const;
88
91
92 void dump(std::ostream& os) const override;
93
94 void accept(Visitor& visitor) const override;
95
96 static bool classof(const Note* note) {
97 return note->type() == Note::TYPE::GNU_PROPERTY_TYPE_0;
98 }
99
100 ~NoteGnuProperty() override = default;
101
102 LIEF_API friend
103 std::ostream& operator<<(std::ostream& os, const NoteGnuProperty& note) {
104 note.dump(os);
105 return os;
106 }
107
108 protected:
109 ARCH arch_ = ARCH::NONE;
110 Header::CLASS class_ = Header::CLASS::NONE;
111};
112
114
115} // namepsace ELF
116} // namespace LIEF
117
118#endif
CLASS
Match the result of Elfxx_Ehdr.e_ident[EI_CLASS]
Definition ELF/Header.hpp:76
This class wraps the different properties that can be used in a NT_GNU_PROPERTY_TYPE_0 note.
Definition NoteGnuProperty.hpp:35
friend std::ostream & operator<<(std::ostream &os, const Property &prop)
Definition NoteGnuProperty.hpp:60
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:51
virtual void dump(std::ostream &os) const
Class that wraps the NT_GNU_PROPERTY_TYPE_0 note.
Definition NoteGnuProperty.hpp:30
std::vector< std::unique_ptr< NoteGnuProperty::Property > > properties_t
Definition NoteGnuProperty.hpp:72
static bool classof(const Note *note)
Definition NoteGnuProperty.hpp:96
std::unique_ptr< Note > clone() const override
Clone the current note and keep its polymorphic type.
Definition NoteGnuProperty.hpp:82
~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:74
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:103
Class which represents an ELF note. This class can be instantiated using the static Note::create func...
Definition Note.hpp:39
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
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:195
Definition Visitor.hpp:224
const char * to_string(DynamicEntry::TAG e)
ARCH
Machine architectures See current registered ELF machine architectures at: http://www....
Definition ELF/enums.hpp:30
LIEF namespace.
Definition Abstract/Binary.hpp:32
#define LIEF_API
Definition visibility.h:41