Skip to content
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

Fast toggling of hooks #72

Closed
bottiger1 opened this issue May 12, 2024 · 6 comments
Closed

Fast toggling of hooks #72

bottiger1 opened this issue May 12, 2024 · 6 comments

Comments

@bottiger1
Copy link
Contributor

I'm looking for a new hooking library replacement and this one seems to suit my purposes except for 1 issue.

There doesn't seem to be a way to quickly toggle the hook on or off. So the only way seems to be completely destroying and recreating the hook which means new memory is allocated, and the prologue has to be disassembled and translated again which seems like a lot of overhead.

Would you be open to having a new member variable indicating whether the hook is on or not, and you could just replace the prologue with the hooked bytes or the original bytes?

@cursey
Copy link
Owner

cursey commented May 13, 2024

I created PR #73 as a starting point for this feature request. Let me know if you have any suggestions.

@bottiger1
Copy link
Contributor Author

Thanks for making this.

Is there any reason you decided to assemble the jump from scratch instead of saving the original detour and just copying over the bytes? I feel like it would be faster but I don't know for sure.

@cursey
Copy link
Owner

cursey commented May 14, 2024

Assembling the jump is just filling out a struct on the stack and copying it over. The overhead is negligible compared to the syscalls needed to unprotect/reprotect the memory we write to (VirtualProtect/mprotect).

@bottiger1
Copy link
Contributor Author

Oh ok. What do you think about adding a flag to disable protection on hook creation and not bothering to re-protect it afterwards?

@cursey
Copy link
Owner

cursey commented May 15, 2024

Oh ok. What do you think about adding a flag to disable protection on hook creation and not bothering to re-protect it afterwards?

I have to think about this some more. This would bypass/undermine a lot of the safety mechanisms put in place and at first glance would be quite disruptive code-wise.

@bottiger1
Copy link
Contributor Author

Ok never mind, I just realized there's probably no use to toggling hooks on and off that fast except for evading anti-cheat. For high performance purposes probably better just to leave the stuff hooked and toggle with a boolean.

I think we can close this issue. I've tested the branch a bit and it seems to be working without issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants