Re: Reading a Wnd structure...
- From: "Scherbina Vladimir" <vladimir.scherbina@xxxxxxxxx>
- Date: Sun, 21 May 2006 21:27:41 +0300
Hi James.
Not a good example, because all mentioned by you code might be changed to
something like:
__asm
{
mov eax, hUser32Instance
add eax, dwOffsetToValidateHwnd
mov ecx, hwnd
call eax
}
which is simpler and *unsafe* as your example.
--
Vladimir
"James Brown [MVP]" <not@home> wrote in message
news:lfqdndLdT93v2e3ZRVny1g@xxxxxxxxxxxx
"James Brown [MVP]" <not@home> wrote in message
news:lq2dnab92oYYo-3ZRVny1w@xxxxxxxxxxxx
"Jack" <jack@xxxxxx> wrote in message
news:h4707216sfc982j2bi9g2n80lqeq9emvov@xxxxxxxxxx
I can get a Wnd pointer in Windows 9x (thanks to one of Matt Pietrek's
books), but I can't figure it out in Windows NT/2k/XP. This page
offers vague information on how to do it:
http://www.winterdom.com/dev/ui/wnd.html
I just need read access to the structure, but if I could get write
access that would be great. And yes, I know it's undocumented, and I'm
not "supposed" to do it, but I would appreciate any help I could get.
Thanks,
Jack
Under NT OSs you need to call the ValidateHwnd function which is a
private function inside user32.dll.
PWND __fastcall ValidateHwnd(HWND hwnd);
Note the __fastcall - this is not a WINAPI definition, the hwnd parameter
gets passed via ecx register. You can use WinDbg to find the address if
you've got debug-symbols installed:
x user32!ValidateHwnd
77d48490 USER32!ValidateHwnd (on my current XP SP2 machine)
So you can't do GetProcAddress. But you can manually locate ValidateHwnd
by finding an exported function from user32 that you *know* calls it
(such as GetWindowRect). Then you parse the opcodes at the start of this
function looking for the "call" (i.e. op-code 0xE8) to ValidateHwnd:
The following C code works for 32bit NT/2000/XP on x86 processors. You
may need to play with function-pointer typedefs if you want it to compile
under C++.
PVOID ValidateHwnd(HWND hwnd){
DWORD ptr = (DWORD )memchr(GetWindowRect, 0xE8, 100);
DWORD addr = *(DWORD *)(ptr+1) + ptr + 5;
// make a function pointer
PVOID (__fastcall * _ValidateHwnd)(HWND hwnd) = (PVOID)addr;
// call the real ValidateHwnd
return _ValidateHwnd(hwnd);}Just call this function, passing in your
HWND and you'll get back a pointer-to-WND (represented as a PVOID here
for simplicity). I would recommend installing WinDbg and debug-symbols,
and inspecting the disassembly for GetWindowRect so that you understand
what the above function is doing, and also appreciate why this is not a
very smart thing to be including in 'production' software...
Formatting went funny there.....here's the function again:
PVOID ValidateHwnd(HWND hwnd)
{
DWORD ptr = (DWORD )memchr(GetWindowRect, 0xE8, 100);
DWORD addr = *(DWORD *)(ptr+1) + ptr + 5;
// make a function pointer
PVOID (__fastcall * _ValidateHwnd)(HWND hwnd) = (PVOID)addr;
// call the real ValidateHwnd
return _ValidateHwnd(hwnd);
}
James
.
- Follow-Ups:
- Re: Reading a Wnd structure...
- From: James Brown [MVP]
- Re: Reading a Wnd structure...
- References:
- Reading a Wnd structure...
- From: Jack
- Re: Reading a Wnd structure...
- From: James Brown [MVP]
- Re: Reading a Wnd structure...
- From: James Brown [MVP]
- Reading a Wnd structure...
- Prev by Date: Re: KEY_WOW64_64KEY flag with RegOpenKeyEx not giving the desired resu
- Next by Date: Re: Automatic logoff
- Previous by thread: Re: Reading a Wnd structure...
- Next by thread: Re: Reading a Wnd structure...
- Index(es):
Relevant Pages
|
Loading