This commit is contained in:
love-code-yeyixiao 2024-05-17 22:09:04 +08:00
parent d0ece79771
commit 5ea9da147b
8 changed files with 139 additions and 111 deletions

View File

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

View File

@ -152,6 +152,7 @@ public:
virtual QString GetSbieMsgStr(quint32 code, quint32 Lang = 1033); 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) RunStart(const QString& BoxName, const QString& Command, bool Elevated = false, const QString& WorkingDir = QString(), QProcess* pProcess = NULL);
virtual SB_RESULT(quint32) RunStart(const QString& BoxName, const QString& Command, bool Elevated = false, const QString& WorkingDir = QString(), bool isFCP,QProcess* pProcess = NULL);
virtual QString GetStartPath() const; virtual QString GetStartPath() const;
virtual quint32 GetSessionID() const; virtual quint32 GetSessionID() const;

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>263</width> <width>278</width>
<height>430</height> <height>475</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -31,77 +31,80 @@
<property name="windowTitle"> <property name="windowTitle">
<string>SandboxiePlus select box</string> <string>SandboxiePlus select box</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QGridLayout" name="gridLayout">
<item> <item row="3" column="0">
<layout class="QGridLayout" name="gridLayout"> <widget class="QTreeWidget" name="treeBoxes">
<item row="5" column="0"> <column>
<widget class="Line" name="line"> <property name="text">
<property name="orientation"> <string>Sandbox</string>
<enum>Qt::Horizontal</enum> </property>
</property> </column>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="5" column="0">
<widget class="QRadioButton" name="radBoxed"> <widget class="QRadioButton" name="radUnBoxed">
<property name="text"> <property name="text">
<string>Run Sandboxed</string> <string>Run Outside the Sandbox</string>
</property> </property>
<property name="checked"> </widget>
<bool>true</bool> </item>
</property> <item row="7" column="0">
</widget> <widget class="Line" name="line">
</item> <property name="orientation">
<item row="7" column="0"> <enum>Qt::Horizontal</enum>
<widget class="QDialogButtonBox" name="buttonBox"> </property>
<property name="standardButtons"> </widget>
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> </item>
</property> <item row="0" column="0">
</widget> <widget class="QLabel" name="label">
</item> <property name="text">
<item row="2" column="0"> <string>Select the sandbox in which to start the program, installer or document.</string>
<widget class="QTreeWidget" name="treeBoxes"> </property>
<column> <property name="wordWrap">
<property name="text"> <bool>true</bool>
<string>Sandbox</string> </property>
</property> </widget>
</column> </item>
</widget> <item row="4" column="0">
</item> <widget class="QRadioButton" name="radBoxedNew">
<item row="4" column="0"> <property name="text">
<widget class="QRadioButton" name="radUnBoxed"> <string>Run in a new Sandbox</string>
<property name="text"> </property>
<string>Run Outside the Sandbox</string> <property name="checked">
</property> <bool>false</bool>
</widget> </property>
</item> </widget>
<item row="6" column="0"> </item>
<widget class="QCheckBox" name="chkAdmin"> <item row="8" column="0">
<property name="text"> <widget class="QCheckBox" name="chkAdmin">
<string>Run As UAC Administrator</string> <property name="text">
</property> <string>Run As UAC Administrator</string>
</widget> </property>
</item> </widget>
<item row="0" column="0"> </item>
<widget class="QLabel" name="label"> <item row="9" column="0">
<property name="text"> <widget class="QDialogButtonBox" name="buttonBox">
<string>Select the sandbox in which to start the program, installer or document.</string> <property name="standardButtons">
</property> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<property name="wordWrap"> </property>
<bool>true</bool> </widget>
</property> </item>
</widget> <item row="1" column="0">
</item> <widget class="QRadioButton" name="radBoxed">
<item row="3" column="0"> <property name="text">
<widget class="QRadioButton" name="radBoxedNew"> <string>Run Sandboxed</string>
<property name="text"> </property>
<string>Run in a new Sandbox</string> <property name="checked">
</property> <bool>true</bool>
<property name="checked"> </property>
<bool>false</bool> </widget>
</property> </item>
</widget> <item row="2" column="0">
</item> <widget class="QRadioButton" name="radFCPRuned">
</layout> <property name="text">
<string>Run Unsandboxed with ForceChildProcess</string>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>

View File

@ -1696,18 +1696,21 @@ bool CSandMan::RunSandboxed(const QStringList& Commands, QString BoxName, const
} }
SB_RESULT(quint32) CSandMan::RunStart(const QString& BoxName, const QString& Command, bool Elevated, const QString& WorkingDir, QProcess* pProcess) SB_RESULT(quint32) CSandMan::RunStart(const QString& BoxName, const QString& Command, bool Elevated, const QString& WorkingDir, QProcess* pProcess)
{
return RunStart(BoxName, Command, Elevated, WorkingDir, false, pProcess);
}
SB_RESULT(quint32) CSandMan::RunStart(const QString& BoxName, const QString& Command, bool Elevated, const QString& WorkingDir,bool isFCP, QProcess* pProcess)
{ {
auto pBoxEx = theAPI->GetBoxByName(BoxName).objectCast<CSandBoxPlus>(); auto pBoxEx = theAPI->GetBoxByName(BoxName).objectCast<CSandBoxPlus>();
if (pBoxEx && pBoxEx->UseImageFile() && pBoxEx->GetMountRoot().isEmpty()){ if (pBoxEx && pBoxEx->UseImageFile() && pBoxEx->GetMountRoot().isEmpty()) {
SB_STATUS Status = ImBoxMount(pBoxEx, true); SB_STATUS Status = ImBoxMount(pBoxEx, true);
if (Status.IsError()) if (Status.IsError())
return Status; return Status;
} }
return theAPI->RunStart(BoxName, Command, Elevated, WorkingDir, pProcess); return theAPI->RunStart(BoxName, Command, Elevated, WorkingDir,isFCP, pProcess);
} }
SB_STATUS CSandMan::ImBoxMount(const CSandBoxPtr& pBox, bool bAutoUnmount) SB_STATUS CSandMan::ImBoxMount(const CSandBoxPtr& pBox, bool bAutoUnmount)
{ {
auto pBoxEx = pBox.objectCast<CSandBoxPlus>(); auto pBoxEx = pBox.objectCast<CSandBoxPlus>();

View File

@ -92,6 +92,7 @@ public:
bool RunSandboxed(const QStringList& Commands, QString BoxName = QString(), const QString& WrkDir = QString()); 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) RunStart(const QString& BoxName, const QString& Command, bool Elevated = false, const QString& WorkingDir = QString(), QProcess* pProcess = NULL);
SB_RESULT(quint32) RunStart(const QString& BoxName, const QString& Command, bool Elevated = false, const QString& WorkingDir = QString(), bool isFCP,QProcess* pProcess = NULL);
SB_STATUS ImBoxMount(const CSandBoxPtr& pBox, bool bAutoUnmount = false); SB_STATUS ImBoxMount(const CSandBoxPtr& pBox, bool bAutoUnmount = false);
void EditIni(const QString& IniPath, bool bPlus = false); void EditIni(const QString& IniPath, bool bPlus = false);

View File

@ -93,6 +93,11 @@ void CSbiePlusAPI::StopMonitor()
} }
SB_RESULT(quint32) CSbiePlusAPI::RunStart(const QString& BoxName, const QString& Command, bool Elevated, const QString& WorkingDir, QProcess* pProcess) SB_RESULT(quint32) CSbiePlusAPI::RunStart(const QString& BoxName, const QString& Command, bool Elevated, const QString& WorkingDir, QProcess* pProcess)
{
return RunStart(BoxName,Command,Elevated,WorkingDir,false,pProcess);
}
SB_RESULT(quint32) CSbiePlusAPI::RunStart(const QString& BoxName, const QString& Command, bool Elevated, const QString& WorkingDir, bool isFCP,QProcess* pProcess)
{ {
if (!pProcess) if (!pProcess)
pProcess = new QProcess(this); pProcess = new QProcess(this);

View File

@ -32,7 +32,7 @@ public:
virtual void StopMonitor(); 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) RunStart(const QString& BoxName, const QString& Command, bool Elevated = false, const QString& WorkingDir = QString(), QProcess* pProcess = NULL);
virtual SB_RESULT(quint32) RunStart(const QString& BoxName, const QString& Command, bool Elevated = false, const QString& WorkingDir = QString(), bool isFCP,QProcess* pProcess = NULL);
virtual bool IsStarting(qint64 pid) const { return m_PendingStarts.contains(pid); } virtual bool IsStarting(qint64 pid) const { return m_PendingStarts.contains(pid); }
private slots: private slots:

View File

@ -186,6 +186,7 @@ CSelectBoxWindow::CSelectBoxWindow(const QStringList& Commands, const QString& B
connect(ui.radBoxed, SIGNAL(clicked(bool)), this, SLOT(OnBoxType())); connect(ui.radBoxed, SIGNAL(clicked(bool)), this, SLOT(OnBoxType()));
connect(ui.radBoxedNew, 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.radUnBoxed, SIGNAL(clicked(bool)), this, SLOT(OnBoxType()));
connect(ui.radFCPRuned, SIGNAL(clicked(bool)), this, SLOT(OnBoxType()));
connect(ui.buttonBox, SIGNAL(accepted()), SLOT(OnRun())); connect(ui.buttonBox, SIGNAL(accepted()), SLOT(OnRun()));
connect(ui.buttonBox, SIGNAL(rejected()), SLOT(reject())); connect(ui.buttonBox, SIGNAL(rejected()), SLOT(reject()));
@ -213,13 +214,13 @@ void CSelectBoxWindow::closeEvent(QCloseEvent *e)
void CSelectBoxWindow::OnBoxType() void CSelectBoxWindow::OnBoxType()
{ {
m_pBoxPicker->setEnabled(ui.radBoxed->isChecked()); m_pBoxPicker->setEnabled(ui.radBoxed->isChecked()||ui.radFCPRuned->isChecked());
} }
void CSelectBoxWindow::OnRun() void CSelectBoxWindow::OnRun()
{ {
QString BoxName; QString BoxName;
bool isFCP = false;
if (ui.radUnBoxed->isChecked()) 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) 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)
@ -233,6 +234,15 @@ void CSelectBoxWindow::OnRun()
return; 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
{ {
BoxName = m_pBoxPicker->GetBoxName(); BoxName = m_pBoxPicker->GetBoxName();
@ -243,7 +253,7 @@ void CSelectBoxWindow::OnRun()
} }
foreach(const QString & Command, m_Commands) foreach(const QString & Command, m_Commands)
theGUI->RunStart(BoxName, Command, ui.chkAdmin->isChecked(), m_WrkDir); theGUI->RunStart(BoxName, Command, ui.chkAdmin->isChecked(), m_WrkDir,isFCP,0);
setResult(1); setResult(1);
close(); close();