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 20 : pub fn value(&self) -> String {
17 20 : self.ptr.value().to_string()
18 20 : }
19 : }
20 :
21 : impl std::fmt::Debug for DyldEnvironment<'_> {
22 20 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23 20 : let base = self as &dyn Command;
24 20 : f.debug_struct("DyldEnvironment")
25 20 : .field("base", &base)
26 20 : .field("value", &self.value())
27 20 : .finish()
28 20 : }
29 : }
30 :
31 : impl FromFFI<ffi::MachO_DyldEnvironment> for DyldEnvironment<'_> {
32 20 : fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_DyldEnvironment>) -> Self {
33 20 : Self {
34 20 : ptr: cmd,
35 20 : _owner: PhantomData,
36 20 : }
37 20 : }
38 : }
39 :
40 : impl Command for DyldEnvironment<'_> {
41 80 : fn get_base(&self) -> &ffi::MachO_Command {
42 80 : self.ptr.as_ref().unwrap().as_ref()
43 80 : }
44 : }
|