LCOV - code coverage report
Current view: top level - src/macho/commands - sub_framework.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 100.0 % 19 19
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 SubFramework command.
       8              : /// Accodring to the Mach-O ``loader.h`` documentation:
       9              : ///
      10              : /// > A dynamically linked shared library may be a subframework of an umbrella
      11              : /// > framework.  If so it will be linked with "-umbrella umbrella_name" where
      12              : /// > Where "umbrella_name" is the name of the umbrella framework. A subframework
      13              : /// > can only be linked against by its umbrella framework or other subframeworks
      14              : /// > that are part of the same umbrella framework.  Otherwise the static link
      15              : /// > editor produces an error and states to link against the umbrella framework.
      16              : /// > The name of the umbrella framework for subframeworks is recorded in the
      17              : /// > following structure.
      18              : pub struct SubFramework<'a> {
      19              :     ptr: cxx::UniquePtr<ffi::MachO_SubFramework>,
      20              :     _owner: PhantomData<&'a ffi::MachO_Binary>
      21              : }
      22              : 
      23              : 
      24              : impl SubFramework<'_> {
      25              :     /// Name of the umbrella framework
      26           40 :     pub fn umbrella(&self) -> String {
      27           40 :         self.ptr.umbrella().to_string()
      28           40 :     }
      29              : }
      30              : 
      31              : impl std::fmt::Debug for SubFramework<'_> {
      32           40 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      33           40 :         let base = self as &dyn Command;
      34           40 :         f.debug_struct("SubFramework")
      35           40 :             .field("base", &base)
      36           40 :             .field("umbrella", &self.umbrella())
      37           40 :             .finish()
      38           40 :     }
      39              : }
      40              : 
      41              : impl FromFFI<ffi::MachO_SubFramework> for SubFramework<'_> {
      42           40 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_SubFramework>) -> Self {
      43           40 :         Self {
      44           40 :             ptr: cmd,
      45           40 :             _owner: PhantomData
      46           40 :         }
      47           40 :     }
      48              : }
      49              : 
      50              : impl Command for SubFramework<'_> {
      51          160 :     fn get_base(&self) -> &ffi::MachO_Command {
      52          160 :         self.ptr.as_ref().unwrap().as_ref()
      53          160 :     }
      54              : }
      55              : 
        

Generated by: LCOV version 2.1-1