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-03-21:00:00:00 Functions: 50.0 % 8 4

            Line data    Source code
       1              : use super::Command;
       2              : use lief_ffi as ffi;
       3              : use crate::common::FromFFI;
       4              : use crate::declare_iterator;
       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           36 :     pub fn path(&self) -> String {
      24           36 :         self.ptr.path().to_string()
      25           36 :     }
      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           36 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      40           36 :         let base = self as &dyn Command;
      41           36 :         f.debug_struct("RPath")
      42           36 :             .field("base", &base)
      43           36 :             .field("path", &self.path())
      44           36 :             .finish()
      45           36 :     }
      46              : }
      47              : 
      48              : impl FromFFI<ffi::MachO_RPathCommand> for RPath<'_> {
      49           36 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_RPathCommand>) -> Self {
      50           36 :         Self {
      51           36 :             ptr: cmd,
      52           36 :             _owner: PhantomData
      53           36 :         }
      54           36 :     }
      55              : }
      56              : 
      57              : impl Command for RPath<'_> {
      58          144 :     fn get_base(&self) -> &ffi::MachO_Command {
      59          144 :         self.ptr.as_ref().unwrap().as_ref()
      60          144 :     }
      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