LCOV - code coverage report
Current view: top level - src/macho/commands - functionstarts.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 90.6 % 32 29
Test Date: 2026-04-12:00:00:00 Functions: 87.5 % 8 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          364 :     pub fn data_offset(&self) -> u32 {
      18          364 :         self.ptr.data_offset()
      19          364 :     }
      20              : 
      21              :     /// Size of the functions list in the binary
      22          364 :     pub fn data_size(&self) -> u32 {
      23          364 :         self.ptr.data_size()
      24          364 :     }
      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          182 :     pub fn functions(&self) -> Vec<u64> {
      34          182 :         Vec::from(self.ptr.functions().as_slice())
      35          182 :     }
      36              : 
      37              :     /// Raw payload as a slice of bytes
      38          182 :     pub fn content(&self) -> &[u8] {
      39          182 :         to_slice!(self.ptr.content());
      40          182 :     }
      41              : 
      42              :     /// Add a function address to the list of function starts
      43            0 :     pub fn add_function(&mut self, address: u64) {
      44            0 :         self.ptr.pin_mut().add_function(address);
      45            0 :     }
      46              : }
      47              : 
      48              : impl std::fmt::Debug for FunctionStarts<'_> {
      49          364 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      50          364 :         let base = self as &dyn Command;
      51          364 :         f.debug_struct("FunctionStarts")
      52          364 :             .field("base", &base)
      53          364 :             .field("data_offset", &self.data_offset())
      54          364 :             .field("data_size", &self.data_size())
      55          364 :             .finish()
      56          364 :     }
      57              : }
      58              : 
      59              : impl FromFFI<ffi::MachO_FunctionStarts> for FunctionStarts<'_> {
      60          364 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_FunctionStarts>) -> Self {
      61          364 :         Self {
      62          364 :             ptr: cmd,
      63          364 :             _owner: PhantomData,
      64          364 :         }
      65          364 :     }
      66              : }
      67              : 
      68              : impl Command for FunctionStarts<'_> {
      69         1456 :     fn get_base(&self) -> &ffi::MachO_Command {
      70         1456 :         self.ptr.as_ref().unwrap().as_ref()
      71         1456 :     }
      72              : }
        

Generated by: LCOV version 2.1-1