stevemk14ebr / PolyHook

x86/x64 C++ Hooking Library
MIT License
882 stars 168 forks source link

Member function hook #18

Closed Houd1ny closed 7 years ago

Houd1ny commented 7 years ago

Sorry maybe for the stupid question. Is it possible to hook not virtual member function using PolyHook? If this is possible there is no example in Tests.cpp

stevemk14ebr commented 7 years ago

Not currently using PolyHook i believe. Member function pointers are strange beasts so require some special work. It may be possible to macgyver something together but PolyHook expects a normal function pointer and passing it anything else may mess up registers in the underlying assembly. I personally haven't hooked a member function yet, the first step would be to get a pointer to the underlying function by itself (member function pointers store extra info) but this is just getting theoretical. I would suggest you take a look at DarthTon's Blackbone library (https://github.com/DarthTon/Blackbone/tree/master/src/BlackBone/LocalHook) as i think he supports member function hooking, or RaptorFactor's HadesMem (https://github.com/RaptorFactor/hadesmem/tree/master/include/memory/hadesmem/local). I will eventually go through and add the necessary logic to support them but I first want to finish my port to linux so it may be quite a while before I add this functionality

Houd1ny commented 7 years ago

Thank you!!! I have found https://www.microsoft.com/en-us/research/project/detours/ and their member.cpp example Is this a good library?

stevemk14ebr commented 7 years ago

It has no x64 support and I created polyhook to be it's direct competitor but yes it is reliable.