use std::path::PathBuf;
use ib_hook::{
inject::dll::app::{DllApp, DllInjectionVec},
process::Pid,
};
#[derive(serde::Serialize, serde::Deserialize)]
struct Input {
injector: Pid,
s: String,
}
struct MyDll;
impl DllApp for MyDll {
const APPLY: &str = "apply_hook";
type Input = Input;
type Output = ();
}
fn main() {
let dll_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.parent()
.unwrap()
.join("target")
.join("debug")
.join("examples")
.join("app_dll.dll");
let mut injections = DllInjectionVec::<MyDll>::new();
injections
.inject_with_process_name("Notepad.exe")
.dll_path(&dll_path)
.apply(&Input {
injector: Pid::current(),
s: "Hello, World!".into(),
})
.on_error(|pid, err| eprintln!("{pid:?}: {err:?}"))
.call()
.unwrap();
let leak = false;
if leak {
injections.leak();
} else {
injections
.eject()
.on_error(|pid, err| eprintln!("{pid:?}: {err:?}"))
.call();
}
}