LIEF: Library to Instrument Executable Formats Version
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
LIEF::MachO::DyldInfo Class Reference

Class that represents the LC_DYLD_INFO and LC_DYLD_INFO_ONLY commands. More...

#include <DyldInfo.hpp>

Inheritance diagram for LIEF::MachO::DyldInfo:
Inheritance graph
[legend]
Collaboration diagram for LIEF::MachO::DyldInfo:
Collaboration graph
[legend]

Public Types

enum class  BINDING_ENCODING_VERSION { UNKNOWN = 0 , V1 , V2 }
 
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
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 (const details::dyld_info_command &dyld_info_cmd)
 
DyldInfooperator= (DyldInfo other)
 
 DyldInfo (const DyldInfo &copy)
 
void swap (DyldInfo &other)
 
DyldInfoclone () const override
 
const info_trebase () 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_tbind () 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_tweak_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_tlazy_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_texport_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 (const details::load_command &command)
 
 LoadCommand (LOAD_COMMAND_TYPES type, uint32_t size)
 
LoadCommandoperator= (LoadCommand copy)
 
 LoadCommand (const LoadCommand &copy)
 
void swap (LoadCommand &other)
 
LOAD_COMMAND_TYPES 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 (const raw_t &data)
 
void command (LOAD_COMMAND_TYPES command)
 
void size (uint32_t size)
 
void command_offset (uint64_t offset)
 
void accept (Visitor &visitor) const override
 
- Public Member Functions inherited from LIEF::Object
 Object (const Object &other)
 
Objectoperator= (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
 

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)
 

Detailed Description

Class that represents the LC_DYLD_INFO and LC_DYLD_INFO_ONLY commands.

Member Function Documentation

◆ accept()

void LIEF::MachO::DyldInfo::accept ( Visitor visitor) const
overridevirtual

Implements LIEF::Object.

◆ bind()

const info_t & LIEF::MachO::DyldInfo::bind ( ) const

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.

See also
/usr/include/mach-o/loader.h

◆ clone()

DyldInfo * LIEF::MachO::DyldInfo::clone ( ) const
overridevirtual

Reimplemented from LIEF::MachO::LoadCommand.

◆ export_info()

const info_t & LIEF::MachO::DyldInfo::export_info ( ) const

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.

See also
/usr/include/mach-o/loader.h

◆ lazy_bind()

const info_t & LIEF::MachO::DyldInfo::lazy_bind ( ) const

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.

See also
/usr/include/mach-o/loader.h

◆ print()

std::ostream & LIEF::MachO::DyldInfo::print ( std::ostream &  os) const
overridevirtual

Reimplemented from LIEF::MachO::LoadCommand.

◆ rebase()

const info_t & LIEF::MachO::DyldInfo::rebase ( ) const

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.

See also
/usr/include/mach-o/loader.h

◆ weak_bind()

const info_t & LIEF::MachO::DyldInfo::weak_bind ( ) const

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.

See also
/usr/include/mach-o/loader.h

The documentation for this class was generated from the following file: