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
use log::{debug, error, trace, warn};
pub struct Injector<'a> {
pub dll: &'a str,
pub pid: u32,
}
pub(crate) type Result<T> = std::result::Result<T, error::Error>;
pub mod error;
mod hof;
mod platforms;
impl<'a> Injector<'a> {
pub fn new(dll: &'a str, pid: u32) -> Self {
Injector { dll, pid }
}
pub fn set_dll(&mut self, dll: &'a str) {
self.dll = dll;
}
pub fn set_pid(&mut self, pid: u32) {
self.pid = pid;
}
}
impl<'a> Default for Injector<'a> {
fn default() -> Self {
Self::new("", 0)
}
}
pub fn strip_rust_path(str: &str) -> &str {
let mut str_no_path = str;
if let Some(n) = str.rfind('/') {
str_no_path = str.get((n + 1)..).unwrap();
}
debug!("str='{}' and truncated='{}'", str, str_no_path);
str_no_path
}
pub fn strip_win_path(str: &str) -> &str {
let mut str_no_path = str;
if let Some(n) = str.rfind('\\') {
str_no_path = str.get((n + 1)..).unwrap();
}
trace!("str='{}' and truncated='{}'", str, str_no_path);
str_no_path
}
pub fn trim_wide_str(mut v: Vec<u16>) -> Vec<u16> {
while v.last().map(|x| *x) == Some(0) {
v.pop();
}
return v;
}