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 304 : pub fn client(&self) -> String {
27 304 : self.ptr.client().to_string()
28 304 : }
29 : }
30 :
31 : impl std::fmt::Debug for SubClient<'_> {
32 304 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 304 : let base = self as &dyn Command;
34 304 : f.debug_struct("SubClient")
35 304 : .field("base", &base)
36 304 : .field("client", &self.client())
37 304 : .finish()
38 304 : }
39 : }
40 :
41 : impl FromFFI<ffi::MachO_SubClient> for SubClient<'_> {
42 304 : fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_SubClient>) -> Self {
43 304 : Self {
44 304 : ptr: cmd,
45 304 : _owner: PhantomData
46 304 : }
47 304 : }
48 : }
49 :
50 : impl Command for SubClient<'_> {
51 1216 : fn get_base(&self) -> &ffi::MachO_Command {
52 1216 : self.ptr.as_ref().unwrap().as_ref()
53 1216 : }
54 : }
55 :
56 152 : declare_iterator!(
57 152 : SubClients,
58 152 : SubClient<'a>,
59 152 : ffi::MachO_SubClient,
60 152 : ffi::MachO_Binary,
61 152 : ffi::MachO_Binary_it_sub_clients
62 152 : );
|