diff --git a/CHANGELOG.md b/CHANGELOG.md index 61cb0c2c..4f7fd8d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,12 +9,16 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [1.10.1 / 5.65.1] - 2023-07-?? +### Changed +- reworked Nt Object Handle handling + ### Fixed - fixed "Disable Security Isolation" causes a game to stop playing audio [#2893](https://github.com/sandboxie-plus/Sandboxie/issues/2893) - fixed NtQueryDirectoryObject not implemented [#2734](https://github.com/sandboxie-plus/Sandboxie/issues/2734) +- fixed issue with working directory for run menu entries +- fixed CreateMutex, GetLastError error ( Ipc_GetName ) [#3112](https://github.com/sandboxie-plus/Sandboxie/issues/3112) + -### Changed -- reworked Nt Object Handle handling diff --git a/Sandboxie/core/dll/ipc.c b/Sandboxie/core/dll/ipc.c index a41ad4ff..a774a151 100644 --- a/Sandboxie/core/dll/ipc.c +++ b/Sandboxie/core/dll/ipc.c @@ -518,6 +518,7 @@ _FX void Ipc_CreateObjects(void) WCHAR *backslash; WCHAR *buffer = NULL; WCHAR *BNOLINKS = NULL; + WCHAR *GLOBAL = NULL; WCHAR *buffer2 = NULL; HANDLE handle; WCHAR str[64]; @@ -631,6 +632,10 @@ _FX void Ipc_CreateObjects(void) wcscpy(buffer, buffer2); wcscat(buffer, L"\\Global"); + GLOBAL = Dll_Alloc((wcslen(buffer) + 32) * sizeof(WCHAR)); + + wcscpy(GLOBAL, buffer); + status = SbieApi_CreateDirOrLink(buffer, buffer2); if (! NT_SUCCESS(status)) { @@ -676,7 +681,7 @@ _FX void Ipc_CreateObjects(void) wcscpy(buffer, CopyPath); wcscat(buffer, L"\\Global"); - status = SbieApi_CreateDirOrLink(buffer, CopyPath); + status = SbieApi_CreateDirOrLink(buffer, GLOBAL); if (! NT_SUCCESS(status)) { errlvl = 41; @@ -713,6 +718,8 @@ finish: Dll_Free(buffer); if(BNOLINKS) Dll_Free(BNOLINKS); + if(GLOBAL) + Dll_Free(GLOBAL); if(buffer2) Dll_Free(buffer2); diff --git a/SandboxiePlus/SandMan/Forms/OptionsWindow.ui b/SandboxiePlus/SandMan/Forms/OptionsWindow.ui index 4e70d414..68f9c0b5 100644 --- a/SandboxiePlus/SandMan/Forms/OptionsWindow.ui +++ b/SandboxiePlus/SandMan/Forms/OptionsWindow.ui @@ -869,11 +869,6 @@ Name - - - Icon - - Command Line diff --git a/SandboxiePlus/SandMan/Forms/SettingsWindow.ui b/SandboxiePlus/SandMan/Forms/SettingsWindow.ui index 5752e6ae..1bc976f1 100644 --- a/SandboxiePlus/SandMan/Forms/SettingsWindow.ui +++ b/SandboxiePlus/SandMan/Forms/SettingsWindow.ui @@ -665,11 +665,6 @@ Name - - - Icon - - Command Line diff --git a/SandboxiePlus/SandMan/Views/FileView.cpp b/SandboxiePlus/SandMan/Views/FileView.cpp index c4515b69..1d796697 100644 --- a/SandboxiePlus/SandMan/Views/FileView.cpp +++ b/SandboxiePlus/SandMan/Views/FileView.cpp @@ -6,6 +6,7 @@ #include "../MiscHelpers/Common/TreeItemModel.h" #include "../MiscHelpers/Common/OtherFunctions.h" #include "../QSbieAPI/SbieUtils.h" +#include "../Windows/SettingsWindow.h" CFileView::CFileView(QWidget *parent) : QWidget(parent) @@ -198,7 +199,8 @@ int openShellContextMenu(const QStringList& Files, void* parentWindow, const CSa QString FoundPin; QString FileName = Files.first(); foreach(const QString & RunOption, RunOptions) { - QString CmdFile = pBoxPlus->GetCommandFile(Split2(RunOption, "|").second); + QVariantMap Entry = GetRunEntry(RunOption); + QString CmdFile = pBoxPlus->GetCommandFile(Entry["Command"].toString()); if(CmdFile.compare(FileName, Qt::CaseInsensitive) == 0) { FoundPin = RunOption; break; diff --git a/SandboxiePlus/SandMan/Views/SbieView.cpp b/SandboxiePlus/SandMan/Views/SbieView.cpp index 73c4a8c8..584577a4 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.cpp +++ b/SandboxiePlus/SandMan/Views/SbieView.cpp @@ -13,6 +13,7 @@ #include "../Views/FileView.h" #include "../Wizards/NewBoxWizard.h" #include "../Helpers/WinHelper.h" +#include "../Windows/SettingsWindow.h" #include "qt_windows.h" #include "qwindowdefs_win.h" @@ -616,7 +617,8 @@ void CSbieView::UpdateProcMenu(const CBoxedProcessPtr& pProcess, int iProcessCou QString FoundPin; QString FileName = pProcess->GetFileName(); foreach(const QString& RunOption, RunOptions) { - QString CmdFile = pBoxPlus->GetCommandFile(Split2(RunOption, "|").second); + QVariantMap Entry = GetRunEntry(RunOption); + QString CmdFile = pBoxPlus->GetCommandFile(Entry["Command"].toString()); if(CmdFile.compare(FileName, Qt::CaseInsensitive) == 0) { FoundPin = RunOption; break; @@ -626,6 +628,7 @@ void CSbieView::UpdateProcMenu(const CBoxedProcessPtr& pProcess, int iProcessCou if (m_pMenuPreset) { m_pMenuPinToRun->setChecked(!FoundPin.isEmpty()); m_pMenuPinToRun->setData(FoundPin); + //m_pMenuPinToRun->setProperty("WorkingDir", pProcess-> // todo m_pMenuAllowInternet->setChecked(pProcess.objectCast()->HasInternetAccess()); @@ -1788,7 +1791,8 @@ void CSbieView::OnMenuContextMenu(const QPoint& point) QString FoundPin; QString FileName = pBoxPlus->GetCommandFile(LinkTarget); foreach(const QString& RunOption, RunOptions) { - QString CmdFile = pBoxPlus->GetCommandFile(Split2(RunOption, "|").second); + QVariantMap Entry = GetRunEntry(RunOption); + QString CmdFile = pBoxPlus->GetCommandFile(Entry["Command"].toString()); if(CmdFile.compare(FileName, Qt::CaseInsensitive) == 0) { FoundPin = RunOption; break; @@ -1796,8 +1800,14 @@ void CSbieView::OnMenuContextMenu(const QPoint& point) } m_pCtxPinToRun->setChecked(!FoundPin.isEmpty()); - if (FoundPin.isEmpty()) - m_pCtxPinToRun->setData(pAction->text() + "|\"" + pBoxPlus->MakeBoxCommand(LinkTarget) + "\""); + if (FoundPin.isEmpty()) { + QVariantMap Entry; + Entry["Name"] = pAction->text(); + Entry["Icon"] = pAction->property("Icon").toString() + "," + pAction->property("IconIndex").toString(); + Entry["WorkingDir"] = pBoxPlus->MakeBoxCommand(pAction->property("WorkingDir").toString()); + Entry["Command"] = "\"" + pBoxPlus->MakeBoxCommand(LinkTarget) + "\""; + m_pCtxPinToRun->setData(MakeRunEntry(Entry)); + } else m_pCtxPinToRun->setData(FoundPin); m_pCtxMkLink->setData(LinkTarget); @@ -1841,6 +1851,8 @@ void CSbieView::UpdateStartMenu(CSandBoxPlus* pBoxEx) if(Icon.isNull()) Icon = m_IconProvider.icon(QFileInfo(Link.Target)); pAction->setIcon(Icon); pAction->setData(Link.Target); + pAction->setProperty("Icon", Link.Icon); + pAction->setProperty("IconIndex", Link.IconIndex); pAction->setProperty("WorkingDir", Link.WorkDir); } } @@ -1857,28 +1869,27 @@ void CSbieView::UpdateRunMenu(const CSandBoxPtr& pBox) QStringList RunOptions = pBox->GetTextList("RunCommand", true, false, true); foreach(const QString& RunOption, RunOptions) { - StrPair NameCmd = Split2(RunOption, "|"); - - StrPair NameIcon = Split2(NameCmd.first, ","); + QVariantMap Entry = GetRunEntry(RunOption); QMenu* pMenu; - StrPair FolderName = Split2(NameIcon.first, "\\", true); + StrPair FolderName = Split2(Entry["Name"].toString(), "\\", true); if (FolderName.second.isEmpty()) { FolderName.second = FolderName.first; pMenu = m_pMenuRun; } else pMenu = GetMenuFolder(FolderName.first.replace("\\", "/"), m_pMenuRun, m_RunFolders); - StrPair IconIndex = Split2(NameIcon.second, ",", true); + StrPair IconIndex = Split2(Entry["Icon"].toString(), ",", true); QAction* pAction = pMenu->addAction(FolderName.second, this, SLOT(OnSandBoxAction())); if (IconIndex.first.isEmpty()) - pAction->setIcon(m_IconProvider.icon(QFileInfo(pBoxEx->GetCommandFile(NameCmd.second)))); + pAction->setIcon(m_IconProvider.icon(QFileInfo(pBoxEx->GetCommandFile(Entry["Command"].toString())))); else if(IconIndex.second.isEmpty()) - pAction->setIcon(LoadWindowsIcon(pBoxEx->GetCommandFile(NameCmd.second), IconIndex.first.toInt())); + pAction->setIcon(LoadWindowsIcon(pBoxEx->GetCommandFile(Entry["Command"].toString()), IconIndex.first.toInt())); else pAction->setIcon(LoadWindowsIcon(pBoxEx->GetCommandFile(IconIndex.first), IconIndex.second.toInt())); - pAction->setData(NameCmd.second); + pAction->setData(Entry["Command"].toString()); + pAction->setProperty("WorkingDir", Entry["WorkingDir"]); } if (!m_pMenuRunStart) diff --git a/SandboxiePlus/SandMan/Windows/OptionsGeneral.cpp b/SandboxiePlus/SandMan/Windows/OptionsGeneral.cpp index e3a14e3f..e946e559 100644 --- a/SandboxiePlus/SandMan/Windows/OptionsGeneral.cpp +++ b/SandboxiePlus/SandMan/Windows/OptionsGeneral.cpp @@ -264,12 +264,7 @@ void COptionsWindow::LoadGeneral() ui.treeRun->clear(); foreach(const QString& Value, m_pBox->GetTextList("RunCommand", m_Template)) - { - StrPair NameCmd = Split2(Value, "|"); - StrPair NameIcon = Split2(NameCmd.first, ","); - QTreeWidgetItem* pItem = new QTreeWidgetItem(); - AddRunItem(NameIcon.first, NameIcon.second, NameCmd.second); - } + AddRunItem(ui.treeRun, GetRunEntry(Value)); QString Action = m_pBox->GetText("DblClickAction"); int pos = -1; @@ -369,14 +364,9 @@ void COptionsWindow::SaveGeneral() QStringList RunCommands; - for (int i = 0; i < ui.treeRun->topLevelItemCount(); i++) { - QTreeWidgetItem* pItem = ui.treeRun->topLevelItem(i); - if(pItem->text(1).isEmpty()) - RunCommands.prepend(pItem->text(0) + "|" + pItem->text(2)); - else - RunCommands.prepend(pItem->text(0) + "," + pItem->text(1) + "|" + pItem->text(2)); + for (int i = 0; i < ui.treeRun->topLevelItemCount(); i++) + RunCommands.prepend(MakeRunEntry(ui.treeRun->topLevelItem(i))); - } //WriteTextList("RunCommand", RunCommands); m_pBox->DelValue("RunCommand"); foreach(const QString& Value, RunCommands) @@ -900,7 +890,12 @@ void COptionsWindow::OnBrowsePath() return; CSandBoxPlus* pBoxEx = qobject_cast(m_pBox.data()); - AddRunItem(Name, "", "\"" + (pBoxEx ? pBoxEx->MakeBoxCommand(Value) : Value) + "\""); + + QVariantMap Entry; + Entry["Name"] = Name; + Entry["Command"] = "\"" + (pBoxEx ? pBoxEx->MakeBoxCommand(Value) : Value) + "\""; + AddRunItem(ui.treeRun, Entry); + m_GeneralChanged = true; OnOptChanged(); } @@ -915,18 +910,12 @@ void COptionsWindow::OnAddCommand() if (Name.isEmpty()) return; - AddRunItem(Name, "", Value); - OnRunChanged(); -} + QVariantMap Entry; + Entry["Name"] = Name; + Entry["Command"] = Value; + AddRunItem(ui.treeRun, Entry); -void COptionsWindow::AddRunItem(const QString& Name, const QString& Icon, const QString& Command) -{ - QTreeWidgetItem* pItem = new QTreeWidgetItem(); - pItem->setText(0, Name); - pItem->setText(1, Icon); - pItem->setText(2, Command); - pItem->setFlags(pItem->flags() | Qt::ItemIsEditable); - ui.treeRun->addTopLevelItem(pItem); + OnRunChanged(); } void COptionsWindow::OnCommandUp() diff --git a/SandboxiePlus/SandMan/Windows/OptionsWindow.h b/SandboxiePlus/SandMan/Windows/OptionsWindow.h index bc98d531..dedb4f40 100644 --- a/SandboxiePlus/SandMan/Windows/OptionsWindow.h +++ b/SandboxiePlus/SandMan/Windows/OptionsWindow.h @@ -351,8 +351,6 @@ protected: void SaveConfig(); void UpdateCurrentTab(); - void AddRunItem(const QString& Name, const QString& Icon, const QString& Command); - void CreateGeneral(); void LoadGeneral(); void SaveGeneral(); diff --git a/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp b/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp index da26d455..d74c4f78 100644 --- a/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp +++ b/SandboxiePlus/SandMan/Windows/SettingsWindow.cpp @@ -14,6 +14,8 @@ #include "../Wizards/TemplateWizard.h" #include "../AddonManager.h" #include +#include +#include #include @@ -698,7 +700,10 @@ void CSettingsWindow::OnBrowsePath() if (Name.isEmpty()) return; - AddRunItem(Name, "", "\"" + Value + "\""); + QVariantMap Entry; + Entry["Name"] = Name; + Entry["Command"] = "\"" + Value + "\""; + AddRunItem(ui.treeRun, Entry); } void CSettingsWindow::OnAddCommand() @@ -711,18 +716,12 @@ void CSettingsWindow::OnAddCommand() if (Name.isEmpty()) return; - AddRunItem(Name, "", Value); - OnRunChanged(); -} + QVariantMap Entry; + Entry["Name"] = Name; + Entry["Command"] = Value; + AddRunItem(ui.treeRun, Entry); -void CSettingsWindow::AddRunItem(const QString& Name, const QString& Icon, const QString& Command) -{ - QTreeWidgetItem* pItem = new QTreeWidgetItem(); - pItem->setText(0, Name); - pItem->setText(1, Icon); - pItem->setText(2, Command); - pItem->setFlags(pItem->flags() | Qt::ItemIsEditable); - ui.treeRun->addTopLevelItem(pItem); + OnRunChanged(); } void CSettingsWindow::OnCommandUp() @@ -899,11 +898,7 @@ void CSettingsWindow::LoadSettings() ui.treeRun->clear(); foreach(const QString& Value, theAPI->GetGlobalSettings()->GetTextList("RunCommand", false)) - { - StrPair NameCmd = Split2(Value, "|"); - StrPair NameIcon = Split2(NameCmd.first, ","); - AddRunItem(NameIcon.first, NameIcon.second, NameCmd.second); - } + AddRunItem(ui.treeRun, GetRunEntry(Value)); m_RunChanged = false; ui.cmbDefault->clear(); @@ -1258,13 +1253,9 @@ void CSettingsWindow::SaveSettings() m_RunChanged = false; QStringList RunCommands; - for (int i = 0; i < ui.treeRun->topLevelItemCount(); i++) { - QTreeWidgetItem* pItem = ui.treeRun->topLevelItem(i); - if (pItem->text(1).isEmpty()) - RunCommands.prepend(pItem->text(0) + "|" + pItem->text(2)); - else - RunCommands.prepend(pItem->text(0) + "," + pItem->text(1) + "|" + pItem->text(2)); - } + for (int i = 0; i < ui.treeRun->topLevelItemCount(); i++) + RunCommands.prepend(MakeRunEntry(ui.treeRun->topLevelItem(i))); + //WriteTextList("RunCommand", RunCommands); theAPI->GetGlobalSettings()->DelValue("RunCommand"); foreach(const QString & Value, RunCommands) @@ -1936,6 +1927,57 @@ void CSettingsWindow::SaveIniSection() LoadIniSection(); } +QVariantMap GetRunEntry(const QString& sEntry) +{ + QVariantMap Entry; + + if (sEntry.left(1) == "{") + { + Entry = QJsonDocument::fromJson(sEntry.toUtf8()).toVariant().toMap(); + } + else + { + StrPair NameCmd = Split2(sEntry, "|"); + StrPair NameIcon = Split2(NameCmd.first, ","); + + Entry["Name"] = NameIcon.first; + Entry["Icon"] = NameIcon.second; + Entry["Command"] = NameCmd.second; + } + + return Entry; +} + +void AddRunItem(QTreeWidget* treeRun, const QVariantMap& Entry) +{ + QTreeWidgetItem* pItem = new QTreeWidgetItem(); + pItem->setText(0, Entry["Name"].toString()); + pItem->setData(0, Qt::UserRole, Entry); + pItem->setText(1, Entry["Command"].toString()); + pItem->setFlags(pItem->flags() | Qt::ItemIsEditable); + treeRun->addTopLevelItem(pItem); +} + +QString MakeRunEntry(QTreeWidgetItem* pItem) +{ + QVariantMap Entry = pItem->data(0, Qt::UserRole).toMap(); + Entry["Name"] = pItem->text(0); + Entry["Command"] = pItem->text(1); + return MakeRunEntry(Entry); +} + +QString MakeRunEntry(const QVariantMap& Entry) +{ + if (!Entry["WorkingDir"].toString().isEmpty() || !Entry["Icon"].toString().isEmpty()) { + QJsonDocument doc(QJsonValue::fromVariant(Entry).toObject()); + QString sEntry = QString::fromUtf8(doc.toJson(QJsonDocument::Compact)); + return sEntry; + } + //if(!Entry["Icon"].toString().isEmpty()) + // return Entry["Name"].toString() + "," + Entry["Icon"].toString() + "|" + Entry["Command"].toString(); + return Entry["Name"].toString() + "|" + Entry["Command"].toString(); +} + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Update // diff --git a/SandboxiePlus/SandMan/Windows/SettingsWindow.h b/SandboxiePlus/SandMan/Windows/SettingsWindow.h index 4b6ae497..9c3a6274 100644 --- a/SandboxiePlus/SandMan/Windows/SettingsWindow.h +++ b/SandboxiePlus/SandMan/Windows/SettingsWindow.h @@ -151,8 +151,6 @@ protected: void AddMessageItem(const QString& ID, const QString& Text = QString()); - void AddRunItem(const QString& Name, const QString& Icon, const QString& Command); - void AddWarnEntry(const QString& Name, int type); void LoadSettings(); @@ -187,6 +185,11 @@ private: Ui::SettingsWindow ui; }; +QVariantMap GetRunEntry(const QString& sEntry); +void AddRunItem(QTreeWidget* treeRun, const QVariantMap& Entry); +QString MakeRunEntry(QTreeWidgetItem* pItem); +QString MakeRunEntry(const QVariantMap& Entry); + void WindowsMoveFile(const QString& from, const QString& to); extern quint32 g_FeatureFlags; diff --git a/SandboxiePlus/version.h b/SandboxiePlus/version.h index efb4ce68..669b98be 100644 --- a/SandboxiePlus/version.h +++ b/SandboxiePlus/version.h @@ -3,7 +3,7 @@ #define VERSION_MJR 1 #define VERSION_MIN 10 #define VERSION_REV 1 -#define VERSION_UPD 0 +#define VERSION_UPD 3 #ifndef STR #define STR2(X) #X