LCOV - code coverage report
Current view: top level - src/macho/commands - dyldinfo.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 100.0 % 49 49
Test Date: 2024-10-27:00:00:00 Functions: 100.0 % 12 12

            Line data    Source code
       1              : use super::Command;
       2              : use crate::common::FromFFI;
       3              : use crate::macho::binding_info::Dyld;
       4              : use crate::macho::{BindingInfo, ExportInfo};
       5              : use std::marker::PhantomData;
       6              : 
       7              : use crate::{declare_iterator, declare_iterator_conv, to_slice};
       8              : 
       9              : use lief_ffi as ffi;
      10              : 
      11              : /// Structure that represents the `LC_DYLD_INFO` and `LC_DYLD_INFO_ONLY` commands
      12              : pub struct DyldInfo<'a> {
      13              :     ptr: cxx::UniquePtr<ffi::MachO_DyldInfo>,
      14              :     _owner: PhantomData<&'a ffi::MachO_Binary>,
      15              : }
      16              : 
      17              : impl std::fmt::Debug for DyldInfo<'_> {
      18          144 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      19          144 :         let base = self as &dyn Command;
      20          144 :         f.debug_struct("DyldInfo")
      21          144 :             .field("base", &base)
      22          144 :             .field("rebase_opcodes", &self.rebase_opcodes().is_empty())
      23          144 :             .field("bind_opcodes", &self.bind_opcodes().is_empty())
      24          144 :             .field("weak_bind_opcodes", &self.weak_bind_opcodes().is_empty())
      25          144 :             .field("lazy_bind_opcodes", &self.lazy_bind_opcodes().is_empty())
      26          144 :             .field("export_trie", &self.export_trie().is_empty())
      27          144 :             .finish()
      28          144 :     }
      29              : }
      30              : 
      31              : impl FromFFI<ffi::MachO_DyldInfo> for DyldInfo<'_> {
      32          144 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_DyldInfo>) -> Self {
      33          144 :         Self {
      34          144 :             ptr: cmd,
      35          144 :             _owner: PhantomData,
      36          144 :         }
      37          144 :     }
      38              : }
      39              : 
      40              : impl<'a> DyldInfo<'a> {
      41              :     /// Return Rebase's opcodes as a slice of bytes
      42          216 :     pub fn rebase_opcodes(&self) -> &[u8] {
      43          216 :         to_slice!(self.ptr.rebase_opcodes());
      44          216 :     }
      45              : 
      46              :     /// Return **regular** binding's opcodes as a slice of bytes
      47          216 :     pub fn bind_opcodes(&self) -> &[u8] {
      48          216 :         to_slice!(self.ptr.bind_opcodes());
      49          216 :     }
      50              : 
      51              :     /// Return **weak** binding's opcodes as a slice of bytes
      52          216 :     pub fn weak_bind_opcodes(&self) -> &[u8] {
      53          216 :         to_slice!(self.ptr.weak_bind_opcodes());
      54          216 :     }
      55              : 
      56              :     /// Return **lazy** binding's opcodes as a slice of bytes
      57          216 :     pub fn lazy_bind_opcodes(&self) -> &[u8] {
      58          216 :         to_slice!(self.ptr.lazy_bind_opcodes());
      59          216 :     }
      60              : 
      61              :     /// Return the raw export trie as a slice of bytes
      62          216 :     pub fn export_trie(&self) -> &[u8] {
      63          216 :         to_slice!(self.ptr.export_trie());
      64          216 :     }
      65              : 
      66              :     /// Return an iterator over the [`crate::macho::BindingInfo::Dyld`] associated with this
      67              :     /// command
      68           72 :     pub fn bindings(&self) -> BindingInfos {
      69           72 :         BindingInfos::new(self.ptr.bindings())
      70           72 :     }
      71              : 
      72              :     /// Return an iterator over the [`crate::macho::ExportInfo`] associated with this command
      73           72 :     pub fn exports(&self) -> ExportInfos {
      74           72 :         ExportInfos::new(self.ptr.exports())
      75           72 :     }
      76              : }
      77              : 
      78              : impl Command for DyldInfo<'_> {
      79          576 :     fn get_base(&self) -> &ffi::MachO_Command {
      80          576 :         self.ptr.as_ref().unwrap().as_ref()
      81          576 :     }
      82              : }
      83              : 
      84              : declare_iterator_conv!(
      85              :     BindingInfos,
      86              :     BindingInfo<'a>,
      87              :     ffi::MachO_BindingInfo,
      88              :     ffi::MachO_DyldInfo,
      89              :     ffi::MachO_DyldInfo_it_bindings,
      90        51560 :     |n| BindingInfo::Dyld(Dyld::from_ffi(n))
      91              : );
      92        63456 : declare_iterator!(
      93        63456 :     ExportInfos,
      94        63456 :     ExportInfo<'a>,
      95        63456 :     ffi::MachO_ExportInfo,
      96        63456 :     ffi::MachO_DyldInfo,
      97        63456 :     ffi::MachO_DyldInfo_it_exports
      98        63456 : );
        

Generated by: LCOV version 2.1-1