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