Class which parses and transforms an ELF file into a ELF::Binary object.
Subclassed by LIEF::OAT::Parser
Public Static Functions
Parse an ELF file and return a LIEF::ELF::Binary object.
For weird binaries (e.g. sectionless) you can choose which method to use for counting dynamic symbols
file – [in] Path to the ELF binary
conf – [in] Optional configuration for the parser
LIEF::ELF::Binary as a unique_ptr
Parse the given raw data as an ELF binary and return a LIEF::ELF::Binary object.
For weird binaries (e.g. sectionless) you can choose which method use to count dynamic symbols
data – [in] Raw ELF as a std::vector of uint8_t
conf – [in] Optional configuration for the parser
Parse the ELF binary from the given stream and return a LIEF::ELF::Binary object.
For weird binaries (e.g. sectionless) you can choose which method use to count dynamic symbols
stream – [in] The stream which wraps the ELF binary
conf – [in] Optional configuration for the parser
Public Static Attributes
Friends
This structure is used to tweak the ELF Parser (ELF::Parser)
Public Types
Methods that can be used by the LIEF::ELF::Parser to count the number of dynamic symbols
Values:
Automatic detection
Count based on sections (not very reliable)
Count based on hash table (reliable)
Count based on PLT/GOT relocations (very reliable but not accurate)
Public Members
Whether relocations (including plt-like relocations) should be parsed.
Whether dynamic symbols (those from .dynsym
) should be parsed.
Whether debug symbols (those from .symtab
) should be parsed.
Whether versioning symbols should be parsed.
Whether ELF notes information should be parsed.
Whether the overlay data should be parsed.
The method used to count the number of dynamic symbols
Public Static Functions
This returns a ParserConfig object configured to process all the ELF elements.
Class which represents an ELF binary.
Subclassed by LIEF::OAT::Binary
Public Types
This enum describes the different ways to relocate the segments table.
Values:
Defer the choice of the layout to LIEF.
The content of the binary right after the segments table is shifted and the relocations are updated accordingly. This kind of shift only works with PIE binaries.
The new segments table is relocated right after the first bss-like segment.
The new segments table is relocated at the end of the binary.
The new segments table is relocated between two LOAD segments. This kind of relocation is only doable when there is an alignment enforcement.
Iterator which outputs Note& object.
Iterator which outputs const Note& object.
Internal container for storing SymbolVersionRequirement.
Iterator which outputs SymbolVersionRequirement& object.
Iterator which outputs const SymbolVersionRequirement& object.
Internal container for storing SymbolVersionDefinition.
Iterator which outputs SymbolVersionDefinition& object.
Iterator which outputs const SymbolVersionDefinition& object.
Internal container for storing ELF’s Segment.
Iterator which outputs Segment& object.
Iterator which outputs const Segment& object.
Internal container for storing ELF’s DynamicEntry.
Iterator which outputs DynamicEntry& object.
Iterator which outputs const DynamicEntry& object.
Internal container for storing ELF’s SymbolVersion.
Iterator which outputs SymbolVersion& object.
Iterator which outputs const SymbolVersion& object.
Internal container for storing ELF’s Relocation.
Iterator which outputs plt/got Relocation& object.
Iterator which outputs plt/got const Relocation& object.
Iterator which outputs dynamic Relocation& object (not related to the PLT/GOT mechanism)
Iterator which outputs dynamic const Relocation& object (not related to the PLT/GOT mechanism)
Iterator which outputs Relocation& object found in object files (.o)
Iterator which outputs const Relocation& object found in object files (.o)
Iterator which outputs Relocation& object.
Iterator which outputs const Relocation& object.
Iterator which outputs the Dynamic Symbol& object.
Iterator which outputs the Dynamic const Symbol& object.
Iterator which outputs the static/debug Symbol& object.
Iterator which outputs the static/debug const Symbol& object.
Iterator which outputs static and dynamic Symbol& object.
Iterator which outputs static and dynamic const Symbol& object.
Iterator which outputs exported Symbol& object.
Iterator which outputs exported const Symbol& object.
Iterator which outputs imported Symbol& object.
Iterator which outputs imported const Symbol& object.
Internal container for storing ELF’s Section.
Iterator which outputs Section& object.
Iterator which outputs const Section& object.
Public Functions
Return Elf header .
Return the last offset used in binary according to sections table.
Return the last offset used in binary according to segments table.
Return the next virtual address available.
Return an iterator over the binary’s sections.
Return the binary’s entrypoint.
Return binary’s segments.
Return binary’s dynamic entries.
Add the given dynamic entry and return the new entry.
Remove the given dynamic entry.
Remove all dynamic entries with the given tag.
Remove the given section. The clear
parameter can be used to zeroize the original content beforehand.
section – [in] The section to remove
clear – [in] Whether zeroize the original content
Return an iterator over the binary’s dynamic symbols The dynamic symbols are those located in the .dynsym
section.
Return symbols which are exported by the binary.
Return symbols which are imported by the binary.
Return the debug symbols from the .symtab
section.
Return the symbol versions.
Return symbols version definition.
Return Symbol version requirement.
Return dynamic relocations.
Add a new dynamic relocation.
We consider a dynamic relocation as a relocation which is not plt-related
See: add_pltgot_relocation
Add a .plt.got relocation. This kind of relocation is usually associated with a PLT stub that aims at resolving the underlying symbol.
See also: add_dynamic_relocation
Add relocation for object file (.o)
The first parameter is the section to add while the second parameter is the LIEF::ELF::Section associated with the relocation.
If there is an error, this function returns a nullptr
. Otherwise, it returns the relocation added.
Return plt.got
relocations.
Return relocations used in an object file (*.o
)
Return all relocations present in the binary.
Return relocation associated with the given address. It returns a nullptr
if it is not found.
Return relocation associated with the given Symbol It returns a nullptr
if it is not found.
Return relocation associated with the given Symbol name It returns a nullptr
if it is not found.
true
if GNU hash is used
See also
Return the GnuHash object in readonly If the ELF binary does not use the GNU hash table, return a nullptr.
true
if SYSV hash is used
See also
Return the SysvHash object as a read-only object If the ELF binary does not use the legacy sysv hash table, return a nullptr.
Check if a section with the given name exists in the binary.
Check if a section that handles the given offset exists.
Check if a section that handles the given virtual address exists.
Return Section with the given name
. If the section can’t be found, it returns a nullptr.
Return the .text
section. If the section can’t be found, it returns a nullptr.
Return the .dynamic
section. If the section can’t be found, it returns a nullptr.
Return the hash section. If the section can’t be found, it returns a nullptr.
Return section which holds the symtab symbols. If the section can’t be found, it returns a nullptr.
Return program image base. For instance 0x40000
To compute the image base, we look for the PT_PHDR segment header (phdr), and we return phdr->p_vaddr - phdr->p_offset
Return the size of the mapped binary.
Check if the binary uses a loader (also named linker or interpreter)
See also
Return the ELF interpreter if any. (e.g. /lib64/ld-linux-x86-64.so.2
) If the binary does not have an interpreter, it returns an empty string.
See also
Change the interpreter.
Return an iterator on both static and dynamic symbols.
Export the given symbol and create it if it doesn’t exist.
Export the symbol with the given name and create it if it doesn’t exist.
Check if the symbol with the given name
exists in the dynamic symbols table.
Get the dynamic symbol from the given name. Return a nullptr if it can’t be found.
Check if the symbol with the given name
exists in the symtab symbol table.
Get the symtab symbol from the given name Return a nullptr if it can’t be found.
Return list of the strings used by the ELF binary.
Basically, this function looks for string in the .roadata
section
Remove symbols with the given name in both:
dynamic symbols
symtab symbols
Remove symtabl symbols with the given name.
Remove dynamic symbols with the given name.
Remove the given symbol from the dynamic symbols table.
As a side effect, it will remove any ELF::Relocation that refers to this symbol and the SymbolVersion (if any) associated with this symbol
Return the address of the given function name.
Return the address of the given function name.
func_name – [in] The function’s name target
demangled – [in] Use the demangled name
Add a new section in the binary.
This function requires a well-formed ELF binary
section – [in] The section object to insert
loaded – [in] Boolean value to indicate that section’s data must be loaded by a PT_LOAD segment
The section added. The size
and the virtual address
might change.
Add a dynamic symbol with the associated SymbolVersion.
Create a symbol for the function at the given address and export it.
Add a library as dependency.
Remove the given library from the dependencies.
Get the library object (DynamicEntryLibrary) from the given name If the library can’t be found, it returns a nullptr.
Get the library object (DynamicEntryLibrary) from the given name If the library can’t be found, it returns a nullptr.
Check if the given library name exists in the current binary.
Add a new segment in the binary.
The segment is inserted at the end
This function requires a well-formed ELF binary
The segment added. Virtual address
and File Offset
might change.
Replace the segment given in 2nd parameter with the segment given in the first one and return the updated segment.
Warning
The original_segment
is no longer valid after this function
Patch the content at virtual address address
with patch_value
.
address – [in] Address to patch
patch_value – [in] Patch to apply
addr_type – [in] Specify if the address should be used as an absolute virtual address or an RVA
Patch the address with the given value.
address – [in] Address to patch
patch_value – [in] Patch to apply
size – [in] Size of the value in bytes (1, 2, … 8)
addr_type – [in] Specify if the address should be used as an absolute virtual address or an RVA
Patch the imported symbol with the address
symbol – [in] Imported symbol to patch
address – [in] New address
Patch the imported symbol’s name with the address
symbol_name – [in] Imported symbol’s name to patch
address – [in] New address
Strip the binary by removing symtab symbols.
Remove a binary’s section.
name – [in] The name of the section to remove
clear – [in] Whether zeroize the original content
Reconstruct the binary object and write it in filename
This function assumes that the layout of the current ELF binary is correct (i.e. the binary can run).
filename – Path for the written ELF binary
Reconstruct the binary object with the given config and write it in filename
This function assumes that the layout of the current ELF binary is correct (i.e. the binary can run).
filename – Path for the written ELF binary
config – Builder configuration
Reconstruct the binary object and write it in os
stream.
This function assumes that the layout of the current ELF binary is correct (i.e. the binary can run).
os – Output stream for the written ELF binary
Reconstruct the binary object with the given config and write it in os
stream.
os – Output stream for the written ELF binary
config – Builder configuration
Reconstruct the binary object and return its content as a byte vector.
Convert a virtual address to a file offset.
Convert the given offset into a virtual address.
offset – [in] The offset to convert.
slide – [in] If not 0, it will replace the default base address (if any)
Check if the binary has been compiled with -fpie -pie
flags.
To do so we check if there is a PT_INTERP
segment and if the binary type is ET_DYN
(Shared object)
Check if the binary uses the NX
protection (Non executable stack)
Symbol index in the dynamic symbol table or -1 if the symbol does not exist.
Symbol index from the .symtab
section or -1 if the symbol is not present.
Return the ELF::Section from the given offset
. Return a nullptr if a section can’t be found.
If skip_nobits
is set (which is the case by default), this function won’t consider section for which the type is SHT_NOBITS
(like .bss, .tbss, ...
)
Return the ELF::Section from the given address
. Return a nullptr if a section can’t be found.
If skip_nobits
is set (which is the case by default), this function won’t consider section for which type is SHT_NOBITS
(like .bss, .tbss, ...
)
Return the ELF::Segment from the given address
. Return a nullptr if a segment can’t be found.
Return the ELF::Segment from the offset
. Return a nullptr if a segment can’t be found.
Return the first ELF::DynamicEntry associated with the given tag If the tag can’t be found, it returns a nullptr.
Return the first ELF::Segment associated with the given type. If a segment can’t be found, it returns a nullptr.
Return the first ELF::Note associated with the given type If a note can’t be found, it returns a nullptr.
Return the first ELF::Section associated with the given type If a section can’t be found, it returns a nullptr.
Check if an ELF::DynamicEntry associated with the given tag exists.
Check if ELF::Segment associated with the given type exists.
Check if a ELF::Section associated with the given type exists.
Return the content located at virtual address.
Method associated with the visitor pattern.
Apply the given permutation on the dynamic symbols table.
List of binary constructors (typically, the functions located in the .init_array
)
List of the binary destructors (typically, the functions located in the .fini_array
)
List of the functions found the in the binary.
true
if the binary embeds notes
Return an iterator over the ELF’s LIEF::ELF::Note.
See also
has_note
Return the last offset used by the ELF binary according to both: the sections table and the segments table.
True if data are present at the end of the binary.
Overlay data (if any)
Force relocating the segments table in a specific way.
This function can be used to enforce a specific relocation of the segments table.
type – [in] The relocation type to apply
The offset of the new segments table or 0 if it fails with the given method.
Return the array defined by the given tag (e.g. DynamicEntry::TAG::INIT_ARRAY) with relocations applied (if any)
True if the current ELF is targeting Android.
Class which represents the ELF’s header. This class mirrors the raw ELF Elfxx_Ehdr
structure.
Public Types
e_ident size and indices.
Values:
File identification index.
File identification index.
File identification index.
File identification index.
File class.
Data encoding.
File version.
OS/ABI identification.
ABI version.
Start of padding bytes.
Number of bytes in e_ident.
The type of the underlying ELF file. This enum matches the semantic of ET_NONE
, ET_REL
, …
Values:
Can’t be determined.
Relocatable file (or object file)
non-pie executable
Shared library or a pie-executable.
Core dump file.
Match the result of Elfxx_Ehdr.e_version
Values:
Invalid ELF version.
Current version (default)
Match the result of Elfxx_Ehdr.e_ident[EI_CLASS]
Values:
Invalid class.
32-bit objects
Match the result Elfxx_Ehdr.e_ident[EI_OSABI]
Values:
UNIX System V ABI.
HP-UX operating system.
NetBSD.
GNU/Linux.
Historical alias for ELFOSABI_GNU.
GNU/Hurd.
Solaris.
AIX.
IRIX.
FreeBSD.
TRU64 UNIX.
Novell Modesto.
OpenBSD.
OpenVMS.
Hewlett-Packard Non-Stop Kernel.
AROS.
FenixOS.
Nuxi CloudABI.
Bare-metal TMS320C6000.
AMD HSA runtime.
Linux TMS320C6000.
ARM.
Match the result Elfxx_Ehdr.e_ident[EI_DATA]
Values:
Invalid data encoding.
2’s complement, little endian
Public Functions
Executable entrypoint.
Offset of the programs table (also known as segments table)
Offset of the sections table.
Processor-specific flags.
Size of the current header (i.e. sizeof(Elfxx_Ehdr)
) This size should be 64 for an ELF64
binary and 52 for an ELF32
.
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
.
Return the number of segments.
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
.
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
Return the section’s index which contains sections’ names.
Return the ELF identity as an std::array
Identifies the version of the ABI for which the object is prepared.
ABI Version.
Class wich represents an ELF Section.
Public Types
Values:
No associated section (inactive entry).
Program-defined contents.
String table.
Relocation entries; explicit addends.
Information for dynamic linking.
Information about the file.
Data occupies no space in the file.
Relocation entries; no explicit addends.
Reserved.
Pointers to initialization functions.
Pointers to termination functions.
Pointers to pre-init functions.
Indices for SHN_XINDEX entries.
Relocation entries; only offsets.
Packed relocations (Android specific).
Packed relocations (Android specific).
This section is used to mark symbols as address-significant.
New relr relocations (Android specific).
Object attributes.
GNU-style hash table.
GNU version definitions.
GNU version references.
GNU symbol versions table.
Exception Index table
BPABI DLL dynamic linking pre-emption map
Object file compatibility attributes
Link editor is to sort the entries in this section based on their sizes
Unwind information
Register usage information
General options
ABI information.
Values:
The data in this section may be merged.
The data in this section is null-terminated strings.
A field in this section holds a section header table index.
Adds special ordering requirements for link editors.
This section requires special OS-specific processing to avoid incorrect behavior
This section is a member of a section group.
This section holds Thread-Local Storage.
Public Functions
Set section content.
section’s size (size in the binary, not the virtual size)
Change the section size.
Offset in the binary.
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
Section information. The meaning of this value depends on the section’s type.
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.
Index to another section.
Return a stream over the content of this section.
Public Static Functions
Public Static Attributes
Class which represents the ELF segments.
Public Types
Values:
Unused segment.
Loadable segment.
Dynamic linking information.
Interpreter pathname.
Auxiliary information.
Reserved.
The program header table itself.
The thread-local storage template.
Indicates stack executability.
GNU property
Read-only after relocation.
Public Functions
The file offset of the data associated with this segment.
The virtual address of the segment.
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
The file size of the data associated with this segment.
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.
The offset alignment of the segment.
The raw data associated with this segment.
Check if the current segment wraps the given ELF::Section.
Check if the current segment wraps the given section’s name.
Iterator over the sections wrapped by this segment.
Public Static Functions
Public Static Attributes
Class which represents an entry in the dynamic table These entries are located in the .dynamic
section or the PT_DYNAMIC
segment.
Subclassed by LIEF::ELF::DynamicEntryArray, LIEF::ELF::DynamicEntryFlags, LIEF::ELF::DynamicEntryLibrary, LIEF::ELF::DynamicEntryRpath, LIEF::ELF::DynamicEntryRunPath, LIEF::ELF::DynamicSharedObject
Public Types
Values:
Marks end of dynamic array.
String table offset of needed library.
Size of relocation entries in PLT.
Address associated with linkage table.
Address of symbolic hash table.
Address of dynamic string table.
Address of dynamic symbol table.
Address of relocation table (Rela entries).
Size of Rela relocation table.
Size of a Rela relocation entry.
Total size of the string table.
Size of a symbol table entry.
Address of initialization function.
Address of termination function.
String table offset of a shared objects name.
String table offset of library search path.
Changes symbol resolution algorithm.
Address of relocation table (Rel entries).
Size of Rel relocation table.
Size of a Rel relocation entry.
Type of relocation entry used for linking.
Reserved for debugger.
Relocations exist for non-writable segments.
Address of relocations associated with PLT.
Process all relocations before execution.
Pointer to array of initialization functions.
Pointer to array of termination functions.
Size of DT_INIT_ARRAY.
Size of DT_FINI_ARRAY.
String table offset of lib search path.
Flags.
Pointer to array of preinit functions.
Size of the DT_PREINIT_ARRAY array.
Address of SYMTAB_SHNDX section
Total size of RELR relative relocations
Address of RELR relative relocations
Size of one RELR relative relocaction
Reference to the GNU hash table.
ELF32_Rela count.
ELF32_Rel count.
Flags_1.
The address of .gnu.version section.
The address of the version definition table.
The number of entries in DT_VERDEF.
The address of the version Dependency table.
The number of entries in DT_VERNEED.
The offset of packed relocation data (older version < M) (Android specific).
The size of packed relocation data in bytes (older version < M) (Android specific).
The offset of packed relocation data (Android specific).
The size of packed relocation data in bytes (Android specific).
The offset of packed relocation data (Android specific).
The size of packed relocation data in bytes (Android specific).
The offset of new relr relocation data (Android specific).
The size of nre relr relocation data in bytes (Android specific).
The size of a new relr relocation entry (Android specific).
Specifies the relative count of new relr relocation entries (Android specific).
32 bit version number for runtime linker interface.
Index of first external dynamic symbol not referenced locally.
Index of first dynamic symbol in global offset table.
Number of page table entries in global offset table.
Address of run time loader map, used for debugging.
Number of entries in DT_MIPS_DELTA_INSTANCE.
Number of entries in DT_MIPS_DELTA_CLASSSYM.
The GOT index of the first PTE for a segment
The GOT index of the first PTE for a local symbol
The GOT index of the first PTE for a hidden symbol
The GOT index of the first PTE for a protected symbol
Address of .MIPS.options. */ MIPS_INTERFACE = MIPS_DISC + 0x7000002A, /**< Address of .interface.
Size of rld_text_resolve function stored in the GOT.
Default suffix of DSO to be added by rld on dlopen() calls.
Public Functions
Return the entry’s value.
The meaning of the value strongly depends on the tag. It can be an offset, an index, a flag, …
Public Static Functions
Public Static Attributes
Friends
Class which represents a DT_NEEDED
entry in the dynamic table.
This kind of entry is usually used to create library dependency.
Public Functions
Return the library associated with this entry (e.g. libc.so.6
)
Public Static Functions
Class that represents a DT_RUNPATH
wich is used by the loader to resolve libraries (DynamicEntryLibrary).
Public Functions
Constructor from (run)path.
Constructor from a list of paths.
Runpath raw value.
Paths as a list.
Insert a path
at the given position
Append the given path
Remove the given path
Public Static Functions
Public Static Attributes
Class which represents a DT_RPATH
entry. This attribute is deprecated (cf. man ld
) in favour of DT_RUNPATH
(See DynamicRunPath)
Public Functions
Constructor from a list of paths.
The actual rpath as a string.
Paths as a list.
Insert a path
at the given position
Append the given path
Remove the given path
Public Static Functions
Public Static Attributes
Class that represent an Array in the dynamic table. This entry is associated with constructors:
DT_PREINIT_ARRAY
DT_INIT_ARRAY
DT_FINI_ARRAY
The underlying values are 64-bits integers to cover both: ELF32 and ELF64 binaries.
Public Types
Public Functions
Insert the given function at pos
Append the given function.
Remove the given function.
Number of function registred in this array.
Public Static Functions
Public Types
Values:
The object may reference $ORIGIN.
Search the shared lib before searching the exe.
Relocations may modify a non-writable segment.
Process all relocations on load.
Reject attempts to load dynamically.
Public Functions
Return flags as a list of integers.
Public Static Functions
Public Static Attributes
Class that represents an ELF relocation.
Public Types
The purpose of a relocation defines how this relocation is used by the loader.
Values: