LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
LIEF::MachO::Binary Class Reference

Class which represents a MachO binary. More...

#include <Binary.hpp>

Inheritance diagram for LIEF::MachO::Binary:
Collaboration diagram for LIEF::MachO::Binary:

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&.
 
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.
 
- 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
 
Binaryoperator= (const Binary &)=delete
 
Headerheader ()
 Return a reference to the MachO::Header.
 
const Headerheader () 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 Symbolget_symbol (const std::string &name) const
 Return Symbol from the given name. If the symbol does not exists, it returns a null pointer.
 
Symbolget_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 (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) 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 LoadCommandget (LoadCommand::TYPE type) const
 Return the LoadCommand associated with the given LoadCommand::TYPE or a nullptr if the command can't be found.
 
LoadCommandget (LoadCommand::TYPE type)
 
LoadCommandadd (std::unique_ptr< LoadCommand > command)
 
LoadCommandadd (const LoadCommand &command)
 Insert a new LoadCommand.
 
LoadCommandadd (const LoadCommand &command, size_t index)
 Insert a new LoadCommand at the specified index
 
LoadCommandadd (const DylibCommand &library)
 Insert the given DylibCommand.
 
LoadCommandadd (const SegmentCommand &segment)
 Add a new LC_SEGMENT command from the given SegmentCommand.
 
LoadCommandadd_library (const std::string &name)
 Insert a new shared library through a LC_LOAD_DYLIB command.
 
Sectionadd_section (const Section &section)
 Add a new MachO::Section in the __TEXT segment.
 
Sectionadd_section (const SegmentCommand &segment, const Section &section)
 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.
 
Sectionget_section (const std::string &name)
 Return the section from the given name of a nullptr if the section can't be found.
 
const Sectionget_section (const std::string &name) const
 Return the section from the given name or a nullptr if the section can't be found.
 
Sectionget_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 Sectionget_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 SegmentCommandget_segment (const std::string &name) const
 Return the segment from the given name.
 
SegmentCommandget_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.
 
Sectionsection_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 Sectionsection_from_offset (uint64_t offset) const
 
Sectionsection_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 Sectionsection_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.
 
SegmentCommandsegment_from_offset (uint64_t offset)
 Return the binary's SegmentCommand that encompasses the provided offset.
 
const SegmentCommandsegment_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.
 
SegmentCommandsegment_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 SegmentCommandsegment_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.
 
UUIDCommanduuid ()
 Return the MachO::UUIDCommand if present, a nullptr otherwise.
 
const UUIDCommanduuid () const
 
bool has_main_command () const
 true if the binary has a MachO::MainCommand command.
 
MainCommandmain_command ()
 Return the MachO::MainCommand if present, a nullptr otherwise.
 
const MainCommandmain_command () const
 
bool has_dylinker () const
 true if the binary has a MachO::DylinkerCommand.
 
DylinkerCommanddylinker ()
 Return the MachO::DylinkerCommand if present, a nullptr otherwise.
 
const DylinkerCommanddylinker () const
 
bool has_dyld_info () const
 true if the binary has a MachO::DyldInfo command.
 
DyldInfodyld_info ()
 Return the MachO::Dyld command if present, a nullptr otherwise.
 
const DyldInfodyld_info () const
 
bool has_function_starts () const
 true if the binary has a MachO::FunctionStarts command.
 
FunctionStartsfunction_starts ()
 Return the MachO::FunctionStarts command if present, a nullptr otherwise.
 
const FunctionStartsfunction_starts () const
 
bool has_source_version () const
 true if the binary has a MachO::SourceVersion command.
 
SourceVersionsource_version ()
 Return the MachO::SourceVersion command if present, a nullptr otherwise.
 
const SourceVersionsource_version () const
 
bool has_version_min () const
 true if the binary has a MachO::VersionMin command.
 
VersionMinversion_min ()
 Return the MachO::VersionMin command if present, a nullptr otherwise.
 
const VersionMinversion_min () const
 
bool has_thread_command () const
 true if the binary has a MachO::ThreadCommand command.
 
ThreadCommandthread_command ()
 Return the MachO::ThreadCommand command if present, a nullptr otherwise.
 
const ThreadCommandthread_command () const
 
bool has_routine_command () const
 true if the binary has a MachO::Routine command.
 
Routineroutine_command ()
 Return the MachO::Routine command if present, a nullptr otherwise.
 
const Routineroutine_command () const
 
bool has_rpath () const
 true if the binary has a MachO::RPathCommand command.
 
RPathCommandrpath ()
 Return the MachO::RPathCommand command if present, a nullptr otherwise.
 
const RPathCommandrpath () 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.
 
SymbolCommandsymbol_command ()
 Return the MachO::SymbolCommand if present, a nullptr otherwise.
 
const SymbolCommandsymbol_command () const
 
bool has_dynamic_symbol_command () const
 true if the binary has a MachO::DynamicSymbolCommand command.
 
DynamicSymbolCommanddynamic_symbol_command ()
 Return the MachO::SymbolCommand if present, a nullptr otherwise.
 
const DynamicSymbolCommanddynamic_symbol_command () const
 
bool has_code_signature () const
 true if the binary is signed with LC_CODE_SIGNATURE command
 
CodeSignaturecode_signature ()
 Return the MachO::CodeSignature if present, a nullptr otherwise.
 
const CodeSignaturecode_signature () const
 
bool has_code_signature_dir () const
 true if the binary is signed with the command DYLIB_CODE_SIGN_DRS
 
CodeSignatureDircode_signature_dir ()
 Return the MachO::CodeSignatureDir if present, a nullptr otherwise.
 
const CodeSignatureDircode_signature_dir () const
 
bool has_data_in_code () const
 true if the binary has a MachO::DataInCode command.
 
DataInCodedata_in_code ()
 Return the MachO::DataInCode if present, a nullptr otherwise.
 
const DataInCodedata_in_code () const
 
bool has_segment_split_info () const
 true if the binary has segment split info.
 
SegmentSplitInfosegment_split_info ()
 Return the MachO::SegmentSplitInfo if present, a nullptr otherwise.
 
const SegmentSplitInfosegment_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.
 
EncryptionInfoencryption_info ()
 Return the MachO::DyldEnvironment if present, a nullptr otherwise.
 
const EncryptionInfoencryption_info () const
 
SubFrameworksub_framework ()
 Return the MachO::SubFramework if present, a nullptr otherwise.
 
const SubFrameworksub_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.
 
DyldEnvironmentdyld_environment ()
 Return the MachO::DyldEnvironment if present, a nullptr otherwise.
 
const DyldEnvironmentdyld_environment () const
 
bool has_build_version () const
 true if the binary has the BuildVersion command.
 
BuildVersionbuild_version ()
 Return the MachO::BuildVersion if present, a nullptr otherwise.
 
const BuildVersionbuild_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.
 
DyldChainedFixupsdyld_chained_fixups ()
 Return the MachO::DyldChainedFixups if present, a nullptr otherwise.
 
const DyldChainedFixupsdyld_chained_fixups () const
 
bool has_dyld_exports_trie () const
 true if the binary has the command LC_DYLD_CHAINED_FIXUPS.
 
DyldExportsTriedyld_exports_trie ()
 Return the MachO::DyldChainedFixups if present, a nullptr otherwise.
 
const DyldExportsTriedyld_exports_trie () const
 
bool has_two_level_hints () const
 true if the binary has the command LC_TWO_LEVEL_HINTS.
 
TwoLevelHintstwo_level_hints ()
 Return the MachO::DyldChainedFixups if present, a nullptr otherwise.
 
const TwoLevelHintstwo_level_hints () const
 
bool has_linker_opt_hint () const
 true if the binary has the command LC_LINKER_OPTIMIZATION_HINT.
 
LinkerOptHintlinker_opt_hint ()
 Return the MachO::LinkerOptHint if present, a nullptr otherwise.
 
const LinkerOptHintlinker_opt_hint () const
 
ExportInfoadd_exported_function (uint64_t address, const std::string &name)
 Add a symbol in the export trie of the current binary.
 
Symboladd_local_symbol (uint64_t address, const std::string &name)
 Add a symbol in LC_SYMTAB command of the current binary.
 
std::unique_ptr< objc::Metadataobjc_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.
 
AtomInfoatom_info ()
 Return the MachO::AtomInfo if present, a nullptr otherwise.
 
const AtomInfoatom_info () 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 >
Binaryfor_commands (Func f)
 
LoadCommandoperator[] (LoadCommand::TYPE type)
 
const LoadCommandoperator[] (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.
 
Symboladd (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.
 
uint32_t page_size () const
 
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
 
Binaryoperator= (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 Symbolget_symbol (const std::string &name) const
 Return the Symbol with the given name If the symbol does not exist, return a nullptr.
 
Symbolget_symbol (const std::string &name)
 
it_sections sections ()
 Return an iterator over the binary's sections (LIEF::Section)
 
it_const_sections sections () const
 
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.
 
DebugInfodebug_info () const
 Return the debug info if present. It can be either a LIEF::dwarf::DebugInfo or a LIEF::pdb::DebugInfo.
 
instructions_it disassemble (uint64_t address, size_t size) const
 Disassemble code starting a the given virtual address and with the given size.
 
instructions_it disassemble (uint64_t address) const
 Disassemble code starting a the given virtual address.
 
instructions_it disassemble (const std::string &function) const
 Disassemble code for the given symbol name.
 
instructions_it disassemble (const uint8_t *buffer, size_t size, uint64_t address=0) const
 Disassemble code provided by the given buffer at the specified address parameter.
 
instructions_it disassemble (const std::vector< uint8_t > &buffer, uint64_t address=0) const
 Disassemble code provided by the given vector of bytes at the specified address parameter.
 
instructions_it disassemble (LIEF::span< const uint8_t > buffer, uint64_t address=0) const
 
instructions_it disassemble (LIEF::span< uint8_t > buffer, uint64_t address=0) const
 
std::vector< uint8_t > assemble (uint64_t address, const std::string &Asm)
 Assemble and patch the provided assembly code at the specified address.
 
- Public Member Functions inherited from LIEF::Object
 Object ()
 
 Object (const Object &other)
 
Objectoperator= (const Object &other)
 
template<class T >
output_t< T > as ()
 
template<class T >
output_const_t< T > as () const
 
virtual bool operator== (const Object &other) const
 
virtual bool operator!= (const Object &other) const
 
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.
 

Detailed Description

Class which represents a MachO binary.

Member Typedef Documentation

◆ commands_t

using LIEF::MachO::Binary::commands_t = std::vector<std::unique_ptr<LoadCommand>>

Internal container for storing Mach-O LoadCommand.

◆ fileset_binaries_t

using LIEF::MachO::Binary::fileset_binaries_t = std::vector<std::unique_ptr<Binary>>

Internal container for storing Mach-O Fileset Binary.

◆ it_bindings

◆ it_commands

◆ it_const_commands

◆ it_const_exported_symbols

Iterator that outputs exported const Symbol&.

◆ it_const_fileset_binaries

◆ it_const_imported_symbols

Iterator that outputs imported const Symbol&.

◆ it_const_libraries

◆ it_const_relocations

◆ it_const_rpaths

Iterator which outputs const RPathCommand&.

◆ it_const_sections

◆ it_const_segments

◆ it_const_sub_clients

Iterator which outputs const SubClient&.

◆ it_const_symbols

Iterator that outputs const Symbol&.

◆ it_exported_symbols

Iterator that outputs exported Symbol&.

◆ it_fileset_binaries

◆ it_imported_symbols

Iterator that outputs imported Symbol&.

◆ it_libraries

◆ it_relocations

◆ it_rpaths

◆ it_sections

◆ it_segments

◆ it_sub_clients

◆ it_symbols

◆ libraries_cache_t

Internal container for storing Mach-O DylibCommand.

◆ relocations_t

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.

◆ sections_cache_t

Internal container for caching Mach-O Section.

◆ segments_cache_t

Internal container for storing Mach-O SegmentCommand.

◆ stub_iterator

◆ symbols_t

using LIEF::MachO::Binary::symbols_t = std::vector<std::unique_ptr<Symbol>>

Internal container for storing Mach-O Symbol.

Constructor & Destructor Documentation

◆ Binary()

LIEF::MachO::Binary::Binary ( const Binary & )
delete

◆ ~Binary()

LIEF::MachO::Binary::~Binary ( )
override

Member Function Documentation

◆ accept()

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

Method so that the visitor can visit us.

Reimplemented from LIEF::Binary.

◆ add() [1/6]

LoadCommand * LIEF::MachO::Binary::add ( const DylibCommand & library)

Insert the given DylibCommand.

◆ add() [2/6]

LoadCommand * LIEF::MachO::Binary::add ( const LoadCommand & command)
inline

◆ add() [3/6]

LoadCommand * LIEF::MachO::Binary::add ( const LoadCommand & command,
size_t index )

Insert a new LoadCommand at the specified index

◆ add() [4/6]

LoadCommand * LIEF::MachO::Binary::add ( const SegmentCommand & segment)

Add a new LC_SEGMENT command from the given SegmentCommand.

◆ add() [5/6]

Symbol & LIEF::MachO::Binary::add ( const Symbol & symbol)

Add a symbol to this binary.

◆ add() [6/6]

LoadCommand * LIEF::MachO::Binary::add ( std::unique_ptr< LoadCommand > command)

◆ add_exported_function()

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.

◆ add_library()

LoadCommand * LIEF::MachO::Binary::add_library ( const std::string & name)

Insert a new shared library through a LC_LOAD_DYLIB command.

◆ add_local_symbol()

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_section() [1/2]

Section * LIEF::MachO::Binary::add_section ( const Section & section)

Add a new MachO::Section in the __TEXT segment.

◆ add_section() [2/2]

Section * LIEF::MachO::Binary::add_section ( const SegmentCommand & segment,
const Section & section )

Add a section in the given MachO::SegmentCommand.

Warning
This method may corrupt the file if the segment is not the first one nor the last one

◆ atom_info() [1/2]

AtomInfo * LIEF::MachO::Binary::atom_info ( )
inline

Return the MachO::AtomInfo if present, a nullptr otherwise.

◆ atom_info() [2/2]

const AtomInfo * LIEF::MachO::Binary::atom_info ( ) const

◆ bindings()

it_bindings LIEF::MachO::Binary::bindings ( ) const

Return an iterator over the binding info which can come from either DyldInfo or DyldChainedFixups commands.

◆ build_version() [1/2]

BuildVersion * LIEF::MachO::Binary::build_version ( )

Return the MachO::BuildVersion if present, a nullptr otherwise.

◆ build_version() [2/2]

const BuildVersion * LIEF::MachO::Binary::build_version ( ) const

◆ can_cache_segment()

static bool LIEF::MachO::Binary::can_cache_segment ( const SegmentCommand & segment)
static

Check if the given segment can go in the offset_seg_ cache.

◆ can_remove()

bool LIEF::MachO::Binary::can_remove ( const Symbol & sym) const

Check if the given symbol can be safely removed.

◆ can_remove_symbol()

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.

◆ classof()

static bool LIEF::MachO::Binary::classof ( const LIEF::Binary * bin)
inlinestatic

◆ code_signature() [1/2]

CodeSignature * LIEF::MachO::Binary::code_signature ( )
inline

Return the MachO::CodeSignature if present, a nullptr otherwise.

◆ code_signature() [2/2]

const CodeSignature * LIEF::MachO::Binary::code_signature ( ) const

◆ code_signature_dir() [1/2]

CodeSignatureDir * LIEF::MachO::Binary::code_signature_dir ( )
inline

Return the MachO::CodeSignatureDir if present, a nullptr otherwise.

◆ code_signature_dir() [2/2]

const CodeSignatureDir * LIEF::MachO::Binary::code_signature_dir ( ) const

◆ command() [1/2]

template<class T >
T * LIEF::MachO::Binary::command ( )

◆ command() [2/2]

template<class T >
const T * LIEF::MachO::Binary::command ( ) const

◆ commands() [1/2]

it_commands LIEF::MachO::Binary::commands ( )
inline

Return an iterator over the MachO LoadCommand present in the binary.

◆ commands() [2/2]

it_const_commands LIEF::MachO::Binary::commands ( ) const
inline

◆ count_commands()

template<class T >
size_t LIEF::MachO::Binary::count_commands ( ) const

◆ ctor_functions()

LIEF::Binary::functions_t LIEF::MachO::Binary::ctor_functions ( ) const
overridevirtual

Return the list of the MachO's constructors.

Implements LIEF::Binary.

◆ data_in_code() [1/2]

DataInCode * LIEF::MachO::Binary::data_in_code ( )

Return the MachO::DataInCode if present, a nullptr otherwise.

◆ data_in_code() [2/2]

const DataInCode * LIEF::MachO::Binary::data_in_code ( ) const

◆ disable_pie()

bool LIEF::MachO::Binary::disable_pie ( )

Remove the PIE flag.

◆ dyld_chained_fixups() [1/2]

DyldChainedFixups * LIEF::MachO::Binary::dyld_chained_fixups ( )

Return the MachO::DyldChainedFixups if present, a nullptr otherwise.

◆ dyld_chained_fixups() [2/2]

const DyldChainedFixups * LIEF::MachO::Binary::dyld_chained_fixups ( ) const

◆ dyld_environment() [1/2]

DyldEnvironment * LIEF::MachO::Binary::dyld_environment ( )

Return the MachO::DyldEnvironment if present, a nullptr otherwise.

◆ dyld_environment() [2/2]

const DyldEnvironment * LIEF::MachO::Binary::dyld_environment ( ) const

◆ dyld_exports_trie() [1/2]

DyldExportsTrie * LIEF::MachO::Binary::dyld_exports_trie ( )

Return the MachO::DyldChainedFixups if present, a nullptr otherwise.

◆ dyld_exports_trie() [2/2]

const DyldExportsTrie * LIEF::MachO::Binary::dyld_exports_trie ( ) const

◆ dyld_info() [1/2]

DyldInfo * LIEF::MachO::Binary::dyld_info ( )

Return the MachO::Dyld command if present, a nullptr otherwise.

◆ dyld_info() [2/2]

const DyldInfo * LIEF::MachO::Binary::dyld_info ( ) const

◆ dylinker() [1/2]

DylinkerCommand * LIEF::MachO::Binary::dylinker ( )

Return the MachO::DylinkerCommand if present, a nullptr otherwise.

◆ dylinker() [2/2]

const DylinkerCommand * LIEF::MachO::Binary::dylinker ( ) const

◆ dynamic_symbol_command() [1/2]

DynamicSymbolCommand * LIEF::MachO::Binary::dynamic_symbol_command ( )

Return the MachO::SymbolCommand if present, a nullptr otherwise.

◆ dynamic_symbol_command() [2/2]

const DynamicSymbolCommand * LIEF::MachO::Binary::dynamic_symbol_command ( ) const

◆ encryption_info() [1/2]

EncryptionInfo * LIEF::MachO::Binary::encryption_info ( )

Return the MachO::DyldEnvironment if present, a nullptr otherwise.

◆ encryption_info() [2/2]

const EncryptionInfo * LIEF::MachO::Binary::encryption_info ( ) const

◆ entrypoint()

uint64_t LIEF::MachO::Binary::entrypoint ( ) const
overridevirtual

The binary entrypoint.

Implements LIEF::Binary.

◆ exported_symbols() [1/2]

it_exported_symbols LIEF::MachO::Binary::exported_symbols ( )
inline

Return binary's exported symbols (iterator over LIEF::MachO::Symbol)

◆ exported_symbols() [2/2]

it_const_exported_symbols LIEF::MachO::Binary::exported_symbols ( ) const
inline

◆ extend()

bool LIEF::MachO::Binary::extend ( const LoadCommand & command,
uint64_t size )

Extend the size of the given LoadCommand.

◆ extend_segment()

bool LIEF::MachO::Binary::extend_segment ( const SegmentCommand & segment,
size_t size )

Extend the content of the given SegmentCommand.

◆ fat_offset()

uint64_t LIEF::MachO::Binary::fat_offset ( ) const
inline

Return binary's fat offset. 0 if not relevant.

◆ fileset_name()

const std::string & LIEF::MachO::Binary::fileset_name ( ) const
inline

Name associated with the LC_FILESET_ENTRY binary.

◆ filesets() [1/2]

it_fileset_binaries LIEF::MachO::Binary::filesets ( )
inline

Return an iterator over the MachO::Binary associated with the LoadCommand::TYPE::FILESET_ENTRY commands.

◆ filesets() [2/2]

it_const_fileset_binaries LIEF::MachO::Binary::filesets ( ) const
inline

◆ for_commands()

template<class CMD , class Func >
Binary & LIEF::MachO::Binary::for_commands ( Func f)

◆ function_starts() [1/2]

FunctionStarts * LIEF::MachO::Binary::function_starts ( )

Return the MachO::FunctionStarts command if present, a nullptr otherwise.

◆ function_starts() [2/2]

const FunctionStarts * LIEF::MachO::Binary::function_starts ( ) const

◆ functions()

LIEF::Binary::functions_t LIEF::MachO::Binary::functions ( ) const

Return all the functions found in this MachO.

◆ get() [1/2]

LoadCommand * LIEF::MachO::Binary::get ( LoadCommand::TYPE type)
inline

◆ get() [2/2]

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.

◆ get_content_from_virtual_address()

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

Return the content located at virtual address.

Implements LIEF::Binary.

◆ get_section() [1/4]

Section * LIEF::MachO::Binary::get_section ( const std::string & name)
inline

Return the section from the given name of a nullptr if the section can't be found.

◆ get_section() [2/4]

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.

◆ get_section() [3/4]

Section * LIEF::MachO::Binary::get_section ( const std::string & segname,
const std::string & secname )
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.

◆ get_section() [4/4]

const Section * LIEF::MachO::Binary::get_section ( const std::string & segname,
const std::string & secname ) const

◆ get_segment() [1/2]

SegmentCommand * LIEF::MachO::Binary::get_segment ( const std::string & name)
inline

Return the segment from the given name.

◆ get_segment() [2/2]

const SegmentCommand * LIEF::MachO::Binary::get_segment ( const std::string & name) const

Return the segment from the given name.

◆ get_symbol() [1/2]

Symbol * LIEF::MachO::Binary::get_symbol ( const std::string & name)
inline

◆ get_symbol() [2/2]

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.

◆ has()

bool LIEF::MachO::Binary::has ( LoadCommand::TYPE type) const

Check if the current binary has the given MachO::LoadCommand::TYPE.

◆ has_atom_info()

bool LIEF::MachO::Binary::has_atom_info ( ) const
inline

true if the binary has the command LC_ATOM_INFO.

◆ has_build_version()

bool LIEF::MachO::Binary::has_build_version ( ) const
inline

true if the binary has the BuildVersion command.

◆ has_code_signature()

bool LIEF::MachO::Binary::has_code_signature ( ) const
inline

true if the binary is signed with LC_CODE_SIGNATURE command

◆ has_code_signature_dir()

bool LIEF::MachO::Binary::has_code_signature_dir ( ) const
inline

true if the binary is signed with the command DYLIB_CODE_SIGN_DRS

◆ has_command()

template<class T >
bool LIEF::MachO::Binary::has_command ( ) const

◆ has_data_in_code()

bool LIEF::MachO::Binary::has_data_in_code ( ) const
inline

true if the binary has a MachO::DataInCode command.

◆ has_dyld_chained_fixups()

bool LIEF::MachO::Binary::has_dyld_chained_fixups ( ) const
inline

true if the binary has the command LC_DYLD_CHAINED_FIXUPS.

◆ has_dyld_environment()

bool LIEF::MachO::Binary::has_dyld_environment ( ) const
inline

true if the binary has Dyld envrionment variables.

◆ has_dyld_exports_trie()

bool LIEF::MachO::Binary::has_dyld_exports_trie ( ) const
inline

true if the binary has the command LC_DYLD_CHAINED_FIXUPS.

◆ has_dyld_info()

bool LIEF::MachO::Binary::has_dyld_info ( ) const
inline

true if the binary has a MachO::DyldInfo command.

◆ has_dylinker()

bool LIEF::MachO::Binary::has_dylinker ( ) const
inline

true if the binary has a MachO::DylinkerCommand.

◆ has_dynamic_symbol_command()

bool LIEF::MachO::Binary::has_dynamic_symbol_command ( ) const
inline

true if the binary has a MachO::DynamicSymbolCommand command.

◆ has_encryption_info()

bool LIEF::MachO::Binary::has_encryption_info ( ) const
inline

true if the binary has Encryption Info.

◆ has_entrypoint()

bool LIEF::MachO::Binary::has_entrypoint ( ) const
inline

true if the binary has an entrypoint.

Basically for libraries it will return false

◆ has_filesets()

bool LIEF::MachO::Binary::has_filesets ( ) const
inline

true if the binary has a LoadCommand::TYPE::FILESET_ENTRY command

◆ has_function_starts()

bool LIEF::MachO::Binary::has_function_starts ( ) const
inline

true if the binary has a MachO::FunctionStarts command.

◆ has_linker_opt_hint()

bool LIEF::MachO::Binary::has_linker_opt_hint ( ) const
inline

true if the binary has the command LC_LINKER_OPTIMIZATION_HINT.

◆ has_main_command()

bool LIEF::MachO::Binary::has_main_command ( ) const
inline

true if the binary has a MachO::MainCommand command.

◆ has_nx()

bool LIEF::MachO::Binary::has_nx ( ) const
inlineoverridevirtual

Check if the binary uses NX protection.

Implements LIEF::Binary.

◆ has_nx_heap()

bool LIEF::MachO::Binary::has_nx_heap ( ) const
inline

Return True if the stack is flagged as non-executable. False otherwise.

◆ has_nx_stack()

bool LIEF::MachO::Binary::has_nx_stack ( ) const
inline

Return True if the heap is flagged as non-executable. False otherwise.

◆ has_routine_command()

bool LIEF::MachO::Binary::has_routine_command ( ) const
inline

true if the binary has a MachO::Routine command.

◆ has_rpath()

bool LIEF::MachO::Binary::has_rpath ( ) const
inline

true if the binary has a MachO::RPathCommand command.

◆ has_section()

bool LIEF::MachO::Binary::has_section ( const std::string & name) const
inline

Check if a section with the given name exists.

◆ has_segment()

bool LIEF::MachO::Binary::has_segment ( const std::string & name) const
inline

Check if a segment with the given name exists.

◆ has_segment_split_info()

bool LIEF::MachO::Binary::has_segment_split_info ( ) const
inline

true if the binary has segment split info.

◆ has_source_version()

bool LIEF::MachO::Binary::has_source_version ( ) const
inline

true if the binary has a MachO::SourceVersion command.

◆ has_sub_framework()

bool LIEF::MachO::Binary::has_sub_framework ( ) const
inline

true if the binary has a sub framework command.

◆ has_subclients()

bool LIEF::MachO::Binary::has_subclients ( ) const

◆ has_symbol()

bool LIEF::MachO::Binary::has_symbol ( const std::string & name) const
inline

Check if a symbol with the given name exists.

◆ has_symbol_command()

bool LIEF::MachO::Binary::has_symbol_command ( ) const
inline

true if the binary has a MachO::SymbolCommand command.

◆ has_thread_command()

bool LIEF::MachO::Binary::has_thread_command ( ) const
inline

true if the binary has a MachO::ThreadCommand command.

◆ has_two_level_hints()

bool LIEF::MachO::Binary::has_two_level_hints ( ) const
inline

true if the binary has the command LC_TWO_LEVEL_HINTS.

◆ has_uuid()

bool LIEF::MachO::Binary::has_uuid ( ) const
inline

true if the binary has a MachO::UUIDCommand command.

◆ has_version_min()

bool LIEF::MachO::Binary::has_version_min ( ) const
inline

true if the binary has a MachO::VersionMin command.

◆ header() [1/2]

Header & LIEF::MachO::Binary::header ( )
inline

Return a reference to the MachO::Header.

◆ header() [2/2]

const Header & LIEF::MachO::Binary::header ( ) const
inline

◆ imagebase()

uint64_t LIEF::MachO::Binary::imagebase ( ) const
overridevirtual

Return the binary's imagebase. 0 if not relevant.

Implements LIEF::Binary.

◆ imported_symbols() [1/2]

it_imported_symbols LIEF::MachO::Binary::imported_symbols ( )
inline

Return binary's imported symbols (iterator over LIEF::MachO::Symbol)

◆ imported_symbols() [2/2]

it_const_imported_symbols LIEF::MachO::Binary::imported_symbols ( ) const
inline

◆ is_exported()

static bool LIEF::MachO::Binary::is_exported ( const Symbol & symbol)
static

Check if the given symbol is exported.

◆ is_imported()

static bool LIEF::MachO::Binary::is_imported ( const Symbol & symbol)
static

Check if the given symbol is an imported one.

◆ is_ios()

bool LIEF::MachO::Binary::is_ios ( ) const
inline

True if this binary targets iOS.

◆ is_macos()

bool LIEF::MachO::Binary::is_macos ( ) const
inline

True if this binary targets macOS.

◆ is_pie()

bool LIEF::MachO::Binary::is_pie ( ) const
inlineoverridevirtual

Check if the binary is position independent.

Implements LIEF::Binary.

◆ is_valid_addr()

bool LIEF::MachO::Binary::is_valid_addr ( uint64_t address) const
inline

Check if the given address is encompassed in the binary's virtual addresses range.

References LIEF::MachO::Binary::range_t::end, and LIEF::MachO::Binary::range_t::start.

◆ libraries() [1/2]

it_libraries LIEF::MachO::Binary::libraries ( )
inline

Return binary imported libraries (MachO::DylibCommand)

◆ libraries() [2/2]

it_const_libraries LIEF::MachO::Binary::libraries ( ) const
inline

◆ linker_opt_hint() [1/2]

LinkerOptHint * LIEF::MachO::Binary::linker_opt_hint ( )
inline

Return the MachO::LinkerOptHint if present, a nullptr otherwise.

◆ linker_opt_hint() [2/2]

const LinkerOptHint * LIEF::MachO::Binary::linker_opt_hint ( ) const

◆ loader()

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.

◆ main_command() [1/2]

MainCommand * LIEF::MachO::Binary::main_command ( )

Return the MachO::MainCommand if present, a nullptr otherwise.

◆ main_command() [2/2]

const MainCommand * LIEF::MachO::Binary::main_command ( ) const

◆ memory_base_address()

uint64_t LIEF::MachO::Binary::memory_base_address ( ) 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

◆ objc_metadata()

std::unique_ptr< objc::Metadata > LIEF::MachO::Binary::objc_metadata ( ) const

Return Objective-C metadata if present.

◆ off_ranges()

range_t LIEF::MachO::Binary::off_ranges ( ) const

Return the range of offsets.

◆ offset_to_virtual_address()

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

Convert the given offset into a virtual address.

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

Implements LIEF::Binary.

◆ operator=()

Binary & LIEF::MachO::Binary::operator= ( const Binary & )
delete

◆ operator[]() [1/2]

LoadCommand * LIEF::MachO::Binary::operator[] ( LoadCommand::TYPE type)
inline

◆ operator[]() [2/2]

const LoadCommand * LIEF::MachO::Binary::operator[] ( LoadCommand::TYPE type) const
inline

◆ overlay()

span< const uint8_t > LIEF::MachO::Binary::overlay ( ) const
inline

◆ page_size()

uint32_t LIEF::MachO::Binary::page_size ( ) const

◆ patch_address() [1/2]

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

Patch the content at virtual address address with patch_value.

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

Implements LIEF::Binary.

◆ patch_address() [2/2]

void LIEF::MachO::Binary::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 )
overridevirtual

Patch the address with the given value.

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

Implements LIEF::Binary.

◆ platform()

BuildVersion::PLATFORMS LIEF::MachO::Binary::platform ( ) const
inline

Return the platform for which this Mach-O has been compiled for.

◆ print()

std::ostream & LIEF::MachO::Binary::print ( std::ostream & os) const
overridevirtual

Reimplemented from LIEF::Binary.

◆ raw()

std::vector< uint8_t > LIEF::MachO::Binary::raw ( )

Reconstruct the binary object and return its content as bytes.

◆ refresh_seg_offset()

void LIEF::MachO::Binary::refresh_seg_offset ( )

◆ relocations() [1/2]

it_relocations LIEF::MachO::Binary::relocations ( )

Return an iterator over the MachO::Relocation.

◆ relocations() [2/2]

it_const_relocations LIEF::MachO::Binary::relocations ( ) const

◆ remove() [1/3]

bool LIEF::MachO::Binary::remove ( const LoadCommand & command)

Remove the given LoadCommand.

◆ remove() [2/3]

bool LIEF::MachO::Binary::remove ( const Symbol & sym)

Remove the given symbol.

◆ remove() [3/3]

bool LIEF::MachO::Binary::remove ( LoadCommand::TYPE type)

Remove all LoadCommand with the given type (MachO::LoadCommand::TYPE)

◆ remove_command()

bool LIEF::MachO::Binary::remove_command ( size_t index)

Remove the Load Command at the provided index

◆ remove_section() [1/2]

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

Remove the section with the name provided in the first parameter.

Parameters
nameName of the MachO::Section to remove
clearIf true clear the content of the section before removing

Implements LIEF::Binary.

◆ remove_section() [2/2]

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.

Parameters
segnameName of the MachO::Segment
secnameName of the MachO::Section to remove
clearIf true clear the content of the section before removing

◆ remove_signature()

bool LIEF::MachO::Binary::remove_signature ( )

Remove the LC_SIGNATURE command.

◆ remove_symbol()

bool LIEF::MachO::Binary::remove_symbol ( const std::string & name)

Remove the symbol with the given name.

◆ routine_command() [1/2]

Routine * LIEF::MachO::Binary::routine_command ( )

Return the MachO::Routine command if present, a nullptr otherwise.

◆ routine_command() [2/2]

const Routine * LIEF::MachO::Binary::routine_command ( ) const

◆ rpath() [1/2]

RPathCommand * LIEF::MachO::Binary::rpath ( )

Return the MachO::RPathCommand command if present, a nullptr otherwise.

◆ rpath() [2/2]

const RPathCommand * LIEF::MachO::Binary::rpath ( ) const

◆ rpaths() [1/2]

it_rpaths LIEF::MachO::Binary::rpaths ( )

Iterator over all the MachO::RPathCommand commands.

◆ rpaths() [2/2]

it_const_rpaths LIEF::MachO::Binary::rpaths ( ) const

◆ section_from_offset() [1/2]

Section * LIEF::MachO::Binary::section_from_offset ( uint64_t offset)
inline

Return the MachO::Section that encompasses the provided offset. If a section can't be found, it returns a null pointer (nullptr)

◆ section_from_offset() [2/2]

const Section * LIEF::MachO::Binary::section_from_offset ( uint64_t offset) const

◆ section_from_virtual_address() [1/2]

Section * LIEF::MachO::Binary::section_from_virtual_address ( uint64_t virtual_address)
inline

Return the MachO::Section that encompasses the provided virtual address. If a section can't be found, it returns a null pointer (nullptr)

◆ section_from_virtual_address() [2/2]

const Section * LIEF::MachO::Binary::section_from_virtual_address ( uint64_t virtual_address) const

◆ sections() [1/2]

it_sections LIEF::MachO::Binary::sections ( )
inline

Return an iterator over the MachO::Section.

◆ sections() [2/2]

it_const_sections LIEF::MachO::Binary::sections ( ) const
inline

◆ segment_from_offset() [1/2]

SegmentCommand * LIEF::MachO::Binary::segment_from_offset ( uint64_t offset)
inline

Return the binary's SegmentCommand that encompasses the provided offset.

If a SegmentCommand can't be found it returns a null pointer (nullptr).

◆ segment_from_offset() [2/2]

const SegmentCommand * LIEF::MachO::Binary::segment_from_offset ( uint64_t offset) const

◆ segment_from_virtual_address() [1/2]

SegmentCommand * LIEF::MachO::Binary::segment_from_virtual_address ( uint64_t virtual_address)
inline

Return the binary's SegmentCommand which encompasses the given virtual address or a nullptr if not found.

◆ segment_from_virtual_address() [2/2]

const SegmentCommand * LIEF::MachO::Binary::segment_from_virtual_address ( uint64_t virtual_address) const

◆ segment_index()

size_t LIEF::MachO::Binary::segment_index ( const SegmentCommand & segment) const

Return the index of the given SegmentCommand.

◆ segment_split_info() [1/2]

SegmentSplitInfo * LIEF::MachO::Binary::segment_split_info ( )

Return the MachO::SegmentSplitInfo if present, a nullptr otherwise.

◆ segment_split_info() [2/2]

const SegmentSplitInfo * LIEF::MachO::Binary::segment_split_info ( ) const

◆ segments() [1/2]

it_segments LIEF::MachO::Binary::segments ( )
inline

Return an iterator over the SegmentCommand.

◆ segments() [2/2]

it_const_segments LIEF::MachO::Binary::segments ( ) const
inline

◆ shift()

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.

◆ shift_linkedit()

ok_error_t LIEF::MachO::Binary::shift_linkedit ( size_t width)

Shift the position on the __LINKEDIT data by width

◆ sort_segments()

void LIEF::MachO::Binary::sort_segments ( )

◆ source_version() [1/2]

SourceVersion * LIEF::MachO::Binary::source_version ( )

Return the MachO::SourceVersion command if present, a nullptr otherwise.

◆ source_version() [2/2]

const SourceVersion * LIEF::MachO::Binary::source_version ( ) const

◆ sub_framework() [1/2]

SubFramework * LIEF::MachO::Binary::sub_framework ( )

Return the MachO::SubFramework if present, a nullptr otherwise.

◆ sub_framework() [2/2]

const SubFramework * LIEF::MachO::Binary::sub_framework ( ) const

◆ subclients() [1/2]

it_sub_clients LIEF::MachO::Binary::subclients ( )

Iterator over all the MachO::SubClient commands.

◆ subclients() [2/2]

it_const_sub_clients LIEF::MachO::Binary::subclients ( ) const

◆ support_arm64_ptr_auth()

bool LIEF::MachO::Binary::support_arm64_ptr_auth ( ) const
inline

Check if the binary is supporting ARM64 pointer authentication (arm64e)

◆ symbol_command() [1/2]

SymbolCommand * LIEF::MachO::Binary::symbol_command ( )

Return the MachO::SymbolCommand if present, a nullptr otherwise.

◆ symbol_command() [2/2]

const SymbolCommand * LIEF::MachO::Binary::symbol_command ( ) const

◆ symbol_stubs()

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

◆ symbols() [1/2]

it_symbols LIEF::MachO::Binary::symbols ( )
inline

Return binary's symbols .

◆ symbols() [2/2]

it_const_symbols LIEF::MachO::Binary::symbols ( ) const
inline

◆ thread_command() [1/2]

ThreadCommand * LIEF::MachO::Binary::thread_command ( )

Return the MachO::ThreadCommand command if present, a nullptr otherwise.

◆ thread_command() [2/2]

const ThreadCommand * LIEF::MachO::Binary::thread_command ( ) const

◆ two_level_hints() [1/2]

TwoLevelHints * LIEF::MachO::Binary::two_level_hints ( )
inline

Return the MachO::DyldChainedFixups if present, a nullptr otherwise.

◆ two_level_hints() [2/2]

const TwoLevelHints * LIEF::MachO::Binary::two_level_hints ( ) const

◆ unexport() [1/2]

bool LIEF::MachO::Binary::unexport ( const std::string & name)

Remove the given MachO::Symbol with the given name from the export table.

◆ unexport() [2/2]

bool LIEF::MachO::Binary::unexport ( const Symbol & sym)

Remove the given symbol from the export table.

◆ unwind_functions()

LIEF::Binary::functions_t LIEF::MachO::Binary::unwind_functions ( ) const

Return the functions found in the __unwind_info section.

◆ uuid() [1/2]

UUIDCommand * LIEF::MachO::Binary::uuid ( )

Return the MachO::UUIDCommand if present, a nullptr otherwise.

◆ uuid() [2/2]

const UUIDCommand * LIEF::MachO::Binary::uuid ( ) const

◆ va_ranges()

range_t LIEF::MachO::Binary::va_ranges ( ) const

Return the range of virtual addresses.

◆ version_min() [1/2]

VersionMin * LIEF::MachO::Binary::version_min ( )

Return the MachO::VersionMin command if present, a nullptr otherwise.

◆ version_min() [2/2]

const VersionMin * LIEF::MachO::Binary::version_min ( ) const

◆ virtual_address_to_offset()

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.

◆ virtual_size()

uint64_t LIEF::MachO::Binary::virtual_size ( ) const
inline

Size of the binary in memory when mapped by the loader (dyld)

References LIEF::align().

◆ write() [1/3]

void LIEF::MachO::Binary::write ( const std::string & filename)
overridevirtual

Reconstruct the binary object and write the result in the given filename

Parameters
filenamePath to write the reconstructed binary

Implements LIEF::Binary.

◆ write() [2/3]

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

Parameters
filenamePath to write the reconstructed binary
configBuilder configuration

◆ write() [3/3]

void LIEF::MachO::Binary::write ( std::ostream & os)
overridevirtual

Reconstruct the binary object and write the result in the given os stream.

Parameters
osOutput stream to write the reconstructed binary

Implements LIEF::Binary.


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