Line data Source code
1 : use lief_ffi as ffi;
2 :
3 : use std::marker::PhantomData;
4 :
5 : use crate::DebugLocation;
6 : use crate::common::FromFFI;
7 : use crate::declare_fwd_iterator;
8 :
9 : pub struct Function<'a> {
10 : ptr: cxx::UniquePtr<ffi::PDB_Function>,
11 : _owner: PhantomData<&'a ()>,
12 : }
13 :
14 : impl FromFFI<ffi::PDB_Function> for Function<'_> {
15 0 : fn from_ffi(ptr: cxx::UniquePtr<ffi::PDB_Function>) -> Self {
16 0 : Self {
17 0 : ptr,
18 0 : _owner: PhantomData,
19 0 : }
20 0 : }
21 : }
22 :
23 : impl Function<'_> {
24 : /// The name of the function (this name is usually demangled)
25 0 : pub fn name(&self) -> String {
26 0 : self.ptr.name().to_string()
27 0 : }
28 :
29 : /// The **Relative** Virtual Address of the function
30 0 : pub fn rva(&self) -> u32 {
31 0 : self.ptr.RVA()
32 0 : }
33 :
34 : /// The size of the function
35 0 : pub fn code_size(&self) -> u32 {
36 0 : self.ptr.code_size()
37 0 : }
38 :
39 : /// The name of the section in which this function is defined
40 0 : pub fn section_name(&self) -> String {
41 0 : self.ptr.section_name().to_string()
42 0 : }
43 :
44 : /// Original source code location
45 0 : pub fn debug_location(&self) -> DebugLocation {
46 0 : DebugLocation::from_ffi(self.ptr.debug_location())
47 0 : }
48 : }
49 :
50 0 : declare_fwd_iterator!(
51 0 : Functions,
52 0 : Function<'a>,
53 0 : ffi::PDB_Function,
54 0 : ffi::PDB_CompilationUnit,
55 0 : ffi::PDB_CompilationUnit_it_functions
56 0 : );
|