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

Generated by: LCOV version 2.1-1