LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
LIEF::Binary Class Referenceabstract

Abstract binary that exposes an uniform API for the different executable file formats. More...

#include <Binary.hpp>

Inheritance diagram for LIEF::Binary:
Inheritance graph
[legend]
Collaboration diagram for LIEF::Binary:
Collaboration graph
[legend]

Public Types

enum class  VA_TYPES { AUTO = 0 , RVA = 1 , VA = 2 }
 Type of a virtual address. 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&.
 
- 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 (FORMATS fmt)
 
Binaryoperator= (const Binary &)
 
 Binary (const Binary &)
 
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 (const std::string &name) const
 Check if a Symbol with the given name exists.
 
const Symbolget_symbol (const std::string &name) const
 Return the Symbol with the given name If the symbol does not exist, return a nullptr.
 
Symbolget_symbol (const std::string &name)
 
it_sections sections ()
 Return an iterator over the binary's sections (LIEF::Section)
 
it_const_sections sections () const
 
virtual void remove_section (const std::string &name, bool clear=false)=0
 Remove all the sections in the underlying binary.
 
it_relocations relocations ()
 Return an iterator over the binary relocation (LIEF::Relocation)
 
it_const_relocations relocations () const
 
virtual uint64_t entrypoint () const =0
 Binary's entrypoint (if any)
 
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.
 
virtual result< uint64_t > get_function_address (const std::string &func_name) const
 Return the address of the given function name.
 
void accept (Visitor &visitor) const override
 Method so that a visitor can visit us.
 
std::vector< uint64_t > xref (uint64_t address) const
 
virtual void patch_address (uint64_t address, const std::vector< uint8_t > &patch_value, VA_TYPES addr_type=VA_TYPES::AUTO)=0
 Patch the content at virtual address address with patch_value.
 
virtual void patch_address (uint64_t address, uint64_t patch_value, size_t size=sizeof(uint64_t), VA_TYPES addr_type=VA_TYPES::AUTO)=0
 Patch the address with the given value.
 
virtual span< const uint8_t > get_content_from_virtual_address (uint64_t virtual_address, uint64_t size, VA_TYPES addr_type=VA_TYPES::AUTO) const =0
 Return the content located at the given virtual address.
 
void original_size (uint64_t size)
 Change binary's original size.
 
virtual bool is_pie () const =0
 Check if the binary is position independent.
 
virtual bool has_nx () const =0
 Check if the binary uses NX protection.
 
virtual uint64_t imagebase () const =0
 Default image base address if the ASLR is not enabled.
 
virtual functions_t ctor_functions () const =0
 Constructor functions that are called prior any other functions.
 
virtual result< uint64_t > offset_to_virtual_address (uint64_t offset, uint64_t slide=0) const =0
 Convert the given offset into a virtual address.
 
virtual std::ostream & print (std::ostream &os) const
 
virtual void write (const std::string &name)=0
 Build & transform the Binary object representation into a real executable.
 
virtual void write (std::ostream &os)=0
 
- Public Member Functions inherited from LIEF::Object
 Object (const Object &other)
 
Objectoperator= (const Object &other)
 
template<class T >
output_t< T > as ()
 
template<class T >
output_const_t< T > as () const
 
virtual bool operator== (const Object &other) const
 
virtual bool operator!= (const Object &other) const
 

Detailed Description

Abstract binary that exposes an uniform API for the different executable file formats.

Member Enumeration Documentation

◆ VA_TYPES

enum class LIEF::Binary::VA_TYPES
strong

Type of a virtual address.

Enumerator
AUTO 

Try to guess if it's relative or not.

RVA 

Relative.

VA 

Absolute.

Member Function Documentation

◆ accept()

void LIEF::Binary::accept ( Visitor & visitor) const
overridevirtual

Method so that a visitor can visit us.

Implements LIEF::Object.

Reimplemented in LIEF::ELF::Binary, LIEF::MachO::Binary, LIEF::OAT::Binary, and LIEF::PE::Binary.

◆ ctor_functions()

virtual functions_t LIEF::Binary::ctor_functions ( ) const
pure virtual

Constructor functions that are called prior any other functions.

Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.

◆ entrypoint()

virtual uint64_t LIEF::Binary::entrypoint ( ) const
pure virtual

Binary's entrypoint (if any)

Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.

◆ get_content_from_virtual_address()

virtual span< const uint8_t > LIEF::Binary::get_content_from_virtual_address ( uint64_t virtual_address,
uint64_t size,
VA_TYPES addr_type = VA_TYPES::AUTO ) const
pure virtual

Return the content located at the given virtual address.

Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.

◆ get_function_address()

virtual result< uint64_t > LIEF::Binary::get_function_address ( const std::string & func_name) const
virtual

Return the address of the given function name.

Reimplemented in LIEF::ELF::Binary.

◆ has_nx()

virtual bool LIEF::Binary::has_nx ( ) const
pure virtual

Check if the binary uses NX protection.

Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.

◆ imagebase()

virtual uint64_t LIEF::Binary::imagebase ( ) const
pure virtual

Default image base address if the ASLR is not enabled.

Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.

◆ is_pie()

virtual bool LIEF::Binary::is_pie ( ) const
pure virtual

Check if the binary is position independent.

Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.

◆ offset_to_virtual_address()

virtual result< uint64_t > LIEF::Binary::offset_to_virtual_address ( uint64_t offset,
uint64_t slide = 0 ) const
pure virtual

Convert the given offset into a virtual address.

Parameters
[in]offsetThe offset to convert.
[in]slideIf not 0, it will replace the default base address (if any)

Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.

◆ original_size()

void LIEF::Binary::original_size ( uint64_t size)
inline

Change binary's original size.

Warning
This function should be used carefully as some optimizations can be performed with this value

◆ patch_address() [1/2]

virtual void LIEF::Binary::patch_address ( uint64_t address,
const std::vector< uint8_t > & patch_value,
VA_TYPES addr_type = VA_TYPES::AUTO )
pure virtual

Patch the content at virtual address address with patch_value.

Parameters
[in]addressAddress to patch
[in]patch_valuePatch to apply
[in]addr_typeSpecify if the address should be used as an absolute virtual address or a RVA

Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.

◆ patch_address() [2/2]

virtual void LIEF::Binary::patch_address ( uint64_t address,
uint64_t patch_value,
size_t size = sizeof(uint64_t),
VA_TYPES addr_type = VA_TYPES::AUTO )
pure virtual

Patch the address with the given value.

Parameters
[in]addressAddress to patch
[in]patch_valuePatch to apply
[in]sizeSize of the value in bytes (1, 2, ... 8)
[in]addr_typeSpecify if the address should be used as an absolute virtual address or an RVA

Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.

◆ remove_section()

virtual void LIEF::Binary::remove_section ( const std::string & name,
bool clear = false )
pure virtual

Remove all the sections in the underlying binary.

Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.

◆ write() [1/2]

virtual void LIEF::Binary::write ( const std::string & name)
pure virtual

Build & transform the Binary object representation into a real executable.

Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.

◆ write() [2/2]

virtual void LIEF::Binary::write ( std::ostream & os)
pure virtual

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