LIEF: Library to Instrument Executable Formats Version 0.16.0
|
Class that represents the LC_DYLD_INFO and LC_DYLD_INFO_ONLY commands. More...
#include <DyldInfo.hpp>
Public Types | |
enum class | BINDING_ENCODING_VERSION { UNKNOWN = 0 , V1 , V2 } |
enum class | REBASE_TYPE : uint64_t { POINTER = 1u , TEXT_ABSOLUTE32 = 2u , TEXT_PCREL32 = 3u , THREADED = 102u } |
enum class | REBASE_OPCODES : uint8_t { DONE = 0x00u , SET_TYPE_IMM = 0x10u , SET_SEGMENT_AND_OFFSET_ULEB = 0x20u , ADD_ADDR_ULEB = 0x30u , ADD_ADDR_IMM_SCALED = 0x40u , DO_REBASE_IMM_TIMES = 0x50u , DO_REBASE_ULEB_TIMES = 0x60u , DO_REBASE_ADD_ADDR_ULEB = 0x70u , DO_REBASE_ULEB_TIMES_SKIPPING_ULEB = 0x80u } |
enum class | BIND_OPCODES : uint8_t { DONE = 0x00u , SET_DYLIB_ORDINAL_IMM = 0x10u , SET_DYLIB_ORDINAL_ULEB = 0x20u , SET_DYLIB_SPECIAL_IMM = 0x30u , SET_SYMBOL_TRAILING_FLAGS_IMM = 0x40u , SET_TYPE_IMM = 0x50u , SET_ADDEND_SLEB = 0x60u , SET_SEGMENT_AND_OFFSET_ULEB = 0x70u , ADD_ADDR_ULEB = 0x80u , DO_BIND = 0x90u , DO_BIND_ADD_ADDR_ULEB = 0xA0u , DO_BIND_ADD_ADDR_IMM_SCALED = 0xB0u , DO_BIND_ULEB_TIMES_SKIPPING_ULEB = 0xC0u , THREADED = 0xD0u , THREADED_APPLY = 0xD0u | 0x01u , THREADED_SET_BIND_ORDINAL_TABLE_SIZE_ULEB = 0xD0u | 0x00u } |
Opcodes used by Dyld info to bind symbols. More... | |
enum class | BIND_SUBOPCODE_THREADED : uint8_t { SET_BIND_ORDINAL_TABLE_SIZE_ULEB = 0x00u , APPLY = 0x01u } |
enum | BIND_SYMBOL_FLAGS { WEAK_IMPORT = 0x1u , NON_WEAK_DEFINITION = 0x8u } |
using | info_t = std::pair<uint32_t, uint32_t> |
Tuple of offset and size | |
using | binding_info_t = std::vector<std::unique_ptr<DyldBindingInfo>> |
Internal container for storing DyldBindingInfo. | |
using | it_binding_info = ref_iterator<binding_info_t&, DyldBindingInfo*> |
Iterator which outputs DyldBindingInfo&. | |
using | it_const_binding_info = const_ref_iterator<const binding_info_t&, DyldBindingInfo*> |
Iterator which outputs const DyldBindingInfo&. | |
using | export_info_t = std::vector<std::unique_ptr<ExportInfo>> |
Internal container for storing ExportInfo. | |
using | it_export_info = ref_iterator<export_info_t&, ExportInfo*> |
Iterator which outputs const ExportInfo&. | |
using | it_const_export_info = const_ref_iterator<const export_info_t&, ExportInfo*> |
Iterator which outputs const ExportInfo&. | |
Public Types inherited from LIEF::MachO::LoadCommand | |
enum class | TYPE : uint64_t { UNKNOWN = 0 , SEGMENT = 0x00000001u , SYMTAB = 0x00000002u , SYMSEG = 0x00000003u , THREAD = 0x00000004u , UNIXTHREAD = 0x00000005u , LOADFVMLIB = 0x00000006u , IDFVMLIB = 0x00000007u , IDENT = 0x00000008u , FVMFILE = 0x00000009u , PREPAGE = 0x0000000Au , DYSYMTAB = 0x0000000Bu , LOAD_DYLIB = 0x0000000Cu , ID_DYLIB = 0x0000000Du , LOAD_DYLINKER = 0x0000000Eu , ID_DYLINKER = 0x0000000Fu , PREBOUND_DYLIB = 0x00000010u , ROUTINES = 0x00000011u , SUB_FRAMEWORK = 0x00000012u , SUB_UMBRELLA = 0x00000013u , SUB_CLIENT = 0x00000014u , SUB_LIBRARY = 0x00000015u , TWOLEVEL_HINTS = 0x00000016u , PREBIND_CKSUM = 0x00000017u , LOAD_WEAK_DYLIB = 0x80000018u , SEGMENT_64 = 0x00000019u , ROUTINES_64 = 0x0000001Au , UUID = 0x0000001Bu , RPATH = 0x8000001Cu , CODE_SIGNATURE = 0x0000001Du , SEGMENT_SPLIT_INFO = 0x0000001Eu , REEXPORT_DYLIB = 0x8000001Fu , LAZY_LOAD_DYLIB = 0x00000020u , ENCRYPTION_INFO = 0x00000021u , DYLD_INFO = 0x00000022u , DYLD_INFO_ONLY = 0x80000022u , LOAD_UPWARD_DYLIB = 0x80000023u , VERSION_MIN_MACOSX = 0x00000024u , VERSION_MIN_IPHONEOS = 0x00000025u , FUNCTION_STARTS = 0x00000026u , DYLD_ENVIRONMENT = 0x00000027u , MAIN = 0x80000028u , DATA_IN_CODE = 0x00000029u , SOURCE_VERSION = 0x0000002Au , DYLIB_CODE_SIGN_DRS = 0x0000002Bu , ENCRYPTION_INFO_64 = 0x0000002Cu , LINKER_OPTION = 0x0000002Du , LINKER_OPTIMIZATION_HINT = 0x0000002Eu , VERSION_MIN_TVOS = 0x0000002Fu , VERSION_MIN_WATCHOS = 0x00000030u , NOTE = 0x00000031u , BUILD_VERSION = 0x00000032u , DYLD_EXPORTS_TRIE = 0x80000033u , DYLD_CHAINED_FIXUPS = 0x80000034u , FILESET_ENTRY = 0x80000035u , LIEF_UNKNOWN = 0xffee0001u } |
using | raw_t = std::vector<uint8_t> |
Public Types inherited from LIEF::Object | |
template<class T > | |
using | output_t = add_pointer_t<decay_t<T>> |
template<class T > | |
using | output_const_t = add_pointer_t<add_const_t<decay_t<T>>> |
Public Member Functions | |
DyldInfo () | |
DyldInfo (const details::dyld_info_command &dyld_info_cmd) | |
DyldInfo & | operator= (DyldInfo other) |
DyldInfo (const DyldInfo ©) | |
void | swap (DyldInfo &other) noexcept |
std::unique_ptr< LoadCommand > | clone () const override |
~DyldInfo () override | |
const info_t & | rebase () const |
Rebase information | |
span< const uint8_t > | rebase_opcodes () const |
Return Rebase's opcodes as raw data. | |
span< uint8_t > | rebase_opcodes () |
void | rebase_opcodes (buffer_t raw) |
Set new opcodes. | |
std::string | show_rebases_opcodes () const |
Return the rebase opcodes in a humman-readable way. | |
const info_t & | bind () const |
Bind information | |
span< const uint8_t > | bind_opcodes () const |
Return Binding's opcodes as raw data. | |
span< uint8_t > | bind_opcodes () |
void | bind_opcodes (buffer_t raw) |
Set new opcodes. | |
std::string | show_bind_opcodes () const |
Return the bind opcodes in a humman-readable way. | |
const info_t & | weak_bind () const |
Weak Bind information | |
span< const uint8_t > | weak_bind_opcodes () const |
Return Weak Binding's opcodes as raw data. | |
span< uint8_t > | weak_bind_opcodes () |
void | weak_bind_opcodes (buffer_t raw) |
Set new opcodes. | |
std::string | show_weak_bind_opcodes () const |
Return the bind opcodes in a humman-readable way. | |
const info_t & | lazy_bind () const |
Lazy Bind information | |
span< const uint8_t > | lazy_bind_opcodes () const |
Return Lazy Binding's opcodes as raw data. | |
span< uint8_t > | lazy_bind_opcodes () |
void | lazy_bind_opcodes (buffer_t raw) |
Set new opcodes. | |
std::string | show_lazy_bind_opcodes () const |
Return the lazy opcodes in a humman-readable way. | |
it_binding_info | bindings () |
Iterator over BindingInfo entries. | |
it_const_binding_info | bindings () const |
const info_t & | export_info () const |
Export information | |
it_export_info | exports () |
Iterator over ExportInfo entries. | |
it_const_export_info | exports () const |
span< const uint8_t > | export_trie () const |
Return Export's trie as raw data. | |
span< uint8_t > | export_trie () |
void | export_trie (buffer_t raw) |
Set new trie. | |
std::string | show_export_trie () const |
Return the export trie in a humman-readable way. | |
void | rebase (const info_t &info) |
void | bind (const info_t &info) |
void | weak_bind (const info_t &info) |
void | lazy_bind (const info_t &info) |
void | export_info (const info_t &info) |
void | set_rebase_offset (uint32_t offset) |
void | set_rebase_size (uint32_t size) |
void | set_bind_offset (uint32_t offset) |
void | set_bind_size (uint32_t size) |
void | set_weak_bind_offset (uint32_t offset) |
void | set_weak_bind_size (uint32_t size) |
void | set_lazy_bind_offset (uint32_t offset) |
void | set_lazy_bind_size (uint32_t size) |
void | set_export_offset (uint32_t offset) |
void | set_export_size (uint32_t size) |
void | add (std::unique_ptr< ExportInfo > info) |
void | accept (Visitor &visitor) const override |
std::ostream & | print (std::ostream &os) const override |
Public Member Functions inherited from LIEF::MachO::LoadCommand | |
LoadCommand ()=default | |
LoadCommand (const details::load_command &command) | |
LoadCommand (LoadCommand::TYPE type, uint32_t size) | |
LoadCommand & | operator= (const LoadCommand ©)=default |
LoadCommand (const LoadCommand ©)=default | |
void | swap (LoadCommand &other) noexcept |
~LoadCommand () override=default | |
LoadCommand::TYPE | command () const |
Command type. | |
uint32_t | size () const |
Size of the command (should be greather than sizeof(load_command) ) | |
span< const uint8_t > | data () const |
Raw command. | |
uint64_t | command_offset () const |
Offset of the command within the Load Command Table | |
void | data (raw_t data) |
void | command (LoadCommand::TYPE command) |
void | size (uint32_t size) |
void | command_offset (uint64_t offset) |
void | accept (Visitor &visitor) const override |
template<class T > | |
const T * | cast () const |
template<class T > | |
T * | cast () |
Public Member Functions inherited from LIEF::Object | |
Object () | |
Object (const Object &other) | |
Object & | operator= (const Object &other) |
template<class T > | |
output_t< T > | as () |
template<class T > | |
output_const_t< T > | as () const |
virtual bool | operator== (const Object &other) const |
virtual bool | operator!= (const Object &other) const |
virtual | ~Object () |
Static Public Member Functions | |
static bool | classof (const LoadCommand *cmd) |
Static Public Member Functions inherited from LIEF::MachO::LoadCommand | |
static bool | is_linkedit_data (const LoadCommand &cmd) |
Static Public Attributes | |
static constexpr auto | OPCODE_MASK = uint32_t(0xF0) |
static constexpr auto | IMMEDIATE_MASK = uint32_t(0x0F) |
Class that represents the LC_DYLD_INFO and LC_DYLD_INFO_ONLY commands.
using LIEF::MachO::DyldInfo::binding_info_t = std::vector<std::unique_ptr<DyldBindingInfo>> |
Internal container for storing DyldBindingInfo.
using LIEF::MachO::DyldInfo::export_info_t = std::vector<std::unique_ptr<ExportInfo>> |
Internal container for storing ExportInfo.
using LIEF::MachO::DyldInfo::info_t = std::pair<uint32_t, uint32_t> |
Tuple of offset
and size
Iterator which outputs DyldBindingInfo&.
using LIEF::MachO::DyldInfo::it_const_binding_info = const_ref_iterator<const binding_info_t&, DyldBindingInfo*> |
Iterator which outputs const DyldBindingInfo&.
using LIEF::MachO::DyldInfo::it_const_export_info = const_ref_iterator<const export_info_t&, ExportInfo*> |
Iterator which outputs const ExportInfo&.
Iterator which outputs const ExportInfo&.
|
strong |
Opcodes used by Dyld info to bind symbols.
|
strong |
|
strong |
|
strong |
|
strong |
LIEF::MachO::DyldInfo::DyldInfo | ( | ) |
LIEF::MachO::DyldInfo::DyldInfo | ( | const details::dyld_info_command & | dyld_info_cmd | ) |
LIEF::MachO::DyldInfo::DyldInfo | ( | const DyldInfo & | copy | ) |
|
override |
|
overridevirtual |
Implements LIEF::Object.
void LIEF::MachO::DyldInfo::add | ( | std::unique_ptr< ExportInfo > | info | ) |
|
inline |
Bind information
Dyld binds an image during the loading process, if the image requires any pointers to be initialized to symbols in other images. The rebase information is a stream of byte sized opcodes for which symbolic names start with BIND_OPCODE_. Conceptually the bind information is a table of tuples: <seg-index, seg-offset, type, symbol-library-ordinal, symbol-name, addend> The opcodes are a compressed way to encode the table by only encoding when a column changes. In addition simple patterns like for runs of pointers initialzed to the same value can be encoded in a few bytes.
/usr/include/mach-o/loader.h
|
inline |
|
inline |
|
inline |
Return Binding's opcodes as raw data.
void LIEF::MachO::DyldInfo::bind_opcodes | ( | buffer_t | raw | ) |
Set new opcodes.
|
inline |
Iterator over BindingInfo entries.
|
inline |
|
inlinestatic |
References LIEF::MachO::LoadCommand::command().
|
inlineoverridevirtual |
Reimplemented from LIEF::MachO::LoadCommand.
|
inline |
Export information
The symbols exported by a dylib are encoded in a trie. This is a compact representation that factors out common prefixes. It also reduces LINKEDIT pages in RAM because it encodes all information (name, address, flags) in one small, contiguous range. The export area is a stream of nodes. The first node sequentially is the start node for the trie.
Nodes for a symbol start with a byte that is the length of the exported symbol information for the string so far. If there is no exported symbol, the byte is zero. If there is exported info, it follows the length byte. The exported info normally consists of a flags and offset both encoded in uleb128. The offset is location of the content named by the symbol. It is the offset from the mach_header for the image.
After the initial byte and optional exported symbol information is a byte of how many edges (0-255) that this node has leaving it, followed by each edge. Each edge is a zero terminated cstring of the addition chars in the symbol, followed by a uleb128 offset for the node that edge points to.
/usr/include/mach-o/loader.h
|
inline |
|
inline |
|
inline |
Return Export's trie as raw data.
void LIEF::MachO::DyldInfo::export_trie | ( | buffer_t | raw | ) |
Set new trie.
|
inline |
Iterator over ExportInfo entries.
|
inline |
|
inline |
Lazy Bind information
Some uses of external symbols do not need to be bound immediately. Instead they can be lazily bound on first use. The lazy_bind are contains a stream of BIND opcodes to bind all lazy symbols. Normal use is that dyld ignores the lazy_bind section when loading an image. Instead the static linker arranged for the lazy pointer to initially point to a helper function which pushes the offset into the lazy_bind area for the symbol needing to be bound, then jumps to dyld which simply adds the offset to lazy_bind_off to get the information on what to bind.
/usr/include/mach-o/loader.h
|
inline |
|
inline |
|
inline |
Return Lazy Binding's opcodes as raw data.
void LIEF::MachO::DyldInfo::lazy_bind_opcodes | ( | buffer_t | raw | ) |
Set new opcodes.
|
overridevirtual |
Reimplemented from LIEF::MachO::LoadCommand.
|
inline |
Rebase information
Dyld rebases an image whenever dyld loads it at an address different from its preferred address. The rebase information is a stream of byte sized opcodes for which symbolic names start with REBASE_OPCODE_. Conceptually the rebase information is a table of tuples: <seg-index, seg-offset, type> The opcodes are a compressed way to encode the table by only encoding when a column changes. In addition simple patterns like "every n'th offset for m times" can be encoded in a few bytes.
/usr/include/mach-o/loader.h
|
inline |
|
inline |
|
inline |
Return Rebase's opcodes as raw data.
void LIEF::MachO::DyldInfo::rebase_opcodes | ( | buffer_t | raw | ) |
Set new opcodes.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
std::string LIEF::MachO::DyldInfo::show_bind_opcodes | ( | ) | const |
Return the bind opcodes in a humman-readable way.
std::string LIEF::MachO::DyldInfo::show_export_trie | ( | ) | const |
Return the export trie in a humman-readable way.
std::string LIEF::MachO::DyldInfo::show_lazy_bind_opcodes | ( | ) | const |
Return the lazy opcodes in a humman-readable way.
std::string LIEF::MachO::DyldInfo::show_rebases_opcodes | ( | ) | const |
Return the rebase opcodes in a humman-readable way.
std::string LIEF::MachO::DyldInfo::show_weak_bind_opcodes | ( | ) | const |
Return the bind opcodes in a humman-readable way.
|
noexcept |
|
inline |
Weak Bind information
Some C++ programs require dyld to unique symbols so that all images in the process use the same copy of some code/data. This step is done after binding. The content of the weak_bind info is an opcode stream like the bind_info. But it is sorted alphabetically by symbol name. This enables dyld to walk all images with weak binding information in order and look for collisions. If there are no collisions, dyld does no updating. That means that some fixups are also encoded in the bind_info. For instance, all calls to "operator new" are first bound to libstdc++.dylib using the information in bind_info. Then if some image overrides operator new that is detected when the weak_bind information is processed and the call to operator new is then rebound.
/usr/include/mach-o/loader.h
|
inline |
|
inline |
|
inline |
Return Weak Binding's opcodes as raw data.
void LIEF::MachO::DyldInfo::weak_bind_opcodes | ( | buffer_t | raw | ) |
Set new opcodes.
|
staticconstexpr |
|
staticconstexpr |