Line data Source code
1 : use super::Command;
2 : use crate::common::FromFFI;
3 : use lief_ffi as ffi;
4 : use std::marker::PhantomData;
5 :
6 : /// Structure that represents the Mach-O linker, also named loader.
7 : /// Most of the time, [`Dylinker::name`] should return `/usr/lib/dyld`
8 : pub struct Dylinker<'a> {
9 : ptr: cxx::UniquePtr<ffi::MachO_Dylinker>,
10 : _owner: PhantomData<&'a ffi::MachO_Binary>,
11 : }
12 :
13 : impl std::fmt::Debug for Dylinker<'_> {
14 96 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15 96 : let base = self as &dyn Command;
16 96 : f.debug_struct("Dylinker")
17 96 : .field("base", &base)
18 96 : .field("name", &self.name())
19 96 : .finish()
20 96 : }
21 : }
22 :
23 : impl Dylinker<'_> {
24 : /// Path to the linker (or loader)
25 96 : pub fn name(&self) -> String {
26 96 : self.ptr.name().to_string()
27 96 : }
28 : }
29 :
30 : impl FromFFI<ffi::MachO_Dylinker> for Dylinker<'_> {
31 96 : fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_Dylinker>) -> Self {
32 96 : Self {
33 96 : ptr: cmd,
34 96 : _owner: PhantomData,
35 96 : }
36 96 : }
37 : }
38 :
39 : impl Command for Dylinker<'_> {
40 384 : fn get_base(&self) -> &ffi::MachO_Command {
41 384 : self.ptr.as_ref().unwrap().as_ref()
42 384 : }
43 : }
|