* Pablo Borobia <pborobia@gmail.com>
*/
-#include <w32k.h>
+#include <win32k.h>
#define NDEBUG
#include <debug.h>
#define DATA_DELAYED_RENDER 0
#define DATA_SYNTHESIZED_RENDER -1
-#define USE_WINSTA \
- PWINSTATION_OBJECT WinStaObj; \
- WinStaObj = PsGetCurrentThreadWin32Thread()->Desktop->WindowStation;
-
-#define WINSTA_ClipboardThread WinStaObj->Clipboard->ClipboardThread
-#define WINSTA_ClipboardOwnerThread WinStaObj->Clipboard->ClipboardOwnerThread
-#define WINSTA_ClipboardWindow WinStaObj->Clipboard->ClipboardWindow
-#define WINSTA_ClipboardViewerWindow WinStaObj->Clipboard->ClipboardViewerWindow
-#define WINSTA_ClipboardOwnerWindow WinStaObj->Clipboard->ClipboardOwnerWindow
-#define WINSTA_sendDrawClipboardMsg WinStaObj->Clipboard->sendDrawClipboardMsg
-#define WINSTA_recentlySetClipboard WinStaObj->Clipboard->recentlySetClipboard
-#define WINSTA_delayedRender WinStaObj->Clipboard->delayedRender
-#define WINSTA_lastEnumClipboardFormats WinStaObj->Clipboard->lastEnumClipboardFormats
-#define WINSTA_ClipboardSequenceNumber WinStaObj->Clipboard->ClipboardSequenceNumber
-#define WINSTA_WindowsChain WinStaObj->Clipboard->WindowsChain
-#define WINSTA_ClipboardData WinStaObj->Clipboard->ClipboardData
-#define WINSTA_synthesizedData WinStaObj->Clipboard->synthesizedData
-#define WINSTA_synthesizedDataSize WinStaObj->Clipboard->synthesizedDataSize
-
-PW32THREAD ClipboardThread;
-PW32THREAD ClipboardOwnerThread;
-PWINDOW_OBJECT ClipboardWindow;
-PWINDOW_OBJECT ClipboardViewerWindow;
-PWINDOW_OBJECT ClipboardOwnerWindow;
+PTHREADINFO ClipboardThread;
+PTHREADINFO ClipboardOwnerThread;
+PWND ClipboardWindow;
+PWND ClipboardViewerWindow;
+PWND ClipboardOwnerWindow;
BOOL sendDrawClipboardMsg;
BOOL recentlySetClipboard;
BOOL delayedRender;
/* return the pointer to the prev window of the finded window,
if NULL does not exists in the chain */
PCLIPBOARDCHAINELEMENT FASTCALL
-IntIsWindowInChain(PWINDOW_OBJECT window)
+IntIsWindowInChain(PWND window)
{
PCLIPBOARDCHAINELEMENT wce = WindowsChain;
return wce;
}
-VOID FASTCALL printChain()
+VOID FASTCALL printChain(VOID)
{
/*test*/
PCLIPBOARDCHAINELEMENT wce2 = WindowsChain;
while (wce2)
{
- DPRINT1("chain: %p\n", wce2->window->hSelf);
+ DPRINT1("chain: %p\n", wce2->window->head.h);
wce2 = wce2->next;
}
}
/* the new window always have to be the first in the chain */
PCLIPBOARDCHAINELEMENT FASTCALL
-IntAddWindowToChain(PWINDOW_OBJECT window)
+IntAddWindowToChain(PWND window)
{
PCLIPBOARDCHAINELEMENT wce = NULL;
{
wce = WindowsChain;
- wce = ExAllocatePool(PagedPool, sizeof(CLIPBOARDCHAINELEMENT));
+ wce = ExAllocatePoolWithTag(PagedPool, sizeof(CLIPBOARDCHAINELEMENT), USERTAG_CLIPBOARD);
if (wce == NULL)
{
SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
}
PCLIPBOARDCHAINELEMENT FASTCALL
-IntRemoveWindowFromChain(PWINDOW_OBJECT window)
+IntRemoveWindowFromChain(PWND window)
{
PCLIPBOARDCHAINELEMENT wce = WindowsChain;
PCLIPBOARDCHAINELEMENT *link = &WindowsChain;
/*==============================================================*/
/* if format exists, returns a non zero value (pointing to format object) */
PCLIPBOARDELEMENT FASTCALL
-intIsFormatAvailable(format)
+intIsFormatAvailable(UINT format)
{
PCLIPBOARDELEMENT ret = NULL;
PCLIPBOARDELEMENT ce = ClipboardData;
/* counts how many distinct format were are in the clipboard */
DWORD FASTCALL
-IntCountClipboardFormats()
+IntCountClipboardFormats(VOID)
{
DWORD ret = 0;
PCLIPBOARDELEMENT ce = ClipboardData;
{
PCLIPBOARDELEMENT ce = NULL;
- ce = ExAllocatePool(PagedPool, sizeof(CLIPBOARDELEMENT));
+ ce = ExAllocatePoolWithTag(PagedPool, sizeof(CLIPBOARDELEMENT), USERTAG_CLIPBOARD);
if (ce == NULL)
{
SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
}
VOID FASTCALL
-IntEmptyClipboardData()
+IntEmptyClipboardData(VOID)
{
PCLIPBOARDELEMENT ce = ClipboardData;
PCLIPBOARDELEMENT tmp;
while(ce)
{
tmp = ce->next;
- ExFreePool(ce->hData);
+ if (ce->hData)
+ {
+ ExFreePool(ce->hData);
+ }
ExFreePool(ce);
ce = tmp;
}
/*==============================================================*/
HANDLE FASTCALL
-renderBITMAPfromDIB(LPBYTE hDIB)
+renderBITMAPfromDIB(LPBYTE pDIB)
{
HDC hdc;
HBITMAP hbitmap;
- unsigned int offset;
- BITMAPINFOHEADER *ih;
+ PBITMAPINFO pBmi, pConvertedBmi = NULL;
+ NTSTATUS Status ;
+ UINT offset = 0; /* Stupid compiler */
+
+ pBmi = (BITMAPINFO*)pDIB;
//hdc = UserGetDCEx(NULL, NULL, DCX_USESTYLE);
hdc = UserGetDCEx(ClipboardWindow, NULL, DCX_USESTYLE);
- ih = (BITMAPINFOHEADER *)hDIB;
-
- offset = sizeof(BITMAPINFOHEADER) + ((ih->biBitCount <= 8) ? (sizeof(RGBQUAD) * (1 << ih->biBitCount)) : 0);
-
- hbitmap = NtGdiCreateDIBitmapInternal(hdc,
- ih->biWidth,
- ih->biHeight,
- CBM_INIT,
- (LPBYTE)ih+offset,
- (LPBITMAPINFO)ih,
- DIB_RGB_COLORS,
- ih->biBitCount,
- ih->biSizeImage,
- 0,
- 0);
+ /* Probe it */
+ _SEH2_TRY
+ {
+ ProbeForRead(&pBmi->bmiHeader.biSize, sizeof(DWORD), 1);
+ ProbeForRead(pBmi, pBmi->bmiHeader.biSize, 1);
+ ProbeForRead(pBmi, DIB_BitmapInfoSize(pBmi, DIB_RGB_COLORS), 1);
+ pConvertedBmi = DIB_ConvertBitmapInfo(pBmi, DIB_RGB_COLORS);
+ if(!pConvertedBmi)
+ {
+ Status = STATUS_INVALID_PARAMETER;
+ }
+ else
+ {
+ offset = DIB_BitmapInfoSize((BITMAPINFO*)pBmi, DIB_RGB_COLORS);
+ ProbeForRead(pDIB + offset, pConvertedBmi->bmiHeader.biSizeImage, 1);
+ }
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ Status = _SEH2_GetExceptionCode();
+ }
+ _SEH2_END
+
+ if(!NT_SUCCESS(Status))
+ {
+ UserReleaseDC(ClipboardWindow, hdc, FALSE);
+ return NULL;
+ }
+
+ hbitmap = GreCreateDIBitmapInternal(hdc,
+ pConvertedBmi->bmiHeader.biWidth,
+ pConvertedBmi->bmiHeader.biHeight,
+ CBM_INIT,
+ pDIB+offset,
+ pConvertedBmi,
+ DIB_RGB_COLORS,
+ 0,
+ 0);
//UserReleaseDC(NULL, hdc, FALSE);
UserReleaseDC(ClipboardWindow, hdc, FALSE);
+ DIB_FreeConvertedBitmapInfo(pConvertedBmi, pBmi);
+
return hbitmap;
}
}
VOID FASTCALL
-freeSynthesizedData()
+freeSynthesizedData(VOID)
{
ExFreePool(synthesizedData);
}
/*==============================================================*/
BOOL FASTCALL
-intIsClipboardOpenByMe()
+intIsClipboardOpenByMe(VOID)
{
/* check if we open the clipboard */
if (ClipboardThread && ClipboardThread == PsGetCurrentThreadWin32Thread())
/* IntClipboardFreeWindow it's called when a window was destroyed */
VOID FASTCALL
-IntClipboardFreeWindow(PWINDOW_OBJECT window)
+IntClipboardFreeWindow(PWND window)
{
/* called from co_UserFreeWindow in window.c */
/* check if clipboard is not locked by this window, if yes, unlock it */
}
}
-BOOL STDCALL
+BOOL APIENTRY
NtUserOpenClipboard(HWND hWnd, DWORD Unknown1)
{
- PWINDOW_OBJECT Window;
+ PWND Window;
BOOL ret = FALSE;
UserEnterExclusive();
{
if (ClipboardOwnerWindow)
{
- if (ClipboardOwnerWindow->hSelf == hWnd)
+ if (ClipboardOwnerWindow->head.h == hWnd)
{
ret = TRUE;
}
return ret;
}
-BOOL STDCALL
+BOOL APIENTRY
NtUserCloseClipboard(VOID)
{
BOOL ret = FALSE;
return ret;
}
-HWND STDCALL
+HWND APIENTRY
NtUserGetOpenClipboardWindow(VOID)
{
HWND ret = NULL;
if (ClipboardWindow)
{
- ret = ClipboardWindow->hSelf;
+ ret = ClipboardWindow->head.h;
}
UserLeave();
return ret;
}
-BOOL STDCALL
+BOOL APIENTRY
NtUserChangeClipboardChain(HWND hWndRemove, HWND hWndNewNext)
{
BOOL ret = FALSE;
PCLIPBOARDCHAINELEMENT w = NULL;
- PWINDOW_OBJECT removeWindow;
+ PWND removeWindow;
UserEnterExclusive();
removeWindow = UserGetWindowObject(hWndRemove);
// then they do the chain
/* WindowsChain->window may be NULL */
- LPARAM lparam = WindowsChain->window == NULL ? 0 : (LPARAM)WindowsChain->window->hSelf;
- DPRINT1("Message: WM_CHANGECBCHAIN to %p", WindowsChain->window->hSelf);
- co_IntSendMessage(WindowsChain->window->hSelf, WM_CHANGECBCHAIN, (WPARAM)hWndRemove, lparam);
+ LPARAM lparam = WindowsChain->window == NULL ? 0 : (LPARAM)WindowsChain->window->head.h;
+ DPRINT1("Message: WM_CHANGECBCHAIN to %p", WindowsChain->window->head.h);
+ co_IntSendMessage(WindowsChain->window->head.h, WM_CHANGECBCHAIN, (WPARAM)hWndRemove, lparam);
}
UserLeave();
return ret;
}
-DWORD STDCALL
+DWORD APIENTRY
NtUserCountClipboardFormats(VOID)
{
DWORD ret = 0;
return ret;
}
-DWORD STDCALL
+DWORD APIENTRY
NtUserEmptyClipboard(VOID)
{
BOOL ret = FALSE;
if (ret && ClipboardOwnerWindow)
{
- DPRINT("Clipboard: WM_DESTROYCLIPBOARD to %p", ClipboardOwnerWindow->hSelf);
- co_IntSendMessage( ClipboardOwnerWindow->hSelf, WM_DESTROYCLIPBOARD, 0, 0);
+ DPRINT("Clipboard: WM_DESTROYCLIPBOARD to %p", ClipboardOwnerWindow->head.h);
+ co_IntSendMessage( ClipboardOwnerWindow->head.h, WM_DESTROYCLIPBOARD, 0, 0);
}
UserLeave();
return ret;
}
-HANDLE STDCALL
-NtUserGetClipboardData(UINT uFormat, DWORD Unknown1)
+HANDLE APIENTRY
+NtUserGetClipboardData(UINT uFormat, PVOID pBuffer)
{
HANDLE ret = NULL;
- PCHAR buffer;
UserEnterShared();
if (intIsClipboardOpenByMe())
{
/* when Unknown1 is zero, we returns to user32 the data size */
- if (Unknown1 == 0)
+ if (!pBuffer)
{
PCLIPBOARDELEMENT data = intIsFormatAvailable(uFormat);
/* tell owner what data needs to be rendered */
if (ClipboardOwnerWindow)
{
- ASSERT(ClipboardOwnerWindow->hSelf);
- co_IntSendMessage(ClipboardOwnerWindow->hSelf, WM_RENDERFORMAT, (WPARAM)uFormat, 0);
+ ASSERT(ClipboardOwnerWindow->head.h);
+ co_IntSendMessage(ClipboardOwnerWindow->head.h, WM_RENDERFORMAT, (WPARAM)uFormat, 0);
data = intIsFormatAvailable(uFormat);
ASSERT(data->size);
- ret = (HANDLE)data->size;
+ ret = (HANDLE)(ULONG_PTR)data->size;
}
}
else
}
}
- ret = (HANDLE)data->size;
+ ret = (HANDLE)(ULONG_PTR)data->size;
}
else
{
}
else
{
- buffer = (PCHAR)Unknown1;
- memcpy(buffer, (PCHAR)synthesizedData, synthesizedDataSize);
+ ret = (HANDLE)pBuffer;
- freeSynthesizedData();
+ _SEH2_TRY
+ {
+ ProbeForWrite(pBuffer, synthesizedDataSize, 1);
+ memcpy(pBuffer, (PCHAR)synthesizedData, synthesizedDataSize);
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ ret = NULL;
+ }
+ _SEH2_END
- ret = (HANDLE)Unknown1;
+ freeSynthesizedData();
}
}
else
{
- buffer = (PCHAR)Unknown1;
- memcpy(buffer, (PCHAR)data->hData, data->size);
+ ret = (HANDLE)pBuffer;
- ret = (HANDLE)Unknown1;
+ _SEH2_TRY
+ {
+ ProbeForWrite(pBuffer, data->size, 1);
+ memcpy(pBuffer, (PCHAR)data->hData, data->size);
+ }
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+ {
+ ret = NULL;
+ }
+ _SEH2_END
}
}
return ret;
}
-INT STDCALL
+INT APIENTRY
NtUserGetClipboardFormatName(UINT format, PUNICODE_STRING FormatName,
INT cchMaxCount)
{
return 0;
}
- _SEH_TRY
+ _SEH2_TRY
{
ProbeForWriteUnicodeString(FormatName);
sFormatName = *(volatile UNICODE_STRING *)FormatName;
ret = 0;
}
}
- _SEH_HANDLE
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- SetLastNtError(_SEH_GetExceptionCode());
+ SetLastNtError(_SEH2_GetExceptionCode());
}
- _SEH_END;
+ _SEH2_END;
return ret;
}
-HWND STDCALL
+HWND APIENTRY
NtUserGetClipboardOwner(VOID)
{
HWND ret = NULL;
if (ClipboardOwnerWindow)
{
- ret = ClipboardOwnerWindow->hSelf;
+ ret = ClipboardOwnerWindow->head.h;
}
UserLeave();
return ret;
}
-HWND STDCALL
+HWND APIENTRY
NtUserGetClipboardViewer(VOID)
{
HWND ret = NULL;
if (WindowsChain)
{
- ret = WindowsChain->window->hSelf;
+ ret = WindowsChain->window->head.h;
}
UserLeave();
return ret;
}
-INT STDCALL
+INT APIENTRY
NtUserGetPriorityClipboardFormat(UINT *paFormatPriorityList, INT cFormats)
{
INT i;
UserEnterExclusive();
- _SEH_TRY
+ _SEH2_TRY
{
if (IntCountClipboardFormats() == 0)
{
}
}
- _SEH_HANDLE
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- SetLastNtError(_SEH_GetExceptionCode());
+ SetLastNtError(_SEH2_GetExceptionCode());
}
- _SEH_END;
+ _SEH2_END;
UserLeave();
}
-BOOL STDCALL
+BOOL APIENTRY
NtUserIsClipboardFormatAvailable(UINT format)
{
BOOL ret = FALSE;
-HANDLE STDCALL
+HANDLE APIENTRY
NtUserSetClipboardData(UINT uFormat, HANDLE hMem, DWORD size)
{
HANDLE hCBData = NULL;
if (hMem)
{
- _SEH_TRY
+ _SEH2_TRY
{
ProbeForRead(hMem, size, 1);
}
- _SEH_HANDLE
+ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
- SetLastNtError(_SEH_GetExceptionCode());
- _SEH_YIELD(goto exit_setCB);
+ SetLastNtError(_SEH2_GetExceptionCode());
+ _SEH2_YIELD(goto exit_setCB);
}
- _SEH_END;
+ _SEH2_END;
if (intIsClipboardOpenByMe())
{
if (!canSinthesize(uFormat))
{
- hCBData = ExAllocatePool(PagedPool, size);
+ hCBData = ExAllocatePoolWithTag(PagedPool, size, USERTAG_CLIPBOARD);
memcpy(hCBData, hMem, size);
intAddFormatedData(uFormat, hCBData, size);
DPRINT1("Data stored\n");
{
//TODO : sinthesize CF_UNICODETEXT & CF_OEMTEXT
// CF_TEXT -> CF_UNICODETEXT
- RtlAnsiStringToUnicodeString(&unicodeString, hCBData, TRUE);
+ ansiString.Buffer = hCBData;
+ ansiString.Length = size;
+ RtlAnsiStringToUnicodeString(&unicodeString, &ansiString, TRUE);
intAddFormatedData(CF_UNICODETEXT, unicodeString.Buffer, unicodeString.Length * sizeof(WCHAR));
// CF_TEXT -> CF_OEMTEXT
RtlUnicodeStringToOemString(&oemString, &unicodeString, TRUE);
// because pallette information may change
HDC hdc;
- INT ret;
BITMAP bm;
BITMAPINFO bi;
- BITMAPOBJ *BitmapObj;
+ SURFACE *psurf;
hdc = UserGetDCEx(NULL, NULL, DCX_USESTYLE);
- BitmapObj = BITMAPOBJ_LockBitmap(hMem);
- BITMAP_GetObject(BitmapObj, sizeof(BITMAP), (LPSTR)&bm);
- if(BitmapObj)
+ psurf = SURFACE_LockSurface(hMem);
+ BITMAP_GetObject(psurf, sizeof(BITMAP), (PVOID)&bm);
+ if(psurf)
{
- BITMAPOBJ_UnlockBitmap(BitmapObj);
+ SURFACE_UnlockSurface(psurf);
}
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biYPelsPerMeter = 0;
bi.bmiHeader.biClrUsed = 0;
- ret = NtGdiGetDIBitsInternal(hdc, hMem, 0, bm.bmHeight, NULL, &bi, DIB_RGB_COLORS, 0, 0);
+ NtGdiGetDIBitsInternal(hdc, hMem, 0, bm.bmHeight, NULL, &bi, DIB_RGB_COLORS, 0, 0);
size = bi.bmiHeader.biSizeImage + sizeof(BITMAPINFOHEADER);
- hCBData = ExAllocatePool(PagedPool, size);
+ hCBData = ExAllocatePoolWithTag(PagedPool, size, USERTAG_CLIPBOARD);
memcpy(hCBData, &bi, sizeof(BITMAPINFOHEADER));
- ret = NtGdiGetDIBitsInternal(hdc, hMem, 0, bm.bmHeight, (LPBYTE)hCBData + sizeof(BITMAPINFOHEADER), &bi, DIB_RGB_COLORS, 0, 0);
+ NtGdiGetDIBitsInternal(hdc, hMem, 0, bm.bmHeight, (LPBYTE)hCBData + sizeof(BITMAPINFOHEADER), &bi, DIB_RGB_COLORS, 0, 0);
UserReleaseDC(NULL, hdc, FALSE);
return hMem;
}
-HWND STDCALL
+HWND APIENTRY
NtUserSetClipboardViewer(HWND hWndNewViewer)
{
HWND ret = NULL;
PCLIPBOARDCHAINELEMENT newWC = NULL;
- PWINDOW_OBJECT window;
+ PWND window;
UserEnterExclusive();
if (newWC->next)
{
// return the next HWND available window in the chain
- ret = newWC->next->window->hSelf;
+ ret = newWC->next->window->head.h;
}
}
}
return ret;
}
-UINT STDCALL
+UINT APIENTRY
IntEnumClipboardFormats(UINT uFormat)
{
UINT ret = 0;
VOID FASTCALL
IntIncrementSequenceNumber(VOID)
{
+ PTHREADINFO pti;
+ PWINSTATION_OBJECT WinStaObj;
- USE_WINSTA
-
- WINSTA_ClipboardSequenceNumber++;
+ pti = PsGetCurrentThreadWin32Thread();
+ WinStaObj = pti->rpdesk->rpwinstaParent;
+ WinStaObj->Clipboard->ClipboardSequenceNumber++;
}
-DWORD STDCALL
+DWORD APIENTRY
NtUserGetClipboardSequenceNumber(VOID)
{
//windowstation sequence number
WinSta = UserGetProcessWindowStation();
- Status = IntValidateWindowStationHandle(WinSta, UserMode, WINSTA_ACCESSCLIPBOARD, &WinStaObj);
+ Status = IntValidateWindowStationHandle(WinSta, KernelMode, WINSTA_ACCESSCLIPBOARD, &WinStaObj);
if (!NT_SUCCESS(Status))
{
/**************** VISTA FUNCTIONS******************/
-BOOL STDCALL NtUserAddClipboardFormatListener(
+BOOL APIENTRY NtUserAddClipboardFormatListener(
HWND hwnd
)
{
return FALSE;
}
-BOOL STDCALL NtUserRemoveClipboardFormatListener(
+BOOL APIENTRY NtUserRemoveClipboardFormatListener(
HWND hwnd
)
{
return FALSE;
}
-BOOL STDCALL NtUserGetUpdatedClipboardFormats(
+BOOL APIENTRY NtUserGetUpdatedClipboardFormats(
PUINT lpuiFormats,
UINT cFormats,
PUINT pcFormatsOut