LIEF: Library to Instrument Executable Formats Version 0.17.0
|
Loading...
Searching...
No Matches
Go to the documentation of this file.
16#ifndef LIEF_MACHO_BINARY_H
17#define LIEF_MACHO_BINARY_H
89 friend class BinaryParser;
91 friend class DyldInfo;
92 friend class BindingInfoIterator;
107 using commands_t = std::vector<std::unique_ptr<LoadCommand>>;
110 using it_commands = ref_iterator<commands_t&, LoadCommand*>;
113 using it_const_commands = const_ref_iterator<const commands_t&, LoadCommand*>;
116 using symbols_t = std::vector<std::unique_ptr<Symbol>>;
119 using it_symbols = ref_iterator<symbols_t&, Symbol*>;
122 using it_const_symbols = const_ref_iterator<const symbols_t&, const Symbol*>;
125 using it_exported_symbols = filter_iterator<symbols_t&, Symbol*>;
128 using it_const_exported_symbols = const_filter_iterator<const symbols_t&, const Symbol*>;
131 using it_imported_symbols = filter_iterator<symbols_t&, Symbol*>;
134 using it_const_imported_symbols = const_filter_iterator<const symbols_t&, const Symbol*>;
137 using sections_cache_t = std::vector<Section*>;
140 using it_sections = ref_iterator<sections_cache_t&>;
143 using it_const_sections = const_ref_iterator<const sections_cache_t&>;
146 using segments_cache_t = std::vector<SegmentCommand*>;
149 using it_segments = ref_iterator<segments_cache_t&>;
152 using it_const_segments = const_ref_iterator<const segments_cache_t&>;
155 using libraries_cache_t = std::vector<DylibCommand*>;
158 using it_libraries = ref_iterator<libraries_cache_t&>;
161 using it_const_libraries = const_ref_iterator<const libraries_cache_t&>;
164 using fileset_binaries_t = std::vector<std::unique_ptr<Binary>>;
167 using it_fileset_binaries = ref_iterator<fileset_binaries_t&, Binary*>;
170 using it_const_fileset_binaries = const_ref_iterator<const fileset_binaries_t&, Binary*>;
175 bool operator() (
const Relocation* lhs,
const Relocation* rhs)
const;
177 using relocations_t = std::set<Relocation*, KeyCmp>;
182 using it_relocations = ref_iterator<relocations_t&, Relocation*>;
185 using it_const_relocations = const_ref_iterator<const relocations_t&, const Relocation*>;
188 using it_rpaths = filter_iterator<commands_t&, RPathCommand*>;
191 using it_const_rpaths = const_filter_iterator<const commands_t&, const RPathCommand*>;
194 using it_sub_clients = filter_iterator<commands_t&, SubClient*>;
197 using it_const_sub_clients = const_filter_iterator<const commands_t&, const SubClient*>;
201 using it_bindings = iterator_range<BindingInfoIterator>;
202 using stub_iterator = iterator_range<Stub::Iterator>;
246 bool has_symbol(
const std::string& name)
const {
249 return get_symbol(name) !=
nullptr;
251 const Symbol*
get_symbol(
const std::string& name)
const;
256 return const_cast<Symbol*
>(
static_cast<const Binary*
>(
this)->get_symbol(name));
264 return {symbols_, [] (
const std::unique_ptr<Symbol>& symbol) {
265 return is_exported(*symbol); }
269 return {symbols_, [] (
const std::unique_ptr<Symbol>& symbol) {
270 return is_exported(*symbol);
279 return {symbols_, [] (
const std::unique_ptr<Symbol>& symbol) {
280 return is_imported(*symbol);
285 return {symbols_, [] (
const std::unique_ptr<Symbol>& symbol) {
286 return is_imported(*symbol);
318 void write(
const std::string& filename);
323 void write(
const std::string& filename, Builder::config_t config);
332 void write(std::ostream& os);
337 void write(std::ostream& os, Builder::config_t config);
344 std::vector<uint8_t>
raw();
347 bool has(LoadCommand::TYPE type)
const;
350 const LoadCommand*
get(LoadCommand::TYPE type)
const;
354 LoadCommand*
get(LoadCommand::TYPE type) {
355 return const_cast<LoadCommand*
>(
static_cast<const Binary*
>(
this)->get(type));
358 LoadCommand*
add(std::unique_ptr<LoadCommand> command);
359 LoadCommand*
add(
const LoadCommand& command) {
362 return add(command.
clone());
364 LoadCommand*
add(
const LoadCommand& command,
size_t index);
367 LoadCommand*
add(
const DylibCommand& library);
370 LoadCommand*
add(
const SegmentCommand& segment);
379 Section*
add_section(
const SegmentCommand& segment,
const Section& section);
385 void remove_section(
const std::string& name,
bool clear =
false)
override;
391 void remove_section(
const std::string& segname,
const std::string& secname,
bool clear =
false);
400 bool remove(
const LoadCommand& command);
403 bool remove(LoadCommand::TYPE type);
412 bool extend(
const LoadCommand& command, uint64_t size);
434 return align(va_ranges().size(), (uint64_t)page_size());
436 std::string
loader()
const;
443 return get_section(name) !=
nullptr;
449 return const_cast<Section*
>(
static_cast<const Binary*
>(
this)->get_section(name));
451 const Section*
get_section(
const std::string& name)
const;
455 Section*
get_section(
const std::string& segname,
const std::string& secname) {
460 return const_cast<Section*
>(
static_cast<const Binary*
>(
this)->get_section(segname, secname));
463 const Section*
get_section(
const std::string& segname,
const std::string& secname)
const;
467 return get_segment(name) !=
nullptr;
469 const SegmentCommand*
get_segment(
const std::string& name)
const;
472 SegmentCommand*
get_segment(
const std::string& name) {
475 return const_cast<SegmentCommand*
>(
static_cast<const Binary*
>(
this)->get_segment(name));
480 bool remove(
const Symbol& sym);
489 bool unexport(
const std::string& name);
499 return const_cast<Section*
>(
static_cast<const Binary*
>(
this)->section_from_offset(offset));
506 return const_cast<Section*
>(
static_cast<const Binary*
>(
this)->section_from_virtual_address(virtual_address));
523 return const_cast<SegmentCommand*
>(
static_cast<const Binary*
>(
this)->segment_from_offset(offset));
538 return const_cast<SegmentCommand*
>(
static_cast<const Binary*
>(
this)->segment_from_virtual_address(virtual_address));
551 const range_t& r = va_ranges();
552 return r.
start <= address && address < r.
end;
554 void accept(LIEF::Visitor& visitor)
const override;
558 std::ostream&
print(std::ostream& os)
const override;
559 void patch_address(uint64_t address,
const std::vector<uint8_t>& patch_value,
577 size_t size =
sizeof(uint64_t),
582 uint64_t virtual_address, uint64_t size,
583 Binary::VA_TYPES addr_type = Binary::VA_TYPES::AUTO)
const override;
587 bool is_pie()
const override {
590 return header().has(Header::FLAGS::PIE);
592 bool has_nx()
const override {
595 return has_nx_stack();
600 return !header().has(Header::FLAGS::ALLOW_STACK_EXECUTION);
605 return !header().has(Header::FLAGS::NO_HEAP_EXECUTION);
612 return has_main_command() || has_thread_command();
617 return uuid() !=
nullptr;
622 const UUIDCommand*
uuid()
const;
626 return main_command() !=
nullptr;
635 return dylinker() !=
nullptr;
644 return dyld_info() !=
nullptr;
653 return function_starts() !=
nullptr;
662 return source_version() !=
nullptr;
671 return version_min() !=
nullptr;
680 return thread_command() !=
nullptr;
689 return routine_command() !=
nullptr;
698 return rpath() !=
nullptr;
700 RPathCommand*
rpath();
711 return symbol_command() !=
nullptr;
720 return dynamic_symbol_command() !=
nullptr;
729 return code_signature() !=
nullptr;
734 return const_cast<CodeSignature*
>(
static_cast<const Binary*
>(
this)->code_signature());
740 return code_signature_dir() !=
nullptr;
745 return const_cast<CodeSignatureDir*
>(
static_cast<const Binary*
>(
this)->code_signature_dir());
751 return data_in_code() !=
nullptr;
760 return segment_split_info() !=
nullptr;
769 return sub_framework() !=
nullptr;
774 return encryption_info() !=
nullptr;
793 return dyld_environment() !=
nullptr;
802 return build_version() !=
nullptr;
808 BuildVersion::PLATFORMS
platform()
const {
811 if (
const BuildVersion* version = build_version()) {
812 return version->platform();
814 return BuildVersion::PLATFORMS::UNKNOWN;
819 return platform() == BuildVersion::PLATFORMS::IOS ||
820 has(LoadCommand::TYPE::VERSION_MIN_IPHONEOS);
825 return platform() == BuildVersion::PLATFORMS::MACOS ||
826 has(LoadCommand::TYPE::VERSION_MIN_MACOSX);
832 return dyld_chained_fixups() !=
nullptr;
841 return dyld_exports_trie() !=
nullptr;
850 return two_level_hints() !=
nullptr;
855 return const_cast<TwoLevelHints*
>(
static_cast<const Binary*
>(
this)->two_level_hints());
861 return linker_opt_hint() !=
nullptr;
866 return const_cast<LinkerOptHint*
>(
static_cast<const Binary*
>(
this)->linker_opt_hint());
889 return atom_info() !=
nullptr;
894 return const_cast<AtomInfo*
>(
static_cast<const Binary*
>(
this)->atom_info());
910 template<
class CMD,
class Func>
916 const LoadCommand*
operator[](LoadCommand::TYPE type)
const {
931 return filesets_.empty();
936 return fileset_name_;
938 Symbol&
add(
const Symbol& symbol);
956 return in_memory_base_addr_;
961 return header().cpu_type() == Header::CPU_TYPE::ARM64 &&
962 (header().cpu_subtype() & ~Header::SUBTYPE_MASK) == Header::CPU_SUBTYPE_ARM64_ARM64E;
971 static bool classof(
const LIEF::Binary* bin) {
972 return bin->
format() == Binary::FORMATS::MACHO;
984 LIEF_LOCAL size_t available_command_space()
const {
987 return available_command_space_;
994 LIEF_LOCAL void shift_command(
size_t width, uint64_t from_offset);
995 LIEF_LOCAL size_t add_cached_segment(SegmentCommand& segment);
1004 LIEF::Header get_abstract_header()
const override {
1013 LIEF_LOCAL std::vector<std::string> get_abstract_imported_libraries()
const override;
1014 ok_error_t ensure_command_space(
size_t size) {
1019 return available_command_space_ < size ? shift(size) :
ok();
1022 relocations_t& relocations_list() {
1023 return this->relocations_;
1026 const relocations_t& relocations_list()
const {
1027 return this->relocations_;
1030 size_t pointer_size()
const {
1031 return this->is64_ ?
sizeof(uint64_t) : sizeof(uint32_t);
1036 commands_t commands_;
1040 libraries_cache_t libraries_;
1044 sections_cache_t sections_;
1047 segments_cache_t segments_;
1049 fileset_binaries_t filesets_;
1052 mutable relocations_t relocations_;
1053 size_t available_command_space_ = 0;
1057 std::map<uint64_t, SegmentCommand*> offset_seg_;
1060 uint64_t fat_offset_ = 0;
1061 uint64_t fileset_offset_ = 0;
1062 uint64_t in_memory_base_addr_ = 0;
1063 std::string fileset_name_;
1064 std::vector<uint8_t> overlay_;
1065 std::vector<std::unique_ptr<IndirectBindingInfo>> indirect_bindings_;
std::vector< Function > functions_t
Definition Abstract/Binary.hpp:70
FORMATS format() const
Executable format (ELF, PE, Mach-O) of the underlying binary.
Definition Abstract/Binary.hpp:112
std::vector< Symbol * > symbols_t
Internal container.
Definition Abstract/Binary.hpp:82
VA_TYPES
Type of a virtual address.
Definition Abstract/Binary.hpp:56
@ AUTO
Try to guess if it's relative or not.
Definition Abstract/Binary.hpp:57
std::vector< Section * > sections_t
Internal container.
Definition Abstract/Binary.hpp:73
std::vector< Relocation * > relocations_t
Internal container.
Definition Abstract/Binary.hpp:91
Class which represents the LC_ATOM_INFO command.
Definition AtomInfo.hpp:36
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:75
Class which represents a MachO binary.
Definition MachO/Binary.hpp:86
Symbol * add_local_symbol(uint64_t address, const std::string &name)
Add a symbol in LC_SYMTAB command of the current binary.
UUIDCommand * uuid()
Return the MachO::UUIDCommand if present, a nullptr otherwise.
bool has_build_version() const
true if the binary has the BuildVersion command.
Definition MachO/Binary.hpp:801
std::vector< uint8_t > raw()
Reconstruct the binary object and return its content as bytes.
size_t count_commands() const
static bool classof(const LIEF::Binary *bin)
Definition MachO/Binary.hpp:971
bool is_pie() const override
Check if the binary is position independent.
Definition MachO/Binary.hpp:589
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...
bool has_function_starts() const
true if the binary has a MachO::FunctionStarts command.
Definition MachO/Binary.hpp:652
uint64_t entrypoint() const override
The binary entrypoint.
bool has_segment_split_info() const
true if the binary has segment split info.
Definition MachO/Binary.hpp:759
it_imported_symbols imported_symbols()
Return binary's imported symbols (iterator over LIEF::MachO::Symbol)
Definition MachO/Binary.hpp:278
const ThreadCommand * thread_command() const
Section * section_from_offset(uint64_t offset)
Return the MachO::Section that encompasses the provided offset. If a section can't be found,...
Definition MachO/Binary.hpp:498
const SegmentSplitInfo * segment_split_info() const
const Section * section_from_offset(uint64_t offset) const
bool has_source_version() const
true if the binary has a MachO::SourceVersion command.
Definition MachO/Binary.hpp:661
const SegmentCommand * get_segment(const std::string &name) const
Return the segment from the given name.
const UUIDCommand * uuid() const
it_commands commands()
Return an iterator over the MachO LoadCommand present in the binary.
Definition MachO/Binary.hpp:221
range_t off_ranges() const
Return the range of offsets.
const DataInCode * data_in_code() const
result< uint64_t > offset_to_virtual_address(uint64_t offset, uint64_t slide=0) const override
Convert the given offset into a virtual address.
const SegmentCommand * segment_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.
bool has_atom_info() const
true if the binary has the command LC_ATOM_INFO.
Definition MachO/Binary.hpp:888
bool has_dynamic_symbol_command() const
true if the binary has a MachO::DynamicSymbolCommand command.
Definition MachO/Binary.hpp:719
const DyldInfo * dyld_info() const
TwoLevelHints * two_level_hints()
Return the MachO::DyldChainedFixups if present, a nullptr otherwise.
Definition MachO/Binary.hpp:854
bool is_valid_addr(uint64_t address) const
Check if the given address is encompassed in the binary's virtual addresses range.
Definition MachO/Binary.hpp:550
void write(const std::string &filename)
Reconstruct the binary object and write the result in the given filename
LoadCommand * add(const DylibCommand &library)
Insert the given DylibCommand.
DylinkerCommand * dylinker()
Return the MachO::DylinkerCommand if present, a nullptr otherwise.
bool has_dylinker() const
true if the binary has a MachO::DylinkerCommand.
Definition MachO/Binary.hpp:634
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...
Definition MachO/Binary.hpp:459
const VersionMin * version_min() const
bool has_dyld_chained_fixups() const
true if the binary has the command LC_DYLD_CHAINED_FIXUPS.
Definition MachO/Binary.hpp:831
it_sub_clients subclients()
Iterator over all the MachO::SubClient commands.
bool has_dyld_info() const
true if the binary has a MachO::DyldInfo command.
Definition MachO/Binary.hpp:643
EncryptionInfo * encryption_info()
Return the MachO::DyldEnvironment if present, a nullptr otherwise.
DataInCode * data_in_code()
Return the MachO::DataInCode if present, a nullptr otherwise.
bool extend_section(Section §ion, size_t size)
Extend the content of the given Section.
const TwoLevelHints * two_level_hints() const
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 loade...
bool has_symbol(const std::string &name) const
Check if a symbol with the given name exists.
Definition MachO/Binary.hpp:248
BuildVersion * build_version()
Return the MachO::BuildVersion if present, a nullptr otherwise.
bool has_symbol_command() const
true if the binary has a MachO::SymbolCommand command.
Definition MachO/Binary.hpp:710
const LoadCommand * operator[](LoadCommand::TYPE type) const
Definition MachO/Binary.hpp:916
size_t segment_index(const SegmentCommand &segment) const
Return the index of the given SegmentCommand.
bool has_rpath() const
true if the binary has a MachO::RPathCommand command.
Definition MachO/Binary.hpp:697
it_const_fileset_binaries filesets() const
Definition MachO/Binary.hpp:235
ok_error_t shift_linkedit(size_t width)
Shift the position on the __LINKEDIT data by width
it_relocations relocations()
Return an iterator over the MachO::Relocation.
bool extend(const LoadCommand &command, uint64_t size)
Extend the size of the given LoadCommand.
VersionMin * version_min()
Return the MachO::VersionMin command if present, a nullptr otherwise.
bool remove_signature()
Remove the LC_SIGNATURE command.
bool has_nx() const override
Check if the binary uses NX protection.
Definition MachO/Binary.hpp:594
bool can_remove(const Symbol &sym) const
Check if the given symbol can be safely removed.
void write(std::ostream &os)
Reconstruct the binary object and write the result in the given os stream.
it_const_sub_clients subclients() const
const SourceVersion * source_version() const
it_bindings bindings() const
Return an iterator over the binding info which can come from either DyldInfo or DyldChainedFixups com...
bool has_routine_command() const
true if the binary has a MachO::Routine command.
Definition MachO/Binary.hpp:688
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...
uint64_t imagebase() const override
Return the binary's imagebase. 0 if not relevant.
std::ostream & print(std::ostream &os) const override
bool is_macos() const
True if this binary targets macOS.
Definition MachO/Binary.hpp:824
bool disable_pie()
Remove the PIE flag.
bool can_remove_symbol(const std::string &name) const
Check if the MachO::Symbol with the given name can be safely removed.
ThreadCommand * thread_command()
Return the MachO::ThreadCommand command if present, a nullptr otherwise.
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,...
Definition MachO/Binary.hpp:505
static bool can_cache_segment(const SegmentCommand &segment)
Check if the given segment can go in the offset_seg_ cache.
bool has_segment(const std::string &name) const
Check if a segment with the given name exists.
Definition MachO/Binary.hpp:466
bool has_uuid() const
true if the binary has a MachO::UUIDCommand command.
Definition MachO/Binary.hpp:616
const Section * section_from_virtual_address(uint64_t virtual_address) const
bool remove_symbol(const std::string &name)
Remove the symbol with the given name.
DyldExportsTrie * dyld_exports_trie()
Return the MachO::DyldChainedFixups if present, a nullptr otherwise.
const DyldEnvironment * dyld_environment() const
it_const_sections sections() const
Definition MachO/Binary.hpp:311
it_const_symbols symbols() const
Definition MachO/Binary.hpp:243
void accept(LIEF::Visitor &visitor) const override
Method so that the visitor can visit us.
bool has_dyld_exports_trie() const
true if the binary has the command LC_DYLD_CHAINED_FIXUPS.
Definition MachO/Binary.hpp:840
bool remove(LoadCommand::TYPE type)
Remove all LoadCommand with the given type (MachO::LoadCommand::TYPE)
const Routine * routine_command() const
it_symbols symbols()
Return binary's symbols .
Definition MachO/Binary.hpp:240
LoadCommand * operator[](LoadCommand::TYPE type)
Definition MachO/Binary.hpp:913
bool has_subclients() const
bool has_linker_opt_hint() const
true if the binary has the command LC_LINKER_OPTIMIZATION_HINT.
Definition MachO/Binary.hpp:860
const DyldChainedFixups * dyld_chained_fixups() const
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 ne...
LIEF::Binary::functions_t ctor_functions() const override
Return the list of the MachO's constructors.
std::unique_ptr< objc::Metadata > objc_metadata() const
Return Objective-C metadata if present.
const FunctionStarts * function_starts() const
void refresh_seg_offset()
it_segments segments()
Return an iterator over the SegmentCommand.
Definition MachO/Binary.hpp:300
Binary(const Binary &)=delete
Section * get_section(const std::string &name)
Return the section from the given name of a nullptr if the section can't be found.
Definition MachO/Binary.hpp:448
it_fileset_binaries filesets()
Return an iterator over the MachO::Binary associated with the LoadCommand::TYPE::FILESET_ENTRY comman...
Definition MachO/Binary.hpp:231
Binary & operator=(const Binary &)=delete
it_const_segments segments() const
Definition MachO/Binary.hpp:303
bool has_nx_stack() const
Return True if the stack is flagged as non-executable. False otherwise.
Definition MachO/Binary.hpp:599
it_libraries libraries()
Return binary imported libraries (MachO::DylibCommand)
Definition MachO/Binary.hpp:291
bool has_data_in_code() const
true if the binary has a MachO::DataInCode command.
Definition MachO/Binary.hpp:750
const SubFramework * sub_framework() const
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.
static bool is_exported(const Symbol &symbol)
Check if the given symbol is exported.
Section * add_section(const Section §ion)
Add a new MachO::Section in the __TEXT segment.
const SegmentCommand * segment_from_offset(uint64_t offset) const
void write(const std::string &filename, Builder::config_t config)
Reconstruct the binary object and write the result in the given filename.
it_exported_symbols exported_symbols()
Return binary's exported symbols (iterator over LIEF::MachO::Symbol)
Definition MachO/Binary.hpp:263
const MainCommand * main_command() const
BuildVersion::PLATFORMS platform() const
Return the platform for which this Mach-O has been compiled for.
Definition MachO/Binary.hpp:810
it_const_relocations relocations() const
span< const uint8_t > overlay() const
Definition MachO/Binary.hpp:975
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 fo...
Definition MachO/Binary.hpp:537
DyldChainedFixups * dyld_chained_fixups()
Return the MachO::DyldChainedFixups if present, a nullptr otherwise.
const RPathCommand * rpath() const
const CodeSignature * code_signature() const
RPathCommand * rpath()
Return the MachO::RPathCommand command if present, a nullptr otherwise.
SegmentCommand * get_segment(const std::string &name)
Return the segment from the given name.
Definition MachO/Binary.hpp:474
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.
const CodeSignatureDir * code_signature_dir() const
bool extend_segment(const SegmentCommand &segment, size_t size)
Extend the content of the given SegmentCommand.
const DynamicSymbolCommand * dynamic_symbol_command() const
const T * command() const
SymbolCommand * symbol_command()
Return the MachO::SymbolCommand if present, a nullptr otherwise.
LinkerOptHint * linker_opt_hint()
Return the MachO::LinkerOptHint if present, a nullptr otherwise.
Definition MachO/Binary.hpp:865
uint64_t fat_offset() const
Return binary's fat offset. 0 if not relevant.
Definition MachO/Binary.hpp:531
const Header & header() const
Definition MachO/Binary.hpp:215
it_rpaths rpaths()
Iterator over all the MachO::RPathCommand commands.
bool has_nx_heap() const
Return True if the heap is flagged as non-executable. False otherwise.
Definition MachO/Binary.hpp:604
const AtomInfo * atom_info() const
uint32_t page_size() const
LoadCommand * add(const LoadCommand &command)
Insert a new LoadCommand.
Definition MachO/Binary.hpp:361
bool remove(const Symbol &sym)
Remove the given symbol.
bool has_version_min() const
true if the binary has a MachO::VersionMin command.
Definition MachO/Binary.hpp:670
DyldEnvironment * dyld_environment()
Return the MachO::DyldEnvironment if present, a nullptr otherwise.
bool remove(const LoadCommand &command)
Remove the given LoadCommand.
SourceVersion * source_version()
Return the MachO::SourceVersion command if present, a nullptr otherwise.
static bool is_imported(const Symbol &symbol)
Check if the given symbol is an imported one.
LoadCommand * add(const LoadCommand &command, size_t index)
Insert a new LoadCommand at the specified index
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.
CodeSignature * code_signature()
Return the MachO::CodeSignature if present, a nullptr otherwise.
Definition MachO/Binary.hpp:733
LoadCommand * add_library(const std::string &name)
Insert a new shared library through a LC_LOAD_DYLIB command.
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.
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.
bool remove_command(size_t index)
Remove the Load Command at the provided index
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 bina...
Definition MachO/Binary.hpp:955
bool has_sub_framework() const
true if the binary has a sub framework command.
Definition MachO/Binary.hpp:768
LIEF::Binary::functions_t functions() const
Return all the functions found in this MachO.
const LoadCommand * get(LoadCommand::TYPE type) const
Return the LoadCommand associated with the given LoadCommand::TYPE or a nullptr if the command can't ...
const LinkerOptHint * linker_opt_hint() const
FunctionStarts * function_starts()
Return the MachO::FunctionStarts command if present, a nullptr otherwise.
SegmentSplitInfo * segment_split_info()
Return the MachO::SegmentSplitInfo if present, a nullptr otherwise.
stub_iterator symbol_stubs() const
Return an iterator over the symbol stubs.
LoadCommand * add(const SegmentCommand &segment)
Add a new LC_SEGMENT command from the given SegmentCommand.
LoadCommand * get(LoadCommand::TYPE type)
Definition MachO/Binary.hpp:354
bool is_ios() const
True if this binary targets iOS.
Definition MachO/Binary.hpp:818
bool has_entrypoint() const
true if the binary has an entrypoint.
Definition MachO/Binary.hpp:611
bool has_two_level_hints() const
true if the binary has the command LC_TWO_LEVEL_HINTS.
Definition MachO/Binary.hpp:849
it_const_rpaths rpaths() const
DyldInfo * dyld_info()
Return the MachO::Dyld command if present, a nullptr otherwise.
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.
const EncryptionInfo * encryption_info() const
MainCommand * main_command()
Return the MachO::MainCommand if present, a nullptr otherwise.
bool has_encryption_info() const
true if the binary has Encryption Info.
Definition MachO/Binary.hpp:773
bool has(LoadCommand::TYPE type) const
Check if the current binary has the given MachO::LoadCommand::TYPE.
const DyldExportsTrie * dyld_exports_trie() const
uint64_t virtual_size() const
Size of the binary in memory when mapped by the loader (dyld)
Definition MachO/Binary.hpp:433
const SymbolCommand * symbol_command() const
range_t va_ranges() const
Return the range of virtual addresses.
DynamicSymbolCommand * dynamic_symbol_command()
Return the MachO::SymbolCommand if present, a nullptr otherwise.
bool has_code_signature_dir() const
true if the binary is signed with the command DYLIB_CODE_SIGN_DRS
Definition MachO/Binary.hpp:739
CodeSignatureDir * code_signature_dir()
Return the MachO::CodeSignatureDir if present, a nullptr otherwise.
Definition MachO/Binary.hpp:744
bool has_code_signature() const
true if the binary is signed with LC_CODE_SIGNATURE command
Definition MachO/Binary.hpp:728
AtomInfo * atom_info()
Return the MachO::AtomInfo if present, a nullptr otherwise.
Definition MachO/Binary.hpp:893
const Section * get_section(const std::string &segname, const std::string &secname) const
bool has_section(const std::string &name) const
Check if a section with the given name exists.
Definition MachO/Binary.hpp:442
it_const_imported_symbols imported_symbols() const
Definition MachO/Binary.hpp:284
bool has_main_command() const
true if the binary has a MachO::MainCommand command.
Definition MachO/Binary.hpp:625
Header & header()
Return a reference to the MachO::Header.
Definition MachO/Binary.hpp:211
ExportInfo * add_exported_function(uint64_t address, const std::string &name)
Add a symbol in the export trie of the current binary.
bool support_arm64_ptr_auth() const
Check if the binary is supporting ARM64 pointer authentication (arm64e)
Definition MachO/Binary.hpp:960
it_const_commands commands() const
Definition MachO/Binary.hpp:225
bool has_dyld_environment() const
true if the binary has Dyld envrionment variables.
Definition MachO/Binary.hpp:792
it_const_libraries libraries() const
Definition MachO/Binary.hpp:295
const std::string & fileset_name() const
Name associated with the LC_FILESET_ENTRY binary.
Definition MachO/Binary.hpp:935
Binary & for_commands(Func f)
bool has_filesets() const
true if the binary has a LoadCommand::TYPE::FILESET_ENTRY command
Definition MachO/Binary.hpp:930
Symbol * get_symbol(const std::string &name)
Definition MachO/Binary.hpp:255
SegmentCommand * segment_from_offset(uint64_t offset)
Return the binary's SegmentCommand that encompasses the provided offset.
Definition MachO/Binary.hpp:522
const DylinkerCommand * dylinker() const
LoadCommand * add(std::unique_ptr< LoadCommand > command)
bool unexport(const std::string &name)
Remove the given MachO::Symbol with the given name from the export table.
LIEF::Binary::functions_t unwind_functions() const
Return the functions found in the __unwind_info section.
it_const_exported_symbols exported_symbols() const
Definition MachO/Binary.hpp:268
bool has_thread_command() const
true if the binary has a MachO::ThreadCommand command.
Definition MachO/Binary.hpp:679
Symbol & add(const Symbol &symbol)
Add a symbol to this binary.
bool unexport(const Symbol &sym)
Remove the given symbol from the export table.
const BuildVersion * build_version() const
SubFramework * sub_framework()
Return the MachO::SubFramework if present, a nullptr otherwise.
Routine * routine_command()
Return the MachO::Routine command if present, a nullptr otherwise.
it_sections sections()
Return an iterator over the MachO::Section.
Definition MachO/Binary.hpp:308
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:60
Definition CodeSignatureDir.hpp:36
Definition CodeSignature.hpp:37
Interface of the LC_DATA_IN_CODE command This command is used to list slices of code sections that co...
Definition DataInCode.hpp:42
Class that represents the LC_DYLD_CHAINED_FIXUPS command.
Definition DyldChainedFixups.hpp:49
Class that represents a LC_DYLD_ENVIRONMENT command which is used by the Mach-O linker/loader to init...
Definition DyldEnvironment.hpp:34
Class that represents the LC_DYLD_EXPORTS_TRIE command.
Definition DyldExportsTrie.hpp:40
Class that represents the LC_DYLD_INFO and LC_DYLD_INFO_ONLY commands.
Definition DyldInfo.hpp:50
Class which represents a library dependency.
Definition DylibCommand.hpp:34
Class that represents the Mach-O linker, also named loader. Most of the time, DylinkerCommand::name()...
Definition DylinkerCommand.hpp:34
Class that represents the LC_DYSYMTAB command.
Definition DynamicSymbolCommand.hpp:40
Class that represents the LC_ENCRYPTION_INFO / LC_ENCRYPTION_INFO_64 commands.
Definition EncryptionInfo.hpp:35
Class that provides an interface over the Dyld export info.
Definition ExportInfo.hpp:38
Class which represents the LC_FUNCTION_STARTS command.
Definition FunctionStarts.hpp:39
This class represents a binding operation infered from the indirect symbol table.
Definition IndirectBindingInfo.hpp:29
Class which represents the LC_LINKER_OPTIMIZATION_HINT command.
Definition LinkerOptHint.hpp:37
virtual std::unique_ptr< LoadCommand > clone() const
Definition LoadCommand.hpp:118
Class that represent the LC_MAIN command. This kind of command can be used to determine the entrypoin...
Definition MainCommand.hpp:33
The main interface to parse a Mach-O binary.
Definition MachO/Parser.hpp:42
Class that represents the LC_RPATH command.
Definition RPathCommand.hpp:36
Class that represents a Mach-O relocation.
Definition MachO/Relocation.hpp:40
Class that represents the LC_ROUTINE/LC_ROUTINE64 commands. Accodring to the Mach-O loader....
Definition Routine.hpp:38
Class that represents a Mach-O section.
Definition MachO/Section.hpp:46
Class which represents a LoadCommand::TYPE::SEGMENT / LoadCommand::TYPE::SEGMENT_64 command.
Definition SegmentCommand.hpp:50
Class that represents the LoadCommand::TYPE::SEGMENT_SPLIT_INFO command.
Definition SegmentSplitInfo.hpp:35
Class that represents the MachO LoadCommand::TYPE::SOURCE_VERSION This command is used to provide the...
Definition SourceVersion.hpp:35
Class that represents the SubClient command. Accodring to the Mach-O loader.h documentation:
Definition SubClient.hpp:43
Class that represents the SubFramework command. Accodring to the Mach-O loader.h documentation:
Definition SubFramework.hpp:46
Class that represents the LC_SYMTAB command.
Definition SymbolCommand.hpp:35
Class that represents a Symbol in a Mach-O file.
Definition MachO/Symbol.hpp:47
Class that represents the LC_THREAD / LC_UNIXTHREAD commands and that can be used to get the binary e...
Definition ThreadCommand.hpp:41
Class which represents the LC_TWOLEVEL_HINTS command.
Definition TwoLevelHints.hpp:39
Class that represents the UUID command.
Definition UUIDCommand.hpp:35
Class that wraps the LC_VERSION_MIN_MACOSX, LC_VERSION_MIN_IPHONEOS, ... commands.
Definition VersionMin.hpp:33
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
Namespace related to ObjC metadata.
Definition MachO/Binary.hpp:41
LIEF namespace.
Definition Abstract/Binary.hpp:39
result< ok_t > ok_error_t
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:109
uint64_t align(uint64_t value, uint64_t align_on)
Definition utils.hpp:28
ok_t ok()
Return success for function with return type ok_error_t.
Definition errors.hpp:93
uint64_t start
Definition MachO/Binary.hpp:96
uint64_t size() const
Definition MachO/Binary.hpp:99
uint64_t end
Definition MachO/Binary.hpp:97
bool empty() const
Definition MachO/Binary.hpp:103
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42