16#ifndef LIEF_ELF_SEGMENT_H
17#define LIEF_ELF_SEGMENT_H
61 static constexpr uint64_t
PT_BIT = 33;
73 enum class TYPE : uint64_t {
74 UNKNOWN = uint64_t(-1),
84 GNU_EH_FRAME = 0x6474e550,
86 GNU_STACK = 0x6474e551,
87 GNU_PROPERTY = 0x6474e553,
88 GNU_RELRO = 0x6474e552,
89 PAX_FLAGS = 0x65041580,
108 HP_CORE_VERSION = (0x60000000 + 0x02) |
PT_HPUX,
109 HP_CORE_KERNEL = (0x60000000 + 0x03) |
PT_HPUX,
112 HP_CORE_LOADABLE = (0x60000000 + 0x06) |
PT_HPUX,
113 HP_CORE_STACK = (0x60000000 + 0x07) |
PT_HPUX,
121 HP_CORE_UTSNAME = (0x60000000 + 0x15) |
PT_HPUX,
139 return from_raw(raw.data(), raw.size());
173 return FLAGS(flags_);
183 return virtual_address_;
192 return physical_address_;
204 return virtual_size_;
217 return (flags_ &
static_cast<uint64_t
>(flag)) != 0;
224 bool has(
const std::string& section_name)
const;
237 flags_ =
static_cast<uint32_t
>(
flags);
273 std::fill(buffer.begin(), buffer.end(), c);
296 std::unique_ptr<SpanStream>
stream()
const;
324 uint64_t file_offset_ = 0;
325 uint64_t virtual_address_ = 0;
326 uint64_t physical_address_ = 0;
328 uint64_t virtual_size_ = 0;
329 uint64_t alignment_ = 0;
330 uint64_t handler_size_ = 0;
332 DataHandler::Handler* datahandler_ =
nullptr;
333 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:44
Class which represents an ELF Section.
Definition ELF/Section.hpp:48
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:191
void physical_address(uint64_t physical_address)
Definition Segment.hpp:254
std::vector< Section * > sections_t
Definition Segment.hpp:56
void add(FLAGS flag)
Append the given ELF_SEGMENT_FLAGS.
static constexpr uint64_t PT_ARM
Definition Segment.hpp:65
static result< Segment > from_raw(const std::vector< uint8_t > &raw)
Definition Segment.hpp:138
friend class Section
Definition Segment.hpp:51
void fill(char c)
Fill the content of this segment with the value provided in parameter.
Definition Segment.hpp:271
size_t get_content_size() const
T get_content_value(size_t offset) const
static constexpr uint64_t PT_MASK
Definition Segment.hpp:63
static constexpr uint64_t PT_BIT
Definition Segment.hpp:61
bool is_interpreter() const
Definition Segment.hpp:158
void flags(FLAGS flags)
Definition Segment.hpp:236
void clear()
Clear the content of this segment.
Definition Segment.hpp:277
~Segment() override=default
bool is_phdr() const
Definition Segment.hpp:162
uint64_t physical_size() const
The file size of the data associated with this segment.
Definition Segment.hpp:196
void clear_flags()
Definition Segment.hpp:244
Segment & operator-=(FLAGS flag)
Definition Segment.hpp:305
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:240
Segment & operator+=(FLAGS flag)
Definition Segment.hpp:300
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:232
static constexpr uint64_t PT_MIPS
Definition Segment.hpp:67
uint64_t virtual_address() const
The virtual address of the segment.
Definition Segment.hpp:182
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:216
static constexpr uint64_t PT_AARCH64
Definition Segment.hpp:66
void swap(Segment &other)
friend class Builder
Definition Segment.hpp:53
FLAGS
Definition Segment.hpp:125
it_sections sections()
Iterator over the sections wrapped by this segment.
Definition Segment.hpp:288
void virtual_size(uint64_t virtual_size)
Definition Segment.hpp:260
static TYPE type_from(uint64_t value, ARCH arch, Header::OS_ABI os)
TYPE type() const
The segment's type (LOAD, DYNAMIC, ...).
Definition Segment.hpp:167
void content(std::vector< uint8_t > content)
friend class Binary
Definition Segment.hpp:52
void physical_size(uint64_t physical_size)
static constexpr uint64_t PT_RISCV
Definition Segment.hpp:68
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:177
bool is_load() const
Definition Segment.hpp:154
it_const_sections sections() const
Definition Segment.hpp:292
friend class Parser
Definition Segment.hpp:50
TYPE
Definition Segment.hpp:73
@ LOAD
Definition Segment.hpp:76
@ PHDR
Definition Segment.hpp:81
@ PT_NULL_
Definition Segment.hpp:75
@ INTERP
Definition Segment.hpp:78
Segment(const Segment &other)
static constexpr uint64_t PT_IA_64
Definition Segment.hpp:69
uint64_t alignment() const
The offset alignment of the segment.
Definition Segment.hpp:208
static constexpr uint64_t PT_HPUX
Definition Segment.hpp:71
static uint64_t to_value(TYPE type)
Definition Segment.hpp:133
ref_iterator< sections_t & > it_sections
Definition Segment.hpp:57
FLAGS flags() const
The flag permissions associated with this segment.
Definition Segment.hpp:172
void virtual_address(uint64_t virtual_address)
Definition Segment.hpp:250
std::unique_ptr< SpanStream > stream() const
Segment(Segment &&)=default
static constexpr uint64_t PT_OS_BIT
Definition Segment.hpp:62
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:203
void alignment(uint64_t alignment)
Definition Segment.hpp:264
void accept(Visitor &visitor) const override
const_ref_iterator< const sections_t & > it_const_sections
Definition Segment.hpp:58
friend std::ostream & operator<<(std::ostream &os, const Segment &segment)
Definition SpanStream.hpp:32
Definition Visitor.hpp:212
Iterator which returns reference on container's values.
Definition iterators.hpp:47
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:77
#define LIEF_LIFETIMEBOUND
Definition compiler_attributes.hpp:72
#define ENABLE_BITMASK_OPERATORS(X)
Definition enums.hpp:24
Definition ELF/Binary.hpp:38
Namespace related to the LIEF's ELF module.
Definition Abstract/Header.hpp:28
const char * to_string(DynamicEntry::TAG e)
ARCH
Definition ELF/enums.hpp:30
@ NONE
Definition ELF/enums.hpp:31
LIEF namespace.
Definition Abstract/Binary.hpp:40
tcb::span< ElementType, Extent > span
Definition span.hpp:22
ref_iterator< CT, U, typename decay_t< CT >::const_iterator > const_ref_iterator
Iterator which returns a const ref on container's values.
Definition iterators.hpp:320
#define LIEF_API
Definition visibility.h:45
#define LIEF_LOCAL
Definition visibility.h:46