here
Load a shared cache from a single file or from a directory specified by the path
parameter.
In the case where multiple architectures are available in the path
directory, the arch
parameter can be used to define which architecture should be prefered.
Example:
// From a directory (split caches)
auto cache = LIEF::dsc::load("vision-pro-2.0/");
// From a single cache file
auto cache = LIEF::dsc::load("ios-14.2/dyld_shared_cache_arm64");
// From a directory with multiple architectures
auto cache = LIEF::dsc::load("macos-12.6/", /*arch=*‍/"x86_64h");
Load a shared cache from a list of files.
std::vector<std::string> files = {
"/tmp/dsc/dyld_shared_cache_arm64e",
"/tmp/dsc/dyld_shared_cache_arm64e.1"
};
auto cache = LIEF::dsc::load(files);
Warning
If you aim at extracting several libraries from a dyld shared cache, it is highly recommended to enable caching. Otherwise, performances can be impacted.
Enable globally cache/memoization. One can also leverage this function by setting the environment variable DYLDSC_ENABLE_CACHE
to 1
By default, LIEF will use the directory specified by the environment variable DYLDSC_CACHE_DIR
as its cache-root directory:
DYLDSC_ENABLE_CACHE=1 DYLDSC_CACHE_DIR=/tmp/my_dir ./my-program
Otherwise, if DYLDSC_CACHE_DIR
is not set, LIEF will use the following directory (in this priority):
System or user cache directory
macOS: DARWIN_USER_TEMP_DIR
/ DARWIN_USER_CACHE_DIR
+ /dyld_shared_cache
Linux: ${XDG_CACHE_HOME}/dyld_shared_cache
Windows: LOCALAPPDATA%\dyld_shared_cache
Home directory
macOS/Linux: $HOME/.dyld_shared_cache
Windows: USERPROFILE%\.dyld_shared_cache
See also
LIEF::dsc::DyldSharedCache::enable_caching for a finer granularity
Same behavior as enable_cache() but with a user-provided cache directory.
This class represents a library embedded in a dyld shared cache. It mirrors the original dyld_cache_image_info
structure.
Public Functions
Original path of the library (e.g. /usr/lib/libcryptex.dylib
)
In-memory address of the library.
Modification time of the library matching stat.st_mtime
, or 0.
File serial number matching stat.st_ino
or 0.
Note that for shared cache targeting iOS, this value can hold a hash of the path (if modtime is set to 0)
Padding alignment value (should be 0)
Get a MachO::Binary representation for this Dylib.
One can use this function to write back the Mach-O binary on the disk:
dyld_cache->libraries()[12]->get()->write("liblockdown.dylib");
This structure is used to tweak the extraction process while calling Dylib::get. These options allow to deoptimize the dylib and get an accurate representation of the origin Mach-O binary.
Public Functions
Public Members
Whether the segment’s offsets should be packed to avoid an in-memory size while writing back the binary.
Note
This option does not have an impact on the performances
Fix call instructions that target addresses outside the current dylib virtual space.
Warning
Enabling this option can have a significant impact on the performances. Make sure to enable the internal cache mechanism: LIEF::dsc::enable_cache or LIEF::dsc::DyldSharedCache::enable_caching
Fix memory accesses performed outside the dylib’s virtual space.
Warning
Enabling this option can have a significant impact on the performances. Make sure to enable the internal cache mechanism: LIEF::dsc::enable_cache or LIEF::dsc::DyldSharedCache::enable_caching
Recover and fix relocations.
Warning
Enabling this option can have a significant impact on the performances. Make sure to enable the internal cache mechanism: LIEF::dsc::enable_cache or LIEF::dsc::DyldSharedCache::enable_caching
Fix Objective-C information.
Public Types
This class represents a dyld_cache_mapping_info
entry.
It provides information about the relationshiop between on-disk shared cache and in-memory shared cache.
Public Functions
The in-memory address where this dyld shared cache region is mapped.
Size of the region being mapped.
End virtual address of the region.
On-disk file offset.
Max memory protection.
Initial memory protection.
Public Types
Public Functions
This class represents a subcache in the case of large/split dyld shared cache.
It mirror (and abstracts) the original dyld_subcache_entry
/ dyld_subcache_entry_v1
Public Functions
The uuid of the subcache file.
The offset of this subcache from the main cache base address.
The file name suffix of the subCache file (e.g. .25.data
, .03.development
)
The associated DyldSharedCache object for this subcache.
Public Types