Skip to content

Add support for inline hooks #2

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

blu-dev
Copy link

@blu-dev blu-dev commented Apr 6, 2022

Resolves #1
Resolves #3

Introduces inline hooks to the exlaunch environment.

Modified:

  • exl::util::Hook
    • Added two new static members for inline hook environment manage (s_InlineHookJit, s_UsedInlineHooks)
    • Added three new static methods:
      • void InlineHook(uinptr_t hook, uintptr_t callback, bool is_extended)
        • hook - The address where the hook should be injected
        • callback - The address of the callback function (must take either ExInlineCtx* or InlineCtx*)
        • is_extended - Needs to be true if the callback takes ExInlineCtx*
      • void InlineHook(uintptr_t hook, ExInlineCallback callback), a wrapper for the less user-friendly InlineHook
      • void InlineHook(uintptr_t hook, InlineCallback callback), a wrapper for the less user-friendly InlineHook
    • Modified the (so far) unused InlineCtx structure to reflect the x29 and x30 registers which are also stored there
    • Added a new ExInlineCtx structure which includes a field for the stack pointer as well as an array of 32 FpuRegister, and all elements in InlineCtx
    • Added a new FpuRegister union which holds representations of A64's SIMD registers
    • Modified Hook::Initialize to also initialize the new inline hook environment members
    • Changed InlineHookHandlerSize from 0x9C -> 0xC to reflect the actual size of the handler
    • Removed what was going to be the InlineHandler imports and replaced them by three new extern "C" imports
  • exl::hook
    • Added four new static functions to help create inline hooks from either function pointers or main offsets
  • __virtmem_rng
    • Added a static counter that is multiplied against the tick to ensure consecutive calls of __virtmem_rng can succeed
      Example output of dumping the extended context from a callback. This callback was run at the beginning of Smash Ultimate's CameraManager::update function and the game continued normal execution afterwards
X0: 3e6f2b20a0
X1: 0
X2: 0
X3: 0
X4: 0
X5: 0
X6: 0
X7: 0
X8: c1200000
X9: 0
X10: 3eacf87650
X11: 0
X12: 0
X13: 0
X14: 0
X15: 0
X16: 6c5c3d47c8
X17: 442d9800c
X18: d
X19: 42aa0000
X20: c1200000
X21: 3e6f2b1400
X22: 6c5906e148
X23: 3eab4d6378
X24: 6c5b449000
X25: 3eaee1df68
X26: 6c5b449000
X27: 3e45c39720
X28: 3e45c39730
X29: 3e46dbad50
X30: 6c554e9d94
SP: 3e46db8580
V0 { 1080, 0, 0, 0 }
V1 { 1920, 0, 0, 0 }
V2 { 1080, 0, 0, 0 }
V3 { 0, 0, 0, 0 }
V4 { 0, 0, 0, 0 }
V5 { 0, 0, 0, 0 }
V6 { 0, 0, 0, 0 }
V7 { 0, 0, 0, 0 }
V8 { 1920, 0, 0, 0 }
V9 { 1080, 0, 0, 0 }
V10 { 0, 0, 0, 0 }
V11 { 0, 0, 0, 0 }
V12 { 0, 0, 0, 0 }
V13 { 0, 0, 0, 0 }
V14 { 0, 0, 0, 0 }
V15 { 0, 0, 0, 0 }
V16 { 0, 0, 0, 0 }
V17 { 0, 0, 0, 0 }
V18 { 0, 0, 0, 0 }
V19 { 0, 0, 0, 0 }
V20 { 0, 0, 0, 0 }
V21 { 0, 0, 0, 0 }
V22 { 0, 0, 0, 0 }
V23 { 0, 0, 0, 0 }
V24 { 0, 0, 0, 0 }
V25 { 0, 0, 0, 0 }
V26 { 0, 0, 0, 0 }
V27 { 0, 0, 0, 0 }
V28 { 0, 0, 0, 0 }
V29 { 0, 0, 0, 0 }
V30 { 0, 0, 0, 0 }
V31 { 0, 0, 0, 0 }

@jonahnm
Copy link

jonahnm commented Sep 6, 2022

Looking forward to seeing this merged!

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

Successfully merging this pull request may close these issues.

svcControlCodeMemory randomly fails Add support for inline hooks (and extended inline hook contexts)
2 participants