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

Is it possible to skip the original instruction in midhook? #38

Closed
asesidaa opened this issue Oct 3, 2023 · 5 comments
Closed

Is it possible to skip the original instruction in midhook? #38

asesidaa opened this issue Oct 3, 2023 · 5 comments

Comments

@asesidaa
Copy link

asesidaa commented Oct 3, 2023

Thanks for the great library. Now I am trying to implement a midhook that need to replace the original instruction. The original instruction is something like

rcpps xmm0, xmm1

and I need to replace it with exact computation so that the result will be consistent on both Intel and AMD.
Is it possible? Maybe related to #37?

@cursey
Copy link
Owner

cursey commented Oct 3, 2023

This is a similar request to #37 but slightly different. I'm more concerned that mid hook doesn't provide access to XMM registers. It's something I've been meaning to address.

As for your specific request, why couldn't you just midhook the next instruction and make the modifications there? This would keep midhook simple, once I make it capture XMM registers.

@asesidaa
Copy link
Author

asesidaa commented Oct 3, 2023

Thanks for the response.

The problem I am trying to solve is that for example,

rcpps xmm0, xmm0

would compute 1/x for the 4 packed floats. However, this instruction would result in different results on Intel and AMD, so I need to replace it with for example divps which would produce the same result.

The problem is after the instruction, the original values (in XMM0) is already replaced with the results, so they are no longer available. So the most robust way is to replace the original instruction (without executing it).

The plan is to use things like asmjit to generate the required instructions as the hook function.

@cursey
Copy link
Owner

cursey commented Oct 4, 2023

I've created a PR #39 that allows you to change the instruction pointer, effectively letting you bypass the trampoline that would execute the original instruction. I think a lot of care will need to be taken to use this safely, but the option is there now.

I will also be adding XMM register capture to this PR before merging it into main.

@cursey
Copy link
Owner

cursey commented Oct 4, 2023

I've added XMM capture as well to that PR. Let me know if those changes are enough for you to do what you want.

@asesidaa
Copy link
Author

asesidaa commented Oct 4, 2023

Thank you, I think it is working in my test

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