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

Class which represents a MachO binary. More...

#include <Binary.hpp>

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

Classes

struct  KeyCmp
 
struct  range_t
 

Public Types

using commands_t = std::vector<std::unique_ptr<LoadCommand>>
 Internal container for storing Mach-O LoadCommand.
 
using it_commands = ref_iterator<commands_t&, LoadCommand*>
 Iterator that outputs LoadCommand&.
 
using it_const_commands = const_ref_iterator<const commands_t&, LoadCommand*>
 Iterator that outputs const LoadCommand&.
 
using symbols_t = std::vector<std::unique_ptr<Symbol>>
 Internal container for storing Mach-O Symbol.
 
using it_symbols = ref_iterator<symbols_t&, Symbol*>
 Iterator that outputs Symbol&.
 
using it_const_symbols = const_ref_iterator<const symbols_t&, const Symbol*>
 Iterator that outputs const Symbol&.
 
using it_exported_symbols = filter_iterator<symbols_t&, Symbol*>
 Iterator that outputs exported Symbol&.
 
using it_const_exported_symbols = const_filter_iterator<const symbols_t&, const Symbol*>
 Iterator that outputs exported const Symbol&.
 
using it_imported_symbols = filter_iterator<symbols_t&, Symbol*>
 Iterator that outputs imported Symbol&.
 
using it_const_imported_symbols = const_filter_iterator<const symbols_t&, const Symbol*>
 Iterator that outputs imported const Symbol&.
 
using sections_cache_t = std::vector<Section*>
 Internal container for caching Mach-O Section.
 
using it_sections = ref_iterator<sections_cache_t&>
 Iterator that outputs Section&.
 
using it_const_sections = const_ref_iterator<const sections_cache_t&>
 Iterator that outputs const Section&.
 
using segments_cache_t = std::vector<SegmentCommand*>
 Internal container for storing Mach-O SegmentCommand.
 
using it_segments = ref_iterator<segments_cache_t&>
 Iterator that outputs SegmentCommand&.
 
using it_const_segments = const_ref_iterator<const segments_cache_t&>
 Iterator that outputs const SegmentCommand&.
 
using libraries_cache_t = std::vector<DylibCommand*>
 Internal container for storing Mach-O DylibCommand.
 
using it_libraries = ref_iterator<libraries_cache_t&>
 Iterator that outputs DylibCommand&.
 
using it_const_libraries = const_ref_iterator<const libraries_cache_t&>
 Iterator that outputs const DylibCommand&.
 
using fileset_binaries_t = std::vector<std::unique_ptr<Binary>>
 Internal container for storing Mach-O Fileset Binary.
 
using it_fileset_binaries = ref_iterator<fileset_binaries_t&, Binary*>
 Iterator that outputs Binary&.
 
using it_const_fileset_binaries = const_ref_iterator<const fileset_binaries_t&, Binary*>
 Iterator that outputs const Binary&.
 
using relocations_t = std::set<Relocation*, KeyCmp>
 Internal container that store all the relocations found in a Mach-O. The relocations are actually owned by Section & SegmentCommand and these references are used for convenience.
 
using it_relocations = ref_iterator<relocations_t&, Relocation*>
 Iterator which outputs Relocation&.
 
using it_const_relocations = const_ref_iterator<const relocations_t&, const Relocation*>
 Iterator which outputs const Relocation&.
 
using it_rpaths = filter_iterator<commands_t&, RPathCommand*>
 Iterator which outputs RPathCommand&.
 
using it_const_rpaths = const_filter_iterator<const commands_t&, const RPathCommand*>
 Iterator which outputs const RPathCommand&.
 
- Public Types inherited from LIEF::Binary
enum class  VA_TYPES { AUTO = 0 , RVA = 1 , VA = 2 }
 Type of a virtual address. More...
 
enum  FORMATS {
  UNKNOWN = 0 , ELF , PE , MACHO ,
  OAT
}
 
using functions_t = std::vector<Function>
 
using sections_t = std::vector<Section*>
 Internal container.
 
using it_sections = ref_iterator<sections_t>
 Iterator that outputs LIEF::Section&.
 
using it_const_sections = const_ref_iterator<sections_t>
 Iterator that outputs const LIEF::Section&.
 
using symbols_t = std::vector<Symbol*>
 Internal container.
 
using it_symbols = ref_iterator<symbols_t>
 Iterator that outputs LIEF::Symbol&.
 
using it_const_symbols = const_ref_iterator<symbols_t>
 Iterator that outputs const LIEF::Symbol&.
 
using relocations_t = std::vector<Relocation*>
 Internal container.
 
using it_relocations = ref_iterator<relocations_t>
 Iterator that outputs LIEF::Relocation&.
 
using it_const_relocations = const_ref_iterator<relocations_t>
 Iterator that outputs const LIEF::Relocation&.
 
- Public Types inherited from LIEF::Object
template<class T >
using output_t = add_pointer_t<decay_t<T>>
 
template<class T >
using output_const_t = add_pointer_t<add_const_t<decay_t<T>>>
 

Public Member Functions

 Binary (const Binary &)=delete
 
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 LOAD_COMMAND_TYPES::LC_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 (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 (LOAD_COMMAND_TYPES type) const
 Check if the current binary has the given MachO::LOAD_COMMAND_TYPES.
 
const LoadCommandget (LOAD_COMMAND_TYPES type) const
 Return the LoadCommand associated with the given LOAD_COMMAND_TYPES or a nullptr if the command can't be found.
 
LoadCommandget (LOAD_COMMAND_TYPES type)
 
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 (LOAD_COMMAND_TYPES type)
 Remove all LoadCommand with the given type (MachO::LOAD_COMMAND_TYPES)
 
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_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
 
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
 
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.
 
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[] (LOAD_COMMAND_TYPES type)
 
const LoadCommandoperator[] (LOAD_COMMAND_TYPES 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 LOAD_COMMAND_TYPES::LC_FILESET_ENTRY command
 
const std::string & fileset_name () const
 Name associated with the LC_FILESET_ENTRY binary.
 
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.
 
uint32_t page_size () const
 
- Public Member Functions inherited from LIEF::Binary
 Binary (FORMATS fmt)
 
Binaryoperator= (const Binary &)
 
 Binary (const Binary &)
 
FORMATS format () const
 Executable format (ELF, PE, Mach-O) of the underlying binary.
 
Header header () const
 Return the abstract header of the binary.
 
it_symbols symbols ()
 Return an iterator over the abstracted symbols in which the elements can be modified.
 
it_const_symbols symbols () const
 Return an iterator over the abstracted symbols in which the elements can't be modified.
 
bool has_symbol (const std::string &name) const
 Check if a Symbol with the given name exists.
 
const Symbolget_symbol (const std::string &name) const
 Return the Symbol with the given name If the symbol does not exist, return a nullptr.
 
Symbolget_symbol (const std::string &name)
 
it_sections sections ()
 Return an iterator over the binary's sections (LIEF::Section)
 
it_const_sections sections () const
 
it_relocations relocations ()
 Return an iterator over the binary relocation (LIEF::Relocation)
 
it_const_relocations relocations () const
 
uint64_t original_size () const
 Binary's original size.
 
functions_t exported_functions () const
 Return the functions exported by the binary.
 
std::vector< std::string > imported_libraries () const
 Return libraries which are imported by the binary.
 
functions_t imported_functions () const
 Return functions imported by the binary.
 
virtual result< uint64_t > get_function_address (const std::string &func_name) const
 Return the address of the given function name.
 
std::vector< uint64_t > xref (uint64_t address) const
 
void original_size (uint64_t size)
 Change binary's original size.
 
- Public Member Functions inherited from LIEF::Object
 Object (const Object &other)
 
Objectoperator= (const Object &other)
 
template<class T >
output_t< T > as ()
 
template<class T >
output_const_t< T > as () const
 
virtual bool operator== (const Object &other) const
 
virtual bool operator!= (const Object &other) const
 

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)
 

Detailed Description

Class which represents a MachO binary.

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_section()

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

◆ ctor_functions()

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

Return the list of the MachO's constructors.

Implements LIEF::Binary.

◆ entrypoint()

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

The binary entrypoint.

Implements LIEF::Binary.

◆ 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.

◆ has_entrypoint()

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

true if the binary has an entrypoint.

Basically for libraries it will return false

◆ has_nx()

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

Check if the binary uses NX protection.

Implements LIEF::Binary.

◆ imagebase()

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

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

Implements LIEF::Binary.

◆ is_pie()

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

Check if the binary is position independent.

Implements LIEF::Binary.

◆ 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

◆ 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.

◆ 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.

◆ print()

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

Reimplemented from LIEF::Binary.

◆ 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

◆ segment_from_offset()

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

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

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

◆ write() [1/2]

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/2]

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: