2008-06-01 18:06:22 +00:00
|
|
|
#include "w32knapi.h"
|
|
|
|
|
|
|
|
HINSTANCE g_hInstance;
|
|
|
|
HMODULE g_hModule = NULL;
|
|
|
|
PGDI_TABLE_ENTRY GdiHandleTable;
|
|
|
|
|
|
|
|
static
|
|
|
|
PGDI_TABLE_ENTRY
|
|
|
|
MyGdiQueryTable()
|
|
|
|
{
|
|
|
|
PTEB pTeb = NtCurrentTeb();
|
|
|
|
PPEB pPeb = pTeb->ProcessEnvironmentBlock;
|
|
|
|
return pPeb->GdiSharedHandleTable;
|
|
|
|
}
|
|
|
|
|
2009-03-24 01:25:03 +00:00
|
|
|
BOOL
|
|
|
|
IsHandleValid(HGDIOBJ hobj)
|
|
|
|
{
|
|
|
|
USHORT Index = (ULONG_PTR)hobj;
|
|
|
|
PGDI_TABLE_ENTRY pentry = &GdiHandleTable[Index];
|
|
|
|
|
|
|
|
if (pentry->KernelData == NULL ||
|
|
|
|
pentry->KernelData < (PVOID)0x80000000 ||
|
|
|
|
(USHORT)pentry->FullUnique != (USHORT)((ULONG_PTR)hobj >> 16))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-08-09 11:27:25 +00:00
|
|
|
PVOID
|
|
|
|
GetHandleUserData(HGDIOBJ hobj)
|
|
|
|
{
|
|
|
|
USHORT Index = (ULONG_PTR)hobj;
|
|
|
|
PGDI_TABLE_ENTRY pentry = &GdiHandleTable[Index];
|
|
|
|
|
|
|
|
if (pentry->KernelData == NULL ||
|
|
|
|
pentry->KernelData < (PVOID)0x80000000 ||
|
|
|
|
(USHORT)pentry->FullUnique != (USHORT)((ULONG_PTR)hobj >> 16))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pentry->UserData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-29 21:37:54 +00:00
|
|
|
static DWORD WINAPI
|
2008-06-01 18:06:22 +00:00
|
|
|
IntSyscall(FARPROC proc, UINT cParams, PVOID pFirstParam)
|
|
|
|
{
|
2009-08-22 14:40:56 +00:00
|
|
|
DWORD retval;
|
2008-06-01 18:06:22 +00:00
|
|
|
|
2009-08-22 14:40:56 +00:00
|
|
|
#ifdef __GNUC__
|
2008-06-01 18:06:22 +00:00
|
|
|
asm volatile
|
|
|
|
(
|
|
|
|
"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
|
2009-08-22 14:40:56 +00:00
|
|
|
: "=a" (retval)
|
2008-06-01 18:06:22 +00:00
|
|
|
: "S" (pFirstParam), "c" (cParams), "d"(proc)
|
|
|
|
: "%edi"
|
|
|
|
);
|
2009-08-22 14:40:56 +00:00
|
|
|
#else
|
|
|
|
__asm
|
|
|
|
{
|
|
|
|
pushf
|
|
|
|
mov eax, cParams
|
|
|
|
shl eax, 2
|
|
|
|
sub esp, eax
|
|
|
|
mov edi, esp
|
|
|
|
cld
|
|
|
|
rep movsd
|
|
|
|
call proc
|
|
|
|
mov retval, eax
|
|
|
|
popf
|
|
|
|
};
|
|
|
|
#endif
|
2008-06-01 18:06:22 +00:00
|
|
|
|
2009-08-22 14:40:56 +00:00
|
|
|
return retval;
|
2008-06-01 18:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
Syscall(LPWSTR pszFunction, int cParams, void* pParams)
|
|
|
|
{
|
|
|
|
char szFunctionName[MAX_PATH];
|
2009-08-22 14:40:56 +00:00
|
|
|
FARPROC proc;
|
2008-06-01 18:06:22 +00:00
|
|
|
|
|
|
|
sprintf(szFunctionName, "%ls", pszFunction);
|
2009-08-22 14:40:56 +00:00
|
|
|
proc = (FARPROC)GetProcAddress(g_hModule, szFunctionName);
|
2008-06-01 18:06:22 +00:00
|
|
|
if (!proc)
|
|
|
|
{
|
|
|
|
printf("Couldn't find proc: %s\n", szFunctionName);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IntSyscall(proc, cParams, pParams);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
IsFunctionPresent(LPWSTR lpszFunction)
|
|
|
|
{
|
|
|
|
char szFunctionName[MAX_PATH];
|
|
|
|
sprintf(szFunctionName, "%ls", lpszFunction);
|
|
|
|
return (GetProcAddress(g_hModule, szFunctionName) != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
int APIENTRY
|
|
|
|
WinMain(HINSTANCE hInstance,
|
|
|
|
HINSTANCE hPrevInstance,
|
|
|
|
LPSTR lpCmdLine,
|
|
|
|
int nCmdShow)
|
|
|
|
{
|
|
|
|
g_hInstance = hInstance;
|
|
|
|
|
|
|
|
printf("Win32k native API test\n");
|
|
|
|
|
|
|
|
/* Convert to gui thread */
|
|
|
|
// IsGUIThread(TRUE); <- does not exists on win2k
|
|
|
|
|
|
|
|
InitOsVersion();
|
|
|
|
printf("g_OsIdx = %d\n", g_OsIdx);
|
|
|
|
|
|
|
|
g_hModule = LoadLibraryW(L"w32kdll.dll");
|
|
|
|
if (!g_hModule)
|
|
|
|
{
|
|
|
|
printf("w32kdll.dll not found!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdiHandleTable = MyGdiQueryTable();
|
|
|
|
if(!GdiHandleTable)
|
|
|
|
{
|
|
|
|
FreeLibrary(g_hModule);
|
|
|
|
printf("GdiHandleTable not found!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
return TestMain(L"w32knapi", L"win32k.sys Nt-Api");
|
|
|
|
}
|