Line data Source code
1 : use super::Command;
2 : use crate::common::FromFFI;
3 : use crate::to_slice;
4 : use lief_ffi as ffi;
5 :
6 : use std::marker::PhantomData;
7 :
8 : /// Structure which represents the `LC_TWOLEVEL_HINTS` command
9 : pub struct TwoLevelHints<'a> {
10 : ptr: cxx::UniquePtr<ffi::MachO_TwoLevelHints>,
11 : _owner: PhantomData<&'a ffi::MachO_Binary>,
12 : }
13 :
14 : impl TwoLevelHints<'_> {
15 : /// Offset of the command. It should point in the `__LINKEDIT` segment
16 26 : pub fn offset(&self) -> u32 {
17 26 : self.ptr.offset()
18 26 : }
19 13 : pub fn original_nb_hints(&self) -> u32 {
20 13 : self.ptr.original_nb_hints()
21 13 : }
22 :
23 : /// Original payload of the command
24 13 : pub fn content(&self) -> &[u8] {
25 13 : to_slice!(self.ptr.content());
26 13 : }
27 : }
28 :
29 : impl std::fmt::Debug for TwoLevelHints<'_> {
30 26 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31 26 : let base = self as &dyn Command;
32 26 : f.debug_struct("TwoLevelHints")
33 26 : .field("base", &base)
34 26 : .field("offset", &self.offset())
35 26 : .finish()
36 26 : }
37 : }
38 :
39 : impl FromFFI<ffi::MachO_TwoLevelHints> for TwoLevelHints<'_> {
40 26 : fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_TwoLevelHints>) -> Self {
41 26 : Self {
42 26 : ptr: cmd,
43 26 : _owner: PhantomData,
44 26 : }
45 26 : }
46 : }
47 :
48 : impl Command for TwoLevelHints<'_> {
49 104 : fn get_base(&self) -> &ffi::MachO_Command {
50 104 : self.ptr.as_ref().unwrap().as_ref()
51 104 : }
52 : }
|