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-10-27: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           48 :     pub fn data_offset(&self) -> u32 {
      22           48 :         self.ptr.data_offset()
      23           48 :     }
      24              : 
      25              :     /// Size of the `LC_DYLD_EXPORTS_TRIE` payload.
      26           48 :     pub fn data_size(&self) -> u32 {
      27           48 :         self.ptr.data_size()
      28           48 :     }
      29              : 
      30              :     /// Raw payload as a slice of bytes
      31           24 :     pub fn content(&self) -> &[u8] {
      32           24 :         to_slice!(self.ptr.content());
      33           24 :     }
      34              : 
      35              :     /// Iterator over the [`crate::macho::ExportInfo`] associated with this command
      36           24 :     pub fn exports(&self) -> ExportInfos {
      37           24 :         ExportInfos::new(self.ptr.exports())
      38           24 :     }
      39              : }
      40              : 
      41              : impl std::fmt::Debug for DyldExportsTrie<'_> {
      42           48 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      43           48 :         let base = self as &dyn Command;
      44           48 :         f.debug_struct("DyldExportsTrie")
      45           48 :             .field("base", &base)
      46           48 :             .field("data_offset", &self.data_offset())
      47           48 :             .field("data_size", &self.data_size())
      48           48 :             .finish()
      49           48 :     }
      50              : }
      51              : 
      52              : impl FromFFI<ffi::MachO_DyldExportsTrie> for DyldExportsTrie<'_> {
      53           48 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_DyldExportsTrie>) -> Self {
      54           48 :         Self {
      55           48 :             ptr: cmd,
      56           48 :             _owner: PhantomData,
      57           48 :         }
      58           48 :     }
      59              : }
      60              : 
      61              : impl Command for DyldExportsTrie<'_> {
      62          192 :     fn get_base(&self) -> &ffi::MachO_Command {
      63          192 :         self.ptr.as_ref().unwrap().as_ref()
      64          192 :     }
      65              : }
      66              : 
      67         7360 : declare_iterator!(
      68         7360 :     ExportInfos,
      69         7360 :     ExportInfo<'a>,
      70         7360 :     ffi::MachO_ExportInfo,
      71         7360 :     ffi::MachO_DyldExportsTrie,
      72         7360 :     ffi::MachO_DyldExportsTrie_it_exports
      73         7360 : );
        

Generated by: LCOV version 2.1-1