16#ifndef LIEF_MACHO_BINARY_PARSER_H
17#define LIEF_MACHO_BINARY_PARSER_H
24#include <unordered_map>
65struct dyld_chained_starts_in_segment;
66struct dyld_chained_fixups_header;
67union dyld_chained_ptr_arm64e;
68union dyld_chained_ptr_generic64;
69union dyld_chained_ptr_generic32;
70union dyld_chained_ptr_arm64e_segmented;
83 constexpr static size_t MAX_RELOCATIONS = (std::numeric_limits<uint16_t>::max)();
86 constexpr static size_t MAX_COMMANDS = (std::numeric_limits<uint16_t>::max)();
89 static std::unique_ptr<Binary>
parse(
const std::string& file);
91 static std::unique_ptr<Binary>
parse(
const std::vector<uint8_t>& data,
94 static std::unique_ptr<Binary>
parse(
const std::vector<uint8_t>& data, uint64_t fat_offset,
97 static std::unique_ptr<Binary>
parse(std::unique_ptr<BinaryStream> stream, uint64_t fat_offset,
106 using exports_list_t = std::vector<std::unique_ptr<ExportInfo>>;
111 template<
class MACHO_T>
114 template<
class MACHO_T>
117 template<
class MACHO_T>
120 template<
class MACHO_T>
128 template<
class MACHO_T>
133 template<
class MACHO_T>
136 template<
class MACHO_T>
139 template<
class MACHO_T>
142 template<
class MACHO_T>
145 template<
class MACHO_T>
148 template<
class MACHO_T>
157 template<
class MACHO_T>
160 using it_opaque_segments =
void*;
162 template<
class MACHO_T>
164 uint64_t segment_offset,
const std::string& symbol_name,
165 int32_t ord, int64_t addend,
bool is_weak,
166 bool is_non_weak_definition, it_opaque_segments segments_ptr, uint64_t offset = 0);
169 template<
class MACHO_T>
171 uint8_t type, uint8_t segment_idx, uint64_t segment_offset,
172 it_opaque_segments segments);
177 template<
class MACHO_T>
180 template<
class MACHO_T>
182 const details::dyld_chained_fixups_header& header,
SpanStream& stream,
185 template<
class MACHO_T>
187 const details::dyld_chained_fixups_header& header,
SpanStream& stream);
189 template<
class MACHO_T>
191 SpanStream& stream, uint32_t seg_info_offset, uint64_t offset,
194 template<
class MACHO_T>
197 int64_t addend,
bool is_weak);
199 template<
class MACHO_T>
201 SegmentCommand& segment, uint64_t chain_address, uint64_t chain_offset,
202 const details::dyld_chained_starts_in_segment& seg_info);
204 template<
class MACHO_T>
206 uint64_t& chain_address, uint64_t chain_offset,
207 const details::dyld_chained_starts_in_segment& seg_info);
209 template<
class MACHO_T>
211 SegmentCommand& segment, uint64_t chain_address, uint64_t chain_offset,
212 const details::dyld_chained_starts_in_segment& seg_info);
215 SegmentCommand& segment, uint64_t chain_address, uint32_t chain_offset,
216 const details::dyld_chained_starts_in_segment& seg_info,
217 const details::dyld_chained_ptr_arm64e& fixup);
220 SegmentCommand& segment, uint64_t chain_address, uint32_t chain_offset,
221 const details::dyld_chained_starts_in_segment& seg_info,
222 const details::dyld_chained_ptr_generic64& fixup);
225 SegmentCommand& segment, uint64_t chain_address, uint32_t chain_offset,
226 const details::dyld_chained_starts_in_segment& seg_info,
227 const details::dyld_chained_ptr_generic32 & fixup);
230 SegmentCommand& segment, uint64_t chain_address, uint32_t chain_offset,
231 const details::dyld_chained_starts_in_segment& seg_info,
232 const details::dyld_chained_ptr_arm64e_segmented& fixup);
234 template<
class MACHO_T>
237 template<
class MACHO_T>
240 template<
class MACHO_T>
243 template<
class MACHO_T>
246 template<
class MACHO_T>
249 template<
class MACHO_T>
252 template<
class MACHO_T>
255 template<
class MACHO_T>
258 template<
class MACHO_T>
261 template<
class MACHO_T>
264 template<
class MACHO_T>
267 template<
class MACHO_T>
279 uint64_t start,
const std::string& prefix,
bool* invalid_names);
283 std::unique_ptr<BinaryStream> stream_;
284 std::unique_ptr<Binary> binary_;
288 std::set<uint64_t> visited_;
289 std::unordered_map<std::string, Symbol*> memoized_symbols_;
290 std::map<uint64_t, Symbol*> memoized_symbols_by_address_;
292 std::vector<DylibCommand*> binding_libs_;
293 std::set<uint64_t> dyld_reloc_addrs_;
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:33
Class which represents the LC_ATOM_INFO command.
Definition AtomInfo.hpp:35
BinaryParser(const BinaryParser ©)=delete
BinaryParser & operator=(const BinaryParser ©)=delete
static std::unique_ptr< Binary > parse(std::unique_ptr< BinaryStream > stream, uint64_t fat_offset, const ParserConfig &conf)
static std::unique_ptr< Binary > parse(const std::vector< uint8_t > &data, uint64_t fat_offset, const ParserConfig &conf=ParserConfig::deep())
static std::unique_ptr< Binary > parse(const std::string &file)
static std::unique_ptr< Binary > parse(const std::string &file, const ParserConfig &conf)
static std::unique_ptr< Binary > parse(const std::vector< uint8_t > &data, const ParserConfig &conf=ParserConfig::deep())
This class represents a symbol binding operation associated with the LC_DYLD_CHAINED_FIXUPS command.
Definition ChainedBindingInfo.hpp:48
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
Definition DyldBindingInfo.hpp:38
Class that represents the LC_DYLD_CHAINED_FIXUPS command.
Definition DyldChainedFixups.hpp:49
Class which represents a library dependency.
Definition DylibCommand.hpp:34
Class that represents the LC_DYSYMTAB command.
Definition DynamicSymbolCommand.hpp:40
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
Class which represents the LC_FUNCTION_VARIANT_FIXUPS command.
Definition FunctionVariantFixups.hpp:34
Class representing the LC_FUNCTION_VARIANTS load command.
Definition FunctionVariants.hpp:59
Class which represents the LC_LINKER_OPTIMIZATION_HINT command.
Definition LinkerOptHint.hpp:37
The main interface to parse a Mach-O binary.
Definition MachO/Parser.hpp:42
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 LC_SYMTAB command.
Definition SymbolCommand.hpp:35
Class that represents a Symbol in a Mach-O file.
Definition MachO/Symbol.hpp:47
Class which represents the LC_TWOLEVEL_HINTS command.
Definition TwoLevelHints.hpp:39
Main interface to parse an executable regardless of its format.
Definition Abstract/Parser.hpp:30
Definition SpanStream.hpp:32
Definition endianness_support.hpp:59
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
DYLD_CHAINED_FORMAT
Definition DyldChainedFormat.hpp:22
MACHO_TYPES
Definition MachO/enums.hpp:23
@ MAGIC_64
64-bit big-endian magic
Definition MachO/enums.hpp:27
LIEF namespace.
Definition Abstract/Binary.hpp:40
result< ok_t > ok_error_t
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:109
tl::expected< T, lief_errors > result
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:75
This structure is used to tweak the MachO Parser (MachO::Parser).
Definition MachO/ParserConfig.hpp:24
static ParserConfig deep()
Return a parser configuration such as all the objects supported by LIEF are parsed.
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42