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 that represents the `LC_SYMTAB` command
9 : pub struct SymbolCommand<'a> {
10 : ptr: cxx::UniquePtr<ffi::MachO_SymbolCommand>,
11 : _owner: PhantomData<&'a ffi::MachO_Binary>,
12 : }
13 :
14 : impl SymbolCommand<'_> {
15 : /// Offset from the start of the file to the n_list associated with the command
16 416 : pub fn symbol_offset(&self) -> u32 {
17 416 : self.ptr.symbol_offset()
18 416 : }
19 :
20 : /// Number of symbols registered
21 416 : pub fn numberof_symbols(&self) -> u32 {
22 416 : self.ptr.numberof_symbols()
23 416 : }
24 :
25 : /// Offset from the start of the file to the string table
26 416 : pub fn strings_offset(&self) -> u32 {
27 416 : self.ptr.strings_offset()
28 416 : }
29 :
30 : /// Size of the size string table
31 416 : pub fn strings_size(&self) -> u32 {
32 416 : self.ptr.strings_size()
33 416 : }
34 :
35 208 : pub fn original_str_size(&self) -> u32 {
36 208 : self.ptr.original_str_size()
37 208 : }
38 :
39 208 : pub fn original_nb_symbols(&self) -> u32 {
40 208 : self.ptr.original_nb_symbols()
41 208 : }
42 :
43 208 : pub fn symbol_table(&self) -> &[u8] {
44 208 : to_slice!(self.ptr.symbol_table());
45 208 : }
46 :
47 208 : pub fn string_table(&self) -> &[u8] {
48 208 : to_slice!(self.ptr.string_table());
49 208 : }
50 : }
51 :
52 : impl std::fmt::Debug for SymbolCommand<'_> {
53 416 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54 416 : let base = self as &dyn Command;
55 416 : f.debug_struct("SymbolCommand")
56 416 : .field("base", &base)
57 416 : .field("symbol_offset", &self.symbol_offset())
58 416 : .field("numberof_symbols", &self.numberof_symbols())
59 416 : .field("strings_offset", &self.strings_offset())
60 416 : .field("strings_size", &self.strings_size())
61 416 : .finish()
62 416 : }
63 : }
64 :
65 : impl FromFFI<ffi::MachO_SymbolCommand> for SymbolCommand<'_> {
66 416 : fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_SymbolCommand>) -> Self {
67 416 : Self {
68 416 : ptr: cmd,
69 416 : _owner: PhantomData,
70 416 : }
71 416 : }
72 : }
73 :
74 : impl Command for SymbolCommand<'_> {
75 1664 : fn get_base(&self) -> &ffi::MachO_Command {
76 1664 : self.ptr.as_ref().unwrap().as_ref()
77 1664 : }
78 : }
|