Python¶
- lief.dsc.load(*args) lief.dsc.DyldSharedCache | None¶
- lief.dsc.load(path: str | os.PathLike, arch: str = '') lief._lief.dsc.DyldSharedCache | None
Overloaded function.
load(files: collections.abc.Sequence[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: Union[str | os.PathLike], arch: str = '') -> Optional[lief._lief.dsc.DyldSharedCache]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 preferred.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")
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.
- lief.dsc.enable_cache(*args) bool¶
- lief.dsc.enable_cache(target_cache_dir: str | os.PathLike) bool
Overloaded function.
enable_cache() -> boolEnable globally cache/memoization. One can also leverage this function by setting the environment variable
DYLDSC_ENABLE_CACHEto1By 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 python ./my-script.pyOtherwise, 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
lief.dsc.DyldSharedCache.enable_caching()for a finer granularityenable_cache(target_cache_dir: Union[str | os.PathLike]) -> boolSame behavior as the other
enable_cache()function but using a user-provided cache directory instead of an inferred one.
Dylib¶
- class lief.dsc.Dylib¶
Bases:
objectThis class represents a library embedded in a dyld shared cache. It mirrors the original
dyld_cache_image_infostructure.- property address int¶
In-memory address of the library
- class extract_opt_t(self)¶
Bases:
objectThis 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 original Mach-O binary.- property create_dyld_chained_fixup_cmd bool¶
Whether the
LC_DYLD_CHAINED_FIXUPScommand should be (re)created.If this value is not set, LIEF will add the command only if it’s meaningful regarding the other options
- property fix_branches bool¶
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()orlief.dsc.DyldSharedCache.enable_caching()
- property fix_memory bool¶
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()orlief.dsc.DyldSharedCache.enable_caching()
- property fix_objc bool¶
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()orlief.dsc.DyldSharedCache.enable_caching()
- property fix_relocations bool¶
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()orlief.dsc.DyldSharedCache.enable_caching()
- property pack bool¶
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(self, opt: lief._lief.dsc.Dylib.extract_opt_t = <lief._lief.dsc.Dylib.extract_opt_t object at 0x7f3b0ba3eac0>) lief._lief.MachO.Binary | None¶
Get a
lief.MachO.Binaryrepresentation 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")
- property inode int¶
File serial number matching
stat.st_inoor 0Note that for shared cache targeting iOS, this value can hold a hash of the path (if modtime is set to 0)
- property modtime int¶
Modification time of the library matching
stat.st_mtime, or 0
- property padding int¶
Padding alignment value (should be 0)
- property path str¶
Original path of the library (e.g.
/usr/lib/libcryptex.dylib)
MappingInfo¶
- class lief.dsc.MappingInfo¶
Bases:
objectThis class represents a
dyld_cache_mapping_infoentry.It provides information about the relationship between on-disk shared cache and in-memory shared cache.
- property address int¶
The in-memory address where this dyld shared cache region is mapped
- property end_address int¶
End virtual address of the region
- property file_offset int¶
On-disk file offset
- property init_prot int¶
Initial memory protection
- property max_prot int¶
Max memory protection
- property size int¶
Size of the region being mapped
SubCache¶
- class lief.dsc.SubCache¶
Bases:
objectThis 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- property cache lief.dsc.DyldSharedCache | None¶
The associated
DyldSharedCacheobject for this subcache
- property suffix str¶
The file name suffix of the subCache file (e.g.
.25.data,.03.development)
- property uuid list[int]¶
The uuid of the subcache file
- property vm_offset int¶
The offset of this subcache from the main cache base address
Utilities¶
Check if the given file is a dyld shared cache