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

            Line data    Source code
       1              : use super::Command;
       2              : use crate::common::FromFFI;
       3              : use crate::macho::export_info::ExportInfo;
       4              : use crate::to_slice;
       5              : use lief_ffi as ffi;
       6              : use std::marker::PhantomData;
       7              : 
       8              : use crate::declare_iterator;
       9              : 
      10              : /// Structure that represents the `LC_DYLD_EXPORTS_TRIE` command
      11              : ///
      12              : /// In recent Mach-O binaries, this command replace the DyldInfo export trie buffer
      13              : pub struct DyldExportsTrie<'a> {
      14              :     ptr: cxx::UniquePtr<ffi::MachO_DyldExportsTrie>,
      15              :     _owner: PhantomData<&'a ffi::MachO_Binary>,
      16              : }
      17              : 
      18              : impl DyldExportsTrie<'_> {
      19              :     /// Offset of the `LC_DYLD_EXPORTS_TRIE`. This offset should point in the
      20              :     /// `__LINKEDIT` segment
      21           60 :     pub fn data_offset(&self) -> u32 {
      22           60 :         self.ptr.data_offset()
      23           60 :     }
      24              : 
      25              :     /// Size of the `LC_DYLD_EXPORTS_TRIE` payload.
      26           60 :     pub fn data_size(&self) -> u32 {
      27           60 :         self.ptr.data_size()
      28           60 :     }
      29              : 
      30              :     /// Raw payload as a slice of bytes
      31           30 :     pub fn content(&self) -> &[u8] {
      32           30 :         to_slice!(self.ptr.content());
      33           30 :     }
      34              : 
      35              :     /// Iterator over the [`crate::macho::ExportInfo`] associated with this command
      36           30 :     pub fn exports(&self) -> ExportInfos {
      37           30 :         ExportInfos::new(self.ptr.exports())
      38           30 :     }
      39              : }
      40              : 
      41              : impl std::fmt::Debug for DyldExportsTrie<'_> {
      42           60 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      43           60 :         let base = self as &dyn Command;
      44           60 :         f.debug_struct("DyldExportsTrie")
      45           60 :             .field("base", &base)
      46           60 :             .field("data_offset", &self.data_offset())
      47           60 :             .field("data_size", &self.data_size())
      48           60 :             .finish()
      49           60 :     }
      50              : }
      51              : 
      52              : impl FromFFI<ffi::MachO_DyldExportsTrie> for DyldExportsTrie<'_> {
      53           60 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_DyldExportsTrie>) -> Self {
      54           60 :         Self {
      55           60 :             ptr: cmd,
      56           60 :             _owner: PhantomData,
      57           60 :         }
      58           60 :     }
      59              : }
      60              : 
      61              : impl Command for DyldExportsTrie<'_> {
      62          240 :     fn get_base(&self) -> &ffi::MachO_Command {
      63          240 :         self.ptr.as_ref().unwrap().as_ref()
      64          240 :     }
      65              : }
      66              : 
      67         9200 : declare_iterator!(
      68         9200 :     ExportInfos,
      69         9200 :     ExportInfo<'a>,
      70         9200 :     ffi::MachO_ExportInfo,
      71         9200 :     ffi::MachO_DyldExportsTrie,
      72         9200 :     ffi::MachO_DyldExportsTrie_it_exports
      73         9200 : );
        

Generated by: LCOV version 2.1-1