This commit is contained in:
DavidXanatos 2024-05-18 10:49:20 +02:00
parent fb31e94fb8
commit bd6cc0f7ad
16 changed files with 128 additions and 126 deletions

View File

@ -920,6 +920,15 @@ Desktop
Programs
.
3198;txt;01
Do you want to start a new program into the sandbox %s?
You received this message because you set AlertBeforeStart=y.
.
3199;txt;01
This startup request does not appear to be invoked by the SANDBOXIE component. Are you sure you want to run it? If this is your action, you can ignore it and choose yes.
.
3202;txt;01
Invalid command line parameter: %2
.
@ -4238,14 +4247,4 @@ This is the third and last retry.
8106;txt;02
The following programs must be closed before the installation can continue.
Click OK to close these programs and continue. Click Cancel to abort the installation.
.
3198;txt;01
Do you want to start a new program into the sandbox %s?
You received this message because you set AlertBeforeStart=y.
.
3199;txt;01
This startup request does not appear to be invoked by the SANDBOXIE component. Are you sure you want to run it? If this is your action, you can ignore it and choose yes.
.
.

View File

@ -147,7 +147,7 @@ SB_STATUS CSandBox::RunStart(const QString& Command, bool Elevated)
if ((QGuiApplication::queryKeyboardModifiers() & Qt::ControlModifier) != 0)
return RunSandboxed(Command);
#endif
return m_pAPI->RunStart(m_Name, Command, Elevated);
return m_pAPI->RunStart(m_Name, Command, Elevated ? CSbieAPI::eStartElevated : CSbieAPI::eStartDefault);
}
SB_STATUS CSandBox::RunSandboxed(const QString& Command)

View File

@ -1029,22 +1029,19 @@ QString CSbieAPI::GetUserSection(QString* pUserName, bool* pIsAdmin) const
return UserSection;
}
SB_RESULT(quint32) CSbieAPI::RunStart(const QString& BoxName, const QString& Command, bool Elevated, const QString& WorkingDir, QProcess* pProcess)
{
return RunStartWithFCP(BoxName, Command,false, Elevated, WorkingDir, pProcess);
}
SB_RESULT(quint32) CSbieAPI::RunStartWithFCP(const QString& BoxName, const QString& Command, bool isFCP,bool Elevated, const QString& WorkingDir, QProcess* pProcess)
SB_RESULT(quint32) CSbieAPI::RunStart(const QString& BoxName, const QString& Command, EStartFlags Flags, const QString& WorkingDir, QProcess* pProcess)
{
if (m_SbiePath.isEmpty())
return SB_ERR(SB_PathFail);
QString StartArgs;
if (Elevated)
if (Flags & eStartElevated)
StartArgs += "/elevated ";
if (Flags & eStartFCP)
StartArgs += "/fcp ";
if (!BoxName.isEmpty())
StartArgs += "/box:" + BoxName + " ";
if (isFCP)
StartArgs += "/fcp ";
else
StartArgs += "/disable_force ";
@ -1075,41 +1072,42 @@ SB_RESULT(quint32) CSbieAPI::RunStartWithFCP(const QString& BoxName, const QStri
/*
QString CommandLine = "\"" + GetStartPath() + "\" " + StartArgs;
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
// Start the child process.
if( !CreateProcessW( NULL, // No module name (use command line)
(wchar_t*)CommandLine.toStdWString().c_str(), // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
// Start the child process.
if( !CreateProcessW( NULL, // No module name (use command line)
(wchar_t*)CommandLine.toStdWString().c_str(), // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return SB_ERR();
}
}
// Wait until child process exits.
//WaitForSingleObject( pi.hProcess, INFINITE );
// Wait until child process exits.
//WaitForSingleObject( pi.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
*/
if (pid == 0)
if(pid == 0)
return SB_ERR();
return CSbieResult<quint32>((quint32)pid);
}
QString CSbieAPI::GetStartPath() const
{
return m_SbiePath + "\\" + QString::fromWCharArray(SBIESTART_EXE);

View File

@ -153,8 +153,14 @@ public:
virtual QString GetSbieMsgStr(quint32 code, quint32 Lang = 1033);
virtual SB_RESULT(quint32) RunStart(const QString& BoxName, const QString& Command, bool Elevated = false, const QString& WorkingDir = QString(), QProcess* pProcess = NULL);
virtual SB_RESULT(quint32) RunStartWithFCP(const QString& BoxName, const QString& Command, bool isFCP,bool Elevated = false, const QString& WorkingDir = QString(),QProcess* pProcess = NULL);
enum EStartFlags
{
eStartDefault = 0,
eStartElevated = 1,
eStartFCP = 2
};
virtual SB_RESULT(quint32) RunStart(const QString& BoxName, const QString& Command, EStartFlags Flags = eStartDefault, const QString& WorkingDir = QString(), QProcess* pProcess = NULL);
virtual QString GetStartPath() const;
virtual quint32 GetSessionID() const;

View File

@ -564,7 +564,7 @@ bool CSbieUtils::GetStartMenuShortcut(CSbieAPI* pApi, QString &BoxName, QString
QString Command = "start_menu:" + QString::fromWCharArray(MapName);
if (!LinkPath.isEmpty())
Command += ":" + LinkPath;
pApi->RunStart(BoxName, Command, false, QString(), &Process);
pApi->RunStart(BoxName, Command, CSbieAPI::eStartDefault, QString(), &Process);
//Process.waitForFinished(-1);
while(Process.state() != QProcess::NotRunning)
QCoreApplication::processEvents(); // keep UI responsive

View File

@ -8,7 +8,7 @@
quint32 CBoxObject::StartTask(const QString& Command, const QVariantMap& Options)
{
SB_RESULT(quint32) result = theGUI->RunStart(getName(), Command, Options["elevalted"].toBool(), Options["directory"].toString());
SB_RESULT(quint32) result = theGUI->RunStart(getName(), Command, Options["elevalted"].toBool() ? CSbieAPI::eStartElevated : CSbieAPI::eStartDefault, Options["directory"].toString());
return result.IsError() ? -1 : result.GetValue();
}

View File

@ -32,7 +32,24 @@
<string>SandboxiePlus select box</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<item row="5" column="0">
<widget class="QRadioButton" name="radUnBoxed">
<property name="text">
<string>Run Outside the Sandbox</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="chkFCP">
<property name="toolTip">
<string>Force child processes to be sandboxed</string>
</property>
<property name="text">
<string>Force Children</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QTreeWidget" name="treeBoxes">
<column>
<property name="text">
@ -41,31 +58,7 @@
</column>
</widget>
</item>
<item row="5" column="0">
<widget class="QRadioButton" name="radUnBoxed">
<property name="text">
<string>Run Outside the Sandbox</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Select the sandbox in which to start the program, installer or document.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="4" column="0" colspan="2">
<widget class="QRadioButton" name="radBoxedNew">
<property name="text">
<string>Run in a new Sandbox</string>
@ -75,21 +68,28 @@
</property>
</widget>
</item>
<item row="8" column="0">
<item row="7" column="0" colspan="2">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="chkAdmin">
<property name="text">
<string>Run As UAC Administrator</string>
</property>
</widget>
</item>
<item row="9" column="0">
<item row="9" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="1" column="0">
<item row="1" column="0" colspan="2">
<widget class="QRadioButton" name="radBoxed">
<property name="text">
<string>Run Sandboxed</string>
@ -99,10 +99,13 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="radFCPRuned">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Run Unsandboxed with ForceChildProcess</string>
<string>Select the sandbox in which to start the program, installer or document.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>

View File

@ -1671,9 +1671,9 @@ void CSandMan::OnMessage(const QString& MsgData)
BoxName = theAPI->GetGlobalSettings()->GetText("DefaultBox", "DefaultBox");
if (!BoxName.isEmpty())
RunStart(BoxName == "*DFP*" ? "" : BoxName, CmdLine, false, WrkDir);
RunStart(BoxName == "*DFP*" ? "" : BoxName, CmdLine, CSbieAPI::eStartDefault, WrkDir);
else
RunSandboxed(QStringList(CmdLine), BoxName, WrkDir);
RunSandboxed(QStringList(CmdLine), BoxName, WrkDir, true);
}
else if (Message.left(3) == "Op:")
{
@ -1702,21 +1702,18 @@ void CSandMan::dragEnterEvent(QDragEnterEvent* e)
}
}
bool CSandMan::RunSandboxed(const QStringList& Commands, QString BoxName, const QString& WrkDir)
bool CSandMan::RunSandboxed(const QStringList& Commands, QString BoxName, const QString& WrkDir, bool bShowFCP)
{
if (BoxName.isEmpty())
BoxName = theAPI->GetGlobalSettings()->GetText("DefaultBox", "DefaultBox");
CSelectBoxWindow* pSelectBoxWindow = new CSelectBoxWindow(Commands, BoxName, WrkDir, g_GUIParent);
if (bShowFCP) pSelectBoxWindow->ShowFCP();
connect(this, SIGNAL(Closed()), pSelectBoxWindow, SLOT(close()));
//pSelectBoxWindow->show();
return SafeExec(pSelectBoxWindow) == 1;
}
SB_RESULT(quint32) CSandMan::RunStart(const QString& BoxName, const QString& Command, bool Elevated, const QString& WorkingDir, QProcess* pProcess)
{
return RunStartWithFCP(BoxName, Command, false, Elevated, WorkingDir, pProcess);
}
SB_RESULT(quint32) CSandMan::RunStartWithFCP(const QString& BoxName, const QString& Command, bool isFCP, bool Elevated, const QString& WorkingDir, QProcess* pProcess)
SB_RESULT(quint32) CSandMan::RunStart(const QString& BoxName, const QString& Command, CSbieAPI::EStartFlags Flags, const QString& WorkingDir, QProcess* pProcess)
{
auto pBoxEx = theAPI->GetBoxByName(BoxName).objectCast<CSandBoxPlus>();
if (pBoxEx && pBoxEx->UseImageFile() && pBoxEx->GetMountRoot().isEmpty()) {
@ -1726,8 +1723,9 @@ SB_RESULT(quint32) CSandMan::RunStartWithFCP(const QString& BoxName, const QStri
return Status;
}
return theAPI->RunStartWithFCP(BoxName, Command, isFCP, Elevated, WorkingDir, pProcess);
return theAPI->RunStart(BoxName, Command, Flags, WorkingDir, pProcess);
}
SB_STATUS CSandMan::ImBoxMount(const CSandBoxPtr& pBox, bool bAutoUnmount)
{
auto pBoxEx = pBox.objectCast<CSandBoxPlus>();

View File

@ -91,9 +91,8 @@ public:
static void SafeShow(QWidget* pWidget);
int SafeExec(QDialog* pDialog);
bool RunSandboxed(const QStringList& Commands, QString BoxName = QString(), const QString& WrkDir = QString());
SB_RESULT(quint32) RunStart(const QString& BoxName, const QString& Command, bool Elevated = false, const QString& WorkingDir = QString(), QProcess* pProcess = NULL);
SB_RESULT(quint32) RunStartWithFCP(const QString& BoxName, const QString& Command, bool isFCP, bool Elevated = false, const QString& WorkingDir = QString(),QProcess* pProcess = NULL);
bool RunSandboxed(const QStringList& Commands, QString BoxName = QString(), const QString& WrkDir = QString(), bool bShowFCP = false);
SB_RESULT(quint32) RunStart(const QString& BoxName, const QString& Command, CSbieAPI::EStartFlags Flags = CSbieAPI::eStartDefault, const QString& WorkingDir = QString(), QProcess* pProcess = NULL);
SB_STATUS ImBoxMount(const CSandBoxPtr& pBox, bool bAutoUnmount = false);
void EditIni(const QString& IniPath, bool bPlus = false);

View File

@ -357,6 +357,6 @@ void CSandMan::OnRecoveryLog()
{
if (!m_pRecoveryLogWnd->isVisible()) {
m_pRecoveryLogWnd->setWindowFlag(Qt::WindowStaysOnTopHint, theGUI->IsAlwaysOnTop());
SafeShow(m_pRecoveryLogWnd);
CSandMan::SafeShow(m_pRecoveryLogWnd);
}
}

View File

@ -92,16 +92,11 @@ void CSbiePlusAPI::StopMonitor()
m_BoxMonitor->Stop();
}
SB_RESULT(quint32) CSbiePlusAPI::RunStart(const QString& BoxName, const QString& Command, bool Elevated, const QString& WorkingDir, QProcess* pProcess)
{
return RunStartWithFCP(BoxName,Command,false,Elevated,WorkingDir,pProcess);
}
SB_RESULT(quint32) CSbiePlusAPI::RunStartWithFCP(const QString& BoxName, const QString& Command, bool isFCP, bool Elevated, const QString& WorkingDir,QProcess* pProcess)
SB_RESULT(quint32) CSbiePlusAPI::RunStart(const QString& BoxName, const QString& Command, EStartFlags Flags, const QString& WorkingDir,QProcess* pProcess)
{
if (!pProcess)
pProcess = new QProcess(this);
SB_RESULT(quint32) Status = CSbieAPI::RunStartWithFCP(BoxName, Command,isFCP, Elevated, WorkingDir, pProcess);
SB_RESULT(quint32) Status = CSbieAPI::RunStart(BoxName, Command, Flags, WorkingDir, pProcess);
if (pProcess->parent() == this) {
if (!Status.IsError()) {
connect(pProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(OnStartFinished()));

View File

@ -31,8 +31,7 @@ public:
virtual void StopMonitor();
virtual SB_RESULT(quint32) RunStart(const QString& BoxName, const QString& Command, bool Elevated = false, const QString& WorkingDir = QString(), QProcess* pProcess = NULL);
virtual SB_RESULT(quint32) RunStartWithFCP(const QString& BoxName, const QString& Command, bool isFCP,bool Elevated = false, const QString& WorkingDir = QString(),QProcess* pProcess = NULL);
virtual SB_RESULT(quint32) RunStart(const QString& BoxName, const QString& Command, EStartFlags Flags = eStartDefault, const QString& WorkingDir = QString(), QProcess* pProcess = NULL);
virtual bool IsStarting(qint64 pid) const { return m_PendingStarts.contains(pid); }
private slots:

View File

@ -1216,7 +1216,7 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList<CSandBoxPtr>& SandB
else if (Action == m_pMenuRunCmd)
Results.append(theGUI->RunStart(SandBoxes.first()->GetName(), "cmd.exe"));
else if (Action == m_pMenuRunCmdAdmin)
Results.append(theGUI->RunStart(SandBoxes.first()->GetName(), "cmd.exe", true));
Results.append(theGUI->RunStart(SandBoxes.first()->GetName(), "cmd.exe", CSbieAPI::eStartElevated));
#ifdef _WIN64
else if (Action == m_pMenuRunCmd32)
Results.append(theGUI->RunStart(SandBoxes.first()->GetName(), "C:\\WINDOWS\\SysWOW64\\cmd.exe"));
@ -1576,10 +1576,10 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList<CSandBoxPtr>& SandB
QString Command = Action->data().toString();
QString WorkingDir = Action->property("WorkingDir").toString();
if (Command.isEmpty())
Results.append(theGUI->RunStart(SandBoxes.first()->GetName(), "start_menu", false, WorkingDir));
Results.append(theGUI->RunStart(SandBoxes.first()->GetName(), "start_menu", CSbieAPI::eStartDefault, WorkingDir));
else {
auto pBoxEx = SandBoxes.first().objectCast<CSandBoxPlus>();
Results.append(theGUI->RunStart(SandBoxes.first()->GetName(), pBoxEx->GetFullCommand(Command), false, pBoxEx->GetFullCommand(WorkingDir)));
Results.append(theGUI->RunStart(SandBoxes.first()->GetName(), pBoxEx->GetFullCommand(Command), CSbieAPI::eStartDefault, pBoxEx->GetFullCommand(WorkingDir)));
}
}

View File

@ -184,7 +184,9 @@ CSelectBoxWindow::CSelectBoxWindow(const QStringList& Commands, const QString& B
connect(ui.radBoxed, SIGNAL(clicked(bool)), this, SLOT(OnBoxType()));
connect(ui.radBoxedNew, SIGNAL(clicked(bool)), this, SLOT(OnBoxType()));
connect(ui.radUnBoxed, SIGNAL(clicked(bool)), this, SLOT(OnBoxType()));
connect(ui.radFCPRuned, SIGNAL(clicked(bool)), this, SLOT(OnBoxType()));
connect(ui.chkFCP, SIGNAL(clicked(bool)), this, SLOT(OnBoxType()));
ui.chkFCP->setEnabled(false);
ui.chkFCP->setVisible(false);
connect(ui.buttonBox, SIGNAL(accepted()), SLOT(OnRun()));
connect(ui.buttonBox, SIGNAL(rejected()), SLOT(reject()));
@ -204,6 +206,11 @@ CSelectBoxWindow::~CSelectBoxWindow()
theConf->SetBlob("SelectBoxWindow/Window_Geometry", saveGeometry());
}
void CSelectBoxWindow::ShowFCP()
{
ui.chkFCP->setVisible(true);
}
void CSelectBoxWindow::closeEvent(QCloseEvent *e)
{
//emit Closed();
@ -212,19 +219,22 @@ void CSelectBoxWindow::closeEvent(QCloseEvent *e)
void CSelectBoxWindow::OnBoxType()
{
m_pBoxPicker->setEnabled(ui.radBoxed->isChecked()||ui.radFCPRuned->isChecked());
ui.chkFCP->setEnabled(ui.radUnBoxed->isChecked());
m_pBoxPicker->setEnabled(ui.radBoxed->isChecked() || (ui.chkFCP->isEnabled() && ui.chkFCP->isChecked()));
}
void CSelectBoxWindow::OnRun()
{
QString BoxName;
bool isFCP = false;
int Flags = CSbieAPI::eStartDefault;
if (ui.chkAdmin->isChecked())
Flags |= CSbieAPI::eStartElevated;
if (ui.radUnBoxed->isChecked())
{
if (QMessageBox("Sandboxie-Plus", tr("Are you sure you want to run the program outside the sandbox?"), QMessageBox::Question, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default | QMessageBox::Escape, QMessageBox::NoButton, this).exec() != QMessageBox::Yes)
return;
}
else if (ui.radBoxedNew->isChecked())
if (ui.radBoxedNew->isChecked())
{
BoxName = theGUI->GetBoxView()->AddNewBox(true);
if (BoxName.isEmpty()) {
@ -232,17 +242,10 @@ void CSelectBoxWindow::OnRun()
return;
}
}
else if (ui.radFCPRuned->isChecked())
{
isFCP = true;
BoxName = m_pBoxPicker->GetBoxName();
if (BoxName.isEmpty()) {
QMessageBox("Sandboxie-Plus", tr("Please select a sandbox."), QMessageBox::Information, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton, this).exec();
return;
}
}
else
else if (!ui.radUnBoxed->isChecked() || ui.chkFCP->isChecked())
{
if (ui.chkFCP->isChecked())
Flags |= CSbieAPI::eStartFCP;
BoxName = m_pBoxPicker->GetBoxName();
if (BoxName.isEmpty()) {
QMessageBox("Sandboxie-Plus", tr("Please select a sandbox."), QMessageBox::Information, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton, this).exec();
@ -250,9 +253,9 @@ void CSelectBoxWindow::OnRun()
}
}
foreach(const QString & Command, m_Commands)
theGUI->RunStartWithFCP(BoxName, Command, isFCP, ui.chkAdmin->isChecked(), m_WrkDir,0);
foreach(const QString& Command, m_Commands)
theGUI->RunStart(BoxName, Command, (CSbieAPI::EStartFlags)Flags, m_WrkDir);
setResult(1);
close();
}
}

View File

@ -44,6 +44,8 @@ public:
CSelectBoxWindow(const QStringList& Commands, const QString& BoxName, const QString& WrkDir = QString(), QWidget *parent = Q_NULLPTR);
~CSelectBoxWindow();
void ShowFCP();
private slots:
void OnBoxType();
void OnRun();

View File

@ -270,8 +270,8 @@ SB_STATUS CNewBoxWizard::TryToCreateBox()
if(field("imagesProtection").toBool())
pBox->SetBool("ProtectHostImages", true);
if (field("coverBoxedWindows").toBool())
pBox->SetBool("CoverBoxedWindows", true);
if (field("coverBoxedWindows").toBool())
pBox->SetBool("CoverBoxedWindows", true);
if (!Password.isEmpty())
pBox->ImBoxCreate(ImageSize / 1024, Password);