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

Generated by: LCOV version 2.1-1