If I have a function foo() that windows has implemented in kernel32.dll and it always returns true, can I have my program: “bar.exe” hook/detour that Windows function and make it return false for all processes instead?
So, if my svchost, for example, calls foo(), it will return false instead of true. The same action should be expected for all other processes currently running.
If so, how? I guess I’m looking for a system-wide hook or something.
Take a look at Detours, it’s perfect for this sort of stuff.
For system-wide hooking, read this article from MSDN.
First, create a DLL which handles hooking the functions. This example below hooks the socket send and receive functions.
Then, create a program to inject the DLL into the target application.
This should be more than enough to get you started!