LCOV - code coverage report
Current view: top level - src/macho/commands - rpath.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 54.3 % 35 19
Test Date: 2026-04-12:00:00:00 Functions: 50.0 % 8 4

            Line data    Source code
       1              : use super::Command;
       2              : use crate::common::FromFFI;
       3              : use crate::declare_iterator;
       4              : use lief_ffi as ffi;
       5              : use std::marker::PhantomData;
       6              : 
       7              : /// Structure that represents the `LC_RPATH` command.
       8              : ///
       9              : /// This command is used to add path for searching libraries
      10              : /// associated with the `@rpath` prefix.
      11              : pub struct RPath<'a> {
      12              :     ptr: cxx::UniquePtr<ffi::MachO_RPathCommand>,
      13              :     _owner: PhantomData<&'a ffi::MachO_Binary>,
      14              : }
      15              : 
      16              : impl RPath<'_> {
      17              :     /// Create a new Rpath command with the given path
      18            0 :     pub fn new(value: &str) -> RPath<'static> {
      19            0 :         RPath::from_ffi(lief_ffi::MachO_RPathCommand::create(value.to_string()))
      20            0 :     }
      21              : 
      22              :     /// The rpath value as a string
      23           78 :     pub fn path(&self) -> String {
      24           78 :         self.ptr.path().to_string()
      25           78 :     }
      26              : 
      27              :     /// Set the rpath value
      28            0 :     pub fn set_path(&mut self, path: &str) {
      29            0 :         self.ptr.pin_mut().set_path(path.to_string());
      30            0 :     }
      31              : 
      32              :     /// Original string offset of the path
      33            0 :     pub fn path_offset(&self) -> u32 {
      34            0 :         self.ptr.path_offset()
      35            0 :     }
      36              : }
      37              : 
      38              : impl std::fmt::Debug for RPath<'_> {
      39           78 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      40           78 :         let base = self as &dyn Command;
      41           78 :         f.debug_struct("RPath")
      42           78 :             .field("base", &base)
      43           78 :             .field("path", &self.path())
      44           78 :             .finish()
      45           78 :     }
      46              : }
      47              : 
      48              : impl FromFFI<ffi::MachO_RPathCommand> for RPath<'_> {
      49           78 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_RPathCommand>) -> Self {
      50           78 :         Self {
      51           78 :             ptr: cmd,
      52           78 :             _owner: PhantomData,
      53           78 :         }
      54           78 :     }
      55              : }
      56              : 
      57              : impl Command for RPath<'_> {
      58          312 :     fn get_base(&self) -> &ffi::MachO_Command {
      59          312 :         self.ptr.as_ref().unwrap().as_ref()
      60          312 :     }
      61              : }
      62              : 
      63            0 : declare_iterator!(
      64            0 :     RPaths,
      65            0 :     RPath<'a>,
      66            0 :     ffi::MachO_RPathCommand,
      67            0 :     ffi::MachO_Binary,
      68            0 :     ffi::MachO_Binary_it_rpaths
      69            0 : );
        

Generated by: LCOV version 2.1-1