LCOV - code coverage report
Current view: top level - src/macho/commands - build_version.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 65.6 % 61 40
Test Date: 2025-01-11:00:00:00 Functions: 72.7 % 11 8

            Line data    Source code
       1              : use std::marker::PhantomData;
       2              : 
       3              : use lief_ffi as ffi;
       4              : 
       5              : use super::Command;
       6              : use crate::common::FromFFI;
       7              : 
       8              : /// Structure that represents the `LC_BUILD_VERSION` command
       9              : pub struct BuildVersion<'a> {
      10              :     ptr: cxx::UniquePtr<ffi::MachO_BuildVersion>,
      11              :     _owner: PhantomData<&'a ffi::MachO_Binary>,
      12              : }
      13              : 
      14              : #[allow(non_camel_case_types)]
      15          240 : #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
      16              : pub enum Platform {
      17              :     MACOS,
      18              :     IOS,
      19              :     TVOS,
      20              :     WATCHOS,
      21              :     BRIDGEOS,
      22              :     MAC_CATALYST,
      23              :     IOS_SIMULATOR,
      24              :     TVOS_SIMULATOR,
      25              :     WATCHOS_SIMULATOR,
      26              :     DRIVERKIT,
      27              :     VISIONOS,
      28              :     VISIONOS_SIMULATOR,
      29              :     FIRMWARE,
      30              :     SEPOS,
      31              :     MACOS_EXCLAVE_CORE,
      32              :     MACOS_EXCLAVE_KIT,
      33              :     IOS_EXCLAVE_CORE,
      34              :     IOS_EXCLAVE_KIT,
      35              :     TVOS_EXCLAVE_CORE,
      36              :     TVOS_EXCLAVE_KIT,
      37              :     ANY,
      38              :     UNKNOWN(u32),
      39              : }
      40              : 
      41              : impl From<u32> for Platform {
      42          240 :     fn from(value: u32) -> Self {
      43          240 :         match value {
      44           60 :             0x00000001 => Platform::MACOS,
      45           90 :             0x00000002 => Platform::IOS,
      46            0 :             0x00000003 => Platform::TVOS,
      47            0 :             0x00000004 => Platform::WATCHOS,
      48            0 :             0x00000005 => Platform::BRIDGEOS,
      49            0 :             0x00000006 => Platform::MAC_CATALYST,
      50            0 :             0x00000007 => Platform::IOS_SIMULATOR,
      51            0 :             0x00000008 => Platform::TVOS_SIMULATOR,
      52            0 :             0x00000009 => Platform::WATCHOS_SIMULATOR,
      53            0 :             0x0000000A => Platform::DRIVERKIT,
      54            0 :             0x0000000B => Platform::VISIONOS,
      55            0 :             0x0000000C => Platform::VISIONOS_SIMULATOR,
      56            0 :             0x0000000D => Platform::FIRMWARE,
      57            0 :             0x0000000E => Platform::SEPOS,
      58            0 :             0x0000000F => Platform::MACOS_EXCLAVE_CORE,
      59            0 :             0x00000010 => Platform::MACOS_EXCLAVE_KIT,
      60            0 :             0x00000011 => Platform::IOS_EXCLAVE_CORE,
      61            0 :             0x00000012 => Platform::IOS_EXCLAVE_KIT,
      62            0 :             0x00000013 => Platform::TVOS_EXCLAVE_CORE,
      63            0 :             0x00000014 => Platform::TVOS_EXCLAVE_KIT,
      64            0 :             0xFFFFFFFF => Platform::ANY,
      65           90 :             _ => Platform::UNKNOWN(value),
      66              :         }
      67          240 :     }
      68              : }
      69              : 
      70              : impl BuildVersion<'_> {
      71          100 :     pub fn sdk(&self) -> (u64, u64, u64) {
      72          100 :         let vec = Vec::from(self.ptr.sdk().as_slice());
      73          100 :         if vec.len() != 3 {
      74            0 :             return (0, 0, 0);
      75          100 :         }
      76          100 :         (vec[0], vec[1], vec[2])
      77          100 :     }
      78              : 
      79          100 :     pub fn minos(&self) -> (u64, u64, u64) {
      80          100 :         let vec = Vec::from(self.ptr.sdk().as_slice());
      81          100 :         if vec.len() != 3 {
      82            0 :             return (0, 0, 0);
      83          100 :         }
      84          100 :         (vec[0], vec[1], vec[2])
      85          100 :     }
      86              : 
      87          100 :     pub fn platform(&self) -> Platform {
      88          100 :         Platform::from(self.ptr.platform())
      89          100 :     }
      90              : }
      91              : 
      92              : impl std::fmt::Debug for BuildVersion<'_> {
      93          100 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      94          100 :         let base = self as &dyn Command;
      95          100 :         f.debug_struct("BuildVersion")
      96          100 :             .field("base", &base)
      97          100 :             .field("sdk", &self.sdk())
      98          100 :             .field("minos", &self.minos())
      99          100 :             .field("platform", &self.platform())
     100          100 :             .finish()
     101          100 :     }
     102              : }
     103              : 
     104              : impl FromFFI<ffi::MachO_BuildVersion> for BuildVersion<'_> {
     105          100 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_BuildVersion>) -> Self {
     106          100 :         Self {
     107          100 :             ptr: cmd,
     108          100 :             _owner: PhantomData,
     109          100 :         }
     110          100 :     }
     111              : }
     112              : 
     113              : impl Command for BuildVersion<'_> {
     114          400 :     fn get_base(&self) -> &ffi::MachO_Command {
     115          400 :         self.ptr.as_ref().unwrap().as_ref()
     116          400 :     }
     117              : }
        

Generated by: LCOV version 2.1-1