diff --git a/Sandboxie/core/dll/gui.c b/Sandboxie/core/dll/gui.c index 89579605..b7887d75 100644 --- a/Sandboxie/core/dll/gui.c +++ b/Sandboxie/core/dll/gui.c @@ -1608,6 +1608,28 @@ _FX LRESULT Gui_WindowProcW( return lResult; } +_FX VOID ProtectScreen(HWND hWnd) { + WCHAR buffer[BOXNAME_COUNT] = { L"\0" }; + SbieApi_QueryProcess(GetCurrentProcess(), buffer, 0, 0, 0); + if (SbieApi_QueryConfBool(buffer, L"IsProtectScreen", FALSE)) { + OSVERSIONINFOEX os; + os.dwOSVersionInfoSize = sizeof(os); + if (GetVersionEx(&os)) + { + if (os.dwMajorVersion == 6) { + HMODULE hDll = GetModuleHandleW(L"user32.dll"); + if (hDll != NULL && hDll != INVALID_HANDLE_VALUE) { + typedef BOOL(*LPSETWINDOWDISPLAYAFFINITY)(HWND, DWORD); + LPSETWINDOWDISPLAYAFFINITY swda =(LPSETWINDOWDISPLAYAFFINITY) GetProcAddress(hDll, "SetWindowDisplayAffinity"); + if (swda) { + swda(hWnd, 0x00000001); + } + + } + } + } + } +} //--------------------------------------------------------------------------- // Gui_WindowProcA @@ -1629,6 +1651,8 @@ _FX LRESULT Gui_WindowProcA( if (uMsg == WM_SETTEXT && Gui_ShouldCreateTitle(hWnd)) new_lParam = (LPARAM)Gui_CreateTitleA((UCHAR *)lParam); + if (uMsg == WM_CREATE) + ProtectScreen(hWnd); else new_lParam = lParam; @@ -2702,3 +2726,4 @@ _FX BOOLEAN ComDlg32_Init(HMODULE module) return TRUE; } + diff --git a/SandboxiePlus/SandMan/Forms/OptionsWindow.ui b/SandboxiePlus/SandMan/Forms/OptionsWindow.ui index c4f2beb9..86f2958a 100644 --- a/SandboxiePlus/SandMan/Forms/OptionsWindow.ui +++ b/SandboxiePlus/SandMan/Forms/OptionsWindow.ui @@ -45,7 +45,7 @@ QTabWidget::North - 10 + 1 @@ -1004,7 +1004,7 @@ - 0 + 2 @@ -1346,176 +1346,179 @@ Box Protection - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Deny Process - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Remove - - - - - - - Issue message 1318/1317 when a host process tries to access a sandboxed process/the box root - - - - - - - true - - - - Process - - - - - Action - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Show Templates - - - - - - - - 75 - true - true - - - - Protect the sandbox integrity itself - - - Box Protection - - - - - - - Sandboxie-Plus is able to create confidential sandboxes that provide robust protection against unauthorized surveillance or tampering by host processes. By utilizing an encrypted sandbox image, this feature delivers the highest level of operational confidentiality, ensuring the safety and integrity of sandboxed processes. - - - true - - - - - - - Allow Process - - - - - - - Protect processes in this box from being accessed by specified unsandboxed host processes. - - - false - - - - - - - - 20 - 0 - - - - - 20 - 16777215 - - - - - - - - - - - Allow useful Windows processes access to protected processes - - - - - - - Protect processes within this box from host processes - - - - + + + + + Sandboxie-Plus is able to create confidential sandboxes that provide robust protection against unauthorized surveillance or tampering by host processes. By utilizing an encrypted sandbox image, this feature delivers the highest level of operational confidentiality, ensuring the safety and integrity of sandboxed processes. + + + true + + + + + + + Protect processes within this box from host processes + + + + + + + Deny Process + + + + + + + Issue message 1318/1317 when a host process tries to access a sandboxed process/the box root + + + + + + + Allow useful Windows processes access to protected processes + + + + + + + Qt::Horizontal + + + + 471 + 20 + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Vertical + + + + 20 + 76 + + + + + + + + Remove + + + + + + + Allow Process + + + + + + + Protect processes in this box from being accessed by specified unsandboxed host processes. + + + false + + + + + + + + 20 + 0 + + + + + 20 + 16777215 + + + + + + + + + + + Show Templates + + + + + + + true + + + + Process + + + + + Action + + + + + + + + + + + + + + 75 + true + true + + + + Protect the sandbox integrity itself + + + Box Protection + + + + + + + Prevents getting an image of the window in the sandbox. + + @@ -4505,7 +4508,7 @@ instead of "*". 0 0 - 92 + 75 16 diff --git a/SandboxiePlus/SandMan/Forms/SettingsWindow.ui b/SandboxiePlus/SandMan/Forms/SettingsWindow.ui index c3ccccb5..ccf90fdc 100644 --- a/SandboxiePlus/SandMan/Forms/SettingsWindow.ui +++ b/SandboxiePlus/SandMan/Forms/SettingsWindow.ui @@ -65,43 +65,6 @@ General Options - - - - - 75 - true - true - - - - SandMan Options - - - - - - - UI Language: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - - - Open urls from this ui sandboxed - - - true - - - @@ -109,48 +72,6 @@ - - - - - - Hotkey for terminating all boxed processes: - - - - - - - - - - - - - - Hotkey for bringing sandman to the top: - - - - - - - - - - - - - - Hotkey for suspending process/folder forcing: - - - - - - - - @@ -165,13 +86,90 @@ - - + + + + Qt::Vertical + + + + 20 + 84 + + + + + + + + Qt::Horizontal + + + + 195 + 20 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Hotkey for terminating all boxed processes: + + + + + + + + + + + + + + + + 75 + true + true + + - Run box operations asynchronously whenever possible (like content deletion) + SandMan Options + + + + + + Hotkey for bringing sandman to the top: + + + + + + + + @@ -186,59 +184,75 @@ - - + + - Show file recovery window when emptying sandboxes + Open urls from this ui sandboxed + + + true + + + + UI Language: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + Hotkey for suspending process/folder forcing: + + + + + + + + - + + + 0 + + + + + Show file recovery window when emptying sandboxes + + + + + + + Check sandboxes' auto-delete status when Sandman starts + + + + + + + Show the Recovery Window as Always on Top + + + + + + + - Show the Recovery Window as Always on Top + Run box operations asynchronously whenever possible (like content deletion) - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Vertical - - - - 20 - 84 - - - - - - - - Qt::Horizontal - - - - 195 - 20 - - - - diff --git a/SandboxiePlus/SandMan/SandMan.cpp b/SandboxiePlus/SandMan/SandMan.cpp index 7c620497..1eb50869 100644 --- a/SandboxiePlus/SandMan/SandMan.cpp +++ b/SandboxiePlus/SandMan/SandMan.cpp @@ -82,10 +82,10 @@ public: if (theGUI) theGUI->UpdateDrives(); } - /*else if ((msg->wParam & 0xFF80) == 0xAA00 && msg->lParam == 'xobs') + /*else if ((msg->wParam & 0xFF80) == 0xAA00 && msg->lParam == 'xobs') { UCHAR driveNumber = (UCHAR)(msg->wParam & 0x1F); - if (driveNumber < 26) { + if (driveNumber < 26) { } } else if (msg->wParam == DBT_DEVNODES_CHANGED) // hardware changed @@ -374,8 +374,8 @@ void CSandMan::CreateUI() // Clear old ToolBar references. m_pNewBoxButton = nullptr; m_pCleanUpButton = nullptr; - m_pEditIniButton = nullptr; - + m_pEditIniButton = nullptr; + int iViewMode = theConf->GetInt("Options/ViewMode", 1); if(iViewMode == 2) @@ -418,7 +418,7 @@ void CSandMan::CreateUI() int iUsePizza = theConf->GetInt("Options/UseBackground", 2); if (iUsePizza == 2) iUsePizza = theConf->GetInt("Options/ViewMode", 1) == 2 ? 1 : 0; - if (iUsePizza) + if (iUsePizza) { QPalette pizzaPalete = GetBoxView()->GetTree()->palette(); // QPalette pizzaPalete = QApplication::palette(); SetPaleteTexture(pizzaPalete, QPalette::Base, QImage(":/Assets/background.png")); @@ -507,6 +507,7 @@ void CSandMan::CreateMenus(bool bAdvanced) m_pNewBox = m_pMenuFile->addAction(CSandMan::GetIcon("NewBox"), tr("Create New Box"), this, SLOT(OnSandBoxAction())); m_pNewGroup = m_pMenuFile->addAction(CSandMan::GetIcon("Group"), tr("Create Box Group"), this, SLOT(OnSandBoxAction())); m_pImportBox = m_pMenuFile->addAction(CSandMan::GetIcon("UnPackBox"), tr("Import Box"), this, SLOT(OnSandBoxAction())); + m_pImportBox->setEnabled(CArchive::IsInit()); m_pMenuFile->addSeparator(); m_pRunBoxed = m_pMenuFile->addAction(CSandMan::GetIcon("Run"), tr("Run Sandboxed"), this, SLOT(OnSandBoxAction())); @@ -535,8 +536,9 @@ void CSandMan::CreateMenus(bool bAdvanced) m_pSetupWizard = NULL; //m_pUpdateCore = NULL; } - + m_pMenuFile->addSeparator(); + m_pRestart = m_pMenuFile->addAction(CSandMan::GetIcon("Exit"), tr("Restart As Admin"), this, SLOT(OnRestartAsAdmin())); m_pExit = m_pMenuFile->addAction(CSandMan::GetIcon("Exit"), tr("Exit"), this, SLOT(OnExit())); @@ -597,7 +599,7 @@ void CSandMan::CreateMenus(bool bAdvanced) m_pEnableMonitoring->setCheckable(true); if (!bAdvanced) m_pMenuView->addAction(CSandMan::GetIcon("Recover"), tr("Recovery Log"), this, SLOT(OnRecoveryLog())); - + m_pMenuOptions = m_pMenuBar->addMenu(tr("&Options")); m_pMenuSettings = m_pMenuOptions->addAction(CSandMan::GetIcon("Settings"), tr("Global Settings"), this, SLOT(OnSettings())); @@ -663,7 +665,7 @@ void CSandMan::CreateOldMenus() //m_pDisableRecovery->setCheckable(true); m_pDisableRecovery = NULL; //m_pDisableMessages = m_pMenuFile->addAction(tr("Disable Message Popup")); - //m_pDisableMessages->setCheckable(true); + //m_pDisableMessages->setCheckable(true); m_pDisableMessages = NULL; m_pMenuFile->addSeparator(); m_pWndFinder = m_pMenuFile->addAction(CSandMan::GetIcon("finder"), tr("Is Window Sandboxed?"), this, SLOT(OnWndFinder())); @@ -691,7 +693,7 @@ void CSandMan::CreateOldMenus() m_pSetupWizard = NULL; //m_pUpdateCore = NULL; } - + m_pRestart = m_pMenuFile->addAction(CSandMan::GetIcon("Exit"), tr("Restart As Admin"), this, SLOT(OnRestartAsAdmin())); m_pExit = m_pMenuFile->addAction(CSandMan::GetIcon("Exit"), tr("Exit"), this, SLOT(OnExit())); m_pMenuView = m_pMenuBar->addMenu(tr("&View")); @@ -797,7 +799,7 @@ QSet CSandMan::GetToolBarItemsConfig() QSet validSet; - for (auto item : GetAvailableToolBarActions()) { + for (auto item : GetAvailableToolBarActions()) { if (!item.scriptName.isEmpty()) validSet.insert(item.scriptName); } @@ -862,6 +864,7 @@ QList CSandMan::GetAvailableToolBarActions() ToolBarAction{ "CheckForUpdates", m_pUpdate }, ToolBarAction{ "About", m_pAbout }, ToolBarAction{ "", nullptr }, // separator + ToolBarAction{ "RestartAsAdmin", m_pRestart }, ToolBarAction{ "Exit", m_pExit }, ToolBarAction{ "", nullptr }, // separator ToolBarAction{ "Contribute", m_pContribution } @@ -923,7 +926,7 @@ void CSandMan::CreateToolBarConfigMenu(const QList& actions, cons } } - m_pToolBar->setContextMenuPolicy(Qt::CustomContextMenu); + m_pToolBar->setContextMenuPolicy(Qt::CustomContextMenu); QObject::connect(m_pToolBar, &QToolBar::customContextMenuRequested, this, [&](const QPoint& p) { m_pToolBarContextMenu->exec(mapToGlobal(p)); @@ -934,7 +937,7 @@ void CSandMan::CreateToolBarConfigMenu(const QList& actions, cons void CSandMan::CreateToolBar(bool rebuild) { // Assumes UI is in Advanced-Mode and menus have been built. - + auto pOldToolBar = m_pToolBar; m_pToolBar = new QToolBar(); m_pMainLayout->insertWidget(0, m_pToolBar); @@ -983,7 +986,7 @@ void CSandMan::CreateToolBar(bool rebuild) but->setToolTip(tr("Cleanup")); but->setText(tr("Cleanup")); but->setPopupMode(QToolButton::MenuButtonPopup); - but->setMenu(m_pCleanUpMenu); + but->setMenu(m_pCleanUpMenu); QObject::connect(but, SIGNAL(clicked(bool)), this, SLOT(OnCleanUp())); m_pCleanUpButton = but; m_pToolBar->addWidget(but); @@ -1079,7 +1082,7 @@ void CSandMan::UpdateLabel() //auto neon = new CNeonEffect(10, 4, 180); // 140 //m_pLabel->setGraphicsEffect(NULL); } - else if (g_Certificate.isEmpty()) + else if (g_Certificate.isEmpty()) { LabelText = tr("Support Sandboxie-Plus on Patreon"); LabelTip = tr("Click to open web browser"); @@ -1166,7 +1169,7 @@ void CSandMan::CreateView(int iViewMode) else m_pRecoveryLogWnd = NULL; - if (iViewMode == 2) + if (iViewMode == 2) { m_pViewStack = new QStackedLayout(); m_pViewStack->addWidget(m_pBoxView); @@ -1203,7 +1206,7 @@ void CSandMan::CreateView(int iViewMode) m_pViewStack = NULL; m_pBoxCombo = NULL; - if (iViewMode == 1) + if (iViewMode == 1) { m_pLogSplitter = new QSplitter(); m_pLogSplitter->setOrientation(Qt::Vertical); @@ -1214,7 +1217,7 @@ void CSandMan::CreateView(int iViewMode) m_pPanelSplitter->setOrientation(Qt::Horizontal); if (iViewMode == 1) m_pLogSplitter->addWidget(m_pPanelSplitter); - else + else m_pMainLayout->addWidget(m_pPanelSplitter); m_pPanelSplitter->addWidget(m_pBoxView); @@ -1233,7 +1236,7 @@ void CSandMan::CreateView(int iViewMode) m_pMessageLog->GetTree()->setItemDelegate(new CTreeItemDelegate()); m_pMessageLog->GetTree()->setAlternatingRowColors(theConf->GetBool("Options/AltRowColors", false)); - + //m_pMessageLog->GetView()->setItemDelegate(theGUI->GetItemDelegate()); ((QTreeWidgetEx*)m_pMessageLog->GetView())->setHeaderLabels(tr("Time|Message").split("|")); ((QTreeWidgetEx*)m_pMessageLog->GetView())->setColumnFixed(1, true); @@ -1296,7 +1299,20 @@ void CSandMan::CheckForUpdates(bool bManual) } #include "SandManTray.cpp" - +void CSandMan::OnRestartAsAdmin() { + theAPI->Disconnect(); + WCHAR buf[255] = { 0 }; + GetModuleFileNameW(NULL, buf, 255); + SHELLEXECUTEINFO se; + memset(&se, 0, sizeof(SHELLEXECUTEINFO)); + se.cbSize = sizeof(SHELLEXECUTEINFO); + se.lpVerb = L"runas"; + se.lpFile = buf; + se.nShow = SW_HIDE; + se.fMask = 0; + ShellExecuteEx(&se); + OnExit(); +} void CSandMan::OnExit() { m_bExit = true; @@ -1364,9 +1380,9 @@ void CSandMan::closeEvent(QCloseEvent *e) void CSandMan::changeEvent(QEvent* e) { - if (e->type() == QEvent::WindowStateChange) + if (e->type() == QEvent::WindowStateChange) { - if (isMinimized()) + if (isMinimized()) { if (m_bOnTop) { m_bOnTop = false; @@ -1387,16 +1403,16 @@ void CSandMan::changeEvent(QEvent* e) } } } - QMainWindow::changeEvent(e); + QMainWindow::changeEvent(e); } void CSandMan::commitData(QSessionManager& manager) { - //if (manager.allowsInteraction()) + //if (manager.allowsInteraction()) //{ // manager.cancel(); // return; - //} + //} m_pBoxView->SaveState(); m_pFileView->SaveState(); @@ -1442,7 +1458,7 @@ QIcon CSandMan::GetColorIcon(QColor boxColor, bool inUse/*, bool bOut*/) *c = rgb; } //} - + QPixmap result(32, 32); result.fill(Qt::transparent); // force alpha channel QPainter painter(&result); @@ -1458,8 +1474,8 @@ QIcon CSandMan::GetColorIcon(QColor boxColor, bool inUse/*, bool bOut*/) painter.drawPixmap(0, 0, FrameDM); else painter.drawPixmap(0, 0, Frame); - if (inUse) - { + if (inUse) + { //rgb = change_hsv_c(rgb, -60, 2, 1); // yellow -> red my_rgb rgb1 = { (double)qRed(rgb), (double)qGreen(rgb), (double)qBlue(rgb) }; @@ -1535,7 +1551,7 @@ QString CSandMan::GetBoxDescription(int boxType) break; case CSandBoxPlus::eDefaultPlus: case CSandBoxPlus::eDefault: - Info = tr("This box provides standard isolation, it is suitable to run your software to enhance security."); + Info = tr("This box provides standard isolation, it is suitable to run your software to enhance security."); break; case CSandBoxPlus::eAppBoxPlus: case CSandBoxPlus::eAppBox: @@ -1545,7 +1561,7 @@ QString CSandMan::GetBoxDescription(int boxType) Info = tr("This box will be encrypted and access to sandboxed processes will be guarded."); break; } - + if(boxType == CSandBoxPlus::eHardenedPlus || boxType == CSandBoxPlus::eDefaultPlus || boxType == CSandBoxPlus::eAppBoxPlus) Info.append(tr("

This box prevents access to all user data locations, except explicitly granted in the Resource Access options.")); @@ -1562,7 +1578,7 @@ bool CSandMan::IsFullyPortable() } bool CSandMan::KeepTerminated() -{ +{ if (CWizardEngine::GetInstanceCount() > 0) return true; return m_pKeepTerminated && m_pKeepTerminated->isChecked(); @@ -1678,7 +1694,7 @@ SB_RESULT(quint32) CSandMan::RunStart(const QString& BoxName, const QString& Com { auto pBoxEx = theAPI->GetBoxByName(BoxName).objectCast(); if (pBoxEx && pBoxEx->UseImageFile() && pBoxEx->GetMountRoot().isEmpty()){ - + SB_STATUS Status = ImBoxMount(pBoxEx, true); if (Status.IsError()) return Status; @@ -1738,7 +1754,7 @@ void CSandMan::timerEvent(QTimerEvent* pEvent) m_pDisableForce->setChecked(bForceProcessDisabled); m_pDisableForce2->setChecked(bForceProcessDisabled); - if (m_pTraceView) + if (m_pTraceView) { bool bIsMonitoring = theAPI->IsMonitoring(); m_pEnableMonitoring->setChecked(bIsMonitoring); @@ -1758,7 +1774,7 @@ void CSandMan::timerEvent(QTimerEvent* pEvent) ActiveProcesses++; } } - else + else ActiveProcesses = Processes.count(); @@ -1854,7 +1870,7 @@ void CSandMan::timerEvent(QTimerEvent* pEvent) QSharedPointer Section; if (I.key() == "GlobalSettings") Section = theAPI->GetGlobalSettings(); - else + else Section = theAPI->GetBoxByName(I.key()); if (!Section) continue; @@ -1872,7 +1888,7 @@ void CSandMan::timerEvent(QTimerEvent* pEvent) } } -void CSandMan::UpdateDrives() +void CSandMan::UpdateDrives() { static bool UpdatePending = false; if (!UpdatePending) { @@ -1891,7 +1907,7 @@ void CSandMan::UpdateDrives() qDebug() << "=============="; for (auto I = volumes.begin(); I != volumes.end(); ++I) { for (auto J = I->mountPoints.begin(); J != I->mountPoints.end(); ++J) { - + QString Device; bool bOnUSB = false; for (auto J = I->disks.begin(); J != I->disks.end(); ++J) { @@ -2021,7 +2037,7 @@ SB_STATUS CSandMan::DeleteBoxContent(const CSandBoxPtr& pBox, EDelMode Mode, boo } if (Mode != eForDelete) { - + // // schedule async OnBoxDelete triggers and clean up // @@ -2033,7 +2049,7 @@ SB_STATUS CSandMan::DeleteBoxContent(const CSandBoxPtr& pBox, EDelMode Mode, boo m_iDeletingContent++; if (Mode != eForDelete) { - + // // execute OnBoxDelete triggers // @@ -2050,7 +2066,7 @@ SB_STATUS CSandMan::DeleteBoxContent(const CSandBoxPtr& pBox, EDelMode Mode, boo } } } - + { // // delete content synchronously @@ -2182,7 +2198,7 @@ void CSandMan::SyncStartMenu() EnumBoxLinks(BoxLinks, "Desktop", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), false); QMap Boxes = theAPI->GetAllBoxes(); - foreach(const CSandBoxPtr & pBox, Boxes) + foreach(const CSandBoxPtr & pBox, Boxes) { CSandBoxPlus* pBoxEx = (CSandBoxPlus*)pBox.data(); @@ -2285,7 +2301,7 @@ void CSandMan::OnBoxClosed(const CSandBoxPtr& pBox) void CSandMan::OnBoxCleaned(CSandBoxPlus* pBoxEx) { - if (pBoxEx->GetBool("AutoRemove", false)) + if (pBoxEx->GetBool("AutoRemove", false)) { if (theConf->GetBool("Options/AutoBoxOpsNotify", false)) OnLogMessage(tr("Auto removing sandbox %1").arg(pBoxEx->GetName()), true); @@ -2302,7 +2318,7 @@ void CSandMan::OnStatusChanged() #else QString appTitle = tr("Sandboxie-Plus v%1").arg(GetVersion()); #endif - + bool bConnected = theAPI->IsConnected(); m_pConnect->setEnabled(!bConnected); m_pDisconnect->setEnabled(bConnected); @@ -2318,7 +2334,7 @@ void CSandMan::OnStatusChanged() OnLogMessage(tr("Data Directory: %1").arg(QString(theConf->GetConfigDir()).replace("/","\\"))); //statusBar()->showMessage(tr("Driver version: %1").arg(theAPI->GetVersion())); - + //appTitle.append(tr(" - Driver: v%1").arg(theAPI->GetVersion())); if (bPortable) { @@ -2332,7 +2348,7 @@ void CSandMan::OnStatusChanged() QString NtBoxRoot = theAPI->GetGlobalSettings()->GetText("FileRootPath", "\\??\\%SystemDrive%\\Sandbox\\%USER%\\%SANDBOX%", false, false).replace("GlobalSettings", "[BoxName]"); bool State = false; - PortableRootDir = CCheckableMessageBox::question(this, "Sandboxie-Plus", + PortableRootDir = CCheckableMessageBox::question(this, "Sandboxie-Plus", tr("Sandboxie-Plus was started in portable mode, do you want to put the Sandbox folder into its parent directory?\nYes will choose: %1\nNo will choose: %2") .arg(BoxPath + "\\[BoxName]") .arg(theAPI->Nt2DosPath(NtBoxRoot)) @@ -2392,7 +2408,7 @@ void CSandMan::OnStatusChanged() theAPI->SetSecureParam("UsageFlags", &UsageFlags, sizeof(UsageFlags)); } } - + g_FeatureFlags = theAPI->GetFeatureFlags(); SB_STATUS Status = theAPI->ReloadBoxes(true); @@ -2432,20 +2448,20 @@ void CSandMan::OnStatusChanged() } int DynData = theAPI->IsDyndataActive(); - if (DynData != 1) + if (DynData != 1) { RTL_OSVERSIONINFOEXW versionInfo; memset(&versionInfo, 0, sizeof(RTL_OSVERSIONINFOEXW)); versionInfo.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW); NTSTATUS(WINAPI *RtlGetVersion)(PRTL_OSVERSIONINFOEXW); *(void**)&RtlGetVersion = GetProcAddress(GetModuleHandleA("ntdll.dll"), "RtlGetVersion"); - if (RtlGetVersion != NULL) + if (RtlGetVersion != NULL) RtlGetVersion(&versionInfo); else GetVersionExW((LPOSVERSIONINFOW)&versionInfo); // since windows 10 this one is lying RtlGetVersion(&versionInfo); - if (DynData == 0) + if (DynData == 0) { QString Message = tr("Your Windows build %1 exceeds the current support capabilities of your Sandboxie version, " "resulting in the disabling of token-based security isolation. Consequently, all applications will operate in application compartment mode without secure isolation.\r\n" @@ -2522,7 +2538,7 @@ void CSandMan::CheckCompat(QObject* receiver, const char* member) return; } } - + m_SbieTemplates->RunCheck(); qDebug() << "Template Check took" << timer->elapsed() << "ms"; @@ -2610,7 +2626,7 @@ void CSandMan::CheckSupport() return; static bool ReminderShown = false; - if (!ReminderShown && (g_CertInfo.expired || (g_CertInfo.expirers_in_sec > 0 && g_CertInfo.expirers_in_sec < (60 * 60 * 24 * 30))) && !theConf->GetBool("Options/NoSupportCheck", false)) + if (!ReminderShown && (g_CertInfo.expired || (g_CertInfo.expirers_in_sec > 0 && g_CertInfo.expirers_in_sec < (60 * 60 * 24 * 30))) && !theConf->GetBool("Options/NoSupportCheck", false)) { ReminderShown = true; CSettingsWindow* pSettingsWindow = new CSettingsWindow(this); @@ -2661,8 +2677,11 @@ void CSandMan::OnHotKey(size_t id) case HK_SUSPEND: { - for (auto each : theAPI->GetAllBoxes()) - each->SetSuspendedAll(TRUE); + + for (auto each : theAPI->GetAllBoxes().toStdMap()) { + each.second->SetSuspendedAll(TRUE); + } + break; } @@ -2753,7 +2772,7 @@ void CSandMan::AddLogMessage(const QDateTime& TimeStamp, const QString& Message, else pItem->setText(1, Message); #endif - + m_pMessageLog->GetView()->verticalScrollBar()->setValue(m_pMessageLog->GetView()->verticalScrollBar()->maximum()); } @@ -2825,7 +2844,7 @@ void CSandMan::OnLogSbieMessage(quint32 MsgCode, const QStringList& MsgData, qui else Message.append(tr("
Become a project supporter, and receive a supporter certificate")); } - else + else { static quint64 iLastCertWarning = 0; if (iLastCertWarning + 60 < QDateTime::currentDateTime().toSecsSinceEpoch()) { // reset after 60 seconds @@ -2892,7 +2911,7 @@ void CSandMan::SaveMessageLog(QIODevice* pFile) pFile->write((Msg.TimeStamp.toString("dd.MM.yyyy hh:mm:ss.zzz") + "\t" + FormatSbieMessage(Msg.MsgCode, Msg.MsgData, Msg.ProcessName)).toLatin1() + "\n"); } -bool CSandMan::CheckCertificate(QWidget* pWidget, int iType) +bool CSandMan::CheckCertificate(QWidget* pWidget, int iType) { QString Message; if (iType == 1) @@ -2949,13 +2968,13 @@ SB_STATUS CSandMan::ReloadCert(QWidget* pWidget) } else if (Status.GetStatus() == 0xC0000804L /*STATUS_CONTENT_BLOCKED*/) { - QMessageBox::critical(pWidget ? pWidget : this, "Sandboxie-Plus", + QMessageBox::critical(pWidget ? pWidget : this, "Sandboxie-Plus", tr("The certificate you are attempting to use has been blocked, meaning it has been invalidated for cause. Any attempt to use it constitutes a breach of its terms of use!")); BYTE CertBlocked = 1; theAPI->SetSecureParam("CertBlocked", &CertBlocked, sizeof(CertBlocked)); } - else if (Status.GetStatus() != 0xC0000225L /*STATUS_NOT_FOUND*/) + else if (Status.GetStatus() != 0xC0000225L /*STATUS_NOT_FOUND*/) { QString Info; switch (Status.GetStatus()) @@ -3005,7 +3024,7 @@ void CSandMan::UpdateCertState() if (theConf->GetBool("Debug/CertFakeGracePeriode", false)) g_CertInfo.grace_period = 1; - // simulate a subscription type certificate having expired + // simulate a subscription type certificate having expired if (theConf->GetBool("Debug/CertFakeOld", false)) { g_CertInfo.active = 0; g_CertInfo.expired = 1; @@ -3060,7 +3079,7 @@ void CSandMan::UpdateCertState() void CSandMan::OnQueuedRequest(quint32 ClientPid, quint32 ClientTid, quint32 RequestId, const QVariantMap& Data) { - if (Data["id"].toInt() == 0) + if (Data["id"].toInt() == 0) { QVariantMap Ret; Ret["retval"] = (theAPI->IsStarting(ClientPid) || CSupportDialog::ShowDialog()) ? 1 : 0; @@ -3213,7 +3232,7 @@ void CSandMan::OnDisablePopUp() SB_RESULT(void*) CSandMan::ConnectSbie() { SB_RESULT(void*) Status; - if (!CSbieUtils::IsRunning(CSbieUtils::eAll)) + if (!CSbieUtils::IsRunning(CSbieUtils::eAll)) { if (!CSbieUtils::IsInstalled(CSbieUtils::eAll)) { @@ -3248,7 +3267,7 @@ SB_RESULT(void*) CSandMan::ConnectSbie() SB_STATUS CSandMan::ConnectSbieImpl() { SB_STATUS Status = theAPI->Connect(g_PendingMessage.isEmpty(), theConf->GetBool("Options/UseInteractiveQueue", true)); - + if (!g_PendingMessage.isEmpty()) { OnMessage(g_PendingMessage); PostQuitMessage(0); @@ -3326,11 +3345,11 @@ void CSandMan::OnMaintenance() } //else if (sender() == m_pUpdateCore) { - // // todo + // // todo // return; //} - // uninstall + // uninstall else if (sender() == m_pUninstallAll) { Status = StopSbie(true); @@ -3351,7 +3370,7 @@ void CSandMan::HandleMaintenance(SB_RESULT(void*) Status) connect(processFinishedNotifier, &QWinEventNotifier::activated, this, [processFinishedNotifier, this, hProcess]() { processFinishedNotifier->setEnabled(false); processFinishedNotifier->deleteLater(); - + DWORD dwStatus = 0; GetExitCodeProcess(hProcess, & dwStatus); @@ -3444,16 +3463,16 @@ void CSandMan::OnCleanUp() m_MessageLog.clear(); if (m_pMessageLog) m_pMessageLog->GetTree()->clear(); } - + if (sender() == m_pCleanUpTrace || sender() == m_pCleanUpButton) - if (m_pTraceView) { - m_pTraceView->Clear(); + if (m_pTraceView) { + m_pTraceView->Clear(); m_pTraceInfo->clear(); } if (sender() == m_pCleanUpRecovery || sender() == m_pCleanUpButton) if(m_pRecoveryLog) m_pRecoveryLog->GetTree()->clear(); - + if (sender() == m_pCleanUpProcesses || sender() == m_pCleanUpButton) theAPI->UpdateProcesses(0, ShowAllSessions()); } @@ -3539,7 +3558,7 @@ void CSandMan::UpdateSettings(bool bRebuildUI) m_pTrayIcon->hide(); - if (bRebuildUI) + if (bRebuildUI) { StoreState(); @@ -3721,7 +3740,7 @@ void CSandMan::EditIni(const QString& IniPath, bool bPlus) if (!bPlus && theConf->GetBool("Options/WatchIni", true)) return; // if the ini is watched don't double reload - + QWinEventNotifier* processFinishedNotifier = new QWinEventNotifier(si.hProcess); processFinishedNotifier->setEnabled(true); connect(processFinishedNotifier, &QWinEventNotifier::activated, this, [processFinishedNotifier, this, si, bPlus]() { @@ -3892,7 +3911,7 @@ QString CSandMan::FormatError(const SB_STATUS& Error) //case SB_RemNotEmpty: Message = tr("A sandbox must be emptied before it can be renamed."); break; case SB_DelNotEmpty: Message = tr("A sandbox must be emptied before it can be deleted."); break; case SB_FailedMoveDir: Message = tr("Failed to move directory '%1' to '%2'"); break; - case SB_FailedMoveImage:Message = tr("Failed to move box image '%1' to '%2'"); break; + case SB_FailedMoveImage:Message = tr("Failed to move box image '%1' to '%2'"); break; case SB_SnapIsRunning: Message = tr("This Snapshot operation can not be performed while processes are still running in the box."); break; case SB_SnapMkDirFail: Message = tr("Failed to create directory for new snapshot"); break; case SB_SnapCopyDatFail:Message = tr("Failed to copy box data files"); break; @@ -3956,7 +3975,7 @@ void CSandMan::OnBoxAssistant() void CSandMan::TryFix(quint32 MsgCode, const QStringList& MsgData, const QString& ProcessName, const QString& BoxName) { SetWindowPos((HWND)m_pPopUpWindow->winId(), HWND_NOTOPMOST , 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); - + QPointer pWizard = new CBoxAssistant(this); pWizard->TryFix(MsgCode, MsgData, ProcessName, BoxName); pWizard->setAttribute(Qt::WA_DeleteOnClose); @@ -3976,7 +3995,7 @@ void CSandMan::OpenUrl(const QUrl& url) { QString scheme = url.scheme(); QString host = url.host(); - QString path = url.path(); + QString path = url.path(); QString query = url.query(); if (scheme == "addon") { @@ -4002,7 +4021,7 @@ void CSandMan::OpenUrl(const QUrl& url) { bool bCheck = false; //QString Message = tr("Do you want to open %1 in a sandboxed (yes) or unsandboxed (no) Web browser?").arg(url.toString()); - //QDialogButtonBox::StandardButton Ret = CCheckableMessageBox::question(this, "Sandboxie-Plus", Message , tr("Remember choice for later."), + //QDialogButtonBox::StandardButton Ret = CCheckableMessageBox::question(this, "Sandboxie-Plus", Message , tr("Remember choice for later."), // &bCheck, QDialogButtonBox::Yes | QDialogButtonBox::No | QDialogButtonBox::Cancel, QDialogButtonBox::Yes, QMessageBox::Question); CCheckableMessageBox mb(this); @@ -4028,9 +4047,9 @@ void CSandMan::OpenUrl(const QUrl& url) else ShellExecute(MainWndHandle, NULL, url.toString().toStdWString().c_str(), NULL, NULL, SW_SHOWNORMAL); } -bool CSandMan::IsWFPEnabled() const -{ - return (g_FeatureFlags & CSbieAPI::eSbieFeatureWFP) != 0; +bool CSandMan::IsWFPEnabled() const +{ + return (g_FeatureFlags & CSbieAPI::eSbieFeatureWFP) != 0; } QString CSandMan::GetVersion() @@ -4058,7 +4077,7 @@ void CSandMan::SetUITheme() bDark = (settings.value("AppsUseLightTheme") == 0); } else bDark = (iDark == 1); - + if (bDark) QApplication::setPalette(m_DarkPalett); else @@ -4070,7 +4089,7 @@ void CSandMan::SetUITheme() int iFusion = theConf->GetInt("Options/UseFusionTheme", 2); if (iFusion == 2) bFusion = bDark; - else + else bFusion = (iFusion == 1); if (bFusion) @@ -4111,7 +4130,7 @@ void CSandMan::SetTitleTheme(const HWND& hwnd) QSettings::NativeFormat).value("CurrentBuild").toInt(); if (CurrentVersion < 17763) // Windows 10 1809 - return; - + HMODULE dwmapi = GetModuleHandle(L"dwmapi.dll"); if (dwmapi) { @@ -4162,7 +4181,7 @@ void CSandMan::LoadLanguage() #endif m_LanguageId = LocaleNameToLCID(m_Language.toStdWString().c_str(), 0); - if (!m_LanguageId) + if (!m_LanguageId) m_LanguageId = 1033; // default to English LoadLanguage(m_Language, "sandman", 0); @@ -4186,7 +4205,7 @@ void CSandMan::LoadLanguage(const QString& Lang, const QString& Module, int Inde if (Lang.isEmpty()) return; - + QString LangAux = Lang; // Short version as fallback LangAux.truncate(LangAux.lastIndexOf('_')); @@ -4210,7 +4229,7 @@ void CSandMan::OnHelp() { //if (sender() == m_pSupport) // QDesktopServices::openUrl(QUrl("https://sandboxie-plus.com/go.php?to=donate")); - //else + //else if (sender() == m_pContribution) QDesktopServices::openUrl(QUrl("https://sandboxie-plus.com/go.php?to=sbie-contribute")); else if (sender() == m_pManual) @@ -4257,14 +4276,14 @@ void CSandMan::OnAbout() msgBox->setInformativeText(AboutText); QIcon ico(QLatin1String(":/SandMan.png")); - + QPixmap pix(128, 160); pix.fill(Qt::transparent); QPainter painter(&pix); painter.drawPixmap(0, 0, ico.pixmap(128, 128)); - if (g_CertInfo.active) + if (g_CertInfo.active) { //painter.setPen(Qt::blue); //painter.drawRect(0, 0, 127, 159); @@ -4335,20 +4354,20 @@ int g_CertAmount = 0; void SlotSend(const std::wstring& message) { std::wstring strSlotName = L"\\\\*\\mailslot\\" + g_SlotName; - HANDLE hSlot = CreateFile(strSlotName.c_str(), - GENERIC_WRITE, + HANDLE hSlot = CreateFile(strSlotName.c_str(), + GENERIC_WRITE, FILE_SHARE_READ, - (LPSECURITY_ATTRIBUTES) NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - (HANDLE) NULL); - if (hSlot == INVALID_HANDLE_VALUE) - { + (LPSECURITY_ATTRIBUTES) NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + (HANDLE) NULL); + if (hSlot == INVALID_HANDLE_VALUE) + { //GetLastError(); return; - } + } - DWORD cbWritten; + DWORD cbWritten; WriteFile(hSlot, message.c_str(), (DWORD)(message.size() + 1) * sizeof(wchar_t), &cbWritten, NULL); CloseHandle(hSlot); @@ -4381,14 +4400,14 @@ int CountSeats() DWORD WINAPI MailThreadFunc(LPVOID lpParam) { std::wstring strSlotName = L"\\\\.\\mailslot\\" + g_SlotName; - HANDLE hSlot = CreateMailslot(strSlotName.c_str(), - 0, // no maximum message size - MAILSLOT_WAIT_FOREVER, // no time-out for operations + HANDLE hSlot = CreateMailslot(strSlotName.c_str(), + 0, // no maximum message size + MAILSLOT_WAIT_FOREVER, // no time-out for operations (LPSECURITY_ATTRIBUTES) NULL); // default security - if (hSlot == INVALID_HANDLE_VALUE) { + if (hSlot == INVALID_HANDLE_VALUE) { //GetLastError() - return FALSE; - } + return FALSE; + } ScanForSeats(); @@ -4398,11 +4417,11 @@ DWORD WINAPI MailThreadFunc(LPVOID lpParam) { DWORD cbMessage; DWORD dwMessageCount; - if(!GetMailslotInfo(hSlot, // mailslot handle - (LPDWORD)NULL, // no maximum message size - &cbMessage, // size of next message - &dwMessageCount, // number of messages - (LPDWORD)NULL)) // no read time-out + if(!GetMailslotInfo(hSlot, // mailslot handle + (LPDWORD)NULL, // no maximum message size + &cbMessage, // size of next message + &dwMessageCount, // number of messages + (LPDWORD)NULL)) // no read time-out { //GetLastError(); continue; diff --git a/SandboxiePlus/SandMan/SandMan.h b/SandboxiePlus/SandMan/SandMan.h index 9a31fab7..d7af590d 100644 --- a/SandboxiePlus/SandMan/SandMan.h +++ b/SandboxiePlus/SandMan/SandMan.h @@ -24,7 +24,7 @@ class CScriptManager; class CAddonManager; struct ToolBarAction { - // Identifier of action stored in ini. Empty for separator. + // Identifier of action stored in ini. Empty for separator. QString scriptName = ""; // Not owned. Null for special cases. @@ -104,7 +104,7 @@ public: QIcon MakeIconBusy(const QIcon& Icon, int Index = 0); QIcon IconAddOverlay(const QIcon& Icon, const QString& Name, int Size = 24); QString GetBoxDescription(int boxType); - + bool CheckCertificate(QWidget* pWidget, int iType = 0); bool IsAlwaysOnTop() const; @@ -156,7 +156,7 @@ protected: CScriptManager* m_SbieScripts; CAddonManager* m_AddonManager; - + QMap>> m_pAsyncProgress; QMap> m_MissingTemplates; @@ -183,7 +183,7 @@ protected: struct SSbieMsg { QDateTime TimeStamp; quint32 MsgCode; - QStringList MsgData; + QStringList MsgData; QString ProcessName; }; QVector m_MessageLog; @@ -279,6 +279,8 @@ private slots: void CheckForUpdates(bool bManual = true); + void OnRestartAsAdmin(); + void OnExit(); void OnHelp(); void OnAbout(); @@ -366,6 +368,7 @@ private: QHBoxLayout* m_pMenuLayout; QMenu* m_pMenuFile; + QAction* m_pRestart; QAction* m_pRunBoxed; QAction* m_pNewBox; QAction* m_pNewGroup; diff --git a/SandboxiePlus/SandMan/Windows/OptionsAdvanced.cpp b/SandboxiePlus/SandMan/Windows/OptionsAdvanced.cpp index 8d5b16ac..798e623d 100644 --- a/SandboxiePlus/SandMan/Windows/OptionsAdvanced.cpp +++ b/SandboxiePlus/SandMan/Windows/OptionsAdvanced.cpp @@ -104,6 +104,7 @@ 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.chkNotifyProtect, SIGNAL(clicked(bool)), this, SLOT(OnAdvancedChanged())); connect(ui.treeInjectDll, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(OnToggleInjectDll(QTreeWidgetItem *, int))); @@ -262,6 +263,7 @@ void COptionsWindow::LoadAdvanced() ui.chkLessConfidential->setChecked(m_BoxTemplates.contains("LessConfidentialBox")); ui.chkNotifyProtect->setChecked(m_pBox->GetBool("NotifyBoxProtected", false)); + ui.chkProtectWindow->setChecked(m_pBox->GetBool("IsProtectScreen")); QStringList Users = m_pBox->GetText("Enabled").split(","); ui.lstUsers->clear(); @@ -465,6 +467,8 @@ void COptionsWindow::SaveAdvanced() WriteAdvancedCheck(ui.chkConfidential, "ConfidentialBox", "y", ""); WriteAdvancedCheck(ui.chkNotifyProtect, "NotifyBoxProtected", "y", ""); + WriteAdvancedCheck(ui.chkProtectWindow, "IsProtectScreen", "y", "n"); + QStringList Users; for (int i = 0; i < ui.lstUsers->count(); i++) Users.append(ui.lstUsers->item(i)->text()); diff --git a/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp b/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp index 50591066..360b52fa 100644 --- a/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp +++ b/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp @@ -313,6 +313,7 @@ CSettingsWindow::CSettingsWindow(QWidget* parent) connect(ui.chkNotifyRecovery, SIGNAL(stateChanged(int)), this, SLOT(OnOptChanged())); connect(ui.chkShowRecovery, SIGNAL(stateChanged(int)), this, SLOT(OnOptChanged())); + connect(ui.chkCheckDelete, SIGNAL(stateChanged(int)), this, SLOT(OnOptChanged())); connect(ui.chkRecoveryTop, SIGNAL(stateChanged(int)), this, SLOT(OnOptChanged())); // @@ -908,6 +909,7 @@ void CSettingsWindow::LoadSettings() ui.chkSandboxUrls->setCheckState(CSettingsWindow__Int2Chk(theConf->GetInt("Options/OpenUrlsSandboxed", 2))); ui.chkShowRecovery->setChecked(theConf->GetBool("Options/ShowRecovery", false)); + ui.chkCheckDelete->setChecked(!theConf->GetBool("Options/CleanUpOnStart", false)); ui.chkNotifyRecovery->setChecked(!theConf->GetBool("Options/InstantRecovery", true)); ui.chkRecoveryTop->setChecked(theConf->GetBool("Options/RecoveryOnTop", true)); ui.chkAsyncBoxOps->setChecked(theConf->GetBool("Options/UseAsyncBoxOps", false)); @@ -1558,6 +1560,8 @@ void CSettingsWindow::SaveSettings() theConf->SetValue("Options/EnableSuspendKey", ui.chkSuspend->isChecked()); theConf->SetValue("Options/SuspendKeySequence", ui.keySuspend->keySequence().toString()); + theConf->SetValue("Options/CleanUpOnStart", !ui.chkCheckDelete->isChecked()); + theConf->SetValue("Options/WatchBoxSize", ui.chkMonitorSize->isChecked()); theConf->SetValue("Options/WatchIni", ui.chkWatchConfig->isChecked());