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

            Line data    Source code
       1              : use super::Command;
       2              : use crate::common::FromFFI;
       3              : use crate::to_slice;
       4              : use lief_ffi as ffi;
       5              : 
       6              : use std::marker::PhantomData;
       7              : 
       8              : /// Structure which represents the `LC_LINKER_OPTIMIZATION_HINT` command
       9              : pub struct LinkerOptHint<'a> {
      10              :     ptr: cxx::UniquePtr<ffi::MachO_LinkerOptHint>,
      11              :     _owner: PhantomData<&'a ffi::MachO_Binary>,
      12              : }
      13              : 
      14              : impl LinkerOptHint<'_> {
      15              :     /// Offset in the binary where the *hint* starts
      16           20 :     pub fn data_offset(&self) -> u32 {
      17           20 :         self.ptr.data_offset()
      18           20 :     }
      19              : 
      20              :     /// Size of the payload
      21           20 :     pub fn data_size(&self) -> u32 {
      22           20 :         self.ptr.data_size()
      23           20 :     }
      24              : 
      25              :     /// Payload as a slice of bytes
      26           10 :     pub fn content(&self) -> &[u8] {
      27           10 :         to_slice!(self.ptr.content());
      28           10 :     }
      29              : }
      30              : 
      31              : impl std::fmt::Debug for LinkerOptHint<'_> {
      32           20 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      33           20 :         let base = self as &dyn Command;
      34           20 :         f.debug_struct("LinkerOptHint")
      35           20 :             .field("base", &base)
      36           20 :             .field("data_offset", &self.data_offset())
      37           20 :             .field("data_size", &self.data_size())
      38           20 :             .finish()
      39           20 :     }
      40              : }
      41              : 
      42              : impl FromFFI<ffi::MachO_LinkerOptHint> for LinkerOptHint<'_> {
      43           20 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_LinkerOptHint>) -> Self {
      44           20 :         Self {
      45           20 :             ptr: cmd,
      46           20 :             _owner: PhantomData,
      47           20 :         }
      48           20 :     }
      49              : }
      50              : 
      51              : impl Command for LinkerOptHint<'_> {
      52           80 :     fn get_base(&self) -> &ffi::MachO_Command {
      53           80 :         self.ptr.as_ref().unwrap().as_ref()
      54           80 :     }
      55              : }
        

Generated by: LCOV version 2.1-1