Overloaded function.
load(files: list[str]) -> Optional[lief._lief.dsc.DyldSharedCache]
Load a shared cache from a list of files.
files = [ "/tmp/dsc/dyld_shared_cache_arm64e", "/tmp/dsc/dyld_shared_cache_arm64e.1" ] cache = lief.dsc.load(files);
load(path: os.PathLike, arch: str = '') -> Optional[lief._lief.dsc.DyldSharedCache]
Load a shared cache from the a single file or from a directory specified by the
path
parameter.In the case where multiple architectures are available in the
path
directory, thearch
parameter can be used to define which architecture should be prefered.Example:
// From a directory (split caches) cache = lief.dsc.load("vision-pro-2.0/"); // From a single cache file cache = lief.dsc.load("ios-14.2/dyld_shared_cache_arm64"); // From a directory with multiple architectures cache = lief.dsc.load("macos-12.6/", "x86_64h");
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.
Overloaded function.
enable_cache() -> bool
Enable globally cache/memoization. One can also leverage this function by setting the environment variable
DYLDSC_ENABLE_CACHE
to1
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 python ./my-script.py
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
lief.dsc.DyldSharedCache.enable_caching()
for a finer granularity
enable_cache(target_cache_dir: str) -> bool
Same behavior as the other
enable_cache()
function but using a user-provided cache directory instead of an inferred one.
Bases: object
This class represents a library embedded in a dyld shared cache. It mirrors the original dyld_cache_image_info
structure.
In-memory address of the library
Bases: object
This structure is used to tweak the extraction process while calling lief.dsc.Dylib.get()
. These options allow to deoptimize the dylib and get an accurate representation of the origin Mach-O binary.
Whether the LC_DYLD_CHAINED_FIXUPS
command should be (re)created.
If this value is not set, LIEF will add the command only if it’s meaningful regarding the other options
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()
Fix Objective-C information
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()
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
Get a lief.MachO.Binary
representation for this Dylib.
One can use this function to write back the Mach-O binary on the disk:
dyld_cache: lief.dsc.DyldSharedCache = ...
dyld_cache.libraries[10].get().write("libsystem.dylib")
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)
Modification time of the library matching stat.st_mtime
, or 0
Padding alignment value (should be 0)
Original path of the library (e.g. /usr/lib/libcryptex.dylib
)
Bases: object
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.
The in-memory address where this dyld shared cache region is mapped
End virtual address of the region
On-disk file offset
Initial memory protection
Max memory protection
Size of the region being mapped
Bases: object
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
The associated DyldSharedCache
object for this subcache
The file name suffix of the subCache file (e.g. .25.data
, .03.development
)
The uuid of the subcache file
The offset of this subcache from the main cache base address