diff --git a/Sandboxie/core/dll/gdi.c b/Sandboxie/core/dll/gdi.c index 64aa275c..73f821ad 100644 --- a/Sandboxie/core/dll/gdi.c +++ b/Sandboxie/core/dll/gdi.c @@ -44,7 +44,7 @@ static ULONG_PTR Gdi_GdiDllInitialize_Common( #ifndef _WIN64 -static HDC Gdi_CreateDCW( +static HDC Gdi_CreateDCW2( void *lpszDriver, void *lpszDevice, void *lpszOutput, void *lpInitData); #endif ! _WIN64 @@ -78,6 +78,8 @@ static int Gdi_EnumFontFamiliesExW( static HGDIOBJ Gdi_GetStockObject(int fnObject); + + //--------------------------------------------------------------------------- #ifndef _WIN64 @@ -92,9 +94,12 @@ static BOOL Gdi_ClosePrinter(HANDLE hPrinter); //--------------------------------------------------------------------------- -typedef HDC (*P_CreateDCW)( - void *lpszDriver, void *lpszDevice, void *lpszOutput, void *lpInitData); +//typedef HDC (*P_CreateDCW)( + // void *lpszDriver, void *lpszDevice, void *lpszOutput, void *lpInitData); +typedef HDC(*P_CreateDCA)(LPCSTR pwszDriver, LPCSTR pwszDevice, LPCSTR pszPort, const void* pdm); +typedef HDC(*P_CreateDCW)(LPCWSTR pwszDriver, LPCWSTR pwszDevice, LPCWSTR pszPort, const void* pdm); +extern P_CreateDCW __sys_CreateDCW; typedef ULONG (*P_GdiAddFontResourceW)( const WCHAR *path, ULONG flags, void *reserved); @@ -144,6 +149,11 @@ P_GetBitmapBits __sys_GetBitmapBits = NULL; P_DeleteObject __sys_DeleteObject = NULL; P_DeleteEnhMetaFile __sys_DeleteEnhMetaFile = NULL; P_GetStockObject __sys_GetStockObject = NULL; +P_CreateDCA __sys_CreateDCA=NULL; +P_DeleteDC __sys_DeleteDC = NULL; +P_BitBlt __sys_BitBlt = NULL; +P_StretchBlt __sys_StretchBlt = NULL; +P_TransparentBlt __sys_TransparentBlt = NULL; //--------------------------------------------------------------------------- @@ -263,38 +273,96 @@ _FX ULONG_PTR Gdi_GdiDllInitialize_Common( return rc; } +//--------------------------------------------------------------------------- +// Gui_BitBlt +// -------------------------------------------------------------------------- +_FX BOOL Gui_DeleteDC(HDC hdc) { + return __sys_DeleteDC(hdc); +} + +_FX BOOL Gui_BitBlt( + HDC hdc, + int x, + int y, + int cx, + int cy, + HDC hdcSrc, + int x1, + int y1, + DWORD rop +) { + int ret = __sys_BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop); + /*if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) { + + typedef int (*P_GetDeviceCaps)(_In_opt_ HDC hdc, _In_ int index); + P_GetDeviceCaps GetDeviceCaps = Ldr_GetProcAddrNew(DllName_gdi32, "GetDeviceCaps", "GetDeviceCaps"); if (!GetDeviceCaps) return ret; + int iWidth = GetDeviceCaps(hdc, HORZRES), iHeight = GetDeviceCaps(hdc, VERTRES); + int iWidth2 = GetDeviceCaps(__sys_GetDC(NULL), HORZRES), iHeight2 = GetDeviceCaps(__sys_GetDC(NULL), VERTRES); + if (iWidth == iWidth2 && iHeight == iHeight2) { + __sys_BitBlt(__sys_GetDC(NULL), x, y, cx, cy, hdcSrc, x1, y1, rop); + } + }*/ + return ret; +} + +_FX BOOL Gui_StretchBlt( + HDC hdcDest, + int xDest, + int yDest, + int wDest, + int hDest, + HDC hdcSrc, + int xSrc, + int ySrc, + int wSrc, + int hSrc, + DWORD rop +) +{ + int ret = __sys_StretchBlt(hdcDest, xDest, yDest, wDest, hDest, hdcSrc, xSrc, ySrc, wSrc, hSrc, rop); + /*if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) { + + typedef int (*P_GetDeviceCaps)(_In_opt_ HDC hdc, _In_ int index); + P_GetDeviceCaps GetDeviceCaps = Ldr_GetProcAddrNew(DllName_gdi32, "GetDeviceCaps", "GetDeviceCaps"); if (!GetDeviceCaps) return ret; + int iWidth = GetDeviceCaps(hdcDest, HORZRES), iHeight = GetDeviceCaps(hdcDest, VERTRES); + int iWidth2 = GetDeviceCaps(__sys_GetDC(NULL), HORZRES), iHeight2 = GetDeviceCaps(__sys_GetDC(NULL), VERTRES); + if (iWidth == iWidth2 && iHeight == iHeight2) { + __sys_StretchBlt(__sys_GetDC(NULL), xDest, yDest, wDest, hDest, hdcSrc, xSrc, ySrc, wSrc, hSrc, rop); + } + }*/ + return ret; +} //--------------------------------------------------------------------------- // Gdi_SplWow64 //--------------------------------------------------------------------------- - _FX void Gdi_SplWow64(BOOLEAN Register) { - // - // see GuiServer::SplWow64Slave - // + // + // see GuiServer::SplWow64Slave + // - // NoSbieDesk BEGIN - if (Dll_CompartmentMode || SbieApi_QueryConfBool(NULL, L"NoSandboxieDesktop", FALSE)) - return; + // NoSbieDesk BEGIN + if (Dll_CompartmentMode || SbieApi_QueryConfBool(NULL, L"NoSandboxieDesktop", FALSE)) + return; // NoSbieDesk END - GUI_SPLWOW64_REQ req; - void *rpl; + GUI_SPLWOW64_REQ req; + void* rpl; - if (Register) { + if (Register) { - if (Ldr_BoxedImage || _wcsicmp(Dll_ImageName, L"splwow64.exe") != 0) - return; - } + 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); + 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); } @@ -306,53 +374,136 @@ _FX void Gdi_SplWow64(BOOLEAN Register) #ifndef _WIN64 -_FX HDC Gdi_CreateDCW( - void *lpszDriver, void *lpszDevice, void *lpszOutput, void *lpInitData) +_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. - // + // + // 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); + HDC hdc = __sys_CreateDCW( + lpszDriver, lpszDevice, lpszOutput, lpInitData); - if ((! hdc) && lpszDriver && _wcsicmp(lpszDriver, L"WINSPOOL") == 0) { + if ((!hdc) && lpszDriver && _wcsicmp(lpszDriver, L"WINSPOOL") == 0) { - P_DocumentProperties __sys_DocumentProperties = - Ldr_GetProcAddrNew(L"winspool.drv", L"DocumentPropertiesW","DocumentPropertiesW"); + P_DocumentProperties __sys_DocumentProperties = + Ldr_GetProcAddrNew(L"winspool.drv", L"DocumentPropertiesW", "DocumentPropertiesW"); - ULONG retry = 0; + ULONG retry = 0; - while (__sys_DocumentProperties && (! hdc) && (retry < 20)) { + while (__sys_DocumentProperties && (!hdc) && (retry < 20)) { - HANDLE hPrinter; + HANDLE hPrinter; - Sleep(retry * 25); + Sleep(retry * 25); - if (! __sys_OpenPrinter2W(lpInitData, &hPrinter, NULL, NULL)) - break; + if (!__sys_OpenPrinter2W(lpInitData, &hPrinter, NULL, NULL)) + break; - __sys_DocumentProperties( - NULL, hPrinter, lpInitData, NULL, NULL, 0); + __sys_DocumentProperties( + NULL, hPrinter, lpInitData, NULL, NULL, 0); - hdc = __sys_CreateDCW( - lpszDriver, lpszDevice, lpszOutput, lpInitData); + hdc = __sys_CreateDCW( + lpszDriver, lpszDevice, lpszOutput, lpInitData); - __sys_ClosePrinter(hPrinter); + __sys_ClosePrinter(hPrinter); - retry++; - } - } + retry++; + } + } - return hdc; + 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); + + if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) { + + if (pwszDevice == NULL && strcmp(pwszDriver, "DISPLAY") == 0) { + + typedef HDC(*P_CreateCompatibleDC)(HDC hdc); + //typedef BOOL(*P_DeleteDC)(HDC hdc); + GET_WIN_API(CreateCompatibleDC, DllName_gdi32); + typedef HBITMAP (*P_CreateCompatibleBitmap)(_In_ HDC hdc, _In_ int cx, _In_ int cy); + GET_WIN_API(CreateCompatibleBitmap, DllName_gdi32); + GET_WIN_API(DeleteDC, DllName_gdi32); + + typedef HGDIOBJ(*P_SelectObject)(_In_ HDC hdc, _In_ HGDIOBJ h); + GET_WIN_API(SelectObject, DllName_gdi32); + typedef int (*P_GetDeviceCaps)(_In_opt_ HDC hdc, _In_ int index); + GET_WIN_API(GetDeviceCaps, DllName_gdi32); + + int iWidth, iHeight; + + HDC ret2 = CreateCompatibleDC(ret); + iWidth = GetDeviceCaps(ret, HORZRES); + iHeight = GetDeviceCaps(ret, VERTRES); + HBITMAP hBmp; + if (bmp2 == NULL) + bmp2 = CreateCompatibleBitmap(ret2, iWidth, iHeight); + hBmp = bmp2; + SelectObject(ret2, hBmp); + DeleteDC(ret); + ret = ret2; + } + } + return ret; +} +_FX HDC Gui_CreateDCW(LPCWSTR pwszDriver, LPCWSTR pwszDevice, LPCWSTR pszPort, const void* pdm) { + void* pdm2=NULL; + memcpy(pdm2, pdm, sizeof(pdm)); +#ifdef _WIN64 + HDC ret = __sys_CreateDCW(pwszDriver, pwszDevice, pszPort, pdm); +#else + HDC ret = Gdi_CreateDCW2((void*)pwszDriver, (void*)pwszDevice, (void*)pszPort, pdm2); +#endif // _WIN64 + + + + + if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) { + + if (pwszDevice == NULL && lstrcmp(pwszDriver, L"DISPLAY") == 0) { + + typedef HDC(*P_CreateCompatibleDC)(HDC hdc); + //typedef BOOL(*P_DeleteDC)(HDC hdc); + GET_WIN_API(CreateCompatibleDC, DllName_gdi32); + typedef HBITMAP(*P_CreateCompatibleBitmap)(_In_ HDC hdc, _In_ int cx, _In_ int cy); + GET_WIN_API(CreateCompatibleBitmap, DllName_gdi32); + GET_WIN_API(DeleteDC, DllName_gdi32); + + typedef HGDIOBJ(*P_SelectObject)(_In_ HDC hdc, _In_ HGDIOBJ h); + GET_WIN_API(SelectObject, DllName_gdi32); + typedef int (*P_GetDeviceCaps)(_In_opt_ HDC hdc, _In_ int index); + GET_WIN_API(GetDeviceCaps, DllName_gdi32); + int iWidth, iHeight; + + HDC ret2 = CreateCompatibleDC(ret); + iWidth = GetDeviceCaps(ret, HORZRES); + iHeight = GetDeviceCaps(ret, VERTRES); + HBITMAP hBmp; + if (bmp2 == NULL) + bmp2 = CreateCompatibleBitmap(ret2, iWidth, iHeight); + hBmp = bmp2; + SelectObject(ret2, hBmp); + DeleteDC(ret); + ret = ret2; + } + } + return ret; +} + + + + //--------------------------------------------------------------------------- @@ -786,6 +937,10 @@ _FX BOOLEAN Gdi_Full_Init_impl(HMODULE module, BOOLEAN full) P_RemoveFontResourceExW RemoveFontResourceExW; P_GetFontResourceInfoW GetFontResourceInfoW; P_CreateScalableFontResourceW CreateScalableFontResourceW; + P_BitBlt BitBlt; + P_StretchBlt StretchBlt; + P_CreateDCA CreateDCA; + P_DeleteDC DeleteDC; P_EnumFontFamiliesEx EnumFontFamiliesExA; P_EnumFontFamiliesEx EnumFontFamiliesExW; @@ -811,6 +966,18 @@ _FX BOOLEAN Gdi_Full_Init_impl(HMODULE module, BOOLEAN full) GetFontResourceInfoW = (P_GetFontResourceInfoW) GetProcAddress(module, "GetFontResourceInfoW"); + CreateDCA = (P_CreateDCA) + GetProcAddress(module, "CreateDCA"); + + BitBlt = (P_BitBlt) + GetProcAddress(module, "BitBlt"); + + StretchBlt = (P_StretchBlt) + GetProcAddress(module, "StretchBlt"); + + DeleteDC = (P_DeleteDC) + GetProcAddress(module, "DeleteDC"); + if (full) { CreateScalableFontResourceW = (P_CreateScalableFontResourceW) GetProcAddress(module, "CreateScalableFontResourceWImpl"); @@ -820,18 +987,25 @@ _FX BOOLEAN Gdi_Full_Init_impl(HMODULE module, BOOLEAN full) GetProcAddress(module, "CreateScalableFontResourceW"); } -#ifndef _WIN64 +/*#ifndef _WIN64 if (Dll_OsBuild >= 8400) { SBIEDLL_HOOK(Gdi_, CreateDCW); } -#endif ! _WIN64 +#endif ! _WIN64*/ SBIEDLL_HOOK(Gdi_, GdiAddFontResourceW); SBIEDLL_HOOK(Gdi_, RemoveFontResourceExW); + //SBIEDLL_HOOK(Gui_,DeleteDC); + //SBIEDLL_HOOK(Gui_,BitBlt); + //SBIEDLL_HOOK(Gui_,StretchBlt); + //SBIEDLL_HOOK_GUI(TransparentBlt); + SBIEDLL_HOOK(Gui_,CreateDCA); + SBIEDLL_HOOK(Gui_,CreateDCW); + if (GetFontResourceInfoW) { SBIEDLL_HOOK(Gdi_, GetFontResourceInfoW); } diff --git a/Sandboxie/core/dll/gui.c b/Sandboxie/core/dll/gui.c index 8f88587f..59b2790a 100644 --- a/Sandboxie/core/dll/gui.c +++ b/Sandboxie/core/dll/gui.c @@ -334,6 +334,52 @@ static DWORD Gui_WaitForInputIdle(HANDLE hProcess, DWORD dwMilliseconds); static BOOL Gui_AttachThreadInput(DWORD idAttach, DWORD idAttachTo, BOOL fAttach); +static BOOL Gui_DeleteDC(HDC hdc); + +static BOOL Gui_BitBlt( + HDC hdc, + int x, + int y, + int cx, + int cy, + HDC hdcSrc, + int x1, + int y1, + DWORD rop +); + +static BOOL Gui_StretchBlt( + HDC hdcDest, + int xDest, + int yDest, + int wDest, + int hDest, + HDC hdcSrc, + int xSrc, + int ySrc, + int wSrc, + int hSrc, + DWORD rop +); + +/*static BOOL Gui_TransparentBlt( + HDC hdcDest, + int xoriginDest, + int yoriginDest, + int wDest, + int hDest, + HDC hdcSrc, + int xoriginSrc, + int yoriginSrc, + int wSrc, + int hSrc, + UINT crTransparent +);*/ + +static HDC Gui_CreateDCA(LPCSTR pwszDriver, LPCSTR pwszDevice, LPCSTR pszPort, const DEVMODEA* pdm); + +static HDC Gui_CreateDCW(LPCWSTR pwszDriver, LPCWSTR pwszDevice, LPCWSTR pszPort, const DEVMODEW* pdm); + //--------------------------------------------------------------------------- // GUI_IMPORT @@ -382,10 +428,17 @@ _FX BOOLEAN Gui_Init(HMODULE module) Gui_UseProxyService = !Dll_CompartmentMode && !SbieApi_QueryConfBool(NULL, L"NoSandboxieDesktop", FALSE); // NoSbieDesk END - /*GUI_IMPORT___(PrintWindow) - GUI_IMPORT___(GetWindowDC) - GUI_IMPORT___(GetDC) - GUI_IMPORT___(GetDCEx)*/ + GUI_IMPORT___(PrintWindow); + GUI_IMPORT___(GetWindowDC); + GUI_IMPORT___(GetDC); + GUI_IMPORT___(GetDCEx); + //GUI_IMPORT___(DeleteDC); + GUI_IMPORT___(ReleaseDC); + //GUI_IMPORT___(BitBlt); + //GUI_IMPORT___(StretchBlt); + //GUI_IMPORT___(TransparentBlt); + // GUI_IMPORT___(CreateDCA); + // GUI_IMPORT___(CreateDCW); GUI_IMPORT___(GetWindowThreadProcessId); GUI_IMPORT___(SetThreadDesktop); GUI_IMPORT___(SwitchDesktop); @@ -620,6 +673,7 @@ _FX BOOLEAN Gui_Init2(HMODULE module) SBIEDLL_HOOK_GUI(MessageBoxW); SBIEDLL_HOOK_GUI(MessageBoxExW); + if (! Gui_OpenAllWinClasses) { SBIEDLL_HOOK_GUI(UserHandleGrantAccess); @@ -1665,12 +1719,10 @@ _FX LRESULT Gui_WindowProcA( new_lParam = (LPARAM)Gui_CreateTitleA((UCHAR *)lParam); else new_lParam = lParam; - + if (uMsg == WM_QUERYENDSESSION) - { if (SbieApi_QueryConfBool(NULL, L"BlockInterferePower", FALSE)) return TRUE; - } wndproc = __sys_GetPropW(hWnd, (LPCWSTR)Gui_WindowProcOldA_Atom); lResult = __sys_CallWindowProcA(wndproc, hWnd, uMsg, wParam, new_lParam); @@ -2741,4 +2793,3 @@ _FX BOOLEAN ComDlg32_Init(HMODULE module) return TRUE; } - diff --git a/Sandboxie/core/dll/gui_p.h b/Sandboxie/core/dll/gui_p.h index 2afd486b..5747118c 100644 --- a/Sandboxie/core/dll/gui_p.h +++ b/Sandboxie/core/dll/gui_p.h @@ -415,13 +415,57 @@ typedef int (*P_LoadString)( typedef BOOL (*P_SetProcessWindowStation)(HWINSTA hWinSta); -/*typedef HDC(*P_GetWindowDC)(HWND hWnd); +typedef HDC(*P_GetWindowDC)(HWND hWnd); typedef HDC(*P_GetDC)(HWND hWnd); typedef HDC(*P_GetDCEx)(HWND hWnd, HRGN hrgnClip,DWORD flags); -typedef BOOL (*P_PrintWindow)(HWND hwnd, HDC hdcBlt,UINT nFlags);*/ +typedef BOOL (*P_PrintWindow)(HWND hwnd, HDC hdcBlt,UINT nFlags); + +typedef BOOL(*P_DeleteDC)(HDC hdc); + +typedef int (*P_ReleaseDC)(HWND hWnd, HDC hDc); + +typedef BOOL (*P_TransparentBlt)( + HDC hdcDest, + int xoriginDest, + int yoriginDest, + int wDest, + int hDest, + HDC hdcSrc, + int xoriginSrc, + int yoriginSrc, + int wSrc, + int hSrc, + UINT crTransparent +); + +typedef BOOL (*P_StretchBlt)( + HDC hdcDest, + int xDest, + int yDest, + int wDest, + int hDest, + HDC hdcSrc, + int xSrc, + int ySrc, + int wSrc, + int hSrc, + DWORD rop +); + +typedef BOOL (*P_BitBlt)( + HDC hdc, + int x, + int y, + int cx, + int cy, + HDC hdcSrc, + int x1, + int y1, + DWORD rop +); typedef BOOL (*P_ShutdownBlockReasonCreate)(HWND hWnd, LPCWSTR pwszReason); @@ -550,10 +594,13 @@ extern ATOM Gui_WindowProcOldA_Atom; #endif #define GUI_SYS_VAR_2(nm) GUI_SYS_VAR_AW(nm,A); GUI_SYS_VAR_AW(nm,W); -/*GUI_SYS_VAR(GetDC) +GUI_SYS_VAR(GetDC) GUI_SYS_VAR(GetDCEx) GUI_SYS_VAR(GetWindowDC) -GUI_SYS_VAR(PrintWindow)*/ +GUI_SYS_VAR(ReleaseDC) +GUI_SYS_VAR(PrintWindow) + + GUI_SYS_VAR(ClipCursor) GUI_SYS_VAR(GetClipCursor) diff --git a/Sandboxie/core/dll/guimisc.c b/Sandboxie/core/dll/guimisc.c index c6bda3cf..7a1d6cab 100644 --- a/Sandboxie/core/dll/guimisc.c +++ b/Sandboxie/core/dll/guimisc.c @@ -99,13 +99,17 @@ static LONG Gui_GetRawInputDeviceInfoW( _In_opt_ HANDLE hDevice, _In_ UINT uiCommand, _Inout_ LPVOID pData, _Inout_ PUINT pcbSize); -/*static HDC Gui_GetDC(HWND hWnd); +static HDC Gui_GetDC(HWND hWnd); static HDC Gui_GetWindowDC(HWND hWnd); static HDC Gui_GetDCEx(HWND hWnd, HRGN hrgnClip, DWORD flags); -static BOOL Gui_PrintWindow(HWND hwnd, HDC hdcBlt, UINT nFlags);*/ +static BOOL Gui_PrintWindow(HWND hwnd, HDC hdcBlt, UINT nFlags); + +static int Gui_ReleaseDC(HWND hWnd, HDC hDc); + + static BOOL Gui_ShutdownBlockReasonCreate(HWND hWnd, LPCWSTR pwszReason); @@ -189,10 +193,13 @@ _FX BOOLEAN Gui_InitMisc(HMODULE module) } SBIEDLL_HOOK_GUI(SwapMouseButton); SBIEDLL_HOOK_GUI(SetDoubleClickTime); - /*SBIEDLL_HOOK_GUI(GetWindowDC); + SBIEDLL_HOOK_GUI(GetWindowDC); SBIEDLL_HOOK_GUI(GetDC); SBIEDLL_HOOK_GUI(GetDCEx); - SBIEDLL_HOOK_GUI(PrintWindow);*/ + SBIEDLL_HOOK_GUI(PrintWindow); + SBIEDLL_HOOK_GUI(ReleaseDC); + + if (Dll_OsBuild >= 6000) { // @@ -1485,30 +1492,48 @@ _FX BOOL Gui_ImmAssociateContextEx( return ok; } -/* + //--------------------------------------------------------------------------- // Gui_GetDC //--------------------------------------------------------------------------- - +HBITMAP bmp=NULL; _FX HDC Gui_GetDC(HWND hWnd) { - if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) { - - if (hWnd == NULL || hWnd == __sys_GetDesktopWindow()) { - - SetLastError(ERROR_ACCESS_DENIED); - return NULL; - } + HDC ret = __sys_GetDC(hWnd); - ULONG_PTR pid=0, tid=0; - if (!Gui_IsSameBox(hWnd, &pid, &tid)) { - - SetLastError(ERROR_ACCESS_DENIED); - return NULL; + if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) { + + ULONG_PTR pid = 0, tid = 0; + if (hWnd == NULL || hWnd == __sys_GetDesktopWindow() || + !Gui_IsSameBox(hWnd, &pid, &tid)) { + + typedef HDC(*P_CreateCompatibleDC)(HDC hdc); + typedef HGDIOBJ (*P_SelectObject)(_In_ HDC hdc, _In_ HGDIOBJ h); + GET_WIN_API(SelectObject, DllName_gdi32); + typedef int (*P_GetDeviceCaps)(_In_opt_ HDC hdc, _In_ int index); + GET_WIN_API(GetDeviceCaps, DllName_gdi32); + typedef HBITMAP(*P_CreateCompatibleBitmap)(_In_ HDC hdc, _In_ int cx, _In_ int cy); + GET_WIN_API(CreateCompatibleBitmap, DllName_gdi32); + + GET_WIN_API(CreateCompatibleDC, DllName_gdi32); + GET_WIN_API(DeleteDC, DllName_gdi32); + //typedef BOOL(*P_DeleteDC)(HDC hdc); + int iWidth, iHeight; + + HDC ret2 = CreateCompatibleDC(ret); + iWidth = GetDeviceCaps(ret, HORZRES); + iHeight = GetDeviceCaps(ret, VERTRES); + HBITMAP hBmp; + if(bmp==NULL) + bmp = CreateCompatibleBitmap(ret2, iWidth, iHeight); + hBmp = bmp; + SelectObject(ret2, hBmp); + DeleteDC(ret); + ret = ret2; } } - return __sys_GetDC(hWnd); + return ret; } @@ -1519,21 +1544,41 @@ _FX HDC Gui_GetDC(HWND hWnd) _FX HDC Gui_GetWindowDC(HWND hWnd) { + HDC ret = __sys_GetWindowDC(hWnd); + if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) { - if (hWnd == NULL || hWnd == __sys_GetDesktopWindow()) { - - SetLastError(ERROR_ACCESS_DENIED); - return NULL; - } ULONG_PTR pid = 0, tid = 0; - if (!Gui_IsSameBox(hWnd, &pid, &tid)) { - - SetLastError(ERROR_ACCESS_DENIED); - return NULL; + if (hWnd == NULL || hWnd == __sys_GetDesktopWindow() || + !Gui_IsSameBox(hWnd, &pid, &tid)) { + + typedef HDC(*P_CreateCompatibleDC)(HDC hdc); + //typedef BOOL(*P_DeleteDC)(HDC hdc); + GET_WIN_API(CreateCompatibleDC, DllName_gdi32); + GET_WIN_API(DeleteDC, DllName_gdi32); + + typedef HGDIOBJ(*P_SelectObject)(_In_ HDC hdc, _In_ HGDIOBJ h); + GET_WIN_API(SelectObject, DllName_gdi32); + typedef int (*P_GetDeviceCaps)(_In_opt_ HDC hdc, _In_ int index); + GET_WIN_API(GetDeviceCaps, DllName_gdi32); + typedef HBITMAP(*P_CreateCompatibleBitmap)(_In_ HDC hdc, _In_ int cx, _In_ int cy); + GET_WIN_API(CreateCompatibleBitmap, DllName_gdi32); + + int iWidth, iHeight; + + HDC ret2 = CreateCompatibleDC(ret); + iWidth = GetDeviceCaps(ret, HORZRES); + iHeight = GetDeviceCaps(ret, VERTRES); + HBITMAP hBmp; + if (bmp == NULL) + bmp = CreateCompatibleBitmap(ret2, iWidth, iHeight); + hBmp = bmp; + SelectObject(ret2, hBmp); + DeleteDC(ret); + ret = ret2; } } - return __sys_GetWindowDC(hWnd); + return ret; } @@ -1544,22 +1589,41 @@ _FX HDC Gui_GetWindowDC(HWND hWnd) _FX HDC Gui_GetDCEx(HWND hWnd, HRGN hrgnClip, DWORD flags) { + HDC ret = __sys_GetDCEx(hWnd, hrgnClip, flags); + if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) { - - if (hWnd == NULL || hWnd == __sys_GetDesktopWindow()) { - - SetLastError(ERROR_ACCESS_DENIED); - return NULL; - } ULONG_PTR pid = 0, tid = 0; - if (!Gui_IsSameBox(hWnd, &pid, &tid)) { - - SetLastError(ERROR_ACCESS_DENIED); - return NULL; + if (hWnd == NULL || hWnd == __sys_GetDesktopWindow() || + !Gui_IsSameBox(hWnd, &pid, &tid)) { + + typedef HDC(*P_CreateCompatibleDC)(HDC hdc); + //typedef BOOL(*P_DeleteDC)(HDC hdc); + GET_WIN_API(CreateCompatibleDC, DllName_gdi32); + GET_WIN_API(DeleteDC, DllName_gdi32); + + typedef HGDIOBJ(*P_SelectObject)(_In_ HDC hdc, _In_ HGDIOBJ h); + GET_WIN_API(SelectObject, DllName_gdi32); + typedef int (*P_GetDeviceCaps)(_In_opt_ HDC hdc, _In_ int index); + GET_WIN_API(GetDeviceCaps, DllName_gdi32); + typedef HBITMAP(*P_CreateCompatibleBitmap)(_In_ HDC hdc, _In_ int cx, _In_ int cy); + GET_WIN_API(CreateCompatibleBitmap, DllName_gdi32); + + int iWidth, iHeight; + + HDC ret2 = CreateCompatibleDC(ret); + iWidth = GetDeviceCaps(ret, HORZRES); + iHeight = GetDeviceCaps(ret, VERTRES); + HBITMAP hBmp; + if (bmp == NULL) + bmp = CreateCompatibleBitmap(ret2, iWidth, iHeight); + hBmp = bmp; + SelectObject(ret2, hBmp); + DeleteDC(ret); + ret = ret2; } } - return __sys_GetDCEx(hWnd, hrgnClip, flags); + return ret; } @@ -1587,7 +1651,10 @@ _FX BOOL Gui_PrintWindow(HWND hwnd, HDC hdcBlt, UINT nFlags) } return __sys_PrintWindow(hwnd, hdcBlt, nFlags); } -*/ +_FX int Gui_ReleaseDC(HWND hWnd, HDC hdc) { + return __sys_ReleaseDC(hWnd, hdc); +} + //--------------------------------------------------------------------------- // Gui_ShutdownBlockReasonCreate diff --git a/SandboxiePlus/SandMan/Forms/OptionsWindow.ui b/SandboxiePlus/SandMan/Forms/OptionsWindow.ui index 6295f6f2..8d450811 100644 --- a/SandboxiePlus/SandMan/Forms/OptionsWindow.ui +++ b/SandboxiePlus/SandMan/Forms/OptionsWindow.ui @@ -666,10 +666,102 @@ Restrictions - - + + + + + 75 + true + true + + + + Protect the system from sandboxed processes + - Open Windows Credentials Store (user mode) + Network restrictions + + + + + + + Block network files and folders, unless specifically opened. + + + + + + + Prevent change to network and firewall parameters (user mode) + + + + + + + + 75 + true + true + + + + Protect the system from sandboxed processes + + + Printing restrictions + + + + + + + Block access to the printer spooler + + + + + + + Remove spooler restriction, printers can be installed outside the sandbox + + + + + + + + 0 + 0 + + + + Allow the print spooler to print to files outside the sandbox + + + + + + + + 75 + true + true + + + + Protect the system from sandboxed processes + + + Other restrictions + + + + + + + Open System Protected Storage @@ -692,13 +784,65 @@ - - + + - Prevents processes in the sandbox from interfering with power operation + Open Windows Credentials Store (user mode) + + + + Block read access to the clipboard + + + + + + + Allow to read memory of unsandboxed processes (not recommended) + + + + + + + Issue message 2111 when a process access is denied + + + + + + + + + Prevents processes in the sandbox from interfering with power operation + + + + + + + Block obtain an image of an un-sandboxied window through Windows public method + + + + + + + + + Qt::Vertical + + + + 20 + 43 + + + + @@ -712,136 +856,6 @@ - - - - Qt::Vertical - - - - 20 - 43 - - - - - - - - - true - true - - - - Protect the system from sandboxed processes - - - Printing restrictions - - - - - - - Allow to read memory of unsandboxed processes (not recommended) - - - - - - - - 0 - 0 - - - - Allow the print spooler to print to files outside the sandbox - - - - - - - Block read access to the clipboard - - - - - - - Block network files and folders, unless specifically opened. - - - - - - - Remove spooler restriction, printers can be installed outside the sandbox - - - - - - - Block access to the printer spooler - - - - - - - Prevent change to network and firewall parameters (user mode) - - - - - - - - true - true - - - - Protect the system from sandboxed processes - - - Other restrictions - - - - - - - Open System Protected Storage - - - - - - - - true - true - - - - Protect the system from sandboxed processes - - - Network restrictions - - - - - - - Issue message 2111 when a process access is denied - - - diff --git a/SandboxiePlus/SandMan/Windows/OptionsAdvanced.cpp b/SandboxiePlus/SandMan/Windows/OptionsAdvanced.cpp index 40510294..f7f2b5e4 100644 --- a/SandboxiePlus/SandMan/Windows/OptionsAdvanced.cpp +++ b/SandboxiePlus/SandMan/Windows/OptionsAdvanced.cpp @@ -104,7 +104,8 @@ void COptionsWindow::CreateAdvanced() connect(ui.chkShowHostProcTmpl, SIGNAL(clicked(bool)), this, SLOT(OnShowHostProcTmpl())); connect(ui.chkConfidential, SIGNAL(clicked(bool)), this, SLOT(OnConfidentialChanged())); connect(ui.chkLessConfidential, SIGNAL(clicked(bool)), this, SLOT(OnLessConfidentialChanged())); - connect(ui.chkProtectWindow, SIGNAL(clicked(bool)), this, SLOT(OnAdvancedChanged())); + connect(ui.chkProtectWindow, SIGNAL(clicked(bool)), this, SLOT(OnProtectChanged())); + connect(ui.chkBlockCapture, SIGNAL(clicked(bool)), this, SLOT(OnCaptureChanged())); connect(ui.chkNotifyProtect, SIGNAL(clicked(bool)), this, SLOT(OnAdvancedChanged())); connect(ui.treeInjectDll, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(OnToggleInjectDll(QTreeWidgetItem *, int))); @@ -264,6 +265,7 @@ void COptionsWindow::LoadAdvanced() ui.chkNotifyProtect->setChecked(m_pBox->GetBool("NotifyBoxProtected", false)); ui.chkProtectWindow->setChecked(m_pBox->GetBool("IsProtectScreen")); + ui.chkBlockCapture->setChecked(m_pBox->GetBool("IsBlockCapture")); QStringList Users = m_pBox->GetText("Enabled").split(","); ui.lstUsers->clear(); @@ -468,6 +470,7 @@ void COptionsWindow::SaveAdvanced() WriteAdvancedCheck(ui.chkNotifyProtect, "NotifyBoxProtected", "y", ""); WriteAdvancedCheck(ui.chkProtectWindow, "IsProtectScreen", "y", "n"); + WriteAdvancedCheck(ui.chkBlockCapture, "IsBlockCapture", "y", "n"); QStringList Users; for (int i = 0; i < ui.lstUsers->count(); i++) @@ -1236,3 +1239,23 @@ void COptionsWindow::SaveDebug() DbgOption.Changed = false; } } +void COptionsWindow::OnCaptureChanged() { + if (ui.chkBlockCapture->checkState()) { + ui.chkProtectWindow->setChecked(FALSE); + ui.chkProtectWindow->setCheckable(FALSE); + } + else { + ui.chkProtectWindow->setCheckable(TRUE); + } + OnAdvancedChanged(); +} +void COptionsWindow::OnProtectChanged() { + if (ui.chkProtectWindow->checkState()) { + ui.chkBlockCapture->setChecked(FALSE); + ui.chkBlockCapture->setCheckable(FALSE); + } + else { + ui.chkBlockCapture->setCheckable(TRUE); + } + OnAdvancedChanged(); +} diff --git a/SandboxiePlus/SandMan/Windows/OptionsWindow.h b/SandboxiePlus/SandMan/Windows/OptionsWindow.h index 8154553e..bd0b223a 100644 --- a/SandboxiePlus/SandMan/Windows/OptionsWindow.h +++ b/SandboxiePlus/SandMan/Windows/OptionsWindow.h @@ -232,6 +232,8 @@ private slots: void OnAccessChanged(); void OnSysSvcChanged(); void OnAdvancedChanged(); + void OnProtectChanged(); + void OnCaptureChanged(); void OnOpenCOM(); void OnIsolationChanged(); void OnDebugChanged(); diff --git a/SandboxiePlus/SandMan/sandman_zh_CN.ts b/SandboxiePlus/SandMan/sandman_zh_CN.ts index f364b48d..59b4e6f9 100644 --- a/SandboxiePlus/SandMan/sandman_zh_CN.ts +++ b/SandboxiePlus/SandMan/sandman_zh_CN.ts @@ -1584,7 +1584,7 @@ Note: The update check is often behind the latest GitHub release to ensure that On Terminate - 在终端内 + 在沙盒终止时