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

Class which represents the ELF's header. This class mirrors the raw ELF Elfxx_Ehdr structure. More...

#include <Header.hpp>

Inheritance diagram for LIEF::ELF::Header:
Collaboration diagram for LIEF::ELF::Header:

Public Types

enum  ELF_INDENT {
  ELI_MAG0 = 0 , ELI_MAG1 = 1 , ELI_MAG2 = 2 , ELI_MAG3 = 3 ,
  ELI_CLASS = 4 , ELI_DATA = 5 , ELI_VERSION = 6 , ELI_OSABI = 7 ,
  ELI_ABIVERSION = 8 , ELI_PAD = 9 , ELI_NIDENT = 16
}
 e_ident size and indices. More...
 
enum class  FILE_TYPE {
  NONE = 0 , REL = 1 , EXEC = 2 , DYN = 3 ,
  CORE = 4
}
 The type of the underlying ELF file. This enum matches the semantic of ET_NONE, ET_REL, ... More...
 
enum class  VERSION { NONE = 0 , CURRENT = 1 }
 Match the result of Elfxx_Ehdr.e_version More...
 
enum class  CLASS { NONE = 0 , ELF32 , ELF64 }
 Match the result of Elfxx_Ehdr.e_ident[EI_CLASS] More...
 
enum class  OS_ABI {
  SYSTEMV = 0 , HPUX = 1 , NETBSD = 2 , GNU = 3 ,
  LINUX = 3 , HURD = 4 , SOLARIS = 6 , AIX = 7 ,
  IRIX = 8 , FREEBSD = 9 , TRU64 = 10 , MODESTO = 11 ,
  OPENBSD = 12 , OPENVMS = 13 , NSK = 14 , AROS = 15 ,
  FENIXOS = 16 , CLOUDABI = 17 , C6000_ELFABI = 64 , AMDGPU_HSA = 64 ,
  C6000_LINUX = 65 , ARM = 97 , STANDALONE = 255
}
 Match the result Elfxx_Ehdr.e_ident[EI_OSABI] More...
 
enum class  ELF_DATA { NONE = 0 , LSB = 1 , MSB = 2 }
 Match the result Elfxx_Ehdr.e_ident[EI_DATA] More...
 
using identity_t = std::array<uint8_t, 16>
 
- 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

 Header ()=default
 
Headeroperator= (const Header &)=default
 
 Header (const Header &)=default
 
 ~Header () override=default
 
FILE_TYPE file_type () const
 Define the object file type. (e.g. executable, library...)
 
ARCH machine_type () const
 Target architecture.
 
VERSION object_file_version () const
 Version of the object file format.
 
uint64_t entrypoint () const
 Executable entrypoint.
 
uint64_t program_headers_offset () const
 Offset of the programs table (also known as segments table)
 
uint64_t section_headers_offset () const
 Offset of the sections table.
 
uint32_t processor_flag () const
 Processor-specific flags.
 
uint32_t header_size () const
 Size of the current header (i.e. sizeof(Elfxx_Ehdr)) This size should be 64 for an ELF64 binary and 52 for an ELF32.
 
uint32_t program_header_size () const
 Return the size of a program header (i.e. sizeof(Elfxx_Phdr)) This size should be 56 for an ELF64 binary and 32 for an ELF32.
 
uint32_t numberof_segments () const
 Return the number of segments.
 
uint32_t section_header_size () const
 Return the size of a section header (i.e. sizeof(Elfxx_Shdr)) This size should be 64 for a ELF64 binary and 40 for an ELF32.
 
uint32_t numberof_sections () const
 Return the number of sections.
 
uint32_t section_name_table_idx () const
 Return the section's index which contains sections' names.
 
identity_tidentity ()
 Return the ELF identity as an std::array
 
const identity_tidentity () const
 
CLASS identity_class () const
 Return the object's class. ELF64 or ELF32
 
ELF_DATA identity_data () const
 Specify the data encoding.
 
VERSION identity_version () const
 
OS_ABI identity_os_abi () const
 Identifies the version of the ABI for which the object is prepared.
 
uint32_t identity_abi_version () const
 ABI Version.
 
bool has (PROCESSOR_FLAGS flag) const
 
std::vector< PROCESSOR_FLAGSflags_list () const
 
void file_type (FILE_TYPE type)
 
void machine_type (ARCH arch)
 
void object_file_version (VERSION version)
 
void entrypoint (uint64_t entry)
 
void program_headers_offset (uint64_t offset)
 
void section_headers_offset (uint64_t offset)
 
void processor_flag (uint32_t flags)
 
void header_size (uint32_t size)
 
void program_header_size (uint32_t size)
 
void numberof_segments (uint32_t n)
 
void section_header_size (uint32_t size)
 
void numberof_sections (uint32_t n)
 
void section_name_table_idx (uint32_t idx)
 
void identity (const std::string &identity)
 
void identity (const identity_t &identity)
 
void identity_class (CLASS cls)
 
void identity_data (ELF_DATA data)
 
void identity_version (VERSION version)
 
void identity_os_abi (OS_ABI osabi)
 
void identity_abi_version (uint8_t version)
 
void accept (Visitor &visitor) const override
 
- 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 ()
 

Detailed Description

Class which represents the ELF's header. This class mirrors the raw ELF Elfxx_Ehdr structure.

Member Typedef Documentation

◆ identity_t

using LIEF::ELF::Header::identity_t = std::array<uint8_t, 16>

Member Enumeration Documentation

◆ CLASS

enum class LIEF::ELF::Header::CLASS
strong

Match the result of Elfxx_Ehdr.e_ident[EI_CLASS]

Enumerator
NONE 
ELF32 

Invalid class.

ELF64 

32-bit objects

◆ ELF_DATA

enum class LIEF::ELF::Header::ELF_DATA
strong

Match the result Elfxx_Ehdr.e_ident[EI_DATA]

Enumerator
NONE 
LSB 

Invalid data encoding.

MSB 

2's complement, little endian

◆ ELF_INDENT

e_ident size and indices.

Enumerator
ELI_MAG0 

File identification index.

ELI_MAG1 

File identification index.

ELI_MAG2 

File identification index.

ELI_MAG3 

File identification index.

ELI_CLASS 

File class.

ELI_DATA 

Data encoding.

ELI_VERSION 

File version.

ELI_OSABI 

OS/ABI identification.

ELI_ABIVERSION 

ABI version.

ELI_PAD 

Start of padding bytes.

ELI_NIDENT 

Number of bytes in e_ident.

◆ FILE_TYPE

enum class LIEF::ELF::Header::FILE_TYPE
strong

The type of the underlying ELF file. This enum matches the semantic of ET_NONE, ET_REL, ...

Enumerator
NONE 

Can't be determined.

REL 

Relocatable file (or object file)

EXEC 

non-pie executable

DYN 

Shared library or a pie-executable.

CORE 

Core dump file.

◆ OS_ABI

enum class LIEF::ELF::Header::OS_ABI
strong

Match the result Elfxx_Ehdr.e_ident[EI_OSABI]

Enumerator
SYSTEMV 
HPUX 

UNIX System V ABI.

NETBSD 

HP-UX operating system.

GNU 

NetBSD.

LINUX 

GNU/Linux.

HURD 

Historical alias for ELFOSABI_GNU.

SOLARIS 

GNU/Hurd.

AIX 

Solaris.

IRIX 

AIX.

FREEBSD 

IRIX.

TRU64 

FreeBSD.

MODESTO 

TRU64 UNIX.

OPENBSD 

Novell Modesto.

OPENVMS 

OpenBSD.

NSK 

OpenVMS.

AROS 

Hewlett-Packard Non-Stop Kernel.

FENIXOS 

AROS.

CLOUDABI 

FenixOS.

C6000_ELFABI 

Nuxi CloudABI.

AMDGPU_HSA 

Bare-metal TMS320C6000.

C6000_LINUX 

AMD HSA runtime.

ARM 

Linux TMS320C6000.

STANDALONE 

ARM.

◆ VERSION

enum class LIEF::ELF::Header::VERSION
strong

Match the result of Elfxx_Ehdr.e_version

Enumerator
NONE 

Invalid ELF version.

CURRENT 

Current version (default)

Constructor & Destructor Documentation

◆ Header() [1/2]

LIEF::ELF::Header::Header ( )
default

◆ Header() [2/2]

LIEF::ELF::Header::Header ( const Header & )
default

◆ ~Header()

LIEF::ELF::Header::~Header ( )
overridedefault

Member Function Documentation

◆ accept()

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

Implements LIEF::Object.

◆ entrypoint() [1/2]

uint64_t LIEF::ELF::Header::entrypoint ( ) const
inline

Executable entrypoint.

◆ entrypoint() [2/2]

void LIEF::ELF::Header::entrypoint ( uint64_t entry)
inline

◆ file_type() [1/2]

FILE_TYPE LIEF::ELF::Header::file_type ( ) const
inline

Define the object file type. (e.g. executable, library...)

◆ file_type() [2/2]

void LIEF::ELF::Header::file_type ( FILE_TYPE type)
inline

◆ flags_list()

std::vector< PROCESSOR_FLAGS > LIEF::ELF::Header::flags_list ( ) const

◆ has()

bool LIEF::ELF::Header::has ( PROCESSOR_FLAGS flag) const

◆ header_size() [1/2]

uint32_t LIEF::ELF::Header::header_size ( ) const
inline

Size of the current header (i.e. sizeof(Elfxx_Ehdr)) This size should be 64 for an ELF64 binary and 52 for an ELF32.

◆ header_size() [2/2]

void LIEF::ELF::Header::header_size ( uint32_t size)
inline

◆ identity() [1/4]

identity_t & LIEF::ELF::Header::identity ( )
inline

Return the ELF identity as an std::array

◆ identity() [2/4]

const identity_t & LIEF::ELF::Header::identity ( ) const
inline

◆ identity() [3/4]

void LIEF::ELF::Header::identity ( const identity_t & identity)

◆ identity() [4/4]

void LIEF::ELF::Header::identity ( const std::string & identity)

◆ identity_abi_version() [1/2]

uint32_t LIEF::ELF::Header::identity_abi_version ( ) const
inline

ABI Version.

◆ identity_abi_version() [2/2]

void LIEF::ELF::Header::identity_abi_version ( uint8_t version)
inline

◆ identity_class() [1/2]

CLASS LIEF::ELF::Header::identity_class ( ) const
inline

Return the object's class. ELF64 or ELF32

◆ identity_class() [2/2]

void LIEF::ELF::Header::identity_class ( CLASS cls)
inline

◆ identity_data() [1/2]

ELF_DATA LIEF::ELF::Header::identity_data ( ) const
inline

Specify the data encoding.

◆ identity_data() [2/2]

void LIEF::ELF::Header::identity_data ( ELF_DATA data)
inline

◆ identity_os_abi() [1/2]

OS_ABI LIEF::ELF::Header::identity_os_abi ( ) const
inline

Identifies the version of the ABI for which the object is prepared.

◆ identity_os_abi() [2/2]

void LIEF::ELF::Header::identity_os_abi ( OS_ABI osabi)
inline

◆ identity_version() [1/2]

VERSION LIEF::ELF::Header::identity_version ( ) const
inline

◆ identity_version() [2/2]

void LIEF::ELF::Header::identity_version ( VERSION version)
inline

◆ machine_type() [1/2]

ARCH LIEF::ELF::Header::machine_type ( ) const
inline

Target architecture.

◆ machine_type() [2/2]

void LIEF::ELF::Header::machine_type ( ARCH arch)
inline

◆ numberof_sections() [1/2]

uint32_t LIEF::ELF::Header::numberof_sections ( ) const
inline

Return the number of sections.

Warning
This value could differ from the real number of sections present in the binary. It must be taken as an indication

◆ numberof_sections() [2/2]

void LIEF::ELF::Header::numberof_sections ( uint32_t n)
inline

◆ numberof_segments() [1/2]

uint32_t LIEF::ELF::Header::numberof_segments ( ) const
inline

Return the number of segments.

◆ numberof_segments() [2/2]

void LIEF::ELF::Header::numberof_segments ( uint32_t n)
inline

◆ object_file_version() [1/2]

VERSION LIEF::ELF::Header::object_file_version ( ) const
inline

Version of the object file format.

◆ object_file_version() [2/2]

void LIEF::ELF::Header::object_file_version ( VERSION version)
inline

◆ operator=()

Header & LIEF::ELF::Header::operator= ( const Header & )
default

◆ processor_flag() [1/2]

uint32_t LIEF::ELF::Header::processor_flag ( ) const
inline

Processor-specific flags.

◆ processor_flag() [2/2]

void LIEF::ELF::Header::processor_flag ( uint32_t flags)
inline

◆ program_header_size() [1/2]

uint32_t LIEF::ELF::Header::program_header_size ( ) const
inline

Return the size of a program header (i.e. sizeof(Elfxx_Phdr)) This size should be 56 for an ELF64 binary and 32 for an ELF32.

◆ program_header_size() [2/2]

void LIEF::ELF::Header::program_header_size ( uint32_t size)
inline

◆ program_headers_offset() [1/2]

uint64_t LIEF::ELF::Header::program_headers_offset ( ) const
inline

Offset of the programs table (also known as segments table)

◆ program_headers_offset() [2/2]

void LIEF::ELF::Header::program_headers_offset ( uint64_t offset)
inline

◆ section_header_size() [1/2]

uint32_t LIEF::ELF::Header::section_header_size ( ) const
inline

Return the size of a section header (i.e. sizeof(Elfxx_Shdr)) This size should be 64 for a ELF64 binary and 40 for an ELF32.

◆ section_header_size() [2/2]

void LIEF::ELF::Header::section_header_size ( uint32_t size)
inline

◆ section_headers_offset() [1/2]

uint64_t LIEF::ELF::Header::section_headers_offset ( ) const
inline

Offset of the sections table.

◆ section_headers_offset() [2/2]

void LIEF::ELF::Header::section_headers_offset ( uint64_t offset)
inline

◆ section_name_table_idx() [1/2]

uint32_t LIEF::ELF::Header::section_name_table_idx ( ) const
inline

Return the section's index which contains sections' names.

◆ section_name_table_idx() [2/2]

void LIEF::ELF::Header::section_name_table_idx ( uint32_t idx)
inline

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