LIEF: Library to Instrument Executable Formats Version 0.15.1
Loading...
Searching...
No Matches
LIEF::ELF::Segment Class Reference

Class which represents the ELF segments. More...

#include <Segment.hpp>

Inheritance diagram for LIEF::ELF::Segment:
Collaboration diagram for LIEF::ELF::Segment:

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 , 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
}
 
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
 
Segmentoperator= (Segment other)
 
 Segment (const Segment &other)
 
Segmentoperator= (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 &section) const
 Check if the current segment wraps the given ELF::Section.
 
bool has (const std::string &section_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)
 
template<typename 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
 
void accept (Visitor &visitor) const override
 
Segmentoperator+= (FLAGS flag)
 
Segmentoperator-= (FLAGS flag)
 
- Public Member Functions inherited from LIEF::Object
 Object ()
 
 Object (const Object &other)
 
Objectoperator= (const Object &other)
 
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)
 
static uint64_t to_value (TYPE type)
 
static result< Segmentfrom_raw (const uint8_t *ptr, size_t size)
 
static result< Segmentfrom_raw (const std::vector< uint8_t > &raw)
 

Static Public Attributes

static constexpr uint64_t PT_BIT = 33
 
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
 

Detailed Description

Class which represents the ELF segments.

Member Typedef Documentation

◆ it_const_sections

◆ it_sections

◆ sections_t

using LIEF::ELF::Segment::sections_t = std::vector<Section*>

Member Enumeration Documentation

◆ FLAGS

enum class LIEF::ELF::Segment::FLAGS
strong
Enumerator
NONE 

◆ TYPE

enum class LIEF::ELF::Segment::TYPE : uint64_t
strong
Enumerator
UNKNOWN 
PT_NULL 

Unused segment.

LOAD 

Loadable segment.

DYNAMIC 

Dynamic linking information.

INTERP 

Interpreter pathname.

NOTE 

Auxiliary information.

SHLIB 

Reserved.

PHDR 

The program header table itself.

TLS 

The thread-local storage template.

GNU_EH_FRAME 
GNU_STACK 

Indicates stack executability.

GNU_PROPERTY 

GNU property

GNU_RELRO 

Read-only after relocation.

ARM_ARCHEXT 

Platform architecture compatibility info

ARM_EXIDX 
AARCH64_MEMTAG_MTE 
MIPS_REGINFO 

Register usage information.

MIPS_RTPROC 

Runtime procedure table.

MIPS_OPTIONS 

Options segment.

MIPS_ABIFLAGS 

Abiflags segment.

RISCV_ATTRIBUTES 

Constructor & Destructor Documentation

◆ Segment() [1/3]

LIEF::ELF::Segment::Segment ( )
default

◆ ~Segment()

LIEF::ELF::Segment::~Segment ( )
overridedefault

◆ Segment() [2/3]

LIEF::ELF::Segment::Segment ( const Segment & other)

◆ Segment() [3/3]

LIEF::ELF::Segment::Segment ( Segment && )
default

Member Function Documentation

◆ accept()

void LIEF::ELF::Segment::accept ( Visitor & visitor) const
overridevirtual

Implements LIEF::Object.

◆ add()

void LIEF::ELF::Segment::add ( FLAGS flag)

Append the given ELF_SEGMENT_FLAGS.

◆ alignment() [1/2]

uint64_t LIEF::ELF::Segment::alignment ( ) const
inline

The offset alignment of the segment.

◆ alignment() [2/2]

void LIEF::ELF::Segment::alignment ( uint64_t alignment)
inline

◆ clear_flags()

void LIEF::ELF::Segment::clear_flags ( )
inline

◆ content() [1/2]

span< const uint8_t > LIEF::ELF::Segment::content ( ) const

The raw data associated with this segment.

◆ content() [2/2]

void LIEF::ELF::Segment::content ( std::vector< uint8_t > content)

◆ file_offset() [1/2]

uint64_t LIEF::ELF::Segment::file_offset ( ) const
inline

The file offset of the data associated with this segment.

◆ file_offset() [2/2]

void LIEF::ELF::Segment::file_offset ( uint64_t file_offset)

◆ flags() [1/3]

FLAGS LIEF::ELF::Segment::flags ( ) const
inline

The flag permissions associated with this segment.

◆ flags() [2/3]

void LIEF::ELF::Segment::flags ( FLAGS flags)
inline

◆ flags() [3/3]

void LIEF::ELF::Segment::flags ( uint32_t flags)
inline

◆ from_raw() [1/2]

static result< Segment > LIEF::ELF::Segment::from_raw ( const std::vector< uint8_t > & raw)
inlinestatic

◆ from_raw() [2/2]

static result< Segment > LIEF::ELF::Segment::from_raw ( const uint8_t * ptr,
size_t size )
static

◆ get_content_size()

size_t LIEF::ELF::Segment::get_content_size ( ) const

◆ get_content_value()

template<typename T >
T LIEF::ELF::Segment::get_content_value ( size_t offset) const

◆ has() [1/3]

bool LIEF::ELF::Segment::has ( const Section & section) const

Check if the current segment wraps the given ELF::Section.

◆ has() [2/3]

bool LIEF::ELF::Segment::has ( const std::string & section_name) const

Check if the current segment wraps the given section's name.

◆ has() [3/3]

bool LIEF::ELF::Segment::has ( FLAGS flag) const
inline

Check if the current segment has the given flag.

◆ is_interpreter()

bool LIEF::ELF::Segment::is_interpreter ( ) const
inline

◆ is_load()

bool LIEF::ELF::Segment::is_load ( ) const
inline

◆ is_phdr()

bool LIEF::ELF::Segment::is_phdr ( ) const
inline

◆ operator+=()

Segment & LIEF::ELF::Segment::operator+= ( FLAGS flag)
inline

◆ operator-=()

Segment & LIEF::ELF::Segment::operator-= ( FLAGS flag)
inline

◆ operator=() [1/2]

Segment & LIEF::ELF::Segment::operator= ( Segment && )
default

◆ operator=() [2/2]

Segment & LIEF::ELF::Segment::operator= ( Segment other)

◆ physical_address() [1/2]

uint64_t LIEF::ELF::Segment::physical_address ( ) const
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

◆ physical_address() [2/2]

void LIEF::ELF::Segment::physical_address ( uint64_t physical_address)
inline

◆ physical_size() [1/2]

uint64_t LIEF::ELF::Segment::physical_size ( ) const
inline

The file size of the data associated with this segment.

◆ physical_size() [2/2]

void LIEF::ELF::Segment::physical_size ( uint64_t physical_size)

◆ remove()

void LIEF::ELF::Segment::remove ( FLAGS flag)

Remove the given ELF_SEGMENT_FLAGS.

◆ sections() [1/2]

it_sections LIEF::ELF::Segment::sections ( )
inline

Iterator over the sections wrapped by this segment.

◆ sections() [2/2]

it_const_sections LIEF::ELF::Segment::sections ( ) const
inline

◆ set_content_value()

template<typename T >
void LIEF::ELF::Segment::set_content_value ( size_t offset,
T value )

◆ swap()

void LIEF::ELF::Segment::swap ( Segment & other)

◆ to_value()

static uint64_t LIEF::ELF::Segment::to_value ( TYPE type)
inlinestatic

◆ type() [1/2]

TYPE LIEF::ELF::Segment::type ( ) const
inline

The segment's type (LOAD, DYNAMIC, ...)

◆ type() [2/2]

void LIEF::ELF::Segment::type ( TYPE type)
inline

◆ type_from()

static TYPE LIEF::ELF::Segment::type_from ( uint64_t value,
ARCH arch )
static

◆ virtual_address() [1/2]

uint64_t LIEF::ELF::Segment::virtual_address ( ) const
inline

The virtual address of the segment.

◆ virtual_address() [2/2]

void LIEF::ELF::Segment::virtual_address ( uint64_t virtual_address)
inline

◆ virtual_size() [1/2]

uint64_t LIEF::ELF::Segment::virtual_size ( ) const
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.

◆ virtual_size() [2/2]

void LIEF::ELF::Segment::virtual_size ( uint64_t virtual_size)
inline

Member Data Documentation

◆ PT_AARCH64

uint64_t LIEF::ELF::Segment::PT_AARCH64 = uint64_t(2) << PT_BIT
staticconstexpr

◆ PT_ARM

uint64_t LIEF::ELF::Segment::PT_ARM = uint64_t(1) << PT_BIT
staticconstexpr

◆ PT_BIT

uint64_t LIEF::ELF::Segment::PT_BIT = 33
staticconstexpr

◆ PT_MASK

uint64_t LIEF::ELF::Segment::PT_MASK = (uint64_t(1) << PT_BIT) - 1
staticconstexpr

◆ PT_MIPS

uint64_t LIEF::ELF::Segment::PT_MIPS = uint64_t(3) << PT_BIT
staticconstexpr

◆ PT_RISCV

uint64_t LIEF::ELF::Segment::PT_RISCV = uint64_t(4) << PT_BIT
staticconstexpr

The documentation for this class was generated from the following file: