win32_hook: preserve ordinal forwarding#3826
Conversation
baldurk
left a comment
There was a problem hiding this comment.
Thanks for finding this, it's a little concerning that user32.dll intermittently has missing ordinal names but it is what it is.
I think in terms of the change it would be better to flip this on its head - leave func alone throughout the function (it could be marked as a const parameter that won't affect the ABI) and instead copy func to a local before the ordinal lookup, update that local inside the if, and use it for the initialisation of search.
If the name ends up as empty or otherwise invalid then the search will fail and we'll fall through and use the original func. From looking at the change it seems like the underlying problem was that func got modified expecting to get a real name, and then when it fell through to the final fallback that was wrong?
Yes, that's exactly what was happening. Updated the implementation as suggested so that:
|
baldurk
left a comment
There was a problem hiding this comment.
Thanks for making those changes. What I was hoping for was to reduce the set of changes though - originalRequest / requestIsOrdinal I don't think is needed and setting searchFunc to NULL then handling that seems unneeded when an empty string would fail the search naturally.
Unless I've misunderstood then all that is needed is to avoid the func trample and everything else would work as-is. Could you do have a new local for func and add no extra processing or changes?
| } | ||
|
|
||
| FARPROC WINAPI Hooked_GetProcAddress(HMODULE mod, LPCSTR func) | ||
| FARPROC WINAPI Hooked_GetProcAddress(HMODULE mod, LPCSTR const func) |
There was a problem hiding this comment.
nitpick: can you make this const LPCSTR func.
There was a problem hiding this comment.
Done. Updated Hooked_GetProcAddress to keep func unchanged and introduced a local searchFunc, without adding any extra processing or changing the existing fallback behaviour.
Description
Fix incorrect forwarding of ordinal-based
GetProcAddresscalls in the Win32 hook layer.On some systems (e.g. WinAppSDK /
CoreMessagingXP),GetProcAddresscan be invoked using an ordinal (e.g.USER32ordinal0xA16). The current hook attempts to resolve such calls via theOrdinalNamesmapping and forward them as name-based lookups. If the mapping entry is missing or invalid, this results in forwarding with an incorrect name and subsequent lookup failure (ERROR_PROC_NOT_FOUND), which can lead to application termination.This change preserves the original request for ordinal-based lookups:
The fix is limited to
renderdoc/os/win32/win32_hook.cppand only affects ordinal handling inHooked_GetProcAddress.Fixes: #3822