Line data Source code
1 : //! This module wraps a PDB public symbol (stream number `n+5`)
2 :
3 : use lief_ffi as ffi;
4 :
5 : use std::marker::PhantomData;
6 :
7 : use crate::common::FromFFI;
8 : use crate::declare_fwd_iterator;
9 :
10 : /// This class provides general information (RVA, name) about a symbol
11 : /// from the PDB's public symbol stream (or Public symbol hash stream)
12 : pub struct PublicSymbol<'a> {
13 : ptr: cxx::UniquePtr<ffi::PDB_PublicSymbol>,
14 : _owner: PhantomData<&'a ()>,
15 : }
16 :
17 :
18 : impl FromFFI<ffi::PDB_PublicSymbol> for PublicSymbol<'_> {
19 0 : fn from_ffi(ptr: cxx::UniquePtr<ffi::PDB_PublicSymbol>) -> Self {
20 0 : Self {
21 0 : ptr,
22 0 : _owner: PhantomData,
23 0 : }
24 0 : }
25 : }
26 :
27 : impl PublicSymbol<'_> {
28 : /// Name of the symbol
29 0 : pub fn name(&self) -> String {
30 0 : self.ptr.name().to_string()
31 0 : }
32 :
33 : /// Demangled representation of the symbol
34 0 : pub fn demangled_name(&self) -> String {
35 0 : self.ptr.name().to_string()
36 0 : }
37 :
38 : /// Name of the section in which this symbol is defined (e.g. `.text`).
39 0 : pub fn section_name(&self) -> Option<String> {
40 0 : let name = self.ptr.section_name().to_string();
41 0 : if !name.is_empty() {
42 0 : Some(name)
43 : } else {
44 0 : None
45 : }
46 0 : }
47 :
48 : /// **Relative** Virtual Address of this symbol.
49 : ///
50 : /// This function returns 0 if the RVA can't be computed.
51 0 : pub fn rva(&self) -> u32 {
52 0 : self.ptr.RVA()
53 0 : }
54 : }
55 :
56 : impl std::fmt::Display for PublicSymbol<'_> {
57 0 : fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
58 0 : write!(f, "{}", self.ptr.to_string())
59 0 : }
60 : }
61 :
62 0 : declare_fwd_iterator!(
63 0 : PublicSymbols,
64 0 : PublicSymbol<'a>,
65 0 : ffi::PDB_PublicSymbol,
66 0 : ffi::PDB_DebugInfo,
67 0 : ffi::PDB_DebugInfo_it_public_symbols
68 0 : );
|