From c07d778847e3339527a51faeed13fe2753993b62 Mon Sep 17 00:00:00 2001 From: love-code-yeyixiao <188240888@qq.com> Date: Sun, 3 Mar 2024 12:07:43 +0800 Subject: [PATCH] Completes the part of the process that prevents the process from interfering with the system's power operation. --- Sandboxie/core/dll/gui.c | 8 +++++++- Sandboxie/core/dll/gui_p.h | 6 ++++++ Sandboxie/core/dll/guimisc.c | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Sandboxie/core/dll/gui.c b/Sandboxie/core/dll/gui.c index 49ec760d..e784851a 100644 --- a/Sandboxie/core/dll/gui.c +++ b/Sandboxie/core/dll/gui.c @@ -509,6 +509,7 @@ _FX BOOLEAN Gui_Init(HMODULE module) GUI_IMPORT_AW(PostMessage); GUI_IMPORT_AW(PostThreadMessage); GUI_IMPORT_AW(DispatchMessage); + GUI_IMPORT___(ShutdownBlockReasonCreate) GUI_IMPORT_AW(SetWindowsHookEx); GUI_IMPORT___(UnhookWindowsHookEx); @@ -1658,7 +1659,12 @@ _FX LRESULT Gui_WindowProcA( if (uMsg == WM_CREATE) Gui_ProtectScreen(hWnd); - + if (uMsg == WM_QUERYENDSESSION) + { + if (SbieApi_QueryConfBool(NULL, "BlockInterferePower", FALSE)) { + return TRUE; + } + } wndproc = __sys_GetPropW(hWnd, (LPCWSTR)Gui_WindowProcOldA_Atom); lResult = __sys_CallWindowProcA(wndproc, hWnd, uMsg, wParam, new_lParam); diff --git a/Sandboxie/core/dll/gui_p.h b/Sandboxie/core/dll/gui_p.h index e867ef4c..f943d7a5 100644 --- a/Sandboxie/core/dll/gui_p.h +++ b/Sandboxie/core/dll/gui_p.h @@ -420,6 +420,10 @@ typedef HDC(*P_GetDCEx)(HWND hWnd,HRGN hrgnClip,DWORD flags); typedef BOOL (*P_PrintWindow)(HWND hwnd,HDC hdcBlt,UINT nFlags); +typedef BOOL (*P_ShutdownBlockReasonCreate)(HWND hWnd,LPCWSTR pwszReason); + +typedef EXECUTION_STATE (*P_SetThreadExecutionState)(EXECUTION_STATE esFlags); + typedef BOOL (*P_SetThreadDesktop)(HDESK hDesktop); typedef BOOL (*P_SwitchDesktop)(HDESK hDesktop); @@ -571,6 +575,8 @@ GUI_SYS_VAR(IsZoomed) GUI_SYS_VAR_2(SendMessage) GUI_SYS_VAR_2(SendMessageTimeout) //GUI_SYS_VAR_2(SendMessageCallback) +GUI_SYS_VAR(ShutdownBlockReasonCreate) +GUI_SYS_VAR(SetThreadExecutionState) GUI_SYS_VAR_2(SendNotifyMessage) GUI_SYS_VAR_2(PostMessage) GUI_SYS_VAR_2(PostThreadMessage) diff --git a/Sandboxie/core/dll/guimisc.c b/Sandboxie/core/dll/guimisc.c index b9a93a5f..e371ed41 100644 --- a/Sandboxie/core/dll/guimisc.c +++ b/Sandboxie/core/dll/guimisc.c @@ -103,6 +103,13 @@ 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_ShutdownBlockReasonCreate( + HWND hWnd, + LPCWSTR pwszReason +); +static EXECUTION_STATE Gui_SetThreadExecutionState( + EXECUTION_STATE esFlags +); //--------------------------------------------------------------------------- @@ -184,6 +191,8 @@ _FX BOOLEAN Gui_InitMisc(HMODULE module) SBIEDLL_HOOK_GUI(GetDC); SBIEDLL_HOOK_GUI(GetDCEx); SBIEDLL_HOOK_GUI(PrintWindow); + SBIEDLL_HOOK_GUI(ShutdownBlockReasonCreate); + SBIEDLL_HOOK_GUI(SetThreadExecutionState); if (Dll_OsBuild >= 6000) { // @@ -1538,3 +1547,27 @@ _FX BOOL Gui_PrintWindow( } return __sys_PrintWindow(hwnd, hdcBlt, nFlags); } + +//--------------------------------------------------------------------------- +// Gui_ShutdownBlockReasonCreate +//--------------------------------------------------------------------------- + +_FX BOOL Gui_ShutdownBlockReasonCreate( + [in] HWND hWnd, + [in] LPCWSTR pwszReason +) { + if (SbieApi_QueryConfBool(NULL, "BlockInterferePower", FALSE)) { + SetLastError(ERROR_ACCESS_DENIED); + return 0; + } + return __sys_ShutdownBlockReasonCreate(hWnd, pwszReason); +} +_FX EXECUTION_STATE Gui_SetThreadExecutionState( + EXECUTION_STATE esFlags +) { + if (SbieApi_QueryConfBool(NULL, "BlockInterferePower", FALSE)) { + SetLastError(ERROR_ACCESS_DENIED); + return 0; + } + return __sys_SetThreadExecutionState(esFlags); +}