LCOV - code coverage report
Current view: top level - src/macho/commands - build_version.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 72.7 % 55 40
Test Date: 2024-11-30: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              :     ANY,
      32              :     UNKNOWN(u32),
      33              : }
      34              : 
      35              : impl From<u32> for Platform {
      36          240 :     fn from(value: u32) -> Self {
      37          240 :         match value {
      38           60 :             0x00000001 => Platform::MACOS,
      39           90 :             0x00000002 => Platform::IOS,
      40            0 :             0x00000003 => Platform::TVOS,
      41            0 :             0x00000004 => Platform::WATCHOS,
      42            0 :             0x00000005 => Platform::BRIDGEOS,
      43            0 :             0x00000006 => Platform::MAC_CATALYST,
      44            0 :             0x00000007 => Platform::IOS_SIMULATOR,
      45            0 :             0x00000008 => Platform::TVOS_SIMULATOR,
      46            0 :             0x00000009 => Platform::WATCHOS_SIMULATOR,
      47            0 :             0x0000000A => Platform::DRIVERKIT,
      48            0 :             0x0000000B => Platform::VISIONOS,
      49            0 :             0x0000000C => Platform::VISIONOS_SIMULATOR,
      50            0 :             0x0000000D => Platform::FIRMWARE,
      51            0 :             0x0000000E => Platform::SEPOS,
      52            0 :             0xFFFFFFFF => Platform::ANY,
      53           90 :             _ => Platform::UNKNOWN(value),
      54              :         }
      55          240 :     }
      56              : }
      57              : 
      58              : impl BuildVersion<'_> {
      59          100 :     pub fn sdk(&self) -> (u64, u64, u64) {
      60          100 :         let vec = Vec::from(self.ptr.sdk().as_slice());
      61          100 :         if vec.len() != 3 {
      62            0 :             return (0, 0, 0);
      63          100 :         }
      64          100 :         (vec[0], vec[1], vec[2])
      65          100 :     }
      66              : 
      67          100 :     pub fn minos(&self) -> (u64, u64, u64) {
      68          100 :         let vec = Vec::from(self.ptr.sdk().as_slice());
      69          100 :         if vec.len() != 3 {
      70            0 :             return (0, 0, 0);
      71          100 :         }
      72          100 :         (vec[0], vec[1], vec[2])
      73          100 :     }
      74              : 
      75          100 :     pub fn platform(&self) -> Platform {
      76          100 :         Platform::from(self.ptr.platform())
      77          100 :     }
      78              : }
      79              : 
      80              : impl std::fmt::Debug for BuildVersion<'_> {
      81          100 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      82          100 :         let base = self as &dyn Command;
      83          100 :         f.debug_struct("BuildVersion")
      84          100 :             .field("base", &base)
      85          100 :             .field("sdk", &self.sdk())
      86          100 :             .field("minos", &self.minos())
      87          100 :             .field("platform", &self.platform())
      88          100 :             .finish()
      89          100 :     }
      90              : }
      91              : 
      92              : impl FromFFI<ffi::MachO_BuildVersion> for BuildVersion<'_> {
      93          100 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_BuildVersion>) -> Self {
      94          100 :         Self {
      95          100 :             ptr: cmd,
      96          100 :             _owner: PhantomData,
      97          100 :         }
      98          100 :     }
      99              : }
     100              : 
     101              : impl Command for BuildVersion<'_> {
     102          400 :     fn get_base(&self) -> &ffi::MachO_Command {
     103          400 :         self.ptr.as_ref().unwrap().as_ref()
     104          400 :     }
     105              : }
        

Generated by: LCOV version 2.1-1