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-11-30: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          180 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      19          180 :         let base = self as &dyn Command;
      20          180 :         f.debug_struct("DyldInfo")
      21          180 :             .field("base", &base)
      22          180 :             .field("rebase_opcodes", &self.rebase_opcodes().is_empty())
      23          180 :             .field("bind_opcodes", &self.bind_opcodes().is_empty())
      24          180 :             .field("weak_bind_opcodes", &self.weak_bind_opcodes().is_empty())
      25          180 :             .field("lazy_bind_opcodes", &self.lazy_bind_opcodes().is_empty())
      26          180 :             .field("export_trie", &self.export_trie().is_empty())
      27          180 :             .finish()
      28          180 :     }
      29              : }
      30              : 
      31              : impl FromFFI<ffi::MachO_DyldInfo> for DyldInfo<'_> {
      32          180 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_DyldInfo>) -> Self {
      33          180 :         Self {
      34          180 :             ptr: cmd,
      35          180 :             _owner: PhantomData,
      36          180 :         }
      37          180 :     }
      38              : }
      39              : 
      40              : impl<'a> DyldInfo<'a> {
      41              :     /// Return Rebase's opcodes as a slice of bytes
      42          270 :     pub fn rebase_opcodes(&self) -> &[u8] {
      43          270 :         to_slice!(self.ptr.rebase_opcodes());
      44          270 :     }
      45              : 
      46              :     /// Return **regular** binding's opcodes as a slice of bytes
      47          270 :     pub fn bind_opcodes(&self) -> &[u8] {
      48          270 :         to_slice!(self.ptr.bind_opcodes());
      49          270 :     }
      50              : 
      51              :     /// Return **weak** binding's opcodes as a slice of bytes
      52          270 :     pub fn weak_bind_opcodes(&self) -> &[u8] {
      53          270 :         to_slice!(self.ptr.weak_bind_opcodes());
      54          270 :     }
      55              : 
      56              :     /// Return **lazy** binding's opcodes as a slice of bytes
      57          270 :     pub fn lazy_bind_opcodes(&self) -> &[u8] {
      58          270 :         to_slice!(self.ptr.lazy_bind_opcodes());
      59          270 :     }
      60              : 
      61              :     /// Return the raw export trie as a slice of bytes
      62          270 :     pub fn export_trie(&self) -> &[u8] {
      63          270 :         to_slice!(self.ptr.export_trie());
      64          270 :     }
      65              : 
      66              :     /// Return an iterator over the [`crate::macho::BindingInfo::Dyld`] associated with this
      67              :     /// command
      68           90 :     pub fn bindings(&self) -> BindingInfos {
      69           90 :         BindingInfos::new(self.ptr.bindings())
      70           90 :     }
      71              : 
      72              :     /// Return an iterator over the [`crate::macho::ExportInfo`] associated with this command
      73           90 :     pub fn exports(&self) -> ExportInfos {
      74           90 :         ExportInfos::new(self.ptr.exports())
      75           90 :     }
      76              : }
      77              : 
      78              : impl Command for DyldInfo<'_> {
      79          720 :     fn get_base(&self) -> &ffi::MachO_Command {
      80          720 :         self.ptr.as_ref().unwrap().as_ref()
      81          720 :     }
      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        64450 :     |n| BindingInfo::Dyld(Dyld::from_ffi(n))
      91              : );
      92        79320 : declare_iterator!(
      93        79320 :     ExportInfos,
      94        79320 :     ExportInfo<'a>,
      95        79320 :     ffi::MachO_ExportInfo,
      96        79320 :     ffi::MachO_DyldInfo,
      97        79320 :     ffi::MachO_DyldInfo_it_exports
      98        79320 : );
        

Generated by: LCOV version 2.1-1