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

Class wich represents an ELF Section. More...

#include <Section.hpp>

Inheritance diagram for LIEF::ELF::Section:
Collaboration diagram for LIEF::ELF::Section:

Public Types

enum class  TYPE : uint64_t {
  SHT_NULL = 0 , PROGBITS = 1 , SYMTAB = 2 , STRTAB = 3 ,
  RELA = 4 , HASH = 5 , DYNAMIC = 6 , NOTE = 7 ,
  NOBITS = 8 , REL = 9 , SHLIB = 10 , DYNSYM = 11 ,
  INIT_ARRAY = 14 , FINI_ARRAY = 15 , PREINIT_ARRAY = 16 , GROUP = 17 ,
  SYMTAB_SHNDX = 18 , RELR = 19 , ANDROID_REL = 0x60000001 , ANDROID_RELA = 0x60000002 ,
  LLVM_ADDRSIG = 0x6fff4c03 , ANDROID_RELR = 0x6fffff00 , GNU_ATTRIBUTES = 0x6ffffff5 , GNU_HASH = 0x6ffffff6 ,
  GNU_VERDEF = 0x6ffffffd , GNU_VERNEED = 0x6ffffffe , GNU_VERSYM = 0x6fffffff , _ID_SHIFT_ = 32 ,
  _ARM_ID_ = 1LLU , _HEX_ID_ = 2LLU , _X86_64_ID_ = 2LLU , _MIPS_ID_ = 3LLU ,
  ARM_EXIDX = 0x70000001U + (_ARM_ID_ << _ID_SHIFT_) , ARM_PREEMPTMAP = 0x70000002U + (_ARM_ID_ << _ID_SHIFT_) , ARM_ATTRIBUTES = 0x70000003U + (_ARM_ID_ << _ID_SHIFT_) , ARM_DEBUGOVERLAY = 0x70000004U + (_ARM_ID_ << _ID_SHIFT_) ,
  ARM_OVERLAYSECTION = 0x70000005U + (_ARM_ID_ << _ID_SHIFT_) , HEX_ORDERED = 0x70000000 + (_HEX_ID_ << _ID_SHIFT_) , X86_64_UNWIND = 0x70000001 + (_X86_64_ID_ << _ID_SHIFT_) , MIPS_REGINFO = 0x70000006 + (_MIPS_ID_ << _ID_SHIFT_) ,
  MIPS_OPTIONS = 0x7000000d + (_MIPS_ID_ << _ID_SHIFT_) , MIPS_ABIFLAGS = 0x7000002a + (_MIPS_ID_ << _ID_SHIFT_)
}
 
enum class  FLAGS : uint64_t {
  NONE = 0x000000000 , WRITE = 0x000000001 , ALLOC = 0x000000002 , EXECINSTR = 0x000000004 ,
  MERGE = 0x000000010 , STRINGS = 0x000000020 , INFO_LINK = 0x000000040 , LINK_ORDER = 0x000000080 ,
  OS_NONCONFORMING = 0x000000100 , GROUP = 0x000000200 , TLS = 0x000000400 , COMPRESSED = 0x000000800 ,
  GNU_RETAIN = 0x000200000 , EXCLUDE = 0x080000000 , _ID_SHIFT_ = 32 , _XCORE_ID_ = 1LLU ,
  _HEX_ID_ = 3LLU , _X86_64_ID_ = 2LLU , _MIPS_ID_ = 4LLU , _ARM_ID_ = 5LLU ,
  XCORE_SHF_DP_SECTION = 0x010000000 + (_XCORE_ID_ << _ID_SHIFT_) , XCORE_SHF_CP_SECTION = 0x020000000 + (_XCORE_ID_ << _ID_SHIFT_) , X86_64_LARGE = 0x010000000 + (_X86_64_ID_ << _ID_SHIFT_) , HEX_GPREL = 0x010000000 + (_HEX_ID_ << _ID_SHIFT_) ,
  MIPS_NODUPES = 0x001000000 + (_MIPS_ID_ << _ID_SHIFT_) , MIPS_NAMES = 0x002000000 + (_MIPS_ID_ << _ID_SHIFT_) , MIPS_LOCAL = 0x004000000 + (_MIPS_ID_ << _ID_SHIFT_) , MIPS_NOSTRIP = 0x008000000 + (_MIPS_ID_ << _ID_SHIFT_) ,
  MIPS_GPREL = 0x010000000 + (_MIPS_ID_ << _ID_SHIFT_) , MIPS_MERGE = 0x020000000 + (_MIPS_ID_ << _ID_SHIFT_) , MIPS_ADDR = 0x040000000 + (_MIPS_ID_ << _ID_SHIFT_) , MIPS_STRING = 0x080000000 + (_MIPS_ID_ << _ID_SHIFT_) ,
  ARM_PURECODE = 0x020000000 + (_ARM_ID_ << _ID_SHIFT_)
}
 
using segments_t = std::vector<Segment*>
 
using it_segments = ref_iterator<segments_t&>
 
using it_const_segments = const_ref_iterator<const segments_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

 Section (const std::string &name, TYPE type=TYPE::PROGBITS)
 
 Section ()=default
 
 ~Section () override=default
 
Sectionoperator= (Section other)
 
 Section (const Section &other)
 
void swap (Section &other) noexcept
 
TYPE type () const
 
span< const uint8_t > content () const override
 Section's content.
 
void content (const std::vector< uint8_t > &data) override
 Set section content.
 
void content (std::vector< uint8_t > &&data)
 
uint64_t flags () const
 Section flags.
 
bool has (FLAGS flag) const
 True if the section has the given flag
 
bool has (const Segment &segment) const
 True if the section is wrapped by the given Segment
 
std::vector< FLAGSflags_list () const
 Return section flags as a std::set
 
uint64_t size () const override
 section's size (size in the binary, not the virtual size)
 
void size (uint64_t size) override
 Change the section size.
 
void offset (uint64_t offset) override
 
uint64_t offset () const override
 Offset in the binary.
 
uint64_t file_offset () const
 
uint64_t original_size () const
 Original size of the section's data.
 
uint64_t alignment () const
 Section file alignment.
 
uint64_t information () const
 Section information. The meaning of this value depends on the section's type.
 
uint64_t entry_size () const
 This function returns the size of an element in the case of a section that contains an array.
 
uint32_t link () const
 Index to another section.
 
Sectionclear (uint8_t value=0)
 Clear the content of the section with the given value
 
void add (FLAGS flag)
 Add the given ELF_SECTION_FLAGS.
 
void remove (FLAGS flag)
 Remove the given ELF_SECTION_FLAGS.
 
void type (TYPE type)
 
void flags (uint64_t flags)
 
void clear_flags ()
 
void file_offset (uint64_t offset)
 
void link (uint32_t link)
 
void information (uint32_t info)
 
void alignment (uint64_t alignment)
 
void entry_size (uint64_t entry_size)
 
it_segments segments ()
 
it_const_segments segments () const
 
Sectionas_frame ()
 
bool is_frame () const
 
void accept (Visitor &visitor) const override
 
Sectionoperator+= (FLAGS c)
 
Sectionoperator-= (FLAGS c)
 
- Public Member Functions inherited from LIEF::Section
 Section ()=default
 
 Section (std::string name)
 
 ~Section () override=default
 
Sectionoperator= (const Section &)=default
 
 Section (const Section &)=default
 
virtual std::string name () const
 section's name
 
virtual const std::string & fullname () const
 Return the complete section's name which might trailing (0) bytes.
 
virtual uint64_t virtual_address () const
 Address where the section should be mapped.
 
virtual void virtual_address (uint64_t virtual_address)
 
virtual void name (std::string name)
 Change the section's name.
 
double entropy () const
 Section's entropy.
 
size_t search (uint64_t integer, size_t pos, size_t size) const
 
size_t search (const std::vector< uint8_t > &pattern, size_t pos=0) const
 
size_t search (const std::string &pattern, size_t pos=0) const
 
size_t search (uint64_t integer, size_t pos=0) const
 
std::vector< size_t > search_all (uint64_t v, size_t size) const
 
std::vector< size_t > search_all (uint64_t v) const
 
std::vector< size_t > search_all (const std::string &v) const
 
void accept (Visitor &visitor) const override
 Method so that the visitor can visit us.
 
- 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 (uint32_t value, ARCH arch)
 
static uint32_t to_value (TYPE type)
 

Static Public Attributes

static constexpr uint32_t MAX_SECTION_SIZE = 2_GB
 
static constexpr uint64_t FLAG_MASK = (uint64_t(1) << uint8_t(FLAGS::_ID_SHIFT_)) - 1
 
static constexpr uint64_t TYPE_MASK = (uint64_t(1) << uint8_t(TYPE::_ID_SHIFT_)) - 1
 
- Static Public Attributes inherited from LIEF::Section
static constexpr size_t npos = -1
 

Detailed Description

Class wich represents an ELF Section.

Member Typedef Documentation

◆ it_const_segments

◆ it_segments

◆ segments_t

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

Member Enumeration Documentation

◆ FLAGS

enum class LIEF::ELF::Section::FLAGS : uint64_t
strong
Enumerator
NONE 
WRITE 

Section data should be writable during execution.

ALLOC 

Section occupies memory during program execution.

EXECINSTR 

Section contains executable machine instructions.

MERGE 

The data in this section may be merged.

STRINGS 

The data in this section is null-terminated strings.

INFO_LINK 

A field in this section holds a section header table index.

LINK_ORDER 

Adds special ordering requirements for link editors.

OS_NONCONFORMING 

This section requires special OS-specific processing to avoid incorrect behavior

GROUP 

This section is a member of a section group.

TLS 

This section holds Thread-Local Storage.

COMPRESSED 
GNU_RETAIN 
EXCLUDE 
_ID_SHIFT_ 
_XCORE_ID_ 
_HEX_ID_ 
_X86_64_ID_ 
_MIPS_ID_ 
_ARM_ID_ 
XCORE_SHF_DP_SECTION 
XCORE_SHF_CP_SECTION 
X86_64_LARGE 
HEX_GPREL 
MIPS_NODUPES 
MIPS_NAMES 
MIPS_LOCAL 
MIPS_NOSTRIP 
MIPS_GPREL 
MIPS_MERGE 
MIPS_ADDR 
MIPS_STRING 
ARM_PURECODE 

◆ TYPE

enum class LIEF::ELF::Section::TYPE : uint64_t
strong
Enumerator
SHT_NULL 

No associated section (inactive entry).

PROGBITS 

Program-defined contents.

SYMTAB 

Symbol table.

STRTAB 

String table.

RELA 

Relocation entries; explicit addends.

HASH 

Symbol hash table.

DYNAMIC 

Information for dynamic linking.

NOTE 

Information about the file.

NOBITS 

Data occupies no space in the file.

REL 

Relocation entries; no explicit addends.

SHLIB 

Reserved.

DYNSYM 

Symbol table.

INIT_ARRAY 

Pointers to initialization functions.

FINI_ARRAY 

Pointers to termination functions.

PREINIT_ARRAY 

Pointers to pre-init functions.

GROUP 

Section group.

SYMTAB_SHNDX 

Indices for SHN_XINDEX entries.

RELR 

Relocation entries; only offsets.

ANDROID_REL 

Packed relocations (Android specific).

ANDROID_RELA 

Packed relocations (Android specific).

LLVM_ADDRSIG 

This section is used to mark symbols as address-significant.

ANDROID_RELR 

New relr relocations (Android specific).

GNU_ATTRIBUTES 

Object attributes.

GNU_HASH 

GNU-style hash table.

GNU_VERDEF 

GNU version definitions.

GNU_VERNEED 

GNU version references.

GNU_VERSYM 

GNU symbol versions table.

_ID_SHIFT_ 
_ARM_ID_ 
_HEX_ID_ 
_X86_64_ID_ 
_MIPS_ID_ 
ARM_EXIDX 

Exception Index table

ARM_PREEMPTMAP 

BPABI DLL dynamic linking pre-emption map

ARM_ATTRIBUTES 

Object file compatibility attributes

ARM_DEBUGOVERLAY 
ARM_OVERLAYSECTION 
HEX_ORDERED 

Link editor is to sort the entries in this section based on their sizes

X86_64_UNWIND 

Unwind information

MIPS_REGINFO 

Register usage information

MIPS_OPTIONS 

General options

MIPS_ABIFLAGS 

ABI information.

Constructor & Destructor Documentation

◆ Section() [1/3]

LIEF::ELF::Section::Section ( const std::string & name,
TYPE type = TYPE::PROGBITS )
inline

◆ Section() [2/3]

LIEF::ELF::Section::Section ( )
default

◆ ~Section()

LIEF::ELF::Section::~Section ( )
overridedefault

◆ Section() [3/3]

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

Member Function Documentation

◆ accept()

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

Implements LIEF::Object.

◆ add()

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

Add the given ELF_SECTION_FLAGS.

◆ alignment() [1/2]

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

Section file alignment.

◆ alignment() [2/2]

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

◆ as_frame()

Section & LIEF::ELF::Section::as_frame ( )
inline

◆ clear()

Section & LIEF::ELF::Section::clear ( uint8_t value = 0)

Clear the content of the section with the given value

◆ clear_flags()

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

◆ content() [1/3]

span< const uint8_t > LIEF::ELF::Section::content ( ) const
overridevirtual

Section's content.

Reimplemented from LIEF::Section.

◆ content() [2/3]

void LIEF::ELF::Section::content ( const std::vector< uint8_t > & data)
overridevirtual

Set section content.

Reimplemented from LIEF::Section.

◆ content() [3/3]

void LIEF::ELF::Section::content ( std::vector< uint8_t > && data)

◆ entry_size() [1/2]

uint64_t LIEF::ELF::Section::entry_size ( ) const
inline

This function returns the size of an element in the case of a section that contains an array.

For instance, the .dynamic section contains an array of DynamicEntry. As the size of the raw C structure of this entry is 0x10 (sizeoe(Elf64_Dyn)) in a ELF64, the entry_size is set to this value.

◆ entry_size() [2/2]

void LIEF::ELF::Section::entry_size ( uint64_t entry_size)
inline

◆ file_offset() [1/2]

uint64_t LIEF::ELF::Section::file_offset ( ) const
inline
See also
offset

◆ file_offset() [2/2]

void LIEF::ELF::Section::file_offset ( uint64_t offset)
inline

◆ flags() [1/2]

uint64_t LIEF::ELF::Section::flags ( ) const
inline

Section flags.

◆ flags() [2/2]

void LIEF::ELF::Section::flags ( uint64_t flags)
inline

◆ flags_list()

std::vector< FLAGS > LIEF::ELF::Section::flags_list ( ) const

Return section flags as a std::set

◆ has() [1/2]

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

True if the section is wrapped by the given Segment

◆ has() [2/2]

bool LIEF::ELF::Section::has ( FLAGS flag) const

True if the section has the given flag

◆ information() [1/2]

uint64_t LIEF::ELF::Section::information ( ) const
inline

Section information. The meaning of this value depends on the section's type.

◆ information() [2/2]

void LIEF::ELF::Section::information ( uint32_t info)
inline

◆ is_frame()

bool LIEF::ELF::Section::is_frame ( ) const
inline

◆ link() [1/2]

uint32_t LIEF::ELF::Section::link ( ) const
inline

Index to another section.

◆ link() [2/2]

void LIEF::ELF::Section::link ( uint32_t link)
inline

◆ offset() [1/2]

uint64_t LIEF::ELF::Section::offset ( ) const
inlineoverridevirtual

Offset in the binary.

Reimplemented from LIEF::Section.

◆ offset() [2/2]

void LIEF::ELF::Section::offset ( uint64_t offset)
overridevirtual

Reimplemented from LIEF::Section.

◆ operator+=()

Section & LIEF::ELF::Section::operator+= ( FLAGS c)
inline

◆ operator-=()

Section & LIEF::ELF::Section::operator-= ( FLAGS c)
inline

◆ operator=()

Section & LIEF::ELF::Section::operator= ( Section other)
inline

◆ original_size()

uint64_t LIEF::ELF::Section::original_size ( ) const
inline

Original size of the section's data.

This value is used by the ELF::Builder to determines if it needs to be relocated to avoid an override of the data

◆ remove()

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

Remove the given ELF_SECTION_FLAGS.

◆ segments() [1/2]

it_segments LIEF::ELF::Section::segments ( )
inline

◆ segments() [2/2]

it_const_segments LIEF::ELF::Section::segments ( ) const
inline

◆ size() [1/2]

uint64_t LIEF::ELF::Section::size ( ) const
inlineoverridevirtual

section's size (size in the binary, not the virtual size)

Reimplemented from LIEF::Section.

◆ size() [2/2]

void LIEF::ELF::Section::size ( uint64_t size)
overridevirtual

Change the section size.

Reimplemented from LIEF::Section.

◆ swap()

void LIEF::ELF::Section::swap ( Section & other)
noexcept

◆ to_value()

static uint32_t LIEF::ELF::Section::to_value ( TYPE type)
inlinestatic

◆ type() [1/2]

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

◆ type() [2/2]

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

◆ type_from()

static TYPE LIEF::ELF::Section::type_from ( uint32_t value,
ARCH arch )
static

Member Data Documentation

◆ FLAG_MASK

uint64_t LIEF::ELF::Section::FLAG_MASK = (uint64_t(1) << uint8_t(FLAGS::_ID_SHIFT_)) - 1
staticconstexpr

◆ MAX_SECTION_SIZE

uint32_t LIEF::ELF::Section::MAX_SECTION_SIZE = 2_GB
staticconstexpr

◆ TYPE_MASK

uint64_t LIEF::ELF::Section::TYPE_MASK = (uint64_t(1) << uint8_t(TYPE::_ID_SHIFT_)) - 1
staticconstexpr

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