16#ifndef LIEF_ELF_SEGMENT_H
17#define LIEF_ELF_SEGMENT_H
34namespace DataHandler {
56 static constexpr uint64_t PT_BIT = 33;
57 static constexpr uint64_t PT_MASK = (uint64_t(1) << PT_BIT) - 1;
59 static constexpr uint64_t PT_ARM = uint64_t(1) << PT_BIT;
60 static constexpr uint64_t PT_AARCH64 = uint64_t(2) << PT_BIT;
61 static constexpr uint64_t PT_MIPS = uint64_t(3) << PT_BIT;
62 static constexpr uint64_t PT_RISCV = uint64_t(4) << PT_BIT;
64 enum class TYPE : uint64_t {
65 UNKNOWN = uint64_t(-1),
75 GNU_EH_FRAME = 0x6474e550,
77 GNU_STACK = 0x6474e551,
78 GNU_PROPERTY = 0x6474e553,
79 GNU_RELRO = 0x6474e552,
81 ARM_ARCHEXT = 0x70000000 | PT_ARM,
82 ARM_EXIDX = 0x70000001 | PT_ARM,
84 AARCH64_MEMTAG_MTE = 0x70000002 | PT_AARCH64,
86 MIPS_REGINFO = 0x70000000 | PT_MIPS,
87 MIPS_RTPROC = 0x70000001 | PT_MIPS,
88 MIPS_OPTIONS = 0x70000002 | PT_MIPS,
89 MIPS_ABIFLAGS = 0x70000003 | PT_MIPS,
91 RISCV_ATTRIBUTES = 0x70000003 | PT_RISCV,
103 return static_cast<uint64_t
>(type) & PT_MASK;
108 return from_raw(raw.data(), raw.size());
124 return type() == TYPE::LOAD;
128 return type() == TYPE::INTERP;
132 return type() == TYPE::PHDR;
142 return FLAGS(flags_);
152 return virtual_address_;
161 return physical_address_;
173 return virtual_size_;
186 return (flags_ &
static_cast<uint64_t
>(flag)) != 0;
193 bool has(
const std::string& section_name)
const;
206 flags_ =
static_cast<uint32_t
>(flags);
220 virtual_address_ = virtual_address;
224 physical_address_ = physical_address;
230 virtual_size_ = virtual_size;
234 alignment_ = alignment;
270 uint64_t handler_size()
const;
273 TYPE type_ = TYPE::PT_NULL;
274 ARCH arch_ = ARCH::NONE;
276 uint64_t file_offset_ = 0;
277 uint64_t virtual_address_ = 0;
278 uint64_t physical_address_ = 0;
280 uint64_t virtual_size_ = 0;
281 uint64_t alignment_ = 0;
282 uint64_t handler_size_ = 0;
284 DataHandler::Handler* datahandler_ =
nullptr;
285 std::vector<uint8_t> content_c_;
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 parses and transforms an ELF file into a ELF::Binary object.
Definition ELF/Parser.hpp:45
Class wich represents an ELF Section.
Definition ELF/Section.hpp:46
Class which represents the ELF segments.
Definition Segment.hpp:44
uint64_t physical_address() const
The physical address of the segment. This value is not really relevant on systems like Linux or Andro...
Definition Segment.hpp:160
void physical_address(uint64_t physical_address)
Definition Segment.hpp:223
std::vector< Section * > sections_t
Definition Segment.hpp:52
void add(FLAGS flag)
Append the given ELF_SEGMENT_FLAGS.
static result< Segment > from_raw(const std::vector< uint8_t > &raw)
Definition Segment.hpp:107
size_t get_content_size() const
T get_content_value(size_t offset) const
bool is_interpreter() const
Definition Segment.hpp:127
void flags(FLAGS flags)
Definition Segment.hpp:205
~Segment() override=default
bool is_phdr() const
Definition Segment.hpp:131
uint64_t physical_size() const
The file size of the data associated with this segment.
Definition Segment.hpp:165
void clear_flags()
Definition Segment.hpp:213
Segment & operator-=(FLAGS flag)
Definition Segment.hpp:259
bool has(const std::string §ion_name) const
Check if the current segment wraps the given section's name.
void flags(uint32_t flags)
Definition Segment.hpp:209
Segment & operator+=(FLAGS flag)
Definition Segment.hpp:254
void set_content_value(size_t offset, T value)
void file_offset(uint64_t file_offset)
Segment & operator=(Segment other)
void remove(FLAGS flag)
Remove the given ELF_SEGMENT_FLAGS.
Segment & operator=(Segment &&)=default
void type(TYPE type)
Definition Segment.hpp:201
uint64_t virtual_address() const
The virtual address of the segment.
Definition Segment.hpp:151
span< const uint8_t > content() const
The raw data associated with this segment.
bool has(FLAGS flag) const
Check if the current segment has the given flag.
Definition Segment.hpp:185
void swap(Segment &other)
FLAGS
Definition Segment.hpp:94
it_sections sections()
Iterator over the sections wrapped by this segment.
Definition Segment.hpp:244
void virtual_size(uint64_t virtual_size)
Definition Segment.hpp:229
TYPE type() const
The segment's type (LOAD, DYNAMIC, ...)
Definition Segment.hpp:136
void content(std::vector< uint8_t > content)
void physical_size(uint64_t physical_size)
bool has(const Section §ion) const
Check if the current segment wraps the given ELF::Section.
uint64_t file_offset() const
The file offset of the data associated with this segment.
Definition Segment.hpp:146
static TYPE type_from(uint64_t value, ARCH arch)
bool is_load() const
Definition Segment.hpp:123
it_const_sections sections() const
Definition Segment.hpp:248
TYPE
Definition Segment.hpp:64
Segment(const Segment &other)
uint64_t alignment() const
The offset alignment of the segment.
Definition Segment.hpp:177
static uint64_t to_value(TYPE type)
Definition Segment.hpp:102
FLAGS flags() const
The flag permissions associated with this segment.
Definition Segment.hpp:141
void virtual_address(uint64_t virtual_address)
Definition Segment.hpp:219
Segment(Segment &&)=default
static result< Segment > from_raw(const uint8_t *ptr, size_t size)
uint64_t virtual_size() const
The in-memory size of this segment. Usually, if the .bss segment is wrapped by this segment then,...
Definition Segment.hpp:172
void alignment(uint64_t alignment)
Definition Segment.hpp:233
void accept(Visitor &visitor) const override
friend std::ostream & operator<<(std::ostream &os, const Segment &segment)
Definition Visitor.hpp:224
Iterator which returns reference on container's values.
Definition iterators.hpp:48
#define ENABLE_BITMASK_OPERATORS(X)
Definition enums.hpp:24
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
tcb::span< ElementType, Extent > span
Definition span.hpp:22
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
#define LIEF_LOCAL
Definition visibility.h:42