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

Add an option to let midhook call original first instead of calling hook code first #37

Open
Nukoooo opened this issue Aug 16, 2023 · 3 comments

Comments

@Nukoooo
Copy link

Nukoooo commented Aug 16, 2023

Example:

mov     rcx, [rax+330h]
mov     edx, 8003h

Let's say I want to get the rcx register address, with the current implementation, I need to hook mov edx, 8003h to get rcx address, which is not that intuitive to me. If there is an option to make it call original first, then I just hook mov rcx, [rax+330h] and grab the address

@Patoke
Copy link

Patoke commented Aug 20, 2023

What you're trying to propose isn't intuitive in on itself, it would cause so much issues for no reason and the feature is entirely useless as you have already shown, you can just hook after the instruction was executed lol
If you need a certain instruction ran before your hook is executed, placing the hook after that instruction is executed is in fact intuitive since code flow goes as:

original_fn:
  mov rcx, [rax+330h]
  jmp hook_proxy
  ; continue_code_flow

hook_proxy:
  jmp hooked_fn
  ; the instructions after this is what is executed after you call original in your hook
  mov edx, 8003h ; original instructions that the library replaced
  jmp continue_code_flow

(also this isn't limited to mid function hooks XD)

@Nukoooo
Copy link
Author

Nukoooo commented Aug 20, 2023

You are right about that. I saw the hooking library that Dalamud is using, found that the library has an option to let you choose the behavior and thought that was useful in some cases, hence I made this issue.

@angelfor3v3r
Copy link
Collaborator

angelfor3v3r commented Aug 20, 2023

At the moment, we have to be careful with how MidHook is used. It currently doesn't back up registers outside flags & base x86 registers so it could easily crash. I believe cursey is working on fixing that (no promises on when it'll be done) and will probably take a look at this idea once that is done. #39 added support for XMM registers.

For now, you could probably just hook in a different place or write your own stub with Xbyak to give yourself more control and access to more registers and such.

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

3 participants