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