4 HMODULE g_hModule
= NULL
;
5 PGDI_TABLE_ENTRY GdiHandleTable
;
11 PTEB pTeb
= NtCurrentTeb();
12 PPEB pPeb
= pTeb
->ProcessEnvironmentBlock
;
13 printf("TEB::PEB=0x%lx PEB::GdiHT=0x%lx, Peb=%p, Teb=%p\n", FIELD_OFFSET(TEB
, ProcessEnvironmentBlock
), FIELD_OFFSET(PEB
, GdiSharedHandleTable
), pTeb
, pPeb
);
14 return pPeb
->GdiSharedHandleTable
;
18 IsHandleValid(HGDIOBJ hobj
)
20 USHORT Index
= (ULONG_PTR
)hobj
;
21 PGDI_TABLE_ENTRY pentry
= &GdiHandleTable
[Index
];
23 if (pentry
->KernelData
== NULL
||
24 pentry
->KernelData
< (PVOID
)0x80000000 ||
25 (USHORT
)pentry
->FullUnique
!= (USHORT
)((ULONG_PTR
)hobj
>> 16))
34 GetHandleUserData(HGDIOBJ hobj
)
36 USHORT Index
= (ULONG_PTR
)hobj
;
37 PGDI_TABLE_ENTRY pentry
= &GdiHandleTable
[Index
];
39 if (pentry
->KernelData
== NULL
||
40 pentry
->KernelData
< (PVOID
)0x80000000 ||
41 (USHORT
)pentry
->FullUnique
!= (USHORT
)((ULONG_PTR
)hobj
>> 16))
46 return pentry
->UserData
;
51 IntSyscall(FARPROC proc
, UINT cParams
, PVOID pFirstParam
)
59 "pushfl;" // Save flags
61 "shl $2, %%eax;" // Calculate param size
62 "subl %%eax, %%esp;" // Calculate new stack pos
63 "movl %%esp, %%edi;" // Destination is stackpointer
64 "cld;" // Clear direction flag
65 "rep movsd;" // Copy params to the stack
66 "call *%%edx;" // Call function
67 "popfl;" // Restore flags
69 : "S" (pFirstParam
), "c" (cParams
), "d"(proc
)
93 Syscall(LPWSTR pszFunction
, int cParams
, void* pParams
)
95 char szFunctionName
[MAX_PATH
];
98 sprintf(szFunctionName
, "%ls", pszFunction
);
99 proc
= (FARPROC
)GetProcAddress(g_hModule
, szFunctionName
);
102 printf("Couldn't find proc: %s\n", szFunctionName
);
106 return IntSyscall(proc
, cParams
, pParams
);
110 IsFunctionPresent(LPWSTR lpszFunction
)
112 char szFunctionName
[MAX_PATH
];
113 sprintf(szFunctionName
, "%ls", lpszFunction
);
114 return (GetProcAddress(g_hModule
, szFunctionName
) != NULL
);
118 WinMain(HINSTANCE hInstance
,
119 HINSTANCE hPrevInstance
,
123 g_hInstance
= hInstance
;
125 printf("Win32k native API test\n");
127 /* Convert to gui thread */
128 // IsGUIThread(TRUE); <- does not exists on win2k
131 printf("g_OsIdx = %d\n", g_OsIdx
);
133 g_hModule
= LoadLibraryW(L
"w32kdll.dll");
136 printf("w32kdll.dll not found!\n");
140 GdiHandleTable
= MyGdiQueryTable();
143 FreeLibrary(g_hModule
);
144 printf("GdiHandleTable not found!\n");
150 return TestMain(L
"w32knapi", L
"win32k.sys Nt-Api");