Line data Source code
1 : use super::Command;
2 : use crate::common::FromFFI;
3 : use lief_ffi as ffi;
4 :
5 : use std::marker::PhantomData;
6 :
7 : /// Class that represents the SubFramework command.
8 : /// Accodring to the Mach-O ``loader.h`` documentation:
9 : ///
10 : /// > A dynamically linked shared library may be a subframework of an umbrella
11 : /// > framework. If so it will be linked with "-umbrella umbrella_name" where
12 : /// > Where "umbrella_name" is the name of the umbrella framework. A subframework
13 : /// > can only be linked against by its umbrella framework or other subframeworks
14 : /// > that are part of the same umbrella framework. Otherwise the static link
15 : /// > editor produces an error and states to link against the umbrella framework.
16 : /// > The name of the umbrella framework for subframeworks is recorded in the
17 : /// > following structure.
18 : pub struct SubFramework<'a> {
19 : ptr: cxx::UniquePtr<ffi::MachO_SubFramework>,
20 : _owner: PhantomData<&'a ffi::MachO_Binary>,
21 : }
22 :
23 : impl SubFramework<'_> {
24 : /// Name of the umbrella framework
25 52 : pub fn umbrella(&self) -> String {
26 52 : self.ptr.umbrella().to_string()
27 52 : }
28 : }
29 :
30 : impl std::fmt::Debug for SubFramework<'_> {
31 52 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32 52 : let base = self as &dyn Command;
33 52 : f.debug_struct("SubFramework")
34 52 : .field("base", &base)
35 52 : .field("umbrella", &self.umbrella())
36 52 : .finish()
37 52 : }
38 : }
39 :
40 : impl FromFFI<ffi::MachO_SubFramework> for SubFramework<'_> {
41 52 : fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_SubFramework>) -> Self {
42 52 : Self {
43 52 : ptr: cmd,
44 52 : _owner: PhantomData,
45 52 : }
46 52 : }
47 : }
48 :
49 : impl Command for SubFramework<'_> {
50 208 : fn get_base(&self) -> &ffi::MachO_Command {
51 208 : self.ptr.as_ref().unwrap().as_ref()
52 208 : }
53 : }
|