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-11-30: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           60 :     pub fn entrypoint(&self) -> u64 {
      17           60 :         self.ptr.entrypoint()
      18           60 :     }
      19              : 
      20              :     /// The initial stack size
      21           60 :     pub fn stack_size(&self) -> u64 {
      22           60 :         self.ptr.stack_size()
      23           60 :     }
      24              : }
      25              : 
      26              : impl std::fmt::Debug for Main<'_> {
      27           60 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      28           60 :         let base = self as &dyn Command;
      29           60 :         f.debug_struct("Main")
      30           60 :             .field("base", &base)
      31           60 :             .field("entrypoint", &self.entrypoint())
      32           60 :             .field("stack_size", &self.stack_size())
      33           60 :             .finish()
      34           60 :     }
      35              : }
      36              : 
      37              : impl<'a> FromFFI<ffi::MachO_Main> for Main<'a> {
      38           60 :     fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_Main>) -> Self {
      39           60 :         Self {
      40           60 :             ptr: cmd,
      41           60 :             _owner: PhantomData,
      42           60 :         }
      43           60 :     }
      44              : }
      45              : 
      46              : impl Command for Main<'_> {
      47          240 :     fn get_base(&self) -> &ffi::MachO_Command {
      48          240 :         self.ptr.as_ref().unwrap().as_ref()
      49          240 :     }
      50              : }
        

Generated by: LCOV version 2.1-1