-
-
Notifications
You must be signed in to change notification settings - Fork 252
Fix/#215 #216
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
Fix/#215 #216
Conversation
Summary of ChangesHello @acidicoala, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request delivers crucial fixes to enhance the robustness and correctness of the Polyhook2 library, particularly concerning its disassembler and hooking mechanisms. The primary focus is on resolving issue #215, which involved misinterpreting specific 'call' instructions that read from the stack pointer. By introducing logic to recognize and transform these instructions into direct register moves, the PR ensures accurate instruction processing and improves the efficiency of hooked functions. Additionally, it addresses minor test discrepancies and updates 'asmjit' header imports to eliminate build warnings, contributing to a cleaner and more reliable codebase. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces several fixes, including a clever solution for handling specific call instructions that retrieve the stack pointer, a fix for a disassembler test, and updates to resolve asmjit warnings. The changes are well-structured and address the intended issues. I have a couple of suggestions to improve the code further: one regarding a redundant check which can be simplified, and another concerning the use of a C++20 feature that could be updated to ensure broader compiler compatibility.
|
This is a good approach, we are already re-writing sequences in other places like the trampoline to semantic equivalents so I am fine with this. It is also more general than the approach I had suggested by hooking later. I would prefer log outputs don't mention bug numbers (comments should, but not logs). Very minor though, up to you if you like to fix. Will merge later tonight. |
|
Thanks for the swift response! I've changed the log line to In the meantime I will create another issue for dealing with the failing test with Linux 32-bit Release build configuration. |
|
Merged parent #218 |
This PR mainly fixes #215, a small bug in the disassembler tests and asmjit warnings.
Fix for #215
The fix consists of:
mov reg, imm32where:regis the destination register. In real Linux binaries I found out that it can be any GP register, not justeaximm32is the original address of the instruction that followscallinstruction.I like this approach because it doesn't involve allocating any new global memory. In fact it even makes the hooked function code a bit more performant since instead of 3 instructions (call, mov, ret) CPU will execute just 1 (mov).
Furthermore, sometimes the first instruction we might see in a function is precisely this call to routine reading SP. Hence I also modified the
followJmpfunction to ignore such first calls, since it would be replaced soon-after.Thanks to this fix, the
build-and-test (ubuntu-latest, Debug, 32, clang)CI is now passing successfully. However, thebuild-and-test (ubuntu-latest, **Release**, 32, clang)is failing due to another issue that is similar in nature, but not the exactly same. I will create another issue detailing it and submit a corresponding PR to fix it once this PR has been approved.Fix
TestDisassemblerJust a minor bug in calculating byte range to disassemble.
Fix asmjit warnings
The
asmjit/ashmjit.jheader got deprecated, and every build was print this warning. I replaced it withasmjit/x86.hto resolve this warning since Polyhook2 supports only x86/x86_64 architecture.There are other constant build warnings related to implicit conversion of types, which is not ideal since such conversion might differ depending on the compiler. These warnings will need to be addressed in a future PR as well.