-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can Redhook (or other project) hook into Rust code? #6
Comments
Looks like the answer is yes, if you're willing to dig out the mangled name, and of course if the Rust compiler version is the same (since there's no stable ABI). If I #![allow(bad_style)]
extern crate libc;
use std::fmt::Arguments;
use std::mem::transmute;
use libc::{c_char, c_void};
#[link(name="dl")]
extern {
fn dlsym(handle: *const c_void, symbol: *const c_char) -> *const c_void;
}
const RTLD_NEXT: *const c_void = -1isize as *const c_void;
#[no_mangle]
pub unsafe fn _ZN2io5stdio6_print20h47445faa595ef503E6gE(args: Arguments) {
let ptr: unsafe extern fn(args: Arguments) =
transmute(dlsym(RTLD_NEXT, b"_ZN2io5stdio6_print20h47445faa595ef503E6gE\0".as_ptr() as *const _));
ptr(args);
ptr(args);
} then I can build both with
The difference with what redhook does already is that this is a |
I was just curious. When Rust's stable ABI land and there be libstd in distros like today's libc, will Redhook extend its scope to also cover hooking into Rust? |
If something is compiled with
-C prefer-dynamic
, can, for example,<std::fs::File as std::io::Write>::write
be instrumented by LD_PRELOAD to inject failures?The text was updated successfully, but these errors were encountered: