Line data Source code
1 : use super::Command;
2 : use lief_ffi as ffi;
3 :
4 : use crate::common::FromFFI;
5 : use std::marker::PhantomData;
6 :
7 : /// Structure that represents a `LC_DYLD_ENVIRONMENT` command which is
8 : /// used by the Mach-O linker/loader to initialize an environment variable
9 : pub struct DyldEnvironment<'a> {
10 : ptr: cxx::UniquePtr<ffi::MachO_DyldEnvironment>,
11 : _owner: PhantomData<&'a ffi::MachO_Binary>,
12 : }
13 :
14 : impl DyldEnvironment<'_> {
15 : /// The actual environment variable
16 24 : pub fn value(&self) -> String {
17 24 : self.ptr.value().to_string()
18 24 : }
19 : }
20 :
21 : impl std::fmt::Debug for DyldEnvironment<'_> {
22 24 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23 24 : let base = self as &dyn Command;
24 24 : f.debug_struct("DyldEnvironment")
25 24 : .field("base", &base)
26 24 : .field("value", &self.value())
27 24 : .finish()
28 24 : }
29 : }
30 :
31 : impl FromFFI<ffi::MachO_DyldEnvironment> for DyldEnvironment<'_> {
32 24 : fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_DyldEnvironment>) -> Self {
33 24 : Self {
34 24 : ptr: cmd,
35 24 : _owner: PhantomData,
36 24 : }
37 24 : }
38 : }
39 :
40 : impl Command for DyldEnvironment<'_> {
41 96 : fn get_base(&self) -> &ffi::MachO_Command {
42 96 : self.ptr.as_ref().unwrap().as_ref()
43 96 : }
44 : }
|