58 using info_t = std::pair<uint32_t, uint32_t>;
78 enum class BINDING_ENCODING_VERSION {
84 enum class REBASE_TYPE: uint64_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,
124 enum class BIND_SUBOPCODE_THREADED: uint8_t {
125 SET_BIND_ORDINAL_TABLE_SIZE_ULEB = 0x00u,
129 enum BIND_SYMBOL_FLAGS {
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);
140 DyldInfo& operator=(DyldInfo other);
141 DyldInfo(
const DyldInfo& copy);
143 void swap(DyldInfo& other)
noexcept;
145 std::unique_ptr<LoadCommand> clone()
const override {
146 return std::unique_ptr<DyldInfo>(
new DyldInfo(*
this));
149 ~DyldInfo()
override;
170 return rebase_opcodes_;
172 span<uint8_t> rebase_opcodes() {
173 return rebase_opcodes_;
202 return bind_opcodes_;
204 span<uint8_t> bind_opcodes() {
205 return bind_opcodes_;
237 return weak_bind_opcodes_;
239 span<uint8_t> weak_bind_opcodes() {
240 return weak_bind_opcodes_;
269 return lazy_bind_opcodes_;
271 span<uint8_t> lazy_bind_opcodes() {
272 return lazy_bind_opcodes_;
283 return binding_info_;
286 it_const_binding_info bindings()
const {
287 return binding_info_;
324 it_const_export_info exports()
const {
332 span<uint8_t> export_trie() {
342 void rebase(
const info_t& info) {
345 void bind(
const info_t& info) {
348 void weak_bind(
const info_t& info) {
351 void lazy_bind(
const info_t& info) {
354 void export_info(
const info_t& info) {
358 void set_rebase_offset(uint32_t offset) {
359 rebase_ = {offset, std::get<1>(rebase())};
361 void set_rebase_size(uint32_t size) {
362 rebase_ = {std::get<0>(rebase()), size};
365 void set_bind_offset(uint32_t offset) {
366 bind_ = {offset, std::get<1>(bind())};
368 void set_bind_size(uint32_t size) {
369 bind_ = {std::get<0>(bind()), size};
372 void set_weak_bind_offset(uint32_t offset) {
373 weak_bind_ = {offset, std::get<1>(weak_bind())};
375 void set_weak_bind_size(uint32_t size) {
376 weak_bind_ = {std::get<0>(weak_bind()), size};
379 void set_lazy_bind_offset(uint32_t offset) {
380 lazy_bind_ = {offset, std::get<1>(lazy_bind())};
382 void set_lazy_bind_size(uint32_t size) {
383 lazy_bind_ = {std::get<0>(lazy_bind()), size};
386 void set_export_offset(uint32_t offset) {
387 export_ = {offset, std::get<1>(export_info())};
390 void set_export_size(uint32_t size) {
391 export_ = {std::get<0>(export_info()), size};
394 void add(std::unique_ptr<ExportInfo> info);
396 void accept(Visitor& visitor)
const override;
398 std::ostream& print(std::ostream& os)
const override;
400 static bool classof(
const LoadCommand* cmd) {
401 const LoadCommand::TYPE type = cmd->command();
402 return type == LoadCommand::TYPE::DYLD_INFO ||
403 type == LoadCommand::TYPE::DYLD_INFO_ONLY;
407 using bind_container_t = std::set<DyldBindingInfo*, std::function<bool(DyldBindingInfo*, DyldBindingInfo*)>>;
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;
413 LIEF_LOCAL DyldInfo& update_standard_bindings(
const bind_container_t& bindings, vector_iostream& stream);
414 LIEF_LOCAL DyldInfo& update_standard_bindings_v1(
const bind_container_t& bindings, vector_iostream& stream);
415 LIEF_LOCAL DyldInfo& update_standard_bindings_v2(
const bind_container_t& bindings,
416 std::vector<RelocationDyld*> rebases, vector_iostream& stream);
418 LIEF_LOCAL DyldInfo& update_weak_bindings(
const bind_container_t& bindings, vector_iostream& stream);
419 LIEF_LOCAL DyldInfo& update_lazy_bindings(
const bind_container_t& bindings, vector_iostream& stream);
421 LIEF_LOCAL DyldInfo& update_rebase_info(vector_iostream& stream);
422 LIEF_LOCAL DyldInfo& update_binding_info(vector_iostream& stream, details::dyld_info_command& cmd);
423 LIEF_LOCAL DyldInfo& update_export_trie(vector_iostream& stream);
426 span<uint8_t> rebase_opcodes_;
429 span<uint8_t> bind_opcodes_;
432 span<uint8_t> weak_bind_opcodes_;
435 span<uint8_t> lazy_bind_opcodes_;
438 span<uint8_t> export_trie_;
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;