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
use ;
use crate::;
/// A struct representing a running process.
/// This struct does **NOT** own the underlying process handle (see also [`OwnedProcess`](crate::OwnedProcess) for an owned version).
pub type BorrowedProcess<'a> = ;
unsafe
unsafe
/*
impl<'a> BorrowedProcess<'a> {
pub fn find_module_by_name(
&self,
module_name: impl AsRef<Path>,
) -> Result<Option<BorrowedProcessModule<'a>>, ProcessError> {
let target_module_name = module_name.as_ref();
// add default file extension if missing
let target_module_name = if target_module_name.extension().is_none() {
Cow::Owned(target_module_name.with_extension("dll").into_os_string())
} else {
Cow::Borrowed(target_module_name.as_os_str())
};
let modules = self.module_handles()?;
for module_handle in modules {
let module = unsafe { ProcessModule::new_unchecked(module_handle?, *self) };
let module_name = module.base_name_os()?;
if module_name.eq_ignore_ascii_case(&target_module_name) {
return Ok(Some(module));
}
}
Ok(None)
}
pub fn find_module_by_path(
&self,
module_path: impl AsRef<Path>,
) -> Result<Option<BorrowedProcessModule<'a>>, ProcessError> {
let target_module_path = module_path.as_ref();
// add default file extension if missing
let target_module_path = if target_module_path.extension().is_none() {
Cow::Owned(target_module_path.with_extension("dll").into_os_string())
} else {
Cow::Borrowed(target_module_path.as_os_str())
};
let target_module_handle = same_file::Handle::from_path(&target_module_path)?;
let modules = self.module_handles()?;
for module_handle in modules {
let module = unsafe { ProcessModule::new_unchecked(module_handle?, *self) };
let module_path = module.path()?.into_os_string();
match same_file::Handle::from_path(&module_path) {
Ok(module_handle) => {
if module_handle == target_module_handle {
return Ok(Some(module));
}
}
Err(_) => {
if target_module_path.eq_ignore_ascii_case(&module_path) {
return Ok(Some(module));
}
}
}
}
Ok(None)
}
pub fn wait_for_module_by_name(
&self,
module_name: impl AsRef<Path>,
timeout: Duration,
) -> Result<Option<BorrowedProcessModule<'a>>, ProcessError> {
retry_faillable_until_some_with_timeout(
|| self.find_module_by_name(module_name.as_ref()),
timeout,
)
}
pub fn wait_for_module_by_path(
&self,
module_path: impl AsRef<Path>,
timeout: Duration,
) -> Result<Option<BorrowedProcessModule<'a>>, ProcessError> {
retry_faillable_until_some_with_timeout(
|| self.find_module_by_path(module_path.as_ref()),
timeout,
)
}
}
*/