LCOV - code coverage report
Current view: top level - src/macho/commands - dylib.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 95.7 % 46 44
Test Date: 2024-10-27:00:00:00 Functions: 100.0 % 8 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        53232 :     pub fn name(&self) -> String {
      17        53232 :         self.ptr.name().to_string()
      18        53232 :     }
      19              : 
      20              :     /// Date and Time when the shared library was built
      21        53232 :     pub fn timestamp(&self) -> u32 {
      22        53232 :         self.ptr.timestamp()
      23        53232 :     }
      24              : 
      25              :     /// Current version of the shared library
      26        53232 :     pub fn current_version(&self) -> (u64, u64, u64) {
      27        53232 :         let vec = Vec::from(self.ptr.current_version().as_slice());
      28        53232 :         if vec.len() != 3 {
      29            0 :             return (0, 0, 0);
      30        53232 :         }
      31        53232 :         (vec[0], vec[1], vec[2])
      32        53232 :     }
      33              :     /// Compatibility version of the shared library
      34        53232 :     pub fn compatibility_version(&self) -> (u64, u64, u64) {
      35        53232 :         let vec = Vec::from(self.ptr.compatibility_version().as_slice());
      36        53232 :         if vec.len() != 3 {
      37            0 :             return (0, 0, 0);
      38        53232 :         }
      39        53232 :         (vec[0], vec[1], vec[2])
      40        53232 :     }
      41              : }
      42              : 
      43              : impl std::fmt::Debug for Dylib<'_> {
      44        53232 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      45        53232 :         let base = self as &dyn Command;
      46        53232 :         f.debug_struct("Dylib")
      47        53232 :             .field("base", &base)
      48        53232 :             .field("name", &self.name())
      49        53232 :             .field("timestamp", &self.timestamp())
      50        53232 :             .field("current_version", &self.current_version())
      51        53232 :             .field("compatibility_version", &self.compatibility_version())
      52        53232 :             .finish()
      53        53232 :     }
      54              : }
      55              : 
      56              : impl FromFFI<ffi::MachO_Dylib> for Dylib<'_> {
      57        53232 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_Dylib>) -> Self {
      58        53232 :         Self {
      59        53232 :             ptr: cmd,
      60        53232 :             _owner: PhantomData,
      61        53232 :         }
      62        53232 :     }
      63              : }
      64              : 
      65              : impl Command for Dylib<'_> {
      66       212928 :     fn get_base(&self) -> &ffi::MachO_Command {
      67       212928 :         self.ptr.as_ref().unwrap().as_ref()
      68       212928 :     }
      69              : }
      70              : 
      71          728 : declare_iterator!(
      72          728 :     Libraries,
      73          728 :     Dylib<'a>,
      74          728 :     ffi::MachO_Dylib,
      75          728 :     ffi::MachO_Binary,
      76          728 :     ffi::MachO_Binary_it_libraries
      77          728 : );
        

Generated by: LCOV version 2.1-1