LCOV - code coverage report
Current view: top level - src/macho/commands - symbol_command.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 100.0 % 43 43
Test Date: 2024-10-27:00:00:00 Functions: 100.0 % 11 11

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

Generated by: LCOV version 2.1-1