mirror of
https://github.com/reactos/reactos.git
synced 2024-08-19 18:02:55 +00:00
[user32]
- Convert LOADUSERAPIHOOK macro to an inline function - Implement ClientLoadLibrary callback from win32k svn path=/branches/GSoC_2011/ThemesSupport/; revision=52648
This commit is contained in:
parent
628b870071
commit
54ac0f497c
|
@ -1482,7 +1482,7 @@ BOOL WINAPI EnableScrollBar( HWND hwnd, UINT nBar, UINT flags )
|
|||
{
|
||||
BOOL Hook, Ret = FALSE;
|
||||
|
||||
LOADUSERAPIHOOK
|
||||
LoadUserApiHook();
|
||||
|
||||
Hook = BeginIfHookedUserApiHook();
|
||||
|
||||
|
@ -1534,7 +1534,7 @@ GetScrollInfo(HWND Wnd, INT SBType, LPSCROLLINFO Info)
|
|||
{
|
||||
BOOL Hook, Ret = FALSE;
|
||||
|
||||
LOADUSERAPIHOOK
|
||||
LoadUserApiHook();
|
||||
|
||||
Hook = BeginIfHookedUserApiHook();
|
||||
|
||||
|
@ -1615,7 +1615,7 @@ SetScrollInfo(HWND Wnd, int SBType, LPCSCROLLINFO Info, BOOL bRedraw)
|
|||
BOOL Hook;
|
||||
INT Ret = 0;
|
||||
|
||||
LOADUSERAPIHOOK
|
||||
LoadUserApiHook();
|
||||
|
||||
Hook = BeginIfHookedUserApiHook();
|
||||
|
||||
|
|
|
@ -45,6 +45,11 @@
|
|||
/* SEH Support with PSEH */
|
||||
#include <pseh/pseh2.h>
|
||||
|
||||
extern PPROCESSINFO g_ppi;
|
||||
extern ULONG_PTR g_ulSharedDelta;
|
||||
extern PSERVERINFO gpsi;
|
||||
extern BOOL gfServerProcess;
|
||||
|
||||
#define HOOKID_TO_FLAG(HookId) (1 << ((HookId) + 1))
|
||||
#define ISITHOOKED(HookId) (GetWin32ClientInfo()->fsHooks & HOOKID_TO_FLAG(HookId) ||\
|
||||
(GetWin32ClientInfo()->pDeskInfo && GetWin32ClientInfo()->pDeskInfo->fsHooks & HOOKID_TO_FLAG(HookId)))
|
||||
|
@ -53,30 +58,38 @@
|
|||
|
||||
extern RTL_CRITICAL_SECTION gcsUserApiHook;
|
||||
extern USERAPIHOOK guah;
|
||||
extern HINSTANCE ghmodUserApiHook;
|
||||
BOOL FASTCALL BeginIfHookedUserApiHook(VOID);
|
||||
BOOL FASTCALL EndUserApiHook(VOID);
|
||||
BOOL FASTCALL IsInsideUserApiHook(VOID);
|
||||
VOID FASTCALL ResetUserApiHook(PUSERAPIHOOK);
|
||||
BOOL FASTCALL IsMsgOverride(UINT,PUAHOWP);
|
||||
BOOL WINAPI InitUserApiHook(HINSTANCE hInstance, USERAPIHOOKPROC pfn);
|
||||
BOOL WINAPI ClearUserApiHook(HINSTANCE hInstance);
|
||||
|
||||
#define LOADUSERAPIHOOK \
|
||||
if (!gfServerProcess && \
|
||||
!IsInsideUserApiHook() && \
|
||||
(gpsi->dwSRVIFlags & SRVINFO_APIHOOK) && \
|
||||
!RtlIsThreadWithinLoaderCallout()) \
|
||||
{ \
|
||||
NtUserCallNoParam(NOPARAM_ROUTINE_LOADUSERAPIHOOK); \
|
||||
} \
|
||||
static __inline void LoadUserApiHook()
|
||||
{
|
||||
if(!(gpsi->dwSRVIFlags & SRVINFO_APIHOOK))
|
||||
return;
|
||||
|
||||
if(IsInsideUserApiHook())
|
||||
return;
|
||||
|
||||
/* HACK! Please remove when gfServerProcess is correct */
|
||||
#if 0
|
||||
if(gfServerProcess)
|
||||
return;
|
||||
#endif
|
||||
if(RtlIsThreadWithinLoaderCallout())
|
||||
return;
|
||||
|
||||
NtUserCallNoParam(NOPARAM_ROUTINE_LOADUSERAPIHOOK);
|
||||
}
|
||||
|
||||
/* FIXME: Use ntgdi.h then cleanup... */
|
||||
LONG WINAPI GdiGetCharDimensions(HDC, LPTEXTMETRICW, LONG *);
|
||||
BOOL FASTCALL IsMetaFile(HDC);
|
||||
|
||||
extern PPROCESSINFO g_ppi;
|
||||
extern ULONG_PTR g_ulSharedDelta;
|
||||
extern PSERVERINFO gpsi;
|
||||
extern BOOL gfServerProcess;
|
||||
|
||||
static __inline PVOID
|
||||
SharedPtrToUser(PVOID Ptr)
|
||||
{
|
||||
|
|
|
@ -113,7 +113,7 @@ GetSystemMetrics(int nIndex)
|
|||
return RealGetSystemMetrics(nIndex);
|
||||
}
|
||||
|
||||
LOADUSERAPIHOOK
|
||||
LoadUserApiHook();
|
||||
|
||||
Hook = BeginIfHookedUserApiHook();
|
||||
|
||||
|
@ -336,7 +336,7 @@ SystemParametersInfoA(UINT uiAction,
|
|||
{
|
||||
BOOL Hook, Ret = FALSE;
|
||||
|
||||
LOADUSERAPIHOOK
|
||||
LoadUserApiHook();
|
||||
|
||||
Hook = BeginIfHookedUserApiHook();
|
||||
|
||||
|
@ -368,7 +368,7 @@ SystemParametersInfoW(UINT uiAction,
|
|||
{
|
||||
BOOL Hook, Ret = FALSE;
|
||||
|
||||
LOADUSERAPIHOOK
|
||||
LoadUserApiHook();
|
||||
|
||||
Hook = BeginIfHookedUserApiHook();
|
||||
|
||||
|
|
|
@ -217,6 +217,8 @@ Init(VOID)
|
|||
(PVOID)User32CallLoadMenuFromKernel;
|
||||
KernelCallbackTable[USER32_CALLBACK_CLIENTTHREADSTARTUP] =
|
||||
(PVOID)User32CallClientThreadSetupFromKernel;
|
||||
KernelCallbackTable[USER32_CALLBACK_CLIENTLOADLIBRARY] =
|
||||
(PVOID)User32CallClientLoadLibraryFromKernel;
|
||||
|
||||
NtUserProcessConnect( NtCurrentProcess(),
|
||||
&UserCon,
|
||||
|
|
|
@ -318,7 +318,7 @@ MDIRedrawFrame(HWND hWnd, DWORD flags)
|
|||
{
|
||||
BOOL Hook, Ret = FALSE;
|
||||
|
||||
LOADUSERAPIHOOK
|
||||
LoadUserApiHook();
|
||||
|
||||
Hook = BeginIfHookedUserApiHook();
|
||||
|
||||
|
|
|
@ -2209,7 +2209,7 @@ DefWindowProcA(HWND hWnd,
|
|||
BOOL Hook, msgOverride = FALSE;
|
||||
LRESULT Result = 0;
|
||||
|
||||
LOADUSERAPIHOOK
|
||||
LoadUserApiHook();
|
||||
|
||||
Hook = BeginIfHookedUserApiHook();
|
||||
if (Hook)
|
||||
|
@ -2242,7 +2242,7 @@ DefWindowProcW(HWND hWnd,
|
|||
BOOL Hook, msgOverride = FALSE;
|
||||
LRESULT Result = 0;
|
||||
|
||||
LOADUSERAPIHOOK
|
||||
LoadUserApiHook();
|
||||
|
||||
Hook = BeginIfHookedUserApiHook();
|
||||
if (Hook)
|
||||
|
|
|
@ -1457,7 +1457,7 @@ DrawFrameControl(HDC hDC, LPRECT rc, UINT uType, UINT uState)
|
|||
{
|
||||
BOOL Hook, Ret = FALSE;
|
||||
|
||||
LOADUSERAPIHOOK
|
||||
LoadUserApiHook();
|
||||
|
||||
Hook = BeginIfHookedUserApiHook();
|
||||
|
||||
|
|
|
@ -427,6 +427,111 @@ SetWindowsHookExW(
|
|||
return IntSetWindowsHook(idHook, lpfn, hMod, dwThreadId, FALSE);
|
||||
}
|
||||
|
||||
HINSTANCE ClientLoadLibrary(PUNICODE_STRING pstrLibName,
|
||||
PUNICODE_STRING pstrInitFunc,
|
||||
BOOL Unload,
|
||||
BOOL ApiHook)
|
||||
{
|
||||
HINSTANCE hLibrary;
|
||||
PVOID pInitFunction;
|
||||
NTSTATUS Status;
|
||||
ANSI_STRING InitFuncName;
|
||||
BOOL Result = FALSE;
|
||||
|
||||
/* Check if we have to load the module */
|
||||
if(Unload == FALSE)
|
||||
{
|
||||
ASSERT(pstrLibName->Buffer != NULL);
|
||||
|
||||
/* Load it */
|
||||
hLibrary = LoadLibrary(pstrLibName->Buffer);
|
||||
if(hLibrary == 0)
|
||||
{
|
||||
return hLibrary;
|
||||
}
|
||||
|
||||
if(ApiHook == FALSE)
|
||||
{
|
||||
/* There is nothing more to do for a global hook*/
|
||||
return hLibrary;
|
||||
}
|
||||
|
||||
/* Initialize the user api hook */
|
||||
ASSERT(pstrInitFunc->Buffer);
|
||||
|
||||
Status = RtlUnicodeStringToAnsiString(&InitFuncName,
|
||||
pstrInitFunc,
|
||||
TRUE);
|
||||
|
||||
/* Get the address of the initialization routine */
|
||||
pInitFunction = GetProcAddress(hLibrary, InitFuncName.Buffer);
|
||||
if(pInitFunction)
|
||||
{
|
||||
/* Call the initialization routine */
|
||||
Result = InitUserApiHook(hLibrary, (USERAPIHOOKPROC)pInitFunction);
|
||||
}
|
||||
RtlFreeAnsiString(&InitFuncName);
|
||||
|
||||
/* In case of error unload the library */
|
||||
if(Result == FALSE)
|
||||
{
|
||||
FreeLibrary(hLibrary);
|
||||
hLibrary = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Cleanup user api hook before unloading */
|
||||
if(ApiHook == TRUE)
|
||||
{
|
||||
Result = ClearUserApiHook(ghmodUserApiHook);
|
||||
hLibrary = Result ? ghmodUserApiHook : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
hLibrary = GetModuleHandle(pstrLibName->Buffer);
|
||||
Result = (hLibrary != 0);
|
||||
}
|
||||
|
||||
if(Result == TRUE)
|
||||
{
|
||||
Result = FreeLibrary(hLibrary);
|
||||
if(Result == FALSE)
|
||||
{
|
||||
hLibrary = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hLibrary;
|
||||
}
|
||||
|
||||
NTSTATUS WINAPI
|
||||
User32CallClientLoadLibraryFromKernel(PVOID Arguments, ULONG ArgumentLength)
|
||||
{
|
||||
HINSTANCE Result;
|
||||
PCLIENT_LOAD_LIBRARY_ARGUMENTS Argument;
|
||||
|
||||
/* Retireve the callback parameters */
|
||||
Argument = (PCLIENT_LOAD_LIBRARY_ARGUMENTS)Arguments;
|
||||
if(Argument->strLibraryName.Buffer != NULL)
|
||||
{
|
||||
Argument->strLibraryName.Buffer = (PWCHAR)((ULONG_PTR)Argument->strLibraryName.Buffer + (ULONG_PTR)Argument);
|
||||
}
|
||||
if(Argument->strInitFuncName.Buffer != NULL)
|
||||
{
|
||||
Argument->strInitFuncName.Buffer = (PWCHAR)((ULONG_PTR)Argument->strInitFuncName.Buffer + (ULONG_PTR)Argument);
|
||||
}
|
||||
|
||||
/* Call the implementation of the callback */
|
||||
Result = ClientLoadLibrary(&Argument->strLibraryName,
|
||||
&Argument->strInitFuncName,
|
||||
Argument->Unload,
|
||||
Argument->ApiHook);
|
||||
|
||||
return ZwCallbackReturn(&Result, sizeof(HINSTANCE), STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
NTSTATUS WINAPI
|
||||
User32CallHookProcFromKernel(PVOID Arguments, ULONG ArgumentLength)
|
||||
{
|
||||
|
|
|
@ -1104,7 +1104,7 @@ AdjustWindowRectEx(LPRECT lpRect,
|
|||
{
|
||||
BOOL Hook, Ret = FALSE;
|
||||
|
||||
LOADUSERAPIHOOK
|
||||
LoadUserApiHook();
|
||||
|
||||
Hook = BeginIfHookedUserApiHook();
|
||||
|
||||
|
@ -1148,7 +1148,7 @@ DrawCaption(HWND hWnd, HDC hDC, LPCRECT lprc, UINT uFlags)
|
|||
{
|
||||
BOOL Hook, Ret = FALSE;
|
||||
|
||||
LOADUSERAPIHOOK
|
||||
LoadUserApiHook();
|
||||
|
||||
Hook = BeginIfHookedUserApiHook();
|
||||
|
||||
|
|
|
@ -200,7 +200,7 @@ SetWindowRgn(
|
|||
BOOL Hook;
|
||||
int Ret = 0;
|
||||
|
||||
LOADUSERAPIHOOK
|
||||
LoadUserApiHook();
|
||||
|
||||
Hook = BeginIfHookedUserApiHook();
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
#define USER32_CALLBACK_EVENTPROC (5)
|
||||
#define USER32_CALLBACK_LOADMENU (6)
|
||||
#define USER32_CALLBACK_CLIENTTHREADSTARTUP (7)
|
||||
#define USER32_CALLBACK_MAXIMUM (7)
|
||||
#define USER32_CALLBACK_CLIENTLOADLIBRARY (8)
|
||||
#define USER32_CALLBACK_MAXIMUM (8)
|
||||
|
||||
typedef struct _WINDOWPROC_CALLBACK_ARGUMENTS
|
||||
{
|
||||
|
@ -76,6 +77,14 @@ typedef struct _LOADMENU_CALLBACK_ARGUMENTS
|
|||
WCHAR MenuName[1];
|
||||
} LOADMENU_CALLBACK_ARGUMENTS, *PLOADMENU_CALLBACK_ARGUMENTS;
|
||||
|
||||
typedef struct _CLIENT_LOAD_LIBRARY_ARGUMENTS
|
||||
{
|
||||
UNICODE_STRING strLibraryName;
|
||||
UNICODE_STRING strInitFuncName;
|
||||
BOOL Unload;
|
||||
BOOL ApiHook;
|
||||
} CLIENT_LOAD_LIBRARY_ARGUMENTS, *PCLIENT_LOAD_LIBRARY_ARGUMENTS;
|
||||
|
||||
NTSTATUS WINAPI
|
||||
User32CallWindowProcFromKernel(PVOID Arguments, ULONG ArgumentLength);
|
||||
NTSTATUS WINAPI
|
||||
|
@ -92,5 +101,6 @@ NTSTATUS WINAPI
|
|||
User32CallLoadMenuFromKernel(PVOID Arguments, ULONG ArgumentLength);
|
||||
NTSTATUS WINAPI
|
||||
User32CallClientThreadSetupFromKernel(PVOID Arguments, ULONG ArgumentLength);
|
||||
|
||||
NTSTATUS WINAPI
|
||||
User32CallClientLoadLibraryFromKernel(PVOID Arguments, ULONG ArgumentLength);
|
||||
#endif /* __INCLUDE_USER32_CALLBACK_H */
|
||||
|
|
Loading…
Reference in a new issue