1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
use super::kernel::{FFIVirtualMemory, Kernel};
use memflow::iter::FnExtend;
use memflow_ffi::mem::virt_mem::VirtualMemoryObj;
use memflow_ffi::util::*;
use memflow_win32::win32::{self, Win32ModuleInfo, Win32ProcessInfo};
use std::ffi::CStr;
use std::os::raw::c_char;
pub type Win32Process = win32::Win32Process<FFIVirtualMemory>;
#[no_mangle]
pub unsafe extern "C" fn process_with_kernel(
kernel: &'static mut Kernel,
proc_info: &Win32ProcessInfo,
) -> &'static mut Win32Process {
let kernel = Box::from_raw(kernel);
to_heap(Win32Process::with_kernel(*kernel, proc_info.clone()))
}
#[no_mangle]
pub extern "C" fn process_virt_mem(
process: &'static mut Win32Process,
) -> &'static mut VirtualMemoryObj {
to_heap(&mut process.virt_mem)
}
#[no_mangle]
pub extern "C" fn process_clone(process: &Win32Process) -> &'static mut Win32Process {
to_heap((*process).clone())
}
#[no_mangle]
pub unsafe extern "C" fn process_free(process: &'static mut Win32Process) {
let _ = Box::from_raw(process);
}
#[no_mangle]
pub unsafe extern "C" fn process_module_list(
process: &mut Win32Process,
out: *mut &'static mut Win32ModuleInfo,
max_len: usize,
) -> usize {
let mut ret = 0;
let buffer = std::slice::from_raw_parts_mut(out, max_len);
let mut extend_fn = FnExtend::new(|info| {
if ret < max_len {
buffer[ret] = to_heap(info);
ret += 1;
}
});
process
.module_list_extend(&mut extend_fn)
.map_err(inspect_err)
.ok()
.map(|_| ret)
.unwrap_or_default()
}
#[no_mangle]
pub unsafe extern "C" fn process_main_module_info(
process: &mut Win32Process,
) -> Option<&'static mut Win32ModuleInfo> {
process
.main_module_info()
.map(to_heap)
.map_err(inspect_err)
.ok()
}
#[no_mangle]
pub unsafe extern "C" fn process_module_info(
process: &mut Win32Process,
name: *const c_char,
) -> Option<&'static mut Win32ModuleInfo> {
let name = CStr::from_ptr(name).to_string_lossy();
process
.module_info(&name)
.map(to_heap)
.map_err(inspect_err)
.ok()
}