Line data Source code
1 : use super::Command;
2 : use crate::common::FromFFI;
3 : use crate::declare_iterator;
4 : use lief_ffi as ffi;
5 :
6 : use std::marker::PhantomData;
7 :
8 : /// Class that represents the SubClient command.
9 : /// Accodring to the Mach-O `loader.h` documentation:
10 : ///
11 : /// > For dynamically linked shared libraries that are subframework of an umbrella
12 : /// > framework they can allow clients other than the umbrella framework or other
13 : /// > subframeworks in the same umbrella framework. To do this the subframework
14 : /// > is built with "-allowable_client client_name" and an LC_SUB_CLIENT load
15 : /// > command is created for each -allowable_client flag. The client_name is
16 : /// > usually a framework name. It can also be a name used for bundles clients
17 : /// > where the bundle is built with "-client_name client_name".
18 : pub struct SubClient<'a> {
19 : ptr: cxx::UniquePtr<ffi::MachO_SubClient>,
20 : _owner: PhantomData<&'a ffi::MachO_Binary>,
21 : }
22 :
23 : impl SubClient<'_> {
24 : /// Name of the subclient
25 494 : pub fn client(&self) -> String {
26 494 : self.ptr.client().to_string()
27 494 : }
28 : }
29 :
30 : impl std::fmt::Debug for SubClient<'_> {
31 494 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32 494 : let base = self as &dyn Command;
33 494 : f.debug_struct("SubClient")
34 494 : .field("base", &base)
35 494 : .field("client", &self.client())
36 494 : .finish()
37 494 : }
38 : }
39 :
40 : impl FromFFI<ffi::MachO_SubClient> for SubClient<'_> {
41 494 : fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_SubClient>) -> Self {
42 494 : Self {
43 494 : ptr: cmd,
44 494 : _owner: PhantomData,
45 494 : }
46 494 : }
47 : }
48 :
49 : impl Command for SubClient<'_> {
50 1976 : fn get_base(&self) -> &ffi::MachO_Command {
51 1976 : self.ptr.as_ref().unwrap().as_ref()
52 1976 : }
53 : }
54 :
55 247 : declare_iterator!(
56 247 : SubClients,
57 247 : SubClient<'a>,
58 247 : ffi::MachO_SubClient,
59 247 : ffi::MachO_Binary,
60 247 : ffi::MachO_Binary_it_sub_clients
61 247 : );
|