LCOV - code coverage report
Current view: top level - src/macho - fat_binary.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 83.9 % 31 26
Test Date: 2024-10-27:00:00:00 Functions: 80.0 % 5 4

            Line data    Source code
       1              : use super::binary::Binary;
       2              : use lief_ffi as ffi;
       3              : 
       4              : use crate::common::FromFFI;
       5              : 
       6              : /// This structure represents a FAT Mach-O
       7              : pub struct FatBinary {
       8              :     pub nb_macho: u32,
       9              :     ptr: cxx::UniquePtr<ffi::MachO_FatBinary>,
      10              : }
      11              : 
      12              : impl FromFFI<ffi::MachO_FatBinary> for FatBinary {
      13           88 :     fn from_ffi(ptr: cxx::UniquePtr<ffi::MachO_FatBinary>) -> Self {
      14           88 :         Self {
      15           88 :             nb_macho: ptr.size(),
      16           88 :             ptr,
      17           88 :         }
      18           88 :     }
      19              : }
      20              : 
      21              : impl std::fmt::Debug for FatBinary {
      22            0 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      23            0 :         f.debug_struct("FatBinary")
      24            0 :             .field("nb_macho", &self.nb_macho)
      25            0 :             .finish()
      26            0 :     }
      27              : }
      28              : 
      29              : /// Iterator over the different [`crate::macho::Binary`] wrapped by this FAT Mach-O
      30              : pub struct FatBinaryIterator<'a> {
      31              :     index: u32,
      32              :     fat: &'a FatBinary,
      33              : }
      34              : 
      35              : impl FatBinary {
      36              :     /// Create a FatBinary from the given Mach-O path.
      37           96 :     pub fn parse(path: &str) -> FatBinary {
      38           96 :         let bin = ffi::MachO_FatBinary::parse(path);
      39           96 :         FatBinary {
      40           96 :             nb_macho: bin.size(),
      41           96 :             ptr: bin,
      42           96 :         }
      43           96 :     }
      44              : 
      45              :     /// Iterator over the [`crate::macho::Binary`]
      46           96 :     pub fn iter(&self) -> FatBinaryIterator {
      47           96 :         FatBinaryIterator {
      48           96 :             index: 0,
      49           96 :             fat: self,
      50           96 :         }
      51           96 :     }
      52              : }
      53              : 
      54              : impl<'a> Iterator for FatBinaryIterator<'a> {
      55              :     type Item = Binary;
      56          208 :     fn next(&mut self) -> Option<Self::Item> {
      57          208 :         if self.index >= self.fat.nb_macho {
      58           96 :             return None;
      59          112 :         }
      60          112 :         self.index += 1;
      61          112 :         Some(Binary::from_ffi(self.fat.ptr.binary_at(self.index - 1)))
      62          208 :     }
      63              : }
        

Generated by: LCOV version 2.1-1