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
use log::{debug, trace, warn};
use std::path::PathBuf;
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 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_path(dll: &str) -> Result<String> {
let pb = PathBuf::from(dll);
match pb.file_name().and_then(|x| x.to_str()) {
None => Err(error::Error::Io(std::io::Error::from(
std::io::ErrorKind::Unsupported,
))),
Some(v) => Ok(v.to_string()),
}
}
pub fn trim_wide_str(mut v: Vec<u16>) -> Vec<u16> {
while v.last().map(|x| *x) == Some(0) {
v.pop();
}
return v;
}