Line data Source code
1 : use super::Command;
2 : use lief_ffi as ffi;
3 : use crate::common::FromFFI;
4 : use crate::to_slice;
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 16 : pub fn offset(&self) -> u32 {
17 16 : self.ptr.offset()
18 16 : }
19 8 : pub fn original_nb_hints(&self) -> u32 {
20 8 : self.ptr.original_nb_hints()
21 8 : }
22 :
23 : /// Original payload of the command
24 8 : pub fn content(&self) -> &[u8] {
25 8 : to_slice!(self.ptr.content());
26 8 : }
27 : }
28 :
29 : impl std::fmt::Debug for TwoLevelHints<'_> {
30 16 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31 16 : let base = self as &dyn Command;
32 16 : f.debug_struct("TwoLevelHints")
33 16 : .field("base", &base)
34 16 : .field("offset", &self.offset())
35 16 : .finish()
36 16 : }
37 : }
38 :
39 : impl FromFFI<ffi::MachO_TwoLevelHints> for TwoLevelHints<'_> {
40 16 : fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_TwoLevelHints>) -> Self {
41 16 : Self {
42 16 : ptr: cmd,
43 16 : _owner: PhantomData
44 16 : }
45 16 : }
46 : }
47 :
48 : impl Command for TwoLevelHints<'_> {
49 64 : fn get_base(&self) -> &ffi::MachO_Command {
50 64 : self.ptr.as_ref().unwrap().as_ref()
51 64 : }
52 : }
53 :
|