Line data Source code
1 : use super::Command;
2 : use lief_ffi as ffi;
3 : use crate::common::FromFFI;
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 :
24 : impl SubFramework<'_> {
25 : /// Name of the umbrella framework
26 32 : pub fn umbrella(&self) -> String {
27 32 : self.ptr.umbrella().to_string()
28 32 : }
29 : }
30 :
31 : impl std::fmt::Debug for SubFramework<'_> {
32 32 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 32 : let base = self as &dyn Command;
34 32 : f.debug_struct("SubFramework")
35 32 : .field("base", &base)
36 32 : .field("umbrella", &self.umbrella())
37 32 : .finish()
38 32 : }
39 : }
40 :
41 : impl FromFFI<ffi::MachO_SubFramework> for SubFramework<'_> {
42 32 : fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_SubFramework>) -> Self {
43 32 : Self {
44 32 : ptr: cmd,
45 32 : _owner: PhantomData
46 32 : }
47 32 : }
48 : }
49 :
50 : impl Command for SubFramework<'_> {
51 128 : fn get_base(&self) -> &ffi::MachO_Command {
52 128 : self.ptr.as_ref().unwrap().as_ref()
53 128 : }
54 : }
55 :
|