16#ifndef LIEF_ELF_SEGMENT_H
17#define LIEF_ELF_SEGMENT_H
60 static constexpr uint64_t
PT_BIT = 33;
72 enum class TYPE : uint64_t {
137 return from_raw(raw.data(), raw.size());
171 return FLAGS(flags_);
181 return virtual_address_;
190 return physical_address_;
202 return virtual_size_;
215 return (flags_ &
static_cast<uint64_t
>(flag)) != 0;
222 bool has(
const std::string& section_name)
const;
235 flags_ =
static_cast<uint32_t
>(
flags);
271 std::fill(buffer.begin(), buffer.end(), c);
290 std::unique_ptr<SpanStream>
stream()
const;
317 uint64_t file_offset_ = 0;
318 uint64_t virtual_address_ = 0;
319 uint64_t physical_address_ = 0;
321 uint64_t virtual_size_ = 0;
322 uint64_t alignment_ = 0;
323 uint64_t handler_size_ = 0;
325 DataHandler::Handler* datahandler_ =
nullptr;
326 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 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:189
void physical_address(uint64_t physical_address)
Definition Segment.hpp:252
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:64
static result< Segment > from_raw(const std::vector< uint8_t > &raw)
Definition Segment.hpp:136
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:269
size_t get_content_size() const
T get_content_value(size_t offset) const
static constexpr uint64_t PT_MASK
Definition Segment.hpp:62
static constexpr uint64_t PT_BIT
Definition Segment.hpp:60
bool is_interpreter() const
Definition Segment.hpp:156
void flags(FLAGS flags)
Definition Segment.hpp:234
void clear()
Clear the content of this segment.
Definition Segment.hpp:275
~Segment() override=default
bool is_phdr() const
Definition Segment.hpp:160
uint64_t physical_size() const
The file size of the data associated with this segment.
Definition Segment.hpp:194
void clear_flags()
Definition Segment.hpp:242
Segment & operator-=(FLAGS flag)
Definition Segment.hpp:299
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:238
Segment & operator+=(FLAGS flag)
Definition Segment.hpp:294
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:230
static constexpr uint64_t PT_MIPS
Definition Segment.hpp:66
uint64_t virtual_address() const
The virtual address of the segment.
Definition Segment.hpp:180
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:214
static constexpr uint64_t PT_AARCH64
Definition Segment.hpp:65
void swap(Segment &other)
friend class Builder
Definition Segment.hpp:53
FLAGS
Definition Segment.hpp:123
@ X
Definition Segment.hpp:125
@ W
Definition Segment.hpp:126
@ NONE
Definition Segment.hpp:124
@ R
Definition Segment.hpp:127
it_sections sections()
Iterator over the sections wrapped by this segment.
Definition Segment.hpp:282
void virtual_size(uint64_t virtual_size)
Definition Segment.hpp:258
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:165
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:67
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:175
bool is_load() const
Definition Segment.hpp:152
it_const_sections sections() const
Definition Segment.hpp:286
friend class Parser
Definition Segment.hpp:50
TYPE
Definition Segment.hpp:72
@ TLS
Definition Segment.hpp:81
@ DYNAMIC
Definition Segment.hpp:76
@ NOTE
Definition Segment.hpp:78
@ GNU_STACK
Definition Segment.hpp:85
@ HP_CORE_PROC
Definition Segment.hpp:110
@ HP_CORE_NONE
Definition Segment.hpp:106
@ HP_CORE_COMM
Definition Segment.hpp:109
@ ARM_ARCHEXT
Definition Segment.hpp:90
@ HP_CORE_MMF
Definition Segment.hpp:114
@ SHLIB
Definition Segment.hpp:79
@ HP_STACK
Definition Segment.hpp:119
@ LOAD
Definition Segment.hpp:75
@ GNU_RELRO
Definition Segment.hpp:87
@ UNKNOWN
Definition Segment.hpp:73
@ PHDR
Definition Segment.hpp:80
@ ARM_EXIDX
Definition Segment.hpp:91
@ AARCH64_MEMTAG_MTE
Definition Segment.hpp:93
@ MIPS_OPTIONS
Definition Segment.hpp:97
@ HP_TLS
Definition Segment.hpp:105
@ HP_CORE_VERSION
Definition Segment.hpp:107
@ MIPS_REGINFO
Definition Segment.hpp:95
@ IA_64_UNWIND
Definition Segment.hpp:103
@ RISCV_ATTRIBUTES
Definition Segment.hpp:100
@ PAX_FLAGS
Definition Segment.hpp:88
@ HP_OPT_ANNOT
Definition Segment.hpp:117
@ IA_64_EXT
Definition Segment.hpp:102
@ GNU_EH_FRAME
Definition Segment.hpp:83
@ PT_NULL_
Definition Segment.hpp:74
@ MIPS_ABIFLAGS
Definition Segment.hpp:98
@ HP_HSL_ANNOT
Definition Segment.hpp:118
@ HP_CORE_LOADABLE
Definition Segment.hpp:111
@ HP_PARALLEL
Definition Segment.hpp:115
@ MIPS_RTPROC
Definition Segment.hpp:96
@ HP_FASTBIND
Definition Segment.hpp:116
@ GNU_PROPERTY
Definition Segment.hpp:86
@ HP_CORE_STACK
Definition Segment.hpp:112
@ HP_CORE_UTSNAME
Definition Segment.hpp:120
@ INTERP
Definition Segment.hpp:77
@ HP_CORE_KERNEL
Definition Segment.hpp:108
@ HP_CORE_SHM
Definition Segment.hpp:113
Segment(const Segment &other)
static constexpr uint64_t PT_IA_64
Definition Segment.hpp:68
uint64_t alignment() const
The offset alignment of the segment.
Definition Segment.hpp:206
static constexpr uint64_t PT_HPUX
Definition Segment.hpp:70
static uint64_t to_value(TYPE type)
Definition Segment.hpp:131
ref_iterator< sections_t & > it_sections
Definition Segment.hpp:57
FLAGS flags() const
The flag permissions associated with this segment.
Definition Segment.hpp:170
void virtual_address(uint64_t virtual_address)
Definition Segment.hpp:248
std::unique_ptr< SpanStream > stream() const
Segment(Segment &&)=default
static constexpr uint64_t PT_OS_BIT
Definition Segment.hpp:61
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:201
void alignment(uint64_t alignment)
Definition Segment.hpp:262
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:210
Iterator which returns reference on container's values.
Definition iterators.hpp:46
#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 return const ref on container's values.
Definition iterators.hpp:257
tl::expected< T, lief_errors > result
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:75
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42