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