From e1c46bb269e6db18c14496783815be7bee09631f Mon Sep 17 00:00:00 2001 From: DavidXanatos <3890945+DavidXanatos@users.noreply.github.com> Date: Sat, 20 Apr 2024 14:09:16 +0200 Subject: [PATCH] 3742 --- CHANGELOG.md | 1 + .../SandMan/Windows/OptionsAdvanced.cpp | 78 +++++++++++++++---- SandboxiePlus/SandMan/Windows/OptionsWindow.h | 2 +- 3 files changed, 65 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77fe66e8..84e41d97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Note: this option may cause issues in games hence do not enable it for gaming boxes. - added support for hardlinks [#3826](https://github.com/sandboxie-plus/Sandboxie/issues/3826) - added mechanism to terminate stuck sandboxed processes from the driver +- added Sandman: Make the trigger list editable [#3742](https://github.com/sandboxie-plus/Sandboxie/issues/3742) ### Changed - improved Avast template [#3777](https://github.com/sandboxie-plus/Sandboxie/pull/3777) diff --git a/SandboxiePlus/SandMan/Windows/OptionsAdvanced.cpp b/SandboxiePlus/SandMan/Windows/OptionsAdvanced.cpp index 4e298342..4a1d9026 100644 --- a/SandboxiePlus/SandMan/Windows/OptionsAdvanced.cpp +++ b/SandboxiePlus/SandMan/Windows/OptionsAdvanced.cpp @@ -83,7 +83,7 @@ void COptionsWindow::CreateAdvanced() connect(ui.chkDbgTrace, SIGNAL(clicked(bool)), this, SLOT(OnAdvancedChanged())); connect(ui.chkErrTrace, SIGNAL(clicked(bool)), this, SLOT(OnAdvancedChanged())); - connect(ui.treeTriggers, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(OnTriggerChanged(QTreeWidgetItem *, int))); + connect(ui.treeTriggers, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(OnTriggerChanged())); connect(ui.btnAddAutoRun, SIGNAL(clicked(bool)), this, SLOT(OnAddAutoRun())); connect(ui.btnAddAutoSvc, SIGNAL(clicked(bool)), this, SLOT(OnAddAutoSvc())); connect(ui.btnAddAutoExec, SIGNAL(clicked(bool)), this, SLOT(OnAddAutoExec())); @@ -238,6 +238,19 @@ void COptionsWindow::LoadAdvanced() foreach(const QString & Value, m_pBox->GetTextList("OnBoxTerminate", m_Template)) AddTriggerItem(Value, eTerminateCmd); + foreach(const QString & Value, m_pBox->GetTextList("StartProgramDisabled", m_Template)) + AddTriggerItem(Value, eOnStartCmd, true); + foreach(const QString & Value, m_pBox->GetTextList("StartServiceDisabled", m_Template)) + AddTriggerItem(Value, eOnStartSvc, true); + foreach(const QString & Value, m_pBox->GetTextList("AutoExecDisabled", m_Template)) + AddTriggerItem(Value, eAutoExec, true); + foreach(const QString & Value, m_pBox->GetTextList("OnFileRecoveryDisabled", m_Template)) + AddTriggerItem(Value, eRecoveryCheck, true); + foreach(const QString & Value, m_pBox->GetTextList("OnBoxDeleteDisabled", m_Template)) + AddTriggerItem(Value, eDeleteCmd, true); + foreach(const QString & Value, m_pBox->GetTextList("OnBoxTerminateDisabled", m_Template)) + AddTriggerItem(Value, eTerminateCmd, true); + ShowTriggersTmpl(); // @@ -304,17 +317,17 @@ void COptionsWindow::ShowTriggersTmpl(bool bUpdate) foreach(const QString& Template, m_pBox->GetTemplates()) { foreach(const QString & Value, m_pBox->GetTextListTmpl("StartProgram", Template)) - AddTriggerItem(Value, eOnStartCmd, Template); + AddTriggerItem(Value, eOnStartCmd, false, Template); foreach(const QString & Value, m_pBox->GetTextListTmpl("StartService", Template)) - AddTriggerItem(Value, eOnStartSvc, Template); + AddTriggerItem(Value, eOnStartSvc, false, Template); foreach(const QString & Value, m_pBox->GetTextListTmpl("AutoExec", Template)) - AddTriggerItem(Value, eAutoExec, Template); + AddTriggerItem(Value, eAutoExec, false, Template); foreach(const QString & Value, m_pBox->GetTextListTmpl("OnFileRecovery", Template)) - AddTriggerItem(Value, eRecoveryCheck, Template); + AddTriggerItem(Value, eRecoveryCheck, false, Template); foreach(const QString & Value, m_pBox->GetTextListTmpl("OnBoxDelete", Template)) - AddTriggerItem(Value, eDeleteCmd, Template); + AddTriggerItem(Value, eDeleteCmd, false, Template); foreach(const QString & Value, m_pBox->GetTextListTmpl("OnBoxTerminate", Template)) - AddTriggerItem(Value, eTerminateCmd, Template); + AddTriggerItem(Value, eTerminateCmd, false, Template); } } else if (bUpdate) @@ -428,24 +441,55 @@ void COptionsWindow::SaveAdvanced() QStringList DeleteCommand; QStringList AutoExec; QStringList TerminateCommand; + + QStringList StartProgramDisabled; + QStringList StartServiceDisabled; + QStringList RecoveryCheckDisabled; + QStringList DeleteCommandDisabled; + QStringList AutoExecDisabled; + QStringList TerminateCommandDisabled; + for (int i = 0; i < ui.treeTriggers->topLevelItemCount(); i++) { QTreeWidgetItem* pItem = ui.treeTriggers->topLevelItem(i); - switch (pItem->data(0, Qt::UserRole).toInt()) + if (pItem->checkState(0) == Qt::Checked) { - case eOnStartCmd: StartProgram.append(pItem->text(2)); break; - case eOnStartSvc: StartService.append(pItem->text(2)); break; - case eAutoExec: AutoExec.append(pItem->text(2)); break; - case eRecoveryCheck: RecoveryCheck.append(pItem->text(2)); break; - case eDeleteCmd: DeleteCommand.append(pItem->text(2)); break; - case eTerminateCmd: TerminateCommand.append(pItem->text(2)); break; + switch (pItem->data(0, Qt::UserRole).toInt()) + { + case eOnStartCmd: StartProgram.append(pItem->text(2)); break; + case eOnStartSvc: StartService.append(pItem->text(2)); break; + case eAutoExec: AutoExec.append(pItem->text(2)); break; + case eRecoveryCheck: RecoveryCheck.append(pItem->text(2)); break; + case eDeleteCmd: DeleteCommand.append(pItem->text(2)); break; + case eTerminateCmd: TerminateCommand.append(pItem->text(2)); break; + } + } + else + { + switch (pItem->data(0, Qt::UserRole).toInt()) + { + case eOnStartCmd: StartProgramDisabled.append(pItem->text(2)); break; + case eOnStartSvc: StartServiceDisabled.append(pItem->text(2)); break; + case eAutoExec: AutoExecDisabled.append(pItem->text(2)); break; + case eRecoveryCheck: RecoveryCheckDisabled.append(pItem->text(2)); break; + case eDeleteCmd: DeleteCommandDisabled.append(pItem->text(2)); break; + case eTerminateCmd: TerminateCommandDisabled.append(pItem->text(2)); break; + } } } + WriteTextList("StartProgram", StartProgram); WriteTextList("StartService", StartService); WriteTextList("AutoExec", AutoExec); WriteTextList("OnFileRecovery", RecoveryCheck); WriteTextList("OnBoxDelete", DeleteCommand); WriteTextList("OnBoxTerminate", TerminateCommand); + + WriteTextList("StartProgramDisabled", StartProgramDisabled); + WriteTextList("StartServiceDisabled", StartServiceDisabled); + WriteTextList("AutoExecDisabled", AutoExecDisabled); + WriteTextList("OnFileRecoveryDisabled", RecoveryCheckDisabled); + WriteTextList("OnBoxDeleteDisabled", DeleteCommandDisabled); + WriteTextList("OnBoxTerminateDisabled", TerminateCommandDisabled); // @@ -874,7 +918,7 @@ void COptionsWindow::CloseOptionEdit(QTreeWidgetItem* pItem, bool bSave) // // triggers -void COptionsWindow::AddTriggerItem(const QString& Value, ETriggerAction Type, const QString& Template) +void COptionsWindow::AddTriggerItem(const QString& Value, ETriggerAction Type, bool disabled, const QString& Template) { QTreeWidgetItem* pItem = new QTreeWidgetItem(); pItem->setData(0, Qt::UserRole, Template.isEmpty() ? Type : -1); @@ -906,6 +950,10 @@ void COptionsWindow::AddTriggerItem(const QString& Value, ETriggerAction Type, c } pItem->setText(2, Value); pItem->setFlags(pItem->flags() | Qt::ItemIsEditable); + + if (Template.isEmpty()) + pItem->setCheckState(0, disabled ? Qt::Unchecked : Qt::Checked); + ui.treeTriggers->addTopLevelItem(pItem); } diff --git a/SandboxiePlus/SandMan/Windows/OptionsWindow.h b/SandboxiePlus/SandMan/Windows/OptionsWindow.h index 2687d328..318c2300 100644 --- a/SandboxiePlus/SandMan/Windows/OptionsWindow.h +++ b/SandboxiePlus/SandMan/Windows/OptionsWindow.h @@ -473,7 +473,7 @@ protected: void SaveAdvanced(); void UpdateBoxIsolation(); void ShowTriggersTmpl(bool bUpdate = false); - void AddTriggerItem(const QString& Value, ETriggerAction Type, const QString& Template = QString()); + void AddTriggerItem(const QString& Value, ETriggerAction Type, bool disabled = false, const QString& Template = QString()); void ShowHiddenProcTmpl(bool bUpdate = false); void ShowHostProcTmpl(bool bUpdate = false); void AddHiddenProcEntry(const QString& Name, const QString& Template = QString());