geofft / redhook

Dynamic function call interposition / hooking (LD_PRELOAD) for Rust
BSD 2-Clause "Simplified" License
177 stars 17 forks source link

Help with `environ()` #25

Closed metaskills closed 2 years ago

metaskills commented 2 years ago

Thanks so much for this library. I used it at Custom Ink for some Lambda Environment variable work here. https://github.com/customink/crypteia

I'd like to also hook into environ() like I do here (https://github.com/customink/crypteia/blob/main/src/lib.rs#L22) for getenv() but could use some help if you have a spare moment. The GNU (https://www.gnu.org/software/libc/manual/html_node/Environment-Access.html) documents both as:

So my two questions are:

1) Would the hook look like this? Or is the type and/or code wrong?

redhook::hook! {
    unsafe fn environ() -> *mut c_char => crypteia_environ {
        let value = redhook::real!(environ)();
        return value;
    }
}

2) Can I call redhook::hook! twice or do I have do combine them?

metaskills commented 2 years ago

Is environ not possible because it is a variable vs. a function?

metaskills commented 2 years ago

Answering this myself. I heard the answer is no. Maybe we could with __start. Closing this issue.