LIEF: Library to Instrument Executable Formats Version 0.17.0
|
Class wich represents an ELF Section. More...
#include <Section.hpp>
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 , _RISCV_ID_ = 4LLU , 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_) , RISCV_ATTRIBUTES = 0x70000003 + (_RISCV_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 | |
Section & | operator= (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< FLAGS > | flags_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. | |
Section & | clear (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 |
Section & | as_frame () |
bool | is_frame () const |
void | accept (Visitor &visitor) const override |
Section & | operator+= (FLAGS c) |
Section & | operator-= (FLAGS c) |
std::unique_ptr< SpanStream > | stream () const |
Return a stream over the content of this section. | |
Public Member Functions inherited from LIEF::Section | |
Section ()=default | |
Section (std::string name) | |
~Section () override=default | |
Section & | operator= (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) | |
Object & | operator= (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 |
using LIEF::ELF::Section::it_const_segments = const_ref_iterator<const segments_t&> |
using LIEF::ELF::Section::segments_t = std::vector<Segment*> |
|
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 |
|
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_ | |
_RISCV_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. |
RISCV_ATTRIBUTES |
|
inline |
|
default |
|
overridedefault |
LIEF::ELF::Section::Section | ( | const Section & | other | ) |
|
overridevirtual |
Implements LIEF::Object.
void LIEF::ELF::Section::add | ( | FLAGS | flag | ) |
Add the given ELF_SECTION_FLAGS.
|
inline |
Section file alignment.
|
inline |
|
inline |
Section & LIEF::ELF::Section::clear | ( | uint8_t | value = 0 | ) |
Clear the content of the section with the given value
|
inline |
|
overridevirtual |
Section's content.
Reimplemented from LIEF::Section.
|
overridevirtual |
Set section content.
Reimplemented from LIEF::Section.
void LIEF::ELF::Section::content | ( | std::vector< uint8_t > && | data | ) |
|
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.
|
inline |
|
inline |
|
inline |
|
inline |
Section flags.
|
inline |
std::vector< FLAGS > LIEF::ELF::Section::flags_list | ( | ) | const |
Return section flags as a std::set
bool LIEF::ELF::Section::has | ( | const Segment & | segment | ) | const |
True
if the section is wrapped by the given Segment
bool LIEF::ELF::Section::has | ( | FLAGS | flag | ) | const |
True
if the section has the given flag
|
inline |
Section information. The meaning of this value depends on the section's type.
|
inline |
|
inline |
|
inline |
Index to another section.
|
inline |
|
inlineoverridevirtual |
Offset in the binary.
Reimplemented from LIEF::Section.
|
overridevirtual |
Reimplemented from LIEF::Section.
|
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
void LIEF::ELF::Section::remove | ( | FLAGS | flag | ) |
Remove the given ELF_SECTION_FLAGS.
|
inline |
|
inline |
|
inlineoverridevirtual |
section's size (size in the binary, not the virtual size)
Reimplemented from LIEF::Section.
|
overridevirtual |
Change the section size.
Reimplemented from LIEF::Section.
std::unique_ptr< SpanStream > LIEF::ELF::Section::stream | ( | ) | const |
Return a stream over the content of this section.
|
noexcept |
|
inlinestatic |
|
inline |
|
inline |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |