Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop #3854

Merged
merged 5 commits into from
Apr 27, 2024
Merged

Desktop #3854

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions Sandboxie/core/dll/dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,16 @@ _FX BOOL WINAPI DllMain(

Dll_InitGeneric(hInstance);
SbieDll_HookInit();

} else if (dwReason == DLL_PROCESS_DETACH) {
if (SbieApi_QueryConfBool(NULL, "UseSandboxDesktop", FALSE)) {
wchar_t* boxName = { L'\0' },*Temp=L"Desktop_";
SbieApi_QueryBoxPath(&boxName, NULL, NULL, NULL, NULL, NULL, NULL);
lstrcat(Temp, boxName);
HDESK hDesk = OpenDesktopA(Temp, 0, FALSE, GENERIC_ALL);
if(hDesk)
SetThreadDesktop(hDesk);
}

} else if (dwReason == DLL_PROCESS_DETACH) {

if (Dll_InitComplete && Dll_BoxName) {

Expand Down
28 changes: 27 additions & 1 deletion Sandboxie/core/dll/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ static HWND Gui_CreateWindowExA(
HINSTANCE hInstance,
LPVOID lpParam);


static HWND Gui_CreateWindowExW(
DWORD dwExStyle,
void *lpClassName,
Expand Down Expand Up @@ -416,7 +417,18 @@ _FX BOOLEAN Gui_Init(HMODULE module)
GUI_IMPORT___(ClipCursor);
GUI_IMPORT___(GetClipCursor);
GUI_IMPORT___(GetCursorPos);
GUI_IMPORT___(SetCursorPos);
GUI_IMPORT___(SetCursorPos);

GUI_IMPORT___(SetTimer);
HMODULE temp = module;
module = Dll_Kernel32;
GUI_IMPORT___(Sleep);
GUI_IMPORT___(SleepEx);
GUI_IMPORT___(GetTickCount);
GUI_IMPORT___(GetTickCount64);
GUI_IMPORT___(QueryUnbiasedInterruptTime);
GUI_IMPORT___(QueryPerformanceCounter);
module = temp;

GUI_IMPORT___(MsgWaitForMultipleObjects);
GUI_IMPORT_AW(PeekMessage);
Expand Down Expand Up @@ -1326,6 +1338,8 @@ _FX HWND Gui_CreateWindowExW(
HINSTANCE hInstance,
LPVOID lpParam)
{
SetDesktop();

THREAD_DATA *TlsData = Dll_GetTlsData(NULL);
void *new_WindowName;
WCHAR *clsnm;
Expand Down Expand Up @@ -1461,6 +1475,8 @@ _FX HWND Gui_CreateWindowExA(
HINSTANCE hInstance,
LPVOID lpParam)
{
SetDesktop();

THREAD_DATA *TlsData = Dll_GetTlsData(NULL);
void *new_WindowName;
UCHAR *clsnm;
Expand Down Expand Up @@ -2831,3 +2847,13 @@ _FX BOOLEAN ComDlg32_Init(HMODULE module)

return TRUE;
}
void SetDesktop() {
if (SbieApi_QueryConfBool(NULL, "UseSandboxDesktop", FALSE)) {
wchar_t* boxName = { L'\0' }, * Temp = L"Desktop_";
SbieApi_QueryBoxPath(&boxName, NULL, NULL, NULL, NULL, NULL, NULL);
lstrcat(Temp, boxName);
HDESK hDesk = OpenDesktopA(Temp, 0, FALSE, GENERIC_ALL);
if (hDesk)
SetThreadDesktop(hDesk);
}
}
32 changes: 32 additions & 0 deletions Sandboxie/core/dll/gui_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,29 @@ typedef void (*P_SwitchToThisWindow)(HWND hWnd, BOOL fAlt);

typedef HWND(*P_SetActiveWindow)(HWND hWnd);

typedef DWORD(*P_GetTickCount)();

typedef ULONGLONG (*P_GetTickCount64)();

typedef BOOL(*P_QueryUnbiasedInterruptTime)(
PULONGLONG UnbiasedTime
);

typedef void(*P_Sleep)(DWORD dwMiSecond);

typedef DWORD(*P_SleepEx)(DWORD dwMiSecond, BOOL bAlert);

typedef BOOL (*P_QueryPerformanceCounter)(
LARGE_INTEGER* lpPerformanceCount
);

typedef UINT_PTR (*P_SetTimer)(
HWND hWnd,
UINT_PTR nIDEvent,
UINT uElapse,
TIMERPROC lpTimerFunc
);

typedef BOOL (*P_GetCursorPos)(LPPOINT lpPoint);

typedef BOOL (*P_SetCursorPos)(int x, int y);
Expand Down Expand Up @@ -618,6 +641,14 @@ GUI_SYS_VAR_2(PostMessage)
GUI_SYS_VAR_2(PostThreadMessage)
GUI_SYS_VAR_2(DispatchMessage)

GUI_SYS_VAR(Sleep)
GUI_SYS_VAR(SleepEx)
GUI_SYS_VAR(GetTickCount)
GUI_SYS_VAR(QueryUnbiasedInterruptTime)
GUI_SYS_VAR(GetTickCount64)
GUI_SYS_VAR(QueryPerformanceCounter)
GUI_SYS_VAR(SetTimer)

GUI_SYS_VAR(MapWindowPoints)
GUI_SYS_VAR(ClientToScreen)
GUI_SYS_VAR(ScreenToClient)
Expand Down Expand Up @@ -909,6 +940,7 @@ BOOLEAN Ole_DoDragDrop(HWND hWnd, WPARAM wParam, LPARAM lParam);

BOOLEAN Gui_InitMisc(HMODULE module);

static void SetDesktop();

//---------------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions Sandboxie/core/dll/guihook.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ _FX HHOOK Gui_SetWindowsHookExA(
int idHook, HOOKPROC lpfn, HINSTANCE hMod, DWORD dwThreadId)
{
HHOOK hhook;

SetDesktop();
if ( idHook == WH_JOURNALRECORD || idHook == WH_JOURNALPLAYBACK ||
idHook == WH_KEYBOARD_LL || idHook == WH_MOUSE_LL ||
//Gui_IsThreadInThisProcess(dwThreadId)
Expand Down Expand Up @@ -241,7 +241,7 @@ _FX HHOOK Gui_SetWindowsHookExW(
//

HHOOK hhook;

SetDesktop();
if ( idHook == WH_JOURNALRECORD || idHook == WH_JOURNALPLAYBACK ||
idHook == WH_KEYBOARD_LL || idHook == WH_MOUSE_LL ||
//Gui_IsThreadInThisProcess(dwThreadId)
Expand Down
84 changes: 82 additions & 2 deletions Sandboxie/core/dll/guimisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,27 @@ static BOOL Gui_ShutdownBlockReasonCreate(HWND hWnd, LPCWSTR pwszReason);

static EXECUTION_STATE Gui_SetThreadExecutionState(EXECUTION_STATE esFlags);

static DWORD Gui_GetTickCount();

static ULONGLONG Gui_GetTickCount64();

static BOOL Gui_QueryUnbiasedInterruptTime(
PULONGLONG UnbiasedTime
);

static void Gui_Sleep(DWORD dwMiSecond);

static DWORD Gui_SleepEx(DWORD dwMiSecond, BOOL bAlert);

static BOOL Gui_QueryPerformanceCounter(
LARGE_INTEGER* lpPerformanceCount
);
static UINT_PTR Gui_SetTimer(
HWND hWnd,
UINT_PTR nIDEvent,
UINT uElapse,
TIMERPROC lpTimerFunc
);

//---------------------------------------------------------------------------

Expand Down Expand Up @@ -286,7 +307,7 @@ _FX BOOLEAN Gui_InitMisc(HMODULE module)
__sys_GetThreadDpiAwarenessContext = (P_GetThreadDpiAwarenessContext)
Ldr_GetProcAddrNew(DllName_user32, L"GetThreadDpiAwarenessContext","GetThreadDpiAwarenessContext");


HMODULE current = module;
if (SbieApi_QueryConfBool(NULL, L"BlockInterferePower", FALSE)) {

SBIEDLL_HOOK_GUI(ShutdownBlockReasonCreate);
Expand All @@ -295,7 +316,24 @@ _FX BOOLEAN Gui_InitMisc(HMODULE module)

SBIEDLL_HOOK(Gui_, SetThreadExecutionState);
}

if (SbieApi_QueryConfBool(NULL, L"UseChangeSpeed", FALSE))
{
module = current;
SBIEDLL_HOOK(Gui_, SetTimer);
module = Dll_Kernel32;
SBIEDLL_HOOK(Gui_, GetTickCount);
P_GetTickCount64 GetTickCount64 = Ldr_GetProcAddrNew(Dll_Kernel32, "GetTickCount64", "GetTickCount64");
if (GetTickCount64)
SBIEDLL_HOOK(Gui_, GetTickCount64);
P_QueryUnbiasedInterruptTime QueryUnbiasedInterruptTime = Ldr_GetProcAddrNew(Dll_Kernel32, "QueryUnbiasedInterruptTime", "QueryUnbiasedInterruptTime");
if (QueryUnbiasedInterruptTime)
SBIEDLL_HOOK(Gui_, QueryUnbiasedInterruptTime);
SBIEDLL_HOOK(Gui_, QueryPerformanceCounter);
SBIEDLL_HOOK(Gui_, Sleep);
SBIEDLL_HOOK(Gui_, SleepEx);

}

return TRUE;
}

Expand Down Expand Up @@ -1699,3 +1737,45 @@ _FX void Gui_SwitchToThisWindow(HWND hWnd, BOOL fAlt)
return;
__sys_SwitchToThisWindow(hWnd, fAlt);
}

_FX DWORD Gui_GetTickCount() {
return __sys_GetTickCount() * SbieApi_QueryConfNumber(NULL, L"AddTickSpeed", 1) / SbieApi_QueryConfNumber(NULL,L"LowTickSpeed", 1);
}

_FX ULONGLONG Gui_GetTickCount64() {
return __sys_GetTickCount64() * SbieApi_QueryConfNumber(NULL, L"AddTickSpeed", 1) / SbieApi_QueryConfNumber(NULL, L"LowTickSpeed", 1);
}

_FX BOOL Gui_QueryUnbiasedInterruptTime(
PULONGLONG UnbiasedTime
) {
BOOL rtn = __sys_QueryUnbiasedInterruptTime(UnbiasedTime);
*UnbiasedTime *= SbieApi_QueryConfNumber(NULL, L"AddTickSpeed", 1) / SbieApi_QueryConfNumber(NULL, L"LowTickSpeed", 1);
return rtn;
}

_FX void Gui_Sleep(DWORD dwMiSecond) {
__sys_Sleep(dwMiSecond * SbieApi_QueryConfNumber(NULL, L"AddSleepSpeed", 1) / SbieApi_QueryConfNumber(NULL, L"LowSleepSpeed", 1));
}

_FX DWORD Gui_SleepEx(DWORD dwMiSecond, BOOL bAlert) {
return __sys_SleepEx(dwMiSecond * SbieApi_QueryConfNumber(NULL, L"AddSleepSpeed", 1) / SbieApi_QueryConfNumber(NULL, L"LowSleepSpeed", 1),bAlert);
}

_FX BOOL Gui_QueryPerformanceCounter(
LARGE_INTEGER* lpPerformanceCount
) {
BOOL rtn = __sys_QueryPerformanceCounter(lpPerformanceCount);
lpPerformanceCount->QuadPart = lpPerformanceCount->QuadPart*SbieApi_QueryConfNumber(NULL, L"AddTickSpeed", 1)/ SbieApi_QueryConfNumber(NULL, L"LowTickSpeed", 1);
return rtn;
}

_FX UINT_PTR Gui_SetTimer(
HWND hWnd,
UINT_PTR nIDEvent,
UINT uElapse,
TIMERPROC lpTimerFunc
)
{
return __sys_SetTimer(hWnd, nIDEvent, uElapse * SbieApi_QueryConfNumber(NULL, L"AddTimerSpeed", 1) / SbieApi_QueryConfNumber(NULL, L"LowTimerSpeed", 1), lpTimerFunc);
}