LIEF: Library to Instrument Executable Formats Version 0.16.0
|
Loading...
Searching...
No Matches
Go to the documentation of this file.
16#ifndef LIEF_MACHO_DYLD_INFO_COMMAND_H
17#define LIEF_MACHO_DYLD_INFO_COMMAND_H
46struct dyld_info_command;
52 friend class BinaryParser;
55 friend class LinkEdit;
56 friend class BindingInfoIterator;
58 public:
using info_t = std::pair<uint32_t, uint32_t>;
61 using binding_info_t = std::vector<std::unique_ptr<DyldBindingInfo>>;
64 using it_binding_info = ref_iterator<binding_info_t&, DyldBindingInfo*>;
67 using it_const_binding_info = const_ref_iterator<const binding_info_t&, DyldBindingInfo*>;
70 using export_info_t = std::vector<std::unique_ptr<ExportInfo>>;
73 using it_export_info = ref_iterator<export_info_t&, ExportInfo*>;
76 using it_const_export_info = const_ref_iterator<const export_info_t&, ExportInfo*>;
80 enum class BINDING_ENCODING_VERSION {
86 enum class REBASE_TYPE: uint64_t {
93 enum class REBASE_OPCODES: uint8_t {
96 SET_SEGMENT_AND_OFFSET_ULEB = 0x20u,
97 ADD_ADDR_ULEB = 0x30u,
98 ADD_ADDR_IMM_SCALED = 0x40u,
99 DO_REBASE_IMM_TIMES = 0x50u,
100 DO_REBASE_ULEB_TIMES = 0x60u,
101 DO_REBASE_ADD_ADDR_ULEB = 0x70u,
102 DO_REBASE_ULEB_TIMES_SKIPPING_ULEB = 0x80u
104 enum class BIND_OPCODES: uint8_t {
108 SET_DYLIB_ORDINAL_IMM = 0x10u,
109 SET_DYLIB_ORDINAL_ULEB = 0x20u,
110 SET_DYLIB_SPECIAL_IMM = 0x30u,
111 SET_SYMBOL_TRAILING_FLAGS_IMM = 0x40u,
112 SET_TYPE_IMM = 0x50u,
113 SET_ADDEND_SLEB = 0x60u,
114 SET_SEGMENT_AND_OFFSET_ULEB = 0x70u,
115 ADD_ADDR_ULEB = 0x80u,
117 DO_BIND_ADD_ADDR_ULEB = 0xA0u,
118 DO_BIND_ADD_ADDR_IMM_SCALED = 0xB0u,
119 DO_BIND_ULEB_TIMES_SKIPPING_ULEB = 0xC0u,
122 THREADED_APPLY = 0xD0u | 0x01u,
123 THREADED_SET_BIND_ORDINAL_TABLE_SIZE_ULEB = 0xD0u | 0x00u,
126 enum class BIND_SUBOPCODE_THREADED: uint8_t {
127 SET_BIND_ORDINAL_TABLE_SIZE_ULEB = 0x00u,
131 enum BIND_SYMBOL_FLAGS {
133 NON_WEAK_DEFINITION = 0x8u,
136 static constexpr auto OPCODE_MASK = uint32_t(0xF0);
137 static constexpr auto IMMEDIATE_MASK = uint32_t(0x0F);
140 DyldInfo(
const details::dyld_info_command& dyld_info_cmd);
145 void swap(DyldInfo& other)
noexcept;
147 std::unique_ptr<LoadCommand>
clone()
const override {
148 return std::unique_ptr<DyldInfo>(
new DyldInfo(*
this));
152 const info_t&
rebase()
const {
172 return rebase_opcodes_;
175 return rebase_opcodes_;
183 const info_t&
bind()
const {
204 return bind_opcodes_;
207 return bind_opcodes_;
239 return weak_bind_opcodes_;
242 return weak_bind_opcodes_;
271 return lazy_bind_opcodes_;
274 return lazy_bind_opcodes_;
285 return binding_info_;
289 return binding_info_;
347 void bind(
const info_t& info) {
361 rebase_ = {offset, std::get<1>(rebase())};
364 rebase_ = {std::get<0>(rebase()), size};
368 bind_ = {offset, std::get<1>(bind())};
371 bind_ = {std::get<0>(bind()), size};
375 weak_bind_ = {offset, std::get<1>(weak_bind())};
378 weak_bind_ = {std::get<0>(weak_bind()), size};
382 lazy_bind_ = {offset, std::get<1>(lazy_bind())};
385 lazy_bind_ = {std::get<0>(lazy_bind()), size};
389 export_ = {offset, std::get<1>(export_info())};
393 export_ = {std::get<0>(export_info()), size};
396 void add(std::unique_ptr<ExportInfo> info);
398 void accept(Visitor& visitor)
const override;
400 std::ostream&
print(std::ostream& os)
const override;
403 const LoadCommand::TYPE type = cmd->
command();
404 return type == LoadCommand::TYPE::DYLD_INFO ||
405 type == LoadCommand::TYPE::DYLD_INFO_ONLY;
409 using bind_container_t = std::set<DyldBindingInfo*, std::function<bool(DyldBindingInfo*, DyldBindingInfo*)>>;
411 LIEF_LOCAL void show_bindings(std::ostream& os, span<const uint8_t> buffer,
bool is_lazy =
false)
const;
413 LIEF_LOCAL void show_trie(std::ostream& output, std::string output_prefix,
414 BinaryStream& stream, uint64_t start, uint64_t end,
415 const std::string& prefix)
const;
417 LIEF_LOCAL DyldInfo& update_standard_bindings(
const bind_container_t& bindings, vector_iostream& stream);
418 LIEF_LOCAL DyldInfo& update_standard_bindings_v1(
const bind_container_t& bindings, vector_iostream& stream);
419 LIEF_LOCAL DyldInfo& update_standard_bindings_v2(
const bind_container_t& bindings,
420 std::vector<RelocationDyld*> rebases, vector_iostream& stream);
422 LIEF_LOCAL DyldInfo& update_weak_bindings(
const bind_container_t& bindings, vector_iostream& stream);
423 LIEF_LOCAL DyldInfo& update_lazy_bindings(
const bind_container_t& bindings, vector_iostream& stream);
425 LIEF_LOCAL DyldInfo& update_rebase_info(vector_iostream& stream);
426 LIEF_LOCAL DyldInfo& update_binding_info(vector_iostream& stream, details::dyld_info_command& cmd);
427 LIEF_LOCAL DyldInfo& update_export_trie(vector_iostream& stream);
430 span<uint8_t> rebase_opcodes_;
433 span<uint8_t> bind_opcodes_;
436 span<uint8_t> weak_bind_opcodes_;
439 span<uint8_t> lazy_bind_opcodes_;
442 span<uint8_t> export_trie_;
444 export_info_t export_info_;
445 binding_info_t binding_info_;
447 BINDING_ENCODING_VERSION binding_encoding_version_ = BINDING_ENCODING_VERSION::UNKNOWN;
449 Binary* binary_ =
nullptr;
Class that is used to a read stream of data from different sources.
Definition BinaryStream.hpp:33
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:85
Definition BindingInfoIterator.hpp:36
Class used to rebuild a Mach-O file.
Definition MachO/Builder.hpp:57
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:50
void weak_bind(const info_t &info)
Definition DyldInfo.hpp:350
std::ostream & print(std::ostream &os) const override
void set_export_size(uint32_t size)
Definition DyldInfo.hpp:392
span< const uint8_t > bind_opcodes() const
Return Binding's opcodes as raw data.
Definition DyldInfo.hpp:203
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:106
it_const_binding_info bindings() const
Definition DyldInfo.hpp:288
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:171
void lazy_bind_opcodes(buffer_t raw)
Set new opcodes.
static bool classof(const LoadCommand *cmd)
Definition DyldInfo.hpp:402
void set_weak_bind_size(uint32_t size)
Definition DyldInfo.hpp:377
const info_t & export_info() const
Export information
Definition DyldInfo.hpp:318
REBASE_OPCODES
Definition DyldInfo.hpp:93
void set_bind_size(uint32_t size)
Definition DyldInfo.hpp:370
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:198
std::unique_ptr< LoadCommand > clone() const override
Definition DyldInfo.hpp:147
const info_t & rebase() const
Rebase information
Definition DyldInfo.hpp:166
DyldInfo & operator=(DyldInfo other)
void rebase_opcodes(buffer_t raw)
Set new opcodes.
void set_bind_offset(uint32_t offset)
Definition DyldInfo.hpp:367
BIND_SUBOPCODE_THREADED
Definition DyldInfo.hpp:126
DyldInfo(const DyldInfo ©)
span< uint8_t > lazy_bind_opcodes()
Definition DyldInfo.hpp:273
void set_rebase_offset(uint32_t offset)
Definition DyldInfo.hpp:360
void export_info(const info_t &info)
Definition DyldInfo.hpp:356
void set_lazy_bind_size(uint32_t size)
Definition DyldInfo.hpp:384
const info_t & weak_bind() const
Weak Bind information
Definition DyldInfo.hpp:233
span< uint8_t > rebase_opcodes()
Definition DyldInfo.hpp:174
void set_export_offset(uint32_t offset)
Definition DyldInfo.hpp:388
it_binding_info bindings()
Iterator over BindingInfo entries.
Definition DyldInfo.hpp:284
span< uint8_t > export_trie()
Definition DyldInfo.hpp:334
void weak_bind_opcodes(buffer_t raw)
Set new opcodes.
it_export_info exports()
Iterator over ExportInfo entries.
Definition DyldInfo.hpp:323
void lazy_bind(const info_t &info)
Definition DyldInfo.hpp:353
void set_weak_bind_offset(uint32_t offset)
Definition DyldInfo.hpp:374
void bind_opcodes(buffer_t raw)
Set new opcodes.
REBASE_TYPE
Definition DyldInfo.hpp:86
void bind(const info_t &info)
Definition DyldInfo.hpp:347
std::string show_bind_opcodes() const
Return the bind opcodes in a humman-readable way.
void rebase(const info_t &info)
Definition DyldInfo.hpp:344
span< uint8_t > weak_bind_opcodes()
Definition DyldInfo.hpp:241
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:270
it_const_export_info exports() const
Definition DyldInfo.hpp:326
void set_lazy_bind_offset(uint32_t offset)
Definition DyldInfo.hpp:381
const info_t & lazy_bind() const
Lazy Bind information
Definition DyldInfo.hpp:265
span< uint8_t > bind_opcodes()
Definition DyldInfo.hpp:206
span< const uint8_t > export_trie() const
Return Export's trie as raw data.
Definition DyldInfo.hpp:331
void swap(DyldInfo &other) noexcept
void accept(Visitor &visitor) const override
void set_rebase_size(uint32_t size)
Definition DyldInfo.hpp:363
span< const uint8_t > weak_bind_opcodes() const
Return Weak Binding's opcodes as raw data.
Definition DyldInfo.hpp:238
std::string show_weak_bind_opcodes() const
Return the bind opcodes in a humman-readable way.
Class that provides an interface over the Dyld export info.
Definition ExportInfo.hpp:38
Definition LinkEdit.hpp:42
Based class for the Mach-O load commands.
Definition LoadCommand.hpp:37
LoadCommand::TYPE command() const
Command type.
Definition LoadCommand.hpp:124
Class that represents a relocation found in the DyldInfo structure.
Definition RelocationDyld.hpp:33
Definition iostream.hpp:29
Definition endianness_support.hpp:59
Namespace related to the LIEF's Mach-O module.
Definition Abstract/Header.hpp:36
@ UNKNOWN
Definition MachO/enums.hpp:25
const char * to_string(BuildToolVersion::TOOLS tool)
LIEF namespace.
Definition Abstract/Binary.hpp:36
#define LIEF_API
Definition visibility.h:41
#define LIEF_LOCAL
Definition visibility.h:42