LIEF: Library to Instrument Executable Formats Version 0.17.0
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 {
28class LIEF_API NoteGnuProperty : public Note {
31 public:
32 class LIEF_API Property {
36 public:
37 enum class TYPE {
40 UNKNOWN = 0,
41 GENERIC,
42 AARCH64_FEATURES,
43 AARCH64_PAUTH,
44 STACK_SIZE,
45 NO_COPY_ON_PROTECTED,
46 X86_ISA,
47 X86_FEATURE,
48 NEEDED,
49 };
50 TYPE type() const {
53 return type_;
54 }
55
56 virtual void dump(std::ostream& os) const;
57
58 virtual ~Property() = default;
59
60 LIEF_API friend
61 std::ostream& operator<<(std::ostream& os, const Property& prop) {
62 prop.dump(os);
63 return os;
64 }
65
66 protected:
67 Property() = delete;
68 Property(TYPE type) :
69 type_(type) {}
70 TYPE type_ = TYPE::UNKNOWN;
71 };
72
73 using properties_t = std::vector<std::unique_ptr<NoteGnuProperty::Property>>;
74
75 NoteGnuProperty(ARCH arch, Header::CLASS cls, std::string name,
76 uint32_t type, description_t description,
77 std::string secname) :
78 Note(std::move(name), TYPE::GNU_PROPERTY_TYPE_0, type, std::move(description),
79 std::move(secname)),
80 arch_(arch), class_(cls)
81 {}
82
83 std::unique_ptr<Note> clone() const override {
84 return std::unique_ptr<Note>(new NoteGnuProperty(*this));
85 }
86 std::unique_ptr<NoteGnuProperty::Property> find(Property::TYPE type) const;
89 properties_t properties() const;
92
93 void dump(std::ostream& os) const override;
94
95 void accept(Visitor& visitor) const override;
96
97 static bool classof(const Note* note) {
98 return note->type() == Note::TYPE::GNU_PROPERTY_TYPE_0;
99 }
100
101 ~NoteGnuProperty() override = default;
102
103 LIEF_API friend
104 std::ostream& operator<<(std::ostream& os, const NoteGnuProperty& note) {
105 note.dump(os);
106 return os;
107 }
108
109 protected:
110 ARCH arch_ = ARCH::NONE;
111 Header::CLASS class_ = Header::CLASS::NONE;
112};
113
114LIEF_API const char* to_string(NoteGnuProperty::Property::TYPE type);
115
116} // namepsace ELF
117} // namespace LIEF
118
119#endif
Note.hpp
LIEF::ELF::NoteGnuProperty::Property::operator<<
friend std::ostream & operator<<(std::ostream &os, const Property &prop)
Definition NoteGnuProperty.hpp:61
LIEF::ELF::NoteGnuProperty::Property::TYPE
TYPE
LIEF's mirror types of the original GNU_PROPERTY_ values.
Definition NoteGnuProperty.hpp:39
LIEF::ELF::NoteGnuProperty::Property::type
TYPE type() const
Return the LIEF's mirror type of the note.
Definition NoteGnuProperty.hpp:52
LIEF::ELF::NoteGnuProperty::Property::~Property
virtual ~Property()=default
LIEF::ELF::NoteGnuProperty::Property::dump
virtual void dump(std::ostream &os) const
LIEF::ELF::NoteGnuProperty
Class that wraps the NT_GNU_PROPERTY_TYPE_0 note.
Definition NoteGnuProperty.hpp:30
LIEF::ELF::NoteGnuProperty::classof
static bool classof(const Note *note)
Definition NoteGnuProperty.hpp:97
LIEF::ELF::NoteGnuProperty::clone
std::unique_ptr< Note > clone() const override
Clone the current note and keep its polymorphic type.
Definition NoteGnuProperty.hpp:83
LIEF::ELF::NoteGnuProperty::~NoteGnuProperty
~NoteGnuProperty() override=default
LIEF::ELF::NoteGnuProperty::find
std::unique_ptr< NoteGnuProperty::Property > find(Property::TYPE type) const
Find the property with the given type or return a nullptr
LIEF::ELF::NoteGnuProperty::dump
void dump(std::ostream &os) const override
LIEF::ELF::NoteGnuProperty::NoteGnuProperty
NoteGnuProperty(ARCH arch, Header::CLASS cls, std::string name, uint32_t type, description_t description, std::string secname)
Definition NoteGnuProperty.hpp:75
LIEF::ELF::NoteGnuProperty::accept
void accept(Visitor &visitor) const override
LIEF::ELF::NoteGnuProperty::properties
properties_t properties() const
Return the properties as a list of Property.
LIEF::ELF::NoteGnuProperty::operator<<
friend std::ostream & operator<<(std::ostream &os, const NoteGnuProperty &note)
Definition NoteGnuProperty.hpp:104
LIEF::ELF::Note
Class which represents an ELF note. This class can be instantiated using the static Note::create func...
Definition Note.hpp:39
LIEF::ELF::Note::type
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
LIEF::ELF
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:28
LIEF::ELF::to_string
const char * to_string(DynamicEntry::TAG e)
LIEF::ELF::ARCH
ARCH
Definition ELF/enums.hpp:30
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:36
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41