Is there any C library for manipulating x86 / x64 machine code? Specifically, I'd like to modify a function in my program's address space at runtime.
For example, I have the functions foo and bar, for which I have the source or knowledge of their inner workings, but can't recompile the library they're in, and I have the function baz I wrote myself. Now I'd like to be able to say things like: "In the function foo, find the call to bar, and inject the instructions of baz right in front of it". The tool would have to adjust all the relevant addresses in the program accordingly.
I know all the bits and pieces exist, for example there are tools to do hotpatching of functions. I guess there are some restrictions on what would be possible, due to optimization and so on, but the basic functionality should be possible. I wasn't able to find anything like this, does anybody have some links?