LCOV - code coverage report
Current view: top level - src/macho/commands - dylib.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 84.6 % 52 44
Test Date: 2026-03-21:00:00:00 Functions: 80.0 % 10 8

            Line data    Source code
       1              : use super::Command;
       2              : use lief_ffi as ffi;
       3              : 
       4              : use crate::common::FromFFI;
       5              : use crate::declare_iterator;
       6              : use std::marker::PhantomData;
       7              : 
       8              : /// Structure which represents a library dependency
       9              : pub struct Dylib<'a> {
      10              :     ptr: cxx::UniquePtr<ffi::MachO_Dylib>,
      11              :     _owner: PhantomData<&'a ffi::MachO_Binary>,
      12              : }
      13              : 
      14              : impl Dylib<'_> {
      15              :     /// Library name
      16        79932 :     pub fn name(&self) -> String {
      17        79932 :         self.ptr.name().to_string()
      18        79932 :     }
      19              : 
      20            0 :     pub fn set_name(&mut self, name: &str) {
      21            0 :         self.ptr.pin_mut().set_name(name.to_string());
      22            0 :     }
      23              : 
      24              :     /// Original string offset of the name
      25            0 :     pub fn name_offset(&self) -> u32 {
      26            0 :         self.ptr.name_offset()
      27            0 :     }
      28              : 
      29              :     /// Date and Time when the shared library was built
      30        79932 :     pub fn timestamp(&self) -> u32 {
      31        79932 :         self.ptr.timestamp()
      32        79932 :     }
      33              : 
      34              :     /// Current version of the shared library
      35        79932 :     pub fn current_version(&self) -> (u64, u64, u64) {
      36        79932 :         let vec = Vec::from(self.ptr.current_version().as_slice());
      37        79932 :         if vec.len() != 3 {
      38            0 :             return (0, 0, 0);
      39        79932 :         }
      40        79932 :         (vec[0], vec[1], vec[2])
      41        79932 :     }
      42              :     /// Compatibility version of the shared library
      43        79932 :     pub fn compatibility_version(&self) -> (u64, u64, u64) {
      44        79932 :         let vec = Vec::from(self.ptr.compatibility_version().as_slice());
      45        79932 :         if vec.len() != 3 {
      46            0 :             return (0, 0, 0);
      47        79932 :         }
      48        79932 :         (vec[0], vec[1], vec[2])
      49        79932 :     }
      50              : }
      51              : 
      52              : impl std::fmt::Debug for Dylib<'_> {
      53        79932 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      54        79932 :         let base = self as &dyn Command;
      55        79932 :         f.debug_struct("Dylib")
      56        79932 :             .field("base", &base)
      57        79932 :             .field("name", &self.name())
      58        79932 :             .field("timestamp", &self.timestamp())
      59        79932 :             .field("current_version", &self.current_version())
      60        79932 :             .field("compatibility_version", &self.compatibility_version())
      61        79932 :             .finish()
      62        79932 :     }
      63              : }
      64              : 
      65              : impl FromFFI<ffi::MachO_Dylib> for Dylib<'_> {
      66        79956 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_Dylib>) -> Self {
      67        79956 :         Self {
      68        79956 :             ptr: cmd,
      69        79956 :             _owner: PhantomData,
      70        79956 :         }
      71        79956 :     }
      72              : }
      73              : 
      74              : impl Command for Dylib<'_> {
      75       319728 :     fn get_base(&self) -> &ffi::MachO_Command {
      76       319728 :         self.ptr.as_ref().unwrap().as_ref()
      77       319728 :     }
      78              : }
      79              : 
      80         1128 : declare_iterator!(
      81         1128 :     Libraries,
      82         1128 :     Dylib<'a>,
      83         1128 :     ffi::MachO_Dylib,
      84         1128 :     ffi::MachO_Binary,
      85         1128 :     ffi::MachO_Binary_it_libraries
      86         1128 : );
        

Generated by: LCOV version 2.1-1