LCOV - code coverage report
Current view: top level - src/macho/commands - source_version.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 95.7 % 23 22
Test Date: 2024-11-30:00:00:00 Functions: 100.0 % 4 4

            Line data    Source code
       1              : use super::Command;
       2              : use lief_ffi as ffi;
       3              : use crate::common::FromFFI;
       4              : 
       5              : use std::marker::PhantomData;
       6              : 
       7              : /// Class that represents the MachO `LC_SOURCE_VERSION`
       8              : /// This command is used to provide the *version* of the sources used to
       9              : /// build the binary.
      10              : pub struct SourceVersion<'a> {
      11              :     ptr: cxx::UniquePtr<ffi::MachO_SourceVersion>,
      12              :     _owner: PhantomData<&'a ffi::MachO_Binary>
      13              : }
      14              : 
      15              : impl SourceVersion<'_> {
      16          240 :     pub fn version(&self) -> (u64, u64, u64, u64, u64) {
      17          240 :         let vec = Vec::from(self.ptr.version().as_slice());
      18          240 :         if vec.len() != 5 {
      19            0 :             return (0, 0, 0, 0, 0);
      20          240 :         }
      21          240 :         (vec[0], vec[1], vec[2], vec[3], vec[4])
      22          240 :     }
      23              : }
      24              : 
      25              : impl std::fmt::Debug for SourceVersion<'_> {
      26          240 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      27          240 :         let base = self as &dyn Command;
      28          240 :         f.debug_struct("SourceVersion")
      29          240 :             .field("base", &base)
      30          240 :             .field("version", &self.version())
      31          240 :             .finish()
      32          240 :     }
      33              : }
      34              : 
      35              : impl<'a> FromFFI<ffi::MachO_SourceVersion> for SourceVersion<'a> {
      36          240 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_SourceVersion>) -> Self {
      37          240 :         Self {
      38          240 :             ptr: cmd,
      39          240 :             _owner: PhantomData
      40          240 :         }
      41          240 :     }
      42              : }
      43              : 
      44              : impl Command for SourceVersion<'_> {
      45          960 :     fn get_base(&self) -> &ffi::MachO_Command {
      46          960 :         self.ptr.as_ref().unwrap().as_ref()
      47          960 :     }
      48              : }
        

Generated by: LCOV version 2.1-1