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: 2026-04-12:00:00:00 Functions: 0.0 % 9 0

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

Generated by: LCOV version 2.1-1