Sandboxie/SandboxiePlus/SandMan/SbiePlusAPI.h

267 lines
7.9 KiB
C
Raw Normal View History

2021-10-16 16:19:51 +01:00
#pragma once
#include "../QSbieAPI/SbieAPI.h"
2023-07-02 17:09:18 +01:00
#include "../QSbieAPI/Sandboxie/SbieTemplates.h"
2022-02-05 14:09:53 +00:00
#include "BoxJob.h"
2021-10-16 16:19:51 +01:00
2022-11-12 09:45:35 +00:00
enum ESbieExMsgCodes
{
SBX_FirstError = SB_LastError,
SBX_7zNotReady,
SBX_7zCreateFailed,
SBX_7zOpenFailed,
SBX_7zExtractFailed,
SBX_NotBoxArchive
};
2021-10-16 16:19:51 +01:00
class CSbiePlusAPI : public CSbieAPI
{
Q_OBJECT
public:
CSbiePlusAPI(QObject* parent);
virtual ~CSbiePlusAPI();
virtual void UpdateWindowMap();
virtual QString GetProcessTitle(quint32 pid) { return m_WindowMap.value(pid); }
virtual bool IsRunningAsAdmin();
2022-02-18 19:09:35 +00:00
virtual bool IsBusy() const { return m_JobCount > 0; }
2022-06-13 19:12:53 +01:00
virtual void StopMonitor();
2023-07-01 17:54:53 +01:00
virtual SB_RESULT(quint32) RunStart(const QString& BoxName, const QString& Command, bool Elevated = false, const QString& WorkingDir = QString(), QProcess* pProcess = NULL);
2022-08-09 17:19:46 +01:00
virtual bool IsStarting(qint64 pid) const { return m_PendingStarts.contains(pid); }
private slots:
virtual void OnStartFinished();
2022-11-12 09:45:35 +00:00
virtual void SbieIniSetSection(const QString& Section, const QString& Value) { SbieIniSet(Section, "", Value); }
2022-08-09 17:19:46 +01:00
2023-01-29 09:49:41 +00:00
signals:
void BoxCleaned(CSandBoxPlus* pBoxEx);
2021-10-16 16:19:51 +01:00
protected:
2022-02-18 19:09:35 +00:00
friend class CSandBoxPlus;
2021-10-16 16:19:51 +01:00
virtual CSandBox* NewSandBox(const QString& BoxName, class CSbieAPI* pAPI);
virtual CBoxedProcess* NewBoxedProcess(quint32 ProcessId, class CSandBox* pBox);
2023-07-01 17:54:53 +01:00
virtual SB_STATUS UpdateBoxPaths(CSandBox* pSandBox) { return CSbieAPI::UpdateBoxPaths(pSandBox); }
2023-04-13 18:46:51 +01:00
virtual CBoxedProcessPtr OnProcessBoxed(quint32 ProcessId, const QString& Path, const QString& Box, quint32 ParentId, const QString& CmdLine);
2021-10-16 16:19:51 +01:00
2022-02-18 19:09:35 +00:00
int m_JobCount;
2021-10-16 16:19:51 +01:00
QMultiMap<quint32, QString> m_WindowMap;
2022-05-16 20:30:40 +01:00
friend class CSandBoxPlus;
class CBoxMonitor* m_BoxMonitor;
2022-08-09 17:19:46 +01:00
QSet<qint64> m_PendingStarts;
2021-10-16 16:19:51 +01:00
};
///////////////////////////////////////////////////////////////////////////////
// CSandBoxPlus
//
class CSandBoxPlus : public CSandBox
{
Q_OBJECT
public:
CSandBoxPlus(const QString& BoxName, class CSbieAPI* pAPI);
virtual ~CSandBoxPlus();
2022-11-12 09:45:35 +00:00
SB_PROGRESS ExportBox(const QString& FileName);
SB_PROGRESS ImportBox(const QString& FileName);
2021-10-16 16:19:51 +01:00
virtual void UpdateDetails();
2022-09-29 17:28:48 +01:00
virtual void ScanStartMenu();
2022-05-16 20:30:40 +01:00
virtual void SetBoxPaths(const QString& FilePath, const QString& RegPath, const QString& IpcPath);
virtual void OpenBox();
2021-10-16 16:19:51 +01:00
virtual void CloseBox();
2023-01-29 16:10:11 +00:00
virtual SB_PROGRESS CleanBox() { BeginModifyingBox(); SB_PROGRESS Status = CSandBox::CleanBox(); ConnectEndSlot(Status); return Status; }
2023-07-01 17:54:53 +01:00
virtual SB_STATUS RenameBox(const QString& NewName);
virtual SB_STATUS RemoveBox();
2023-01-29 16:10:11 +00:00
virtual SB_PROGRESS TakeSnapshot(const QString& Name) { BeginModifyingBox(); SB_PROGRESS Status = CSandBox::TakeSnapshot(Name); ConnectEndSlot(Status); return Status; }
virtual SB_PROGRESS RemoveSnapshot(const QString& ID) { BeginModifyingBox(); SB_PROGRESS Status = CSandBox::RemoveSnapshot(ID); ConnectEndSlot(Status); return Status; }
virtual SB_PROGRESS SelectSnapshot(const QString& ID) { BeginModifyingBox(); SB_PROGRESS Status = CSandBox::SelectSnapshot(ID); ConnectEndSlot(Status); return Status; }
2022-05-16 20:30:40 +01:00
2023-07-01 17:54:53 +01:00
virtual bool IsEmpty() const;
2021-10-16 16:19:51 +01:00
virtual QString GetStatusStr() const;
virtual void SetINetBlock(bool bEnable);
virtual bool IsINetBlocked() const { return m_bINetBlocked; }
virtual void SetAllowShares(bool bEnable);
virtual bool HasSharesAccess() const { return m_bSharesAllowed; }
virtual void SetDropRights(bool bEnable);
virtual bool IsDropRights() const { return m_bDropRights; }
virtual bool IsUnsecureDebugging() const { return m_iUnsecureDebugging != 0; }
virtual void BlockProgram(const QString& ProgName);
virtual void SetInternetAccess(const QString& ProgName, bool bSet);
virtual bool HasInternetAccess(const QString& ProgName);
virtual void SetForcedProgram(const QString& ProgName, bool bSet);
virtual bool IsForcedProgram(const QString& ProgName);
virtual void SetLingeringProgram(const QString& ProgName, bool bSet);
virtual int IsLingeringProgram(const QString& ProgName);
virtual void SetLeaderProgram(const QString& ProgName, bool bSet);
virtual int IsLeaderProgram(const QString& ProgName);
2022-06-13 19:12:53 +01:00
virtual bool IsEmptyCached() const { return m_IsEmpty; }
2023-07-01 17:54:53 +01:00
virtual void UpdateSize(bool bReset = true);
2022-05-16 20:30:40 +01:00
virtual quint64 GetSize() const { if(m_TotalSize == -1) return 0; return m_TotalSize; }
virtual void SetSize(quint64 Size); //{ m_TotalSize = Size; }
2022-06-13 19:12:53 +01:00
virtual bool IsSizePending() const;
2022-05-16 20:30:40 +01:00
2022-09-29 17:28:48 +01:00
virtual bool IsBoxexPath(const QString& Path);
2021-10-16 16:19:51 +01:00
virtual bool IsRecoverySuspended() const { return m_SuspendRecovery; }
virtual void SetSuspendRecovery(bool bSet = true) { m_SuspendRecovery = bSet; }
2023-05-21 18:23:43 +01:00
virtual QString MakeBoxCommand(const QString& FileName);
2022-09-29 17:28:48 +01:00
virtual QString GetCommandFile(const QString& Command);
2023-05-21 18:23:43 +01:00
virtual QString GetFullCommand(const QString& Command);
2022-09-29 17:28:48 +01:00
2021-10-16 16:19:51 +01:00
const QSet<QString>& GetRecentPrograms() { return m_RecentPrograms; }
enum EBoxTypes
{
2021-11-13 08:28:32 +00:00
eHardenedPlus,
2021-10-16 16:19:51 +01:00
eHardened,
2021-11-13 08:28:32 +00:00
eDefaultPlus,
eDefault,
eAppBoxPlus,
eAppBox,
2021-10-16 16:19:51 +01:00
eInsecure,
2022-07-10 17:28:10 +01:00
eOpen,
2021-10-16 16:19:51 +01:00
2021-11-13 08:28:32 +00:00
eUnknown
2021-10-16 16:19:51 +01:00
};
2022-07-10 17:28:10 +01:00
EBoxTypes GetType() const { return m_BoxType; }
2022-11-07 11:06:15 +00:00
bool IsAutoDelete() const { return m_BoxDel; }
2023-04-29 10:55:43 +01:00
bool IsForceDisabled() const { return m_NoForce; }
2022-07-10 17:28:10 +01:00
QRgb GetColor() const { return m_BoxColor; }
2021-10-16 16:19:51 +01:00
class COptionsWindow* m_pOptionsWnd;
class CRecoveryWindow* m_pRecoveryWnd;
2023-07-01 17:54:53 +01:00
bool IsBoxBusy() const { return IsSizePending() || !m_JobQueue.isEmpty(); }
2023-02-03 07:00:11 +00:00
SB_STATUS DeleteContentAsync(bool DeleteSnapshots = true, bool bOnAutoDelete = false);
2022-02-05 14:09:53 +00:00
2022-09-29 17:28:48 +01:00
struct SLink {
2023-08-04 16:47:12 +01:00
SLink() :Url(false), IconIndex(0) {}
2022-09-29 17:28:48 +01:00
QString Folder;
QString Name;
2023-08-04 16:47:12 +01:00
bool Url;
2022-09-29 17:28:48 +01:00
QString Target;
2023-07-24 18:08:26 +01:00
QString Arguments;
2022-09-29 17:28:48 +01:00
QString Icon;
int IconIndex;
2023-05-27 16:12:22 +01:00
QString WorkDir;
2022-09-29 17:28:48 +01:00
};
QList<SLink> GetStartMenu() const { return m_StartMenu.values(); }
2022-07-14 09:46:13 +01:00
signals:
2023-01-29 16:10:11 +00:00
void AboutToBeModified();
2022-09-29 17:28:48 +01:00
void StartMenuChanged();
2022-02-05 14:09:53 +00:00
public slots:
void OnAsyncFinished();
void OnAsyncMessage(const QString& Text);
void OnAsyncProgress(int Progress);
void OnCancelAsync();
2023-01-29 16:10:11 +00:00
protected slots:
virtual void BeginModifyingBox();
virtual void EndModifyingBox();
2021-10-16 16:19:51 +01:00
protected:
friend class CSbiePlusAPI;
2022-06-13 19:12:53 +01:00
2023-01-29 22:50:56 +00:00
struct SFoundLink {
QString Snapshot;
QString LinkPath;
QString RealPath;
QString SubPath;
};
2023-01-29 16:10:11 +00:00
virtual void ConnectEndSlot(const SB_PROGRESS& Status);
2021-10-16 16:19:51 +01:00
virtual bool CheckUnsecureConfig() const;
2022-07-10 17:28:10 +01:00
EBoxTypes GetTypeImpl() const;
2021-10-16 16:19:51 +01:00
virtual bool TestProgramGroup(const QString& Group, const QString& ProgName);
virtual void EditProgramGroup(const QString& Group, const QString& ProgName, bool bSet);
2022-02-05 14:09:53 +00:00
void AddJobToQueue(CBoxJob* pJob);
void StartNextJob();
2022-11-12 09:45:35 +00:00
static void ExportBoxAsync(const CSbieProgressPtr& pProgress, const QString& ExportPath, const QString& RootPath, const QString& Section);
static void ImportBoxAsync(const CSbieProgressPtr& pProgress, const QString& ImportPath, const QString& RootPath, const QString& BoxName);
2023-02-03 07:00:11 +00:00
bool IsFileDeleted(const QString& RealPath, const QString& Snapshot, const QStringList& SnapshotList, const QMap<QString, QList<QString>>& DeletedPaths);
2023-01-29 22:50:56 +00:00
2022-02-05 14:09:53 +00:00
QList<QSharedPointer<CBoxJob>> m_JobQueue;
2021-10-16 16:19:51 +01:00
bool m_bINetBlocked;
2023-05-21 13:48:58 +01:00
bool m_bINetExceptions;
2021-10-16 16:19:51 +01:00
bool m_bSharesAllowed;
bool m_bDropRights;
2021-11-13 08:28:32 +00:00
bool m_bSecurityEnhanced;
bool m_bPrivacyEnhanced;
bool m_bApplicationCompartment;
2021-10-16 16:19:51 +01:00
int m_iUnsecureDebugging;
2022-08-27 19:55:35 +01:00
bool m_bRootAccessOpen;
2021-10-16 16:19:51 +01:00
2022-05-16 20:30:40 +01:00
quint64 m_TotalSize;
2021-10-16 16:19:51 +01:00
bool m_SuspendRecovery;
2022-05-16 20:30:40 +01:00
bool m_IsEmpty;
2022-02-05 14:09:53 +00:00
QString m_StatusStr;
2021-10-16 16:19:51 +01:00
QSet<QString> m_RecentPrograms;
2021-11-13 08:28:32 +00:00
2022-09-29 17:28:48 +01:00
QMap<QString, SLink> m_StartMenu;
2022-07-10 17:28:10 +01:00
EBoxTypes m_BoxType;
2022-11-07 11:06:15 +00:00
bool m_BoxDel;
2023-04-29 10:55:43 +01:00
bool m_NoForce;
2022-07-10 17:28:10 +01:00
QRgb m_BoxColor;
2021-10-16 16:19:51 +01:00
};
2023-07-02 17:09:18 +01:00
///////////////////////////////////////////////////////////////////////////////
// CSbieTemplatesEx
//
class CSbieTemplatesEx : public CSbieTemplates
{
Q_OBJECT
public:
CSbieTemplatesEx(class CSbieAPI* pAPI, QObject* paretn = 0)
:CSbieTemplates(pAPI, paretn) {}
virtual void Reset();
QList<QVariantMap> GetUpdates();
bool CheckUpdates(const QString& Value);
protected:
void CollectUpdates();
QList<QVariantMap> m_Updates;
};