Merge pull request #3904 from love-code-yeyixiao/FCP_GUI

Add UI about FCP
This commit is contained in:
DavidXanatos 2024-05-18 09:29:16 +02:00 committed by GitHub
commit 893efa2f3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 140 additions and 112 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)
{
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)
{
if (m_SbiePath.isEmpty())
return SB_ERR(SB_PathFail);
QString StartArgs;
if(Elevated)
if (Elevated)
StartArgs += "/elevated ";
if (!BoxName.isEmpty())
StartArgs += "/box:" + BoxName + " ";
if (isFCP)
StartArgs += "/fcp ";
else
StartArgs += "/disable_force ";
@ -1055,7 +1061,7 @@ SB_RESULT(quint32) CSbieAPI::RunStart(const QString& BoxName, const QString& Com
pProcess->setNativeArguments(StartArgs);
pProcess->start();
pid = pProcess->processId();
}
}
else {
QProcess process;
//process.setWorkingDirectory(QString::fromWCharArray(sysPath));
@ -1069,42 +1075,41 @@ SB_RESULT(quint32) CSbieAPI::RunStart(const QString& BoxName, const QString& Com
/*
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

@ -154,6 +154,7 @@ 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);
virtual QString GetStartPath() const;
virtual quint32 GetSessionID() const;

View File

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

View File

@ -1713,18 +1713,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)
{
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)
{
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);
if (Status.IsError())
return Status;
}
return theAPI->RunStart(BoxName, Command, Elevated, WorkingDir, pProcess);
return theAPI->RunStartWithFCP(BoxName, Command, isFCP, Elevated, WorkingDir, pProcess);
}
SB_STATUS CSandMan::ImBoxMount(const CSandBoxPtr& pBox, bool bAutoUnmount)
{
auto pBoxEx = pBox.objectCast<CSandBoxPlus>();

View File

@ -93,6 +93,7 @@ public:
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);
SB_STATUS ImBoxMount(const CSandBoxPtr& pBox, bool bAutoUnmount = false);
void EditIni(const QString& IniPath, bool bPlus = false);

View File

@ -93,10 +93,15 @@ void CSbiePlusAPI::StopMonitor()
}
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)
{
if (!pProcess)
pProcess = new QProcess(this);
SB_RESULT(quint32) Status = CSbieAPI::RunStart(BoxName, Command, Elevated, WorkingDir, pProcess);
SB_RESULT(quint32) Status = CSbieAPI::RunStartWithFCP(BoxName, Command,isFCP, Elevated, WorkingDir, pProcess);
if (pProcess->parent() == this) {
if (!Status.IsError()) {
connect(pProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(OnStartFinished()));

View File

@ -32,7 +32,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 bool IsStarting(qint64 pid) const { return m_PendingStarts.contains(pid); }
private slots:
@ -280,4 +280,4 @@ protected:
void CollectUpdates();
QList<QVariantMap> m_Updates;
};
};

View File

@ -184,6 +184,7 @@ 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.buttonBox, SIGNAL(accepted()), SLOT(OnRun()));
connect(ui.buttonBox, SIGNAL(rejected()), SLOT(reject()));
@ -211,13 +212,13 @@ void CSelectBoxWindow::closeEvent(QCloseEvent *e)
void CSelectBoxWindow::OnBoxType()
{
m_pBoxPicker->setEnabled(ui.radBoxed->isChecked());
m_pBoxPicker->setEnabled(ui.radBoxed->isChecked()||ui.radFCPRuned->isChecked());
}
void CSelectBoxWindow::OnRun()
{
QString BoxName;
bool isFCP = false;
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)
@ -231,6 +232,15 @@ 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
{
BoxName = m_pBoxPicker->GetBoxName();
@ -241,8 +251,8 @@ void CSelectBoxWindow::OnRun()
}
foreach(const QString & Command, m_Commands)
theGUI->RunStart(BoxName, Command, ui.chkAdmin->isChecked(), m_WrkDir);
theGUI->RunStartWithFCP(BoxName, Command, isFCP, ui.chkAdmin->isChecked(), m_WrkDir,0);
setResult(1);
close();
}
}