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

            Line data    Source code
       1              : use super::Command;
       2              : use crate::common::FromFFI;
       3              : use lief_ffi as ffi;
       4              : use std::marker::PhantomData;
       5              : 
       6              : /// Structure that represent the `LC_MAIN` command. This kind of command can be used to determine the
       7              : /// entrypoint of an executable.
       8              : pub struct Main<'a> {
       9              :     ptr: cxx::UniquePtr<ffi::MachO_Main>,
      10              :     _owner: PhantomData<&'a ffi::MachO_Binary>,
      11              : }
      12              : 
      13              : impl Main<'_> {
      14              :     /// Offset of the *main* function **relative** to the `__TEXT`
      15              :     /// segment
      16           48 :     pub fn entrypoint(&self) -> u64 {
      17           48 :         self.ptr.entrypoint()
      18           48 :     }
      19              : 
      20              :     /// The initial stack size
      21           48 :     pub fn stack_size(&self) -> u64 {
      22           48 :         self.ptr.stack_size()
      23           48 :     }
      24              : }
      25              : 
      26              : impl std::fmt::Debug for Main<'_> {
      27           48 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      28           48 :         let base = self as &dyn Command;
      29           48 :         f.debug_struct("Main")
      30           48 :             .field("base", &base)
      31           48 :             .field("entrypoint", &self.entrypoint())
      32           48 :             .field("stack_size", &self.stack_size())
      33           48 :             .finish()
      34           48 :     }
      35              : }
      36              : 
      37              : impl<'a> FromFFI<ffi::MachO_Main> for Main<'a> {
      38           48 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_Main>) -> Self {
      39           48 :         Self {
      40           48 :             ptr: cmd,
      41           48 :             _owner: PhantomData,
      42           48 :         }
      43           48 :     }
      44              : }
      45              : 
      46              : impl Command for Main<'_> {
      47          192 :     fn get_base(&self) -> &ffi::MachO_Command {
      48          192 :         self.ptr.as_ref().unwrap().as_ref()
      49          192 :     }
      50              : }
        

Generated by: LCOV version 2.1-1