LCOV - code coverage report
Current view: top level - src - dsc.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 0.0 % 17 0
Test Date: 2024-11-30:00:00:00 Functions: 0.0 % 2 0

            Line data    Source code
       1              : //! Module for Dyld shared cache support
       2              : //!
       3              : //! ### Getting Started
       4              : //!
       5              : //! ```rust
       6              : //! let dyld_cache = lief::dsc::from_path("macos-15.0.1/");
       7              : //! for dylib in dyld_cache.libraries() {
       8              : //!     println!("0x{:016x}: {}", dylib.address(), dylib.path());
       9              : //!     let macho: lief::macho::Binary = dylib.get().expect("Can't get Mach-O representation");
      10              : //! }
      11              : //! ```
      12              : //!
      13              : //! ### Performance Considerations
      14              : //!
      15              : //! <div class="warning">
      16              : //! If you aim at extracting several libraries from a dyld shared cache, it is
      17              : //! <b>highly</b> recommended to enable caching. Otherwise, performances can be
      18              : //! impacted.
      19              : //! </div>
      20              : //!
      21              : //! See: [`crate::dsc::enable_cache`] and [`crate::dsc::enable_cache_from_dir`]
      22              : use lief_ffi as ffi;
      23              : use std::ffi::{CString, c_char};
      24              : use crate::common::into_optional;
      25              : 
      26              : pub mod dyld_shared_cache;
      27              : pub mod mapping_info;
      28              : pub mod subcache;
      29              : pub mod dylib;
      30              : pub mod uuid;
      31              : 
      32              : mod caching;
      33              : 
      34              : #[doc(inline)]
      35              : pub use dyld_shared_cache::DyldSharedCache;
      36              : 
      37              : #[doc(inline)]
      38              : pub use dylib::Dylib;
      39              : 
      40              : #[doc(inline)]
      41              : pub use subcache::SubCache;
      42              : 
      43              : #[doc(inline)]
      44              : pub use mapping_info::MappingInfo;
      45              : 
      46              : #[doc(inline)]
      47              : pub use uuid::UUID;
      48              : 
      49              : #[doc(inline)]
      50              : pub use caching::enable_cache;
      51              : 
      52              : #[doc(inline)]
      53              : pub use caching::enable_cache_from_dir;
      54              : 
      55              : 
      56              : /// Load a shared cache from a single file or from a directory specified
      57              : /// by the `path` parameter.
      58              : ///
      59              : /// In the case where multiple architectures are
      60              : /// available in the `path` directory, the `arch` parameter can be used to
      61              : /// define which architecture should be prefered.
      62              : ///
      63              : /// **Example:**
      64              : ///
      65              : /// ```rust
      66              : /// // From a directory (split caches)
      67              : /// let cache = lief::dsc::load("vision-pro-2.0/", "");
      68              : ///
      69              : /// // From a single cache file
      70              : /// let cache = lief::dsc::load("ios-14.2/dyld_shared_cache_arm64", "");
      71              : ///
      72              : /// // From a directory with multiple architectures
      73              : /// let cache = LIEF::dsc::load("macos-12.6/", /*arch=*/"x86_64h");
      74              : /// ```
      75            0 : pub fn load_from_path(path: &str, arch: &str) -> Option<DyldSharedCache> {
      76            0 :     into_optional(ffi::dsc_DyldSharedCache::from_path(path, arch))
      77            0 : }
      78              : 
      79            0 : pub fn load_from_files(files: &[String]) -> Option<DyldSharedCache> {
      80            0 :     let mut c_strings = Vec::new();
      81            0 :     let mut c_ptrs = Vec::new();
      82            0 :     for file in files.iter() {
      83            0 :         let c_str = CString::new(file.as_str()).unwrap();
      84            0 :         c_strings.push(c_str);
      85            0 :         let c_ptr = c_strings.last().unwrap().as_ptr() as *const c_char;
      86            0 :         c_ptrs.push(c_ptr);
      87            0 :     }
      88            0 :     let files_ptr: *const *const c_char = c_ptrs.as_ptr();
      89            0 :     unsafe {
      90            0 :         into_optional(ffi::dsc_DyldSharedCache::from_files(files_ptr as *const c_char, c_ptrs.len()))
      91            0 :     }
      92            0 : }
        

Generated by: LCOV version 2.1-1