16#ifndef LIEF_MACHO_DYLD_INFO_COMMAND_H
17#define LIEF_MACHO_DYLD_INFO_COMMAND_H
45struct dyld_info_command;
58 using info_t = std::pair<uint32_t, uint32_t>;
94 SET_SEGMENT_AND_OFFSET_ULEB = 0x20u,
95 ADD_ADDR_ULEB = 0x30u,
96 ADD_ADDR_IMM_SCALED = 0x40u,
97 DO_REBASE_IMM_TIMES = 0x50u,
98 DO_REBASE_ULEB_TIMES = 0x60u,
99 DO_REBASE_ADD_ADDR_ULEB = 0x70u,
100 DO_REBASE_ULEB_TIMES_SKIPPING_ULEB = 0x80u
106 SET_DYLIB_ORDINAL_IMM = 0x10u,
107 SET_DYLIB_ORDINAL_ULEB = 0x20u,
108 SET_DYLIB_SPECIAL_IMM = 0x30u,
109 SET_SYMBOL_TRAILING_FLAGS_IMM = 0x40u,
110 SET_TYPE_IMM = 0x50u,
111 SET_ADDEND_SLEB = 0x60u,
112 SET_SEGMENT_AND_OFFSET_ULEB = 0x70u,
113 ADD_ADDR_ULEB = 0x80u,
115 DO_BIND_ADD_ADDR_ULEB = 0xA0u,
116 DO_BIND_ADD_ADDR_IMM_SCALED = 0xB0u,
117 DO_BIND_ULEB_TIMES_SKIPPING_ULEB = 0xC0u,
120 THREADED_APPLY = 0xD0u | 0x01u,
121 THREADED_SET_BIND_ORDINAL_TABLE_SIZE_ULEB = 0xD0u | 0x00u,
125 SET_BIND_ORDINAL_TABLE_SIZE_ULEB = 0x00u,
131 NON_WEAK_DEFINITION = 0x8u,
134 static constexpr auto OPCODE_MASK = uint32_t(0xF0);
135 static constexpr auto IMMEDIATE_MASK = uint32_t(0x0F);
138 DyldInfo(
const details::dyld_info_command& dyld_info_cmd);
145 std::unique_ptr<LoadCommand>
clone()
const override {
146 return std::unique_ptr<DyldInfo>(
new DyldInfo(*
this));
170 return rebase_opcodes_;
173 return rebase_opcodes_;
202 return bind_opcodes_;
205 return bind_opcodes_;
237 return weak_bind_opcodes_;
240 return weak_bind_opcodes_;
269 return lazy_bind_opcodes_;
272 return lazy_bind_opcodes_;
283 return binding_info_;
287 return binding_info_;
359 rebase_ = {offset, std::get<1>(rebase())};
362 rebase_ = {std::get<0>(rebase()), size};
366 bind_ = {offset, std::get<1>(bind())};
369 bind_ = {std::get<0>(bind()), size};
373 weak_bind_ = {offset, std::get<1>(weak_bind())};
376 weak_bind_ = {std::get<0>(weak_bind()), size};
380 lazy_bind_ = {offset, std::get<1>(lazy_bind())};
383 lazy_bind_ = {std::get<0>(lazy_bind()), size};
387 export_ = {offset, std::get<1>(export_info())};
391 export_ = {std::get<0>(export_info()), size};
394 void add(std::unique_ptr<ExportInfo> info);
398 std::ostream&
print(std::ostream& os)
const override;
402 return type == LoadCommand::TYPE::DYLD_INFO ||
403 type == LoadCommand::TYPE::DYLD_INFO_ONLY;
409 void show_bindings(std::ostream& os,
span<const uint8_t> buffer,
bool is_lazy =
false)
const;
411 void show_trie(std::ostream& output, std::string output_prefix,
BinaryStream& stream, uint64_t start, uint64_t end,
const std::string& prefix)
const;
440 export_info_t export_info_;
441 binding_info_t binding_info_;
443 BINDING_ENCODING_VERSION binding_encoding_version_ = BINDING_ENCODING_VERSION::UNKNOWN;
445 Binary* binary_ =
nullptr;
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:34
Class used to parse a single binary (i.e. non-FAT)
Definition BinaryParser.hpp:74
Class which represents a MachO binary.
Definition MachO/Binary.hpp:77
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:55
This class represents a symbol binding operation associated with the LC_DYLD_INFO bytecode.
Definition DyldBindingInfo.hpp:34
Class that represents the LC_DYLD_INFO and LC_DYLD_INFO_ONLY commands.
Definition DyldInfo.hpp:49
BIND_SYMBOL_FLAGS
Definition DyldInfo.hpp:129
void weak_bind(const info_t &info)
Definition DyldInfo.hpp:348
std::ostream & print(std::ostream &os) const override
void set_export_size(uint32_t size)
Definition DyldInfo.hpp:390
span< const uint8_t > bind_opcodes() const
Return Binding's opcodes as raw data.
Definition DyldInfo.hpp:201
void add(std::unique_ptr< ExportInfo > info)
std::string show_lazy_bind_opcodes() const
Return the lazy opcodes in a humman-readable way.
BIND_OPCODES
Opcodes used by Dyld info to bind symbols.
Definition DyldInfo.hpp:104
it_const_binding_info bindings() const
Definition DyldInfo.hpp:286
DyldInfo(const details::dyld_info_command &dyld_info_cmd)
span< const uint8_t > rebase_opcodes() const
Return Rebase's opcodes as raw data.
Definition DyldInfo.hpp:169
void lazy_bind_opcodes(buffer_t raw)
Set new opcodes.
static bool classof(const LoadCommand *cmd)
Definition DyldInfo.hpp:400
void set_weak_bind_size(uint32_t size)
Definition DyldInfo.hpp:375
const info_t & export_info() const
Export information
Definition DyldInfo.hpp:316
REBASE_OPCODES
Definition DyldInfo.hpp:91
void set_bind_size(uint32_t size)
Definition DyldInfo.hpp:368
std::string show_export_trie() const
Return the export trie in a humman-readable way.
const info_t & bind() const
Bind information
Definition DyldInfo.hpp:196
std::unique_ptr< LoadCommand > clone() const override
Definition DyldInfo.hpp:145
const info_t & rebase() const
Rebase information
Definition DyldInfo.hpp:164
std::vector< std::unique_ptr< DyldBindingInfo > > binding_info_t
Internal container for storing DyldBindingInfo.
Definition DyldInfo.hpp:61
DyldInfo & operator=(DyldInfo other)
void rebase_opcodes(buffer_t raw)
Set new opcodes.
void set_bind_offset(uint32_t offset)
Definition DyldInfo.hpp:365
BIND_SUBOPCODE_THREADED
Definition DyldInfo.hpp:124
DyldInfo(const DyldInfo ©)
span< uint8_t > lazy_bind_opcodes()
Definition DyldInfo.hpp:271
void set_rebase_offset(uint32_t offset)
Definition DyldInfo.hpp:358
void export_info(const info_t &info)
Definition DyldInfo.hpp:354
BINDING_ENCODING_VERSION
Definition DyldInfo.hpp:78
void set_lazy_bind_size(uint32_t size)
Definition DyldInfo.hpp:382
const info_t & weak_bind() const
Weak Bind information
Definition DyldInfo.hpp:231
span< uint8_t > rebase_opcodes()
Definition DyldInfo.hpp:172
void set_export_offset(uint32_t offset)
Definition DyldInfo.hpp:386
it_binding_info bindings()
Iterator over BindingInfo entries.
Definition DyldInfo.hpp:282
span< uint8_t > export_trie()
Definition DyldInfo.hpp:332
void weak_bind_opcodes(buffer_t raw)
Set new opcodes.
it_export_info exports()
Iterator over ExportInfo entries.
Definition DyldInfo.hpp:321
void lazy_bind(const info_t &info)
Definition DyldInfo.hpp:351
void set_weak_bind_offset(uint32_t offset)
Definition DyldInfo.hpp:372
void bind_opcodes(buffer_t raw)
Set new opcodes.
REBASE_TYPE
Definition DyldInfo.hpp:84
std::pair< uint32_t, uint32_t > info_t
Tuple of offset and size
Definition DyldInfo.hpp:58
void bind(const info_t &info)
Definition DyldInfo.hpp:345
std::string show_bind_opcodes() const
Return the bind opcodes in a humman-readable way.
void rebase(const info_t &info)
Definition DyldInfo.hpp:342
span< uint8_t > weak_bind_opcodes()
Definition DyldInfo.hpp:239
std::string show_rebases_opcodes() const
Return the rebase opcodes in a humman-readable way.
void export_trie(buffer_t raw)
Set new trie.
span< const uint8_t > lazy_bind_opcodes() const
Return Lazy Binding's opcodes as raw data.
Definition DyldInfo.hpp:268
it_const_export_info exports() const
Definition DyldInfo.hpp:324
void set_lazy_bind_offset(uint32_t offset)
Definition DyldInfo.hpp:379
const info_t & lazy_bind() const
Lazy Bind information
Definition DyldInfo.hpp:263
span< uint8_t > bind_opcodes()
Definition DyldInfo.hpp:204
std::vector< std::unique_ptr< ExportInfo > > export_info_t
Internal container for storing ExportInfo.
Definition DyldInfo.hpp:70
span< const uint8_t > export_trie() const
Return Export's trie as raw data.
Definition DyldInfo.hpp:329
void swap(DyldInfo &other) noexcept
void accept(Visitor &visitor) const override
void set_rebase_size(uint32_t size)
Definition DyldInfo.hpp:361
span< const uint8_t > weak_bind_opcodes() const
Return Weak Binding's opcodes as raw data.
Definition DyldInfo.hpp:236
std::string show_weak_bind_opcodes() const
Return the bind opcodes in a humman-readable way.
Definition LinkEdit.hpp:42
Based class for the Mach-O load commands.
Definition LoadCommand.hpp:36
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:122
TYPE
Definition LoadCommand.hpp:42
Definition Visitor.hpp:224
Iterator which returns reference on container's values.
Definition iterators.hpp:48
Definition iostream.hpp:29
std::vector< uint8_t > buffer_t
Definition MachO/type_traits.hpp:24
const char * to_string(BuildToolVersion::TOOLS tool)
LIEF namespace.
Definition Abstract/Binary.hpp:32
tcb::span< ElementType, Extent > span
Definition span.hpp:22
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42