Here is the code
1. Checkout MS Detours library from GitHub and build the library
2. Checkout @ColdZer0's latest commit (mentioned above) from GitLab and build FPC.
3. Add the new compiler path(s) to Lazarus and you should be able to build the project.
4. Use the
TargetCBinary and
FPCDLLInjector from previous comments to test function hooking.
Note: I have only defined external functions absolutely needed for hooking, detours library has tons of APIs. You can look at detour.h and define others if you want to experiment. It has APIs to find target functions, to insert payload in new process etc. Argument types are simple and easily translated from c++ to pas.
I have included the DLL in the zip in case you don't want to build stuff.
Edit: Figured out a way to get (runtime) address of any target function in any binary dynamically (assuming the symbols/debug file exists).
https://forum.lazarus.freepascal.org/index.php?topic=74031.msg582712#msg582712works flawlessly