C++¶
Note
You can also find the Doxygen documentation here: here
- inline std::unique_ptr<DyldSharedCache> LIEF::dsc::load(const std::string &path, const std::string &arch = "")¶
Load a shared cache from a single file or from a directory specified by the
pathparameter.In the case where multiple architectures are available in the
pathdirectory, thearchparameter 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");
- inline std::unique_ptr<DyldSharedCache> LIEF::dsc::load(const std::vector<std::string> &files)¶
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);
Cache Processing¶
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.
- bool LIEF::dsc::enable_cache()¶
Enable globally cache/memoization. One can also leverage this function by setting the environment variable
DYLDSC_ENABLE_CACHEto1.By default, LIEF will use the directory specified by the environment variable
DYLDSC_CACHE_DIRas its cache-root directory:DYLDSC_ENABLE_CACHE=1 DYLDSC_CACHE_DIR=/tmp/my_dir ./my-program
Otherwise, if
DYLDSC_CACHE_DIRis 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_cacheLinux:
${XDG_CACHE_HOME}/dyld_shared_cacheWindows:
LOCALAPPDATA%\dyld_shared_cache
Home directory
macOS/Linux:
$HOME/.dyld_shared_cacheWindows:
USERPROFILE%\.dyld_shared_cache
See also
LIEF::dsc::DyldSharedCache::enable_caching for a finer granularity
- bool LIEF::dsc::enable_cache(const std::string &dir)¶
Same behavior as enable_cache() but with a user-provided cache directory.
Dylib¶
- class Dylib¶
This class represents a library embedded in a dyld shared cache. It mirrors the original
dyld_cache_image_infostructure.Public Functions
- Dylib(std::unique_ptr<details::Dylib> impl)¶
- ~Dylib()¶
- std::string path() const¶
Original path of the library (e.g.
/usr/lib/libcryptex.dylib).
- uint64_t address() const¶
In-memory address of the library.
- uint64_t modtime() const¶
Modification time of the library matching
stat.st_mtime, or 0.
- uint64_t inode() const¶
File serial number matching
stat.st_inoor 0.Note that for shared cache targeting iOS, this value can hold a hash of the path (if modtime is set to 0)
- uint64_t padding() const¶
Padding alignment value (should be 0).
- std::unique_ptr<LIEF::MachO::Binary> get(const extract_opt_t &opt = extract_opt_t()) const¶
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");
- class Iterator : public LIEF::iterator_facade_base<Iterator, std::random_access_iterator_tag, Dylib, std::ptrdiff_t, const Dylib*, const Dylib&>¶
-
Public Types
- using implementation = details::DylibIt¶
- using implementation = details::DylibIt¶
- struct extract_opt_t¶
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
- extract_opt_t()¶
Public Members
- bool pack = true¶
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
- bool fix_branches = false¶
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
- bool fix_memory = false¶
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
- bool fix_relocations = false¶
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
- bool fix_objc = false¶
Fix Objective-C information.
- extract_opt_t()¶
- Dylib(std::unique_ptr<details::Dylib> impl)¶
MappingInfo¶
- class MappingInfo¶
This class represents a
dyld_cache_mapping_infoentry.It provides information about the relationship between on-disk shared cache and in-memory shared cache.
Public Functions
- MappingInfo(std::unique_ptr<details::MappingInfo> impl)¶
- ~MappingInfo()¶
- uint64_t address() const¶
The in-memory address where this dyld shared cache region is mapped.
- uint64_t size() const¶
Size of the region being mapped.
- inline uint64_t end_address() const¶
End virtual address of the region.
- uint64_t file_offset() const¶
On-disk file offset.
- uint32_t max_prot() const¶
Max memory protection.
- uint32_t init_prot() const¶
Initial memory protection.
- class Iterator : public LIEF::iterator_facade_base<Iterator, std::random_access_iterator_tag, MappingInfo, std::ptrdiff_t, const MappingInfo*, const MappingInfo&>¶
-
Public Types
- using implementation = details::MappingInfoIt¶
Public Functions
- Iterator()¶
- Iterator(std::unique_ptr<details::MappingInfoIt> impl)¶
- ~Iterator()¶
- const MappingInfo &operator*() const¶
- const MappingInfo *operator->() const¶
- std::unique_ptr<MappingInfo> yield()¶
Transfer ownership of the mapping info at the current position to the caller. Returns
nullptrif the iterator is past-the-end.
- using implementation = details::MappingInfoIt¶
- MappingInfo(std::unique_ptr<details::MappingInfo> impl)¶
SubCache¶
- class SubCache¶
This class represents a subcache in the case of large/split dyld shared cache.
It mirrors (and abstracts) the original
dyld_subcache_entry/dyld_subcache_entry_v1Public Functions
- SubCache(std::unique_ptr<details::SubCache> impl)¶
- ~SubCache()¶
- sc_uuid_t uuid() const¶
The uuid of the subcache file.
- uint64_t vm_offset() const¶
The offset of this subcache from the main cache base address.
- std::string suffix() const¶
The file name suffix of the subCache file (e.g.
.25.data,.03.development).
- std::unique_ptr<const DyldSharedCache> cache() const¶
The associated DyldSharedCache object for this subcache.
- SubCache(std::unique_ptr<details::SubCache> impl)¶
Utilities¶
Check if the given stream wraps a Dyld Shared Cache.
Check if the given buffer points to a dyld shared cache file.
Check if the given buffer points to a dyld shared cache file.