Build 0.2.1 / 5.41.1

This commit is contained in:
DavidXanatos 2020-06-18 17:44:29 +02:00
parent a202d3d990
commit 61124974bc
64 changed files with 868 additions and 156 deletions

View File

@ -3,6 +3,29 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/). This project adheres to [Semantic Versioning](http://semver.org/).
## [0.2.1 / 5.41.1] - 2020-06-18
### Added
- added different sandbox icons for different types
-- Red LogAPI/BSA enabled
-- More to come :D
- Added progress window for async operations that take time
- added DPI awareness
- the driver file is now obfuscated to avoid false positives
- additional debug options to sandboxie.ini OpenToken=y that combines UnrestrictedToken=y and UnfilteredToken=y
-- Note: using these options weekens the sandboxing, they are intended for debugging and may be used for better application virtualization later
### Changed
- SbieDll.dll when processinh InjectDll now looks in the SbieHome folder for the Dll's if the entered path starts with a backslash
-- i.e. "InjectDll=\LogAPI\i386\logapi32v.dll" or "InjectDll64=\LogAPI\amd64\logapi64v.dll"
### Fixed
- IniWatcher did not work in portable mode
- service path fix broke other services, now properly fixed, may be
- found workaround for the msi installer issue
## [0.2 / 5.41.0] - 2020-06-08 ## [0.2 / 5.41.0] - 2020-06-08
### Added ### Added

View File

@ -925,7 +925,11 @@ int Program_Start(void)
expanded = MyHeapAlloc(8192 * sizeof(WCHAR)); expanded = MyHeapAlloc(8192 * sizeof(WCHAR));
ExpandEnvironmentStrings(cmdline, expanded, 8192); ExpandEnvironmentStrings(cmdline, expanded, 8192);
if (wcsstr(expanded, L" ") && !wcsstr(expanded, L"\"")) //
// If the comman contains a space but no ", try to fix it
//
if (wcsstr(expanded, L" ") && !wcsstr(expanded, L"\"") && _waccess(expanded, 0) != -1)
{ {
wmemmove(expanded + 1, expanded, wcslen(expanded) + 1); wmemmove(expanded + 1, expanded, wcslen(expanded) + 1);
expanded[0] = L'\"'; expanded[0] = L'\"';

View File

@ -22,7 +22,7 @@
#define MY_VERSION_BINARY 5,41 #define MY_VERSION_BINARY 5,41
#define MY_VERSION_STRING "5.41" #define MY_VERSION_STRING "5.41"
#define MY_VERSION_STRING_EX "5.41.0" #define MY_VERSION_STRING_EX "5.41.1"
// These #defines are used by either Resource Compiler, or by NSIC installer // These #defines are used by either Resource Compiler, or by NSIC installer
#define SBIE_INSTALLER_PATH "..\\Bin\\" #define SBIE_INSTALLER_PATH "..\\Bin\\"

View File

@ -37,7 +37,7 @@
#ifdef WITH_DEBUG #ifdef WITH_DEBUG
//#define BREAK_IMAGE_1 L"java.exe" // L"jp2launcher.exe" //#define BREAK_IMAGE_1 L"java.exe" // L"jp2launcher.exe"
#define BREAK_IMAGE_1 L"TestTarget.exe" // L"jp2launcher.exe" #define BREAK_IMAGE_1 L"TestTarget.exe"
int Debug_Init(void); int Debug_Init(void);

View File

@ -952,6 +952,11 @@ _FX BOOLEAN Gui_ConnectToWindowStationAndDesktop(HMODULE User32)
rc = (ULONG_PTR)NtCurrentThread(); rc = (ULONG_PTR)NtCurrentThread();
// OpenBox1 BEGIN
if (SbieApi_QueryConfBool(NULL, L"OriginalToken", FALSE))
rc = 0;
else
// OpenBox1 END
if (__sys_NtSetInformationThread) if (__sys_NtSetInformationThread)
{ {
rc = __sys_NtSetInformationThread(NtCurrentThread(), rc = __sys_NtSetInformationThread(NtCurrentThread(),

View File

@ -181,6 +181,9 @@ _FX void Ldr_LoadInjectDlls(BOOLEAN bHostInject)
WCHAR *dllname = Dll_AllocTemp(MAX_PATH * 2 * sizeof(WCHAR)); WCHAR *dllname = Dll_AllocTemp(MAX_PATH * 2 * sizeof(WCHAR));
ULONG index = 0; ULONG index = 0;
WCHAR *path = Dll_AllocTemp(1024 * sizeof(WCHAR));
SbieApi_GetHomePath(NULL, 0, path, 1020);
if (!__sys_LdrLoadDll) if (!__sys_LdrLoadDll)
__sys_LdrLoadDll = (P_LdrLoadDll)GetProcAddress(Dll_Ntdll, "LdrLoadDll"); __sys_LdrLoadDll = (P_LdrLoadDll)GetProcAddress(Dll_Ntdll, "LdrLoadDll");
@ -196,6 +199,18 @@ _FX void Ldr_LoadInjectDlls(BOOLEAN bHostInject)
break; break;
} }
//
// For expidient use we allow to enter the dll name without a path
// starting with \ in that case the DLL is looked for in %SbieHome%
//
if (dllname[0] == L'\\' && wcslen(path) + wcslen(dllname) + 1 < MAX_PATH * 2)
{
wmemmove(dllname + wcslen(path), dllname, wcslen(dllname) + 1);
wmemcpy(dllname, path, wcslen(path));
}
// //
// we have to prevent invocation of Ldr_CallDllCallbacks while // we have to prevent invocation of Ldr_CallDllCallbacks while
// loading the DLL here, otherwise we will end up our per-dll // loading the DLL here, otherwise we will end up our per-dll
@ -225,6 +240,7 @@ _FX void Ldr_LoadInjectDlls(BOOLEAN bHostInject)
} }
Dll_Free(dllname); Dll_Free(dllname);
Dll_Free(path);
} }

View File

@ -1106,6 +1106,9 @@ _FX BOOL Proc_CreateProcessInternalW_RS5(
err = GetLastError(); err = GetLastError();
} }
// OpenBox1 BEGIN
if (!SbieApi_QueryConfBool(NULL, L"OriginalToken", FALSE))
// OpenBox1 END
if (ok) { if (ok) {
// //

View File

@ -1304,8 +1304,12 @@ _FX BOOL Scm_StartServiceCtrlDispatcherX(
args[2] = NULL; args[2] = NULL;
} }
if (_wcsicmp(ServiceName, Scm_MsiServer) == 0) if (_wcsicmp(ServiceName, Scm_MsiServer) == 0) {
Scm_IsMsiServer = TRUE; if (Dll_OsBuild >= 17763 && SbieApi_QueryConfBool(NULL, L"AnonymousLogon", TRUE) == TRUE) {
SbieApi_Log(2194, L"");
}
Scm_IsMsiServer = TRUE;
}
if (! CreateThread(NULL, 0, Scm_ServiceMainThread, args, 0, &ThreadId)) if (! CreateThread(NULL, 0, Scm_ServiceMainThread, args, 0, &ThreadId))
Scm_Stopped = TRUE; Scm_Stopped = TRUE;

View File

@ -1230,7 +1230,7 @@ _FX NTSTATUS Conf_Api_Reload(PROCESS *proc, ULONG64 *parms)
Conf_Data.pool = NULL; Conf_Data.pool = NULL;
List_Init(&Conf_Data.sections); List_Init(&Conf_Data.sections);
Conf_Data.home = TRUE; // = FALSE; Conf_Data.home = FALSE;
ExReleaseResourceLite(Conf_Lock); ExReleaseResourceLite(Conf_Lock);
KeLowerIrql(irql); KeLowerIrql(irql);
@ -1371,7 +1371,7 @@ _FX BOOLEAN Conf_Init(void)
{ {
Conf_Data.pool = NULL; Conf_Data.pool = NULL;
List_Init(&Conf_Data.sections); List_Init(&Conf_Data.sections);
Conf_Data.home = TRUE; // = FALSE; Conf_Data.home = FALSE;
if (! Mem_GetLockResource(&Conf_Lock, TRUE)) if (! Mem_GetLockResource(&Conf_Lock, TRUE))
return FALSE; return FALSE;

View File

@ -222,7 +222,6 @@ _FX NTSTATUS Key_Callback(void *Context, void *Arg1, void *Arg2)
} }
} }
if (status != STATUS_SUCCESS) if (status != STATUS_SUCCESS)
return status; return status;

View File

@ -1248,8 +1248,8 @@ _FX void Process_NotifyImage(
if (ok) if (ok)
ok = Process_Low_InitConsole(proc); ok = Process_Low_InitConsole(proc);
if (ok) if (ok)
ok = Token_ReplacePrimary(proc); ok = Token_ReplacePrimary(proc);
if (ok) if (ok)
ok = Thread_InitProcess(proc); ok = Thread_InitProcess(proc);

View File

@ -19,6 +19,7 @@
// Syscall Management // Syscall Management
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#include "conf.h"
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Functions // Functions
@ -643,6 +644,9 @@ _FX NTSTATUS Syscall_DuplicateHandle_2(
// thread_token.c has a function for this specific case. // thread_token.c has a function for this specific case.
// //
// OpenBox2 BEGIN
if (!(Conf_Get_Boolean(proc->box->name, L"OpenToken", 0, FALSE) || Conf_Get_Boolean(proc->box->name, L"UnfilteredToken", 0, FALSE)))
// OpenBox2 END
status = Thread_CheckTokenObject( status = Thread_CheckTokenObject(
proc, OpenedObject, HandleInfo.GrantedAccess); proc, OpenedObject, HandleInfo.GrantedAccess);
} }

View File

@ -21,7 +21,7 @@
#include "common/my_version.h" #include "common/my_version.h"
#include "conf.h"
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// Defines // Defines
@ -1243,6 +1243,9 @@ _FX NTSTATUS Thread_SetInformationThread_ImpersonationToken(
MyTokenHandle, TOKEN_IMPERSONATE, MyTokenHandle, TOKEN_IMPERSONATE,
*SeTokenObjectType, UserMode, &TokenObject, NULL); *SeTokenObjectType, UserMode, &TokenObject, NULL);
// OpenBox2 BEGIN
if (!(Conf_Get_Boolean(proc->box->name, L"OpenToken", 0, FALSE) || Conf_Get_Boolean(proc->box->name, L"UnfilteredToken", 0, FALSE)))
// OpenBox2 END
if (NT_SUCCESS(status)) { if (NT_SUCCESS(status)) {
status = Thread_CheckTokenForImpersonation( status = Thread_CheckTokenForImpersonation(

View File

@ -433,6 +433,12 @@ _FX void *Token_FilterPrimary(PROCESS *proc, void *ProcessObject)
return NULL; return NULL;
} }
// OpenBox2 BEGIN
if (Conf_Get_Boolean(proc->box->name, L"OpenToken", 0, FALSE) || Conf_Get_Boolean(proc->box->name, L"UnfilteredToken", 0, FALSE)) {
return PrimaryToken;
}
// OpenBox2 END
// DbgPrint(" Process Token %08X - %d <%S>\n", PrimaryToken, proc->pid, proc->image_name); // DbgPrint(" Process Token %08X - %d <%S>\n", PrimaryToken, proc->pid, proc->image_name);
proc->drop_rights = proc->drop_rights =
@ -775,6 +781,15 @@ _FX void *Token_Restrict(
TOKEN_PRIVILEGES *privs; TOKEN_PRIVILEGES *privs;
TOKEN_USER *user; TOKEN_USER *user;
void *NewTokenObject; void *NewTokenObject;
// OpenBox2 BEGIN
if (Conf_Get_Boolean(proc->box->name, L"OpenToken", 0, FALSE) || Conf_Get_Boolean(proc->box->name, L"UnrestrictedToken", 0, FALSE)) {
SeFilterToken(TokenObject, 0, NULL, NULL, NULL, &NewTokenObject);
return NewTokenObject;
//ObReferenceObject(TokenObject);
//return TokenObject;
}
// OpenBox2 END
groups = Token_Query(TokenObject, TokenGroups, proc->box->session_id); groups = Token_Query(TokenObject, TokenGroups, proc->box->session_id);
privs = Token_Query(TokenObject, TokenPrivileges, proc->box->session_id); privs = Token_Query(TokenObject, TokenPrivileges, proc->box->session_id);
@ -1648,6 +1663,11 @@ _FX BOOLEAN Token_ReplacePrimary(PROCESS *proc)
NTSTATUS status; NTSTATUS status;
BOOLEAN ok = FALSE; BOOLEAN ok = FALSE;
// OpenBox1 BEGIN
if (Conf_Get_Boolean(proc->box->name, L"OriginalToken", 0, FALSE))
return TRUE;
// OpenBox1 END
// //
// lookup the process object to get the old primary token // lookup the process object to get the old primary token
// //

View File

@ -719,6 +719,19 @@ HANDLE ProcessServer::RunSandboxedGetToken(
CloseHandle(ThreadHandle); CloseHandle(ThreadHandle);
// OpenBox1 BEGIN
if (!ok && SbieApi_QueryConfBool(NULL, L"OriginalToken", FALSE))
{
ThreadHandle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE,
PipeServer::GetCallerProcessId());
ok = OpenProcessToken(
ThreadHandle, TOKEN_RIGHTS, &OldTokenHandle);
CloseHandle(ThreadHandle);
}
// OpenBox1 END
if (! ok) { if (! ok) {
SetLastError(LastError); SetLastError(LastError);
return NULL; return NULL;

View File

@ -35,6 +35,7 @@ SetCompressor /SOLID /FINAL lzma
!define BIN_ROOT_BASE "${SBIE_INSTALLER_PATH}" !define BIN_ROOT_BASE "${SBIE_INSTALLER_PATH}"
!define SBIEDRV_SYS4 "${SBIEDRV_SYS}.rc4"
!define OUTFILE_BOTH "${PRODUCT_NAME}Install.exe" !define OUTFILE_BOTH "${PRODUCT_NAME}Install.exe"
!define NAME_Win32 "${PRODUCT_FULL_NAME} ${VERSION} (32-bit)" !define NAME_Win32 "${PRODUCT_FULL_NAME} ${VERSION} (32-bit)"
@ -428,7 +429,7 @@ InstDir_Check_Suffix:
Push -12 Push -12
Pop $2 Pop $2
StrCpy $1 $0 "" $2 StrCpy $1 $0 "" $2
StrCmp $1 "\${SBIEDRV_SYS}" InstDir_Suffix_Good StrCmp $1 "\${SBIEDRV_SYS4}" InstDir_Suffix_Good
Goto InstDir_ProgramFiles Goto InstDir_ProgramFiles
@ -463,7 +464,7 @@ InstDir_Done:
StrCmp "$EXEDIR" "$WINDIR\Installer\" InstType_Remove StrCmp "$EXEDIR" "$WINDIR\Installer\" InstType_Remove
StrCmp "$EXEDIR\" "$WINDIR\Installer" InstType_Remove StrCmp "$EXEDIR\" "$WINDIR\Installer" InstType_Remove
IfFileExists $INSTDIR\${SBIEDRV_SYS} InstType_Upgrade IfFileExists $INSTDIR\${SBIEDRV_SYS4} InstType_Upgrade
IfFileExists $INSTDIR\${SBIESVC_EXE} InstType_Upgrade IfFileExists $INSTDIR\${SBIESVC_EXE} InstType_Upgrade
IfFileExists $INSTDIR\${SBIEDLL_DLL} InstType_Upgrade IfFileExists $INSTDIR\${SBIEDLL_DLL} InstType_Upgrade
@ -967,7 +968,7 @@ WriteLoop:
File /oname=${SBIEMSG_DLL} "${BIN_ROOT}\SbieMsg.dll" File /oname=${SBIEMSG_DLL} "${BIN_ROOT}\SbieMsg.dll"
File /oname=${SBIEDRV_SYS} "${BIN_ROOT}\SbieDrv.sys" File /oname=${SBIEDRV_SYS4} "${BIN_ROOT}\SbieDrv.sys.rc4"
File /oname=SboxHostDll.dll "${BIN_ROOT}\SboxHostDll.dll" File /oname=SboxHostDll.dll "${BIN_ROOT}\SboxHostDll.dll"
@ -1072,7 +1073,7 @@ Function DeleteProgramFiles
Delete "$INSTDIR\${SBIEMSG_DLL}" Delete "$INSTDIR\${SBIEMSG_DLL}"
Delete "$INSTDIR\${SBIEDRV_SYS}" Delete "$INSTDIR\${SBIEDRV_SYS4}"
Delete "$INSTDIR\${SANDBOXIE}WUAU.exe" Delete "$INSTDIR\${SANDBOXIE}WUAU.exe"
Delete "$INSTDIR\${SANDBOXIE}EventSys.exe" Delete "$INSTDIR\${SANDBOXIE}EventSys.exe"
@ -1422,7 +1423,7 @@ Driver_Silent:
; For Install and Upgrade, install the driver ; For Install and Upgrade, install the driver
; ;
StrCpy $0 'install ${SBIEDRV} "$INSTDIR\${SBIEDRV_SYS}" type=kernel start=demand "msgfile=$INSTDIR\${SBIEMSG_DLL}" altitude=${FILTER_ALTITUDE}' StrCpy $0 'install ${SBIEDRV} "$INSTDIR\${SBIEDRV_SYS4}" type=kernel start=demand "msgfile=$INSTDIR\${SBIEMSG_DLL}" altitude=${FILTER_ALTITUDE}'
Push $0 Push $0
Call KmdUtil Call KmdUtil

View File

@ -25,6 +25,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "common/defines.h" #include "common/defines.h"
#include "common/my_version.h" #include "common/my_version.h"
#include "rc4.h"
extern void Kmd_ScanDll(BOOLEAN silent); extern void Kmd_ScanDll(BOOLEAN silent);
@ -714,6 +715,39 @@ int __stdcall WinMain(
&Options)) &Options))
return EXIT_FAILURE; return EXIT_FAILURE;
if (Driver_Path)
{
int path_len = wcslen(Driver_Path);
if (path_len > 8 && wcscmp(Driver_Path + path_len - 8, L".sys.rc4") == 0)
{
FILE* inFile = _wfopen(Driver_Path, L"rb");
if (inFile)
{
Driver_Path[path_len - 4] = L'\0';
FILE* outFile = _wfopen(Driver_Path, L"wb");
if (outFile)
{
fseek(inFile, 0, SEEK_END);
DWORD fileSize = ftell(inFile);
fseek(inFile, 0, SEEK_SET);
void* buffer = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, fileSize);
fread(buffer, 1, fileSize, inFile);
char key[] = "default_key";
rc4_sbox_t sbox;
rc4_init(&sbox, key, strlen(key));
rc4_transform(&sbox, buffer, fileSize);
fwrite(buffer, 1, fileSize, outFile);
fclose(outFile);
}
fclose(inFile);
}
}
}
ScMgr = OpenSCManager( ScMgr = OpenSCManager(
NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CREATE_SERVICE); NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CREATE_SERVICE);

View File

@ -123,6 +123,12 @@
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="KmdUtil.c" /> <ClCompile Include="KmdUtil.c" />
<ClCompile Include="rc4.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="sbiedrv.c" /> <ClCompile Include="sbiedrv.c" />
<ClCompile Include="scandll.c" /> <ClCompile Include="scandll.c" />
<ClCompile Include="stdafx.c"> <ClCompile Include="stdafx.c">
@ -133,6 +139,7 @@
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="rc4.h" />
<ClInclude Include="stdafx.h" /> <ClInclude Include="stdafx.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -0,0 +1,49 @@
#include "rc4.h"
void
rc4_swap(unsigned char &a, unsigned char &b)
{
unsigned char c = a;
a = b;
b = c;
}
void
rc4_init(rc4_sbox_t *rc4_sbox, const unsigned char *key_ptr, unsigned int key_len)
{
rc4_sbox->x = 0;
rc4_sbox->y = 0;
// Initialisation of the permutation
unsigned int i;
for(i = 0; i < 256; i++)
rc4_sbox->state[i] = (char)i;
// Mixing permutation
unsigned int j = 0;
unsigned int k;
for(i = 0; i < 256; i++)
{
k = i % key_len;
j = (key_ptr[k] + rc4_sbox->state[i] + j) & 0xff;
rc4_swap(rc4_sbox->state[i], rc4_sbox->state[j]);
}
}
void
rc4_transform(rc4_sbox_t *rc4_sbox, unsigned char *buffer_ptr, unsigned int buffer_len)
{
unsigned int i;
for(i = 0; i < buffer_len; i ++)
{
// The pseudo-random generation algorithm
rc4_sbox->x = (rc4_sbox->x + 1) & 0xff;
rc4_sbox->y = (rc4_sbox->y + rc4_sbox->state[rc4_sbox->x]) & 0xff;
rc4_swap(rc4_sbox->state[rc4_sbox->x], rc4_sbox->state[rc4_sbox->y]);
unsigned char keyChar = rc4_sbox->state[(rc4_sbox->state[rc4_sbox->x] + rc4_sbox->state[rc4_sbox->y]) & 0xff];
if(buffer_ptr) // NULL when seeking
buffer_ptr[i] ^= keyChar;
}
}

View File

@ -0,0 +1,24 @@
#ifndef rc4_INCLUDED
# define rc4_INCLUDED
typedef struct rc4_sbox_s
{
unsigned char state[256];
unsigned int x;
unsigned int y;
} rc4_sbox_t;
#ifdef __cplusplus
extern "C"
{
#endif
void rc4_init(rc4_sbox_t *rc4_sbox, const unsigned char *key_ptr, unsigned int key_len);
void rc4_transform(rc4_sbox_t *rc4_sbox, unsigned char *buffer_ptr, unsigned int buffer_len);
#ifdef __cplusplus
} /* end extern "C" */
#endif
#endif /* rc4_INCLUDED */

View File

@ -28,7 +28,7 @@
</ImportGroup> </ImportGroup>
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">
<OutDir>..\</OutDir> <OutDir>..\..\bin\</OutDir>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">
<ClCompile> <ClCompile>
@ -38,7 +38,7 @@
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>..\$(TargetName)$(TargetExt)</OutputFile> <OutputFile>..\..\bin\$(TargetName)$(TargetExt)</OutputFile>
<UACExecutionLevel>RequireAdministrator</UACExecutionLevel> <UACExecutionLevel>RequireAdministrator</UACExecutionLevel>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>

Binary file not shown.

Binary file not shown.

View File

@ -318,4 +318,27 @@ QAction* MakeAction(QActionGroup* pGroup, QMenu* pParent, const QString& Text, c
pAction->setActionGroup(pGroup); pAction->setActionGroup(pGroup);
pParent->addAction(pAction); pParent->addAction(pAction);
return pAction; return pAction;
} }
//////////////////////////////////////////////////////////////////////////////////////////
//
//
#ifdef WIN32
#include <windows.h>
#include <io.h>
#include <fcntl.h>
bool InitConsole(bool bCreateIfNeeded)
{
if (AttachConsole(ATTACH_PARENT_PROCESS) == FALSE)
{
if (!bCreateIfNeeded)
return false;
AllocConsole();
}
freopen("CONOUT$", "w", stdout);
printf("\r\n");
return true;
}
#endif

View File

@ -90,3 +90,7 @@ MISCHELPERS_EXPORT QMenu* MakeMenu(QMenu* pParent, const QString& Text, const QS
MISCHELPERS_EXPORT QAction* MakeAction(QMenu* pParent, const QString& Text, const QString& IconFile = ""); MISCHELPERS_EXPORT QAction* MakeAction(QMenu* pParent, const QString& Text, const QString& IconFile = "");
MISCHELPERS_EXPORT QAction* MakeAction(QActionGroup* pGroup, QMenu* pParent, const QString& Text, const QVariant& Data); MISCHELPERS_EXPORT QAction* MakeAction(QActionGroup* pGroup, QMenu* pParent, const QString& Text, const QVariant& Data);
#ifdef WIN32
MISCHELPERS_EXPORT bool InitConsole(bool bCreateIfNeeded = true);
#endif

View File

@ -0,0 +1,63 @@
#include "stdafx.h"
#include "qRC4.h"
#include <QByteArray>
void
rc4_swap(unsigned char &a, unsigned char &b)
{
unsigned char c = a;
a = b;
b = c;
}
void
rc4_init(rc4_sbox_t *rc4_sbox, const unsigned char *key_ptr, unsigned int key_len)
{
rc4_sbox->x = 0;
rc4_sbox->y = 0;
// Initialisation of the permutation
unsigned int i;
for (i = 0; i < 256; i++)
rc4_sbox->state[i] = (char)i;
// Mixing permutation
unsigned int j = 0;
unsigned int k;
for (i = 0; i < 256; i++)
{
k = i % key_len;
j = (key_ptr[k] + rc4_sbox->state[i] + j) & 0xff;
rc4_swap(rc4_sbox->state[i], rc4_sbox->state[j]);
}
}
void
rc4_transform(rc4_sbox_t *rc4_sbox, unsigned char *buffer_ptr, unsigned int buffer_len)
{
unsigned int i;
for (i = 0; i < buffer_len; i++)
{
// The pseudo-random generation algorithm
rc4_sbox->x = (rc4_sbox->x + 1) & 0xff;
rc4_sbox->y = (rc4_sbox->y + rc4_sbox->state[rc4_sbox->x]) & 0xff;
rc4_swap(rc4_sbox->state[rc4_sbox->x], rc4_sbox->state[rc4_sbox->y]);
unsigned char keyChar = rc4_sbox->state[(rc4_sbox->state[rc4_sbox->x] + rc4_sbox->state[rc4_sbox->y]) & 0xff];
if (buffer_ptr) // NULL when seeking
buffer_ptr[i] ^= keyChar;
}
}
void MISCHELPERS_EXPORT rc4_init(rc4_sbox_t *rc4_sbox, const QByteArray& Key)
{
rc4_init(rc4_sbox, (unsigned char*)Key.data(), Key.size());
}
QByteArray MISCHELPERS_EXPORT rc4_transform(rc4_sbox_t *rc4_sbox, const QByteArray& Data)
{
QByteArray Temp = Data;
rc4_transform(rc4_sbox, (unsigned char*)Temp.data(), Temp.size());
return Temp;
}

View File

@ -0,0 +1,18 @@
#pragma once
#include "../mischelpers_global.h"
typedef struct MISCHELPERS_EXPORT rc4_sbox_s
{
unsigned char state[256];
unsigned int x;
unsigned int y;
} rc4_sbox_t;
void MISCHELPERS_EXPORT rc4_init(rc4_sbox_t *rc4_sbox, const unsigned char *key_ptr, unsigned int key_len);
void MISCHELPERS_EXPORT rc4_transform(rc4_sbox_t *rc4_sbox, unsigned char *buffer_ptr, unsigned int buffer_len);
void MISCHELPERS_EXPORT rc4_init(rc4_sbox_t *rc4_sbox, const QByteArray& Key);
QByteArray MISCHELPERS_EXPORT rc4_transform(rc4_sbox_t *rc4_sbox, const QByteArray& Data);

View File

@ -186,6 +186,7 @@
<ClCompile Include="Common\ListItemModel.cpp" /> <ClCompile Include="Common\ListItemModel.cpp" />
<ClCompile Include="Common\MultiLineInputDialog.cpp" /> <ClCompile Include="Common\MultiLineInputDialog.cpp" />
<ClCompile Include="Common\PanelView.cpp" /> <ClCompile Include="Common\PanelView.cpp" />
<ClCompile Include="Common\qRC4.cpp" />
<ClCompile Include="Common\Settings.cpp" /> <ClCompile Include="Common\Settings.cpp" />
<ClCompile Include="Common\SettingsWidgets.cpp" /> <ClCompile Include="Common\SettingsWidgets.cpp" />
<ClCompile Include="Common\SmartGridWidget.cpp" /> <ClCompile Include="Common\SmartGridWidget.cpp" />
@ -227,6 +228,7 @@
<QtMoc Include="Common\TreeViewEx.h" /> <QtMoc Include="Common\TreeViewEx.h" />
<QtMoc Include="Common\TreeWidgetEx.h" /> <QtMoc Include="Common\TreeWidgetEx.h" />
<ClInclude Include="Common\IconExtreactor.h" /> <ClInclude Include="Common\IconExtreactor.h" />
<ClInclude Include="Common\qRC4.h" />
<ClInclude Include="Common\Xml.h" /> <ClInclude Include="Common\Xml.h" />
<ClInclude Include="MiscHelpers.h" /> <ClInclude Include="MiscHelpers.h" />
<ClInclude Include="mischelpers_global.h" /> <ClInclude Include="mischelpers_global.h" />

View File

@ -87,6 +87,9 @@
<ClCompile Include="Common\IconExtreactor.cpp"> <ClCompile Include="Common\IconExtreactor.cpp">
<Filter>Common</Filter> <Filter>Common</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Common\qRC4.cpp">
<Filter>Common</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="MiscHelpers.h"> <ClInclude Include="MiscHelpers.h">
@ -119,6 +122,9 @@
<ClInclude Include="Common\IconExtreactor.h"> <ClInclude Include="Common\IconExtreactor.h">
<Filter>Common</Filter> <Filter>Common</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Common\qRC4.h">
<Filter>Common</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="mischelpers_global.h"> <ClInclude Include="mischelpers_global.h">

View File

@ -52,7 +52,7 @@ CBoxedProcess::~CBoxedProcess()
//delete m; //delete m;
} }
void CBoxedProcess::UpdateProcessInfo() void CBoxedProcess::InitProcessInfo()
{ {
HANDLE ProcessHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, (DWORD)m_ProcessId); HANDLE ProcessHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, (DWORD)m_ProcessId);
if (ProcessHandle != INVALID_HANDLE_VALUE) if (ProcessHandle != INVALID_HANDLE_VALUE)

View File

@ -18,17 +18,18 @@
#pragma once #pragma once
#include <qobject.h> #include <qobject.h>
#include "../qsbieapi_global.h"
#include "../SbieError.h" #include "../SbieError.h"
class CBoxedProcess : public QObject class QSBIEAPI_EXPORT CBoxedProcess : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
CBoxedProcess(quint64 ProcessId, class CSandBox* pBox); CBoxedProcess(quint64 ProcessId, class CSandBox* pBox);
virtual ~CBoxedProcess(); virtual ~CBoxedProcess();
virtual void UpdateProcessInfo(); virtual void InitProcessInfo();
virtual quint64 GetProcessId() const { return m_ProcessId; } virtual quint64 GetProcessId() const { return m_ProcessId; }
virtual quint64 GetParendPID() const { return m_ParendPID; } virtual quint64 GetParendPID() const { return m_ParendPID; }

View File

@ -18,6 +18,11 @@
#include "stdafx.h" #include "stdafx.h"
#include "IniSection.h" #include "IniSection.h"
#include "../SbieAPI.h" #include "../SbieAPI.h"
#include <ntstatus.h>
#define WIN32_NO_STATUS
typedef long NTSTATUS;
#include "..\..\Sandboxie\core\drv\api_flags.h" #include "..\..\Sandboxie\core\drv\api_flags.h"
CIniSection::CIniSection(const QString& Section, class CSbieAPI* pAPI, QObject* parent) : QObject(parent) CIniSection::CIniSection(const QString& Section, class CSbieAPI* pAPI, QObject* parent) : QObject(parent)
@ -54,7 +59,8 @@ SB_STATUS CIniSection::SetBool(const QString& Setting, bool Value)
QString CIniSection::GetText(const QString& Setting, const QString& Default) const QString CIniSection::GetText(const QString& Setting, const QString& Default) const
{ {
QString Value = m_pAPI->SbieIniGet(m_Name, Setting, CONF_GET_NO_GLOBAL | CONF_GET_NO_EXPAND); int flags = (m_Name.isEmpty() ? 0 : CONF_GET_NO_GLOBAL) | CONF_GET_NO_EXPAND;
QString Value = m_pAPI->SbieIniGet(m_Name, Setting, flags);
if (Value.isNull()) Value = Default; if (Value.isNull()) Value = Default;
return Value; return Value;
} }
@ -87,6 +93,25 @@ bool CIniSection::GetBool(const QString& Setting, bool Default) const
return Default; return Default;
} }
QStringList CIniSection::GetTextList(const QString &Setting, bool withBrackets)
{
QStringList TextList;
int flags = (m_Name.isEmpty() ? 0 : CONF_GET_NO_GLOBAL) | CONF_GET_NO_EXPAND;
if (withBrackets)
flags |= CONF_GET_NO_TEMPLS;
for(int index = 0; ; index++)
{
QString Value = m_pAPI->SbieIniGet(m_Name, Setting, index | flags);
if (Value.isNull())
break;
TextList.append(Value);
}
return TextList;
}
SB_STATUS CIniSection::InsertText(const QString& Setting, const QString& Value) SB_STATUS CIniSection::InsertText(const QString& Setting, const QString& Value)
{ {
return m_pAPI->SbieIniSet(m_Name, Setting, Value, CSbieAPI::eIniInsert); return m_pAPI->SbieIniSet(m_Name, Setting, Value, CSbieAPI::eIniInsert);
@ -100,4 +125,88 @@ SB_STATUS CIniSection::AppendText(const QString& Setting, const QString& Value)
SB_STATUS CIniSection::DelValue(const QString& Setting, const QString& Value) SB_STATUS CIniSection::DelValue(const QString& Setting, const QString& Value)
{ {
return m_pAPI->SbieIniSet(m_Name, Setting, Value, CSbieAPI::eIniDelete); return m_pAPI->SbieIniSet(m_Name, Setting, Value, CSbieAPI::eIniDelete);
}
SB_STATUS CIniSection::RenameSection( const QString& NewName, bool deleteOld) // Note: deleteOld is used when duplicating a box
{
if (m_Name.isEmpty() || NewName.isEmpty())
return SB_ERR();
bool SameName = (bool)(NewName.compare(m_Name, Qt::CaseInsensitive) == 0);
qint32 status = STATUS_SUCCESS;
// Get all Settigns
QList<QPair<QString, QString>> Settings;
for (int setting_index = 0; ; setting_index++)
{
QString setting_name = m_pAPI->SbieIniGet(m_Name, NULL, setting_index | CONF_GET_NO_TEMPLS | CONF_GET_NO_EXPAND, &status);
if (status == STATUS_RESOURCE_NAME_NOT_FOUND) {
status = STATUS_SUCCESS;
break;
}
if (status != STATUS_SUCCESS)
break;
for (int value_index = 0; ; value_index++)
{
QString setting_value = m_pAPI->SbieIniGet(m_Name, setting_name, value_index | CONF_GET_NO_GLOBAL | CONF_GET_NO_TEMPLS | CONF_GET_NO_EXPAND, &status);
if (status == STATUS_RESOURCE_NAME_NOT_FOUND) {
status = STATUS_SUCCESS;
break;
}
if (status != STATUS_SUCCESS)
break;
Settings.append(qMakePair(setting_name, setting_value));
}
if (status != STATUS_SUCCESS)
break;
}
if (status != STATUS_SUCCESS)
return SB_ERR(CSbieAPI::tr("Failed to copy configuration from sandbox %1: %2").arg(m_Name).arg(status, 8, 16), status);
// check if such a box already exists
if (!SameName)
{
m_pAPI->SbieIniGet(NewName, NULL, CONF_GET_NO_EXPAND, &status);
if (status != STATUS_RESOURCE_NAME_NOT_FOUND)
return SB_ERR(CSbieAPI::tr("A sandbox of the name %1 already exists").arg(NewName));
}
// if the name is the same we first delete than write,
// else we first write and than delete, fro safety reasons
if (deleteOld && SameName)
goto do_delete;
do_write:
// Apply all Settigns
for (QList<QPair<QString, QString>>::iterator I = Settings.begin(); I != Settings.end(); ++I)
{
SB_STATUS Status = m_pAPI->SbieIniSet(NewName, I->first, I->second);
if (Status.IsError())
return Status;
}
do_delete:
// Selete ini section
if (deleteOld)
{
SB_STATUS Status = m_pAPI->SbieIniSet(m_Name, "*", "");
if (Status.IsError())
return SB_ERR(CSbieAPI::tr("Failed to delete sandbox %1: %2").arg(m_Name).arg(Status.GetStatus(), 8, 16), Status.GetStatus());
deleteOld = false;
if (SameName)
goto do_write;
}
return SB_OK;
}
SB_STATUS CIniSection::RemoveSection()
{
return m_pAPI->SbieIniSet(m_Name, "*", "");
} }

View File

@ -1,9 +1,11 @@
#pragma once #pragma once
#include <QObject> #include <QObject>
#include "../qsbieapi_global.h"
#include "../SbieError.h" #include "../SbieError.h"
class CIniSection: public QObject class QSBIEAPI_EXPORT CIniSection: public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -20,11 +22,16 @@ public:
virtual __int64 GetNum64(const QString& Setting, __int64 Default = 0) const; virtual __int64 GetNum64(const QString& Setting, __int64 Default = 0) const;
virtual bool GetBool(const QString& Setting, bool Default = false) const; virtual bool GetBool(const QString& Setting, bool Default = false) const;
virtual QStringList GetTextList(const QString &Setting, bool withBrackets = false);
virtual SB_STATUS InsertText(const QString& Setting, const QString& Value); virtual SB_STATUS InsertText(const QString& Setting, const QString& Value);
virtual SB_STATUS AppendText(const QString& Setting, const QString& Value); virtual SB_STATUS AppendText(const QString& Setting, const QString& Value);
virtual SB_STATUS DelValue(const QString& Setting, const QString& Value); virtual SB_STATUS DelValue(const QString& Setting, const QString& Value);
virtual SB_STATUS RenameSection(const QString& NewName, bool deleteOld = true);
virtual SB_STATUS RemoveSection();
protected: protected:
QString m_Name; QString m_Name;

View File

@ -60,6 +60,10 @@ CSandBox::~CSandBox()
//delete m; //delete m;
} }
void CSandBox::UpdateDetails()
{
}
SB_STATUS CSandBox::RunStart(const QString& Command) SB_STATUS CSandBox::RunStart(const QString& Command)
{ {
return m_pAPI->RunStart(m_Name, Command); return m_pAPI->RunStart(m_Name, Command);
@ -80,19 +84,26 @@ SB_STATUS CSandBox::CleanBox()
SB_STATUS Status = m_pAPI->TerminateAll(m_Name); SB_STATUS Status = m_pAPI->TerminateAll(m_Name);
if (Status.IsError()) if (Status.IsError())
return Status; return Status;
return m_pAPI->CleanBox(m_Name);
QProcess* pProcess = new QProcess(this);
connect(pProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SIGNAL(BoxCleaned()));
// ToDo-later: do that manually
Status = m_pAPI->RunStart(m_Name, "delete_sandbox", pProcess);
return Status;
} }
SB_STATUS CSandBox::RenameBox(const QString& NewName) SB_STATUS CSandBox::RenameBox(const QString& NewName)
{ {
if (QDir(m_pAPI->Nt2DosPath(m_FilePath)).exists()) if (QDir(m_pAPI->Nt2DosPath(m_FilePath)).exists())
return SB_ERR("A sandbox must be emptied before it can be renamed."); return SB_ERR("A sandbox must be emptied before it can be renamed.");
return m_pAPI->RenameBox(m_Name, NewName); return RenameSection(NewName);
} }
SB_STATUS CSandBox::RemoveBox() SB_STATUS CSandBox::RemoveBox()
{ {
if (QDir(m_pAPI->Nt2DosPath(m_FilePath)).exists()) if (QDir(m_pAPI->Nt2DosPath(m_FilePath)).exists())
return SB_ERR("A sandbox must be emptied before it can be deleted."); return SB_ERR("A sandbox must be emptied before it can be deleted.");
return m_pAPI->RemoveBox(m_Name); return RemoveSection();
} }

View File

@ -18,16 +18,20 @@
#pragma once #pragma once
#include <qobject.h> #include <qobject.h>
#include "../qsbieapi_global.h"
#include "BoxedProcess.h" #include "BoxedProcess.h"
#include "IniSection.h" #include "IniSection.h"
class CSandBox : public CIniSection class QSBIEAPI_EXPORT CSandBox : public CIniSection
{ {
Q_OBJECT Q_OBJECT
public: public:
CSandBox(const QString& BoxName, class CSbieAPI* pAPI); CSandBox(const QString& BoxName, class CSbieAPI* pAPI);
virtual ~CSandBox(); virtual ~CSandBox();
virtual void UpdateDetails();
virtual QString GetName() const { return m_Name; } virtual QString GetName() const { return m_Name; }
virtual QMap<quint64, CBoxedProcessPtr> GetProcessList() const { return m_ProcessList; } virtual QMap<quint64, CBoxedProcessPtr> GetProcessList() const { return m_ProcessList; }
@ -42,6 +46,9 @@ public:
class CSbieAPI* Api() { return m_pAPI; } class CSbieAPI* Api() { return m_pAPI; }
signals:
void BoxCleaned();
protected: protected:
friend class CSbieAPI; friend class CSbieAPI;

View File

@ -122,6 +122,16 @@ CSbieAPI::~CSbieAPI()
delete m; delete m;
} }
CSandBox* CSbieAPI::NewSandBox(const QString& BoxName, class CSbieAPI* pAPI)
{
return new CSandBox(BoxName, pAPI);
}
CBoxedProcess* CSbieAPI::NewBoxedProcess(quint64 ProcessId, class CSandBox* pBox)
{
return new CBoxedProcess(ProcessId, pBox);
}
SB_STATUS CSbieAPI::Connect(bool takeOver, bool andLoad) SB_STATUS CSbieAPI::Connect(bool takeOver, bool andLoad)
{ {
if (IsConnected()) if (IsConnected())
@ -575,7 +585,7 @@ QString CSbieAPI::GetIniPath(bool* IsHome) const
return IniPath; return IniPath;
} }
SB_STATUS CSbieAPI::RunStart(const QString& BoxName, const QString& Command) SB_STATUS CSbieAPI::RunStart(const QString& BoxName, const QString& Command, QProcess* pProcess)
{ {
if (m_SbiePath.isEmpty()) if (m_SbiePath.isEmpty())
return SB_ERR(tr("Can't find Sandboxie instal path.")); return SB_ERR(tr("Can't find Sandboxie instal path."));
@ -583,12 +593,14 @@ SB_STATUS CSbieAPI::RunStart(const QString& BoxName, const QString& Command)
QStringList Arguments; QStringList Arguments;
Arguments.append("/box:" + BoxName); Arguments.append("/box:" + BoxName);
Arguments.append(Command); Arguments.append(Command);
QProcess::startDetached(m_SbiePath + "//" + QString::fromWCharArray(SBIESTART_EXE), Arguments); if (pProcess)
pProcess->start(m_SbiePath + "//" + QString::fromWCharArray(SBIESTART_EXE), Arguments);
else
QProcess::startDetached(m_SbiePath + "//" + QString::fromWCharArray(SBIESTART_EXE), Arguments);
return SB_OK; return SB_OK;
} }
SB_STATUS CSbieAPI::ReloadBoxes() SB_STATUS CSbieAPI::ReloadBoxes(bool bFull)
{ {
QMap<QString, CSandBoxPtr> OldSandBoxes = m_SandBoxes; QMap<QString, CSandBoxPtr> OldSandBoxes = m_SandBoxes;
@ -603,11 +615,15 @@ SB_STATUS CSbieAPI::ReloadBoxes()
CSandBoxPtr pBox = OldSandBoxes.take(BoxName); CSandBoxPtr pBox = OldSandBoxes.take(BoxName);
if (!pBox) if (!pBox)
{ {
pBox = CSandBoxPtr(new CSandBox(BoxName, this)); pBox = CSandBoxPtr(NewSandBox(BoxName, this));
m_SandBoxes.insert(BoxName, pBox); m_SandBoxes.insert(BoxName, pBox);
SetBoxPaths(pBox); SetBoxPaths(pBox);
} }
else if (!bFull)
continue;
pBox->UpdateDetails();
// todo: // todo:
} }
@ -701,96 +717,6 @@ SB_STATUS CSbieAPI::CreateBox(const QString& BoxName)
return SbieIniSet(BoxName, "Enabled", "y"); return SbieIniSet(BoxName, "Enabled", "y");
} }
SB_STATUS CSbieAPI::CleanBox(const QString& BoxName)
{
// ToDo-later: do that manually
return RunStart(BoxName, "delete_sandbox");
}
SB_STATUS CSbieAPI::RenameBox(const QString& OldName, const QString& NewName, bool deleteOld) // Note: deleteOld is used when duplicating a box
{
if (OldName.isEmpty() || NewName.isEmpty())
return SB_ERR();
bool SameName = (bool)(NewName.compare(OldName, Qt::CaseInsensitive) == 0);
qint32 status = STATUS_SUCCESS;
// Get all Settigns
QList<QPair<QString, QString>> Settings;
for (int setting_index = 0; ; setting_index++)
{
QString setting_name = SbieIniGet(OldName, NULL, setting_index | CONF_GET_NO_TEMPLS | CONF_GET_NO_EXPAND, &status);
if (status == STATUS_RESOURCE_NAME_NOT_FOUND) {
status = STATUS_SUCCESS;
break;
}
if (status != STATUS_SUCCESS)
break;
for (int value_index = 0; ; value_index++)
{
QString setting_value = SbieIniGet(OldName, setting_name, value_index | CONF_GET_NO_GLOBAL | CONF_GET_NO_TEMPLS | CONF_GET_NO_EXPAND, &status);
if (status == STATUS_RESOURCE_NAME_NOT_FOUND) {
status = STATUS_SUCCESS;
break;
}
if (status != STATUS_SUCCESS)
break;
Settings.append(qMakePair(setting_name, setting_value));
}
if (status != STATUS_SUCCESS)
break;
}
if (status != STATUS_SUCCESS)
return SB_ERR(CSbieAPI::tr("Failed to copy configuration from sandbox %1: %2").arg(OldName).arg(status, 8, 16), status);
// check if such a box already exists
if (!SameName)
{
SbieIniGet(NewName, NULL, CONF_GET_NO_EXPAND, &status);
if (status != STATUS_RESOURCE_NAME_NOT_FOUND)
return SB_ERR(CSbieAPI::tr("A sandbox of the name %1 already exists").arg(NewName));
}
// if the name is the same we first delete than write,
// else we first write and than delete, fro safety reasons
if (deleteOld && SameName)
goto do_delete;
do_write:
// Apply all Settigns
for (QList<QPair<QString, QString>>::iterator I = Settings.begin(); I != Settings.end(); ++I)
{
SB_STATUS Status = SbieIniSet(NewName, I->first, I->second);
if (Status.IsError())
return Status;
}
do_delete:
// Selete ini section
if (deleteOld)
{
SB_STATUS Status = SbieIniSet(OldName, "*", "");
if (Status.IsError())
return SB_ERR(CSbieAPI::tr("Failed to delete sandbox %1: %2").arg(OldName).arg(Status.GetStatus(), 8, 16), Status.GetStatus());
deleteOld = false;
if (SameName)
goto do_write;
}
return SB_OK;
}
SB_STATUS CSbieAPI::RemoveBox(const QString& BoxName)
{
// Note: SandBox must be emptied at this point
return SbieIniSet(BoxName, "*", "");
}
SB_STATUS CSbieAPI::UpdateProcesses(bool bKeep) SB_STATUS CSbieAPI::UpdateProcesses(bool bKeep)
{ {
foreach(const CSandBoxPtr& pBox, m_SandBoxes) foreach(const CSandBoxPtr& pBox, m_SandBoxes)
@ -827,13 +753,13 @@ SB_STATUS CSbieAPI::UpdateProcesses(bool bKeep, const CSandBoxPtr& pBox)
CBoxedProcessPtr pProcess = OldProcessList.take(ProcessId); CBoxedProcessPtr pProcess = OldProcessList.take(ProcessId);
if (!pProcess) if (!pProcess)
{ {
pProcess = CBoxedProcessPtr(new CBoxedProcess(ProcessId, pBox.data())); pProcess = CBoxedProcessPtr(NewBoxedProcess(ProcessId, pBox.data()));
//pProcess->m_pBox = pBox; //pProcess->m_pBox = pBox;
pBox->m_ProcessList.insert(ProcessId, pProcess); pBox->m_ProcessList.insert(ProcessId, pProcess);
m_BoxedProxesses.insert(ProcessId, pProcess); m_BoxedProxesses.insert(ProcessId, pProcess);
SetProcessInfo(pProcess); SetProcessInfo(pProcess);
pProcess->UpdateProcessInfo(); pProcess->InitProcessInfo();
} }
// todo: // todo:
@ -1194,6 +1120,9 @@ SB_STATUS CSbieAPI::ReloadConfig(quint32 SessionId)
return SB_ERR(status); return SB_ERR(status);
emit LogMessage("Sandboxie config has been reloaded."); emit LogMessage("Sandboxie config has been reloaded.");
ReloadBoxes(true);
return SB_OK; return SB_OK;
} }

View File

@ -27,7 +27,7 @@
#include "./Sandboxie/SandBox.h" #include "./Sandboxie/SandBox.h"
#include "./Sandboxie/BoxedProcess.h" #include "./Sandboxie/BoxedProcess.h"
class CResLogEntry : public QSharedData class QSBIEAPI_EXPORT CResLogEntry : public QSharedData
{ {
public: public:
CResLogEntry(quint64 ProcessId, quint32 Type, const QString& Value); CResLogEntry(quint64 ProcessId, quint32 Type, const QString& Value);
@ -77,7 +77,7 @@ public:
virtual void UpdateDriveLetters(); virtual void UpdateDriveLetters();
virtual QString Nt2DosPath(QString NtPath) const; virtual QString Nt2DosPath(QString NtPath) const;
virtual SB_STATUS ReloadBoxes(); virtual SB_STATUS ReloadBoxes(bool bFull = false);
virtual SB_STATUS CreateBox(const QString& BoxName); virtual SB_STATUS CreateBox(const QString& BoxName);
virtual SB_STATUS UpdateProcesses(bool bKeep); virtual SB_STATUS UpdateProcesses(bool bKeep);
@ -122,14 +122,13 @@ protected:
friend class CSandBox; friend class CSandBox;
friend class CBoxedProcess; friend class CBoxedProcess;
virtual CSandBox* NewSandBox(const QString& BoxName, class CSbieAPI* pAPI);
virtual CBoxedProcess* NewBoxedProcess(quint64 ProcessId, class CSandBox* pBox);
virtual QString GetSbieHome() const; virtual QString GetSbieHome() const;
virtual QString GetIniPath(bool* IsHome) const; virtual QString GetIniPath(bool* IsHome) const;
virtual SB_STATUS RunStart(const QString& BoxName, const QString& Command); virtual SB_STATUS RunStart(const QString& BoxName, const QString& Command, QProcess* pProcess = NULL);
virtual SB_STATUS CleanBox(const QString& BoxName);
virtual SB_STATUS RenameBox(const QString& OldName, const QString& NewName, bool deleteOld = true);
virtual SB_STATUS RemoveBox(const QString& BoxName);
virtual bool GetLog(); virtual bool GetLog();
virtual bool GetMonitor(); virtual bool GetMonitor();

View File

@ -7,8 +7,11 @@
CSbieModel::CSbieModel(QObject *parent) CSbieModel::CSbieModel(QObject *parent)
:CTreeItemModel(parent) :CTreeItemModel(parent)
{ {
m_BoxEmpty = QIcon(":/BoxEmpty"); for (int i = 0; i < eMaxColor; i++)
m_BoxInUse = QIcon(":/BoxInUse"); m_BoxIcons[(EBoxColors)i] = qMakePair(QIcon(QString(":/Boxes/Empty%1").arg(i)), QIcon(QString(":/Boxes/Full%1").arg(i)));
//m_BoxEmpty = QIcon(":/BoxEmpty");
//m_BoxInUse = QIcon(":/BoxInUse");
m_ExeIcon = QIcon(":/exeIcon32"); m_ExeIcon = QIcon(":/exeIcon32");
m_Root = MkNode(QVariant()); m_Root = MkNode(QVariant());
@ -91,6 +94,8 @@ QList<QVariant> CSbieModel::Sync(const QMap<QString, CSandBoxPtr>& BoxList)
Index = Find(m_Root, pNode); Index = Find(m_Root, pNode);
} }
CSandBoxPlus* pBoxEx = qobject_cast<CSandBoxPlus*>(pBox.data());
int Col = 0; int Col = 0;
bool State = false; bool State = false;
int Changed = 0; int Changed = 0;
@ -98,11 +103,16 @@ QList<QVariant> CSbieModel::Sync(const QMap<QString, CSandBoxPtr>& BoxList)
QMap<quint64, CBoxedProcessPtr> ProcessList = pBox->GetProcessList(); QMap<quint64, CBoxedProcessPtr> ProcessList = pBox->GetProcessList();
bool HasActive = Sync(pBox, ProcessList, New, Old, Added); bool HasActive = Sync(pBox, ProcessList, New, Old, Added);
int inUse = (HasActive ? 1 : 0);
if (pNode->inUse != (HasActive ? 1 : 0)) int boxType = pBoxEx && pBoxEx->HasLogApi() ? eLogApi : eNormal;
if (pBoxEx && pBoxEx->IsOpenBox())
boxType = eOpenBox;// : eOpenInSys;
if (pNode->inUse != inUse || pNode->boxType != boxType)
{ {
pNode->inUse = (HasActive ? 1 : 0); pNode->inUse = inUse;
pNode->Icon = pNode->inUse ? m_BoxInUse : m_BoxEmpty; pNode->boxType = boxType;
//pNode->Icon = pNode->inUse ? m_BoxInUse : m_BoxEmpty;
pNode->Icon = pNode->inUse ? m_BoxIcons[(EBoxColors)boxType].second : m_BoxIcons[(EBoxColors)boxType].first;
Changed = 1; // set change for first column Changed = 1; // set change for first column
} }
@ -115,6 +125,7 @@ QList<QVariant> CSbieModel::Sync(const QMap<QString, CSandBoxPtr>& BoxList)
switch(section) switch(section)
{ {
case eName: Value = pBox->GetName(); break; case eName: Value = pBox->GetName(); break;
case eStatus: Value = boxType; break;
} }
SSandBoxNode::SValue& ColValue = pNode->Values[section]; SSandBoxNode::SValue& ColValue = pNode->Values[section];
@ -125,10 +136,10 @@ QList<QVariant> CSbieModel::Sync(const QMap<QString, CSandBoxPtr>& BoxList)
Changed = 1; Changed = 1;
ColValue.Raw = Value; ColValue.Raw = Value;
/*switch (section) switch (section)
{ {
case eStatus: ColValue.Formated = boxType == eLogApi ? tr("LogApi Enabled") : tr("Normal"); break; // todo: add more
}*/ }
} }
if(State != (Changed != 0)) if(State != (Changed != 0))

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <qwidget.h> #include <qwidget.h>
#include "../../QSbieAPI/Sandboxie/SandBox.h" #include "../SbiePlusAPI.h"
#include "../../MiscHelpers/Common/TreeItemModel.h" #include "../../MiscHelpers/Common/TreeItemModel.h"
@ -36,10 +36,11 @@ protected:
struct SSandBoxNode: STreeNode struct SSandBoxNode: STreeNode
{ {
SSandBoxNode(const QVariant& Id) : STreeNode(Id) { inUse = -1; } SSandBoxNode(const QVariant& Id) : STreeNode(Id) { inUse = -1; boxType = -1; }
CSandBoxPtr pBox; CSandBoxPtr pBox;
int inUse; int inUse;
int boxType;
CBoxedProcessPtr pProcess; CBoxedProcessPtr pProcess;
}; };
@ -53,7 +54,29 @@ protected:
//virtual QVariant GetDefaultIcon() const; //virtual QVariant GetDefaultIcon() const;
private: private:
QIcon m_BoxEmpty; enum EBoxColors
QIcon m_BoxInUse; {
eYelow = 0,
eRed,
eGreen,
eBlue,
eCyan,
eMagenta,
eOrang,
eMaxColor,
eNormal = eYelow,
eLogApi = eRed,
eOpenLogApi = eCyan,
eOpenBox = eGreen,
// = eMagenta,
// = eOrang,
eAnonBox = eBlue
};
QMap<EBoxColors, QPair<QIcon, QIcon> > m_BoxIcons;
//QIcon m_BoxEmpty;
//QIcon m_BoxInUse;
QIcon m_ExeIcon; QIcon m_ExeIcon;
}; };

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -26,4 +26,20 @@
<file alias="Advanced">Actions/Advanced.png</file> <file alias="Advanced">Actions/Advanced.png</file>
<file alias="Service">Actions/Service.png</file> <file alias="Service">Actions/Service.png</file>
</qresource> </qresource>
<qresource prefix="/Boxes">
<file alias="Empty3">Boxes/sandbox-b-empty.png</file>
<file alias="Full3">Boxes/sandbox-b-full.png</file>
<file alias="Empty4">Boxes/sandbox-c-empty.png</file>
<file alias="Full4">Boxes/sandbox-c-full.png</file>
<file alias="Empty2">Boxes/sandbox-g-empty.png</file>
<file alias="Full2">Boxes/sandbox-g-full.png</file>
<file alias="Empty5">Boxes/sandbox-m-empty.png</file>
<file alias="Full5">Boxes/sandbox-m-full.png</file>
<file alias="Empty1">Boxes/sandbox-r-empty.png</file>
<file alias="Full1">Boxes/sandbox-r-full.png</file>
<file alias="Empty0">Boxes/sandbox-y-empty.png</file>
<file alias="Full0">Boxes/sandbox-y-full.png</file>
<file alias="Empty6">Boxes/sandbox-o-empty.png</file>
<file alias="Full6">Boxes/sandbox-o-full.png</file>
</qresource>
</RCC> </RCC>

View File

@ -10,7 +10,7 @@
#include "./Dialogs/MultiErrorDialog.h" #include "./Dialogs/MultiErrorDialog.h"
#include "../QSbieAPI/SbieUtils.h" #include "../QSbieAPI/SbieUtils.h"
CSbieAPI* theAPI = NULL; CSbiePlusAPI* theAPI = NULL;
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
#include <wtypes.h> #include <wtypes.h>
@ -67,6 +67,8 @@ public:
HWND MainWndHandle = NULL; HWND MainWndHandle = NULL;
#endif #endif
CSandMan* theGUI = NULL;
CSandMan::CSandMan(QWidget *parent) CSandMan::CSandMan(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
{ {
@ -76,9 +78,11 @@ CSandMan::CSandMan(QWidget *parent)
QApplication::instance()->installNativeEventFilter(new CNativeEventFilter); QApplication::instance()->installNativeEventFilter(new CNativeEventFilter);
#endif #endif
theGUI = this;
m_bExit = false; m_bExit = false;
theAPI = new CSbieAPI(this); theAPI = new CSbiePlusAPI(this);
connect(theAPI, SIGNAL(StatusChanged()), this, SLOT(OnStatusChanged())); connect(theAPI, SIGNAL(StatusChanged()), this, SLOT(OnStatusChanged()));
QString appTitle = tr("Sandboxie-Plus v%1").arg(GetVersion()); QString appTitle = tr("Sandboxie-Plus v%1").arg(GetVersion());
@ -327,23 +331,25 @@ CSandMan::CSandMan(QWidget *parent)
m_pPanelSplitter->restoreState(theConf->GetBlob("MainWindow/Panel_Splitter")); m_pPanelSplitter->restoreState(theConf->GetBlob("MainWindow/Panel_Splitter"));
m_pLogTabs->setCurrentIndex(theConf->GetInt("GUI/LogTab", 0)); m_pLogTabs->setCurrentIndex(theConf->GetInt("GUI/LogTab", 0));
if (theConf->GetBool("Options/NoStatusBar", false))
statusBar()->hide();
else if (theConf->GetBool("Options/NoSizeGrip", false))
statusBar()->setSizeGripEnabled(false);
bool bIsMonitoring = theAPI->IsMonitoring(); bool bIsMonitoring = theAPI->IsMonitoring();
m_pResourceLog->setEnabled(bIsMonitoring); m_pResourceLog->setEnabled(bIsMonitoring);
m_pEnableMonitoring->setChecked(bIsMonitoring); m_pEnableMonitoring->setChecked(bIsMonitoring);
m_pKeepTerminated->setChecked(theConf->GetBool("Options/pKeepTerminated")); m_pKeepTerminated->setChecked(theConf->GetBool("Options/KeepTerminated"));
m_pProgressDialog = new CProgressDialog("Maintenance operation progress...", this);
m_pProgressDialog->setWindowModality(Qt::ApplicationModal);
connect(theAPI, SIGNAL(LogMessage(const QString&)), this, SLOT(OnLogMessage(const QString&))); connect(theAPI, SIGNAL(LogMessage(const QString&)), this, SLOT(OnLogMessage(const QString&)));
if (CSbieUtils::IsRunning(CSbieUtils::eAll) || theConf->GetBool("Options/StartIfStopped", true)) if (CSbieUtils::IsRunning(CSbieUtils::eAll) || theConf->GetBool("Options/StartIfStopped", true))
ConnectSbie(); ConnectSbie();
if (theConf->GetBool("Options/WatchIni", true))
theAPI->WatchIni();
m_uTimerID = startTimer(250); m_uTimerID = startTimer(250);
} }
@ -366,6 +372,8 @@ CSandMan::~CSandMan()
theConf->SetValue("GUI/LogTab", m_pLogTabs->currentIndex()); theConf->SetValue("GUI/LogTab", m_pLogTabs->currentIndex());
theAPI = NULL; theAPI = NULL;
theGUI = NULL;
} }
void CSandMan::OnExit() void CSandMan::OnExit()
@ -457,6 +465,7 @@ void CSandMan::OnMessage(const QString& Message)
if (m_bConnectPending) if (m_bConnectPending)
theAPI->Connect(true); theAPI->Connect(true);
} }
m_pProgressDialog->hide();
m_bConnectPending = false; m_bConnectPending = false;
m_bStopPending = false; m_bStopPending = false;
} }
@ -536,10 +545,15 @@ void CSandMan::OnStatusChanged()
OnLogMessage(tr("Sbie Directory: %1").arg(theAPI->GetSbiePath())); OnLogMessage(tr("Sbie Directory: %1").arg(theAPI->GetSbiePath()));
OnLogMessage(tr("Loaded Config: %1").arg(theAPI->GetIniPath())); OnLogMessage(tr("Loaded Config: %1").arg(theAPI->GetIniPath()));
if (theConf->GetBool("Options/WatchIni", true))
theAPI->WatchIni(true);
} }
else else
{ {
appTitle.append(tr(" - Driver NOT connected").arg(theAPI->GetVersion())); appTitle.append(tr(" - Driver NOT connected").arg(theAPI->GetVersion()));
theAPI->WatchIni(false);
} }
this->setWindowTitle(appTitle); this->setWindowTitle(appTitle);
} }
@ -716,6 +730,7 @@ void CSandMan::OnMaintenance()
if (Status.GetStatus() == OP_ASYNC) { if (Status.GetStatus() == OP_ASYNC) {
statusBar()->showMessage(tr("Executing maintenance operation, please wait...")); statusBar()->showMessage(tr("Executing maintenance operation, please wait..."));
m_pProgressDialog->show();
return; return;
} }
@ -739,7 +754,7 @@ void CSandMan::OnCleanUp()
void CSandMan::OnSetKeep() void CSandMan::OnSetKeep()
{ {
theConf->SetValue("Options/pKeepTerminated", m_pKeepTerminated->isChecked()); theConf->SetValue("Options/KeepTerminated", m_pKeepTerminated->isChecked());
} }
void CSandMan::OnEditIni() void CSandMan::OnEditIni()

View File

@ -5,15 +5,17 @@
#include "../MiscHelpers/Common/Settings.h" #include "../MiscHelpers/Common/Settings.h"
#include "../MiscHelpers/Common/TreeViewEx.h" #include "../MiscHelpers/Common/TreeViewEx.h"
#include "../MiscHelpers/Common/PanelView.h" #include "../MiscHelpers/Common/PanelView.h"
#include "../MiscHelpers/Common/ProgressDialog.h"
#include "Models/ResMonModel.h" #include "Models/ResMonModel.h"
#define VERSION_MJR 0 #define VERSION_MJR 0
#define VERSION_MIN 2 #define VERSION_MIN 2
#define VERSION_REV 0 #define VERSION_REV 1
#define VERSION_UPD 0 #define VERSION_UPD 0
#include "../QSbieAPI/SbieAPI.h" //#include "../QSbieAPI/SbieAPI.h"
#include "SbiePlusAPI.h"
class CSbieView; class CSbieView;
class CApiLog; class CApiLog;
@ -26,6 +28,8 @@ public:
CSandMan(QWidget *parent = Q_NULLPTR); CSandMan(QWidget *parent = Q_NULLPTR);
virtual ~CSandMan(); virtual ~CSandMan();
CProgressDialog* GetProgressDialog() { return m_pProgressDialog; }
static QString GetVersion(); static QString GetVersion();
static void CheckResults(QList<SB_STATUS> Results); static void CheckResults(QList<SB_STATUS> Results);
@ -145,4 +149,8 @@ private:
bool m_bIconEmpty; bool m_bIconEmpty;
bool m_bExit; bool m_bExit;
CProgressDialog* m_pProgressDialog;
}; };
extern CSandMan* theGUI;

View File

@ -197,6 +197,7 @@
<ClCompile Include="Models\ResMonModel.cpp" /> <ClCompile Include="Models\ResMonModel.cpp" />
<ClCompile Include="Models\SbieModel.cpp" /> <ClCompile Include="Models\SbieModel.cpp" />
<ClCompile Include="SandMan.cpp" /> <ClCompile Include="SandMan.cpp" />
<ClCompile Include="SbiePlusAPI.cpp" />
<ClCompile Include="stdafx.cpp"> <ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
@ -213,6 +214,7 @@
<QtMoc Include="ApiLog.h" /> <QtMoc Include="ApiLog.h" />
<QtMoc Include="Dialogs\MultiErrorDialog.h" /> <QtMoc Include="Dialogs\MultiErrorDialog.h" />
<ClInclude Include="Resources\resource.h" /> <ClInclude Include="Resources\resource.h" />
<QtMoc Include="SbiePlusAPI.h" />
<ClInclude Include="stdafx.h" /> <ClInclude Include="stdafx.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -61,6 +61,9 @@
<ClCompile Include="Dialogs\MultiErrorDialog.cpp"> <ClCompile Include="Dialogs\MultiErrorDialog.cpp">
<Filter>Dialogs</Filter> <Filter>Dialogs</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="SbiePlusAPI.cpp">
<Filter>SandMan</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="stdafx.h"> <ClInclude Include="stdafx.h">
@ -89,6 +92,9 @@
<QtMoc Include="Dialogs\MultiErrorDialog.h"> <QtMoc Include="Dialogs\MultiErrorDialog.h">
<Filter>Dialogs</Filter> <Filter>Dialogs</Filter>
</QtMoc> </QtMoc>
<QtMoc Include="SbiePlusAPI.h">
<Filter>SandMan</Filter>
</QtMoc>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtRcc Include="Resources\SandMan.qrc"> <QtRcc Include="Resources\SandMan.qrc">

View File

@ -0,0 +1,47 @@
#include "stdafx.h"
#include "SbiePlusAPI.h"
CSbiePlusAPI::CSbiePlusAPI(QObject* parent) : CSbieAPI(parent)
{
}
CSbiePlusAPI::~CSbiePlusAPI()
{
}
CSandBox* CSbiePlusAPI::NewSandBox(const QString& BoxName, class CSbieAPI* pAPI)
{
return new CSandBoxPlus(BoxName, pAPI);
}
CBoxedProcess* CSbiePlusAPI::NewBoxedProcess(quint64 ProcessId, class CSandBox* pBox)
{
return new CBoxedProcess(ProcessId, pBox);
}
///////////////////////////////////////////////////////////////////////////////
// CSandBox
//
CSandBoxPlus::CSandBoxPlus(const QString& BoxName, class CSbieAPI* pAPI) : CSandBox(BoxName, pAPI)
{
m_bLogApiFound = false;
m_bIsOpenBox = false;
}
CSandBoxPlus::~CSandBoxPlus()
{
}
void CSandBoxPlus::UpdateDetails()
{
QStringList List = GetTextList("OpenPipePath");
m_bLogApiFound = List.contains("\\Device\\NamedPipe\\LogAPI");
m_bIsOpenBox = GetBool("OpenToken") || GetBool("UnrestrictedToken") || GetBool("UnfilteredToken") || GetBool("OriginalToken");
CSandBox::UpdateDetails();
}

View File

@ -0,0 +1,40 @@
#pragma once
#include "../QSbieAPI/SbieAPI.h"
class CSbiePlusAPI : public CSbieAPI
{
Q_OBJECT
public:
CSbiePlusAPI(QObject* parent);
virtual ~CSbiePlusAPI();
protected:
virtual CSandBox* NewSandBox(const QString& BoxName, class CSbieAPI* pAPI);
virtual CBoxedProcess* NewBoxedProcess(quint64 ProcessId, class CSandBox* pBox);
};
///////////////////////////////////////////////////////////////////////////////
// CSandBox
//
class CSandBoxPlus : public CSandBox
{
Q_OBJECT
public:
CSandBoxPlus(const QString& BoxName, class CSbieAPI* pAPI);
virtual ~CSandBoxPlus();
virtual void UpdateDetails();
virtual bool HasLogApi() const { return m_bLogApiFound; }
virtual bool IsOpenBox() const { return m_bIsOpenBox; }
protected:
bool m_bLogApiFound;
bool m_bIsOpenBox;
};

View File

@ -168,8 +168,15 @@ void CSbieView::OnSandBoxAction()
if (QMessageBox("Sandboxie-Plus", tr("Do you really want delete teh content of the sellected sandboxes?"), QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default | QMessageBox::Escape, QMessageBox::NoButton).exec() != QMessageBox::Yes) if (QMessageBox("Sandboxie-Plus", tr("Do you really want delete teh content of the sellected sandboxes?"), QMessageBox::Warning, QMessageBox::Yes, QMessageBox::No | QMessageBox::Default | QMessageBox::Escape, QMessageBox::NoButton).exec() != QMessageBox::Yes)
return; return;
theGUI->GetProgressDialog()->show();
m_BoxesToClean = 0;
foreach(const CSandBoxPtr& pBox, SandBoxes) foreach(const CSandBoxPtr& pBox, SandBoxes)
{
m_BoxesToClean++;
Results.append(pBox->CleanBox()); Results.append(pBox->CleanBox());
connect(pBox.data(), SIGNAL(BoxCleaned()), this, SLOT(OnBoxCleaned()));
}
} }
else if (Action == m_pMenuEmptyBox) else if (Action == m_pMenuEmptyBox)
{ {
@ -180,6 +187,14 @@ void CSbieView::OnSandBoxAction()
CSandMan::CheckResults(Results); CSandMan::CheckResults(Results);
} }
void CSbieView::OnBoxCleaned()
{
disconnect(sender(), SIGNAL(BoxCleaned()), this, SLOT(OnBoxCleaned()));
if(--m_BoxesToClean <= 0)
theGUI->GetProgressDialog()->hide();
}
void CSbieView::OnProcessAction() void CSbieView::OnProcessAction()
{ {
QList<SB_STATUS> Results; QList<SB_STATUS> Results;

View File

@ -24,6 +24,8 @@ private slots:
void OnSandBoxAction(); void OnSandBoxAction();
void OnProcessAction(); void OnProcessAction();
void OnBoxCleaned();
protected: protected:
virtual void OnMenu(const QPoint& Point); virtual void OnMenu(const QPoint& Point);
virtual QTreeView* GetView() { return m_pSbieTree; } virtual QTreeView* GetView() { return m_pSbieTree; }
@ -52,4 +54,6 @@ private:
QAction* m_pMenuSuspend; QAction* m_pMenuSuspend;
QAction* m_pMenuResume; QAction* m_pMenuResume;
int m_iMenuProc; int m_iMenuProc;
int m_BoxesToClean;
}; };

View File

@ -4,13 +4,33 @@
#include "../QSbieAPI/SbieAPI.h" #include "../QSbieAPI/SbieAPI.h"
#include "../QtSingleApp/src/qtsingleapplication.h" #include "../QtSingleApp/src/qtsingleapplication.h"
#include "../QSbieAPI/SbieUtils.h" #include "../QSbieAPI/SbieUtils.h"
#include "../MiscHelpers/Common/qRC4.h"
#include "../MiscHelpers/Common/Common.h"
#include <windows.h>
CSettings* theConf = NULL; CSettings* theConf = NULL;
void PackDriver();
void UnPackDrivers();
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#ifdef Q_OS_WIN
SetProcessDPIAware();
#endif // Q_OS_WIN
//QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
//QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
QtSingleApplication app(argc, argv); QtSingleApplication app(argc, argv);
//InitConsole(false);
if (app.arguments().contains("-rc4"))
{
PackDriver();
return 0;
}
SB_STATUS Status = CSbieUtils::DoAssist(); SB_STATUS Status = CSbieUtils::DoAssist();
if (Status.GetStatus()) { if (Status.GetStatus()) {
app.sendMessage("Status:" + Status.GetText()); app.sendMessage("Status:" + Status.GetText());
@ -22,6 +42,8 @@ int main(int argc, char *argv[])
theConf = new CSettings("Sandboxie-Plus"); theConf = new CSettings("Sandboxie-Plus");
UnPackDrivers();
//QThreadPool::globalInstance()->setMaxThreadCount(theConf->GetInt("Options/MaxThreadPool", 10)); //QThreadPool::globalInstance()->setMaxThreadCount(theConf->GetInt("Options/MaxThreadPool", 10));
CSandMan* pWnd = new CSandMan(); CSandMan* pWnd = new CSandMan();
@ -38,3 +60,118 @@ int main(int argc, char *argv[])
return ret; return ret;
} }
bool TransformFile(const QString& InName, const QString& OutName, const QString& Key = "default_key")
{
QFile InFile(InName);
QFile OutFile(OutName);
if (InFile.open(QIODevice::ReadOnly))
{
if (OutFile.open(QIODevice::WriteOnly))
{
rc4_sbox_s sbox;
rc4_init(&sbox, Key.toLatin1());
OutFile.write(rc4_transform(&sbox, InFile.readAll()));
OutFile.flush();
return true;
}
}
return false;
}
bool TestFile(const QString& OutName)
{
QThread::sleep(3);
return QFile::exists(OutName);
}
void PackDriver()
{
int pos = QCoreApplication::arguments().indexOf("-rc4");
QString InName = QCoreApplication::arguments().at(pos + 1);
QString OutName = InName;
if (OutName.right(4) == ".rc4")
OutName.truncate(OutName.length() - 4);
else
OutName.append(".rc4");
if (TransformFile(InName, OutName))
printf("success\r\n");
else
printf("failed\r\n");
}
bool NotifyCert()
{
QString Caption = QObject::tr(
"<h3>Important Notie</h3>"
);
QString Text = QObject::tr(
"<p>Sandboxie requires a driver to operate (SbieDrv.sys), Windows however denies loading a driver file that has not been digitally signed using an expensive <b>EV-Code Signing Certificate</b>. "
"Such certificates cost upwards of 1000$ per year!</p>"
"<p>Luckily brave hackers have Leaked a few of these Certificates over the years, one of them was found by the author of this software and put to good use.</p>"
"<p>Unfortunately, such certificates have been abused by malware authors resulting in many Anti Malware Fools being Lazy and flagging Everything signed with them Wrongfully as Malware. "
"This Prejudice is Damaging the Open Source Ecosystem as most nonprofit developers can't afford to waste this kind of money every year only to pay that <u>Windows Kernel \"Tax\"</u>.</p>"
"<p>Therefore, the required driver is provided in an obfuscated form and before use must be unpacked. "
"<font color='red'>When doing so said said Anti Virus Ass's will complain and attempt to destroy the freshly created file.</font> "
"Please be aware that this is a <u>false positive</u> caused by the necessary use of a compromitted certificate. "
"If this happens you will be notified and offered the option to repeat the unpacking operation, for the operation to succeed you will need to <u>configure an aproproate exemption</u>.</p>"
"<p></p>"
"<p><b>If you want the project to obtain a genuine EV-Code Signing Certificate please visit the <a href=\"https://xanasoft.com/\">Homepage</a> <font color='red'>and please donate</font></b>.</p>"
"<p></p>"
"<p>If you want to proceed with the unpacking of the driver pres YES.</p>"
);
QMessageBox *msgBox = new QMessageBox(NULL);
msgBox->setAttribute(Qt::WA_DeleteOnClose);
msgBox->setWindowTitle("Sandboxie-Plus");
msgBox->setText(Caption);
msgBox->setInformativeText(Text);
msgBox->setStandardButtons(QMessageBox::Yes);
msgBox->addButton(QMessageBox::No);
msgBox->setDefaultButton(QMessageBox::Yes);
QIcon ico(QLatin1String(":/SandMan.png"));
msgBox->setIconPixmap(ico.pixmap(64, 64));
return msgBox->exec() == QMessageBox::Yes;
}
void UnPackDrivers()
{
bool notifyNotOk = false;
QDir appDir(QApplication::applicationDirPath());
foreach(const QString& FileName, appDir.entryList(QStringList("*.sys.rc4"), QDir::Files))
{
QString InName = QApplication::applicationDirPath() + "/" + FileName;
QString OutName = InName.mid(0, InName.length() - 4);
QFileInfo InInfo(InName);
QFileInfo OutInfo(OutName);
if (InInfo.size() != OutInfo.size() || InInfo.lastModified() > OutInfo.lastModified())
{
if (theConf->GetBool("Options/NotifyUnPack", true)) {
if (!NotifyCert()) {
notifyNotOk = true;
break;
}
theConf->SetValue("Options/NotifyUnPack", false);
}
retry:
if (!TransformFile(InName, OutName))
QMessageBox::warning(NULL, "Sandboxie-Plus", QObject::tr("Failed to decrypt %1 ensure app directory is writable.").arg(FileName));
else if (!TestFile(OutName))
{
if (QMessageBox("Sandboxie-Plus",
QObject::tr("The decrypted file %1 seam to have been removed. Retry file extraction?").arg(FileName),
QMessageBox::Information, QMessageBox::Yes | QMessageBox::Default, QMessageBox::Cancel, QMessageBox::NoButton).exec() == QMessageBox::Yes)
goto retry;
notifyNotOk = true;
}
}
}
if (notifyNotOk)
QMessageBox::warning(NULL, "Sandboxie-Plus", QObject::tr("Without the Driver Sandboxie-Plus wont be able to run properly."));
}

View File

@ -133,4 +133,4 @@ using namespace std;
#define USE_QEXTWIDGETS #define USE_QEXTWIDGETS
extern class CSettings* theConf; extern class CSettings* theConf;
extern class CSbieAPI* theAPI; extern class CSbiePlusAPI* theAPI;