Skip to main content

vmread/
win_dll.rs

1
2use crate::win_export::*;
3
4/// Represents a single Windows process module
5///
6/// Has basic information about the module in `info`, and a function to retrieve list of its exports.
7#[derive(Clone)]
8pub struct WinDll {
9    pub name: String,
10    pub info: sys::WinModule,
11    pub export_list: Vec<WinExport>
12}
13
14impl WinDll {
15    pub fn new(info: sys::WinModule) -> WinDll {
16        let mut ret = WinDll{
17            info: info,
18            name: unsafe { std::ffi::CStr::from_ptr(info.name).to_str().unwrap_or("").to_string() },
19            export_list: vec![],
20        };
21        
22        ret.info.name = std::ptr::null_mut::<i8>();
23
24        ret
25    }
26
27    /// Refresh the export list for the module
28    ///
29    /// # Arguments
30    ///
31    /// * `proc` - target process
32    /// * `ctx` - vmread C context
33    pub fn refresh_exports(&mut self, proc: &sys::WinProc, ctx: sys::WinCtx) -> &mut Self {
34        let mut c_list = sys::WinExportList {
35            list: std::ptr::null_mut(),
36            size: 0 as u64
37        };
38
39        unsafe {
40            sys::GenerateExportList(&ctx, proc, self.info.baseAddress, &mut c_list);
41        }
42
43        self.export_list.clear();
44        self.export_list.reserve(c_list.size as usize);
45
46        let lslice = unsafe { std::slice::from_raw_parts(c_list.list, c_list.size as usize) };
47
48        for i in lslice.iter() {
49            self.export_list.push(WinExport::new(*i));
50        }
51
52        unsafe {
53            sys::FreeExportList(c_list);
54        }
55
56        self
57    }
58
59}