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

            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              : use std::marker::PhantomData;
       6              : 
       7              : /// Structure which represents the `LC_FUNCTION_STARTS` command
       8              : ///
       9              : /// This command is an array of ULEB128 encoded values
      10              : pub struct FunctionStarts<'a> {
      11              :     ptr: cxx::UniquePtr<ffi::MachO_FunctionStarts>,
      12              :     _owner: PhantomData<&'a ffi::MachO_Binary>,
      13              : }
      14              : 
      15              : impl FunctionStarts<'_> {
      16              :     /// Offset in the ``__LINKEDIT`` segment where *start functions* are located
      17          192 :     pub fn data_offset(&self) -> u32 {
      18          192 :         self.ptr.data_offset()
      19          192 :     }
      20              : 
      21              :     /// Size of the functions list in the binary
      22          192 :     pub fn data_size(&self) -> u32 {
      23          192 :         self.ptr.data_size()
      24          192 :     }
      25              : 
      26              :     /// Addresses of every function entry point in the executable.
      27              :     ///
      28              :     /// This allows functions to exist for which there are no entries in the symbol table.
      29              :     ///
      30              :     /// <div class="warning">
      31              :     /// The address is relative to the __TEXT segment
      32              :     /// </div>
      33           96 :     pub fn functions(&self) -> Vec<u64> {
      34           96 :         Vec::from(self.ptr.functions().as_slice())
      35           96 :     }
      36              : 
      37              :     /// Raw payload as a slice of bytes
      38           96 :     pub fn content(&self) -> &[u8] {
      39           96 :         to_slice!(self.ptr.content());
      40           96 :     }
      41              : }
      42              : 
      43              : impl std::fmt::Debug for FunctionStarts<'_> {
      44          192 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      45          192 :         let base = self as &dyn Command;
      46          192 :         f.debug_struct("FunctionStarts")
      47          192 :             .field("base", &base)
      48          192 :             .field("data_offset", &self.data_offset())
      49          192 :             .field("data_size", &self.data_size())
      50          192 :             .finish()
      51          192 :     }
      52              : }
      53              : 
      54              : impl FromFFI<ffi::MachO_FunctionStarts> for FunctionStarts<'_> {
      55          192 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_FunctionStarts>) -> Self {
      56          192 :         Self {
      57          192 :             ptr: cmd,
      58          192 :             _owner: PhantomData,
      59          192 :         }
      60          192 :     }
      61              : }
      62              : 
      63              : impl Command for FunctionStarts<'_> {
      64          768 :     fn get_base(&self) -> &ffi::MachO_Command {
      65          768 :         self.ptr.as_ref().unwrap().as_ref()
      66          768 :     }
      67              : }
        

Generated by: LCOV version 2.1-1