LCOV - code coverage report
Current view: top level - src - generic.rs (source / functions) Coverage Total Hit
Test: lief.lcov Lines: 91.3 % 69 63
Test Date: 2024-10-27:00:00:00 Functions: 67.2 % 61 41

            Line data    Source code
       1              : use lief_ffi as ffi;
       2              : use crate::to_slice;
       3              : use crate::common::into_optional;
       4              : 
       5              : /// Trait shared by all the symbols in executable formats
       6              : pub trait Symbol {
       7              :     #[doc(hidden)]
       8              :     fn as_generic(&self) -> &ffi::AbstractSymbol;
       9              : 
      10              :     /// Symbol's name
      11       394968 :     fn name(&self) -> String {
      12       394968 :         self.as_generic().name().to_string()
      13       394968 :     }
      14              :     /// Symbol's value whose interpretation depends on the symbol's kind.
      15              :     /// Usually this is the address of the symbol though.
      16       361304 :     fn value(&self) -> u64 {
      17       361304 :         self.as_generic().value()
      18       361304 :     }
      19              :     /// Size of the symbol (can be 0)
      20       361304 :     fn size(&self) -> u64 {
      21       361304 :         self.as_generic().size()
      22       361304 :     }
      23              : }
      24              : 
      25              : impl std::fmt::Debug for &dyn Symbol {
      26       355088 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      27       355088 :         f.debug_struct("Symbol")
      28       355088 :             .field("name", &self.name())
      29       355088 :             .field("value", &self.value())
      30       355088 :             .field("size", &self.size())
      31       355088 :             .finish()
      32       355088 :     }
      33              : }
      34              : 
      35              : /// Trait shared by all the sections in executable formats
      36              : pub trait Section {
      37              :     #[doc(hidden)]
      38              :     fn as_generic(&self) -> &ffi::AbstractSection;
      39              : 
      40              :     /// Name of the section
      41       183344 :     fn name(&self) -> String {
      42       183344 :         self.as_generic().name().to_string()
      43       183344 :     }
      44              : 
      45              :     /// Size of the section **in the file**
      46       181808 :     fn size(&self) -> u64 {
      47       181808 :         self.as_generic().size()
      48       181808 :     }
      49              : 
      50              :     /// Offset of the section **in the file**
      51       181752 :     fn offset(&self) -> u64 {
      52       181752 :         self.as_generic().offset()
      53       181752 :     }
      54              : 
      55              :     /// Address of the section **in memory**
      56       181752 :     fn virtual_address(&self) -> u64 {
      57       181752 :         self.as_generic().virtual_address()
      58       181752 :     }
      59              : 
      60              :     /// Content of the section
      61            0 :     fn content(&self) -> &[u8] {
      62            0 :         to_slice!(self.as_generic().content());
      63            0 :     }
      64              : }
      65              : 
      66              : impl std::fmt::Debug for &dyn Section {
      67       180160 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      68       180160 :         f.debug_struct("Section")
      69       180160 :             .field("name", &self.name())
      70       180160 :             .field("size", &self.size())
      71       180160 :             .field("offset", &self.offset())
      72       180160 :             .field("virtual_address", &self.virtual_address())
      73       180160 :             .finish()
      74       180160 :     }
      75              : }
      76              : 
      77              : pub trait Relocation {
      78              :     #[doc(hidden)]
      79              :     fn as_generic(&self) -> &ffi::AbstractRelocation;
      80              : 
      81              :     /// Address where the relocation should take place
      82      1137184 :     fn address(&self) -> u64 {
      83      1137184 :         self.as_generic().address()
      84      1137184 :     }
      85              : 
      86              :     /// Size of the relocation
      87      1137184 :     fn size(&self) -> u64 {
      88      1137184 :         self.as_generic().size()
      89      1137184 :     }
      90              : }
      91              : 
      92              : impl std::fmt::Debug for &dyn Relocation {
      93      1137184 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      94      1137184 :         f.debug_struct("Relocation")
      95      1137184 :             .field("address", &self.address())
      96      1137184 :             .field("size", &self.size())
      97      1137184 :             .finish()
      98      1137184 :     }
      99              : }
     100              : 
     101              : pub trait Binary {
     102              :     #[doc(hidden)]
     103              :     fn as_generic(&self) -> &ffi::AbstractBinary;
     104              : 
     105              :     /// Binary's entrypoint
     106           30 :     fn entrypoint(&self) -> u64 {
     107           30 :         self.as_generic().entrypoint()
     108           30 :     }
     109              : 
     110              :     /// Default base address where the binary should be mapped
     111            8 :     fn imagebase(&self) -> u64 {
     112            8 :         self.as_generic().imagebase()
     113            8 :     }
     114              : 
     115              :     /// Whether the current binary is **an executable** and **position independent**
     116            8 :     fn is_pie(&self) -> bool {
     117            8 :         self.as_generic().is_pie()
     118            8 :     }
     119              : 
     120              :     /// Whether the binary defines a non-executable stack
     121            8 :     fn has_nx(&self) -> bool {
     122            8 :         self.as_generic().has_nx()
     123            8 :     }
     124              : 
     125              :     /// Original file size of the binary
     126            8 :     fn original_size(&self) -> u64 {
     127            8 :         self.as_generic().original_size()
     128            8 :     }
     129              : 
     130              :     /// Return the debug info if present. It can be either a
     131              :     /// [`crate::pdb::DebugInfo`] or [`crate::dwarf::DebugInfo`].
     132              :     ///
     133              :     /// For ELF and Mach-O binaries, it returns the given DebugInfo object **only**
     134              :     /// if the binary embeds the DWARF debug info in the binary itself.
     135              :     ///
     136              :     /// For PE file, this function tries to find the **external** PDB using
     137              :     /// the [`crate::pe::debug::CodeViewPDB::filename`] output (if present). One can also
     138              :     /// use [`crate::pdb::load`] or [`crate::pdb::DebugInfo::from`] to get PDB debug
     139              :     /// info.
     140              :     ///
     141              :     /// <div class="warning">
     142              :     /// This function requires LIEF's extended version otherwise it **always** return `None`
     143              :     /// </div>
     144            0 :     fn debug_info(&self) -> Option<crate::DebugInfo> {
     145            0 :         into_optional(self.as_generic().debug_info())
     146            0 :     }
     147              : 
     148              : 
     149              : }
     150              : 
     151              : pub trait DebugInfo {
     152              :     #[doc(hidden)]
     153              :     fn as_generic(&self) -> &ffi::AbstracDebugInfo;
     154              : }
        

Generated by: LCOV version 2.1-1