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 : /// Generic structure when the command is not recognized by LIEF (e.g private `LC_xxx` command)
8 : pub struct Unknown<'a> {
9 : ptr: cxx::UniquePtr<ffi::MachO_UnknownCommand>,
10 : _owner: PhantomData<&'a ffi::MachO_Binary>
11 : }
12 :
13 :
14 : impl Unknown<'_> {
15 : /// The original `LC_` int that is not supported by LIEF
16 80 : pub fn original_command(&self) -> u64 {
17 80 : self.ptr.original_command()
18 80 : }
19 : }
20 :
21 : impl std::fmt::Debug for Unknown<'_> {
22 40 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23 40 : let base = self as &dyn Command;
24 40 : f.debug_struct("UnknownCommand")
25 40 : .field("base", &base)
26 40 : .field("original_command", &self.original_command())
27 40 : .finish()
28 40 : }
29 : }
30 :
31 : impl FromFFI<ffi::MachO_UnknownCommand> for Unknown<'_> {
32 40 : fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_UnknownCommand>) -> Self {
33 40 : Self {
34 40 : ptr: cmd,
35 40 : _owner: PhantomData
36 40 : }
37 40 : }
38 : }
39 :
40 : impl Command for Unknown<'_> {
41 160 : fn get_base(&self) -> &ffi::MachO_Command {
42 160 : self.ptr.as_ref().unwrap().as_ref()
43 160 : }
44 : }
|