gittup/tup — pull request #72 by foresterLV (2012-06-05 11:18:16+00:00)
Title: Implemented stronger function hooking using "hot patching" method.

Original IAT patching approach have a drawback of not intercepting
function calls done dynamically (i.e. GetProcAddress->call). Also it
requires all variants of the function to be hooked instead of single
base one making whole process open to calls not visible to hook.

This fix implements "hot patching" hooking method which inserts redirection
instructions directly to function body if the function is compiled with
"hot patching" compiler switches on. Most functions on recent Windows
versions have this option enabled.

However not all API functions support this method, therefore IAT and hot
patching are both enabled for now. In first pass hot patching redirection
is applied, and then functions which cannot be hooked using redirection are
then patched in import tables (IAT).

In overall this makes hooking much stable for me when using old MingW
/Cygwin tool builds. In long run IAT patching can be probably dropped
allowing to greatly simplify dllinject.c but that would require
re-organizing list of patched functions.

As a side-effect dllinject.c was refactored a bit into multiple modules.