-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unloading DLL without manually resetting hooks no longer restores original bytes #85
Comments
I think we can support easily unhooking everything. DllMain gets called when unloading so sticking a call to cleanup everything there seems easy enough, or having a global object who's destructor cleans everything up. I have to give it some thought. Thanks for the report. |
A minimal reproducible test for this failing behavior would be nice if you have the time. |
Sorry for the late reply. There's an example project in the first post that should show the crash in the host-0.5.0 and later targets. The working output should be something like this:
For later targets, it should crash before printing the final line:
From playing around a bit more, it seems like
|
I'm still holiday brained and I'm not in love with this approach but as a fast and dirty solution it works. Can you give #88 a try and let me know if it fixes the DLL unloading problem in your real projects, not just the test one. Thanks! |
I noticed that Splinter Cell Conviction shows an error message when exiting with enabled hooks(didn't before thread trapping was implemented), so I tested on that one. I reproduced the message with current code, then replaced the file in the PR. The message is gone, but seemingly I'm having the game stuck in a loop on exit still: And console log just spams:
|
Recently ran into an issue with v0.5.x where hooking a function from a DLL, then unloading it will cause any subsequent calls to the function to crash. Destructing the hook manually in the DllMain detach notification works, but this wasn't necessary in v0.4.1.
Example that builds against every amalgamated version from v0.4.1 onwards: test.zip
Stack trace below is from Clang-cl 18.1.8, same as with MSVC 17.12.3. This issue does not occur with MSYS2 (UCRT64) GCC 14.2.0.
This doesn't quite tell the whole story though, as it only seems to crash in this way when running with a debugger attached. When run without, it unloads the hook library, makes it to the pause call, then crashes when running the previously hooked
print
function.I checked where the hook was placed and saw the
jmp
was still there, even after the DLL had been unloaded.The convenience of not having to worry about manually unhooking was nice, but now that I'm looking at the example code again, I realize I might've been getting away with misusing it until now. I thought it would be worth mentioning just to be sure.
The text was updated successfully, but these errors were encountered: