LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
LIEF::ELF::Section Class Reference

Class wich represents an ELF Section. More...

#include <Section.hpp>

Inheritance diagram for LIEF::ELF::Section:
Inheritance graph
[legend]
Collaboration diagram for LIEF::ELF::Section:
Collaboration graph
[legend]

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 = 0x010000000 + (_MIPS_ID_ << _ID_SHIFT_) , MIPS_NAMES = 0x020000000 + (_MIPS_ID_ << _ID_SHIFT_) , MIPS_LOCAL = 0x040000000 + (_MIPS_ID_ << _ID_SHIFT_) , MIPS_NOSTRIP = 0x080000000 + (_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)
 
Sectionoperator= (Section other)
 
 Section (const Section &other)
 
void swap (Section &other)
 
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. This 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 (std::string name)
 
Sectionoperator= (const Section &)
 
 Section (const Section &)
 
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 (const 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 (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
 

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 Enumeration Documentation

◆ FLAGS

enum class LIEF::ELF::Section::FLAGS : uint64_t
strong
Enumerator
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.

◆ 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.

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.

ARM_EXIDX 

Exception Index table

ARM_PREEMPTMAP 

BPABI DLL dynamic linking pre-emption map

ARM_ATTRIBUTES 

Object file compatibility attributes

HEX_ORDERED 

Link editor is to sort the entries in

X86_64_UNWIND 

Unwind information

MIPS_REGINFO 

Register usage information

MIPS_OPTIONS 

General options

MIPS_ABIFLAGS 

ABI information.

Member Function Documentation

◆ accept()

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

Implements LIEF::Object.

◆ content() [1/2]

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

Section's content.

Reimplemented from LIEF::Section.

◆ content() [2/2]

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

Set section content.

Reimplemented from LIEF::Section.

◆ entry_size()

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 (sizeof(Elf64_Dyn)) in a ELF64, the entry_size is set to this value.

◆ file_offset()

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

◆ 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.

◆ 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

◆ 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.


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