SamuelTulach / LightHook

Single-header, minimalistic, cross-platform hook library written in pure C
MIT License
291 stars 46 forks source link

PlatformFree not called in DisableHook? #2

Closed bogen85 closed 1 year ago

bogen85 commented 1 year ago

First off, let me say that of all the hooking libraries I tried recently LightHook is first one I got completely working. :smile:

A couple issues regarding compiling, but I may file separate issues for those. (Mainly in regard to -Wall -Werror and could not get around those with clang++) Also, no arm, arm64 or risc-v support, but I may have a friend help me get LightHook working with those architectures.

I was able to compile with g++ -Wall -Werror -Os -std=gnu++17 -Wno-pointer-arith -Wno-error=parentheses -Wno-parentheses -Wno-error=sign-compare -Wno-sign-compare and that is how I noticed that PlatformFree was never being called (as I got an error about that, and was not going to disable that warning/error).

I'm using this with Free Pascal (FPC) and there was no way it could import LightHook.h (without major surgery) so I did not bother, I just wrote a wrapper C unit and created a much smaller header file that FPC could import.

In my wrapper I'm calling PlatformFree immediately after DisableHook.

Despite functions I tried hooking not being C compatible as far as calling, LightHook had no problem hooking them.

So, should I be calling PlatformFree immediately after DisableHook each time? I noticed I could enable and disable more than once and it performed as expected.

SamuelTulach commented 1 year ago

As you can tell by the commit history, this was weekend project so I simply forgot to call PlatformFree. Unfortunately I am quite busy atm but I will try to push a fix as soon as possible for it so you won't need to call it manually.

bogen85 commented 1 year ago

No rush! Thanks! As I have a suitable solid workaround I don't need immediate resolution on this. Was mainly wanting to point it out.

bogen85 commented 1 year ago

I see you updated it! Thanks. I removed my work around.

bogen85 commented 1 year ago

Was resolved in this commit: https://github.com/SamuelTulach/LightHook/commit/451093cb6944080927b0270fdf6e542c47721d45