This commit is contained in:
DavidXanatos 2023-08-27 12:34:06 +02:00
parent d870afd192
commit 938e0a8c8d
5 changed files with 106 additions and 40 deletions

View File

@ -6,6 +6,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [1.11.1 / 5.66.1] - 2023-08-??
### Added
- added 'RamDiskLetter=R:\' option allowing to mount the ramdisk root to a drive letter
### Changed
- changed the new optin layout to now be the default for non vintage views (can be changed back in the settings)

View File

@ -729,7 +729,7 @@ retry:
//---------------------------------------------------------------------------
std::shared_ptr<BOX_MOUNT> MountManager::MountImDisk(const std::wstring& ImageFile, const wchar_t* pPassword, ULONG64 sizeKb, ULONG session_id)
std::shared_ptr<BOX_MOUNT> MountManager::MountImDisk(const std::wstring& ImageFile, const wchar_t* pPassword, ULONG64 sizeKb, ULONG session_id, const wchar_t* drvLetter)
{
bool ok = false;
@ -744,8 +744,17 @@ std::shared_ptr<BOX_MOUNT> MountManager::MountImDisk(const std::wstring& ImageFi
// todo allow mounting without mount
WCHAR Drive[4] = L" :";
Drive[0] = ImDiskFindFreeDriveLetter();
WCHAR Drive[4] = L"\0:";
if (drvLetter) {
WCHAR letter = towupper(drvLetter[0]);
if (letter >= L'A' && letter <= L'Z' && drvLetter[1] == L':') {
DWORD logical_drives = GetLogicalDrives();
if((logical_drives & (1 << (letter - L'A'))) == 0)
Drive[0] = letter;
}
}
else
Drive[0] = ImDiskFindFreeDriveLetter();
if (Drive[0] == 0) {
SbieApi_LogEx(session_id, 2234, L"");
return NULL;
@ -842,8 +851,10 @@ std::shared_ptr<BOX_MOUNT> MountManager::MountImDisk(const std::wstring& ImageFi
ok = true;
if (!DefineDosDevice(DDD_REMOVE_DEFINITION | DDD_EXACT_MATCH_ON_REMOVE | DDD_RAW_TARGET_PATH, Drive, pMount->NtPath.c_str())) {
SbieApi_LogEx(session_id, 2235, L"%S", Drive);
if (!drvLetter) {
if (!DefineDosDevice(DDD_REMOVE_DEFINITION | DDD_EXACT_MATCH_ON_REMOVE | DDD_RAW_TARGET_PATH, Drive, pMount->NtPath.c_str())) {
SbieApi_LogEx(session_id, 2235, L"%S", Drive);
}
}
}
}
@ -998,8 +1009,11 @@ bool MountManager::AcquireBoxRoot(const WCHAR* boxname, const WCHAR* reg_root, c
ULONG sizeKb = SbieApi_QueryConfNumber(NULL, L"RamDiskSizeKb", 0);
if (sizeKb < 100*1024) // we want at lesat 100MB
SbieApi_LogEx(session_id, 2238, L"");
else
m_RamDisk = MountImDisk(L"", NULL, sizeKb, session_id);
else {
WCHAR drvLetter[32] = { 0 };
SbieApi_QueryConf(NULL, L"RamDiskLetter", 0, drvLetter, ARRAYSIZE(drvLetter));
m_RamDisk = MountImDisk(L"", NULL, sizeKb, session_id, *drvLetter ? drvLetter : NULL);
}
}
pRoot->Mount = m_RamDisk;
}

View File

@ -80,7 +80,7 @@ protected:
bool RemoveJunction(const std::wstring& FileRootPath, ULONG session_id);
std::shared_ptr<BOX_MOUNT> FindImDisk(const std::wstring& ImageFile, ULONG session_id);
std::shared_ptr<BOX_MOUNT> MountImDisk(const std::wstring& ImageFile, const wchar_t* pPassword, ULONG64 sizeKb, ULONG session_id);
std::shared_ptr<BOX_MOUNT> MountImDisk(const std::wstring& ImageFile, const wchar_t* pPassword, ULONG64 sizeKb, ULONG session_id, const wchar_t* drvLetter = NULL);
static bool TryUnmountImDisk(const std::wstring& Device, HANDLE hProcess, int iMode = 0);
static bool UnmountImDisk(const std::wstring& Device, HANDLE hProcess);
bool UnmountImDiskLocked(const std::shared_ptr<BOX_MOUNT>& pToUnMount, ULONG session_id);

View File

@ -1176,7 +1176,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="tabsAddons">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tabAddonList">
<attribute name="title">
@ -1267,16 +1267,6 @@
<layout class="QGridLayout" name="gridLayout_40">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout_39">
<item row="2" column="4">
<widget class="QLineEdit" name="txtRamLimit">
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QCheckBox" name="chkRamDisk">
<property name="text">
@ -1284,13 +1274,53 @@
</property>
</widget>
</item>
<item row="2" column="5">
<item row="2" column="6">
<widget class="QLabel" name="lblRamLimit">
<property name="text">
<string>kilobytes</string>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QComboBox" name="cmbRamLetter">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QCheckBox" name="chkRamLetter">
<property name="text">
<string>Assign drive letter to Ram Disk</string>
</property>
</widget>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer_13">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1" colspan="6">
<widget class="QLabel" name="lblImDisk">
<property name="text">
<string>&lt;a href=&quot;addon://ImDisk&quot;&gt;Install ImDisk&lt;/a&gt; driver to enable Ram Disk and Disk Image support.</string>
</property>
<property name="openExternalLinks">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblDiskImage">
<property name="font">
@ -1304,20 +1334,17 @@
</property>
</widget>
</item>
<item row="3" column="1">
<spacer name="verticalSpacer_13">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<item row="2" column="5">
<widget class="QLineEdit" name="txtRamLimit">
<property name="maximumSize">
<size>
<width>20</width>
<height>40</height>
<width>100</width>
<height>16777215</height>
</size>
</property>
</spacer>
</widget>
</item>
<item row="2" column="3">
<item row="2" column="3" colspan="2">
<widget class="QLabel" name="lblRamDisk">
<property name="text">
<string>RAM Limit</string>
@ -1327,7 +1354,7 @@
</property>
</widget>
</item>
<item row="3" column="2" colspan="4">
<item row="4" column="6">
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -1340,13 +1367,13 @@
</property>
</spacer>
</item>
<item row="1" column="1" colspan="5">
<widget class="QLabel" name="lblImDisk">
<property name="text">
<string>&lt;a href=&quot;addon://ImDisk&quot;&gt;Install ImDisk&lt;/a&gt; driver to enable Ram Disk and Disk Image support.</string>
<item row="3" column="4" colspan="3">
<widget class="QLabel" name="lblRamLetter">
<property name="toolTip">
<string>When a Ram Disk is already mounted you need to unmount it for this option to take effect.</string>
</property>
<property name="openExternalLinks">
<bool>false</bool>
<property name="text">
<string>* takes effect on disk creation</string>
</property>
</widget>
</item>

View File

@ -376,6 +376,13 @@ CSettingsWindow::CSettingsWindow(QWidget* parent)
}
});
connect(ui.txtRamLimit, SIGNAL(textChanged(const QString&)), this, SLOT(OnRamDiskChange()));
connect(ui.chkRamLetter, SIGNAL(stateChanged(int)), this, SLOT(OnRamDiskChange()));
connect(ui.cmbRamLetter, SIGNAL(currentIndexChanged(int)), this, SLOT(OnGeneralChanged()));
DWORD logical_drives = GetLogicalDrives();
for (CHAR search = 'D'; search <= 'Z'; search++) {
if ((logical_drives & (1 << (search - 'A'))) == 0)
ui.cmbRamLetter->addItem(QString("%1:\\").arg(QChar(search)));
}
//
// Advanced Config
@ -521,9 +528,11 @@ CSettingsWindow::CSettingsWindow(QWidget* parent)
connect(ui.buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked(bool)), this, SLOT(apply()));
connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
//COptionsWindow__AddCertIcon(ui.chkUpdateTemplates);
COptionsWindow__AddCertIcon(ui.chkUpdateIssues);
COptionsWindow__AddCertIcon(ui.chkRamDisk);
if (!CERT_IS_LEVEL(g_CertInfo, eCertStandard)) {
//COptionsWindow__AddCertIcon(ui.chkUpdateTemplates);
COptionsWindow__AddCertIcon(ui.chkUpdateIssues);
COptionsWindow__AddCertIcon(ui.chkRamDisk);
}
this->installEventFilter(this); // prevent enter from closing the dialog
@ -932,6 +941,9 @@ void CSettingsWindow::LoadSettings()
quint32 uDiskLimit = theAPI->GetGlobalSettings()->GetNum64("RamDiskSizeKb");
ui.chkRamDisk->setChecked(uDiskLimit > 0);
if(uDiskLimit > 0) ui.txtRamLimit->setText(QString::number(uDiskLimit));
QString RamLetter = theAPI->GetGlobalSettings()->GetText("RamDiskLetter");
ui.chkRamLetter->setChecked(!RamLetter.isEmpty());
ui.cmbRamLetter->setCurrentText(RamLetter);
m_HoldChange = true;
OnRamDiskChange();
m_HoldChange = false;
@ -1047,6 +1059,11 @@ void CSettingsWindow::LoadSettings()
void CSettingsWindow::OnRamDiskChange()
{
if (sender() == ui.chkRamDisk) {
if (ui.chkRamDisk->isChecked())
theGUI->CheckCertificate(this);
}
if (ui.chkRamDisk->isChecked() && ui.txtRamLimit->text().isEmpty())
ui.txtRamLimit->setText(QString::number(2 * 1024 * 1024));
@ -1056,6 +1073,10 @@ void CSettingsWindow::OnRamDiskChange()
ui.lblRamLimit->setEnabled(bEnabled);
ui.lblRamLimit->setText(tr("kilobytes (%1)").arg(FormatSize(ui.txtRamLimit->text().toULongLong() * 1024)));
ui.chkRamLetter->setEnabled(bEnabled);
ui.cmbRamLetter->setEnabled(bEnabled && ui.chkRamLetter->isChecked());
ui.lblRamLetter->setEnabled(bEnabled && ui.chkRamLetter->isChecked());
OnGeneralChanged();
}
@ -1437,6 +1458,7 @@ void CSettingsWindow::SaveSettings()
WriteText("IpcRootPath", ui.ipcRoot->text()); //ui.ipcRoot->setText("\\Sandbox\\%USER%\\%SANDBOX%\\Session_%SESSION%");
WriteText("RamDiskSizeKb", ui.chkRamDisk->isChecked() ? ui.txtRamLimit->text() : "");
WriteText("RamDiskLetter", ui.chkRamLetter->isChecked() ? ui.cmbRamLetter->currentText() : "");
WriteAdvancedCheck(ui.chkWFP, "NetworkEnableWFP", "y", "");
WriteAdvancedCheck(ui.chkObjCb, "EnableObjectFiltering", "", "n");