Skip to content

Commit

Permalink
🍎 Simply supported macOS hijacking
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve-xmh committed Mar 3, 2024
1 parent c504e2f commit afe1ada
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
30 changes: 24 additions & 6 deletions crates/launcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub fn default_lib_filename<'a>() -> Result<&'a str, Box<dyn Error>> {

#[cfg(target_os = "macos")]
{
// TODO: not sure
Ok("libv8_killer_core.dylib")
}

Expand All @@ -25,7 +24,7 @@ pub fn default_lib_filename<'a>() -> Result<&'a str, Box<dyn Error>> {
}

#[cfg(target_os = "linux")]
pub fn launch(lib_path: &str, executable: &str, args: &[String]) {
pub fn launch(lib_path: &str, executable: &str, args: &[&str]) {
use std::process::Command;
use std::process::ExitStatus;
use std::process::Stdio;
Expand All @@ -49,7 +48,7 @@ pub fn launch(lib_path: &str, executable: &str, args: &[String]) {
}

#[cfg(target_os = "windows")]
pub fn launch(lib_path: &str, executable: &str, args: &[String]) {
pub fn launch(lib_path: &str, executable: &str, args: &[&str]) {
use std::ffi::c_void;
use windows::core::PWSTR;
use windows::core::{s, w};
Expand Down Expand Up @@ -162,12 +161,31 @@ pub fn launch(lib_path: &str, executable: &str, args: &[String]) {
}

#[cfg(target_os = "macos")]
pub fn launch(lib_path: &str, exe_cmdline: &str) {
eprintln!("macOS is not supported yet.");
pub fn launch(lib_path: &str, executable: &str, args: &[&str]) {
use std::process::Command;
use std::process::ExitStatus;
use std::process::Stdio;

let mut child = Command::new(executable)
.args(args)
.env("DYLD_INSERT_LIBRARIES", lib_path)
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()
.expect("Failed to start command");

let status: ExitStatus = child.wait().expect("Failed to wait for child process");

if status.success() {
println!("Command executed successfully");
} else {
println!("Command failed with exit code: {:?}", status.code());
}
}

// 非以上系统
#[cfg(not(any(target_os = "linux", target_os = "windows", target_os = "macos")))]
pub fn launch(lib_path: &str, exe_cmdline: &str) {
pub fn launch(lib_path: &str, executable: &str, args: &[&str]) {
eprintln!("Unsupported platform.");
}
3 changes: 2 additions & 1 deletion crates/launcher/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ fn main() {
let lib_path_str = lib_path.to_str().unwrap();

let exe = std::env::args().nth(1).expect("no executable provided");
let args = std::env::args().skip(2).collect::<Vec<String>>();
let args = std::env::args().skip(2).collect::<Vec<_>>();
let args = args.iter().map(|s| s.as_str()).collect::<Vec<_>>();

println!("[*] Executable: {}", exe);
println!("[*] Args: {:?}", args);
Expand Down

0 comments on commit afe1ada

Please sign in to comment.