From 3d5487d8a0cd0db8c0de566af1bb87e1db6980a6 Mon Sep 17 00:00:00 2001 From: Steve-xmh <39523898+Steve-xmh@users.noreply.github.com> Date: Sun, 3 Mar 2024 12:31:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=8D=8E=20Simply=20supported=20macOS?= =?UTF-8?q?=20hijacking?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/launcher/src/lib.rs | 30 ++++++++++++++++++++++++------ crates/launcher/src/main.rs | 3 ++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/crates/launcher/src/lib.rs b/crates/launcher/src/lib.rs index 9f3cb56..4f46eec 100644 --- a/crates/launcher/src/lib.rs +++ b/crates/launcher/src/lib.rs @@ -13,7 +13,6 @@ pub fn default_lib_filename<'a>() -> Result<&'a str, Box> { #[cfg(target_os = "macos")] { - // TODO: not sure Ok("libv8_killer_core.dylib") } @@ -25,7 +24,7 @@ pub fn default_lib_filename<'a>() -> Result<&'a str, Box> { } #[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; @@ -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}; @@ -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."); } diff --git a/crates/launcher/src/main.rs b/crates/launcher/src/main.rs index 43f4f06..48bba72 100644 --- a/crates/launcher/src/main.rs +++ b/crates/launcher/src/main.rs @@ -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::>(); + let args = std::env::args().skip(2).collect::>(); + let args = args.iter().map(|s| s.as_str()).collect::>(); println!("[*] Executable: {}", exe); println!("[*] Args: {:?}", args); From 411b4a912c59ff68614884567accd6c0aaf5e6bd Mon Sep 17 00:00:00 2001 From: Steve-xmh <39523898+Steve-xmh@users.noreply.github.com> Date: Sun, 3 Mar 2024 15:00:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8D=8E=20Set=20up=20build=20action=20?= =?UTF-8?q?for=20macOS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yaml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 095d3ff..dd6fee8 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -8,12 +8,24 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ ubuntu-latest, windows-latest ] + os: [ ubuntu-latest, windows-latest, macos-latest ] steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - - name: Build + - name: Build for Windows/Linux + if: matrix.os == 'ubuntu-latest' || matrix.os == 'windows-latest' run: cargo build --verbose --release + - name: Build for macOS + if: matrix.os == 'macos-latest' + run: | + rustup target add aarch64-apple-darwin x86_64-apple-darwin + cargo build --verbose --release --target aarch64-apple-darwin + cargo build --verbose --release --target x86_64-apple-darwin + lipo -create -output target/libv8_killer_core.dylib \ + target/aarch64-apple-darwin/release/libv8_killer_core.dylib \ + target/x86_64-apple-darwin/release/libv8_killer_core.dylib + lipo -create -output target/v8_killer_launcher \ + target/aarch64-apple-darwin/release/v8_killer_launcher \ + target/x86_64-apple-darwin/release/v8_killer_launcher - name: Upload artifact uses: actions/upload-artifact@v3 with: @@ -24,3 +36,5 @@ jobs: target/release/libv8_killer_core.so target/release/libv8_killer_launcher.so target/release/v8_killer_launcher + target/libv8_killer_core.dylib + target/v8_killer_launcher