Detours is a very interesting library from Microsoft Research that allows you to intercept Windows API calls that an application makes and redirect them to your code that can then:
- do some pre-and-post processing work around the call to the original API, and/or
- customize what is returned to the caller of the API
This does not involve accessing original application source code and can be done at runtime!
For an example, check the screenshot below for a sample that intercepts calls to GetVersionEx API by an application and displays the OS version details. The first output is the original OS version information when the application invokes GetVersionEx. The second output is when the application is launched by my wrapper application that enabled GetVersionEx interception and returns the version details specified at the command line:
For those interested, you can download the complete sample source code from here.