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