LCOV - code coverage report
Current view: top level - src/pe - exception.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 84.6 % 26 22
Test Date: 2025-06-24:00:00:00 Functions: 60.0 % 5 3

            Line data    Source code
       1              : //! Module for the PE exception support
       2              : 
       3              : use lief_ffi as ffi;
       4              : use super::exception_x64;
       5              : use super::exception_aarch64;
       6              : 
       7              : use crate::common::FromFFI;
       8              : 
       9              : /// Enum that wraps the different kinds of runtime functions associated with exceptions
      10       925308 : #[derive(Debug)]
      11              : pub enum RuntimeExceptionFunction<'a> {
      12              :     /// An x86_64 exception entry
      13              :     X86_64(exception_x64::RuntimeFunction<'a>),
      14              : 
      15              :     /// An ARM64 exception entry
      16              :     AArch64(exception_aarch64::RuntimeFunction<'a>),
      17              : }
      18              : 
      19              : impl<'a> FromFFI<ffi::PE_ExceptionInfo> for RuntimeExceptionFunction<'a> {
      20       925308 :     fn from_ffi(ffi_entry: cxx::UniquePtr<ffi::PE_ExceptionInfo>) -> Self {
      21       925308 :         unsafe {
      22       925308 :             let obj_ref = ffi_entry.as_ref().unwrap();
      23       925308 :             if ffi::PE_RuntimeFunctionX64::classof(obj_ref) {
      24       642000 :                 let raw = {
      25       642000 :                     type From = cxx::UniquePtr<ffi::PE_ExceptionInfo>;
      26       642000 :                     type To = cxx::UniquePtr<ffi::PE_RuntimeFunctionX64>;
      27       642000 :                     std::mem::transmute::<From, To>(ffi_entry)
      28       642000 :                 };
      29       642000 :                 RuntimeExceptionFunction::X86_64(exception_x64::RuntimeFunction::from_ffi(raw))
      30       283308 :             } else if ffi::PE_RuntimeFunctionAArch64::classof(obj_ref) {
      31       283308 :                 let raw = {
      32       283308 :                     type From = cxx::UniquePtr<ffi::PE_ExceptionInfo>;
      33       283308 :                     type To = cxx::UniquePtr<ffi::PE_RuntimeFunctionAArch64>;
      34       283308 :                     std::mem::transmute::<From, To>(ffi_entry)
      35       283308 :                 };
      36       283308 :                 RuntimeExceptionFunction::AArch64(exception_aarch64::RuntimeFunction::from_ffi(raw))
      37              :             } else {
      38            0 :                 panic!("unsupported architecture");
      39              :             }
      40              :         }
      41       925308 :     }
      42              : }
      43              : 
      44              : /// Trait shared by all runtime functions
      45              : pub trait ExceptionInfo {
      46              :     #[doc(hidden)]
      47              :     fn as_generic(&self) -> &ffi::PE_ExceptionInfo;
      48              : 
      49              :     /// Function start address
      50       642000 :     fn rva_start(&self) -> u32 {
      51       642000 :         self.as_generic().rva_start()
      52       642000 :     }
      53              : }
      54              : 
      55              : impl std::fmt::Display for &dyn ExceptionInfo {
      56            0 :     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
      57            0 :         write!(f, "{}", self.as_generic().to_string())
      58            0 :     }
      59              : }
        

Generated by: LCOV version 2.1-1