Line data Source code
1 : use super::Command;
2 : use crate::to_slice;
3 : use crate::common::FromFFI;
4 : use lief_ffi as ffi;
5 : use std::marker::PhantomData;
6 :
7 : /// Class that represent the `LC_NOTE` command.
8 : ///
9 : /// This command is used to include arbitrary notes or metadata within a binary.
10 : pub struct Note<'a> {
11 : ptr: cxx::UniquePtr<ffi::MachO_NoteCommand>,
12 : _owner: PhantomData<&'a ffi::MachO_Binary>,
13 : }
14 :
15 : impl Note<'_> {
16 : /// Offset of the data associated with this note
17 4320 : pub fn note_offset(&self) -> u64 {
18 4320 : self.ptr.note_offset()
19 4320 : }
20 :
21 : /// Size of the data referenced by the note_offset
22 4320 : pub fn note_size(&self) -> u64 {
23 4320 : self.ptr.note_size()
24 4320 : }
25 :
26 : /// Owner of the note (e.g. `AIR_METALLIB`)
27 4320 : pub fn owner(&self) -> &[u8] {
28 4320 : to_slice!(self.ptr.owner());
29 4320 : }
30 :
31 0 : pub fn set_note_offset(&mut self, offset: u64) {
32 0 : self.ptr.pin_mut().set_note_offset(offset);
33 0 : }
34 :
35 0 : pub fn set_note_size(&mut self, size: u64) {
36 0 : self.ptr.pin_mut().set_note_size(size);
37 0 : }
38 : }
39 :
40 : impl std::fmt::Debug for Note<'_> {
41 4320 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42 4320 : let base = self as &dyn Command;
43 4320 : f.debug_struct("Note")
44 4320 : .field("base", &base)
45 4320 : .field("note_offset", &self.note_offset())
46 4320 : .field("note_size", &self.note_size())
47 4320 : .field("owner", &self.owner())
48 4320 : .finish()
49 4320 : }
50 : }
51 :
52 : impl<'a> FromFFI<ffi::MachO_NoteCommand> for Note<'a> {
53 2880 : fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_NoteCommand>) -> Self {
54 2880 : Self {
55 2880 : ptr: cmd,
56 2880 : _owner: PhantomData,
57 2880 : }
58 2880 : }
59 : }
60 :
61 : impl Command for Note<'_> {
62 17280 : fn get_base(&self) -> &ffi::MachO_Command {
63 17280 : self.ptr.as_ref().unwrap().as_ref()
64 17280 : }
65 : }
|