cli: use memexec crate to execute raw bytes on Windows without spawning a process

This commit is contained in:
Brian Carroll 2022-08-24 21:36:49 +01:00
parent cc24186a10
commit 6038a5da0d
No known key found for this signature in database
GPG key ID: 9CF4E3BF9C4722C7
3 changed files with 15 additions and 13 deletions

View file

@ -919,20 +919,12 @@ impl ExecutableFile {
libc::execve(path_cstring.as_ptr().cast(), argv.as_ptr(), envp.as_ptr())
}
#[cfg(all(target_family = "windows"))]
#[cfg(target_family = "windows")]
ExecutableFile::OnDisk(_, path) => {
use std::process::Command;
let _ = argv;
let _ = envp;
let mut command = Command::new(path);
let output = command.output().unwrap();
println!("{}", String::from_utf8_lossy(&output.stdout));
std::process::exit(0)
use memexec::memexec_exe;
let bytes = std::fs::read(path).unwrap();
memexec_exe(&bytes).unwrap();
std::process::exit(0);
}
}
}