Say I compile a simple application called myproggy that depends on the libfoo dynamic library. Assuming I have another dynamic library libbaz that implements absolutely the same interface (in other words it has definitions of the same functions as libfoo), is it possible to modify the myproggy to depend upon libbaz without the need for rebuild?I can easily do this in the case when I can dynamically load the library, but what if I can't, and I also can't re-compile the library? I am also aware of the security issues related to this.
Is it possible to modify a native executable and change (dynamic) library it depends on?
binary
If it really does implement exactly the same interface,m then a simple rename should be sufficient.Otherwise, yes you can - using a binary editor, you can find the location of the system calls to the dll and modify them to call the new library. Hackers do this (or similar techniques) all the time to remove copy-protection mechanisms.In addition, Microsoft has a tool (Fakes) that is used for unit testing by rewriting the binary to call different methods at runtime, so you can slip in a modified stub for a real library call for testing purposes. This uses their tool Detours that:contains utilities to attach arbitrary DLLs and data segments (called  payloads) to any Win32 binaryI used to use a tool called Purify that instrumented (ie edited the binary) of running applications to inject performance and quality-checking code.