Skip to content

Conversation

@Kenzzer
Copy link
Member

@Kenzzer Kenzzer commented Oct 21, 2025

Initially reported in alliedmodders/sourcemod#2212, and then unidentified in alliedmodders/sourcemod#2343 and reported again by @dysphie in AM's internal channels. I've decided to have a look at safetyhook internal works and introduce a proper fix for those __x86_get_pc_thunks.

Fix is trivial, each __x86_get_pc_thunk is basically

mov reg, [esp]
ret

Where the reg is the one that corresponds to the function name. EAX for AX, ECX for CX, etc...
Those thunks can be easily identified by checking for their opcodes.

If a thunk call is discovered and moved into the trampoline, instead of copying the original bytes, we replace those original bytes with mov reg, 0xInstructionAddress
which coincidentally only use 5 bytes, the same amount used to call __x86_get_pc_thunk.

@Kenzzer Kenzzer merged commit 0e87c1e into main Nov 11, 2025
@Kenzzer Kenzzer deleted the fpic_fix branch November 11, 2025 13:36
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.

3 participants