Skip to content

Commit 4fb9230

Browse files
author
Yuxuan Shui
committed
user32: Add hotpatchable wrapper for GetWindowLongA.
ntlea for some reason expects GetWindowLongA to start with a "push $-2", and will try to skip over this instruction. If we don't anticipate this, it will ended up either skipping over critical instructions, or on a desync address. (upstream commit f9f9481) CW-Bug-Id: #22660
1 parent 1135dee commit 4fb9230

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

dlls/user32/win.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,28 @@ WORD WINAPI GetWindowWord( HWND hwnd, INT offset )
888888
/**********************************************************************
889889
* GetWindowLongA (USER32.@)
890890
*/
891-
LONG WINAPI GetWindowLongA( HWND hwnd, INT offset )
891+
892+
#ifdef __i386__
893+
894+
/* This wrapper is here to workaround a ntlea quirk. First of all, ntlea
895+
* checks whether GetWindowLongA starts with the Win32 hotpatchable prologue,
896+
* if it can find that, it will use a hooking strategy more difficult for us
897+
* to deal with. Secondly, it assumes what follows the prologue is a `pushl $-2`,
898+
* and will try to skip over this instruction when calling `GetWindowLongA`,
899+
* (i.e. it tries to jump to `GetWindowLongA + 7`, 5 bytes for the prologue, 2
900+
* bytes for the `pushl`.). We have to anticipate that and make sure the result
901+
* of doing this won't be a messed up stack, or a desynced PC.
902+
*/
903+
__ASM_STDCALL_FUNC( GetWindowLongA, 8,
904+
".byte 0x8b, 0xff, 0x55, 0x8b, 0xec\n" /* Win32 hotpatchable prologue. */
905+
"pushl $-2\n"
906+
"addl $4, %esp\n"
907+
"popl %ebp\n"
908+
"jmp " __ASM_STDCALL("get_window_longA", 8) )
909+
LONG WINAPI get_window_longA( HWND hwnd, INT offset )
910+
#else
911+
LONG WINAPI DECLSPEC_HOTPATCH GetWindowLongA( HWND hwnd, INT offset )
912+
#endif
892913
{
893914
switch (offset)
894915
{

0 commit comments

Comments
 (0)