LCOV - code coverage report
Current view: top level - src/objc - metadata.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 0.0 % 38 0
Test Date: 2024-11-30:00:00:00 Functions: 0.0 % 9 0

            Line data    Source code
       1              : use lief_ffi as ffi;
       2              : 
       3              : use std::marker::PhantomData;
       4              : use crate::common::{FromFFI, into_optional};
       5              : use crate::declare_fwd_iterator;
       6              : 
       7              : use super::{Class, Protocol, DeclOpt};
       8              : 
       9              : 
      10              : /// This structure is the main interface to inspect Objective-C metadata
      11              : ///
      12              : /// It can be access using the function [`crate::macho::Binary::objc_metadata`]
      13              : pub struct Metadata<'a> {
      14              :     ptr: cxx::UniquePtr<ffi::ObjC_Metadata>,
      15              :     _owner: PhantomData<&'a ()>,
      16              : }
      17              : 
      18              : impl FromFFI<ffi::ObjC_Metadata> for Metadata<'_> {
      19            0 :     fn from_ffi(info: cxx::UniquePtr<ffi::ObjC_Metadata>) -> Self {
      20            0 :         Self {
      21            0 :             ptr: info,
      22            0 :             _owner: PhantomData
      23            0 :         }
      24            0 :     }
      25              : }
      26              : 
      27              : impl Metadata<'_> {
      28              :     /// Return an iterator over the different Objective-C classes (`@interface`)
      29            0 :     pub fn classes(&self) -> Classes {
      30            0 :         Classes::new(self.ptr.classes())
      31            0 :     }
      32              : 
      33              :     /// Return an iterator over the Objective-C protocols declared in this binary (`@protocol`).
      34            0 :     pub fn protocols(&self) -> Protocols {
      35            0 :         Protocols::new(self.ptr.protocols())
      36            0 :     }
      37              : 
      38              :     /// Try to find the Objective-C class with the given **mangled** name
      39            0 :     pub fn class_by_name(&self, name: &str) -> Option<Class> {
      40            0 :         into_optional(self.ptr.get_class(name))
      41            0 :     }
      42              : 
      43              :     /// Try to find the Objective-C protocol with the given **mangled** name
      44            0 :     pub fn protocol_by_name(&self, name: &str) -> Option<Protocol> {
      45            0 :         into_optional(self.ptr.get_protocol(name))
      46            0 :     }
      47              : 
      48              :     /// Generate a header-like of all the Objective-C metadata identified in the
      49              :     /// binary.
      50            0 :     pub fn to_decl(&self) -> String {
      51            0 :         self.ptr.to_decl().to_string()
      52            0 :     }
      53              : 
      54              :     /// Same behavior as [`Metadata::to_decl`] but with an additional
      55              :     /// [`DeclOpt`] parameter to customize the output
      56            0 :     pub fn to_decl_with_opt(&self, opt: &DeclOpt) -> String {
      57            0 :         self.ptr.to_decl_with_opt(opt.to_ffi()).to_string()
      58            0 :     }
      59              : }
      60              : 
      61            0 : declare_fwd_iterator!(
      62            0 :     Classes,
      63            0 :     Class<'a>,
      64            0 :     ffi::ObjC_Class,
      65            0 :     ffi::ObjC_Metadata,
      66            0 :     ffi::ObjC_Metadata_it_classes
      67            0 : );
      68              : 
      69            0 : declare_fwd_iterator!(
      70            0 :     Protocols,
      71            0 :     Protocol<'a>,
      72            0 :     ffi::ObjC_Protocol,
      73            0 :     ffi::ObjC_Metadata,
      74            0 :     ffi::ObjC_Metadata_it_protocols
      75            0 : );
        

Generated by: LCOV version 2.1-1