LIEF: Library to Instrument Executable Formats Version 0.17.0
|
Abstract binary that exposes an uniform API for the different executable file formats. More...
#include <Binary.hpp>
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&. | |
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 () | |
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 (const std::string &name) const |
Check if a Symbol with the given name exists. | |
const Symbol * | get_symbol (const std::string &name) const |
Return the Symbol with the given name If the symbol does not exist, return a nullptr. | |
Symbol * | get_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. | |
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. | |
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 |
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 a the given virtual address and with the given size. | |
instructions_it | disassemble (uint64_t address) const |
Disassemble code starting a the given virtual address. | |
instructions_it | disassemble (const std::string &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, const std::string &Asm) |
Assemble and patch the provided assembly code at the specified address. | |
Public Member Functions inherited from LIEF::Object | |
Object () | |
Object (const Object &other) | |
Object & | operator= (const Object &other) |
template<class T > | |
output_t< T > | as () |
template<class T > | |
output_const_t< T > | as () const |
virtual bool | operator== (const Object &other) const |
virtual bool | operator!= (const Object &other) const |
virtual | ~Object () |
Abstract binary that exposes an uniform API for the different executable file formats.
using LIEF::Binary::functions_t = std::vector<Function> |
Instruction iterator.
Iterator that outputs const LIEF::Relocation&.
Iterator that outputs const LIEF::Section&.
Iterator that outputs const LIEF::Symbol&.
Iterator that outputs LIEF::Relocation&.
Iterator that outputs LIEF::Section&.
Iterator that outputs LIEF::Symbol&.
using LIEF::Binary::relocations_t = std::vector<Relocation*> |
Internal container.
using LIEF::Binary::sections_t = std::vector<Section*> |
Internal container.
using LIEF::Binary::symbols_t = std::vector<Symbol*> |
Internal container.
|
strong |
LIEF::Binary::Binary | ( | ) |
LIEF::Binary::Binary | ( | FORMATS | fmt | ) |
|
override |
|
delete |
|
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.
std::vector< uint8_t > LIEF::Binary::assemble | ( | uint64_t | address, |
const std::string & | Asm ) |
Assemble and patch the provided assembly code at the specified address.
The function returns the generated assembly bytes
|
pure virtual |
Constructor functions that are called prior any other functions.
Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.
DebugInfo * LIEF::Binary::debug_info | ( | ) | const |
Return the debug info if present. It can be either a LIEF::dwarf::DebugInfo or a LIEF::pdb::DebugInfo.
For ELF and Mach-O binaries, it returns the given DebugInfo object only if the binary embeds the DWARF debug info in the binary itself.
For PE file, this function tries to find the external PDB using the LIEF::PE::CodeViewPDB::filename() output (if present). One can also use LIEF::pdb::load() or LIEF::pdb::DebugInfo::from_file() to get PDB debug info.
instructions_it LIEF::Binary::disassemble | ( | const std::string & | function | ) | const |
Disassemble code for the given symbol name.
|
inline |
Disassemble code provided by the given vector of bytes at the specified address
parameter.
instructions_it LIEF::Binary::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.
|
inline |
|
inline |
instructions_it LIEF::Binary::disassemble | ( | uint64_t | address | ) | const |
Disassemble code starting a the given virtual address.
instructions_it LIEF::Binary::disassemble | ( | uint64_t | address, |
size_t | size ) const |
Disassemble code starting a the given virtual address and with the given size.
|
pure virtual |
Binary's entrypoint (if any)
Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.
|
inline |
Return the functions exported by the binary.
|
inline |
Executable format (ELF, PE, Mach-O) of the underlying binary.
Referenced by LIEF::ELF::Binary::classof(), LIEF::MachO::Binary::classof(), LIEF::OAT::Binary::classof(), and LIEF::PE::Binary::classof().
|
pure virtual |
Return the content located at the given virtual address.
Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.
|
virtual |
Return the address of the given function name.
Reimplemented in LIEF::ELF::Binary.
|
inline |
Get the integer value at the given virtual address.
References make_error_code(), and read_error.
|
inline |
const Symbol * LIEF::Binary::get_symbol | ( | const std::string & | name | ) | const |
Return the Symbol with the given name If the symbol does not exist, return a nullptr.
|
pure virtual |
Check if the binary uses NX
protection.
Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.
|
inline |
Check if a Symbol with the given name exists.
|
inline |
Return the abstract header of the binary.
|
pure virtual |
Default image base address if the ASLR is not enabled.
Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.
|
inline |
Return functions imported by the binary.
|
inline |
Return libraries which are imported by the binary.
|
pure virtual |
Check if the binary is position independent.
Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.
|
pure virtual |
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) |
Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.
|
inline |
Binary's original size.
|
inline |
Change binary's original size.
|
pure virtual |
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 a RVA |
Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.
|
pure virtual |
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 |
Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.
|
inlinevirtual |
Reimplemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.
Referenced by operator<<.
|
inline |
Return an iterator over the binary relocation (LIEF::Relocation)
|
inline |
|
pure virtual |
Remove all the sections in the underlying binary.
Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.
|
inline |
Return an iterator over the binary's sections (LIEF::Section)
|
inline |
|
inline |
Return an iterator over the abstracted symbols in which the elements can be modified.
|
inline |
Return an iterator over the abstracted symbols in which the elements can't be modified.
|
pure virtual |
Build & transform the Binary object representation into a real executable.
Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.
|
pure virtual |
Implemented in LIEF::ELF::Binary, LIEF::MachO::Binary, and LIEF::PE::Binary.
std::vector< uint64_t > LIEF::Binary::xref | ( | uint64_t | address | ) | const |