Skip to content

Commit

Permalink
🍎basically implemented macOS hijacking (?)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve-xmh committed Mar 1, 2024
1 parent 4b14fcd commit 9cee2b3
Show file tree
Hide file tree
Showing 9 changed files with 882 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"crates/core",
"crates/insert_dylib",
"crates/launcher",
]
resolver = "2"
Expand Down
10 changes: 10 additions & 0 deletions crates/insert_dylib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "v8_killer_insert_dylib"
version.workspace = true
edition.workspace = true
authors.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
cc = "1.0"
3 changes: 3 additions & 0 deletions crates/insert_dylib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# insert_dylib

A Rust binding of [tyilo/insert_dylib](https://github.com/tyilo/insert_dylib).
5 changes: 5 additions & 0 deletions crates/insert_dylib/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
cc::Build::new()
.file("./src/main.c")
.compile("insert_dylib");
}
114 changes: 114 additions & 0 deletions crates/insert_dylib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
use std::{
error::Error,
ffi::{c_char, c_int, CString},
path::Path,
};

#[link(name = "insert_dylib", kind = "static")]
extern "C" {
fn insert_dylib_main(argn: c_int, argv: *const *const c_char) -> c_int;
fn test_insert_dylib_main();
}

#[derive(Debug, Default)]
pub struct InsertDyLibConfig {
pub weak: bool,
pub no_strip_codesig: bool,
}

pub fn insert_dylib(
binary_path: impl AsRef<Path>,
dylib_path: impl AsRef<Path>,
output_path: impl AsRef<Path>,
config: &InsertDyLibConfig,
) -> Result<(), Box<dyn Error>> {
let binary_path = binary_path.as_ref();
let dylib_path = dylib_path.as_ref();
let output_path = output_path.as_ref();
if !binary_path.is_file() {
return Err("binary file not exists".into());
}
if !dylib_path.is_file() {
return Err("dylib file not exists".into());
}
let binary_path = binary_path.to_str().unwrap();
let dylib_path = dylib_path.to_str().unwrap();
let output_path = output_path.to_str().unwrap();
let weak = if config.weak { "--weak" } else { "" };
let no_strip_codesig = if config.no_strip_codesig {
"--no-strip-codesig"
} else {
"--strip-codesig"
};
let args = vec![
"insert_dylib".to_string(),
"--all-yes".to_string(),
weak.to_string(),
no_strip_codesig.to_string(),
dylib_path.to_string(),
binary_path.to_string(),
output_path.to_string(),
];
let args = args
.into_iter()
.filter(|s| !s.is_empty())
.collect::<Vec<_>>();
let args: Vec<_> = dbg!(args)
.into_iter()
.map(|s| CString::new(s).unwrap())
.collect();
let args: Vec<_> = args.iter().map(|s| s.as_ptr()).collect();
let result = dbg!(unsafe { insert_dylib_main(dbg!(args.len() as c_int), args.as_ptr()) });
if result == 0 {
Ok(())
} else {
Err("insert_dylib failed".into())
}
}

pub fn insert_dylib_inplace(
binary_path: impl AsRef<Path>,
dylib_path: impl AsRef<Path>,
config: &InsertDyLibConfig,
) -> Result<(), Box<dyn Error>> {
let binary_path = binary_path.as_ref();
let dylib_path = dylib_path.as_ref();
if !binary_path.is_file() {
return Err("binary file not exists".into());
}
if !dylib_path.is_file() {
return Err("dylib file not exists".into());
}
let binary_path = binary_path.to_str().unwrap();
let dylib_path = dylib_path.to_str().unwrap();
let weak = if config.weak { "--weak" } else { "" };
let no_strip_codesig = if config.no_strip_codesig {
"--no-strip-codesig"
} else {
"--strip-codesig"
};
let args = vec![
"insert_dylib".to_string(),
"--all-yes".to_string(),
weak.to_string(),
"--inplace".to_string(),
no_strip_codesig.to_string(),
dylib_path.to_string(),
binary_path.to_string(),
];
let args = args
.into_iter()
.filter(|s| !s.is_empty())
.collect::<Vec<_>>();
let args: Vec<_> = dbg!(args)
.into_iter()
.map(|s| CString::new(s).unwrap())
.collect();
let args: Vec<_> = args.iter().map(|s| s.as_ptr()).collect();
let result = dbg!(unsafe { insert_dylib_main(dbg!(args.len() as c_int), args.as_ptr()) });
if result == 0 {
Ok(())
} else {
Err("insert_dylib failed".into())
}
}
Loading

0 comments on commit 9cee2b3

Please sign in to comment.