2007-08-02 21:42:37 +00:00
|
|
|
#include "w32knapi.h"
|
|
|
|
|
|
|
|
HINSTANCE g_hInstance;
|
|
|
|
HMODULE g_hModule = NULL;
|
2007-08-28 15:06:36 +00:00
|
|
|
PGDI_TABLE_ENTRY GdiHandleTable;
|
2007-08-02 21:42:37 +00:00
|
|
|
|
2007-12-15 04:35:16 +00:00
|
|
|
static
|
|
|
|
PGDI_TABLE_ENTRY
|
|
|
|
MyGdiQueryTable()
|
|
|
|
{
|
|
|
|
PTEB pTeb = NtCurrentTeb();
|
|
|
|
PPEB pPeb = pTeb->ProcessEnvironmentBlock;
|
|
|
|
return pPeb->GdiSharedHandleTable;
|
|
|
|
}
|
|
|
|
|
2007-08-07 23:13:25 +00:00
|
|
|
static DWORD STDCALL
|
2007-08-24 22:23:44 +00:00
|
|
|
IntSyscall(FARPROC proc, UINT cParams, PVOID pFirstParam)
|
2007-08-07 23:13:25 +00:00
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
2007-10-19 23:01:40 +00:00
|
|
|
asm volatile
|
2007-08-07 23:13:25 +00:00
|
|
|
(
|
|
|
|
"pushfl;" // Save flags
|
|
|
|
"movl %%ecx, %%eax;"
|
|
|
|
"shl $2, %%eax;" // Calculate param size
|
|
|
|
"subl %%eax, %%esp;" // Calculate new stack pos
|
|
|
|
"movl %%esp, %%edi;" // Destination is stackpointer
|
|
|
|
"cld;" // Clear direction flag
|
|
|
|
"rep movsd;" // Copy params to the stack
|
|
|
|
"call *%%edx;" // Call function
|
|
|
|
"popfl;" // Restore flags
|
|
|
|
: "=a" (ret)
|
|
|
|
: "S" (pFirstParam), "c" (cParams), "d"(proc)
|
|
|
|
: "%edi"
|
|
|
|
);
|
|
|
|
|
|
|
|
return ret;
|
2007-08-02 21:42:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
Syscall(LPWSTR pszFunction, int cParams, void* pParams)
|
|
|
|
{
|
2007-08-24 22:23:44 +00:00
|
|
|
char szFunctionName[MAX_PATH];
|
2007-08-07 23:13:25 +00:00
|
|
|
|
2007-08-24 22:23:44 +00:00
|
|
|
sprintf(szFunctionName, "%ls", pszFunction);
|
|
|
|
FARPROC proc = (FARPROC)GetProcAddress(g_hModule, szFunctionName);
|
|
|
|
if (!proc)
|
2007-08-02 21:42:37 +00:00
|
|
|
{
|
2007-08-24 22:23:44 +00:00
|
|
|
printf("Couldn't find proc: %s\n", szFunctionName);
|
|
|
|
return FALSE;
|
2007-08-02 21:42:37 +00:00
|
|
|
}
|
2007-08-24 22:23:44 +00:00
|
|
|
|
|
|
|
return IntSyscall(proc, cParams, pParams);
|
2007-08-02 21:42:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
IsFunctionPresent(LPWSTR lpszFunction)
|
|
|
|
{
|
2007-08-24 22:23:44 +00:00
|
|
|
char szFunctionName[MAX_PATH];
|
|
|
|
sprintf(szFunctionName, "%ls", lpszFunction);
|
|
|
|
return (GetProcAddress(g_hModule, szFunctionName) != NULL);
|
2007-08-02 21:42:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int APIENTRY
|
|
|
|
WinMain(HINSTANCE hInstance,
|
|
|
|
HINSTANCE hPrevInstance,
|
|
|
|
LPSTR lpCmdLine,
|
|
|
|
int nCmdShow)
|
|
|
|
{
|
|
|
|
g_hInstance = hInstance;
|
2007-08-28 15:06:36 +00:00
|
|
|
|
2007-08-02 21:42:37 +00:00
|
|
|
printf("Win32k native API test\n");
|
|
|
|
|
|
|
|
/* Convert to gui thread */
|
2007-08-11 08:52:38 +00:00
|
|
|
// IsGUIThread(TRUE); <- does not exists on win2k
|
2007-08-02 21:42:37 +00:00
|
|
|
|
2008-03-22 03:12:01 +00:00
|
|
|
InitOsVersion();
|
|
|
|
printf("g_OsIdx = %d\n", g_OsIdx);
|
|
|
|
|
2007-08-24 22:23:44 +00:00
|
|
|
g_hModule = LoadLibraryW(L"w32kdll.dll");
|
|
|
|
if (!g_hModule)
|
2007-08-02 21:42:37 +00:00
|
|
|
{
|
2007-08-24 22:23:44 +00:00
|
|
|
printf("w32kdll.dll not found!\n");
|
2007-08-28 15:06:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-12-15 04:35:16 +00:00
|
|
|
GdiHandleTable = MyGdiQueryTable();
|
2007-08-28 15:06:36 +00:00
|
|
|
if(!GdiHandleTable)
|
|
|
|
{
|
2008-05-23 18:14:15 +00:00
|
|
|
FreeLibrary(g_hModule);
|
|
|
|
printf("GdiHandleTable not found!\n");
|
2007-08-28 15:06:36 +00:00
|
|
|
return -1;
|
2007-08-02 21:42:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
2007-08-04 16:51:10 +00:00
|
|
|
return TestMain(L"w32knapi", L"win32k.sys Nt-Api");
|
2007-08-02 21:42:37 +00:00
|
|
|
}
|