From dd21b8cb1f18fd0ade309af525ad50e4ee38d1fa Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Sat, 16 Mar 2024 11:10:08 +0800 Subject: [PATCH] Fix over again. --- Sandboxie/core/dll/gdi.c | 181 ++++++++++++++++++++------------------- 1 file changed, 91 insertions(+), 90 deletions(-) diff --git a/Sandboxie/core/dll/gdi.c b/Sandboxie/core/dll/gdi.c index c9066823..eda4a1cf 100644 --- a/Sandboxie/core/dll/gdi.c +++ b/Sandboxie/core/dll/gdi.c @@ -323,7 +323,91 @@ _FX BOOL Gui_StretchBlt( } return ret; } -HBITMAP bmp = NULL; +_FX void Gdi_SplWow64(BOOLEAN Register) +{ + // + // see GuiServer::SplWow64Slave + // + + // NoSbieDesk BEGIN + if (Dll_CompartmentMode || SbieApi_QueryConfBool(NULL, L"NoSandboxieDesktop", FALSE)) + return; + // NoSbieDesk END + + GUI_SPLWOW64_REQ req; + void* rpl; + + if (Register) { + + if (Ldr_BoxedImage || _wcsicmp(Dll_ImageName, L"splwow64.exe") != 0) + return; + } + + req.msgid = GUI_SPLWOW64; + req.set = Register; + req.win8 = (Dll_OsBuild >= 8400) ? TRUE : FALSE; + rpl = Gui_CallProxy(&req, sizeof(req), sizeof(ULONG)); + if (rpl) + Dll_Free(rpl); + +} + + +//--------------------------------------------------------------------------- +// Gdi_CreateDCW +//--------------------------------------------------------------------------- + + +#ifndef _WIN64 + +_FX HDC Gdi_CreateDCW2( + void* lpszDriver, void* lpszDevice, void* lpszOutput, void* lpInitData) +{ + // + // on 64-bit Windows 8, some 32-bit programs (Notepad, Chrome) cannot + // create a printer DC (via WINSPOOL) if an instance of SplWow64.exe + // has been terminated, since the last time that 32-bit process has + // connected to SplWow64.exe. the reason for this is not clear, but + // it seems a possible workaround is to try recreating the DC several + // times, until the CreateDC call finally works. + // + + HDC hdc = __sys_CreateDCW( + lpszDriver, lpszDevice, lpszOutput, lpInitData); + + if ((!hdc) && lpszDriver && _wcsicmp(lpszDriver, L"WINSPOOL") == 0) { + + P_DocumentProperties __sys_DocumentProperties = + Ldr_GetProcAddrNew(L"winspool.drv", L"DocumentPropertiesW", "DocumentPropertiesW"); + + ULONG retry = 0; + + while (__sys_DocumentProperties && (!hdc) && (retry < 20)) { + + HANDLE hPrinter; + + Sleep(retry * 25); + + if (!__sys_OpenPrinter2W(lpInitData, &hPrinter, NULL, NULL)) + break; + + __sys_DocumentProperties( + NULL, hPrinter, lpInitData, NULL, NULL, 0); + + hdc = __sys_CreateDCW( + lpszDriver, lpszDevice, lpszOutput, lpInitData); + + __sys_ClosePrinter(hPrinter); + + retry++; + } + } + + return hdc; +} + +#endif ! _WIN64 +HBITMAP bmp2 = NULL; _FX HDC Gui_CreateDCA(LPCSTR pwszDriver, LPCSTR pwszDevice, LPCSTR pszPort, const void* pdm) { HDC ret = __sys_CreateDCA(pwszDriver, pwszDevice, pszPort, pdm); @@ -341,9 +425,9 @@ _FX HDC Gui_CreateDCA(LPCSTR pwszDriver, LPCSTR pwszDevice, LPCSTR pszPort, co iWidth = GetDeviceCaps(ret, HORZRES); iHeight = GetDeviceCaps(ret, VERTRES); HBITMAP hBmp; - if (bmp == NULL) - bmp = CreateCompatibleBitmap(ret2, iWidth, iHeight); - hBmp = bmp; + if (bmp2 == NULL) + bmp2 = CreateCompatibleBitmap(ret2, iWidth, iHeight); + hBmp = bmp2; SelectObject(ret2, hBmp); DeleteDC(ret); ret = ret2; @@ -375,9 +459,9 @@ _FX HDC Gui_CreateDCW(LPCWSTR pwszDriver, LPCWSTR pwszDevice, LPCWSTR pszPort, iWidth = GetDeviceCaps(ret, HORZRES); iHeight = GetDeviceCaps(ret, VERTRES); HBITMAP hBmp; - if (bmp == NULL) - bmp = CreateCompatibleBitmap(ret2, iWidth, iHeight); - hBmp = bmp; + if (bmp2 == NULL) + bmp2 = CreateCompatibleBitmap(ret2, iWidth, iHeight); + hBmp = bmp2; SelectObject(ret2, hBmp); DeleteDC(ret); ret = ret2; @@ -391,90 +475,7 @@ _FX HDC Gui_CreateDCW(LPCWSTR pwszDriver, LPCWSTR pwszDevice, LPCWSTR pszPort, //--------------------------------------------------------------------------- -_FX void Gdi_SplWow64(BOOLEAN Register) -{ - // - // see GuiServer::SplWow64Slave - // - // NoSbieDesk BEGIN - if (Dll_CompartmentMode || SbieApi_QueryConfBool(NULL, L"NoSandboxieDesktop", FALSE)) - return; - // NoSbieDesk END - - GUI_SPLWOW64_REQ req; - void *rpl; - - if (Register) { - - if (Ldr_BoxedImage || _wcsicmp(Dll_ImageName, L"splwow64.exe") != 0) - return; - } - - req.msgid = GUI_SPLWOW64; - req.set = Register; - req.win8 = (Dll_OsBuild >= 8400) ? TRUE : FALSE; - rpl = Gui_CallProxy(&req, sizeof(req), sizeof(ULONG)); - if (rpl) - Dll_Free(rpl); - -} - - -//--------------------------------------------------------------------------- -// Gdi_CreateDCW -//--------------------------------------------------------------------------- - - -#ifndef _WIN64 - -_FX HDC Gdi_CreateDCW2( - void *lpszDriver, void *lpszDevice, void *lpszOutput, void *lpInitData) -{ - // - // on 64-bit Windows 8, some 32-bit programs (Notepad, Chrome) cannot - // create a printer DC (via WINSPOOL) if an instance of SplWow64.exe - // has been terminated, since the last time that 32-bit process has - // connected to SplWow64.exe. the reason for this is not clear, but - // it seems a possible workaround is to try recreating the DC several - // times, until the CreateDC call finally works. - // - - HDC hdc = __sys_CreateDCW( - lpszDriver, lpszDevice, lpszOutput, lpInitData); - - if ((! hdc) && lpszDriver && _wcsicmp(lpszDriver, L"WINSPOOL") == 0) { - - P_DocumentProperties __sys_DocumentProperties = - Ldr_GetProcAddrNew(L"winspool.drv", L"DocumentPropertiesW","DocumentPropertiesW"); - - ULONG retry = 0; - - while (__sys_DocumentProperties && (! hdc) && (retry < 20)) { - - HANDLE hPrinter; - - Sleep(retry * 25); - - if (! __sys_OpenPrinter2W(lpInitData, &hPrinter, NULL, NULL)) - break; - - __sys_DocumentProperties( - NULL, hPrinter, lpInitData, NULL, NULL, 0); - - hdc = __sys_CreateDCW( - lpszDriver, lpszDevice, lpszOutput, lpInitData); - - __sys_ClosePrinter(hPrinter); - - retry++; - } - } - - return hdc; -} - -#endif ! _WIN64 //---------------------------------------------------------------------------