-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🍎basically implemented macOS hijacking (?)
- Loading branch information
Showing
9 changed files
with
882 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |
Oops, something went wrong.