LIEF: Library to Instrument Executable Formats Version 0.15.1
|
Class which represents a MachO binary. More...
#include <Binary.hpp>
Classes | |
struct | KeyCmp |
struct | range_t |
Public Types | |
using | commands_t = std::vector<std::unique_ptr<LoadCommand>> |
Internal container for storing Mach-O LoadCommand. | |
using | it_commands = ref_iterator<commands_t&, LoadCommand*> |
Iterator that outputs LoadCommand&. | |
using | it_const_commands = const_ref_iterator<const commands_t&, LoadCommand*> |
Iterator that outputs const LoadCommand&. | |
using | symbols_t = std::vector<std::unique_ptr<Symbol>> |
Internal container for storing Mach-O Symbol. | |
using | it_symbols = ref_iterator<symbols_t&, Symbol*> |
Iterator that outputs Symbol&. | |
using | it_const_symbols = const_ref_iterator<const symbols_t&, const Symbol*> |
Iterator that outputs const Symbol&. | |
using | it_exported_symbols = filter_iterator<symbols_t&, Symbol*> |
Iterator that outputs exported Symbol&. | |
using | it_const_exported_symbols = const_filter_iterator<const symbols_t&, const Symbol*> |
Iterator that outputs exported const Symbol&. | |
using | it_imported_symbols = filter_iterator<symbols_t&, Symbol*> |
Iterator that outputs imported Symbol&. | |
using | it_const_imported_symbols = const_filter_iterator<const symbols_t&, const Symbol*> |
Iterator that outputs imported const Symbol&. | |
using | sections_cache_t = std::vector<Section*> |
Internal container for caching Mach-O Section. | |
using | it_sections = ref_iterator<sections_cache_t&> |
Iterator that outputs Section&. | |
using | it_const_sections = const_ref_iterator<const sections_cache_t&> |
Iterator that outputs const Section&. | |
using | segments_cache_t = std::vector<SegmentCommand*> |
Internal container for storing Mach-O SegmentCommand. | |
using | it_segments = ref_iterator<segments_cache_t&> |
Iterator that outputs SegmentCommand&. | |
using | it_const_segments = const_ref_iterator<const segments_cache_t&> |
Iterator that outputs const SegmentCommand&. | |
using | libraries_cache_t = std::vector<DylibCommand*> |
Internal container for storing Mach-O DylibCommand. | |
using | it_libraries = ref_iterator<libraries_cache_t&> |
Iterator that outputs DylibCommand&. | |
using | it_const_libraries = const_ref_iterator<const libraries_cache_t&> |
Iterator that outputs const DylibCommand&. | |
using | fileset_binaries_t = std::vector<std::unique_ptr<Binary>> |
Internal container for storing Mach-O Fileset Binary. | |
using | it_fileset_binaries = ref_iterator<fileset_binaries_t&, Binary*> |
Iterator that outputs Binary&. | |
using | it_const_fileset_binaries = const_ref_iterator<const fileset_binaries_t&, Binary*> |
Iterator that outputs const Binary&. | |
using | relocations_t = std::set<Relocation*, KeyCmp> |
Internal container that store all the relocations found in a Mach-O. The relocations are actually owned by Section & SegmentCommand and these references are used for convenience. | |
using | it_relocations = ref_iterator<relocations_t&, Relocation*> |
Iterator which outputs Relocation&. | |
using | it_const_relocations = const_ref_iterator<const relocations_t&, const Relocation*> |
Iterator which outputs const Relocation&. | |
using | it_rpaths = filter_iterator<commands_t&, RPathCommand*> |
Iterator which outputs RPathCommand&. | |
using | it_const_rpaths = const_filter_iterator<const commands_t&, const RPathCommand*> |
Iterator which outputs const RPathCommand&. | |
Public Types inherited from LIEF::Binary | |
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 (const Binary &)=delete | |
Binary & | operator= (const Binary &)=delete |
Header & | header () |
Return a reference to the MachO::Header. | |
const Header & | header () const |
it_commands | commands () |
Return an iterator over the MachO LoadCommand present in the binary. | |
it_const_commands | commands () const |
it_fileset_binaries | filesets () |
Return an iterator over the MachO::Binary associated with the LoadCommand::TYPE::FILESET_ENTRY commands. | |
it_const_fileset_binaries | filesets () const |
it_symbols | symbols () |
Return binary's symbols . | |
it_const_symbols | symbols () const |
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 Symbol from the given name. If the symbol does not exists, it returns a null pointer. | |
Symbol * | get_symbol (const std::string &name) |
it_exported_symbols | exported_symbols () |
Return binary's exported symbols (iterator over LIEF::MachO::Symbol) | |
it_const_exported_symbols | exported_symbols () const |
it_imported_symbols | imported_symbols () |
Return binary's imported symbols (iterator over LIEF::MachO::Symbol) | |
it_const_imported_symbols | imported_symbols () const |
it_libraries | libraries () |
Return binary imported libraries (MachO::DylibCommand) | |
it_const_libraries | libraries () const |
it_segments | segments () |
Return an iterator over the SegmentCommand. | |
it_const_segments | segments () const |
it_sections | sections () |
Return an iterator over the MachO::Section. | |
it_const_sections | sections () const |
it_relocations | relocations () |
Return an iterator over the MachO::Relocation. | |
it_const_relocations | relocations () const |
void | write (const std::string &filename) override |
Reconstruct the binary object and write the result in the given filename | |
void | write (std::ostream &os) override |
Reconstruct the binary object and write the result in the given os stream. | |
std::vector< uint8_t > | raw () |
Reconstruct the binary object and return its content as bytes. | |
bool | has (LoadCommand::TYPE type) const |
Check if the current binary has the given MachO::LoadCommand::TYPE. | |
const LoadCommand * | get (LoadCommand::TYPE type) const |
Return the LoadCommand associated with the given LoadCommand::TYPE or a nullptr if the command can't be found. | |
LoadCommand * | get (LoadCommand::TYPE type) |
LoadCommand * | add (const LoadCommand &command) |
Insert a new LoadCommand. | |
LoadCommand * | add (const LoadCommand &command, size_t index) |
Insert a new LoadCommand at the specified index | |
LoadCommand * | add (const DylibCommand &library) |
Insert the given DylibCommand. | |
LoadCommand * | add (const SegmentCommand &segment) |
Add a new LC_SEGMENT command from the given SegmentCommand. | |
LoadCommand * | add_library (const std::string &name) |
Insert a new shared library through a LC_LOAD_DYLIB command. | |
Section * | add_section (const Section §ion) |
Add a new MachO::Section in the __TEXT segment. | |
Section * | add_section (const SegmentCommand &segment, const Section §ion) |
Add a section in the given MachO::SegmentCommand. | |
void | remove_section (const std::string &name, bool clear=false) override |
Remove the section with the name provided in the first parameter. | |
void | remove_section (const std::string &segname, const std::string &secname, bool clear=false) |
Remove the section from the segment with the name given in the first parameter and with the section's name provided in the second parameter. | |
bool | remove (const LoadCommand &command) |
Remove the given LoadCommand. | |
bool | remove (LoadCommand::TYPE type) |
Remove all LoadCommand with the given type (MachO::LoadCommand::TYPE) | |
bool | remove_command (size_t index) |
Remove the Load Command at the provided index | |
bool | remove_signature () |
Remove the LC_SIGNATURE command. | |
bool | extend (const LoadCommand &command, uint64_t size) |
Extend the size of the given LoadCommand. | |
bool | extend_segment (const SegmentCommand &segment, size_t size) |
Extend the content of the given SegmentCommand. | |
bool | disable_pie () |
Remove the PIE flag. | |
uint64_t | imagebase () const override |
Return the binary's imagebase. 0 if not relevant. | |
uint64_t | virtual_size () const |
Size of the binary in memory when mapped by the loader (dyld ) | |
std::string | loader () const |
Return the binary's loader (e.g. /usr/lib/dyld ) or an empty string if the binary does not use a loader/linker. | |
bool | has_section (const std::string &name) const |
Check if a section with the given name exists. | |
Section * | get_section (const std::string &name) |
Return the section from the given name of a nullptr if the section can't be found. | |
const Section * | get_section (const std::string &name) const |
Return the section from the given name or a nullptr if the section can't be found. | |
Section * | get_section (const std::string &segname, const std::string &secname) |
Return the section from the segment with the name given in the first parameter and with the section's name provided in the second parameter. If the section cannot be found, it returns a nullptr. | |
const Section * | get_section (const std::string &segname, const std::string &secname) const |
bool | has_segment (const std::string &name) const |
Check if a segment with the given name exists. | |
const SegmentCommand * | get_segment (const std::string &name) const |
Return the segment from the given name. | |
SegmentCommand * | get_segment (const std::string &name) |
Return the segment from the given name. | |
bool | remove_symbol (const std::string &name) |
Remove the symbol with the given name. | |
bool | remove (const Symbol &sym) |
Remove the given symbol. | |
bool | can_remove (const Symbol &sym) const |
Check if the given symbol can be safely removed. | |
bool | can_remove_symbol (const std::string &name) const |
Check if the MachO::Symbol with the given name can be safely removed. | |
bool | unexport (const std::string &name) |
Remove the given MachO::Symbol with the given name from the export table. | |
bool | unexport (const Symbol &sym) |
Remove the given symbol from the export table. | |
Section * | section_from_offset (uint64_t offset) |
Return the MachO::Section that encompasses the provided offset. If a section can't be found, it returns a null pointer (nullptr ) | |
const Section * | section_from_offset (uint64_t offset) const |
Section * | section_from_virtual_address (uint64_t virtual_address) |
Return the MachO::Section that encompasses the provided virtual address. If a section can't be found, it returns a null pointer (nullptr ) | |
const Section * | section_from_virtual_address (uint64_t virtual_address) const |
result< uint64_t > | virtual_address_to_offset (uint64_t virtual_address) const |
Convert a virtual address to an offset in the file. | |
result< uint64_t > | offset_to_virtual_address (uint64_t offset, uint64_t slide=0) const override |
Convert the given offset into a virtual address. | |
SegmentCommand * | segment_from_offset (uint64_t offset) |
Return the binary's SegmentCommand that encompasses the provided offset. | |
const SegmentCommand * | segment_from_offset (uint64_t offset) const |
size_t | segment_index (const SegmentCommand &segment) const |
Return the index of the given SegmentCommand. | |
uint64_t | fat_offset () const |
Return binary's fat offset. 0 if not relevant. | |
SegmentCommand * | segment_from_virtual_address (uint64_t virtual_address) |
Return the binary's SegmentCommand which encompasses the given virtual address or a nullptr if not found. | |
const SegmentCommand * | segment_from_virtual_address (uint64_t virtual_address) const |
range_t | va_ranges () const |
Return the range of virtual addresses. | |
range_t | off_ranges () const |
Return the range of offsets. | |
bool | is_valid_addr (uint64_t address) const |
Check if the given address is encompassed in the binary's virtual addresses range. | |
void | accept (LIEF::Visitor &visitor) const override |
Method so that the visitor can visit us. | |
std::ostream & | print (std::ostream &os) const override |
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. | |
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. | |
uint64_t | entrypoint () const override |
The binary entrypoint. | |
bool | is_pie () const override |
Check if the binary is position independent. | |
bool | has_nx () const override |
Check if the binary uses NX protection. | |
bool | has_nx_stack () const |
Return True if the heap is flagged as non-executable. False otherwise. | |
bool | has_nx_heap () const |
Return True if the stack is flagged as non-executable. False otherwise. | |
bool | has_entrypoint () const |
true if the binary has an entrypoint. | |
bool | has_uuid () const |
true if the binary has a MachO::UUIDCommand command. | |
UUIDCommand * | uuid () |
Return the MachO::UUIDCommand if present, a nullptr otherwise. | |
const UUIDCommand * | uuid () const |
bool | has_main_command () const |
true if the binary has a MachO::MainCommand command. | |
MainCommand * | main_command () |
Return the MachO::MainCommand if present, a nullptr otherwise. | |
const MainCommand * | main_command () const |
bool | has_dylinker () const |
true if the binary has a MachO::DylinkerCommand. | |
DylinkerCommand * | dylinker () |
Return the MachO::DylinkerCommand if present, a nullptr otherwise. | |
const DylinkerCommand * | dylinker () const |
bool | has_dyld_info () const |
true if the binary has a MachO::DyldInfo command. | |
DyldInfo * | dyld_info () |
Return the MachO::Dyld command if present, a nullptr otherwise. | |
const DyldInfo * | dyld_info () const |
bool | has_function_starts () const |
true if the binary has a MachO::FunctionStarts command. | |
FunctionStarts * | function_starts () |
Return the MachO::FunctionStarts command if present, a nullptr otherwise. | |
const FunctionStarts * | function_starts () const |
bool | has_source_version () const |
true if the binary has a MachO::SourceVersion command. | |
SourceVersion * | source_version () |
Return the MachO::SourceVersion command if present, a nullptr otherwise. | |
const SourceVersion * | source_version () const |
bool | has_version_min () const |
true if the binary has a MachO::VersionMin command. | |
VersionMin * | version_min () |
Return the MachO::VersionMin command if present, a nullptr otherwise. | |
const VersionMin * | version_min () const |
bool | has_thread_command () const |
true if the binary has a MachO::ThreadCommand command. | |
ThreadCommand * | thread_command () |
Return the MachO::ThreadCommand command if present, a nullptr otherwise. | |
const ThreadCommand * | thread_command () const |
bool | has_rpath () const |
true if the binary has a MachO::RPathCommand command. | |
RPathCommand * | rpath () |
Return the MachO::RPathCommand command if present, a nullptr otherwise. | |
const RPathCommand * | rpath () const |
it_rpaths | rpaths () |
Iterator over all the MachO::RPathCommand commands. | |
it_const_rpaths | rpaths () const |
bool | has_symbol_command () const |
true if the binary has a MachO::SymbolCommand command. | |
SymbolCommand * | symbol_command () |
Return the MachO::SymbolCommand if present, a nullptr otherwise. | |
const SymbolCommand * | symbol_command () const |
bool | has_dynamic_symbol_command () const |
true if the binary has a MachO::DynamicSymbolCommand command. | |
DynamicSymbolCommand * | dynamic_symbol_command () |
Return the MachO::SymbolCommand if present, a nullptr otherwise. | |
const DynamicSymbolCommand * | dynamic_symbol_command () const |
bool | has_code_signature () const |
true if the binary is signed with LC_CODE_SIGNATURE command | |
CodeSignature * | code_signature () |
Return the MachO::CodeSignature if present, a nullptr otherwise. | |
const CodeSignature * | code_signature () const |
bool | has_code_signature_dir () const |
true if the binary is signed with the command DYLIB_CODE_SIGN_DRS | |
CodeSignatureDir * | code_signature_dir () |
Return the MachO::CodeSignatureDir if present, a nullptr otherwise. | |
const CodeSignatureDir * | code_signature_dir () const |
bool | has_data_in_code () const |
true if the binary has a MachO::DataInCode command. | |
DataInCode * | data_in_code () |
Return the MachO::DataInCode if present, a nullptr otherwise. | |
const DataInCode * | data_in_code () const |
bool | has_segment_split_info () const |
true if the binary has segment split info. | |
SegmentSplitInfo * | segment_split_info () |
Return the MachO::SegmentSplitInfo if present, a nullptr otherwise. | |
const SegmentSplitInfo * | segment_split_info () const |
bool | has_sub_framework () const |
true if the binary has a sub framework command. | |
bool | has_encryption_info () const |
true if the binary has Encryption Info. | |
EncryptionInfo * | encryption_info () |
Return the MachO::DyldEnvironment if present, a nullptr otherwise. | |
const EncryptionInfo * | encryption_info () const |
SubFramework * | sub_framework () |
Return the MachO::SubFramework if present, a nullptr otherwise. | |
const SubFramework * | sub_framework () const |
bool | has_dyld_environment () const |
true if the binary has Dyld envrionment variables. | |
DyldEnvironment * | dyld_environment () |
Return the MachO::DyldEnvironment if present, a nullptr otherwise. | |
const DyldEnvironment * | dyld_environment () const |
bool | has_build_version () const |
true if the binary has the BuildVersion command. | |
BuildVersion * | build_version () |
Return the MachO::BuildVersion if present, a nullptr otherwise. | |
const BuildVersion * | build_version () const |
bool | has_dyld_chained_fixups () const |
true if the binary has the command LC_DYLD_CHAINED_FIXUPS. | |
DyldChainedFixups * | dyld_chained_fixups () |
Return the MachO::DyldChainedFixups if present, a nullptr otherwise. | |
const DyldChainedFixups * | dyld_chained_fixups () const |
bool | has_dyld_exports_trie () const |
true if the binary has the command LC_DYLD_CHAINED_FIXUPS. | |
DyldExportsTrie * | dyld_exports_trie () |
Return the MachO::DyldChainedFixups if present, a nullptr otherwise. | |
const DyldExportsTrie * | dyld_exports_trie () const |
bool | has_two_level_hints () const |
true if the binary has the command LC_TWO_LEVEL_HINTS. | |
TwoLevelHints * | two_level_hints () |
Return the MachO::DyldChainedFixups if present, a nullptr otherwise. | |
const TwoLevelHints * | two_level_hints () const |
bool | has_linker_opt_hint () const |
true if the binary has the command LC_LINKER_OPTIMIZATION_HINT. | |
LinkerOptHint * | linker_opt_hint () |
Return the MachO::LinkerOptHint if present, a nullptr otherwise. | |
const LinkerOptHint * | linker_opt_hint () const |
ExportInfo * | add_exported_function (uint64_t address, const std::string &name) |
Add a symbol in the export trie of the current binary. | |
Symbol * | add_local_symbol (uint64_t address, const std::string &name) |
Add a symbol in LC_SYMTAB command of the current binary. | |
std::unique_ptr< objc::Metadata > | objc_metadata () const |
Return Objective-C metadata if present. | |
template<class T > | |
bool | has_command () const |
template<class T > | |
T * | command () |
template<class T > | |
const T * | command () const |
template<class T > | |
size_t | count_commands () const |
template<class CMD , class Func > | |
Binary & | for_commands (Func f) |
LoadCommand * | operator[] (LoadCommand::TYPE type) |
const LoadCommand * | operator[] (LoadCommand::TYPE type) const |
LIEF::Binary::functions_t | ctor_functions () const override |
Return the list of the MachO's constructors. | |
LIEF::Binary::functions_t | functions () const |
Return all the functions found in this MachO. | |
LIEF::Binary::functions_t | unwind_functions () const |
Return the functions found in the __unwind_info section. | |
bool | has_filesets () const |
true if the binary has a LoadCommand::TYPE::FILESET_ENTRY command | |
const std::string & | fileset_name () const |
Name associated with the LC_FILESET_ENTRY binary. | |
~Binary () override | |
ok_error_t | shift (size_t value) |
Shift the content located right after the Load commands table. This operation can be used to add a new command. | |
ok_error_t | shift_linkedit (size_t width) |
Shift the position on the __LINKEDIT data by width | |
uint64_t | memory_base_address () const |
If this Mach-O binary has been parsed from memory, it returns the in-memory base address of this binary. | |
bool | support_arm64_ptr_auth () const |
uint32_t | page_size () const |
span< const uint8_t > | overlay () 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 (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 |
it_relocations | relocations () |
Return an iterator over the binary relocation (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. | |
virtual result< uint64_t > | get_function_address (const std::string &func_name) const |
Return the address of the given function name. | |
std::vector< uint64_t > | xref (uint64_t address) const |
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. | |
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 () |
Static Public Member Functions | |
static bool | is_exported (const Symbol &symbol) |
Check if the given symbol is exported. | |
static bool | is_imported (const Symbol &symbol) |
Check if the given symbol is an imported one. | |
static bool | classof (const LIEF::Binary *bin) |
Class which represents a MachO binary.
using LIEF::MachO::Binary::commands_t = std::vector<std::unique_ptr<LoadCommand>> |
Internal container for storing Mach-O LoadCommand.
using LIEF::MachO::Binary::fileset_binaries_t = std::vector<std::unique_ptr<Binary>> |
Internal container for storing Mach-O Fileset Binary.
Iterator that outputs LoadCommand&.
using LIEF::MachO::Binary::it_const_commands = const_ref_iterator<const commands_t&, LoadCommand*> |
Iterator that outputs const LoadCommand&.
using LIEF::MachO::Binary::it_const_exported_symbols = const_filter_iterator<const symbols_t&, const Symbol*> |
Iterator that outputs exported const Symbol&.
using LIEF::MachO::Binary::it_const_fileset_binaries = const_ref_iterator<const fileset_binaries_t&, Binary*> |
Iterator that outputs const Binary&.
using LIEF::MachO::Binary::it_const_imported_symbols = const_filter_iterator<const symbols_t&, const Symbol*> |
Iterator that outputs imported const Symbol&.
Iterator that outputs const DylibCommand&.
using LIEF::MachO::Binary::it_const_relocations = const_ref_iterator<const relocations_t&, const Relocation*> |
Iterator which outputs const Relocation&.
using LIEF::MachO::Binary::it_const_rpaths = const_filter_iterator<const commands_t&, const RPathCommand*> |
Iterator which outputs const RPathCommand&.
using LIEF::MachO::Binary::it_const_sections = const_ref_iterator<const sections_cache_t&> |
Iterator that outputs const Section&.
using LIEF::MachO::Binary::it_const_segments = const_ref_iterator<const segments_cache_t&> |
Iterator that outputs const SegmentCommand&.
using LIEF::MachO::Binary::it_const_symbols = const_ref_iterator<const symbols_t&, const Symbol*> |
Iterator that outputs const Symbol&.
Iterator that outputs exported Symbol&.
Iterator that outputs Binary&.
Iterator that outputs imported Symbol&.
Iterator that outputs DylibCommand&.
Iterator which outputs Relocation&.
Iterator which outputs RPathCommand&.
Iterator that outputs Section&.
Iterator that outputs SegmentCommand&.
using LIEF::MachO::Binary::it_symbols = ref_iterator<symbols_t&, Symbol*> |
Iterator that outputs Symbol&.
using LIEF::MachO::Binary::libraries_cache_t = std::vector<DylibCommand*> |
Internal container for storing Mach-O DylibCommand.
using LIEF::MachO::Binary::relocations_t = std::set<Relocation*, KeyCmp> |
Internal container that store all the relocations found in a Mach-O. The relocations are actually owned by Section & SegmentCommand and these references are used for convenience.
using LIEF::MachO::Binary::sections_cache_t = std::vector<Section*> |
Internal container for caching Mach-O Section.
using LIEF::MachO::Binary::segments_cache_t = std::vector<SegmentCommand*> |
Internal container for storing Mach-O SegmentCommand.
using LIEF::MachO::Binary::symbols_t = std::vector<std::unique_ptr<Symbol>> |
Internal container for storing Mach-O Symbol.
|
delete |
|
override |
|
overridevirtual |
Method so that the visitor
can visit us.
Reimplemented from LIEF::Binary.
LoadCommand * LIEF::MachO::Binary::add | ( | const DylibCommand & | library | ) |
Insert the given DylibCommand.
LoadCommand * LIEF::MachO::Binary::add | ( | const LoadCommand & | command | ) |
Insert a new LoadCommand.
LoadCommand * LIEF::MachO::Binary::add | ( | const LoadCommand & | command, |
size_t | index ) |
Insert a new LoadCommand at the specified index
LoadCommand * LIEF::MachO::Binary::add | ( | const SegmentCommand & | segment | ) |
Add a new LC_SEGMENT command from the given SegmentCommand.
ExportInfo * LIEF::MachO::Binary::add_exported_function | ( | uint64_t | address, |
const std::string & | name ) |
Add a symbol in the export trie of the current binary.
LoadCommand * LIEF::MachO::Binary::add_library | ( | const std::string & | name | ) |
Insert a new shared library through a LC_LOAD_DYLIB
command.
Symbol * LIEF::MachO::Binary::add_local_symbol | ( | uint64_t | address, |
const std::string & | name ) |
Add a symbol in LC_SYMTAB command of the current binary.
Add a new MachO::Section in the __TEXT segment.
Section * LIEF::MachO::Binary::add_section | ( | const SegmentCommand & | segment, |
const Section & | section ) |
Add a section in the given MachO::SegmentCommand.
BuildVersion * LIEF::MachO::Binary::build_version | ( | ) |
Return the MachO::BuildVersion if present, a nullptr otherwise.
const BuildVersion * LIEF::MachO::Binary::build_version | ( | ) | const |
bool LIEF::MachO::Binary::can_remove | ( | const Symbol & | sym | ) | const |
Check if the given symbol can be safely removed.
bool LIEF::MachO::Binary::can_remove_symbol | ( | const std::string & | name | ) | const |
Check if the MachO::Symbol with the given name can be safely removed.
|
inlinestatic |
References LIEF::Binary::format().
CodeSignature * LIEF::MachO::Binary::code_signature | ( | ) |
Return the MachO::CodeSignature if present, a nullptr otherwise.
const CodeSignature * LIEF::MachO::Binary::code_signature | ( | ) | const |
CodeSignatureDir * LIEF::MachO::Binary::code_signature_dir | ( | ) |
Return the MachO::CodeSignatureDir if present, a nullptr otherwise.
const CodeSignatureDir * LIEF::MachO::Binary::code_signature_dir | ( | ) | const |
T * LIEF::MachO::Binary::command | ( | ) |
const T * LIEF::MachO::Binary::command | ( | ) | const |
|
inline |
Return an iterator over the MachO LoadCommand present in the binary.
|
inline |
size_t LIEF::MachO::Binary::count_commands | ( | ) | const |
|
overridevirtual |
Return the list of the MachO's constructors.
Implements LIEF::Binary.
DataInCode * LIEF::MachO::Binary::data_in_code | ( | ) |
Return the MachO::DataInCode if present, a nullptr otherwise.
const DataInCode * LIEF::MachO::Binary::data_in_code | ( | ) | const |
bool LIEF::MachO::Binary::disable_pie | ( | ) |
Remove the PIE
flag.
DyldChainedFixups * LIEF::MachO::Binary::dyld_chained_fixups | ( | ) |
Return the MachO::DyldChainedFixups if present, a nullptr otherwise.
const DyldChainedFixups * LIEF::MachO::Binary::dyld_chained_fixups | ( | ) | const |
DyldEnvironment * LIEF::MachO::Binary::dyld_environment | ( | ) |
Return the MachO::DyldEnvironment if present, a nullptr otherwise.
const DyldEnvironment * LIEF::MachO::Binary::dyld_environment | ( | ) | const |
DyldExportsTrie * LIEF::MachO::Binary::dyld_exports_trie | ( | ) |
Return the MachO::DyldChainedFixups if present, a nullptr otherwise.
const DyldExportsTrie * LIEF::MachO::Binary::dyld_exports_trie | ( | ) | const |
DyldInfo * LIEF::MachO::Binary::dyld_info | ( | ) |
Return the MachO::Dyld command if present, a nullptr otherwise.
const DyldInfo * LIEF::MachO::Binary::dyld_info | ( | ) | const |
DylinkerCommand * LIEF::MachO::Binary::dylinker | ( | ) |
Return the MachO::DylinkerCommand if present, a nullptr otherwise.
const DylinkerCommand * LIEF::MachO::Binary::dylinker | ( | ) | const |
DynamicSymbolCommand * LIEF::MachO::Binary::dynamic_symbol_command | ( | ) |
Return the MachO::SymbolCommand if present, a nullptr otherwise.
const DynamicSymbolCommand * LIEF::MachO::Binary::dynamic_symbol_command | ( | ) | const |
EncryptionInfo * LIEF::MachO::Binary::encryption_info | ( | ) |
Return the MachO::DyldEnvironment if present, a nullptr otherwise.
const EncryptionInfo * LIEF::MachO::Binary::encryption_info | ( | ) | const |
|
overridevirtual |
The binary entrypoint.
Implements LIEF::Binary.
|
inline |
Return binary's exported symbols (iterator over LIEF::MachO::Symbol)
|
inline |
bool LIEF::MachO::Binary::extend | ( | const LoadCommand & | command, |
uint64_t | size ) |
Extend the size of the given LoadCommand.
bool LIEF::MachO::Binary::extend_segment | ( | const SegmentCommand & | segment, |
size_t | size ) |
Extend the content of the given SegmentCommand.
|
inline |
Return binary's fat offset. 0
if not relevant.
|
inline |
Name associated with the LC_FILESET_ENTRY binary.
|
inline |
Return an iterator over the MachO::Binary associated with the LoadCommand::TYPE::FILESET_ENTRY commands.
|
inline |
Binary & LIEF::MachO::Binary::for_commands | ( | Func | f | ) |
FunctionStarts * LIEF::MachO::Binary::function_starts | ( | ) |
Return the MachO::FunctionStarts command if present, a nullptr otherwise.
const FunctionStarts * LIEF::MachO::Binary::function_starts | ( | ) | const |
LIEF::Binary::functions_t LIEF::MachO::Binary::functions | ( | ) | const |
Return all the functions found in this MachO.
LoadCommand * LIEF::MachO::Binary::get | ( | LoadCommand::TYPE | type | ) |
const LoadCommand * LIEF::MachO::Binary::get | ( | LoadCommand::TYPE | type | ) | const |
Return the LoadCommand associated with the given LoadCommand::TYPE or a nullptr if the command can't be found.
|
overridevirtual |
Return the content located at virtual address.
Implements LIEF::Binary.
Section * LIEF::MachO::Binary::get_section | ( | const std::string & | name | ) |
Return the section from the given name of a nullptr if the section can't be found.
const Section * LIEF::MachO::Binary::get_section | ( | const std::string & | name | ) | const |
Return the section from the given name or a nullptr if the section can't be found.
Section * LIEF::MachO::Binary::get_section | ( | const std::string & | segname, |
const std::string & | secname ) |
Return the section from the segment with the name given in the first parameter and with the section's name provided in the second parameter. If the section cannot be found, it returns a nullptr.
const Section * LIEF::MachO::Binary::get_section | ( | const std::string & | segname, |
const std::string & | secname ) const |
SegmentCommand * LIEF::MachO::Binary::get_segment | ( | const std::string & | name | ) |
Return the segment from the given name.
const SegmentCommand * LIEF::MachO::Binary::get_segment | ( | const std::string & | name | ) | const |
Return the segment from the given name.
Symbol * LIEF::MachO::Binary::get_symbol | ( | const std::string & | name | ) |
const Symbol * LIEF::MachO::Binary::get_symbol | ( | const std::string & | name | ) | const |
Return Symbol from the given name. If the symbol does not exists, it returns a null pointer.
bool LIEF::MachO::Binary::has | ( | LoadCommand::TYPE | type | ) | const |
Check if the current binary has the given MachO::LoadCommand::TYPE.
bool LIEF::MachO::Binary::has_build_version | ( | ) | const |
true
if the binary has the BuildVersion command.
bool LIEF::MachO::Binary::has_code_signature | ( | ) | const |
true
if the binary is signed with LC_CODE_SIGNATURE
command
bool LIEF::MachO::Binary::has_code_signature_dir | ( | ) | const |
true
if the binary is signed with the command DYLIB_CODE_SIGN_DRS
bool LIEF::MachO::Binary::has_command | ( | ) | const |
bool LIEF::MachO::Binary::has_data_in_code | ( | ) | const |
true
if the binary has a MachO::DataInCode command.
bool LIEF::MachO::Binary::has_dyld_chained_fixups | ( | ) | const |
true
if the binary has the command LC_DYLD_CHAINED_FIXUPS.
bool LIEF::MachO::Binary::has_dyld_environment | ( | ) | const |
true
if the binary has Dyld envrionment variables.
bool LIEF::MachO::Binary::has_dyld_exports_trie | ( | ) | const |
true
if the binary has the command LC_DYLD_CHAINED_FIXUPS.
bool LIEF::MachO::Binary::has_dyld_info | ( | ) | const |
true
if the binary has a MachO::DyldInfo command.
bool LIEF::MachO::Binary::has_dylinker | ( | ) | const |
true
if the binary has a MachO::DylinkerCommand.
bool LIEF::MachO::Binary::has_dynamic_symbol_command | ( | ) | const |
true
if the binary has a MachO::DynamicSymbolCommand command.
bool LIEF::MachO::Binary::has_encryption_info | ( | ) | const |
true
if the binary has Encryption Info.
|
inline |
true
if the binary has an entrypoint.
Basically for libraries it will return false
bool LIEF::MachO::Binary::has_filesets | ( | ) | const |
true
if the binary has a LoadCommand::TYPE::FILESET_ENTRY command
bool LIEF::MachO::Binary::has_function_starts | ( | ) | const |
true
if the binary has a MachO::FunctionStarts command.
bool LIEF::MachO::Binary::has_linker_opt_hint | ( | ) | const |
true
if the binary has the command LC_LINKER_OPTIMIZATION_HINT.
bool LIEF::MachO::Binary::has_main_command | ( | ) | const |
true
if the binary has a MachO::MainCommand command.
|
inlineoverridevirtual |
Check if the binary uses NX
protection.
Implements LIEF::Binary.
|
inline |
Return True if the stack is flagged as non-executable. False otherwise.
|
inline |
Return True if the heap is flagged as non-executable. False otherwise.
bool LIEF::MachO::Binary::has_rpath | ( | ) | const |
true
if the binary has a MachO::RPathCommand command.
|
inline |
Check if a section with the given name exists.
|
inline |
Check if a segment with the given name exists.
bool LIEF::MachO::Binary::has_segment_split_info | ( | ) | const |
true
if the binary has segment split info.
bool LIEF::MachO::Binary::has_source_version | ( | ) | const |
true
if the binary has a MachO::SourceVersion command.
bool LIEF::MachO::Binary::has_sub_framework | ( | ) | const |
true
if the binary has a sub framework command.
|
inline |
Check if a symbol with the given name exists.
bool LIEF::MachO::Binary::has_symbol_command | ( | ) | const |
true
if the binary has a MachO::SymbolCommand command.
bool LIEF::MachO::Binary::has_thread_command | ( | ) | const |
true
if the binary has a MachO::ThreadCommand command.
bool LIEF::MachO::Binary::has_two_level_hints | ( | ) | const |
true
if the binary has the command LC_TWO_LEVEL_HINTS.
bool LIEF::MachO::Binary::has_uuid | ( | ) | const |
true
if the binary has a MachO::UUIDCommand command.
bool LIEF::MachO::Binary::has_version_min | ( | ) | const |
true
if the binary has a MachO::VersionMin command.
|
inline |
Return a reference to the MachO::Header.
|
inline |
|
overridevirtual |
Return the binary's imagebase. 0
if not relevant.
Implements LIEF::Binary.
|
inline |
Return binary's imported symbols (iterator over LIEF::MachO::Symbol)
|
inline |
|
static |
Check if the given symbol is exported.
|
static |
Check if the given symbol is an imported one.
|
inlineoverridevirtual |
Check if the binary is position independent.
Implements LIEF::Binary.
bool LIEF::MachO::Binary::is_valid_addr | ( | uint64_t | address | ) | const |
Check if the given address is encompassed in the binary's virtual addresses range.
|
inline |
Return binary imported libraries (MachO::DylibCommand)
|
inline |
LinkerOptHint * LIEF::MachO::Binary::linker_opt_hint | ( | ) |
Return the MachO::LinkerOptHint if present, a nullptr otherwise.
const LinkerOptHint * LIEF::MachO::Binary::linker_opt_hint | ( | ) | const |
std::string LIEF::MachO::Binary::loader | ( | ) | const |
Return the binary's loader (e.g. /usr/lib/dyld
) or an empty string if the binary does not use a loader/linker.
MainCommand * LIEF::MachO::Binary::main_command | ( | ) |
Return the MachO::MainCommand if present, a nullptr otherwise.
const MainCommand * LIEF::MachO::Binary::main_command | ( | ) | const |
|
inline |
If this Mach-O binary has been parsed from memory, it returns the in-memory base address of this binary.
Otherwise, it returns 0
std::unique_ptr< objc::Metadata > LIEF::MachO::Binary::objc_metadata | ( | ) | const |
Return Objective-C metadata if present.
range_t LIEF::MachO::Binary::off_ranges | ( | ) | const |
Return the range of offsets.
|
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 |
|
inline |
|
inline |
uint32_t LIEF::MachO::Binary::page_size | ( | ) | const |
|
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.
|
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.
|
overridevirtual |
Reimplemented from LIEF::Binary.
std::vector< uint8_t > LIEF::MachO::Binary::raw | ( | ) |
Reconstruct the binary object and return its content as bytes.
it_relocations LIEF::MachO::Binary::relocations | ( | ) |
Return an iterator over the MachO::Relocation.
it_const_relocations LIEF::MachO::Binary::relocations | ( | ) | const |
bool LIEF::MachO::Binary::remove | ( | const LoadCommand & | command | ) |
Remove the given LoadCommand.
bool LIEF::MachO::Binary::remove | ( | const Symbol & | sym | ) |
Remove the given symbol.
bool LIEF::MachO::Binary::remove | ( | LoadCommand::TYPE | type | ) |
Remove all LoadCommand with the given type (MachO::LoadCommand::TYPE)
bool LIEF::MachO::Binary::remove_command | ( | size_t | index | ) |
Remove the Load Command at the provided index
|
overridevirtual |
Remove the section with the name provided in the first parameter.
name | Name of the MachO::Section to remove |
clear | If true clear the content of the section before removing |
Implements LIEF::Binary.
void LIEF::MachO::Binary::remove_section | ( | const std::string & | segname, |
const std::string & | secname, | ||
bool | clear = false ) |
Remove the section from the segment with the name given in the first parameter and with the section's name provided in the second parameter.
segname | Name of the MachO::Segment |
secname | Name of the MachO::Section to remove |
clear | If true clear the content of the section before removing |
bool LIEF::MachO::Binary::remove_signature | ( | ) |
Remove the LC_SIGNATURE command.
bool LIEF::MachO::Binary::remove_symbol | ( | const std::string & | name | ) |
Remove the symbol with the given name.
RPathCommand * LIEF::MachO::Binary::rpath | ( | ) |
Return the MachO::RPathCommand command if present, a nullptr otherwise.
const RPathCommand * LIEF::MachO::Binary::rpath | ( | ) | const |
it_rpaths LIEF::MachO::Binary::rpaths | ( | ) |
Iterator over all the MachO::RPathCommand commands.
it_const_rpaths LIEF::MachO::Binary::rpaths | ( | ) | const |
Section * LIEF::MachO::Binary::section_from_offset | ( | uint64_t | offset | ) |
Return the MachO::Section that encompasses the provided offset. If a section can't be found, it returns a null pointer (nullptr
)
const Section * LIEF::MachO::Binary::section_from_offset | ( | uint64_t | offset | ) | const |
Section * LIEF::MachO::Binary::section_from_virtual_address | ( | uint64_t | virtual_address | ) |
Return the MachO::Section that encompasses the provided virtual address. If a section can't be found, it returns a null pointer (nullptr
)
const Section * LIEF::MachO::Binary::section_from_virtual_address | ( | uint64_t | virtual_address | ) | const |
|
inline |
Return an iterator over the MachO::Section.
|
inline |
SegmentCommand * LIEF::MachO::Binary::segment_from_offset | ( | uint64_t | offset | ) |
Return the binary's SegmentCommand that encompasses the provided offset.
If a SegmentCommand can't be found it returns a null pointer (nullptr
).
const SegmentCommand * LIEF::MachO::Binary::segment_from_offset | ( | uint64_t | offset | ) | const |
SegmentCommand * LIEF::MachO::Binary::segment_from_virtual_address | ( | uint64_t | virtual_address | ) |
Return the binary's SegmentCommand which encompasses the given virtual address or a nullptr if not found.
const SegmentCommand * LIEF::MachO::Binary::segment_from_virtual_address | ( | uint64_t | virtual_address | ) | const |
size_t LIEF::MachO::Binary::segment_index | ( | const SegmentCommand & | segment | ) | const |
Return the index of the given SegmentCommand.
SegmentSplitInfo * LIEF::MachO::Binary::segment_split_info | ( | ) |
Return the MachO::SegmentSplitInfo if present, a nullptr otherwise.
const SegmentSplitInfo * LIEF::MachO::Binary::segment_split_info | ( | ) | const |
|
inline |
Return an iterator over the SegmentCommand.
|
inline |
ok_error_t LIEF::MachO::Binary::shift | ( | size_t | value | ) |
Shift the content located right after the Load commands table. This operation can be used to add a new command.
ok_error_t LIEF::MachO::Binary::shift_linkedit | ( | size_t | width | ) |
Shift the position on the __LINKEDIT data by width
SourceVersion * LIEF::MachO::Binary::source_version | ( | ) |
Return the MachO::SourceVersion command if present, a nullptr otherwise.
const SourceVersion * LIEF::MachO::Binary::source_version | ( | ) | const |
SubFramework * LIEF::MachO::Binary::sub_framework | ( | ) |
Return the MachO::SubFramework if present, a nullptr otherwise.
const SubFramework * LIEF::MachO::Binary::sub_framework | ( | ) | const |
|
inline |
SymbolCommand * LIEF::MachO::Binary::symbol_command | ( | ) |
Return the MachO::SymbolCommand if present, a nullptr otherwise.
const SymbolCommand * LIEF::MachO::Binary::symbol_command | ( | ) | const |
|
inline |
Return binary's symbols .
|
inline |
ThreadCommand * LIEF::MachO::Binary::thread_command | ( | ) |
Return the MachO::ThreadCommand command if present, a nullptr otherwise.
const ThreadCommand * LIEF::MachO::Binary::thread_command | ( | ) | const |
TwoLevelHints * LIEF::MachO::Binary::two_level_hints | ( | ) |
Return the MachO::DyldChainedFixups if present, a nullptr otherwise.
const TwoLevelHints * LIEF::MachO::Binary::two_level_hints | ( | ) | const |
bool LIEF::MachO::Binary::unexport | ( | const std::string & | name | ) |
Remove the given MachO::Symbol with the given name from the export table.
bool LIEF::MachO::Binary::unexport | ( | const Symbol & | sym | ) |
Remove the given symbol from the export table.
LIEF::Binary::functions_t LIEF::MachO::Binary::unwind_functions | ( | ) | const |
Return the functions found in the __unwind_info
section.
UUIDCommand * LIEF::MachO::Binary::uuid | ( | ) |
Return the MachO::UUIDCommand if present, a nullptr otherwise.
const UUIDCommand * LIEF::MachO::Binary::uuid | ( | ) | const |
range_t LIEF::MachO::Binary::va_ranges | ( | ) | const |
Return the range of virtual addresses.
VersionMin * LIEF::MachO::Binary::version_min | ( | ) |
Return the MachO::VersionMin command if present, a nullptr otherwise.
const VersionMin * LIEF::MachO::Binary::version_min | ( | ) | const |
result< uint64_t > LIEF::MachO::Binary::virtual_address_to_offset | ( | uint64_t | virtual_address | ) | const |
Convert a virtual address to an offset in the file.
uint64_t LIEF::MachO::Binary::virtual_size | ( | ) | const |
Size of the binary in memory when mapped by the loader (dyld
)
|
overridevirtual |
Reconstruct the binary object and write the result in the given filename
filename | Path to write the reconstructed binary |
Implements LIEF::Binary.
|
overridevirtual |
Reconstruct the binary object and write the result in the given os
stream.
os | Output stream to write the reconstructed binary |
Implements LIEF::Binary.