Merge pull request #3693 from love-code-yeyixiao/master

Add“Prevent the program from getting the image of  un-sandboxed  windows” function
This commit is contained in:
DavidXanatos 2024-03-16 16:26:38 +01:00 committed by GitHub
commit 6813051285
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 623 additions and 245 deletions

View File

@ -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,12 +273,70 @@ _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)
{
//
@ -281,7 +349,7 @@ _FX void Gdi_SplWow64(BOOLEAN Register)
// NoSbieDesk END
GUI_SPLWOW64_REQ req;
void *rpl;
void* rpl;
if (Register) {
@ -306,8 +374,8 @@ _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
@ -321,20 +389,20 @@ _FX HDC Gdi_CreateDCW(
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");
Ldr_GetProcAddrNew(L"winspool.drv", L"DocumentPropertiesW", "DocumentPropertiesW");
ULONG retry = 0;
while (__sys_DocumentProperties && (! hdc) && (retry < 20)) {
while (__sys_DocumentProperties && (!hdc) && (retry < 20)) {
HANDLE hPrinter;
Sleep(retry * 25);
if (! __sys_OpenPrinter2W(lpInitData, &hPrinter, NULL, NULL))
if (!__sys_OpenPrinter2W(lpInitData, &hPrinter, NULL, NULL))
break;
__sys_DocumentProperties(
@ -353,6 +421,89 @@ _FX HDC Gdi_CreateDCW(
}
#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);
}

View File

@ -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);
@ -1667,10 +1721,8 @@ _FX LRESULT Gui_WindowProcA(
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;
}

View File

@ -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)

View File

@ -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)
{
HDC ret = __sys_GetDC(hWnd);
if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) {
if (hWnd == NULL || hWnd == __sys_GetDesktopWindow()) {
ULONG_PTR pid = 0, tid = 0;
if (hWnd == NULL || hWnd == __sys_GetDesktopWindow() ||
!Gui_IsSameBox(hWnd, &pid, &tid)) {
SetLastError(ERROR_ACCESS_DENIED);
return NULL;
}
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);
ULONG_PTR pid=0, tid=0;
if (!Gui_IsSameBox(hWnd, &pid, &tid)) {
GET_WIN_API(CreateCompatibleDC, DllName_gdi32);
GET_WIN_API(DeleteDC, DllName_gdi32);
//typedef BOOL(*P_DeleteDC)(HDC hdc);
int iWidth, iHeight;
SetLastError(ERROR_ACCESS_DENIED);
return NULL;
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)
{
if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) {
if (hWnd == NULL || hWnd == __sys_GetDesktopWindow()) {
HDC ret = __sys_GetWindowDC(hWnd);
SetLastError(ERROR_ACCESS_DENIED);
return NULL;
}
if (SbieApi_QueryConfBool(NULL, L"IsBlockCapture", FALSE)) {
ULONG_PTR pid = 0, tid = 0;
if (!Gui_IsSameBox(hWnd, &pid, &tid)) {
if (hWnd == NULL || hWnd == __sys_GetDesktopWindow() ||
!Gui_IsSameBox(hWnd, &pid, &tid)) {
SetLastError(ERROR_ACCESS_DENIED);
return NULL;
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)) {
if (hWnd == NULL || hWnd == __sys_GetDesktopWindow() ||
!Gui_IsSameBox(hWnd, &pid, &tid)) {
SetLastError(ERROR_ACCESS_DENIED);
return NULL;
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

View File

@ -666,10 +666,102 @@
<string>Restrictions</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_36">
<item row="9" column="2">
<widget class="QCheckBox" name="chkOpenCredentials">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="lblNetwork">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
<kerning>true</kerning>
</font>
</property>
<property name="toolTip">
<string>Protect the system from sandboxed processes</string>
</property>
<property name="text">
<string>Open Windows Credentials Store (user mode)</string>
<string>Network restrictions</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QCheckBox" name="chkBlockNetShare">
<property name="text">
<string>Block network files and folders, unless specifically opened.</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QCheckBox" name="chkBlockNetParam">
<property name="text">
<string>Prevent change to network and firewall parameters (user mode)</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="lblPrinting">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
<kerning>true</kerning>
</font>
</property>
<property name="toolTip">
<string>Protect the system from sandboxed processes</string>
</property>
<property name="text">
<string>Printing restrictions</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QCheckBox" name="chkBlockSpooler">
<property name="text">
<string>Block access to the printer spooler</string>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QCheckBox" name="chkOpenSpooler">
<property name="text">
<string>Remove spooler restriction, printers can be installed outside the sandbox</string>
</property>
</widget>
</item>
<item row="6" column="2">
<widget class="QCheckBox" name="chkPrintToFile">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Allow the print spooler to print to files outside the sandbox</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="lblOther">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
<kerning>true</kerning>
</font>
</property>
<property name="toolTip">
<string>Protect the system from sandboxed processes</string>
</property>
<property name="text">
<string>Other restrictions</string>
</property>
</widget>
</item>
<item row="8" column="1" colspan="2">
<widget class="QCheckBox" name="chkOpenProtectedStorage">
<property name="text">
<string>Open System Protected Storage</string>
</property>
</widget>
</item>
@ -692,13 +784,65 @@
</property>
</widget>
</item>
<item row="9" column="2">
<widget class="QCheckBox" name="chkOpenCredentials">
<property name="text">
<string>Open Windows Credentials Store (user mode)</string>
</property>
</widget>
</item>
<item row="10" column="1" colspan="2">
<widget class="QCheckBox" name="chkCloseClipBoard">
<property name="text">
<string>Block read access to the clipboard</string>
</property>
</widget>
</item>
<item row="11" column="1" colspan="2">
<widget class="QCheckBox" name="chkVmRead">
<property name="text">
<string>Allow to read memory of unsandboxed processes (not recommended)</string>
</property>
</widget>
</item>
<item row="12" column="2">
<widget class="QCheckBox" name="chkVmReadNotify">
<property name="text">
<string>Issue message 2111 when a process access is denied</string>
</property>
</widget>
</item>
<item row="13" column="1" colspan="2">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="chkProtectPower">
<property name="text">
<string>Prevents processes in the sandbox from interfering with power operation</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkBlockCapture">
<property name="text">
<string>Block obtain an image of an un-sandboxied window through Windows public method</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="14" column="1">
<spacer name="verticalSpacer_12">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>43</height>
</size>
</property>
</spacer>
</item>
<item row="15" column="2">
<spacer name="horizontalSpacer_5">
<property name="orientation">
@ -712,136 +856,6 @@
</property>
</spacer>
</item>
<item row="14" column="0">
<spacer name="verticalSpacer_12">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>43</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="lblPrinting">
<property name="font">
<font>
<bold>true</bold>
<kerning>true</kerning>
</font>
</property>
<property name="toolTip">
<string>Protect the system from sandboxed processes</string>
</property>
<property name="text">
<string>Printing restrictions</string>
</property>
</widget>
</item>
<item row="11" column="1" colspan="2">
<widget class="QCheckBox" name="chkVmRead">
<property name="text">
<string>Allow to read memory of unsandboxed processes (not recommended)</string>
</property>
</widget>
</item>
<item row="6" column="2">
<widget class="QCheckBox" name="chkPrintToFile">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Allow the print spooler to print to files outside the sandbox</string>
</property>
</widget>
</item>
<item row="10" column="1" colspan="2">
<widget class="QCheckBox" name="chkCloseClipBoard">
<property name="text">
<string>Block read access to the clipboard</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QCheckBox" name="chkBlockNetShare">
<property name="text">
<string>Block network files and folders, unless specifically opened.</string>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QCheckBox" name="chkOpenSpooler">
<property name="text">
<string>Remove spooler restriction, printers can be installed outside the sandbox</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QCheckBox" name="chkBlockSpooler">
<property name="text">
<string>Block access to the printer spooler</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QCheckBox" name="chkBlockNetParam">
<property name="text">
<string>Prevent change to network and firewall parameters (user mode)</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="lblOther">
<property name="font">
<font>
<bold>true</bold>
<kerning>true</kerning>
</font>
</property>
<property name="toolTip">
<string>Protect the system from sandboxed processes</string>
</property>
<property name="text">
<string>Other restrictions</string>
</property>
</widget>
</item>
<item row="8" column="1" colspan="2">
<widget class="QCheckBox" name="chkOpenProtectedStorage">
<property name="text">
<string>Open System Protected Storage</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="lblNetwork">
<property name="font">
<font>
<bold>true</bold>
<kerning>true</kerning>
</font>
</property>
<property name="toolTip">
<string>Protect the system from sandboxed processes</string>
</property>
<property name="text">
<string>Network restrictions</string>
</property>
</widget>
</item>
<item row="12" column="2">
<widget class="QCheckBox" name="chkVmReadNotify">
<property name="text">
<string>Issue message 2111 when a process access is denied</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabRun">

View File

@ -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();
}

View File

@ -232,6 +232,8 @@ private slots:
void OnAccessChanged();
void OnSysSvcChanged();
void OnAdvancedChanged();
void OnProtectChanged();
void OnCaptureChanged();
void OnOpenCOM();
void OnIsolationChanged();
void OnDebugChanged();

View File

@ -1584,7 +1584,7 @@ Note: The update check is often behind the latest GitHub release to ensure that
<message>
<location filename="Windows/OptionsAdvanced.cpp" line="893"/>
<source>On Terminate</source>
<translation></translation>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="Windows/OptionsAdvanced.cpp" line="903"/>