WM_PRINT hooking in QWebKit Windows
-
Hi All!
I've tried to do some porting of "Qt for Windows IA64":http://developer.qt.nokia.com/forums/viewthread/13204 ... I have noticed WebKit may not work well on all Windows x64 (AMD64) versions because of specific implementation of WM_PRINT hooking for x64 platform in PluginViewWin.cpp and PaintHooks.asm .
I see it's risky to hardcode syscall IDs how it is now done in PaintHooks.asm . I'll show some code examples here:
Code snapshot from user32.dll in Windows Server 2008 / Windows 7:
@.text:0000000078C3B390 ; Exported entry 1729. EndPaint
.text:0000000078C3B390
.text:0000000078C3B390 ; =============== S U B R O U T I N E =======================================
.text:0000000078C3B390
.text:0000000078C3B390
.text:0000000078C3B390 ; BOOL __stdcall ZwUserEndPaint(HWND hWnd, const PAINTSTRUCT *lpPaint)
.text:0000000078C3B390 public ZwUserEndPaint
.text:0000000078C3B390 ZwUserEndPaint proc near
.text:0000000078C3B390
.text:0000000078C3B390 4C 8B D1 mov r10, rcx
.text:0000000078C3B393 B8 19 10 00 00 mov eax, 1019h
.text:0000000078C3B398 0F 05 syscall
.text:0000000078C3B39A C3 retn
.text:0000000078C3B39A ZwUserEndPaint endp
.text:0000000078C3B39A
.text:0000000078C3B39A ; ---------------------------------------------------------------------------
.text:0000000078C3B39B 90 90 90 90 90 align 20h
.text:0000000078C3B3A0 ; Exported entry 1516. BeginPaint
.text:0000000078C3B3A0
.text:0000000078C3B3A0 ; =============== S U B R O U T I N E =======================================
.text:0000000078C3B3A0
.text:0000000078C3B3A0
.text:0000000078C3B3A0 ; HDC __stdcall NtUserBeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint)
.text:0000000078C3B3A0 public NtUserBeginPaint
.text:0000000078C3B3A0 NtUserBeginPaint proc near
.text:0000000078C3B3A0
.text:0000000078C3B3A0 4C 8B D1 mov r10, rcx
.text:0000000078C3B3A3 B8 17 10 00 00 mov eax, 1017h
.text:0000000078C3B3A8 0F 05 syscall
.text:0000000078C3B3AA C3 retn
.text:0000000078C3B3AA NtUserBeginPaint endp
.text:0000000078C3B3AA
.text:0000000078C3B3AA ; ---------------------------------------------------------------------------
.text:0000000078C3B3AB 90 90 90 90 90 90 90 90+ db 9 dup(90h)
@Code snapshot from user32.dll in Windows Server 2003 / XP64:
@.text:0000000078C50850 ; Exported entry 14. BeginPaint
.text:0000000078C50850
.text:0000000078C50850 ; =============== S U B R O U T I N E =======================================
.text:0000000078C50850
.text:0000000078C50850
.text:0000000078C50850 ; HDC __stdcall NtUserBeginPaint(HWND hWnd, LPPAINTSTRUCT lpPaint)
.text:0000000078C50850 public NtUserBeginPaint
.text:0000000078C50850 NtUserBeginPaint proc near
.text:0000000078C50850
.text:0000000078C50850 4C 8B D1 mov r10, rcx
.text:0000000078C50853 B8 16 10 00 00 mov eax, 1016h
.text:0000000078C50858 0F 05 syscall
.text:0000000078C5085A C3 retn
.text:0000000078C5085A NtUserBeginPaint endp
.text:0000000078C5085A
.text:0000000078C5085A ; ---------------------------------------------------------------------------
.text:0000000078C5085B 90 90 90 90 90 align 20h
.text:0000000078C50860 ; Exported entry 201. EndPaint
.text:0000000078C50860
.text:0000000078C50860 ; =============== S U B R O U T I N E =======================================
.text:0000000078C50860
.text:0000000078C50860
.text:0000000078C50860 ; BOOL __stdcall ZwUserEndPaint(HWND hWnd, const PAINTSTRUCT *lpPaint)
.text:0000000078C50860 public ZwUserEndPaint
.text:0000000078C50860 ZwUserEndPaint proc near
.text:0000000078C50860
.text:0000000078C50860 4C 8B D1 mov r10, rcx
.text:0000000078C50863 B8 18 10 00 00 mov eax, 1018h
.text:0000000078C50868 0F 05 syscall
.text:0000000078C5086A C3 retn
.text:0000000078C5086A ZwUserEndPaint endp
.text:0000000078C5086A
@Here in Windows 2008 / Seven we have syscall IDs 0x1017 and 0x1019 for BeginPaint() and EndPaint(). In Windows 2003 / XP64 we have syscall IDs 0x1016 and 0x1018. This means Qt WebKit will not work in Windows 2003 because of current WM_PRINT hooking implementation!!!
Ok man may say Fck Win2003 we don't care about this old sht, but who knows what IDs come in next version of Windows x64... It can happen in next Windows release someone have to fix this thing if/when IDs will change again. The problem here is that Microsoft doesn't document Windows syscall IDs and doesn't disclose their future planes in this area. Moreover syscall IDs are different in 32-bit and 64-bit versions of Windows.
WBR,
redscorp -
Sorry the post was too long so I have to split it... Second part is here!!!
As an alternative for this tricky situation I have prepared a demo code based on original example from "Feng Yuan":http://www.fengyuan.com/article/wmprint.html . My implementation looks much cleaner and will work on all x86, x64 and ia64 platforms and can be potentially extended to ARM and whatever... I've prepared "wmpaint64 project on sourceforge":http://sourceforge.net/projects/wmpaint64/ to demonstrate how WM_PRINT hook can be reimplemented to work well in all releases of Windows. Please go to Files area to download a working code example for all platforms Windows may run on currently. "The code is available in Git repository":http://wmpaint64.git.sourceforge.net/git/gitweb.cgi?p=wmpaint64/wmpaint64;a=tree . Basically I invented nothing new, I simple changed the way of hooking. And what is really important, I rid of assembler code so it can be compiled with different C++ compilers (e.g. g++ and msvc++) w/o #ifdef's.
Before I will port my code to Qt WebKit I would like to read your opinions about it.
Thanks!
-
Have you considered to "file a bug report":http://bugreports.qt.nokia.com/ against Qt Webkit?
-
[quote author="Tobias Hunger" date="1326706775"]Have you considered to "file a bug report":http://bugreports.qt.nokia.com/ against Qt Webkit?[/quote]
I guess you are right. I have to post it as a bug report. I simply wanted to discuss this theme before I post a bug but it seems no one can talk about such a topic it is not presented as a bug or so. :)
Additionally I have prepared "small article":http://wmpaint64.sourceforge.net/ to comment the demo code from before.
-
[quote author="Tobias Hunger" date="1326706775"]Have you considered to "file a bug report":http://bugreports.qt.nokia.com/ against Qt Webkit?[/quote]
Actually, the bugtracker does not accept my bug report for QtWebKit. Should I file it to http://bugs.webkit.org/ instead?