LIEF: Library to Instrument Executable Formats Version 0.17.0
|
Loading...
Searching...
No Matches
Go to the documentation of this file.
16#ifndef LIEF_ELF_NOTE_H
17#define LIEF_ELF_NOTE_H
44 public:
using description_t = std::vector<uint8_t>;
50 UNKNOWN = 0, GNU_ABI_TAG, GNU_HWCAP, GNU_BUILD_ID, GNU_GOLD_VERSION, GNU_PROPERTY_TYPE_0,
65 GNU_BUILD_ATTRIBUTE_OPEN,
66 GNU_BUILD_ATTRIBUTE_FUNC,
73 CORE_FPREGSET, CORE_PRPSINFO,
78 CORE_TASKSTRUCT, CORE_AUXV,
83 CORE_PSTATUS, CORE_FPREGS, CORE_PSINFO,
104 CORE_TAGGED_ADDR_CTRL,
105 CORE_PAC_ENABLED_KEYS,
119 GO_BUILDID, STAPSDT, QNX_STACK
128 public:
static result<TYPE>
convert_type(Header::FILE_TYPE ftype, uint32_t type,
131 const std::string& name);
139 if (sec_name.empty()) {
140 return type_to_section(note.
type());
144 static result<const char*>
type_owner(TYPE type);
147 static std::unique_ptr<Note>
create(
152 const std::string& name, uint32_t type, description_t description,
153 std::string section_name,
154 Header::FILE_TYPE ftype = Header::FILE_TYPE::NONE, ARCH arch = ARCH::NONE,
155 Header::CLASS cls = Header::CLASS::NONE);
156 static std::unique_ptr<Note>
create(
161 const std::string& name, TYPE type, description_t description,
162 std::string section_name,
163 ARCH arch = ARCH::NONE, Header::CLASS cls = Header::CLASS::NONE);
164 static std::unique_ptr<Note>
create(BinaryStream& stream,
169 std::string section_name,
170 Header::FILE_TYPE ftype = Header::FILE_TYPE::NONE, ARCH arch = ARCH::NONE,
171 Header::CLASS cls = Header::CLASS::NONE);
174 Note(
const Note& copy) =
default;
177 virtual std::unique_ptr<Note>
clone()
const {
180 return std::unique_ptr<Note>(
new Note(*
this));
182 const std::string&
name()
const {
190 return section_name_;
202 return original_type_;
215 name_ = std::move(name);
220 description_ = std::move(description);
222 uint64_t
size()
const;
226 virtual void dump(std::ostream& os)
const;
228 void accept(Visitor& visitor)
const override;
231 std::ostream&
operator<<(std::ostream& os,
const Note& note) {
238 static_assert(std::is_base_of<Note, T>::value,
239 "Require Note inheritance");
240 if (T::classof(
this)) {
241 return static_cast<const T*
>(
this);
248 return const_cast<T*
>(
static_cast<const Note*
>(
this)->cast<T>());
253 Note(std::string name, TYPE type, uint32_t original_type,
254 description_t description, std::string section) :
255 name_(std::move(name)),
257 original_type_(original_type),
258 description_(std::move(description)),
259 section_name_(std::move(section))
263 LIEF_LOCAL result<T> read_at(
size_t offset)
const;
271 read_string_at(
size_t offset,
size_t maxsize = 0)
const;
274 TYPE type_ = TYPE::UNKNOWN;
275 uint32_t original_type_ = 0;
276 description_t description_;
277 std::string section_name_;
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:33
Class which represents an ELF binary.
Definition ELF/Binary.hpp:59
Class which takes an ELF::Binary object and reconstructs a valid binary.
Definition ELF/Builder.hpp:48
Class which represents an ELF note. This class can be instantiated using the static Note::create func...
Definition Note.hpp:39
TYPE
LIEF representation of the ELF NT_ values.
Definition Note.hpp:49
const T * cast() const
Definition Note.hpp:237
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
static result< const char * > type_owner(TYPE type)
Try to determine the owner's name of the TYPE provided in parameter.
static std::unique_ptr< Note > create(const std::string &name, TYPE type, description_t description, std::string section_name, ARCH arch=ARCH::NONE, Header::CLASS cls=Header::CLASS::NONE)
Create a new note from the given parameters. Additional information such as the architecture or the E...
friend std::ostream & operator<<(std::ostream &os, const Note ¬e)
Definition Note.hpp:231
static result< std::string > note_to_section(const Note ¬e)
Definition Note.hpp:137
static std::unique_ptr< Note > create(const std::string &name, uint32_t type, description_t description, std::string section_name, Header::FILE_TYPE ftype=Header::FILE_TYPE::NONE, ARCH arch=ARCH::NONE, Header::CLASS cls=Header::CLASS::NONE)
Create a new note from the given parameters. Additional information such as the architecture or the E...
uint32_t original_type() const
The original NT_xxx integer value. The meaning of this value likely depends on the owner of the note.
Definition Note.hpp:201
static std::unique_ptr< Note > create(BinaryStream &stream, std::string section_name, Header::FILE_TYPE ftype=Header::FILE_TYPE::NONE, ARCH arch=ARCH::NONE, Header::CLASS cls=Header::CLASS::NONE)
Create a new note from the given stream. Additional information such as the architecture or the ELF c...
virtual void dump(std::ostream &os) const
static result< const char * > type_to_section(TYPE type)
Try to determine the ELF section name associated with the TYPE provided in parameter.
T * cast()
Definition Note.hpp:247
void description(description_t description)
Change the description of the note.
Definition Note.hpp:219
uint64_t size() const
Size of the raw note which includes padding.
void accept(Visitor &visitor) const override
static result< TYPE > convert_type(Header::FILE_TYPE ftype, uint32_t type, const std::string &name)
Convert the raw integer note type into a TYPE according to the owner.
const std::string & section_name() const
Return the section name in which the note is or should be stored.
Definition Note.hpp:189
const std::string & name() const
Return the name of the note (also known as 'owner' )
Definition Note.hpp:184
virtual std::unique_ptr< Note > clone() const
Clone the current note and keep its polymorphic type.
Definition Note.hpp:179
Note & operator=(const Note ©)=default
Note(const Note ©)=default
span< const uint8_t > description() const
Return the description associated with the note.
Definition Note.hpp:206
span< uint8_t > description()
Definition Note.hpp:210
void name(std::string name)
Definition Note.hpp:214
Class which parses and transforms an ELF file into a ELF::Binary object.
Definition ELF/Parser.hpp:45
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:28
const char * to_string(DynamicEntry::TAG e)
LIEF namespace.
Definition Abstract/Binary.hpp:36
result< ok_t > ok_error_t
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:109
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42