LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
NoteAbi.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_ABI_H
17#define LIEF_ELF_NOTE_ABI_H
18
19#include <ostream>
20#include <array>
21#include <memory>
22
23#include "LIEF/visibility.h"
24#include "LIEF/ELF/Note.hpp"
25
26namespace LIEF {
27namespace ELF {
28
30class LIEF_API NoteAbi : public Note {
31 public:
33 enum class ABI {
34 LINUX = 0,
35 GNU,
36 SOLARIS2,
37 FREEBSD,
38 NETBSD,
39 SYLLABLE,
40 NACL
41 };
43 using version_t = std::array<uint32_t, 3>;
44
45 static constexpr size_t abi_offset = 0;
46 static constexpr size_t abi_size = sizeof(uint32_t);
47
48 static constexpr size_t version_offset = abi_size;
49 static constexpr size_t version_size = 3 * sizeof(uint32_t);
50
51 public:
52 using Note::Note;
53
54 std::unique_ptr<Note> clone() const override {
55 return std::unique_ptr<Note>(new NoteAbi(*this));
56 }
57
60
63
64 void version(const version_t& version);
65 void version(ABI abi);
66
67 void dump(std::ostream& os) const override;
68
69 void accept(Visitor& visitor) const override;
70
71 static bool classof(const Note* note) {
72 return note->type() == Note::TYPE::GNU_ABI_TAG;
73 }
74
76 static constexpr uint8_t description_size() {
77 return /* abi */ sizeof(uint32_t) + /* version */ 3 * sizeof(uint32_t);
78 }
79
80 ~NoteAbi() override = default;
81
82 LIEF_API friend
83 std::ostream& operator<<(std::ostream& os, const NoteAbi& note) {
84 note.dump(os);
85 return os;
86 }
87};
88
90
91} // namepsace ELF
92} // namespace LIEF
93
94#endif
Class that wraps the NT_GNU_ABI_TAG note.
Definition NoteAbi.hpp:30
void version(const version_t &version)
std::unique_ptr< Note > clone() const override
Clone the current note and keep its polymorphic type.
Definition NoteAbi.hpp:54
void accept(Visitor &visitor) const override
~NoteAbi() override=default
void version(ABI abi)
void dump(std::ostream &os) const override
result< ABI > abi() const
Return the ABI or an error if it can't be parsed.
std::array< uint32_t, 3 > version_t
Version type: (Major, Minor, Patch)
Definition NoteAbi.hpp:43
static constexpr uint8_t description_size()
Definition NoteAbi.hpp:76
friend std::ostream & operator<<(std::ostream &os, const NoteAbi &note)
Definition NoteAbi.hpp:83
static bool classof(const Note *note)
Definition NoteAbi.hpp:71
result< version_t > version() const
Return the version or an error if it can't be parsed.
ABI
ABI recognized by this note.
Definition NoteAbi.hpp:33
Class which represents an ELF note. This class can be instantiated using the static Note::create func...
Definition Note.hpp:39
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)
LIEF namespace.
Definition Abstract/Binary.hpp:32
tl::expected< T, lief_errors > result
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:74
#define LIEF_API
Definition visibility.h:41