LIEF: Library to Instrument Executable Formats Version 0.17.0
|
Class which represents the ELF segments. More...
#include <Segment.hpp>
Public Types | |
enum class | TYPE : uint64_t { UNKNOWN = uint64_t(-1) , PT_NULL_ = 0 , LOAD = 1 , DYNAMIC = 2 , INTERP = 3 , NOTE = 4 , SHLIB = 5 , PHDR = 6 , TLS = 7 , GNU_EH_FRAME = 0x6474e550 , GNU_STACK = 0x6474e551 , GNU_PROPERTY = 0x6474e553 , GNU_RELRO = 0x6474e552 , PAX_FLAGS = 0x65041580 , ARM_ARCHEXT = 0x70000000 | PT_ARM , ARM_EXIDX = 0x70000001 | PT_ARM , AARCH64_MEMTAG_MTE = 0x70000002 | PT_AARCH64 , MIPS_REGINFO = 0x70000000 | PT_MIPS , MIPS_RTPROC = 0x70000001 | PT_MIPS , MIPS_OPTIONS = 0x70000002 | PT_MIPS , MIPS_ABIFLAGS = 0x70000003 | PT_MIPS , RISCV_ATTRIBUTES = 0x70000003 | PT_RISCV , IA_64_EXT = (0x70000000 + 0x0) | PT_IA_64 , IA_64_UNWIND = (0x70000000 + 0x1) | PT_IA_64 , HP_TLS = (0x60000000 + 0x0) | PT_HPUX , HP_CORE_NONE = (0x60000000 + 0x1) | PT_HPUX , HP_CORE_VERSION = (0x60000000 + 0x2) | PT_HPUX , HP_CORE_KERNEL = (0x60000000 + 0x3) | PT_HPUX , HP_CORE_COMM = (0x60000000 + 0x4) | PT_HPUX , HP_CORE_PROC = (0x60000000 + 0x5) | PT_HPUX , HP_CORE_LOADABLE = (0x60000000 + 0x6) | PT_HPUX , HP_CORE_STACK = (0x60000000 + 0x7) | PT_HPUX , HP_CORE_SHM = (0x60000000 + 0x8) | PT_HPUX , HP_CORE_MMF = (0x60000000 + 0x9) | PT_HPUX , HP_PARALLEL = (0x60000000 + 0x10) | PT_HPUX , HP_FASTBIND = (0x60000000 + 0x11) | PT_HPUX , HP_OPT_ANNOT = (0x60000000 + 0x12) | PT_HPUX , HP_HSL_ANNOT = (0x60000000 + 0x13) | PT_HPUX , HP_STACK = (0x60000000 + 0x14) | PT_HPUX , HP_CORE_UTSNAME = (0x60000000 + 0x15) | PT_HPUX } |
enum class | FLAGS { NONE = 0 , X = 1 , W = 2 , R = 4 } |
using | sections_t = std::vector<Section*> |
using | it_sections = ref_iterator<sections_t&> |
using | it_const_sections = const_ref_iterator<const sections_t&> |
Public Types inherited from LIEF::Object | |
template<class T> | |
using | output_t = add_pointer_t<decay_t<T>> |
template<class T> | |
using | output_const_t = add_pointer_t<add_const_t<decay_t<T>>> |
Public Member Functions | |
Segment ()=default | |
~Segment () override=default | |
Segment & | operator= (Segment other) |
Segment (const Segment &other) | |
Segment & | operator= (Segment &&)=default |
Segment (Segment &&)=default | |
void | swap (Segment &other) |
bool | is_load () const |
bool | is_interpreter () const |
bool | is_phdr () const |
TYPE | type () const |
The segment's type (LOAD, DYNAMIC, ...). | |
FLAGS | flags () const |
The flag permissions associated with this segment. | |
uint64_t | file_offset () const |
The file offset of the data associated with this segment. | |
uint64_t | virtual_address () const |
The virtual address of the segment. | |
uint64_t | physical_address () const |
The physical address of the segment. This value is not really relevant on systems like Linux or Android. On the other hand, Qualcomm trustlets might use this value. | |
uint64_t | physical_size () const |
The file size of the data associated with this segment. | |
uint64_t | virtual_size () const |
The in-memory size of this segment. Usually, if the .bss segment is wrapped by this segment then, virtual_size is larger than physical_size. | |
uint64_t | alignment () const |
The offset alignment of the segment. | |
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. | |
bool | has (const Section §ion) const |
Check if the current segment wraps the given ELF::Section. | |
bool | has (const std::string §ion_name) const |
Check if the current segment wraps the given section's name. | |
void | add (FLAGS flag) |
Append the given ELF_SEGMENT_FLAGS. | |
void | remove (FLAGS flag) |
Remove the given ELF_SEGMENT_FLAGS. | |
void | type (TYPE type) |
void | flags (FLAGS flags) |
void | flags (uint32_t flags) |
void | clear_flags () |
void | file_offset (uint64_t file_offset) |
void | virtual_address (uint64_t virtual_address) |
void | physical_address (uint64_t physical_address) |
void | physical_size (uint64_t physical_size) |
void | virtual_size (uint64_t virtual_size) |
void | alignment (uint64_t alignment) |
void | content (std::vector< uint8_t > content) |
void | fill (char c) |
Fill the content of this segment with the value provided in parameter. | |
void | clear () |
Clear the content of this segment. | |
template<typename T> | |
T | get_content_value (size_t offset) const |
template<typename T> | |
void | set_content_value (size_t offset, T value) |
size_t | get_content_size () const |
it_sections | sections () |
Iterator over the sections wrapped by this segment. | |
it_const_sections | sections () const |
std::unique_ptr< SpanStream > | stream () const |
void | accept (Visitor &visitor) const override |
Segment & | operator+= (FLAGS flag) |
Segment & | operator-= (FLAGS flag) |
Public Member Functions inherited from LIEF::Object | |
Object () | |
Object (const Object &other) | |
Object & | operator= (const Object &other) |
Object (Object &&other) noexcept=default | |
Object & | operator= (Object &&other) noexcept=default |
template<class T> | |
output_t< T > | as () |
template<class T> | |
output_const_t< T > | as () const |
virtual bool | operator== (const Object &other) const |
virtual bool | operator!= (const Object &other) const |
virtual | ~Object () |
Static Public Member Functions | |
static TYPE | type_from (uint64_t value, ARCH arch, Header::OS_ABI os) |
static uint64_t | to_value (TYPE type) |
static result< Segment > | from_raw (const uint8_t *ptr, size_t size) |
static result< Segment > | from_raw (const std::vector< uint8_t > &raw) |
Static Public Attributes | |
static constexpr uint64_t | PT_BIT = 33 |
static constexpr uint64_t | PT_OS_BIT = 53 |
static constexpr uint64_t | PT_MASK = (uint64_t(1) << PT_BIT) - 1 |
static constexpr uint64_t | PT_ARM = uint64_t(1) << PT_BIT |
static constexpr uint64_t | PT_AARCH64 = uint64_t(2) << PT_BIT |
static constexpr uint64_t | PT_MIPS = uint64_t(3) << PT_BIT |
static constexpr uint64_t | PT_RISCV = uint64_t(4) << PT_BIT |
static constexpr uint64_t | PT_IA_64 = uint64_t(5) << PT_BIT |
static constexpr uint64_t | PT_HPUX = uint64_t(1) << PT_OS_BIT |
Class which represents the ELF segments.
using LIEF::ELF::Segment::it_const_sections = const_ref_iterator<const sections_t&> |
using LIEF::ELF::Segment::sections_t = std::vector<Section*> |
|
strong |
|
strong |
|
default |
Referenced by operator+=(), operator-=(), operator<<, operator=(), operator=(), Segment(), Segment(), and swap().
|
overridedefault |
|
overridevirtual |
Implements LIEF::Object.
void LIEF::ELF::Segment::add | ( | FLAGS | flag | ) |
Append the given ELF_SEGMENT_FLAGS.
Referenced by operator+=().
|
inline |
The offset alignment of the segment.
Referenced by alignment().
|
inline |
References alignment().
|
inline |
Clear the content of this segment.
References fill().
|
inline |
span< const uint8_t > LIEF::ELF::Segment::content | ( | ) | const |
The raw data associated with this segment.
Referenced by content().
void LIEF::ELF::Segment::content | ( | std::vector< uint8_t > | content | ) |
References content().
|
inline |
The file offset of the data associated with this segment.
Referenced by file_offset().
void LIEF::ELF::Segment::file_offset | ( | uint64_t | file_offset | ) |
References file_offset().
|
inline |
Fill the content of this segment with the value provided in parameter.
Referenced by clear().
|
inline |
|
inline |
References flags().
References from_raw().
Referenced by from_raw().
size_t LIEF::ELF::Segment::get_content_size | ( | ) | const |
T LIEF::ELF::Segment::get_content_value | ( | size_t | offset | ) | const |
bool LIEF::ELF::Segment::has | ( | const Section & | section | ) | const |
Check if the current segment wraps the given ELF::Section.
References Section.
bool LIEF::ELF::Segment::has | ( | const std::string & | section_name | ) | const |
Check if the current segment wraps the given section's name.
|
inline |
Check if the current segment has the given flag.
|
inline |
The physical address of the segment. This value is not really relevant on systems like Linux or Android. On the other hand, Qualcomm trustlets might use this value.
Usually this value matches virtual_address
Referenced by physical_address().
|
inline |
References physical_address().
|
inline |
The file size of the data associated with this segment.
Referenced by physical_size().
void LIEF::ELF::Segment::physical_size | ( | uint64_t | physical_size | ) |
References physical_size().
void LIEF::ELF::Segment::remove | ( | FLAGS | flag | ) |
Remove the given ELF_SEGMENT_FLAGS.
Referenced by operator-=().
|
inline |
Iterator over the sections wrapped by this segment.
|
inline |
void LIEF::ELF::Segment::set_content_value | ( | size_t | offset, |
T | value ) |
std::unique_ptr< SpanStream > LIEF::ELF::Segment::stream | ( | ) | const |
|
inline |
The segment's type (LOAD, DYNAMIC, ...).
Referenced by is_interpreter(), is_load(), is_phdr(), to_value(), and type().
|
static |
|
inline |
The virtual address of the segment.
Referenced by virtual_address().
|
inline |
References virtual_address().
|
inline |
The in-memory size of this segment. Usually, if the .bss segment is wrapped by this segment then, virtual_size is larger than physical_size.
Referenced by virtual_size().
|
inline |
References virtual_size().
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
Referenced by to_value().
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |