|
LIEF: Library to Instrument Executable Formats Version 2.0.0
|
Class which represents an ELF binary. More...
#include <Binary.hpp>


Public Types | |
| enum | PHDR_RELOC { AUTO = 0 , PIE_SHIFT , BSS_END , BINARY_END , SEGMENT_GAP , EXEC_BACKWARD , SECTIONS_SHIFT } |
| enum class | SEC_INSERT_POS { AUTO = 0 , POST_SEGMENT , POST_SECTION } |
| This enum defines where the content of a newly added section should be inserted. More... | |
| using | string_list_t = std::vector<std::string> |
| using | notes_t = std::vector<std::unique_ptr<Note>> |
| Internal container for storing notes. | |
| using | it_notes = ref_iterator<notes_t&, Note*> |
| Iterator which outputs Note& object. | |
| using | it_const_notes = const_ref_iterator<const notes_t&, const Note*> |
| Iterator which outputs const Note& object. | |
| using | symbols_version_requirement_t |
| Internal container for storing SymbolVersionRequirement. | |
| using | it_symbols_version_requirement |
| Iterator which outputs SymbolVersionRequirement& object. | |
| using | it_const_symbols_version_requirement |
| Iterator which outputs const SymbolVersionRequirement& object. | |
| using | symbols_version_definition_t |
| Internal container for storing SymbolVersionDefinition. | |
| using | it_symbols_version_definition |
| Iterator which outputs SymbolVersionDefinition& object. | |
| using | it_const_symbols_version_definition |
| Iterator which outputs const SymbolVersionDefinition& object. | |
| using | segments_t = std::vector<std::unique_ptr<Segment>> |
| Internal container for storing ELF's Segment. | |
| using | it_segments = ref_iterator<segments_t&, Segment*> |
| Iterator which outputs Segment& object. | |
| using | it_const_segments = const_ref_iterator<const segments_t&, const Segment*> |
| Iterator which outputs const Segment& object. | |
| using | dynamic_entries_t = std::vector<std::unique_ptr<DynamicEntry>> |
| Internal container for storing ELF's DynamicEntry. | |
| using | it_dynamic_entries = ref_iterator<dynamic_entries_t&, DynamicEntry*> |
| Iterator which outputs DynamicEntry& object. | |
| using | it_const_dynamic_entries |
| Iterator which outputs const DynamicEntry& object. | |
| using | symbols_version_t = std::vector<std::unique_ptr<SymbolVersion>> |
| Internal container for storing ELF's SymbolVersion. | |
| using | it_symbols_version = ref_iterator<symbols_version_t&, SymbolVersion*> |
| Iterator which outputs SymbolVersion& object. | |
| using | it_const_symbols_version |
| Iterator which outputs const SymbolVersion& object. | |
| using | relocations_t = std::vector<std::unique_ptr<Relocation>> |
| Internal container for storing ELF's Relocation. | |
| using | it_pltgot_relocations = filter_iterator<relocations_t&, Relocation*> |
| Iterator which outputs plt/got Relocation& object. | |
| using | it_const_pltgot_relocations |
| Iterator which outputs plt/got const Relocation& object. | |
| using | it_dynamic_relocations = filter_iterator<relocations_t&, Relocation*> |
| Iterator which outputs dynamic Relocation& object (not related to the PLT/GOT mechanism). | |
| using | it_const_dynamic_relocations |
| Iterator which outputs dynamic const Relocation& object (not related to the PLT/GOT mechanism). | |
| using | it_object_relocations = filter_iterator<relocations_t&, Relocation*> |
| Iterator which outputs Relocation& object found in object files (.o). | |
| using | it_const_object_relocations |
| Iterator which outputs const Relocation& object found in object files (.o). | |
| using | it_relocations = ref_iterator<relocations_t&, Relocation*> |
| Iterator which outputs Relocation& object. | |
| using | it_const_relocations |
| Iterator which outputs const Relocation& object. | |
| using | symbols_t = std::vector<std::unique_ptr<Symbol>> |
| Internal container for storing ELF's Symbol. | |
| using | it_dynamic_symbols = ref_iterator<symbols_t&, Symbol*> |
| Iterator which outputs the Dynamic Symbol& object. | |
| using | it_const_dynamic_symbols |
| Iterator which outputs the Dynamic const Symbol& object. | |
| using | it_symtab_symbols = ref_iterator<symbols_t&, Symbol*> |
| Iterator which outputs the static/debug Symbol& object. | |
| using | it_const_symtab_symbols |
| Iterator which outputs the static/debug const Symbol& object. | |
| using | it_symbols = ref_iterator<std::vector<Symbol*>> |
| Iterator which outputs static and dynamic Symbol& object. | |
| using | it_const_symbols = const_ref_iterator<std::vector<Symbol*>> |
| Iterator which outputs static and dynamic const Symbol& object. | |
| using | it_exported_symbols = filter_iterator<std::vector<Symbol*>> |
| Iterator which outputs exported Symbol& object. | |
| using | it_const_exported_symbols = const_filter_iterator<std::vector<Symbol*>> |
| Iterator which outputs exported const Symbol& object. | |
| using | it_imported_symbols = filter_iterator<std::vector<Symbol*>> |
| Iterator which outputs imported Symbol& object. | |
| using | it_const_imported_symbols = const_filter_iterator<std::vector<Symbol*>> |
| Iterator which outputs imported const Symbol& object. | |
| using | sections_t = std::vector<std::unique_ptr<Section>> |
| Internal container for storing ELF's Section. | |
| using | it_sections = ref_iterator<sections_t&, Section*> |
| Iterator which outputs Section& object. | |
| using | it_const_sections = const_ref_iterator<const sections_t&, const Section*> |
| Iterator which outputs const Section& object. | |
| Public Types inherited from LIEF::Binary | |
| enum class | VA_TYPES { AUTO = 0 , RVA = 1 , VA = 2 } |
| Enumeration of virtual address types used for patching and memory access. More... | |
| enum | FORMATS { UNKNOWN = 0 , ELF , PE , MACHO , OAT } |
| using | functions_t = std::vector<Function> |
| using | sections_t = std::vector<Section*> |
| Internal container. | |
| using | it_sections = ref_iterator<sections_t> |
| Iterator that outputs LIEF::Section&. | |
| using | it_const_sections = const_ref_iterator<sections_t> |
| Iterator that outputs const LIEF::Section&. | |
| using | symbols_t = std::vector<Symbol*> |
| Internal container. | |
| using | it_symbols = ref_iterator<symbols_t> |
| Iterator that outputs LIEF::Symbol&. | |
| using | it_const_symbols = const_ref_iterator<symbols_t> |
| Iterator that outputs const LIEF::Symbol&. | |
| using | relocations_t = std::vector<Relocation*> |
| Internal container. | |
| using | it_relocations = ref_iterator<relocations_t> |
| Iterator that outputs LIEF::Relocation&. | |
| using | it_const_relocations = const_ref_iterator<relocations_t> |
| Iterator that outputs const LIEF::Relocation&. | |
| using | instructions_it = iterator_range<assembly::Instruction::Iterator> |
| Instruction iterator. | |
| 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 | |
| Binary & | operator= (const Binary &)=delete |
| Binary (const Binary ©)=delete | |
| Header::CLASS | type () const |
| Return binary's class (ELF32 or ELF64). | |
| Header & | header () |
| Return Elf header . | |
| const Header & | header () const |
| uint64_t | last_offset_section () const |
| Return the last offset used in binary according to sections table. | |
| uint64_t | last_offset_segment () const |
| Return the last offset used in binary according to segments table. | |
| uint64_t | next_virtual_address () const |
| Return the next virtual address available. | |
| it_sections | sections () |
| Return an iterator over the binary's sections. | |
| it_const_sections | sections () const |
| uint64_t | entrypoint () const override |
| Return the binary's entrypoint. | |
| it_segments | segments () |
| Return binary's segments. | |
| it_const_segments | segments () const |
| it_dynamic_entries | dynamic_entries () |
| Return binary's dynamic entries. | |
| it_const_dynamic_entries | dynamic_entries () const |
| DynamicEntry & | add (const DynamicEntry &entry) |
| Add the given dynamic entry and return the new entry. | |
| Note & | add (const Note ¬e) |
| Add the given note and return the created entry. | |
| void | remove (const DynamicEntry &entry) |
| Remove the given dynamic entry. | |
| void | remove (DynamicEntry::TAG tag) |
| Remove all dynamic entries with the given tag. | |
| void | remove (const Section §ion, bool clear=false) |
| Remove the given section. The clear parameter can be used to zeroize the original content beforehand. | |
| void | remove (const Note ¬e) |
| Remove the given note. | |
| void | remove (Note::TYPE type) |
| Remove all notes with the given type. | |
| void | remove (const Segment &seg, bool clear=false) |
Remove the given segment. If clear is set, the original content of the segment will be filled with zeros before removal. | |
| void | remove (Segment::TYPE type, bool clear=false) |
| Remove all segments associated with the given type. | |
| it_dynamic_symbols | dynamic_symbols () |
| Return an iterator over the binary's dynamic symbols The dynamic symbols are those located in the .dynsym section. | |
| it_const_dynamic_symbols | dynamic_symbols () const |
| it_exported_symbols | exported_symbols () |
| Return symbols which are exported by the binary. | |
| it_const_exported_symbols | exported_symbols () const |
| it_imported_symbols | imported_symbols () |
| Return symbols which are imported by the binary. | |
| it_const_imported_symbols | imported_symbols () const |
| it_symtab_symbols | symtab_symbols () |
| Return the debug symbols from the .symtab section. | |
| it_const_symtab_symbols | symtab_symbols () const |
| it_symbols_version | symbols_version () |
| Return the symbol versions. | |
| it_const_symbols_version | symbols_version () const |
| it_symbols_version_definition | symbols_version_definition () |
| Return symbols version definition. | |
| it_const_symbols_version_definition | symbols_version_definition () const |
| it_symbols_version_requirement | symbols_version_requirement () |
| Return Symbol version requirement. | |
| it_const_symbols_version_requirement | symbols_version_requirement () const |
| std::pair< uint32_t, uint32_t > | required_glibc_version () const |
| Highest glibc version (major, minor) required by this binary. | |
| it_dynamic_relocations | dynamic_relocations () |
| Return dynamic relocations. | |
| it_const_dynamic_relocations | dynamic_relocations () const |
| Relocation & | add_dynamic_relocation (const Relocation &relocation) |
| Add a new dynamic relocation. | |
| Relocation & | add_pltgot_relocation (const Relocation &relocation) |
| Add a .plt.got relocation. This kind of relocation is usually associated with a PLT stub that aims at resolving the underlying symbol. | |
| Relocation * | add_object_relocation (const Relocation &relocation, const Section §ion) |
| Add relocation for object file (.o). | |
| it_pltgot_relocations | pltgot_relocations () |
| Return plt.got relocations. | |
| it_const_pltgot_relocations | pltgot_relocations () const |
| it_object_relocations | object_relocations () |
| Return relocations used in an object file (*.o). | |
| it_const_object_relocations | object_relocations () const |
| it_relocations | relocations () |
| Return all relocations present in the binary. | |
| it_const_relocations | relocations () const |
| const Relocation * | get_relocation (uint64_t address) const |
| Return relocation associated with the given address. It returns a nullptr if it is not found. | |
| Relocation * | get_relocation (uint64_t address) |
| const Relocation * | get_relocation (const Symbol &symbol) const |
| Return relocation associated with the given Symbol It returns a nullptr if it is not found. | |
| Relocation * | get_relocation (const Symbol &symbol) |
| const Relocation * | get_relocation (std::string_view symbol_name) const |
| Return relocation associated with the given Symbol name It returns a nullptr if it is not found. | |
| Relocation * | get_relocation (std::string_view symbol_name) |
| bool | use_gnu_hash () const |
| true if GNU hash is used | |
| const GnuHash * | gnu_hash () const |
| Return the GnuHash object in readonly If the ELF binary does not use the GNU hash table, return a nullptr. | |
| bool | use_sysv_hash () const |
| true if SYSV hash is used | |
| const SysvHash * | sysv_hash () const |
| Return the SysvHash object as a read-only object If the ELF binary does not use the legacy sysv hash table, return a nullptr. | |
| bool | has_section (std::string_view name) const |
| Check if a section with the given name exists in the binary. | |
| bool | has_section_with_offset (uint64_t offset) const |
| Check if a section that handles the given offset exists. | |
| bool | has_section_with_va (uint64_t va) const |
| Check if a section that handles the given virtual address exists. | |
| Section * | get_section (std::string_view name) |
| Return Section with the given name. If the section can't be found, it returns a nullptr. | |
| const Section * | get_section (std::string_view name) const |
| Section * | text_section () |
| Return the .text section. If the section can't be found, it returns a nullptr. | |
| Section * | dynamic_section () |
| Return the .dynamic section. If the section can't be found, it returns a nullptr. | |
| Section * | hash_section () |
| Return the hash section. If the section can't be found, it returns a nullptr. | |
| Section * | symtab_symbols_section () |
| Return section which holds the symtab symbols. If the section can't be found, it returns a nullptr. | |
| uint64_t | imagebase () const override |
| Return program image base. For instance 0x40000. | |
| uint64_t | virtual_size () const override |
| Return the size of the mapped binary. | |
| bool | has_interpreter () const |
| Check if the binary uses a loader (also named linker or interpreter). | |
| std::string_view | interpreter () const |
| 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. | |
| void | interpreter (std::string_view interpreter) |
| Change the interpreter. | |
| it_symbols | symbols () |
| Return an iterator on both static and dynamic symbols. | |
| it_const_symbols | symbols () const |
| Symbol & | export_symbol (const Symbol &symbol) |
| Export the given symbol and create it if it doesn't exist. | |
| Symbol & | export_symbol (std::string_view symbol_name, uint64_t value=0) |
| Export the symbol with the given name and create it if it doesn't exist. | |
| bool | has_dynamic_symbol (std::string_view name) const |
| Check if the symbol with the given name exists in the dynamic symbols table. | |
| const Symbol * | get_dynamic_symbol (std::string_view name) const |
| Get the dynamic symbol from the given name. Return a nullptr if it can't be found. | |
| Symbol * | get_dynamic_symbol (std::string_view name) |
| bool | has_symtab_symbol (std::string_view name) const |
| Check if the symbol with the given name exists in the symtab symbol table. | |
| const Symbol * | get_symtab_symbol (std::string_view name) const |
| Get the symtab symbol from the given name Return a nullptr if it can't be found. | |
| Symbol * | get_symtab_symbol (std::string_view name) |
| string_list_t | strings (size_t min_size=5) const |
| Return list of the strings used by the ELF binary. | |
| void | remove_symbol (std::string_view name) |
| Remove symbols with the given name in both: | |
| void | remove_symtab_symbol (std::string_view name) |
| Remove symtab symbols with the given name. | |
| void | remove_symtab_symbol (Symbol *symbol) |
| void | remove_dynamic_symbol (std::string_view name) |
| Remove dynamic symbols with the given name. | |
| void | remove_dynamic_symbol (Symbol *symbol) |
| Remove the given symbol from the dynamic symbols table. | |
| result< uint64_t > | get_function_address (std::string_view func_name) const override |
| Return the address of the given function name. | |
| result< uint64_t > | get_function_address (std::string_view func_name, bool demangled) const |
| Return the address of the given function name. | |
| Section * | add (const Section §ion, bool loaded=true, SEC_INSERT_POS pos=SEC_INSERT_POS::AUTO) |
| Add a new section in the binary. | |
| Section * | extend (const Section §ion, uint64_t size) |
| Symbol & | add_symtab_symbol (const Symbol &symbol) |
| Add a symtab symbol. | |
| Symbol & | add_dynamic_symbol (const Symbol &symbol, const SymbolVersion *version=nullptr) |
| Add a dynamic symbol with the associated SymbolVersion. | |
| Symbol & | add_exported_function (uint64_t address, std::string_view name="") |
| Create a symbol for the function at the given address and export it. | |
| DynamicEntryLibrary & | add_library (std::string_view library_name) |
| Add a library as dependency. | |
| void | remove_library (std::string_view library_name) |
| Remove the given library from the dependencies. | |
| DynamicEntryLibrary * | get_library (std::string_view library_name) |
| Get the library object (DynamicEntryLibrary) from the given name If the library can't be found, it returns a nullptr. | |
| const DynamicEntryLibrary * | get_library (std::string_view library_name) const |
| Get the library object (DynamicEntryLibrary) from the given name If the library can't be found, it returns a nullptr. | |
| bool | has_library (std::string_view name) const |
| Check if the given library name exists in the current binary. | |
| Segment * | add (const Segment &segment, uint64_t base=0) |
| Add a new segment in the binary. | |
| Segment * | replace (const Segment &new_segment, const Segment &original_segment, uint64_t base=0) |
| Replace the segment given in 2nd parameter with the segment given in the first one and return the updated segment. | |
| Segment * | extend (const Segment &segment, uint64_t size) |
| void | patch_address (uint64_t address, const std::vector< uint8_t > &patch_value, LIEF::Binary::VA_TYPES addr_type=LIEF::Binary::VA_TYPES::AUTO) override |
Patch the content at virtual address address with patch_value. | |
| void | patch_address (uint64_t address, uint64_t patch_value, size_t size=sizeof(uint64_t), LIEF::Binary::VA_TYPES addr_type=LIEF::Binary::VA_TYPES::AUTO) override |
| Patch the address with the given value. | |
| void | patch_pltgot (const Symbol &symbol, uint64_t address) |
| Patch the imported symbol with the address. | |
| void | patch_pltgot (std::string_view symbol_name, uint64_t address) |
| Patch the imported symbol's name with the address. | |
| void | strip () |
| Strip the binary by removing symtab symbols. | |
| void | remove_section (std::string_view name, bool clear=false) override |
| Remove a binary's section. | |
| void | write (const std::string &filename) |
| Reconstruct the binary object and write it in filename. | |
| void | write (const std::string &filename, const Builder::config_t &config) |
| Reconstruct the binary object with the given config and write it in filename. | |
| void | write (std::ostream &os) |
| Reconstruct the binary object and write it in os stream. | |
| void | write (std::ostream &os, const Builder::config_t &config) |
| Reconstruct the binary object with the given config and write it in os stream. | |
| std::vector< uint8_t > | raw () |
| Reconstruct the binary object and return its content as a byte vector. | |
| result< uint64_t > | virtual_address_to_offset (uint64_t virtual_address) const |
| Convert a virtual address to a file offset. | |
| result< uint64_t > | offset_to_virtual_address (uint64_t offset, uint64_t slide=0) const override |
| Convert the given offset into a virtual address. | |
| bool | is_pie () const override |
| Check if the binary has been compiled with -fpie -pie flags. | |
| bool | has_nx () const override |
| Check if the binary uses the NX protection (Non executable stack). | |
| int64_t | dynsym_idx (std::string_view name) const |
| Symbol index in the dynamic symbol table or -1 if the symbol does not exist. | |
| int64_t | dynsym_idx (const Symbol &sym) const |
| int64_t | symtab_idx (std::string_view name) const |
| Symbol index from the .symtab section or -1 if the symbol is not present. | |
| int64_t | symtab_idx (const Symbol &sym) const |
| const Section * | section_from_offset (uint64_t offset, bool skip_nobits=true) const |
Return the ELF::Section from the given offset. Return a nullptr if a section can't be found. | |
| Section * | section_from_offset (uint64_t offset, bool skip_nobits=true) |
| const Section * | section_from_virtual_address (uint64_t address, bool skip_nobits=true) const |
Return the ELF::Section from the given address. Return a nullptr if a section can't be found. | |
| Section * | section_from_virtual_address (uint64_t address, bool skip_nobits=true) |
| const Segment * | segment_from_virtual_address (uint64_t address) const |
Return the ELF::Segment from the given address. Return a nullptr if a segment can't be found. | |
| Segment * | segment_from_virtual_address (uint64_t address) |
| const Segment * | segment_from_virtual_address (Segment::TYPE type, uint64_t address) const |
| Segment * | segment_from_virtual_address (Segment::TYPE type, uint64_t address) |
| const Segment * | segment_from_offset (uint64_t offset) const |
Return the ELF::Segment from the offset. Return a nullptr if a segment can't be found. | |
| Segment * | segment_from_offset (uint64_t offset) |
| const Segment * | segment_from_offset (Segment::TYPE type, uint64_t offset) const |
| Segment * | segment_from_offset (Segment::TYPE type, uint64_t offset) |
| const DynamicEntry * | get (DynamicEntry::TAG tag) const |
| Return the first ELF::DynamicEntry associated with the given tag If the tag can't be found, it returns a nullptr. | |
| DynamicEntry * | get (DynamicEntry::TAG tag) |
| const Segment * | get (Segment::TYPE type) const |
| Return the first ELF::Segment associated with the given type. If a segment can't be found, it returns a nullptr. | |
| Segment * | get (Segment::TYPE type) |
| const Note * | get (Note::TYPE type) const |
| Return the first ELF::Note associated with the given type If a note can't be found, it returns a nullptr. | |
| Note * | get (Note::TYPE type) |
| const Section * | get (Section::TYPE type) const |
| Return the first ELF::Section associated with the given type If a section can't be found, it returns a nullptr. | |
| Section * | get (Section::TYPE type) |
| bool | has (DynamicEntry::TAG tag) const |
| Check if an ELF::DynamicEntry associated with the given tag exists. | |
| bool | has (Segment::TYPE type) const |
| Check if ELF::Segment associated with the given type exists. | |
| bool | has (Note::TYPE type) const |
| Check if a ELF::Note associated with the given type exists. | |
| bool | has (Section::TYPE type) const |
| Check if a ELF::Section associated with the given type exists. | |
| span< const uint8_t > | get_content_from_virtual_address (uint64_t virtual_address, uint64_t size, Binary::VA_TYPES addr_type=Binary::VA_TYPES::AUTO) const override |
| Return the content located at virtual address. | |
| void | accept (LIEF::Visitor &visitor) const override |
| Method associated with the visitor pattern. | |
| void | permute_dynamic_symbols (const std::vector< size_t > &permutation) |
| Apply the given permutation on the dynamic symbols table. | |
| LIEF::Binary::functions_t | ctor_functions () const override |
| List of binary constructors (typically, the functions located in the .init_array). | |
| LIEF::Binary::functions_t | dtor_functions () const |
| List of the binary destructors (typically, the functions located in the .fini_array). | |
| LIEF::Binary::functions_t | functions () const |
| List of the functions found in the binary. | |
| bool | has_notes () const |
| true if the binary embeds notes | |
| it_const_notes | notes () const |
| Return an iterator over the ELF's LIEF::ELF::Note. | |
| it_notes | notes () |
| uint64_t | eof_offset () const |
| Return the last offset used by the ELF binary according to both: the sections table and the segments table. | |
| bool | has_overlay () const |
| True if data are present at the end of the binary. | |
| span< const uint8_t > | overlay () const |
| Overlay data (if any). | |
| void | overlay (std::vector< uint8_t > overlay) |
| Function to set the overlay. | |
| uint64_t | relocate_phdr_table (PHDR_RELOC type) |
| Force relocating the segments table in a specific way. | |
| std::vector< uint64_t > | get_relocated_dynamic_array (DynamicEntry::TAG tag) const |
| Return the array defined by the given tag (e.g. DynamicEntry::TAG::INIT_ARRAY) with relocations applied (if any). | |
| bool | is_targeting_android () const |
| True if the current ELF is targeting Android. | |
| result< size_t > | get_section_idx (const Section §ion) const |
| Find the index of the section given in the first parameter. | |
| result< size_t > | get_section_idx (std::string_view name) const |
| Find the index of the section with the name given in the first parameter. | |
| const SymbolVersionRequirement * | find_version_requirement (std::string_view libname) const |
| Try to find the SymbolVersionRequirement associated with the given library name (e.g. libc.so.6). | |
| SymbolVersionRequirement * | find_version_requirement (std::string_view name) |
| bool | remove_version_requirement (std::string_view libname) |
| Deletes all required symbol versions linked to the specified library name. The function returns true if the operation succeed, false otherwise. | |
| bool | contains_sections (uint64_t start, uint64_t end) const |
| uint8_t | ptr_size () const |
| uint64_t | page_size () const override |
| Get the default memory page size according to the architecture and the format of the current binary. | |
| uint64_t | layout_pagesize () const |
| bool | is_symbolic () const |
| Check if the binary is flagged with DT_SYMBOLIC or DF_SYMBOLIC. | |
| size_t | hash (std::string_view name) |
| ~Binary () override | |
| std::ostream & | print (std::ostream &os) const override |
| Binary & | operator+= (const DynamicEntry &entry) |
| Binary & | operator+= (const Section §ion) |
| Binary & | operator+= (const Segment &segment) |
| Binary & | operator+= (const Note ¬e) |
| Binary & | operator-= (const DynamicEntry &entry) |
| Binary & | operator-= (DynamicEntry::TAG tag) |
| Binary & | operator-= (const Note ¬e) |
| Binary & | operator-= (Note::TYPE type) |
| Segment * | operator[] (Segment::TYPE type) |
| const Segment * | operator[] (Segment::TYPE type) const |
| DynamicEntry * | operator[] (DynamicEntry::TAG tag) |
| const DynamicEntry * | operator[] (DynamicEntry::TAG tag) const |
| Note * | operator[] (Note::TYPE type) |
| const Note * | operator[] (Note::TYPE type) const |
| Section * | operator[] (Section::TYPE type) |
| const Section * | operator[] (Section::TYPE type) const |
| bool | should_swap () const |
| Public Member Functions inherited from LIEF::Binary | |
| Binary () | |
| Binary (FORMATS fmt) | |
| ~Binary () override | |
| Binary & | operator= (const Binary &)=delete |
| Binary (const Binary &)=delete | |
| FORMATS | format () const |
| Executable format (ELF, PE, Mach-O) of the underlying binary. | |
| Header | header () const |
| Return the abstract header of the binary. | |
| it_symbols | symbols () |
| Return an iterator over the abstracted symbols in which the elements can be modified. | |
| it_const_symbols | symbols () const |
| Return an iterator over the abstracted symbols in which the elements can't be modified. | |
| bool | has_symbol (std::string_view name) const |
| Check if a Symbol with the given name exists. | |
| const Symbol * | get_symbol (std::string_view name) const |
| Return the Symbol with the given name If the symbol does not exist, return a nullptr. | |
| Symbol * | get_symbol (std::string_view name) |
| it_sections | sections () |
| Return an iterator over the binary's sections (LIEF::Section). | |
| it_const_sections | sections () const |
| it_relocations | relocations () |
| Return an iterator over the binary relocations (LIEF::Relocation). | |
| it_const_relocations | relocations () const |
| uint64_t | original_size () const |
| Binary's original size. | |
| functions_t | exported_functions () const |
| Return the functions exported by the binary. | |
| std::vector< std::string > | imported_libraries () const |
| Return libraries which are imported by the binary. | |
| functions_t | imported_functions () const |
| Return functions imported by the binary. | |
| std::vector< uint64_t > | xref (uint64_t address) const |
| template<class T> | |
| LIEF::result< T > | get_int_from_virtual_address (uint64_t va, VA_TYPES addr_type=VA_TYPES::AUTO) const |
| Get the integer value at the given virtual address. | |
| void | original_size (uint64_t size) |
| Change binary's original size. | |
| DebugInfo * | debug_info () const |
| Return the debug info if present. It can be either a LIEF::dwarf::DebugInfo or a LIEF::pdb::DebugInfo. | |
| instructions_it | disassemble (uint64_t address, size_t size) const |
| Disassemble code starting at the given virtual address and with the given size. | |
| instructions_it | disassemble (uint64_t address) const |
| Disassemble code starting at the given virtual address. | |
| instructions_it | disassemble (std::string_view function) const |
| Disassemble code for the given symbol name. | |
| instructions_it | disassemble (const uint8_t *buffer, size_t size, uint64_t address=0) const |
| Disassemble code provided by the given buffer at the specified address parameter. | |
| instructions_it | disassemble (const std::vector< uint8_t > &buffer, uint64_t address=0) const |
| Disassemble code provided by the given vector of bytes at the specified address parameter. | |
| instructions_it | disassemble (LIEF::span< const uint8_t > buffer, uint64_t address=0) const |
| instructions_it | disassemble (LIEF::span< uint8_t > buffer, uint64_t address=0) const |
| std::vector< uint8_t > | assemble (uint64_t address, std::string_view Asm, assembly::AssemblerConfig &config=assembly::AssemblerConfig::default_config()) |
| Assemble and patch the provided assembly code at the specified address. | |
| std::vector< uint8_t > | assemble (uint64_t address, const llvm::MCInst &inst) |
| Assemble and patch the address with the given LLVM MCInst. | |
| std::vector< uint8_t > | assemble (uint64_t address, const std::vector< llvm::MCInst > &insts) |
| Assemble and patch the address with the given LLVM MCInst. | |
| DebugInfo * | load_debug_info (std::string_view path) |
| Load and associate an external debug file (e.g., DWARF or PDB) with this binary. | |
| template<class T> | |
| const T * | cast () const |
| This function can be used to down cast a Binary: | |
| template<class T> | |
| T * | cast () |
| Public Member Functions inherited from LIEF::Object | |
| Object () | |
| Object (const Object &other) | |
| Object & | operator= (const Object &other) |
| Object (Object &&) noexcept=default | |
| Object & | operator= (Object &&) noexcept=default |
| 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 bool | classof (const LIEF::Binary *bin) |
Class which represents an ELF binary.
| using LIEF::ELF::Binary::dynamic_entries_t = std::vector<std::unique_ptr<DynamicEntry>> |
Internal container for storing ELF's DynamicEntry.
Iterator which outputs const DynamicEntry& object.
Iterator which outputs dynamic const Relocation& object (not related to the PLT/GOT mechanism).
Iterator which outputs the Dynamic const Symbol& object.
| using LIEF::ELF::Binary::it_const_exported_symbols = const_filter_iterator<std::vector<Symbol*>> |
Iterator which outputs exported const Symbol& object.
| using LIEF::ELF::Binary::it_const_imported_symbols = const_filter_iterator<std::vector<Symbol*>> |
Iterator which outputs imported const Symbol& object.
| using LIEF::ELF::Binary::it_const_notes = const_ref_iterator<const notes_t&, const Note*> |
Iterator which outputs const Note& object.
Iterator which outputs const Relocation& object found in object files (.o).
Iterator which outputs plt/got const Relocation& object.
Iterator which outputs const Relocation& object.
| using LIEF::ELF::Binary::it_const_sections = const_ref_iterator<const sections_t&, const Section*> |
Iterator which outputs const Section& object.
| using LIEF::ELF::Binary::it_const_segments = const_ref_iterator<const segments_t&, const Segment*> |
Iterator which outputs const Segment& object.
| using LIEF::ELF::Binary::it_const_symbols = const_ref_iterator<std::vector<Symbol*>> |
Iterator which outputs static and dynamic const Symbol& object.
Iterator which outputs const SymbolVersion& object.
Iterator which outputs const SymbolVersionDefinition& object.
Iterator which outputs const SymbolVersionRequirement& object.
Iterator which outputs the static/debug const Symbol& object.
Iterator which outputs DynamicEntry& object.
Iterator which outputs dynamic Relocation& object (not related to the PLT/GOT mechanism).
Iterator which outputs the Dynamic Symbol& object.
| using LIEF::ELF::Binary::it_exported_symbols = filter_iterator<std::vector<Symbol*>> |
Iterator which outputs exported Symbol& object.
| using LIEF::ELF::Binary::it_imported_symbols = filter_iterator<std::vector<Symbol*>> |
Iterator which outputs imported Symbol& object.
| using LIEF::ELF::Binary::it_notes = ref_iterator<notes_t&, Note*> |
Iterator which outputs Note& object.
Iterator which outputs Relocation& object found in object files (.o).
Iterator which outputs plt/got Relocation& object.
Iterator which outputs Relocation& object.
| using LIEF::ELF::Binary::it_sections = ref_iterator<sections_t&, Section*> |
Iterator which outputs Section& object.
| using LIEF::ELF::Binary::it_segments = ref_iterator<segments_t&, Segment*> |
Iterator which outputs Segment& object.
| using LIEF::ELF::Binary::it_symbols = ref_iterator<std::vector<Symbol*>> |
Iterator which outputs static and dynamic Symbol& object.
Iterator which outputs SymbolVersion& object.
Iterator which outputs SymbolVersionDefinition& object.
Iterator which outputs SymbolVersionRequirement& object.
Iterator which outputs the static/debug Symbol& object.
| using LIEF::ELF::Binary::notes_t = std::vector<std::unique_ptr<Note>> |
Internal container for storing notes.
| using LIEF::ELF::Binary::relocations_t = std::vector<std::unique_ptr<Relocation>> |
Internal container for storing ELF's Relocation.
| using LIEF::ELF::Binary::sections_t = std::vector<std::unique_ptr<Section>> |
| using LIEF::ELF::Binary::segments_t = std::vector<std::unique_ptr<Segment>> |
| using LIEF::ELF::Binary::string_list_t = std::vector<std::string> |
| using LIEF::ELF::Binary::symbols_t = std::vector<std::unique_ptr<Symbol>> |
Internal container for storing SymbolVersionDefinition.
Internal container for storing SymbolVersionRequirement.
| using LIEF::ELF::Binary::symbols_version_t = std::vector<std::unique_ptr<SymbolVersion>> |
Internal container for storing ELF's SymbolVersion.
This enum describes the different ways to relocate the segments table.
| Enumerator | |
|---|---|
| AUTO | Defer the choice of the layout to LIEF. |
| PIE_SHIFT | 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. |
| BSS_END | The new segments table is relocated right after the last bss-like segment of the file. Its bss area is expanded in the file. |
| BINARY_END | The new segments table is relocated at the end of the binary. |
| SEGMENT_GAP | The new segments table is relocated between two LOAD segments. This kind of relocation is only doable when there is an alignment enforcement. |
| EXEC_BACKWARD | For a non-PIE image only: duplicate backward the ELF header and the segments table. The new PHDR table is located between the former ELF header and the new one. This strategy ensures that the virtual addresses stay exactly at the same place as in the unmodified binary. It requires the first LOAD segment to map the ELF header and the segments table, and the page before this segment to be free. Credit: this is the layout that patchelf uses for the non-PIE executables (ET_EXEC). |
| SECTIONS_SHIFT | Grow the PHDR table by shifting known section in the first LOAD segment. Code and data keep their virtual addresses but this strategy assumes that the sections are consistent and not corrupted. |
|
strong |
This enum defines where the content of a newly added section should be inserted.
| Enumerator | |
|---|---|
| AUTO | Defer the choice to LIEF. |
| POST_SEGMENT | Insert the section after the last valid offset in the segments table. With this choice, the section is inserted after the loaded content but before any debug information. |
| POST_SECTION | Insert the section after the last valid offset in the section table. With this choice, the section is inserted at the very end of the binary. |
|
delete |
References Binary().
Referenced by Binary(), find_version_requirement(), get(), get(), get(), get(), get_dynamic_symbol(), get_library(), get_relocation(), get_relocation(), get_relocation(), get_section(), get_symtab_symbol(), operator+=(), operator+=(), operator+=(), operator+=(), operator-=(), operator-=(), operator-=(), operator-=(), operator=(), patch_address(), patch_address(), section_from_offset(), section_from_virtual_address(), segment_from_offset(), segment_from_offset(), segment_from_virtual_address(), and segment_from_virtual_address().
|
override |
|
overridevirtual |
Method associated with the visitor pattern.
Reimplemented from LIEF::Binary.
Reimplemented in LIEF::OAT::Binary.
| DynamicEntry & LIEF::ELF::Binary::add | ( | const DynamicEntry & | entry | ) |
Add the given dynamic entry and return the new entry.
References LIEF_LIFETIMEBOUND.
Referenced by operator+=(), operator+=(), operator+=(), and operator+=().
Add the given note and return the created entry.
References LIEF_LIFETIMEBOUND.
| Section * LIEF::ELF::Binary::add | ( | const Section & | section, |
| bool | loaded = true, | ||
| SEC_INSERT_POS | pos = SEC_INSERT_POS::AUTO ) |
Add a new section in the binary.
| [in] | section | The section object to insert |
| [in] | loaded | Boolean value to indicate that section's data must be loaded by a PT_LOAD segment |
| [in] | pos | Position where to insert the data in the sections table |
This function requires a well-formed ELF binary
References AUTO, and LIEF_LIFETIMEBOUND.
Add a new segment in the binary.
The segment is inserted at the end
This function requires a well-formed ELF binary
References LIEF_LIFETIMEBOUND.
| Relocation & LIEF::ELF::Binary::add_dynamic_relocation | ( | const Relocation & | relocation | ) |
Add a new dynamic relocation.
We consider a dynamic relocation as a relocation which is not plt-related
See: add_pltgot_relocation
References add_dynamic_relocation(), and LIEF_LIFETIMEBOUND.
Referenced by add_dynamic_relocation().
| Symbol & LIEF::ELF::Binary::add_dynamic_symbol | ( | const Symbol & | symbol, |
| const SymbolVersion * | version = nullptr ) |
Add a dynamic symbol with the associated SymbolVersion.
References LIEF_LIFETIMEBOUND, and LIEF::version().
| Symbol & LIEF::ELF::Binary::add_exported_function | ( | uint64_t | address, |
| std::string_view | name = "" ) |
Create a symbol for the function at the given address and export it.
References add_exported_function(), and LIEF_LIFETIMEBOUND.
Referenced by add_exported_function().
| DynamicEntryLibrary & LIEF::ELF::Binary::add_library | ( | std::string_view | library_name | ) |
Add a library as dependency.
References add_library(), and LIEF_LIFETIMEBOUND.
Referenced by add_library().
| Relocation * LIEF::ELF::Binary::add_object_relocation | ( | const Relocation & | relocation, |
| const Section & | section ) |
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.
References add_object_relocation(), and LIEF_LIFETIMEBOUND.
Referenced by add_object_relocation().
| Relocation & LIEF::ELF::Binary::add_pltgot_relocation | ( | const Relocation & | 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
References add_pltgot_relocation(), and LIEF_LIFETIMEBOUND.
Referenced by add_pltgot_relocation().
Add a symtab symbol.
References LIEF_LIFETIMEBOUND.
|
inlinestatic |
References LIEF::Binary::ELF, LIEF::Binary::format(), and LIEF::Binary::OAT.
| bool LIEF::ELF::Binary::contains_sections | ( | uint64_t | start, |
| uint64_t | end ) const |
|
overridevirtual |
List of binary constructors (typically, the functions located in the .init_array).
Implements LIEF::Binary.
| LIEF::Binary::functions_t LIEF::ELF::Binary::dtor_functions | ( | ) | const |
List of the binary destructors (typically, the functions located in the .fini_array).
|
inline |
Return binary's dynamic entries.
References LIEF_LIFETIMEBOUND.
|
inline |
References LIEF_LIFETIMEBOUND.
| it_dynamic_relocations LIEF::ELF::Binary::dynamic_relocations | ( | ) |
| it_const_dynamic_relocations LIEF::ELF::Binary::dynamic_relocations | ( | ) | const |
References dynamic_relocations(), and LIEF_LIFETIMEBOUND.
| Section * LIEF::ELF::Binary::dynamic_section | ( | ) |
Return the .dynamic section. If the section can't be found, it returns a nullptr.
References LIEF_LIFETIMEBOUND.
|
inline |
Return an iterator over the binary's dynamic symbols The dynamic symbols are those located in the .dynsym section.
References LIEF_LIFETIMEBOUND.
|
inline |
References LIEF_LIFETIMEBOUND.
| int64_t LIEF::ELF::Binary::dynsym_idx | ( | const Symbol & | sym | ) | const |
| int64_t LIEF::ELF::Binary::dynsym_idx | ( | std::string_view | name | ) | const |
Symbol index in the dynamic symbol table or -1 if the symbol does not exist.
|
inlineoverridevirtual |
Return the binary's entrypoint.
Implements LIEF::Binary.
| uint64_t LIEF::ELF::Binary::eof_offset | ( | ) | const |
Return the last offset used by the ELF binary according to both: the sections table and the segments table.
Export the given symbol and create it if it doesn't exist.
References LIEF_LIFETIMEBOUND.
| Symbol & LIEF::ELF::Binary::export_symbol | ( | std::string_view | symbol_name, |
| uint64_t | value = 0 ) |
Export the symbol with the given name and create it if it doesn't exist.
References LIEF_LIFETIMEBOUND.
| it_exported_symbols LIEF::ELF::Binary::exported_symbols | ( | ) |
Return symbols which are exported by the binary.
References LIEF_LIFETIMEBOUND.
Referenced by exported_symbols().
| it_const_exported_symbols LIEF::ELF::Binary::exported_symbols | ( | ) | const |
References exported_symbols(), and LIEF_LIFETIMEBOUND.
References LIEF_LIFETIMEBOUND.
Referenced by extend().
References extend(), and LIEF_LIFETIMEBOUND.
| const SymbolVersionRequirement * LIEF::ELF::Binary::find_version_requirement | ( | std::string_view | libname | ) | const |
Try to find the SymbolVersionRequirement associated with the given library name (e.g. libc.so.6).
References LIEF_LIFETIMEBOUND.
|
inline |
References Binary(), and LIEF_LIFETIMEBOUND.
| LIEF::Binary::functions_t LIEF::ELF::Binary::functions | ( | ) | const |
List of the functions found in the binary.
|
inline |
References Binary(), and LIEF_LIFETIMEBOUND.
| const DynamicEntry * LIEF::ELF::Binary::get | ( | DynamicEntry::TAG | tag | ) | const |
Return the first ELF::DynamicEntry associated with the given tag If the tag can't be found, it returns a nullptr.
References LIEF_LIFETIMEBOUND.
Referenced by has(), has(), has(), has(), operator[](), operator[](), operator[](), operator[](), operator[](), operator[](), operator[](), and operator[]().
|
inline |
References Binary(), LIEF_LIFETIMEBOUND, and type().
| const Note * LIEF::ELF::Binary::get | ( | Note::TYPE | type | ) | const |
Return the first ELF::Note associated with the given type If a note can't be found, it returns a nullptr.
References LIEF_LIFETIMEBOUND, and type().
|
inline |
References Binary(), LIEF_LIFETIMEBOUND, and type().
| const Section * LIEF::ELF::Binary::get | ( | Section::TYPE | type | ) | const |
Return the first ELF::Section associated with the given type If a section can't be found, it returns a nullptr.
References LIEF_LIFETIMEBOUND, and type().
|
inline |
References Binary(), LIEF_LIFETIMEBOUND, and type().
| const Segment * LIEF::ELF::Binary::get | ( | Segment::TYPE | type | ) | const |
Return the first ELF::Segment associated with the given type. If a segment can't be found, it returns a nullptr.
References LIEF_LIFETIMEBOUND, and type().
|
overridevirtual |
Return the content located at virtual address.
Implements LIEF::Binary.
References LIEF::Binary::AUTO, and LIEF_LIFETIMEBOUND.
|
inline |
References Binary(), and LIEF_LIFETIMEBOUND.
| const Symbol * LIEF::ELF::Binary::get_dynamic_symbol | ( | std::string_view | name | ) | const |
Get the dynamic symbol from the given name. Return a nullptr if it can't be found.
References LIEF_LIFETIMEBOUND.
Referenced by has_dynamic_symbol().
|
overridevirtual |
Return the address of the given function name.
Reimplemented from LIEF::Binary.
| result< uint64_t > LIEF::ELF::Binary::get_function_address | ( | std::string_view | func_name, |
| bool | demangled ) const |
Return the address of the given function name.
| [in] | func_name | The function's name target |
| [in] | demangled | Use the demangled name |
|
inline |
Get the library object (DynamicEntryLibrary) from the given name If the library can't be found, it returns a nullptr.
References Binary(), get_library(), and LIEF_LIFETIMEBOUND.
Referenced by get_library(), and has_library().
| const DynamicEntryLibrary * LIEF::ELF::Binary::get_library | ( | std::string_view | library_name | ) | const |
Get the library object (DynamicEntryLibrary) from the given name If the library can't be found, it returns a nullptr.
References LIEF_LIFETIMEBOUND.
| std::vector< uint64_t > LIEF::ELF::Binary::get_relocated_dynamic_array | ( | DynamicEntry::TAG | tag | ) | const |
Return the array defined by the given tag (e.g. DynamicEntry::TAG::INIT_ARRAY) with relocations applied (if any).
|
inline |
References Binary(), and LIEF_LIFETIMEBOUND.
| const Relocation * LIEF::ELF::Binary::get_relocation | ( | const Symbol & | symbol | ) | const |
Return relocation associated with the given Symbol It returns a nullptr if it is not found.
References LIEF_LIFETIMEBOUND.
|
inline |
References Binary(), and LIEF_LIFETIMEBOUND.
| const Relocation * LIEF::ELF::Binary::get_relocation | ( | std::string_view | symbol_name | ) | const |
Return relocation associated with the given Symbol name It returns a nullptr if it is not found.
References LIEF_LIFETIMEBOUND.
|
inline |
References Binary(), and LIEF_LIFETIMEBOUND.
| const Relocation * LIEF::ELF::Binary::get_relocation | ( | uint64_t | address | ) | const |
Return relocation associated with the given address. It returns a nullptr if it is not found.
References LIEF_LIFETIMEBOUND.
|
inline |
Return Section with the given name. If the section can't be found, it returns a nullptr.
References Binary(), and LIEF_LIFETIMEBOUND.
Referenced by has_section(), and text_section().
| const Section * LIEF::ELF::Binary::get_section | ( | std::string_view | name | ) | const |
References LIEF_LIFETIMEBOUND.
Find the index of the section given in the first parameter.
References make_error_code(), and not_found.
|
inline |
Find the index of the section with the name given in the first parameter.
References make_error_code(), and not_found.
|
inline |
References Binary(), and LIEF_LIFETIMEBOUND.
| const Symbol * LIEF::ELF::Binary::get_symtab_symbol | ( | std::string_view | name | ) | const |
Get the symtab symbol from the given name Return a nullptr if it can't be found.
References LIEF_LIFETIMEBOUND.
Referenced by has_symtab_symbol().
|
inline |
Return the GnuHash object in readonly If the ELF binary does not use the GNU hash table, return a nullptr.
References LIEF_LIFETIMEBOUND, and use_gnu_hash().
|
inline |
Check if an ELF::DynamicEntry associated with the given tag exists.
References get().
Referenced by use_gnu_hash(), and use_sysv_hash().
|
inline |
|
inline |
Check if a ELF::Section associated with the given type exists.
|
inline |
Check if ELF::Segment associated with the given type exists.
|
inline |
Check if the symbol with the given name exists in the dynamic symbols table.
References get_dynamic_symbol(), and has_dynamic_symbol().
Referenced by has_dynamic_symbol().
| bool LIEF::ELF::Binary::has_interpreter | ( | ) | const |
Check if the binary uses a loader (also named linker or interpreter).
References has_interpreter().
Referenced by has_interpreter().
|
inline |
Check if the given library name exists in the current binary.
References get_library().
| bool LIEF::ELF::Binary::has_notes | ( | ) | const |
true if the binary embeds notes
|
overridevirtual |
Check if the binary uses the NX protection (Non executable stack).
Implements LIEF::Binary.
|
inline |
True if data are present at the end of the binary.
|
inline |
Check if a section with the given name exists in the binary.
References get_section().
| bool LIEF::ELF::Binary::has_section_with_offset | ( | uint64_t | offset | ) | const |
Check if a section that handles the given offset exists.
| bool LIEF::ELF::Binary::has_section_with_va | ( | uint64_t | va | ) | const |
Check if a section that handles the given virtual address exists.
|
inline |
Check if the symbol with the given name exists in the symtab symbol table.
References get_symtab_symbol().
| size_t LIEF::ELF::Binary::hash | ( | std::string_view | name | ) |
| Section * LIEF::ELF::Binary::hash_section | ( | ) |
Return the hash section. If the section can't be found, it returns a nullptr.
References hash_section(), and LIEF_LIFETIMEBOUND.
Referenced by hash_section().
|
inline |
Return Elf header .
References LIEF_LIFETIMEBOUND.
|
inline |
References LIEF_LIFETIMEBOUND.
|
overridevirtual |
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
Implements LIEF::Binary.
References imagebase().
Referenced by imagebase().
| it_imported_symbols LIEF::ELF::Binary::imported_symbols | ( | ) |
Return symbols which are imported by the binary.
References imported_symbols(), and LIEF_LIFETIMEBOUND.
Referenced by imported_symbols(), and imported_symbols().
| it_const_imported_symbols LIEF::ELF::Binary::imported_symbols | ( | ) | const |
References imported_symbols(), and LIEF_LIFETIMEBOUND.
|
inline |
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.
References interpreter(), and LIEF_LIFETIMEBOUND.
Referenced by interpreter(), and interpreter().
|
inline |
Change the interpreter.
References interpreter().
|
overridevirtual |
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)
Implements LIEF::Binary.
| bool LIEF::ELF::Binary::is_symbolic | ( | ) | const |
Check if the binary is flagged with DT_SYMBOLIC or DF_SYMBOLIC.
| bool LIEF::ELF::Binary::is_targeting_android | ( | ) | const |
| uint64_t LIEF::ELF::Binary::last_offset_section | ( | ) | const |
Return the last offset used in binary according to sections table.
| uint64_t LIEF::ELF::Binary::last_offset_segment | ( | ) | const |
Return the last offset used in binary according to segments table.
| uint64_t LIEF::ELF::Binary::layout_pagesize | ( | ) | const |
| uint64_t LIEF::ELF::Binary::next_virtual_address | ( | ) | const |
Return the next virtual address available.
|
inline |
References LIEF_LIFETIMEBOUND.
|
inline |
| it_object_relocations LIEF::ELF::Binary::object_relocations | ( | ) |
Return relocations used in an object file (*.o).
References LIEF_LIFETIMEBOUND, and object_relocations().
Referenced by object_relocations(), and object_relocations().
| it_const_object_relocations LIEF::ELF::Binary::object_relocations | ( | ) | const |
References LIEF_LIFETIMEBOUND, and object_relocations().
|
overridevirtual |
Convert the given offset into a virtual address.
| [in] | offset | The offset to convert. |
| [in] | slide | If not 0, it will replace the default base address (if any) |
Implements LIEF::Binary.
|
inline |
References add(), Binary(), and LIEF_LIFETIMEBOUND.
References add(), Binary(), and LIEF_LIFETIMEBOUND.
References add(), Binary(), and LIEF_LIFETIMEBOUND.
References add(), Binary(), and LIEF_LIFETIMEBOUND.
|
inline |
References Binary(), LIEF_LIFETIMEBOUND, and remove().
References Binary(), LIEF_LIFETIMEBOUND, and remove().
|
inline |
References Binary(), LIEF_LIFETIMEBOUND, and remove().
|
inline |
References Binary(), LIEF_LIFETIMEBOUND, remove(), and type().
|
inline |
References get(), and LIEF_LIFETIMEBOUND.
|
inline |
References get(), and LIEF_LIFETIMEBOUND.
|
inline |
References get(), LIEF_LIFETIMEBOUND, and type().
|
inline |
References get(), LIEF_LIFETIMEBOUND, and type().
|
inline |
References get(), LIEF_LIFETIMEBOUND, and type().
|
inline |
References get(), LIEF_LIFETIMEBOUND, and type().
|
inline |
References get(), LIEF_LIFETIMEBOUND, and type().
|
inline |
References get(), LIEF_LIFETIMEBOUND, and type().
|
inline |
|
inline |
|
overridevirtual |
Get the default memory page size according to the architecture and the format of the current binary.
Reimplemented from LIEF::Binary.
|
overridevirtual |
Patch the content at virtual address address with patch_value.
| [in] | address | Address to patch |
| [in] | patch_value | Patch to apply |
| [in] | addr_type | Specify if the address should be used as an absolute virtual address or an RVA |
Implements LIEF::Binary.
References AUTO, Binary(), and patch_address().
Referenced by patch_address(), and patch_address().
|
overridevirtual |
Patch the address with the given value.
| [in] | address | Address to patch |
| [in] | patch_value | Patch to apply |
| [in] | size | Size of the value in bytes (1, 2, ... 8) |
| [in] | addr_type | Specify if the address should be used as an absolute virtual address or an RVA |
Implements LIEF::Binary.
References AUTO, Binary(), and patch_address().
| void LIEF::ELF::Binary::patch_pltgot | ( | const Symbol & | symbol, |
| uint64_t | address ) |
Patch the imported symbol with the address.
| [in] | symbol | Imported symbol to patch |
| [in] | address | New address |
References patch_pltgot().
Referenced by patch_pltgot(), and patch_pltgot().
| void LIEF::ELF::Binary::patch_pltgot | ( | std::string_view | symbol_name, |
| uint64_t | address ) |
Patch the imported symbol's name with the address.
| [in] | symbol_name | Imported symbol's name to patch |
| [in] | address | New address |
References patch_pltgot().
| void LIEF::ELF::Binary::permute_dynamic_symbols | ( | const std::vector< size_t > & | permutation | ) |
Apply the given permutation on the dynamic symbols table.
| it_pltgot_relocations LIEF::ELF::Binary::pltgot_relocations | ( | ) |
Return plt.got relocations.
References LIEF_LIFETIMEBOUND, and pltgot_relocations().
Referenced by pltgot_relocations(), and pltgot_relocations().
| it_const_pltgot_relocations LIEF::ELF::Binary::pltgot_relocations | ( | ) | const |
References LIEF_LIFETIMEBOUND, and pltgot_relocations().
|
overridevirtual |
Reimplemented from LIEF::Binary.
|
inline |
References LIEF::ELF::Header::ELF32, LIEF::ELF::Header::ELF64, and type().
| std::vector< uint8_t > LIEF::ELF::Binary::raw | ( | ) |
Reconstruct the binary object and return its content as a byte vector.
| uint64_t LIEF::ELF::Binary::relocate_phdr_table | ( | PHDR_RELOC | type | ) |
Force relocating the segments table in a specific way.
This function can be used to enforce a specific relocation of the segments table.
| [in] | type | The relocation type to apply |
References type().
|
inline |
Return all relocations present in the binary.
References LIEF_LIFETIMEBOUND, and relocations().
Referenced by relocations().
|
inline |
References LIEF_LIFETIMEBOUND.
| void LIEF::ELF::Binary::remove | ( | const DynamicEntry & | entry | ) |
Remove the given dynamic entry.
Referenced by operator-=(), operator-=(), operator-=(), and operator-=().
| void LIEF::ELF::Binary::remove | ( | const Note & | note | ) |
Remove the given note.
| void LIEF::ELF::Binary::remove | ( | const Section & | section, |
| bool | clear = false ) |
Remove the given section. The clear parameter can be used to zeroize the original content beforehand.
| [in] | section | The section to remove |
| [in] | clear | Whether zeroize the original content |
| void LIEF::ELF::Binary::remove | ( | const Segment & | seg, |
| bool | clear = false ) |
Remove the given segment. If clear is set, the original content of the segment will be filled with zeros before removal.
| void LIEF::ELF::Binary::remove | ( | DynamicEntry::TAG | tag | ) |
Remove all dynamic entries with the given tag.
| void LIEF::ELF::Binary::remove | ( | Note::TYPE | type | ) |
Remove all notes with the given type.
References type().
| void LIEF::ELF::Binary::remove | ( | Segment::TYPE | type, |
| bool | clear = false ) |
Remove all segments associated with the given type.
If clear is set, the original content of the segment will be filled with zeros before removal.
References type().
| void LIEF::ELF::Binary::remove_dynamic_symbol | ( | std::string_view | name | ) |
Remove dynamic symbols with the given name.
| void LIEF::ELF::Binary::remove_dynamic_symbol | ( | Symbol * | symbol | ) |
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
| void LIEF::ELF::Binary::remove_library | ( | std::string_view | library_name | ) |
Remove the given library from the dependencies.
References remove_library().
Referenced by remove_library().
|
overridevirtual |
Remove a binary's section.
| [in] | name | The name of the section to remove |
| [in] | clear | Whether zeroize the original content |
Implements LIEF::Binary.
References remove_section().
Referenced by remove_section().
| void LIEF::ELF::Binary::remove_symbol | ( | std::string_view | name | ) |
Remove symbols with the given name in both:
| void LIEF::ELF::Binary::remove_symtab_symbol | ( | std::string_view | name | ) |
Remove symtab symbols with the given name.
| void LIEF::ELF::Binary::remove_symtab_symbol | ( | Symbol * | symbol | ) |
| bool LIEF::ELF::Binary::remove_version_requirement | ( | std::string_view | libname | ) |
Deletes all required symbol versions linked to the specified library name. The function returns true if the operation succeed, false otherwise.
| Segment * LIEF::ELF::Binary::replace | ( | const Segment & | new_segment, |
| const Segment & | original_segment, | ||
| uint64_t | base = 0 ) |
Replace the segment given in 2nd parameter with the segment given in the first one and return the updated segment.
References LIEF_LIFETIMEBOUND, and replace().
Referenced by replace().
| std::pair< uint32_t, uint32_t > LIEF::ELF::Binary::required_glibc_version | ( | ) | const |
Highest glibc version (major, minor) required by this binary.
Patch components are ignored and GLIBC_ABI_DT_RELR counts as glibc 2.36.
Returns (0, 0) if no glibc requirement is identified.
|
inline |
References Binary(), LIEF_LIFETIMEBOUND, and section_from_offset().
| const Section * LIEF::ELF::Binary::section_from_offset | ( | uint64_t | offset, |
| bool | skip_nobits = true ) const |
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,
...)
References LIEF_LIFETIMEBOUND.
Referenced by section_from_offset().
|
inline |
References Binary(), LIEF_LIFETIMEBOUND, and section_from_virtual_address().
| const Section * LIEF::ELF::Binary::section_from_virtual_address | ( | uint64_t | address, |
| bool | skip_nobits = true ) const |
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, ...)
References LIEF_LIFETIMEBOUND.
Referenced by section_from_virtual_address().
|
inline |
Return an iterator over the binary's sections.
References LIEF_LIFETIMEBOUND.
|
inline |
References LIEF_LIFETIMEBOUND.
|
inline |
References Binary(), LIEF_LIFETIMEBOUND, and type().
| const Segment * LIEF::ELF::Binary::segment_from_offset | ( | Segment::TYPE | type, |
| uint64_t | offset ) const |
References LIEF_LIFETIMEBOUND, and type().
|
inline |
References Binary(), and LIEF_LIFETIMEBOUND.
| const Segment * LIEF::ELF::Binary::segment_from_offset | ( | uint64_t | offset | ) | const |
Return the ELF::Segment from the offset. Return a nullptr if a segment can't be found.
References LIEF_LIFETIMEBOUND.
|
inline |
References Binary(), LIEF_LIFETIMEBOUND, and type().
| const Segment * LIEF::ELF::Binary::segment_from_virtual_address | ( | Segment::TYPE | type, |
| uint64_t | address ) const |
References LIEF_LIFETIMEBOUND, and type().
|
inline |
References Binary(), and LIEF_LIFETIMEBOUND.
| const Segment * LIEF::ELF::Binary::segment_from_virtual_address | ( | uint64_t | address | ) | const |
Return the ELF::Segment from the given address. Return a nullptr if a segment can't be found.
References LIEF_LIFETIMEBOUND.
|
inline |
Return binary's segments.
References LIEF_LIFETIMEBOUND.
|
inline |
References LIEF_LIFETIMEBOUND.
|
inline |
| string_list_t LIEF::ELF::Binary::strings | ( | size_t | min_size = 5 | ) | const |
Return list of the strings used by the ELF binary.
Basically, this function looks for strings in the .rodata section
| void LIEF::ELF::Binary::strip | ( | ) |
|
inline |
Return an iterator on both static and dynamic symbols.
References LIEF_LIFETIMEBOUND.
|
inline |
References LIEF_LIFETIMEBOUND.
|
inline |
Return the symbol versions.
References LIEF_LIFETIMEBOUND.
|
inline |
References LIEF_LIFETIMEBOUND.
|
inline |
Return symbols version definition.
References LIEF_LIFETIMEBOUND.
|
inline |
References LIEF_LIFETIMEBOUND.
|
inline |
Return Symbol version requirement.
References LIEF_LIFETIMEBOUND.
|
inline |
References LIEF_LIFETIMEBOUND.
| int64_t LIEF::ELF::Binary::symtab_idx | ( | const Symbol & | sym | ) | const |
| int64_t LIEF::ELF::Binary::symtab_idx | ( | std::string_view | name | ) | const |
Symbol index from the .symtab section or -1 if the symbol is not present.
|
inline |
Return the debug symbols from the .symtab section.
References LIEF_LIFETIMEBOUND, and symtab_symbols().
Referenced by symtab_symbols().
|
inline |
References LIEF_LIFETIMEBOUND.
| Section * LIEF::ELF::Binary::symtab_symbols_section | ( | ) |
Return section which holds the symtab symbols. If the section can't be found, it returns a nullptr.
References LIEF_LIFETIMEBOUND, and symtab_symbols_section().
Referenced by symtab_symbols_section().
|
inline |
Return the SysvHash object as a read-only object If the ELF binary does not use the legacy sysv hash table, return a nullptr.
References LIEF_LIFETIMEBOUND, and use_sysv_hash().
|
inline |
Return the .text section. If the section can't be found, it returns a nullptr.
References get_section(), and LIEF_LIFETIMEBOUND.
|
inline |
Return binary's class (ELF32 or ELF64).
Referenced by get(), get(), get(), get(), get(), get(), has(), has(), has(), operator-=(), operator[](), operator[](), operator[](), operator[](), operator[](), operator[](), ptr_size(), relocate_phdr_table(), remove(), remove(), segment_from_offset(), segment_from_offset(), segment_from_virtual_address(), and segment_from_virtual_address().
|
inline |
true if GNU hash is used
References LIEF::ELF::DynamicEntry::GNU_HASH, and has().
Referenced by gnu_hash().
|
inline |
true if SYSV hash is used
References has(), and LIEF::ELF::DynamicEntry::HASH.
Referenced by sysv_hash().
| result< uint64_t > LIEF::ELF::Binary::virtual_address_to_offset | ( | uint64_t | virtual_address | ) | const |
Convert a virtual address to a file offset.
|
overridevirtual |
Return the size of the mapped binary.
Reimplemented from LIEF::Binary.
References virtual_size().
Referenced by virtual_size().
|
inline |
| void LIEF::ELF::Binary::write | ( | const std::string & | filename, |
| const Builder::config_t & | config ) |
|
inline |
| void LIEF::ELF::Binary::write | ( | std::ostream & | os, |
| const Builder::config_t & | config ) |