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