LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
MachO/Binary.hpp
Go to the documentation of this file.
1/* Copyright 2017 - 2025 R. Thomas
2 * Copyright 2017 - 2025 Quarkslab
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef LIEF_MACHO_BINARY_H
17#define LIEF_MACHO_BINARY_H
18
19#include <vector>
20#include <map>
21#include <set>
22#include <memory>
23
25#include "LIEF/MachO/Header.hpp"
28#include "LIEF/MachO/Stub.hpp"
30
31#include "LIEF/visibility.h"
32#include "LIEF/utils.hpp"
33
35
36#include "LIEF/iterators.hpp"
37#include "LIEF/errors.hpp"
38
39namespace LIEF {
40
41namespace objc {
42class Metadata;
43}
44namespace MachO {
47
48class AtomInfo;
49class BinaryParser;
50class Builder;
51class CodeSignature;
53class DataInCode;
55class DyldEnvironment;
56class DyldExportsTrie;
57class DyldInfo;
58class DylibCommand;
59class DylinkerCommand;
61class EncryptionInfo;
62class ExportInfo;
63class FunctionStarts;
64class Header;
66class LinkerOptHint;
67class MainCommand;
68class Parser;
69class RPathCommand;
70class Relocation;
71class Routine;
72class Section;
73class SegmentCommand;
75class SourceVersion;
76class SubClient;
77class SubFramework;
78class Symbol;
79class SymbolCommand;
80class ThreadCommand;
81class TwoLevelHints;
82class UUIDCommand;
83class VersionMin;
84class LIEF_API Binary : public LIEF::Binary {
87
88 friend class Parser;
89 friend class BinaryParser;
90 friend class Builder;
91 friend class DyldInfo;
92 friend class BindingInfoIterator;
93
94 public:
95 struct range_t {
96 uint64_t start = 0;
97 uint64_t end = 0;
98
99 uint64_t size() const {
100 return end - start;
101 }
102
103 bool empty() const {
104 return start == end;
105 }
106 };
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*>;
173
174 struct KeyCmp {
175 bool operator() (const Relocation* lhs, const Relocation* rhs) const;
176 };
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*>;
200
201 using it_bindings = iterator_range<BindingInfoIterator>;
202 using stub_iterator = iterator_range<Stub::Iterator>;
205
206 public:
207 Binary(const Binary&) = delete;
208 Binary& operator=(const Binary&) = delete;
209 Header& header() {
212 return header_;
213 }
214
215 const Header& header() const {
216 return header_;
217 }
218 it_commands commands() {
222 return commands_;
223 }
224
225 it_const_commands commands() const {
226 return commands_;
227 }
228 it_fileset_binaries filesets() {
232 return filesets_;
233 }
234
235 it_const_fileset_binaries filesets() const {
236 return filesets_;
237 }
238 it_symbols symbols() {
241 return symbols_;
242 }
243 it_const_symbols symbols() const {
244 return symbols_;
245 }
246 bool has_symbol(const std::string& name) const {
249 return get_symbol(name) != nullptr;
250 }
251 const Symbol* get_symbol(const std::string& name) const;
255 Symbol* get_symbol(const std::string& name) {
256 return const_cast<Symbol*>(static_cast<const Binary*>(this)->get_symbol(name));
257 }
258 static bool is_exported(const Symbol& symbol);
261 it_exported_symbols exported_symbols() {
264 return {symbols_, [] (const std::unique_ptr<Symbol>& symbol) {
265 return is_exported(*symbol); }
266 };
267 }
268 it_const_exported_symbols exported_symbols() const {
269 return {symbols_, [] (const std::unique_ptr<Symbol>& symbol) {
270 return is_exported(*symbol);
271 }};
272 }
273 static bool is_imported(const Symbol& symbol);
276 it_imported_symbols imported_symbols() {
279 return {symbols_, [] (const std::unique_ptr<Symbol>& symbol) {
280 return is_imported(*symbol);
281 }};
282 }
283
284 it_const_imported_symbols imported_symbols() const {
285 return {symbols_, [] (const std::unique_ptr<Symbol>& symbol) {
286 return is_imported(*symbol);
287 }};
288 }
289 it_libraries libraries() {
292 return libraries_;
293 }
294
295 it_const_libraries libraries() const {
296 return libraries_;
297 }
298 it_segments segments() {
301 return segments_;
302 }
303 it_const_segments segments() const {
304 return segments_;
305 }
306 it_sections sections() {
309 return sections_;
310 }
311 it_const_sections sections() const {
312 return sections_;
313 }
314 it_relocations relocations();
317 it_const_relocations relocations() const;
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));
356 }
357
358 LoadCommand* add(std::unique_ptr<LoadCommand> command);
359 LoadCommand* add(const LoadCommand& command) {
362 return add(command.clone());
363 }
364 LoadCommand* add(const LoadCommand& command, size_t index);
367 LoadCommand* add(const DylibCommand& library);
370 LoadCommand* add(const SegmentCommand& segment);
373 LoadCommand* add_library(const std::string& name);
376 Section* add_section(const Section& section);
379 const DylibCommand* find_library(const std::string& name) const;
385
386 DylibCommand* find_library(const std::string& name) {
387 return const_cast<DylibCommand*>(static_cast<const Binary*>(this)->find_library(name));
388 }
389 Section* add_section(const SegmentCommand& segment, const Section& section);
395 void remove_section(const std::string& name, bool clear = false) override;
401 void remove_section(const std::string& segname, const std::string& secname, bool clear = false);
410 bool remove(const LoadCommand& command);
413 bool remove(LoadCommand::TYPE type);
416 bool remove_command(size_t index);
419 bool remove_signature();
422 bool extend(const LoadCommand& command, uint64_t size);
425 bool extend_segment(const SegmentCommand& segment, size_t size);
428 bool extend_section(Section& section, size_t size);
435 bool disable_pie();
438 uint64_t imagebase() const override;
441 uint64_t virtual_size() const {
444 return align(va_ranges().size(), (uint64_t)page_size());
445 }
446 std::string loader() const;
450 bool has_section(const std::string& name) const {
453 return get_section(name) != nullptr;
454 }
455 Section* get_section(const std::string& name) {
459 return const_cast<Section*>(static_cast<const Binary*>(this)->get_section(name));
460 }
461 const Section* get_section(const std::string& name) const;
465 Section* get_section(const std::string& segname, const std::string& secname) {
470 return const_cast<Section*>(static_cast<const Binary*>(this)->get_section(segname, secname));
471 }
472
473 const Section* get_section(const std::string& segname, const std::string& secname) const;
474 bool has_segment(const std::string& name) const {
477 return get_segment(name) != nullptr;
478 }
479 const SegmentCommand* get_segment(const std::string& name) const;
482 SegmentCommand* get_segment(const std::string& name) {
485 return const_cast<SegmentCommand*>(static_cast<const Binary*>(this)->get_segment(name));
486 }
487 bool remove_symbol(const std::string& name);
490 bool remove(const Symbol& sym);
493 bool can_remove(const Symbol& sym) const;
496 bool can_remove_symbol(const std::string& name) const;
499 bool unexport(const std::string& name);
502 bool unexport(const Symbol& sym);
505 Section* section_from_offset(uint64_t offset) {
509 return const_cast<Section*>(static_cast<const Binary*>(this)->section_from_offset(offset));
510 }
511 const Section* section_from_offset(uint64_t offset) const;
512 Section* section_from_virtual_address(uint64_t virtual_address) {
516 return const_cast<Section*>(static_cast<const Binary*>(this)->section_from_virtual_address(virtual_address));
517 }
518 const Section* section_from_virtual_address(uint64_t virtual_address) const;
519 result<uint64_t> virtual_address_to_offset(uint64_t virtual_address) const;
522 result<uint64_t> offset_to_virtual_address(uint64_t offset, uint64_t slide = 0) const override;
528 SegmentCommand* segment_from_offset(uint64_t offset) {
533 return const_cast<SegmentCommand*>(static_cast<const Binary*>(this)->segment_from_offset(offset));
534 }
535 const SegmentCommand* segment_from_offset(uint64_t offset) const;
536 size_t segment_index(const SegmentCommand& segment) const;
539 uint64_t fat_offset() const {
542 return fat_offset_;
543 }
544 SegmentCommand* segment_from_virtual_address(uint64_t virtual_address) {
548 return const_cast<SegmentCommand*>(static_cast<const Binary*>(this)->segment_from_virtual_address(virtual_address));
549 }
550 const SegmentCommand* segment_from_virtual_address(uint64_t virtual_address) const;
551 range_t va_ranges() const;
554 range_t off_ranges() const;
557 bool is_valid_addr(uint64_t address) const {
561 const range_t& r = va_ranges();
562 return r.start <= address && address < r.end;
563 }
564 void accept(LIEF::Visitor& visitor) const override;
567
568 std::ostream& print(std::ostream& os) const override;
569 void patch_address(uint64_t address, const std::vector<uint8_t>& patch_value,
577 LIEF::Binary::VA_TYPES addr_type = LIEF::Binary::VA_TYPES::AUTO) override;
578 void patch_address(uint64_t address, uint64_t patch_value,
587 size_t size = sizeof(uint64_t),
588 LIEF::Binary::VA_TYPES addr_type = LIEF::Binary::VA_TYPES::AUTO) override;
589 span<const uint8_t> get_content_from_virtual_address(
592 uint64_t virtual_address, uint64_t size,
593 Binary::VA_TYPES addr_type = Binary::VA_TYPES::AUTO) const override;
594 uint64_t entrypoint() const override;
597 bool is_pie() const override {
600 return header().has(Header::FLAGS::PIE);
601 }
602 bool has_nx() const override {
605 return has_nx_stack();
606 }
607 bool has_nx_stack() const {
610 return !header().has(Header::FLAGS::ALLOW_STACK_EXECUTION);
611 }
612 bool has_nx_heap() const {
615 return !header().has(Header::FLAGS::NO_HEAP_EXECUTION);
616 }
617 bool has_entrypoint() const {
622 return has_main_command() || has_thread_command();
623 }
624 bool has_uuid() const {
627 return uuid() != nullptr;
628 }
629 UUIDCommand* uuid();
632 const UUIDCommand* uuid() const;
633 bool has_main_command() const {
636 return main_command() != nullptr;
637 }
638 MainCommand* main_command();
641 const MainCommand* main_command() const;
642 bool has_dylinker() const {
645 return dylinker() != nullptr;
646 }
647 DylinkerCommand* dylinker();
650 const DylinkerCommand* dylinker() const;
651 bool has_dyld_info() const {
654 return dyld_info() != nullptr;
655 }
656 DyldInfo* dyld_info();
659 const DyldInfo* dyld_info() const;
660 bool has_function_starts() const {
663 return function_starts() != nullptr;
664 }
665 FunctionStarts* function_starts();
668 const FunctionStarts* function_starts() const;
669 bool has_source_version() const {
672 return source_version() != nullptr;
673 }
674 SourceVersion* source_version();
677 const SourceVersion* source_version() const;
678 bool has_version_min() const {
681 return version_min() != nullptr;
682 }
683 VersionMin* version_min();
686 const VersionMin* version_min() const;
687 bool has_thread_command() const {
690 return thread_command() != nullptr;
691 }
692 ThreadCommand* thread_command();
695 const ThreadCommand* thread_command() const;
696 bool has_routine_command() const {
699 return routine_command() != nullptr;
700 }
701 Routine* routine_command();
704 const Routine* routine_command() const;
705 bool has_rpath() const {
708 return rpath() != nullptr;
709 }
710 RPathCommand* rpath();
713 const RPathCommand* rpath() const;
714 it_rpaths rpaths();
717 it_const_rpaths rpaths() const;
718 bool has_symbol_command() const {
721 return symbol_command() != nullptr;
722 }
723 SymbolCommand* symbol_command();
726 const SymbolCommand* symbol_command() const;
727 bool has_dynamic_symbol_command() const {
730 return dynamic_symbol_command() != nullptr;
731 }
732 DynamicSymbolCommand* dynamic_symbol_command();
735 const DynamicSymbolCommand* dynamic_symbol_command() const;
736 bool has_code_signature() const {
739 return code_signature() != nullptr;
740 }
741 CodeSignature* code_signature() {
744 return const_cast<CodeSignature*>(static_cast<const Binary*>(this)->code_signature());
745 }
746 const CodeSignature* code_signature() const;
747 bool has_code_signature_dir() const {
750 return code_signature_dir() != nullptr;
751 }
752 CodeSignatureDir* code_signature_dir() {
755 return const_cast<CodeSignatureDir*>(static_cast<const Binary*>(this)->code_signature_dir());
756 }
757 const CodeSignatureDir* code_signature_dir() const;
758 bool has_data_in_code() const {
761 return data_in_code() != nullptr;
762 }
763 DataInCode* data_in_code();
766 const DataInCode* data_in_code() const;
767 bool has_segment_split_info() const {
770 return segment_split_info() != nullptr;
771 }
772 SegmentSplitInfo* segment_split_info();
775 const SegmentSplitInfo* segment_split_info() const;
776 bool has_sub_framework() const {
779 return sub_framework() != nullptr;
780 }
781 bool has_encryption_info() const {
784 return encryption_info() != nullptr;
785 }
786 EncryptionInfo* encryption_info();
789 const EncryptionInfo* encryption_info() const;
790 SubFramework* sub_framework();
793 const SubFramework* sub_framework() const;
794 it_sub_clients subclients();
797 it_const_sub_clients subclients() const;
798
799 bool has_subclients() const;
800 bool has_dyld_environment() const {
803 return dyld_environment() != nullptr;
804 }
805 DyldEnvironment* dyld_environment();
808 const DyldEnvironment* dyld_environment() const;
809 bool has_build_version() const {
812 return build_version() != nullptr;
813 }
814 BuildVersion* build_version();
817 const BuildVersion* build_version() const;
818 BuildVersion::PLATFORMS platform() const {
821 if (const BuildVersion* version = build_version()) {
822 return version->platform();
823 }
824 return BuildVersion::PLATFORMS::UNKNOWN;
825 }
826 bool is_ios() const {
829 return platform() == BuildVersion::PLATFORMS::IOS ||
830 has(LoadCommand::TYPE::VERSION_MIN_IPHONEOS);
831 }
832 bool is_macos() const {
835 return platform() == BuildVersion::PLATFORMS::MACOS ||
836 has(LoadCommand::TYPE::VERSION_MIN_MACOSX);
837 }
838
839 bool has_dyld_chained_fixups() const {
842 return dyld_chained_fixups() != nullptr;
843 }
844 DyldChainedFixups* dyld_chained_fixups();
847 const DyldChainedFixups* dyld_chained_fixups() const;
848 bool has_dyld_exports_trie() const {
851 return dyld_exports_trie() != nullptr;
852 }
853 DyldExportsTrie* dyld_exports_trie();
856 const DyldExportsTrie* dyld_exports_trie() const;
857 bool has_two_level_hints() const {
860 return two_level_hints() != nullptr;
861 }
862 TwoLevelHints* two_level_hints() {
865 return const_cast<TwoLevelHints*>(static_cast<const Binary*>(this)->two_level_hints());
866 }
867 const TwoLevelHints* two_level_hints() const;
868 bool has_linker_opt_hint() const {
871 return linker_opt_hint() != nullptr;
872 }
873 LinkerOptHint* linker_opt_hint() {
876 return const_cast<LinkerOptHint*>(static_cast<const Binary*>(this)->linker_opt_hint());
877 }
878 const LinkerOptHint* linker_opt_hint() const;
879 ExportInfo* add_exported_function(uint64_t address, const std::string& name);
882 Symbol* add_local_symbol(uint64_t address, const std::string& name);
885 std::unique_ptr<objc::Metadata> objc_metadata() const;
888 stub_iterator symbol_stubs() const;
896 bool has_atom_info() const {
899 return atom_info() != nullptr;
900 }
901 AtomInfo* atom_info() {
904 return const_cast<AtomInfo*>(static_cast<const Binary*>(this)->atom_info());
905 }
906 const AtomInfo* atom_info() const;
907
908 template<class T>
909 LIEF_LOCAL bool has_command() const;
910
911 template<class T>
912 LIEF_LOCAL T* command();
913
914 template<class T>
915 LIEF_LOCAL const T* command() const;
916
917 template<class T>
918 LIEF_LOCAL size_t count_commands() const;
919
920 template<class CMD, class Func>
921 LIEF_LOCAL Binary& for_commands(Func f);
922
923 LoadCommand* operator[](LoadCommand::TYPE type) {
924 return get(type);
925 }
926 const LoadCommand* operator[](LoadCommand::TYPE type) const {
927 return get(type);
928 }
929 LIEF::Binary::functions_t ctor_functions() const override;
932 LIEF::Binary::functions_t functions() const;
935 LIEF::Binary::functions_t unwind_functions() const;
938 bool has_filesets() const {
941 return filesets_.empty();
942 }
943 const std::string& fileset_name() const {
946 return fileset_name_;
947 }
948 Symbol& add(const Symbol& symbol);
951
952 ~Binary() override;
953 ok_error_t shift(size_t value);
957 ok_error_t shift_linkedit(size_t width);
960 uint64_t memory_base_address() const {
966 return in_memory_base_addr_;
967 }
968 bool support_arm64_ptr_auth() const {
971 return header().cpu_type() == Header::CPU_TYPE::ARM64 &&
972 (header().cpu_subtype() & ~Header::SUBTYPE_MASK) == Header::CPU_SUBTYPE_ARM64_ARM64E;
973 }
974 it_bindings bindings() const;
978
979 static bool classof(const LIEF::Binary* bin) {
980 return bin->format() == Binary::FORMATS::MACHO;
981 }
982
983 span<const uint8_t> overlay() const {
984 return overlay_;
985 }
986
987 void sort_segments();
988 void refresh_seg_offset();
989 static LIEF_LOCAL bool can_cache_segment(const SegmentCommand& segment);
992 LIEF_LOCAL size_t available_command_space() const {
995 return available_command_space_;
996 }
997
998 private: LIEF_LOCAL Binary();
1001
1002 LIEF_LOCAL void shift_command(size_t width, uint64_t from_offset);
1003 LIEF_LOCAL size_t add_cached_segment(SegmentCommand& segment);
1007
1008 template<class T>
1009 LIEF_LOCAL ok_error_t patch_relocation(Relocation& relocation, uint64_t from,
1010 uint64_t shift);
1011
1012 LIEF::Header get_abstract_header() const override {
1013 return LIEF::Header::from(*this);
1014 }
1015
1016 LIEF_LOCAL LIEF::Binary::sections_t get_abstract_sections() override;
1017 LIEF_LOCAL LIEF::Binary::symbols_t get_abstract_symbols() override;
1018 LIEF_LOCAL LIEF::Binary::relocations_t get_abstract_relocations() override;
1019 LIEF_LOCAL LIEF::Binary::functions_t get_abstract_exported_functions() const override;
1020 LIEF_LOCAL LIEF::Binary::functions_t get_abstract_imported_functions() const override;
1021 LIEF_LOCAL std::vector<std::string> get_abstract_imported_libraries() const override;
1022 ok_error_t ensure_command_space(size_t size) {
1027 return available_command_space_ < size ? shift(size) : ok();
1028 }
1029
1030 relocations_t& relocations_list() {
1031 return this->relocations_;
1032 }
1033
1034 const relocations_t& relocations_list() const {
1035 return this->relocations_;
1036 }
1037
1038 size_t pointer_size() const {
1039 return this->is64_ ? sizeof(uint64_t) : sizeof(uint32_t);
1040 }
1041
1042 bool is64_ = true;
1043 Header header_;
1044 commands_t commands_;
1045 symbols_t symbols_;
1046
1047 // Same purpose as sections_cache_t
1048 libraries_cache_t libraries_;
1049
1050 // The sections are owned by the SegmentCommand object.
1051 // This attribute is a cache to speed-up the iteration
1052 sections_cache_t sections_;
1053
1054 // Same purpose as sections_cache_t
1055 segments_cache_t segments_;
1056
1057 fileset_binaries_t filesets_;
1058
1059 // Cached relocations from segment / sections
1060 mutable relocations_t relocations_;
1061 size_t available_command_space_ = 0;
1062
1063 // This is used to improve performances of
1064 // offset_to_virtual_address
1065 std::map<uint64_t, SegmentCommand*> offset_seg_;
1066
1067 protected:
1068 uint64_t fat_offset_ = 0;
1069 uint64_t fileset_offset_ = 0;
1070 uint64_t in_memory_base_addr_ = 0;
1071 std::string fileset_name_;
1072 std::vector<uint8_t> overlay_;
1073 std::vector<std::unique_ptr<IndirectBindingInfo>> indirect_bindings_;
1074};
1075
1076} // namespace MachO
1077} // namespace LIEF
1078#endif
Binary.hpp
BindingInfoIterator.hpp
BuildVersion.hpp
LoadCommand.hpp
Builder.hpp
Header.hpp
Stub.hpp
LIEF::Binary::functions_t
std::vector< Function > functions_t
Definition Abstract/Binary.hpp:70
LIEF::Binary::format
FORMATS format() const
Executable format (ELF, PE, Mach-O) of the underlying binary.
Definition Abstract/Binary.hpp:112
LIEF::Binary::symbols_t
std::vector< Symbol * > symbols_t
Internal container.
Definition Abstract/Binary.hpp:82
LIEF::Binary::VA_TYPES
VA_TYPES
Type of a virtual address.
Definition Abstract/Binary.hpp:56
LIEF::Binary::VA_TYPES::AUTO
@ AUTO
Try to guess if it's relative or not.
Definition Abstract/Binary.hpp:57
LIEF::Binary::sections_t
std::vector< Section * > sections_t
Internal container.
Definition Abstract/Binary.hpp:73
LIEF::Binary::relocations_t
std::vector< Relocation * > relocations_t
Internal container.
Definition Abstract/Binary.hpp:91
LIEF::Header::from
static Header from(const LIEF::ELF::Binary &elf)
LIEF::MachO::AtomInfo
Class which represents the LC_ATOM_INFO command.
Definition AtomInfo.hpp:36
LIEF::MachO::BinaryParser
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:75
LIEF::MachO::Binary
Class which represents a MachO binary.
Definition MachO/Binary.hpp:86
LIEF::MachO::Binary::add_local_symbol
Symbol * add_local_symbol(uint64_t address, const std::string &name)
Add a symbol in LC_SYMTAB command of the current binary.
LIEF::MachO::Binary::uuid
UUIDCommand * uuid()
Return the MachO::UUIDCommand if present, a nullptr otherwise.
LIEF::MachO::Binary::has_build_version
bool has_build_version() const
true if the binary has the BuildVersion command.
Definition MachO/Binary.hpp:811
LIEF::MachO::Binary::raw
std::vector< uint8_t > raw()
Reconstruct the binary object and return its content as bytes.
LIEF::MachO::Binary::count_commands
size_t count_commands() const
LIEF::MachO::Binary::classof
static bool classof(const LIEF::Binary *bin)
Definition MachO/Binary.hpp:979
LIEF::MachO::Binary::is_pie
bool is_pie() const override
Check if the binary is position independent.
Definition MachO/Binary.hpp:599
LIEF::MachO::Binary::write
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...
LIEF::MachO::Binary::has_function_starts
bool has_function_starts() const
true if the binary has a MachO::FunctionStarts command.
Definition MachO/Binary.hpp:662
LIEF::MachO::Binary::entrypoint
uint64_t entrypoint() const override
The binary entrypoint.
LIEF::MachO::Binary::has_segment_split_info
bool has_segment_split_info() const
true if the binary has segment split info.
Definition MachO/Binary.hpp:769
LIEF::MachO::Binary::imported_symbols
it_imported_symbols imported_symbols()
Return binary's imported symbols (iterator over LIEF::MachO::Symbol)
Definition MachO/Binary.hpp:278
LIEF::MachO::Binary::thread_command
const ThreadCommand * thread_command() const
LIEF::MachO::Binary::section_from_offset
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:508
LIEF::MachO::Binary::segment_split_info
const SegmentSplitInfo * segment_split_info() const
LIEF::MachO::Binary::section_from_offset
const Section * section_from_offset(uint64_t offset) const
LIEF::MachO::Binary::has_source_version
bool has_source_version() const
true if the binary has a MachO::SourceVersion command.
Definition MachO/Binary.hpp:671
LIEF::MachO::Binary::get_segment
const SegmentCommand * get_segment(const std::string &name) const
Return the segment from the given name.
LIEF::MachO::Binary::uuid
const UUIDCommand * uuid() const
LIEF::MachO::Binary::commands
it_commands commands()
Return an iterator over the MachO LoadCommand present in the binary.
Definition MachO/Binary.hpp:221
LIEF::MachO::Binary::off_ranges
range_t off_ranges() const
Return the range of offsets.
LIEF::MachO::Binary::data_in_code
const DataInCode * data_in_code() const
LIEF::MachO::Binary::offset_to_virtual_address
result< uint64_t > offset_to_virtual_address(uint64_t offset, uint64_t slide=0) const override
Convert the given offset into a virtual address.
LIEF::MachO::Binary::segment_from_virtual_address
const SegmentCommand * segment_from_virtual_address(uint64_t virtual_address) const
LIEF::MachO::Binary::virtual_address_to_offset
result< uint64_t > virtual_address_to_offset(uint64_t virtual_address) const
Convert a virtual address to an offset in the file.
LIEF::MachO::Binary::has_atom_info
bool has_atom_info() const
true if the binary has the command LC_ATOM_INFO.
Definition MachO/Binary.hpp:898
LIEF::MachO::Binary::has_dynamic_symbol_command
bool has_dynamic_symbol_command() const
true if the binary has a MachO::DynamicSymbolCommand command.
Definition MachO/Binary.hpp:729
LIEF::MachO::Binary::dyld_info
const DyldInfo * dyld_info() const
LIEF::MachO::Binary::two_level_hints
TwoLevelHints * two_level_hints()
Return the MachO::DyldChainedFixups if present, a nullptr otherwise.
Definition MachO/Binary.hpp:864
LIEF::MachO::Binary::is_valid_addr
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:560
LIEF::MachO::Binary::write
void write(const std::string &filename)
Reconstruct the binary object and write the result in the given filename
LIEF::MachO::Binary::add
LoadCommand * add(const DylibCommand &library)
Insert the given DylibCommand.
LIEF::MachO::Binary::dylinker
DylinkerCommand * dylinker()
Return the MachO::DylinkerCommand if present, a nullptr otherwise.
LIEF::MachO::Binary::has_dylinker
bool has_dylinker() const
true if the binary has a MachO::DylinkerCommand.
Definition MachO/Binary.hpp:644
LIEF::MachO::Binary::get_section
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:469
LIEF::MachO::Binary::version_min
const VersionMin * version_min() const
LIEF::MachO::Binary::has_dyld_chained_fixups
bool has_dyld_chained_fixups() const
true if the binary has the command LC_DYLD_CHAINED_FIXUPS.
Definition MachO/Binary.hpp:841
LIEF::MachO::Binary::subclients
it_sub_clients subclients()
Iterator over all the MachO::SubClient commands.
LIEF::MachO::Binary::has_dyld_info
bool has_dyld_info() const
true if the binary has a MachO::DyldInfo command.
Definition MachO/Binary.hpp:653
LIEF::MachO::Binary::encryption_info
EncryptionInfo * encryption_info()
Return the MachO::DyldEnvironment if present, a nullptr otherwise.
LIEF::MachO::Binary::data_in_code
DataInCode * data_in_code()
Return the MachO::DataInCode if present, a nullptr otherwise.
LIEF::MachO::Binary::extend_section
bool extend_section(Section &section, size_t size)
Extend the content of the given Section.
LIEF::MachO::Binary::two_level_hints
const TwoLevelHints * two_level_hints() const
LIEF::MachO::Binary::loader
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...
LIEF::MachO::Binary::has_symbol
bool has_symbol(const std::string &name) const
Check if a symbol with the given name exists.
Definition MachO/Binary.hpp:248
LIEF::MachO::Binary::build_version
BuildVersion * build_version()
Return the MachO::BuildVersion if present, a nullptr otherwise.
LIEF::MachO::Binary::has_symbol_command
bool has_symbol_command() const
true if the binary has a MachO::SymbolCommand command.
Definition MachO/Binary.hpp:720
LIEF::MachO::Binary::operator[]
const LoadCommand * operator[](LoadCommand::TYPE type) const
Definition MachO/Binary.hpp:926
LIEF::MachO::Binary::segment_index
size_t segment_index(const SegmentCommand &segment) const
Return the index of the given SegmentCommand.
LIEF::MachO::Binary::has_rpath
bool has_rpath() const
true if the binary has a MachO::RPathCommand command.
Definition MachO/Binary.hpp:707
LIEF::MachO::Binary::filesets
it_const_fileset_binaries filesets() const
Definition MachO/Binary.hpp:235
LIEF::MachO::Binary::shift_linkedit
ok_error_t shift_linkedit(size_t width)
Shift the position on the __LINKEDIT data by width
LIEF::MachO::Binary::sort_segments
void sort_segments()
LIEF::MachO::Binary::relocations
it_relocations relocations()
Return an iterator over the MachO::Relocation.
LIEF::MachO::Binary::extend
bool extend(const LoadCommand &command, uint64_t size)
Extend the size of the given LoadCommand.
LIEF::MachO::Binary::version_min
VersionMin * version_min()
Return the MachO::VersionMin command if present, a nullptr otherwise.
LIEF::MachO::Binary::remove_signature
bool remove_signature()
Remove the LC_SIGNATURE command.
LIEF::MachO::Binary::has_nx
bool has_nx() const override
Check if the binary uses NX protection.
Definition MachO/Binary.hpp:604
LIEF::MachO::Binary::can_remove
bool can_remove(const Symbol &sym) const
Check if the given symbol can be safely removed.
LIEF::MachO::Binary::write
void write(std::ostream &os)
Reconstruct the binary object and write the result in the given os stream.
LIEF::MachO::Binary::subclients
it_const_sub_clients subclients() const
LIEF::MachO::Binary::source_version
const SourceVersion * source_version() const
LIEF::MachO::Binary::bindings
it_bindings bindings() const
Return an iterator over the binding info which can come from either DyldInfo or DyldChainedFixups com...
LIEF::MachO::Binary::has_routine_command
bool has_routine_command() const
true if the binary has a MachO::Routine command.
Definition MachO/Binary.hpp:698
LIEF::MachO::Binary::remove_section
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...
LIEF::MachO::Binary::imagebase
uint64_t imagebase() const override
Return the binary's imagebase. 0 if not relevant.
LIEF::MachO::Binary::print
std::ostream & print(std::ostream &os) const override
LIEF::MachO::Binary::find_library
const DylibCommand * find_library(const std::string &name) const
Try to find the library with the given library name.
LIEF::MachO::Binary::is_macos
bool is_macos() const
True if this binary targets macOS.
Definition MachO/Binary.hpp:834
LIEF::MachO::Binary::disable_pie
bool disable_pie()
Remove the PIE flag.
LIEF::MachO::Binary::can_remove_symbol
bool can_remove_symbol(const std::string &name) const
Check if the MachO::Symbol with the given name can be safely removed.
LIEF::MachO::Binary::thread_command
ThreadCommand * thread_command()
Return the MachO::ThreadCommand command if present, a nullptr otherwise.
LIEF::MachO::Binary::section_from_virtual_address
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:515
LIEF::MachO::Binary::command
T * command()
LIEF::MachO::Binary::can_cache_segment
static bool can_cache_segment(const SegmentCommand &segment)
Check if the given segment can go in the offset_seg_ cache.
LIEF::MachO::Binary::has_segment
bool has_segment(const std::string &name) const
Check if a segment with the given name exists.
Definition MachO/Binary.hpp:476
LIEF::MachO::Binary::has_uuid
bool has_uuid() const
true if the binary has a MachO::UUIDCommand command.
Definition MachO/Binary.hpp:626
LIEF::MachO::Binary::section_from_virtual_address
const Section * section_from_virtual_address(uint64_t virtual_address) const
LIEF::MachO::Binary::remove_symbol
bool remove_symbol(const std::string &name)
Remove the symbol with the given name.
LIEF::MachO::Binary::dyld_exports_trie
DyldExportsTrie * dyld_exports_trie()
Return the MachO::DyldChainedFixups if present, a nullptr otherwise.
LIEF::MachO::Binary::dyld_environment
const DyldEnvironment * dyld_environment() const
LIEF::MachO::Binary::sections
it_const_sections sections() const
Definition MachO/Binary.hpp:311
LIEF::MachO::Binary::symbols
it_const_symbols symbols() const
Definition MachO/Binary.hpp:243
LIEF::MachO::Binary::accept
void accept(LIEF::Visitor &visitor) const override
Method so that the visitor can visit us.
LIEF::MachO::Binary::has_dyld_exports_trie
bool has_dyld_exports_trie() const
true if the binary has the command LC_DYLD_CHAINED_FIXUPS.
Definition MachO/Binary.hpp:850
LIEF::MachO::Binary::remove
bool remove(LoadCommand::TYPE type)
Remove all LoadCommand with the given type (MachO::LoadCommand::TYPE)
LIEF::MachO::Binary::routine_command
const Routine * routine_command() const
LIEF::MachO::Binary::symbols
it_symbols symbols()
Return binary's symbols .
Definition MachO/Binary.hpp:240
LIEF::MachO::Binary::operator[]
LoadCommand * operator[](LoadCommand::TYPE type)
Definition MachO/Binary.hpp:923
LIEF::MachO::Binary::has_subclients
bool has_subclients() const
LIEF::MachO::Binary::has_linker_opt_hint
bool has_linker_opt_hint() const
true if the binary has the command LC_LINKER_OPTIMIZATION_HINT.
Definition MachO/Binary.hpp:870
LIEF::MachO::Binary::dyld_chained_fixups
const DyldChainedFixups * dyld_chained_fixups() const
LIEF::MachO::Binary::shift
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::MachO::Binary::ctor_functions
LIEF::Binary::functions_t ctor_functions() const override
Return the list of the MachO's constructors.
LIEF::MachO::Binary::objc_metadata
std::unique_ptr< objc::Metadata > objc_metadata() const
Return Objective-C metadata if present.
LIEF::MachO::Binary::function_starts
const FunctionStarts * function_starts() const
LIEF::MachO::Binary::refresh_seg_offset
void refresh_seg_offset()
LIEF::MachO::Binary::segments
it_segments segments()
Return an iterator over the SegmentCommand.
Definition MachO/Binary.hpp:300
LIEF::MachO::Binary::Binary
Binary(const Binary &)=delete
LIEF::MachO::Binary::get_section
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:458
LIEF::MachO::Binary::filesets
it_fileset_binaries filesets()
Return an iterator over the MachO::Binary associated with the LoadCommand::TYPE::FILESET_ENTRY comman...
Definition MachO/Binary.hpp:231
LIEF::MachO::Binary::operator=
Binary & operator=(const Binary &)=delete
LIEF::MachO::Binary::segments
it_const_segments segments() const
Definition MachO/Binary.hpp:303
LIEF::MachO::Binary::has_nx_stack
bool has_nx_stack() const
Return True if the stack is flagged as non-executable. False otherwise.
Definition MachO/Binary.hpp:609
LIEF::MachO::Binary::libraries
it_libraries libraries()
Return binary imported libraries (MachO::DylibCommand)
Definition MachO/Binary.hpp:291
LIEF::MachO::Binary::has_data_in_code
bool has_data_in_code() const
true if the binary has a MachO::DataInCode command.
Definition MachO/Binary.hpp:760
LIEF::MachO::Binary::sub_framework
const SubFramework * sub_framework() const
LIEF::MachO::Binary::get_section
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.
LIEF::MachO::Binary::is_exported
static bool is_exported(const Symbol &symbol)
Check if the given symbol is exported.
LIEF::MachO::Binary::add_section
Section * add_section(const Section &section)
Add a new MachO::Section in the __TEXT segment.
LIEF::MachO::Binary::segment_from_offset
const SegmentCommand * segment_from_offset(uint64_t offset) const
LIEF::MachO::Binary::write
void write(const std::string &filename, Builder::config_t config)
Reconstruct the binary object and write the result in the given filename.
LIEF::MachO::Binary::exported_symbols
it_exported_symbols exported_symbols()
Return binary's exported symbols (iterator over LIEF::MachO::Symbol)
Definition MachO/Binary.hpp:263
LIEF::MachO::Binary::main_command
const MainCommand * main_command() const
LIEF::MachO::Binary::platform
BuildVersion::PLATFORMS platform() const
Return the platform for which this Mach-O has been compiled for.
Definition MachO/Binary.hpp:820
LIEF::MachO::Binary::relocations
it_const_relocations relocations() const
LIEF::MachO::Binary::overlay
span< const uint8_t > overlay() const
Definition MachO/Binary.hpp:983
LIEF::MachO::Binary::segment_from_virtual_address
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:547
LIEF::MachO::Binary::dyld_chained_fixups
DyldChainedFixups * dyld_chained_fixups()
Return the MachO::DyldChainedFixups if present, a nullptr otherwise.
LIEF::MachO::Binary::rpath
const RPathCommand * rpath() const
LIEF::MachO::Binary::code_signature
const CodeSignature * code_signature() const
LIEF::MachO::Binary::rpath
RPathCommand * rpath()
Return the MachO::RPathCommand command if present, a nullptr otherwise.
LIEF::MachO::Binary::get_segment
SegmentCommand * get_segment(const std::string &name)
Return the segment from the given name.
Definition MachO/Binary.hpp:484
LIEF::MachO::Binary::get_content_from_virtual_address
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.
LIEF::MachO::Binary::code_signature_dir
const CodeSignatureDir * code_signature_dir() const
LIEF::MachO::Binary::extend_segment
bool extend_segment(const SegmentCommand &segment, size_t size)
Extend the content of the given SegmentCommand.
LIEF::MachO::Binary::dynamic_symbol_command
const DynamicSymbolCommand * dynamic_symbol_command() const
LIEF::MachO::Binary::command
const T * command() const
LIEF::MachO::Binary::symbol_command
SymbolCommand * symbol_command()
Return the MachO::SymbolCommand if present, a nullptr otherwise.
LIEF::MachO::Binary::linker_opt_hint
LinkerOptHint * linker_opt_hint()
Return the MachO::LinkerOptHint if present, a nullptr otherwise.
Definition MachO/Binary.hpp:875
LIEF::MachO::Binary::fat_offset
uint64_t fat_offset() const
Return binary's fat offset. 0 if not relevant.
Definition MachO/Binary.hpp:541
LIEF::MachO::Binary::header
const Header & header() const
Definition MachO/Binary.hpp:215
LIEF::MachO::Binary::rpaths
it_rpaths rpaths()
Iterator over all the MachO::RPathCommand commands.
LIEF::MachO::Binary::has_nx_heap
bool has_nx_heap() const
Return True if the heap is flagged as non-executable. False otherwise.
Definition MachO/Binary.hpp:614
LIEF::MachO::Binary::atom_info
const AtomInfo * atom_info() const
LIEF::MachO::Binary::add
LoadCommand * add(const LoadCommand &command)
Insert a new LoadCommand.
Definition MachO/Binary.hpp:361
LIEF::MachO::Binary::remove
bool remove(const Symbol &sym)
Remove the given symbol.
LIEF::MachO::Binary::has_version_min
bool has_version_min() const
true if the binary has a MachO::VersionMin command.
Definition MachO/Binary.hpp:680
LIEF::MachO::Binary::dyld_environment
DyldEnvironment * dyld_environment()
Return the MachO::DyldEnvironment if present, a nullptr otherwise.
LIEF::MachO::Binary::has_command
bool has_command() const
LIEF::MachO::Binary::remove
bool remove(const LoadCommand &command)
Remove the given LoadCommand.
LIEF::MachO::Binary::source_version
SourceVersion * source_version()
Return the MachO::SourceVersion command if present, a nullptr otherwise.
LIEF::MachO::Binary::is_imported
static bool is_imported(const Symbol &symbol)
Check if the given symbol is an imported one.
LIEF::MachO::Binary::add
LoadCommand * add(const LoadCommand &command, size_t index)
Insert a new LoadCommand at the specified index
LIEF::MachO::Binary::patch_address
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.
LIEF::MachO::Binary::code_signature
CodeSignature * code_signature()
Return the MachO::CodeSignature if present, a nullptr otherwise.
Definition MachO/Binary.hpp:743
LIEF::MachO::Binary::add_library
LoadCommand * add_library(const std::string &name)
Insert a new shared library through a LC_LOAD_DYLIB command.
LIEF::MachO::Binary::add_section
Section * add_section(const SegmentCommand &segment, const Section &section)
Add a section in the given MachO::SegmentCommand.
LIEF::MachO::Binary::remove_section
void remove_section(const std::string &name, bool clear=false) override
Remove the section with the name provided in the first parameter.
LIEF::MachO::Binary::get_symbol
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.
LIEF::MachO::Binary::remove_command
bool remove_command(size_t index)
Remove the Load Command at the provided index
LIEF::MachO::Binary::memory_base_address
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:965
LIEF::MachO::Binary::has_sub_framework
bool has_sub_framework() const
true if the binary has a sub framework command.
Definition MachO/Binary.hpp:778
LIEF::MachO::Binary::functions
LIEF::Binary::functions_t functions() const
Return all the functions found in this MachO.
LIEF::MachO::Binary::get
const LoadCommand * get(LoadCommand::TYPE type) const
Return the LoadCommand associated with the given LoadCommand::TYPE or a nullptr if the command can't ...
LIEF::MachO::Binary::linker_opt_hint
const LinkerOptHint * linker_opt_hint() const
LIEF::MachO::Binary::function_starts
FunctionStarts * function_starts()
Return the MachO::FunctionStarts command if present, a nullptr otherwise.
LIEF::MachO::Binary::segment_split_info
SegmentSplitInfo * segment_split_info()
Return the MachO::SegmentSplitInfo if present, a nullptr otherwise.
LIEF::MachO::Binary::symbol_stubs
stub_iterator symbol_stubs() const
Return an iterator over the symbol stubs.
LIEF::MachO::Binary::add
LoadCommand * add(const SegmentCommand &segment)
Add a new LC_SEGMENT command from the given SegmentCommand.
LIEF::MachO::Binary::get
LoadCommand * get(LoadCommand::TYPE type)
Definition MachO/Binary.hpp:354
LIEF::MachO::Binary::is_ios
bool is_ios() const
True if this binary targets iOS.
Definition MachO/Binary.hpp:828
LIEF::MachO::Binary::has_entrypoint
bool has_entrypoint() const
true if the binary has an entrypoint.
Definition MachO/Binary.hpp:621
LIEF::MachO::Binary::has_two_level_hints
bool has_two_level_hints() const
true if the binary has the command LC_TWO_LEVEL_HINTS.
Definition MachO/Binary.hpp:859
LIEF::MachO::Binary::rpaths
it_const_rpaths rpaths() const
LIEF::MachO::Binary::dyld_info
DyldInfo * dyld_info()
Return the MachO::Dyld command if present, a nullptr otherwise.
LIEF::MachO::Binary::patch_address
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.
LIEF::MachO::Binary::encryption_info
const EncryptionInfo * encryption_info() const
LIEF::MachO::Binary::main_command
MainCommand * main_command()
Return the MachO::MainCommand if present, a nullptr otherwise.
LIEF::MachO::Binary::has_encryption_info
bool has_encryption_info() const
true if the binary has Encryption Info.
Definition MachO/Binary.hpp:783
LIEF::MachO::Binary::has
bool has(LoadCommand::TYPE type) const
Check if the current binary has the given MachO::LoadCommand::TYPE.
LIEF::MachO::Binary::dyld_exports_trie
const DyldExportsTrie * dyld_exports_trie() const
LIEF::MachO::Binary::virtual_size
uint64_t virtual_size() const
Size of the binary in memory when mapped by the loader (dyld)
Definition MachO/Binary.hpp:443
LIEF::MachO::Binary::symbol_command
const SymbolCommand * symbol_command() const
LIEF::MachO::Binary::find_library
DylibCommand * find_library(const std::string &name)
Definition MachO/Binary.hpp:386
LIEF::MachO::Binary::va_ranges
range_t va_ranges() const
Return the range of virtual addresses.
LIEF::MachO::Binary::dynamic_symbol_command
DynamicSymbolCommand * dynamic_symbol_command()
Return the MachO::SymbolCommand if present, a nullptr otherwise.
LIEF::MachO::Binary::has_code_signature_dir
bool has_code_signature_dir() const
true if the binary is signed with the command DYLIB_CODE_SIGN_DRS
Definition MachO/Binary.hpp:749
LIEF::MachO::Binary::code_signature_dir
CodeSignatureDir * code_signature_dir()
Return the MachO::CodeSignatureDir if present, a nullptr otherwise.
Definition MachO/Binary.hpp:754
LIEF::MachO::Binary::has_code_signature
bool has_code_signature() const
true if the binary is signed with LC_CODE_SIGNATURE command
Definition MachO/Binary.hpp:738
LIEF::MachO::Binary::~Binary
~Binary() override
LIEF::MachO::Binary::atom_info
AtomInfo * atom_info()
Return the MachO::AtomInfo if present, a nullptr otherwise.
Definition MachO/Binary.hpp:903
LIEF::MachO::Binary::get_section
const Section * get_section(const std::string &segname, const std::string &secname) const
LIEF::MachO::Binary::has_section
bool has_section(const std::string &name) const
Check if a section with the given name exists.
Definition MachO/Binary.hpp:452
LIEF::MachO::Binary::imported_symbols
it_const_imported_symbols imported_symbols() const
Definition MachO/Binary.hpp:284
LIEF::MachO::Binary::has_main_command
bool has_main_command() const
true if the binary has a MachO::MainCommand command.
Definition MachO/Binary.hpp:635
LIEF::MachO::Binary::header
Header & header()
Return a reference to the MachO::Header.
Definition MachO/Binary.hpp:211
LIEF::MachO::Binary::add_exported_function
ExportInfo * add_exported_function(uint64_t address, const std::string &name)
Add a symbol in the export trie of the current binary.
LIEF::MachO::Binary::support_arm64_ptr_auth
bool support_arm64_ptr_auth() const
Check if the binary is supporting ARM64 pointer authentication (arm64e)
Definition MachO/Binary.hpp:970
LIEF::MachO::Binary::commands
it_const_commands commands() const
Definition MachO/Binary.hpp:225
LIEF::MachO::Binary::has_dyld_environment
bool has_dyld_environment() const
true if the binary has Dyld envrionment variables.
Definition MachO/Binary.hpp:802
LIEF::MachO::Binary::libraries
it_const_libraries libraries() const
Definition MachO/Binary.hpp:295
LIEF::MachO::Binary::fileset_name
const std::string & fileset_name() const
Name associated with the LC_FILESET_ENTRY binary.
Definition MachO/Binary.hpp:945
LIEF::MachO::Binary::for_commands
Binary & for_commands(Func f)
LIEF::MachO::Binary::has_filesets
bool has_filesets() const
true if the binary has a LoadCommand::TYPE::FILESET_ENTRY command
Definition MachO/Binary.hpp:940
LIEF::MachO::Binary::get_symbol
Symbol * get_symbol(const std::string &name)
Definition MachO/Binary.hpp:255
LIEF::MachO::Binary::segment_from_offset
SegmentCommand * segment_from_offset(uint64_t offset)
Return the binary's SegmentCommand that encompasses the provided offset.
Definition MachO/Binary.hpp:532
LIEF::MachO::Binary::dylinker
const DylinkerCommand * dylinker() const
LIEF::MachO::Binary::add
LoadCommand * add(std::unique_ptr< LoadCommand > command)
LIEF::MachO::Binary::unexport
bool unexport(const std::string &name)
Remove the given MachO::Symbol with the given name from the export table.
LIEF::MachO::Binary::unwind_functions
LIEF::Binary::functions_t unwind_functions() const
Return the functions found in the __unwind_info section.
LIEF::MachO::Binary::exported_symbols
it_const_exported_symbols exported_symbols() const
Definition MachO/Binary.hpp:268
LIEF::MachO::Binary::has_thread_command
bool has_thread_command() const
true if the binary has a MachO::ThreadCommand command.
Definition MachO/Binary.hpp:689
LIEF::MachO::Binary::add
Symbol & add(const Symbol &symbol)
Add a symbol to this binary.
LIEF::MachO::Binary::unexport
bool unexport(const Symbol &sym)
Remove the given symbol from the export table.
LIEF::MachO::Binary::build_version
const BuildVersion * build_version() const
LIEF::MachO::Binary::sub_framework
SubFramework * sub_framework()
Return the MachO::SubFramework if present, a nullptr otherwise.
LIEF::MachO::Binary::routine_command
Routine * routine_command()
Return the MachO::Routine command if present, a nullptr otherwise.
LIEF::MachO::Binary::sections
it_sections sections()
Return an iterator over the MachO::Section.
Definition MachO/Binary.hpp:308
LIEF::MachO::Builder
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:60
LIEF::MachO::CodeSignatureDir
Definition CodeSignatureDir.hpp:36
LIEF::MachO::CodeSignature
Definition CodeSignature.hpp:37
LIEF::MachO::DataInCode
Interface of the LC_DATA_IN_CODE command This command is used to list slices of code sections that co...
Definition DataInCode.hpp:42
LIEF::MachO::DyldChainedFixups
Class that represents the LC_DYLD_CHAINED_FIXUPS command.
Definition DyldChainedFixups.hpp:49
LIEF::MachO::DyldEnvironment
Class that represents a LC_DYLD_ENVIRONMENT command which is used by the Mach-O linker/loader to init...
Definition DyldEnvironment.hpp:34
LIEF::MachO::DyldExportsTrie
Class that represents the LC_DYLD_EXPORTS_TRIE command.
Definition DyldExportsTrie.hpp:40
LIEF::MachO::DyldInfo
Class that represents the LC_DYLD_INFO and LC_DYLD_INFO_ONLY commands.
Definition DyldInfo.hpp:50
LIEF::MachO::DylibCommand
Class which represents a library dependency.
Definition DylibCommand.hpp:34
LIEF::MachO::DylinkerCommand
Class that represents the Mach-O linker, also named loader. Most of the time, DylinkerCommand::name()...
Definition DylinkerCommand.hpp:34
LIEF::MachO::DynamicSymbolCommand
Class that represents the LC_DYSYMTAB command.
Definition DynamicSymbolCommand.hpp:40
LIEF::MachO::EncryptionInfo
Class that represents the LC_ENCRYPTION_INFO / LC_ENCRYPTION_INFO_64 commands.
Definition EncryptionInfo.hpp:35
LIEF::MachO::ExportInfo
Class that provides an interface over the Dyld export info.
Definition ExportInfo.hpp:38
LIEF::MachO::FunctionStarts
Class which represents the LC_FUNCTION_STARTS command.
Definition FunctionStarts.hpp:39
LIEF::MachO::Header
Class that represents the Mach-O header.
Definition MachO/Header.hpp:38
LIEF::MachO::IndirectBindingInfo
This class represents a binding operation infered from the indirect symbol table.
Definition IndirectBindingInfo.hpp:29
LIEF::MachO::LinkerOptHint
Class which represents the LC_LINKER_OPTIMIZATION_HINT command.
Definition LinkerOptHint.hpp:37
LIEF::MachO::LoadCommand::clone
virtual std::unique_ptr< LoadCommand > clone() const
Definition LoadCommand.hpp:118
LIEF::MachO::MainCommand
Class that represent the LC_MAIN command. This kind of command can be used to determine the entrypoin...
Definition MainCommand.hpp:33
LIEF::MachO::Parser
The main interface to parse a Mach-O binary.
Definition MachO/Parser.hpp:42
LIEF::MachO::RPathCommand
Class that represents the LC_RPATH command.
Definition RPathCommand.hpp:36
LIEF::MachO::Relocation
Class that represents a Mach-O relocation.
Definition MachO/Relocation.hpp:40
LIEF::MachO::Routine
Class that represents the LC_ROUTINE/LC_ROUTINE64 commands. Accodring to the Mach-O loader....
Definition Routine.hpp:38
LIEF::MachO::Section
Class that represents a Mach-O section.
Definition MachO/Section.hpp:46
LIEF::MachO::SegmentCommand
Class which represents a LoadCommand::TYPE::SEGMENT / LoadCommand::TYPE::SEGMENT_64 command.
Definition SegmentCommand.hpp:50
LIEF::MachO::SegmentSplitInfo
Class that represents the LoadCommand::TYPE::SEGMENT_SPLIT_INFO command.
Definition SegmentSplitInfo.hpp:35
LIEF::MachO::SourceVersion
Class that represents the MachO LoadCommand::TYPE::SOURCE_VERSION This command is used to provide the...
Definition SourceVersion.hpp:35
LIEF::MachO::SubClient
Class that represents the SubClient command. Accodring to the Mach-O loader.h documentation:
Definition SubClient.hpp:43
LIEF::MachO::SubFramework
Class that represents the SubFramework command. Accodring to the Mach-O loader.h documentation:
Definition SubFramework.hpp:46
LIEF::MachO::SymbolCommand
Class that represents the LC_SYMTAB command.
Definition SymbolCommand.hpp:35
LIEF::MachO::Symbol
Class that represents a Symbol in a Mach-O file.
Definition MachO/Symbol.hpp:47
LIEF::MachO::ThreadCommand
Class that represents the LC_THREAD / LC_UNIXTHREAD commands and that can be used to get the binary e...
Definition ThreadCommand.hpp:41
LIEF::MachO::TwoLevelHints
Class which represents the LC_TWOLEVEL_HINTS command.
Definition TwoLevelHints.hpp:39
LIEF::MachO::UUIDCommand
Class that represents the UUID command.
Definition UUIDCommand.hpp:35
LIEF::MachO::VersionMin
Class that wraps the LC_VERSION_MIN_MACOSX, LC_VERSION_MIN_IPHONEOS, ... commands.
Definition VersionMin.hpp:33
LIEF::objc::Metadata
This class is the main interface to inspect Objective-C metadata.
Definition ObjC/Metadata.hpp:37
errors.hpp
iterators.hpp
LIEF::MachO
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
LIEF::objc
Namespace related to ObjC metadata.
Definition MachO/Binary.hpp:41
LIEF
LIEF namespace.
Definition Abstract/Binary.hpp:39
LIEF::ok_error_t
result< ok_t > ok_error_t
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:109
LIEF::align
uint64_t align(uint64_t value, uint64_t align_on)
Definition utils.hpp:28
LIEF::ok
ok_t ok()
Return success for function with return type ok_error_t.
Definition errors.hpp:93
LIEF::MachO::Binary::range_t::start
uint64_t start
Definition MachO/Binary.hpp:96
LIEF::MachO::Binary::range_t::size
uint64_t size() const
Definition MachO/Binary.hpp:99
LIEF::MachO::Binary::range_t::end
uint64_t end
Definition MachO/Binary.hpp:97
LIEF::MachO::Binary::range_t::empty
bool empty() const
Definition MachO/Binary.hpp:103
utils.hpp
visibility.h
LIEF_API
#define LIEF_API
Definition visibility.h:41
LIEF_LOCAL
#define LIEF_LOCAL
Definition visibility.h:42