Crates.io | upgrayedd |
lib.rs | upgrayedd |
version | 0.1.2 |
source | src |
created_at | 2023-11-13 01:23:31.066367 |
updated_at | 2023-11-24 19:34:32.992086 |
description | Ergonomic function interposition in Rust |
homepage | |
repository | https://github.com/woodruffw/upgrayedd |
max_upload_size | |
id | 1033179 |
size | 6,708 |
"Two Ds for a double dose of debugging."
[!WARNING] You do not need this library. Do not use this library, especially in production systems. It is not safe, even if you only use safe Rust with it. It cannot be made safe.
upgrayedd
is a convenience proc macro for building function interposition
tools in Rust. When used in a shared library build (which is the only
way you should be using it), it makes LD_PRELOAD
-style interposition
look like (relatively) idiomatic Rust.
Interposing on an OpenSSL API:
use upgrayedd::upgrayedd;
#[upgrayedd]
fn X509_VERIFY_PARAM_set_auth_level(param: *mut std::ffi::c_void, level: std::ffi::c_int) {
eprintln!("before!");
unsafe { upgrayedd(param, level) };
eprintln!("after!");
}
Rewriting parameters:
use upgrayedd::upgrayedd;
#[upgrayedd]
fn frobulate(size: libc::size_t) {
unsafe { upgrayedd(size + 42) };
}
Stubbing functions out:
use upgrayedd::upgrayedd;
#[upgrayedd]
fn verify_cert(cert: *mut std::ffi::c_void) -> libc::c_int {
// nothing to see here
1
}
See the docs for more usage examples.
malloc
and free
) may or may not work,
depending on what you put in your hook. In particular, if you accidentally
recurse while holding a lock (which is easy to do when hooking malloc
and calling println!
), you'll probably end up deadlocking.upgrayedd
will happily let you do.upgrayedd
will happily let you do.