LIEF: Library to Instrument Executable Formats Version 0.17.0
|
Class which represents a MachO binary. More...
#include <Binary.hpp>
Classes | |
struct | range_t |
struct | KeyCmp |
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&. | |
using | it_sub_clients = filter_iterator<commands_t&, SubClient*> |
Iterator which outputs SubClient&. | |
using | it_const_sub_clients = const_filter_iterator<const commands_t&, const SubClient*> |
Iterator which outputs const SubClient&. | |
using | it_bindings = iterator_range<BindingInfoIterator> |
using | stub_iterator = iterator_range<Stub::Iterator> |
Iterator type for Symbol's stub. | |
using | it_notes = filter_iterator<commands_t&, NoteCommand*> |
Iterator which outputs NoteCommand&. | |
using | it_const_notes = const_filter_iterator<const commands_t&, const NoteCommand*> |
Iterator which outputs const NoteCommand&. | |
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&. | |
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 (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) |
Reconstruct the binary object and write the result in the given filename. | |
void | write (const std::string &filename, Builder::config_t config) |
Reconstruct the binary object and write the result in the given filename. | |
void | write (std::ostream &os) |
Reconstruct the binary object and write the result in the given os stream. | |
void | write (std::ostream &os, Builder::config_t config) |
Reconstruct the binary object and write the result in the given os stream for the given configuration. | |
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 (std::unique_ptr< LoadCommand > command) |
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. | |
const DylibCommand * | find_library (const std::string &name) const |
Try to find the library with the given library name. | |
DylibCommand * | find_library (const std::string &name) |
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 | extend_section (Section §ion, size_t size) |
Extend the content of the given Section. | |
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 stack is flagged as non-executable. False otherwise. | |
bool | has_nx_heap () const |
Return True if the heap 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_routine_command () const |
true if the binary has a MachO::Routine command. | |
Routine * | routine_command () |
Return the MachO::Routine command if present, a nullptr otherwise. | |
const Routine * | routine_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 |
it_sub_clients | subclients () |
Iterator over all the MachO::SubClient commands. | |
it_const_sub_clients | subclients () const |
bool | has_subclients () 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 |
BuildVersion::PLATFORMS | platform () const |
Return the platform for which this Mach-O has been compiled for. | |
bool | is_ios () const |
True if this binary targets iOS. | |
bool | is_macos () const |
True if this binary targets macOS. | |
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. | |
stub_iterator | symbol_stubs () const |
Return an iterator over the symbol stubs. | |
bool | has_atom_info () const |
true if the binary has the command LC_ATOM_INFO. | |
AtomInfo * | atom_info () |
Return the MachO::AtomInfo if present, a nullptr otherwise. | |
const AtomInfo * | atom_info () const |
it_notes | notes () |
Iterator over the different LC_NOTE commands. | |
it_const_notes | notes () const |
bool | has_notes () const |
True if the binary contains LC_NOTE command(s). | |
bool | has_function_variants () const |
true if the binary has the command LC_FUNCTION_VARIANTS. | |
FunctionVariants * | function_variants () |
Return the FunctionVariants if present, a nullptr otherwise. | |
const FunctionVariants * | function_variants () const |
bool | has_function_variant_fixups () const |
true if the binary has the command LC_FUNCTION_VARIANT_FIXUPS. | |
FunctionVariantFixups * | function_variant_fixups () |
Return the FunctionVariantFixups if present, a nullptr otherwise. | |
const FunctionVariantFixups * | function_variant_fixups () const |
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. | |
Symbol & | add (const Symbol &symbol) |
Add a symbol to this 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 |
Check if the binary is supporting ARM64 pointer authentication (arm64e). | |
it_bindings | bindings () const |
Return an iterator over the binding info which can come from either DyldInfo or DyldChainedFixups commands. | |
span< const uint8_t > | overlay () const |
void | sort_segments () |
void | refresh_seg_offset () |
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 |
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 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, 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. | |
virtual uint64_t | page_size () const |
Get the default memory page size according to the architecture and the format of the current binary. | |
Public Member Functions inherited from LIEF::Object | |
Object () | |
Object (const Object &other) | |
Object & | operator= (const Object &other) |
Object (Object &&other) noexcept=default | |
Object & | operator= (Object &&other) 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 | 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) |
static bool | can_cache_segment (const SegmentCommand &segment) |
Check if the given segment can go in the offset_seg_ cache. |
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_notes = const_filter_iterator<const commands_t&, const NoteCommand*> |
Iterator which outputs const NoteCommand&.
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_sub_clients = const_filter_iterator<const commands_t&, const SubClient*> |
Iterator which outputs const SubClient&.
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 NoteCommand&.
Iterator which outputs Relocation&.
Iterator which outputs RPathCommand&.
Iterator that outputs Section&.
Iterator that outputs SegmentCommand&.
Iterator which outputs SubClient&.
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.
Iterator type for Symbol's stub.
using LIEF::MachO::Binary::symbols_t = std::vector<std::unique_ptr<Symbol>> |
Internal container for storing Mach-O Symbol.
|
delete |
References Binary().
Referenced by atom_info(), Binary(), code_signature(), code_signature_dir(), find_library(), for_commands(), function_variant_fixups(), function_variants(), get(), get_section(), get_section(), get_segment(), get_symbol(), linker_opt_hint(), operator=(), section_from_offset(), section_from_virtual_address(), segment_from_offset(), segment_from_virtual_address(), and two_level_hints().
|
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.
|
inline |
Insert a new LoadCommand.
LoadCommand * LIEF::MachO::Binary::add | ( | const LoadCommand & | command, |
size_t | index ) |
Insert a new LoadCommand at the specified index.
References command().
LoadCommand * LIEF::MachO::Binary::add | ( | const SegmentCommand & | segment | ) |
Add a new LC_SEGMENT command from the given SegmentCommand.
LoadCommand * LIEF::MachO::Binary::add | ( | std::unique_ptr< LoadCommand > | command | ) |
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.
|
inline |
Return the MachO::AtomInfo if present, a nullptr otherwise.
References Binary().
Referenced by has_atom_info().
const AtomInfo * LIEF::MachO::Binary::atom_info | ( | ) | const |
it_bindings LIEF::MachO::Binary::bindings | ( | ) | const |
Return an iterator over the binding info which can come from either DyldInfo or DyldChainedFixups commands.
BuildVersion * LIEF::MachO::Binary::build_version | ( | ) |
Return the MachO::BuildVersion if present, a nullptr otherwise.
Referenced by has_build_version(), and platform().
const BuildVersion * LIEF::MachO::Binary::build_version | ( | ) | const |
|
static |
Check if the given segment can go in the offset_seg_ cache.
References LIEF_LOCAL.
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(), and LIEF::Binary::MACHO.
|
inline |
Return the MachO::CodeSignature if present, a nullptr otherwise.
References Binary().
Referenced by has_code_signature().
const CodeSignature * LIEF::MachO::Binary::code_signature | ( | ) | const |
|
inline |
Return the MachO::CodeSignatureDir if present, a nullptr otherwise.
References Binary().
Referenced by has_code_signature_dir().
const CodeSignatureDir * LIEF::MachO::Binary::code_signature_dir | ( | ) | const |
T * LIEF::MachO::Binary::command | ( | ) |
const T * LIEF::MachO::Binary::command | ( | ) | const |
References LIEF_LOCAL.
|
inline |
Return an iterator over the MachO LoadCommand present in the binary.
|
inline |
size_t LIEF::MachO::Binary::count_commands | ( | ) | const |
References LIEF_LOCAL.
|
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.
Referenced by has_data_in_code().
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.
Referenced by has_dyld_chained_fixups().
const DyldChainedFixups * LIEF::MachO::Binary::dyld_chained_fixups | ( | ) | const |
DyldEnvironment * LIEF::MachO::Binary::dyld_environment | ( | ) |
Return the MachO::DyldEnvironment if present, a nullptr otherwise.
Referenced by has_dyld_environment().
const DyldEnvironment * LIEF::MachO::Binary::dyld_environment | ( | ) | const |
DyldExportsTrie * LIEF::MachO::Binary::dyld_exports_trie | ( | ) |
Return the MachO::DyldChainedFixups if present, a nullptr otherwise.
Referenced by has_dyld_exports_trie().
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.
References DyldInfo.
Referenced by has_dyld_info().
DylinkerCommand * LIEF::MachO::Binary::dylinker | ( | ) |
Return the MachO::DylinkerCommand if present, a nullptr otherwise.
Referenced by has_dylinker().
const DylinkerCommand * LIEF::MachO::Binary::dylinker | ( | ) | const |
DynamicSymbolCommand * LIEF::MachO::Binary::dynamic_symbol_command | ( | ) |
Return the MachO::SymbolCommand if present, a nullptr otherwise.
Referenced by has_dynamic_symbol_command().
const DynamicSymbolCommand * LIEF::MachO::Binary::dynamic_symbol_command | ( | ) | const |
EncryptionInfo * LIEF::MachO::Binary::encryption_info | ( | ) |
Return the MachO::DyldEnvironment if present, a nullptr otherwise.
Referenced by has_encryption_info().
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).
References is_exported().
|
inline |
References is_exported().
bool LIEF::MachO::Binary::extend | ( | const LoadCommand & | command, |
uint64_t | size ) |
Extend the size of the given LoadCommand.
References command().
bool LIEF::MachO::Binary::extend_section | ( | Section & | section, |
size_t | size ) |
Extend the content of the given Section.
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 |
|
inline |
References Binary().
const DylibCommand * LIEF::MachO::Binary::find_library | ( | const std::string & | name | ) | const |
Try to find the library with the given library name.
This function tries to match the fullpath of the DylibCommand or the library name suffix.
Binary & LIEF::MachO::Binary::for_commands | ( | Func | f | ) |
References Binary(), and LIEF_LOCAL.
FunctionStarts * LIEF::MachO::Binary::function_starts | ( | ) |
Return the MachO::FunctionStarts command if present, a nullptr otherwise.
Referenced by has_function_starts().
const FunctionStarts * LIEF::MachO::Binary::function_starts | ( | ) | const |
|
inline |
Return the FunctionVariantFixups if present, a nullptr otherwise.
References Binary().
Referenced by has_function_variant_fixups().
const FunctionVariantFixups * LIEF::MachO::Binary::function_variant_fixups | ( | ) | const |
|
inline |
Return the FunctionVariants if present, a nullptr otherwise.
References Binary().
Referenced by has_function_variants().
const FunctionVariants * LIEF::MachO::Binary::function_variants | ( | ) | const |
LIEF::Binary::functions_t LIEF::MachO::Binary::functions | ( | ) | const |
Return all the functions found in this MachO.
|
inline |
References Binary().
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.
Referenced by has_notes(), operator[](), and operator[]().
|
overridevirtual |
Return the content located at virtual address.
Implements LIEF::Binary.
References LIEF::Binary::AUTO.
|
inline |
Return the section from the given name of a nullptr if the section can't be found.
References Binary().
Referenced by has_section().
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.
|
inline |
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.
References Binary().
const Section * LIEF::MachO::Binary::get_section | ( | const std::string & | segname, |
const std::string & | secname ) const |
|
inline |
Return the segment from the given name.
References Binary().
const SegmentCommand * LIEF::MachO::Binary::get_segment | ( | const std::string & | name | ) | const |
Return the segment from the given name.
Referenced by has_segment().
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.
Referenced by has_symbol().
bool LIEF::MachO::Binary::has | ( | LoadCommand::TYPE | type | ) | const |
Check if the current binary has the given MachO::LoadCommand::TYPE.
Referenced by is_ios(), and is_macos().
|
inline |
true if the binary has the command LC_ATOM_INFO.
References atom_info().
|
inline |
true if the binary has the BuildVersion command.
References build_version().
|
inline |
true if the binary is signed with LC_CODE_SIGNATURE command
References code_signature().
|
inline |
true if the binary is signed with the command DYLIB_CODE_SIGN_DRS
References code_signature_dir().
bool LIEF::MachO::Binary::has_command | ( | ) | const |
References LIEF_LOCAL.
|
inline |
true if the binary has a MachO::DataInCode command.
References data_in_code().
|
inline |
true if the binary has the command LC_DYLD_CHAINED_FIXUPS.
References dyld_chained_fixups().
|
inline |
true if the binary has Dyld envrionment variables.
References dyld_environment().
|
inline |
true if the binary has the command LC_DYLD_CHAINED_FIXUPS.
References dyld_exports_trie().
|
inline |
true if the binary has a MachO::DyldInfo command.
References dyld_info().
|
inline |
true if the binary has a MachO::DylinkerCommand.
References dylinker().
|
inline |
true if the binary has a MachO::DynamicSymbolCommand command.
References dynamic_symbol_command().
|
inline |
true if the binary has Encryption Info.
References encryption_info().
|
inline |
true if the binary has an entrypoint.
Basically for libraries it will return false
References has_main_command(), and has_thread_command().
|
inline |
true if the binary has a LoadCommand::TYPE::FILESET_ENTRY command
|
inline |
true if the binary has a MachO::FunctionStarts command.
References function_starts().
|
inline |
true if the binary has the command LC_FUNCTION_VARIANT_FIXUPS.
References function_variant_fixups().
|
inline |
true if the binary has the command LC_FUNCTION_VARIANTS.
References function_variants().
|
inline |
true if the binary has the command LC_LINKER_OPTIMIZATION_HINT.
References linker_opt_hint().
|
inline |
true if the binary has a MachO::MainCommand command.
References main_command().
Referenced by has_entrypoint().
|
inline |
True if the binary contains LC_NOTE command(s).
References get(), and LIEF::MachO::LoadCommand::NOTE.
|
inlineoverridevirtual |
|
inline |
Return True if the heap is flagged as non-executable. False otherwise.
References header(), and LIEF::MachO::Header::NO_HEAP_EXECUTION.
|
inline |
Return True if the stack is flagged as non-executable. False otherwise.
References LIEF::MachO::Header::ALLOW_STACK_EXECUTION, and header().
Referenced by has_nx().
|
inline |
true if the binary has a MachO::Routine command.
References routine_command().
|
inline |
true if the binary has a MachO::RPathCommand command.
References rpath().
|
inline |
Check if a section with the given name exists.
References get_section().
|
inline |
Check if a segment with the given name exists.
References get_segment().
|
inline |
true if the binary has segment split info.
References segment_split_info().
|
inline |
true if the binary has a MachO::SourceVersion command.
References source_version().
|
inline |
true if the binary has a sub framework command.
References sub_framework().
bool LIEF::MachO::Binary::has_subclients | ( | ) | const |
|
inline |
Check if a symbol with the given name exists.
References get_symbol().
|
inline |
true if the binary has a MachO::SymbolCommand command.
References symbol_command().
|
inline |
true if the binary has a MachO::ThreadCommand command.
References thread_command().
Referenced by has_entrypoint().
|
inline |
true if the binary has the command LC_TWO_LEVEL_HINTS.
References two_level_hints().
|
inline |
true if the binary has a MachO::UUIDCommand command.
References uuid().
|
inline |
true if the binary has a MachO::VersionMin command.
References version_min().
|
inline |
Return a reference to the MachO::Header.
Referenced by has_nx_heap(), has_nx_stack(), is_pie(), and support_arm64_ptr_auth().
|
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).
References is_imported().
|
inline |
References is_imported().
|
static |
Check if the given symbol is exported.
Referenced by exported_symbols(), and exported_symbols().
|
static |
Check if the given symbol is an imported one.
Referenced by imported_symbols(), and imported_symbols().
|
inline |
True if this binary targets iOS.
References has(), LIEF::MachO::BuildVersion::IOS, platform(), and LIEF::MachO::LoadCommand::VERSION_MIN_IPHONEOS.
|
inline |
True if this binary targets macOS.
References has(), LIEF::MachO::BuildVersion::MACOS, platform(), and LIEF::MachO::LoadCommand::VERSION_MIN_MACOSX.
|
inlineoverridevirtual |
Check if the binary is position independent.
Implements LIEF::Binary.
References header(), and LIEF::MachO::Header::PIE.
|
inline |
Check if the given address is encompassed in the binary's virtual addresses range.
References LIEF::MachO::Binary::range_t::end, LIEF::MachO::Binary::range_t::start, and va_ranges().
|
inline |
Return binary imported libraries (MachO::DylibCommand).
|
inline |
|
inline |
Return the MachO::LinkerOptHint if present, a nullptr otherwise.
References Binary().
Referenced by has_linker_opt_hint().
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.
Referenced by has_main_command().
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
it_notes LIEF::MachO::Binary::notes | ( | ) |
Iterator over the different LC_NOTE commands.
it_const_notes LIEF::MachO::Binary::notes | ( | ) | const |
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 |
References get().
|
inline |
References get().
|
inline |
|
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 LIEF::Binary::AUTO.
|
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 LIEF::Binary::AUTO.
|
inline |
Return the platform for which this Mach-O has been compiled for.
References build_version(), LIEF::MachO::BuildVersion::UNKNOWN, and LIEF::version().
Referenced by is_ios(), and is_macos().
|
overridevirtual |
Reimplemented from LIEF::Binary.
std::vector< uint8_t > LIEF::MachO::Binary::raw | ( | ) |
Reconstruct the binary object and return its content as bytes.
void LIEF::MachO::Binary::refresh_seg_offset | ( | ) |
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.
References command().
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.
Routine * LIEF::MachO::Binary::routine_command | ( | ) |
Return the MachO::Routine command if present, a nullptr otherwise.
Referenced by has_routine_command().
const Routine * LIEF::MachO::Binary::routine_command | ( | ) | const |
RPathCommand * LIEF::MachO::Binary::rpath | ( | ) |
Return the MachO::RPathCommand command if present, a nullptr otherwise.
Referenced by has_rpath().
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 |
|
inline |
Return the MachO::Section that encompasses the provided offset. If a section can't be found, it returns a null pointer (nullptr).
References Binary().
const Section * LIEF::MachO::Binary::section_from_offset | ( | uint64_t | offset | ) | const |
|
inline |
Return the MachO::Section that encompasses the provided virtual address. If a section can't be found, it returns a null pointer (nullptr).
References Binary().
const Section * LIEF::MachO::Binary::section_from_virtual_address | ( | uint64_t | virtual_address | ) | const |
|
inline |
Return an iterator over the MachO::Section.
|
inline |
|
inline |
Return the binary's SegmentCommand that encompasses the provided offset.
If a SegmentCommand can't be found it returns a null pointer (nullptr).
References Binary().
const SegmentCommand * LIEF::MachO::Binary::segment_from_offset | ( | uint64_t | offset | ) | const |
|
inline |
Return the binary's SegmentCommand which encompasses the given virtual address or a nullptr if not found.
References Binary().
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.
Referenced by has_segment_split_info().
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.
void LIEF::MachO::Binary::sort_segments | ( | ) |
SourceVersion * LIEF::MachO::Binary::source_version | ( | ) |
Return the MachO::SourceVersion command if present, a nullptr otherwise.
Referenced by has_source_version().
const SourceVersion * LIEF::MachO::Binary::source_version | ( | ) | const |
SubFramework * LIEF::MachO::Binary::sub_framework | ( | ) |
Return the MachO::SubFramework if present, a nullptr otherwise.
Referenced by has_sub_framework().
const SubFramework * LIEF::MachO::Binary::sub_framework | ( | ) | const |
it_sub_clients LIEF::MachO::Binary::subclients | ( | ) |
Iterator over all the MachO::SubClient commands.
it_const_sub_clients LIEF::MachO::Binary::subclients | ( | ) | const |
|
inline |
Check if the binary is supporting ARM64 pointer authentication (arm64e).
References LIEF::MachO::Header::ARM64, LIEF::MachO::Header::CPU_SUBTYPE_ARM64_ARM64E, and header().
SymbolCommand * LIEF::MachO::Binary::symbol_command | ( | ) |
Return the MachO::SymbolCommand if present, a nullptr otherwise.
Referenced by has_symbol_command().
const SymbolCommand * LIEF::MachO::Binary::symbol_command | ( | ) | const |
stub_iterator LIEF::MachO::Binary::symbol_stubs | ( | ) | const |
Return an iterator over the symbol stubs.
These stubs are involved when calling an imported function and are similar to the ELF's plt/got mechanism.
There are located in sections like: __stubs,__auth_stubs,__symbol_stub,__picsymbolstub4
|
inline |
Return binary's symbols .
|
inline |
ThreadCommand * LIEF::MachO::Binary::thread_command | ( | ) |
Return the MachO::ThreadCommand command if present, a nullptr otherwise.
Referenced by has_thread_command().
const ThreadCommand * LIEF::MachO::Binary::thread_command | ( | ) | const |
|
inline |
Return the MachO::DyldChainedFixups if present, a nullptr otherwise.
References Binary().
Referenced by has_two_level_hints().
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.
Referenced by has_uuid().
const UUIDCommand * LIEF::MachO::Binary::uuid | ( | ) | const |
range_t LIEF::MachO::Binary::va_ranges | ( | ) | const |
Return the range of virtual addresses.
Referenced by is_valid_addr(), and virtual_size().
VersionMin * LIEF::MachO::Binary::version_min | ( | ) |
Return the MachO::VersionMin command if present, a nullptr otherwise.
Referenced by has_version_min().
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.
|
inline |
Size of the binary in memory when mapped by the loader (dyld).
References LIEF::align(), LIEF::Binary::page_size(), and va_ranges().
void LIEF::MachO::Binary::write | ( | const std::string & | filename | ) |
Reconstruct the binary object and write the result in the given filename.
filename | Path to write the reconstructed binary |
void LIEF::MachO::Binary::write | ( | const std::string & | filename, |
Builder::config_t | config ) |
Reconstruct the binary object and write the result in the given filename.
The second config parameter is used to tweak the building process
filename | Path to write the reconstructed binary |
config | Builder configuration |
void LIEF::MachO::Binary::write | ( | std::ostream & | os | ) |
Reconstruct the binary object and write the result in the given os stream.
os | Output stream to write the reconstructed binary |
void LIEF::MachO::Binary::write | ( | std::ostream & | os, |
Builder::config_t | config ) |
Reconstruct the binary object and write the result in the given os stream for the given configuration.
os | Output stream to write the reconstructed binary |
config | Builder configuration |