LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
LIEF::dsc::DyldSharedCache Class Reference

This class represents a dyld shared cache file. More...

#include <DyldSharedCache.hpp>

Public Types

enum class  VERSION : uint32_t {
  UNKNOWN = 0 , DYLD_95_3 , DYLD_195_5 , DYLD_239_3 ,
  DYLD_360_14 , DYLD_421_1 , DYLD_832_7_1 , DYLD_940 ,
  DYLD_1042_1 , DYLD_1231_3 , UNRELEASED
}
 This enum wraps the dyld's git tags for which the structure of dyld shared cache evolved. More...
 
enum class  DYLD_TARGET_PLATFORM : uint32_t {
  UNKNOWN = 0 , MACOS = 1 , IOS = 2 , TVOS = 3 ,
  WATCHOS = 4 , BRIDGEOS = 5 , IOSMAC = 6 , IOS_SIMULATOR = 7 ,
  TVOS_SIMULATOR = 8 , WATCHOS_SIMULATOR = 9 , DRIVERKIT = 10 , VISIONOS = 11 ,
  VISIONOS_SIMULATOR = 12 , FIRMWARE = 13 , SEPOS = 14 , ANY = 0xFFFFFFFF
}
 Platforms supported by the dyld shared cache. More...
 
enum class  DYLD_TARGET_ARCH {
  UNKNOWN = 0 , I386 , X86_64 , X86_64H ,
  ARMV5 , ARMV6 , ARMV7 , ARM64 ,
  ARM64E
}
 Architecture supported by the dyld shared cache. More...
 
using dylib_iterator = iterator_range<Dylib::Iterator>
 Iterator over the libraries in the shared cache.
 
using mapping_info_iterator = iterator_range<MappingInfo::Iterator>
 Iterator over the mapping info in the shared cache.
 
using subcache_iterator = iterator_range<SubCache::Iterator>
 Iterator over the split/sub-cache in this main shared cache.
 
using instructions_iterator = iterator_range<assembly::Instruction::Iterator>
 

Public Member Functions

 DyldSharedCache (std::unique_ptr< details::DyldSharedCache > impl)
 
 ~DyldSharedCache ()
 
std::string filename () const
 Filename of the dyld shared file associated with this object.
 
VERSION version () const
 Version of dyld used by this cache.
 
std::string filepath () const
 Full path to the original dyld shared cache file associated with object (e.g. /home/lief/downloads/visionos/dyld_shared_cache_arm64e.42)
 
uint64_t load_address () const
 Based address of this cache.
 
std::string arch_name () const
 Name of the architecture targeted by this cache (x86_64h)
 
DYLD_TARGET_PLATFORM platform () const
 Platform targeted by this cache (e.g. vision-os)
 
DYLD_TARGET_ARCH arch () const
 Architecture targeted by this cache.
 
std::unique_ptr< Dylibfind_lib_from_va (uint64_t va) const
 Find the Dylib that encompasses the given virtual address. It returns a nullptr if a Dylib can't be found.
 
std::unique_ptr< Dylibfind_lib_from_path (const std::string &path) const
 Find the Dylib whose Dylib::path matches the provided path.
 
std::unique_ptr< Dylibfind_lib_from_name (const std::string &name) const
 Find the Dylib whose filename of Dylib::path matches the provided name.
 
bool has_subcaches () const
 True if the subcaches are associated with this cache.
 
dylib_iterator libraries () const
 Return an interator over the libraries embedded in this dyld shared cache.
 
mapping_info_iterator mapping_info () const
 Return an interator over the mapping information of this dyld shared cache.
 
subcache_iterator subcaches () const
 Return an interator over the subcaches associated with this (main) dyld shared cache.
 
instructions_iterator disassemble (uint64_t va) const
 Disassemble instructions at the provided virtual address. This function returns an iterator over assembly::Instruction.
 
std::vector< uint8_t > get_content_from_va (uint64_t va, uint64_t size) const
 Return the content at the specified virtual address.
 
std::unique_ptr< DyldSharedCachecache_for_address (uint64_t va) const
 Find the sub-DyldSharedCache that wraps the given virtual address.
 
std::unique_ptr< DyldSharedCachemain_cache () const
 Return the principal dyld shared cache in the case of multiple subcaches.
 
std::unique_ptr< DyldSharedCachefind_subcache (const std::string &filename) const
 Try to find the DyldSharedCache associated with the filename given in the first parameter.
 
result< uint64_t > va_to_offset (uint64_t va) const
 Convert the given virtual address into an offset.
 
FileStreamstream () const
 Return the stream associated with this dyld shared cache.
 
FileStreamstream ()
 Return the stream associated with this dyld shared cache.
 
void enable_caching (const std::string &target_cache_dir) const
 When enabled, this function allows to record and to keep in cache, dyld shared cache information that are costly to access.
 
void flush_cache () const
 Flush internal information into the on-disk cache (see: enable_caching)
 

Static Public Member Functions

static std::unique_ptr< DyldSharedCachefrom_path (const std::string &path, const std::string &arch="")
 See the load functions for the details.
 
static std::unique_ptr< DyldSharedCachefrom_files (const std::vector< std::string > &path)
 See the load functions for the details.
 

Detailed Description

This class represents a dyld shared cache file.

Member Typedef Documentation

◆ dylib_iterator

Iterator over the libraries in the shared cache.

◆ instructions_iterator

◆ mapping_info_iterator

Iterator over the mapping info in the shared cache.

◆ subcache_iterator

Iterator over the split/sub-cache in this main shared cache.

Member Enumeration Documentation

◆ DYLD_TARGET_ARCH

Architecture supported by the dyld shared cache.

Enumerator
UNKNOWN 
I386 
X86_64 
X86_64H 
ARMV5 
ARMV6 
ARMV7 
ARM64 
ARM64E 

◆ DYLD_TARGET_PLATFORM

Platforms supported by the dyld shared cache.

Enumerator
UNKNOWN 
MACOS 
IOS 
TVOS 
WATCHOS 
BRIDGEOS 
IOSMAC 
IOS_SIMULATOR 
TVOS_SIMULATOR 
WATCHOS_SIMULATOR 
DRIVERKIT 
VISIONOS 
VISIONOS_SIMULATOR 
FIRMWARE 
SEPOS 
ANY 

◆ VERSION

enum class LIEF::dsc::DyldSharedCache::VERSION : uint32_t
strong

This enum wraps the dyld's git tags for which the structure of dyld shared cache evolved.

Enumerator
UNKNOWN 
DYLD_95_3 

dyld-95.3 (2007-10-30)

DYLD_195_5 

dyld-195.5 (2011-07-13)

DYLD_239_3 

dyld-239.3 (2013-10-29)

DYLD_360_14 

dyld-360.14 (2015-09-04)

DYLD_421_1 

dyld-421.1 (2016-09-22)

DYLD_832_7_1 

dyld-832.7.1 (2020-11-19)

DYLD_940 

dyld-940 (2021-02-09)

DYLD_1042_1 

dyld-1042.1 (2022-10-19)

DYLD_1231_3 

dyld-1231.3 (2024-09-24)

UNRELEASED 

This value is used for versions of dyld not publicly released or not yet supported by LIEF.

Constructor & Destructor Documentation

◆ DyldSharedCache()

LIEF::dsc::DyldSharedCache::DyldSharedCache ( std::unique_ptr< details::DyldSharedCache > impl)

◆ ~DyldSharedCache()

LIEF::dsc::DyldSharedCache::~DyldSharedCache ( )

Member Function Documentation

◆ arch()

DYLD_TARGET_ARCH LIEF::dsc::DyldSharedCache::arch ( ) const

Architecture targeted by this cache.

◆ arch_name()

std::string LIEF::dsc::DyldSharedCache::arch_name ( ) const

Name of the architecture targeted by this cache (x86_64h)

◆ cache_for_address()

std::unique_ptr< DyldSharedCache > LIEF::dsc::DyldSharedCache::cache_for_address ( uint64_t va) const

Find the sub-DyldSharedCache that wraps the given virtual address.

◆ disassemble()

instructions_iterator LIEF::dsc::DyldSharedCache::disassemble ( uint64_t va) const

Disassemble instructions at the provided virtual address. This function returns an iterator over assembly::Instruction.

◆ enable_caching()

void LIEF::dsc::DyldSharedCache::enable_caching ( const std::string & target_cache_dir) const

When enabled, this function allows to record and to keep in cache, dyld shared cache information that are costly to access.

For instance, GOT symbols, rebases information, stub symbols, ...

It is highly recommended to enable this function when processing a dyld shared cache several times or when extracting a large number of LIEF::dsc::Dylib with enhanced extraction options (e.g. Dylib::extract_opt_t::fix_branches)

One can enable caching by calling this function:

auto dyld_cache = LIEF::dsc::load("macos-15.0.1/");
dyld_cache->enable_caching("/home/user/.cache/lief-dsc");
std::unique_ptr< DyldSharedCache > load(const std::string &path, const std::string &arch="")
Load a shared cache from a single file or from a directory specified by the path parameter.
Definition DyldSharedCache/DyldSharedCache.hpp:282

One can also enable this cache optimization globally using the function: LIEF::dsc::enable_cache or by setting the environment variable DYLDSC_ENABLE_CACHE to 1.

◆ filename()

std::string LIEF::dsc::DyldSharedCache::filename ( ) const

Filename of the dyld shared file associated with this object.

For instance: dyld_shared_cache_arm64e, dyld_shared_cache_arm64e.62.dyldlinkedit

◆ filepath()

std::string LIEF::dsc::DyldSharedCache::filepath ( ) const

Full path to the original dyld shared cache file associated with object (e.g. /home/lief/downloads/visionos/dyld_shared_cache_arm64e.42)

◆ find_lib_from_name()

std::unique_ptr< Dylib > LIEF::dsc::DyldSharedCache::find_lib_from_name ( const std::string & name) const

Find the Dylib whose filename of Dylib::path matches the provided name.

If multiple libraries have the same name (but with a different path), the first one matching the provided name is returned.

◆ find_lib_from_path()

std::unique_ptr< Dylib > LIEF::dsc::DyldSharedCache::find_lib_from_path ( const std::string & path) const

Find the Dylib whose Dylib::path matches the provided path.

◆ find_lib_from_va()

std::unique_ptr< Dylib > LIEF::dsc::DyldSharedCache::find_lib_from_va ( uint64_t va) const

Find the Dylib that encompasses the given virtual address. It returns a nullptr if a Dylib can't be found.

◆ find_subcache()

std::unique_ptr< DyldSharedCache > LIEF::dsc::DyldSharedCache::find_subcache ( const std::string & filename) const

Try to find the DyldSharedCache associated with the filename given in the first parameter.

◆ flush_cache()

void LIEF::dsc::DyldSharedCache::flush_cache ( ) const

Flush internal information into the on-disk cache (see: enable_caching)

◆ from_files()

static std::unique_ptr< DyldSharedCache > LIEF::dsc::DyldSharedCache::from_files ( const std::vector< std::string > & path)
static

See the load functions for the details.

Referenced by LIEF::dsc::load().

◆ from_path()

static std::unique_ptr< DyldSharedCache > LIEF::dsc::DyldSharedCache::from_path ( const std::string & path,
const std::string & arch = "" )
static

See the load functions for the details.

Referenced by LIEF::dsc::load().

◆ get_content_from_va()

std::vector< uint8_t > LIEF::dsc::DyldSharedCache::get_content_from_va ( uint64_t va,
uint64_t size ) const

Return the content at the specified virtual address.

◆ has_subcaches()

bool LIEF::dsc::DyldSharedCache::has_subcaches ( ) const

True if the subcaches are associated with this cache.

◆ libraries()

dylib_iterator LIEF::dsc::DyldSharedCache::libraries ( ) const

Return an interator over the libraries embedded in this dyld shared cache.

This iterator implements the random access trait. Thus, one can use iterator_range::size, iterator_range::at, iterator_range::operator[] to a access Dylib at an arbitrary index:

auto libraries = cache.libaries();
for (size_t i = 0; i < libraries.size(); ++i) {
std::string path = libaries[i]->path();
}
dylib_iterator libraries() const
Return an interator over the libraries embedded in this dyld shared cache.

◆ load_address()

uint64_t LIEF::dsc::DyldSharedCache::load_address ( ) const

Based address of this cache.

◆ main_cache()

std::unique_ptr< DyldSharedCache > LIEF::dsc::DyldSharedCache::main_cache ( ) const

Return the principal dyld shared cache in the case of multiple subcaches.

◆ mapping_info()

mapping_info_iterator LIEF::dsc::DyldSharedCache::mapping_info ( ) const

Return an interator over the mapping information of this dyld shared cache.

This iterator implements the random access trait. Thus, one can use iterator_range::size, iterator_range::at, iterator_range::operator[] to access a MappingInfo at an arbitrary index:

auto mapping = cache.mapping_info();
for (size_t i = 0; i < mapping.size(); ++i) {
const uint64_t addr = mapping[i]->address();
}

◆ platform()

DYLD_TARGET_PLATFORM LIEF::dsc::DyldSharedCache::platform ( ) const

Platform targeted by this cache (e.g. vision-os)

◆ stream() [1/2]

FileStream & LIEF::dsc::DyldSharedCache::stream ( )

Return the stream associated with this dyld shared cache.

◆ stream() [2/2]

FileStream & LIEF::dsc::DyldSharedCache::stream ( ) const

Return the stream associated with this dyld shared cache.

◆ subcaches()

subcache_iterator LIEF::dsc::DyldSharedCache::subcaches ( ) const

Return an interator over the subcaches associated with this (main) dyld shared cache.

This iterator implements the random access trait. Thus, one can use iterator_range::size, iterator_range::at, iterator_range::operator[] to access a SubCache at an arbitrary index:

auto subcaches = cache.subcaches();
for (size_t i = 0; i < subcaches.size(); ++i) {
std::unique_ptr<DyldSharedCache> impl = subcaches[i]->cache();
}
subcache_iterator subcaches() const
Return an interator over the subcaches associated with this (main) dyld shared cache.

◆ va_to_offset()

result< uint64_t > LIEF::dsc::DyldSharedCache::va_to_offset ( uint64_t va) const

Convert the given virtual address into an offset.

Warning
If the shared cache contains multiple subcaches, this function needs to be called on the targeted subcache. See cache_for_address() to find the associated subcache.

◆ version()

VERSION LIEF::dsc::DyldSharedCache::version ( ) const

Version of dyld used by this cache.


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