diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c2c97aa..a1238934 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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/). +## [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 ### Added diff --git a/Sandboxie/apps/start/start.cpp b/Sandboxie/apps/start/start.cpp index 1375d999..e6766124 100644 --- a/Sandboxie/apps/start/start.cpp +++ b/Sandboxie/apps/start/start.cpp @@ -925,7 +925,11 @@ int Program_Start(void) expanded = MyHeapAlloc(8192 * sizeof(WCHAR)); 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); expanded[0] = L'\"'; diff --git a/Sandboxie/common/my_version.h b/Sandboxie/common/my_version.h index 5c63de2c..690c2607 100644 --- a/Sandboxie/common/my_version.h +++ b/Sandboxie/common/my_version.h @@ -22,7 +22,7 @@ #define MY_VERSION_BINARY 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 #define SBIE_INSTALLER_PATH "..\\Bin\\" diff --git a/Sandboxie/core/dll/debug.h b/Sandboxie/core/dll/debug.h index 2f34f52b..b8e6872c 100644 --- a/Sandboxie/core/dll/debug.h +++ b/Sandboxie/core/dll/debug.h @@ -37,7 +37,7 @@ #ifdef WITH_DEBUG //#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); diff --git a/Sandboxie/core/dll/gui.c b/Sandboxie/core/dll/gui.c index c26759cc..bf20269d 100644 --- a/Sandboxie/core/dll/gui.c +++ b/Sandboxie/core/dll/gui.c @@ -952,6 +952,11 @@ _FX BOOLEAN Gui_ConnectToWindowStationAndDesktop(HMODULE User32) rc = (ULONG_PTR)NtCurrentThread(); + // OpenBox1 BEGIN + if (SbieApi_QueryConfBool(NULL, L"OriginalToken", FALSE)) + rc = 0; + else + // OpenBox1 END if (__sys_NtSetInformationThread) { rc = __sys_NtSetInformationThread(NtCurrentThread(), diff --git a/Sandboxie/core/dll/ldr_init.c b/Sandboxie/core/dll/ldr_init.c index e64d72bc..6109ea84 100644 --- a/Sandboxie/core/dll/ldr_init.c +++ b/Sandboxie/core/dll/ldr_init.c @@ -181,6 +181,9 @@ _FX void Ldr_LoadInjectDlls(BOOLEAN bHostInject) WCHAR *dllname = Dll_AllocTemp(MAX_PATH * 2 * sizeof(WCHAR)); ULONG index = 0; + WCHAR *path = Dll_AllocTemp(1024 * sizeof(WCHAR)); + SbieApi_GetHomePath(NULL, 0, path, 1020); + if (!__sys_LdrLoadDll) __sys_LdrLoadDll = (P_LdrLoadDll)GetProcAddress(Dll_Ntdll, "LdrLoadDll"); @@ -196,6 +199,18 @@ _FX void Ldr_LoadInjectDlls(BOOLEAN bHostInject) 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 // 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(path); } diff --git a/Sandboxie/core/dll/proc.c b/Sandboxie/core/dll/proc.c index 12b07145..cedc074c 100644 --- a/Sandboxie/core/dll/proc.c +++ b/Sandboxie/core/dll/proc.c @@ -1106,6 +1106,9 @@ _FX BOOL Proc_CreateProcessInternalW_RS5( err = GetLastError(); } + // OpenBox1 BEGIN + if (!SbieApi_QueryConfBool(NULL, L"OriginalToken", FALSE)) + // OpenBox1 END if (ok) { // diff --git a/Sandboxie/core/dll/scm_create.c b/Sandboxie/core/dll/scm_create.c index eaeb233f..7df25cd1 100644 --- a/Sandboxie/core/dll/scm_create.c +++ b/Sandboxie/core/dll/scm_create.c @@ -1304,8 +1304,12 @@ _FX BOOL Scm_StartServiceCtrlDispatcherX( args[2] = NULL; } - if (_wcsicmp(ServiceName, Scm_MsiServer) == 0) - Scm_IsMsiServer = TRUE; + if (_wcsicmp(ServiceName, Scm_MsiServer) == 0) { + 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)) Scm_Stopped = TRUE; diff --git a/Sandboxie/core/drv/conf.c b/Sandboxie/core/drv/conf.c index 919fe10b..f19480b8 100644 --- a/Sandboxie/core/drv/conf.c +++ b/Sandboxie/core/drv/conf.c @@ -1230,7 +1230,7 @@ _FX NTSTATUS Conf_Api_Reload(PROCESS *proc, ULONG64 *parms) Conf_Data.pool = NULL; List_Init(&Conf_Data.sections); - Conf_Data.home = TRUE; // = FALSE; + Conf_Data.home = FALSE; ExReleaseResourceLite(Conf_Lock); KeLowerIrql(irql); @@ -1371,7 +1371,7 @@ _FX BOOLEAN Conf_Init(void) { Conf_Data.pool = NULL; List_Init(&Conf_Data.sections); - Conf_Data.home = TRUE; // = FALSE; + Conf_Data.home = FALSE; if (! Mem_GetLockResource(&Conf_Lock, TRUE)) return FALSE; diff --git a/Sandboxie/core/drv/key_flt.c b/Sandboxie/core/drv/key_flt.c index 8f037a1c..592ea84a 100644 --- a/Sandboxie/core/drv/key_flt.c +++ b/Sandboxie/core/drv/key_flt.c @@ -222,7 +222,6 @@ _FX NTSTATUS Key_Callback(void *Context, void *Arg1, void *Arg2) } } - if (status != STATUS_SUCCESS) return status; diff --git a/Sandboxie/core/drv/process.c b/Sandboxie/core/drv/process.c index 955f8583..e5cffa12 100644 --- a/Sandboxie/core/drv/process.c +++ b/Sandboxie/core/drv/process.c @@ -1248,8 +1248,8 @@ _FX void Process_NotifyImage( if (ok) ok = Process_Low_InitConsole(proc); - if (ok) - ok = Token_ReplacePrimary(proc); + if (ok) + ok = Token_ReplacePrimary(proc); if (ok) ok = Thread_InitProcess(proc); diff --git a/Sandboxie/core/drv/syscall_open.c b/Sandboxie/core/drv/syscall_open.c index 1dbcd27e..c3e63255 100644 --- a/Sandboxie/core/drv/syscall_open.c +++ b/Sandboxie/core/drv/syscall_open.c @@ -19,6 +19,7 @@ // Syscall Management //--------------------------------------------------------------------------- +#include "conf.h" //--------------------------------------------------------------------------- // Functions @@ -643,6 +644,9 @@ _FX NTSTATUS Syscall_DuplicateHandle_2( // 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( proc, OpenedObject, HandleInfo.GrantedAccess); } diff --git a/Sandboxie/core/drv/thread_token.c b/Sandboxie/core/drv/thread_token.c index dad9e6ef..892ad583 100644 --- a/Sandboxie/core/drv/thread_token.c +++ b/Sandboxie/core/drv/thread_token.c @@ -21,7 +21,7 @@ #include "common/my_version.h" - +#include "conf.h" //--------------------------------------------------------------------------- // Defines @@ -1243,6 +1243,9 @@ _FX NTSTATUS Thread_SetInformationThread_ImpersonationToken( MyTokenHandle, TOKEN_IMPERSONATE, *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)) { status = Thread_CheckTokenForImpersonation( diff --git a/Sandboxie/core/drv/token.c b/Sandboxie/core/drv/token.c index 9fd3274a..0466b772 100644 --- a/Sandboxie/core/drv/token.c +++ b/Sandboxie/core/drv/token.c @@ -433,6 +433,12 @@ _FX void *Token_FilterPrimary(PROCESS *proc, void *ProcessObject) 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); proc->drop_rights = @@ -775,6 +781,15 @@ _FX void *Token_Restrict( TOKEN_PRIVILEGES *privs; TOKEN_USER *user; 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); privs = Token_Query(TokenObject, TokenPrivileges, proc->box->session_id); @@ -1648,6 +1663,11 @@ _FX BOOLEAN Token_ReplacePrimary(PROCESS *proc) NTSTATUS status; 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 // diff --git a/Sandboxie/core/svc/ProcessServer.cpp b/Sandboxie/core/svc/ProcessServer.cpp index ad6a9b0c..918092c3 100644 --- a/Sandboxie/core/svc/ProcessServer.cpp +++ b/Sandboxie/core/svc/ProcessServer.cpp @@ -719,6 +719,19 @@ HANDLE ProcessServer::RunSandboxedGetToken( 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) { SetLastError(LastError); return NULL; diff --git a/Sandboxie/install/SandboxieVS.nsi b/Sandboxie/install/SandboxieVS.nsi index b5534f96..ff83f5ea 100644 --- a/Sandboxie/install/SandboxieVS.nsi +++ b/Sandboxie/install/SandboxieVS.nsi @@ -35,6 +35,7 @@ SetCompressor /SOLID /FINAL lzma !define BIN_ROOT_BASE "${SBIE_INSTALLER_PATH}" +!define SBIEDRV_SYS4 "${SBIEDRV_SYS}.rc4" !define OUTFILE_BOTH "${PRODUCT_NAME}Install.exe" !define NAME_Win32 "${PRODUCT_FULL_NAME} ${VERSION} (32-bit)" @@ -428,7 +429,7 @@ InstDir_Check_Suffix: Push -12 Pop $2 StrCpy $1 $0 "" $2 - StrCmp $1 "\${SBIEDRV_SYS}" InstDir_Suffix_Good + StrCmp $1 "\${SBIEDRV_SYS4}" InstDir_Suffix_Good Goto InstDir_ProgramFiles @@ -463,7 +464,7 @@ InstDir_Done: 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\${SBIEDLL_DLL} InstType_Upgrade @@ -967,7 +968,7 @@ WriteLoop: 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" @@ -1072,7 +1073,7 @@ Function DeleteProgramFiles Delete "$INSTDIR\${SBIEMSG_DLL}" - Delete "$INSTDIR\${SBIEDRV_SYS}" + Delete "$INSTDIR\${SBIEDRV_SYS4}" Delete "$INSTDIR\${SANDBOXIE}WUAU.exe" Delete "$INSTDIR\${SANDBOXIE}EventSys.exe" @@ -1422,7 +1423,7 @@ Driver_Silent: ; 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 Call KmdUtil diff --git a/Sandboxie/install/kmdutil/kmdutil.c b/Sandboxie/install/kmdutil/kmdutil.c index 2fb32929..3f26b412 100644 --- a/Sandboxie/install/kmdutil/kmdutil.c +++ b/Sandboxie/install/kmdutil/kmdutil.c @@ -25,6 +25,7 @@ #include #include "common/defines.h" #include "common/my_version.h" +#include "rc4.h" extern void Kmd_ScanDll(BOOLEAN silent); @@ -714,6 +715,39 @@ int __stdcall WinMain( &Options)) 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( NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CREATE_SERVICE); diff --git a/Sandboxie/install/kmdutil/kmdutil.vcxproj b/Sandboxie/install/kmdutil/kmdutil.vcxproj index d94d736c..d5d70d9f 100644 --- a/Sandboxie/install/kmdutil/kmdutil.vcxproj +++ b/Sandboxie/install/kmdutil/kmdutil.vcxproj @@ -123,6 +123,12 @@ + + NotUsing + NotUsing + NotUsing + NotUsing + @@ -133,6 +139,7 @@ + diff --git a/Sandboxie/install/kmdutil/rc4.cpp b/Sandboxie/install/kmdutil/rc4.cpp new file mode 100644 index 00000000..ad51eadb --- /dev/null +++ b/Sandboxie/install/kmdutil/rc4.cpp @@ -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; + } +} \ No newline at end of file diff --git a/Sandboxie/install/kmdutil/rc4.h b/Sandboxie/install/kmdutil/rc4.h new file mode 100644 index 00000000..cb97b1d6 --- /dev/null +++ b/Sandboxie/install/kmdutil/rc4.h @@ -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 */ diff --git a/Sandboxie/install/release/SandboxieInstall.vcxproj b/Sandboxie/install/release/SandboxieInstall.vcxproj index c52a5c41..b2a7c837 100644 --- a/Sandboxie/install/release/SandboxieInstall.vcxproj +++ b/Sandboxie/install/release/SandboxieInstall.vcxproj @@ -28,7 +28,7 @@ - ..\ + ..\..\bin\ @@ -38,7 +38,7 @@ %(AdditionalDependencies) - ..\$(TargetName)$(TargetExt) + ..\..\bin\$(TargetName)$(TargetExt) RequireAdministrator diff --git a/Sandboxie/msgs/Sbie-English-1033.txt b/Sandboxie/msgs/Sbie-English-1033.txt index d1d4e70f..3ebe665f 100644 Binary files a/Sandboxie/msgs/Sbie-English-1033.txt and b/Sandboxie/msgs/Sbie-English-1033.txt differ diff --git a/Sandboxie/msgs/Text-German-1031.txt b/Sandboxie/msgs/Text-German-1031.txt index 54e5d367..8f2ed2d4 100644 Binary files a/Sandboxie/msgs/Text-German-1031.txt and b/Sandboxie/msgs/Text-German-1031.txt differ diff --git a/SandboxiePlus/MiscHelpers/Common/Common.cpp b/SandboxiePlus/MiscHelpers/Common/Common.cpp index dfddd2c5..efa861f1 100644 --- a/SandboxiePlus/MiscHelpers/Common/Common.cpp +++ b/SandboxiePlus/MiscHelpers/Common/Common.cpp @@ -318,4 +318,27 @@ QAction* MakeAction(QActionGroup* pGroup, QMenu* pParent, const QString& Text, c pAction->setActionGroup(pGroup); pParent->addAction(pAction); return pAction; -} \ No newline at end of file +} + +////////////////////////////////////////////////////////////////////////////////////////// +// +// + +#ifdef WIN32 +#include +#include +#include + +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 \ No newline at end of file diff --git a/SandboxiePlus/MiscHelpers/Common/Common.h b/SandboxiePlus/MiscHelpers/Common/Common.h index 3cbaae45..808c845d 100644 --- a/SandboxiePlus/MiscHelpers/Common/Common.h +++ b/SandboxiePlus/MiscHelpers/Common/Common.h @@ -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(QActionGroup* pGroup, QMenu* pParent, const QString& Text, const QVariant& Data); + +#ifdef WIN32 +MISCHELPERS_EXPORT bool InitConsole(bool bCreateIfNeeded = true); +#endif \ No newline at end of file diff --git a/SandboxiePlus/MiscHelpers/Common/qRC4.cpp b/SandboxiePlus/MiscHelpers/Common/qRC4.cpp new file mode 100644 index 00000000..54da5bda --- /dev/null +++ b/SandboxiePlus/MiscHelpers/Common/qRC4.cpp @@ -0,0 +1,63 @@ +#include "stdafx.h" +#include "qRC4.h" +#include + +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; +} \ No newline at end of file diff --git a/SandboxiePlus/MiscHelpers/Common/qRC4.h b/SandboxiePlus/MiscHelpers/Common/qRC4.h new file mode 100644 index 00000000..3ddc440b --- /dev/null +++ b/SandboxiePlus/MiscHelpers/Common/qRC4.h @@ -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); \ No newline at end of file diff --git a/SandboxiePlus/MiscHelpers/MiscHelpers.vcxproj b/SandboxiePlus/MiscHelpers/MiscHelpers.vcxproj index 5c109c91..d3e878c5 100644 --- a/SandboxiePlus/MiscHelpers/MiscHelpers.vcxproj +++ b/SandboxiePlus/MiscHelpers/MiscHelpers.vcxproj @@ -186,6 +186,7 @@ + @@ -227,6 +228,7 @@ + diff --git a/SandboxiePlus/MiscHelpers/MiscHelpers.vcxproj.filters b/SandboxiePlus/MiscHelpers/MiscHelpers.vcxproj.filters index 4cecefc0..e5ea6c3b 100644 --- a/SandboxiePlus/MiscHelpers/MiscHelpers.vcxproj.filters +++ b/SandboxiePlus/MiscHelpers/MiscHelpers.vcxproj.filters @@ -87,6 +87,9 @@ Common + + Common + @@ -119,6 +122,9 @@ Common + + Common + diff --git a/SandboxiePlus/QSbieAPI/Sandboxie/BoxedProcess.cpp b/SandboxiePlus/QSbieAPI/Sandboxie/BoxedProcess.cpp index 192903e3..78bc5860 100644 --- a/SandboxiePlus/QSbieAPI/Sandboxie/BoxedProcess.cpp +++ b/SandboxiePlus/QSbieAPI/Sandboxie/BoxedProcess.cpp @@ -52,7 +52,7 @@ CBoxedProcess::~CBoxedProcess() //delete m; } -void CBoxedProcess::UpdateProcessInfo() +void CBoxedProcess::InitProcessInfo() { HANDLE ProcessHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, (DWORD)m_ProcessId); if (ProcessHandle != INVALID_HANDLE_VALUE) diff --git a/SandboxiePlus/QSbieAPI/Sandboxie/BoxedProcess.h b/SandboxiePlus/QSbieAPI/Sandboxie/BoxedProcess.h index c5761535..00566208 100644 --- a/SandboxiePlus/QSbieAPI/Sandboxie/BoxedProcess.h +++ b/SandboxiePlus/QSbieAPI/Sandboxie/BoxedProcess.h @@ -18,17 +18,18 @@ #pragma once #include +#include "../qsbieapi_global.h" #include "../SbieError.h" -class CBoxedProcess : public QObject +class QSBIEAPI_EXPORT CBoxedProcess : public QObject { Q_OBJECT public: CBoxedProcess(quint64 ProcessId, class CSandBox* pBox); virtual ~CBoxedProcess(); - virtual void UpdateProcessInfo(); + virtual void InitProcessInfo(); virtual quint64 GetProcessId() const { return m_ProcessId; } virtual quint64 GetParendPID() const { return m_ParendPID; } diff --git a/SandboxiePlus/QSbieAPI/Sandboxie/IniSection.cpp b/SandboxiePlus/QSbieAPI/Sandboxie/IniSection.cpp index cf093d8c..44034550 100644 --- a/SandboxiePlus/QSbieAPI/Sandboxie/IniSection.cpp +++ b/SandboxiePlus/QSbieAPI/Sandboxie/IniSection.cpp @@ -18,6 +18,11 @@ #include "stdafx.h" #include "IniSection.h" #include "../SbieAPI.h" + +#include +#define WIN32_NO_STATUS +typedef long NTSTATUS; + #include "..\..\Sandboxie\core\drv\api_flags.h" 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 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; return Value; } @@ -87,6 +93,25 @@ bool CIniSection::GetBool(const QString& Setting, bool Default) const 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) { 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) { 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> 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>::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, "*", ""); } \ No newline at end of file diff --git a/SandboxiePlus/QSbieAPI/Sandboxie/IniSection.h b/SandboxiePlus/QSbieAPI/Sandboxie/IniSection.h index af5d96af..bcd80c53 100644 --- a/SandboxiePlus/QSbieAPI/Sandboxie/IniSection.h +++ b/SandboxiePlus/QSbieAPI/Sandboxie/IniSection.h @@ -1,9 +1,11 @@ #pragma once #include +#include "../qsbieapi_global.h" + #include "../SbieError.h" -class CIniSection: public QObject +class QSBIEAPI_EXPORT CIniSection: public QObject { Q_OBJECT public: @@ -20,11 +22,16 @@ public: virtual __int64 GetNum64(const QString& Setting, __int64 Default = 0) 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 AppendText(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: QString m_Name; diff --git a/SandboxiePlus/QSbieAPI/Sandboxie/SandBox.cpp b/SandboxiePlus/QSbieAPI/Sandboxie/SandBox.cpp index 25454c7e..b67dd9a3 100644 --- a/SandboxiePlus/QSbieAPI/Sandboxie/SandBox.cpp +++ b/SandboxiePlus/QSbieAPI/Sandboxie/SandBox.cpp @@ -60,6 +60,10 @@ CSandBox::~CSandBox() //delete m; } +void CSandBox::UpdateDetails() +{ +} + SB_STATUS CSandBox::RunStart(const QString& Command) { return m_pAPI->RunStart(m_Name, Command); @@ -80,19 +84,26 @@ SB_STATUS CSandBox::CleanBox() SB_STATUS Status = m_pAPI->TerminateAll(m_Name); if (Status.IsError()) 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) { if (QDir(m_pAPI->Nt2DosPath(m_FilePath)).exists()) 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() { if (QDir(m_pAPI->Nt2DosPath(m_FilePath)).exists()) return SB_ERR("A sandbox must be emptied before it can be deleted."); - return m_pAPI->RemoveBox(m_Name); + return RemoveSection(); } diff --git a/SandboxiePlus/QSbieAPI/Sandboxie/SandBox.h b/SandboxiePlus/QSbieAPI/Sandboxie/SandBox.h index 0dc6bcbd..b4d55624 100644 --- a/SandboxiePlus/QSbieAPI/Sandboxie/SandBox.h +++ b/SandboxiePlus/QSbieAPI/Sandboxie/SandBox.h @@ -18,16 +18,20 @@ #pragma once #include +#include "../qsbieapi_global.h" + #include "BoxedProcess.h" #include "IniSection.h" -class CSandBox : public CIniSection +class QSBIEAPI_EXPORT CSandBox : public CIniSection { Q_OBJECT public: CSandBox(const QString& BoxName, class CSbieAPI* pAPI); virtual ~CSandBox(); + virtual void UpdateDetails(); + virtual QString GetName() const { return m_Name; } virtual QMap GetProcessList() const { return m_ProcessList; } @@ -42,6 +46,9 @@ public: class CSbieAPI* Api() { return m_pAPI; } +signals: + void BoxCleaned(); + protected: friend class CSbieAPI; diff --git a/SandboxiePlus/QSbieAPI/SbieAPI.cpp b/SandboxiePlus/QSbieAPI/SbieAPI.cpp index cb6e1d88..a006a4f2 100644 --- a/SandboxiePlus/QSbieAPI/SbieAPI.cpp +++ b/SandboxiePlus/QSbieAPI/SbieAPI.cpp @@ -122,6 +122,16 @@ CSbieAPI::~CSbieAPI() 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) { if (IsConnected()) @@ -575,7 +585,7 @@ QString CSbieAPI::GetIniPath(bool* IsHome) const 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()) 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; Arguments.append("/box:" + BoxName); 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; } -SB_STATUS CSbieAPI::ReloadBoxes() +SB_STATUS CSbieAPI::ReloadBoxes(bool bFull) { QMap OldSandBoxes = m_SandBoxes; @@ -603,11 +615,15 @@ SB_STATUS CSbieAPI::ReloadBoxes() CSandBoxPtr pBox = OldSandBoxes.take(BoxName); if (!pBox) { - pBox = CSandBoxPtr(new CSandBox(BoxName, this)); + pBox = CSandBoxPtr(NewSandBox(BoxName, this)); m_SandBoxes.insert(BoxName, pBox); SetBoxPaths(pBox); } + else if (!bFull) + continue; + + pBox->UpdateDetails(); // todo: } @@ -701,96 +717,6 @@ SB_STATUS CSbieAPI::CreateBox(const QString& BoxName) 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> 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>::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) { foreach(const CSandBoxPtr& pBox, m_SandBoxes) @@ -827,13 +753,13 @@ SB_STATUS CSbieAPI::UpdateProcesses(bool bKeep, const CSandBoxPtr& pBox) CBoxedProcessPtr pProcess = OldProcessList.take(ProcessId); if (!pProcess) { - pProcess = CBoxedProcessPtr(new CBoxedProcess(ProcessId, pBox.data())); + pProcess = CBoxedProcessPtr(NewBoxedProcess(ProcessId, pBox.data())); //pProcess->m_pBox = pBox; pBox->m_ProcessList.insert(ProcessId, pProcess); m_BoxedProxesses.insert(ProcessId, pProcess); SetProcessInfo(pProcess); - pProcess->UpdateProcessInfo(); + pProcess->InitProcessInfo(); } // todo: @@ -1194,6 +1120,9 @@ SB_STATUS CSbieAPI::ReloadConfig(quint32 SessionId) return SB_ERR(status); emit LogMessage("Sandboxie config has been reloaded."); + + ReloadBoxes(true); + return SB_OK; } diff --git a/SandboxiePlus/QSbieAPI/SbieAPI.h b/SandboxiePlus/QSbieAPI/SbieAPI.h index 83402e92..88edb4ea 100644 --- a/SandboxiePlus/QSbieAPI/SbieAPI.h +++ b/SandboxiePlus/QSbieAPI/SbieAPI.h @@ -27,7 +27,7 @@ #include "./Sandboxie/SandBox.h" #include "./Sandboxie/BoxedProcess.h" -class CResLogEntry : public QSharedData +class QSBIEAPI_EXPORT CResLogEntry : public QSharedData { public: CResLogEntry(quint64 ProcessId, quint32 Type, const QString& Value); @@ -77,7 +77,7 @@ public: virtual void UpdateDriveLetters(); 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 UpdateProcesses(bool bKeep); @@ -122,14 +122,13 @@ protected: friend class CSandBox; 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 GetIniPath(bool* IsHome) const; - virtual SB_STATUS RunStart(const QString& BoxName, const QString& Command); - - 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 SB_STATUS RunStart(const QString& BoxName, const QString& Command, QProcess* pProcess = NULL); virtual bool GetLog(); virtual bool GetMonitor(); diff --git a/SandboxiePlus/SandMan/Models/SbieModel.cpp b/SandboxiePlus/SandMan/Models/SbieModel.cpp index 8f812fd9..27d72b7f 100644 --- a/SandboxiePlus/SandMan/Models/SbieModel.cpp +++ b/SandboxiePlus/SandMan/Models/SbieModel.cpp @@ -7,8 +7,11 @@ CSbieModel::CSbieModel(QObject *parent) :CTreeItemModel(parent) { - m_BoxEmpty = QIcon(":/BoxEmpty"); - m_BoxInUse = QIcon(":/BoxInUse"); + for (int i = 0; i < eMaxColor; i++) + 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_Root = MkNode(QVariant()); @@ -91,6 +94,8 @@ QList CSbieModel::Sync(const QMap& BoxList) Index = Find(m_Root, pNode); } + CSandBoxPlus* pBoxEx = qobject_cast(pBox.data()); + int Col = 0; bool State = false; int Changed = 0; @@ -98,11 +103,16 @@ QList CSbieModel::Sync(const QMap& BoxList) QMap ProcessList = pBox->GetProcessList(); bool HasActive = Sync(pBox, ProcessList, New, Old, Added); - - if (pNode->inUse != (HasActive ? 1 : 0)) + int 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->Icon = pNode->inUse ? m_BoxInUse : m_BoxEmpty; + pNode->inUse = inUse; + 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 } @@ -115,6 +125,7 @@ QList CSbieModel::Sync(const QMap& BoxList) switch(section) { case eName: Value = pBox->GetName(); break; + case eStatus: Value = boxType; break; } SSandBoxNode::SValue& ColValue = pNode->Values[section]; @@ -125,10 +136,10 @@ QList CSbieModel::Sync(const QMap& BoxList) Changed = 1; 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)) diff --git a/SandboxiePlus/SandMan/Models/SbieModel.h b/SandboxiePlus/SandMan/Models/SbieModel.h index 66ed32c1..0640d4cf 100644 --- a/SandboxiePlus/SandMan/Models/SbieModel.h +++ b/SandboxiePlus/SandMan/Models/SbieModel.h @@ -1,6 +1,6 @@ #pragma once #include -#include "../../QSbieAPI/Sandboxie/SandBox.h" +#include "../SbiePlusAPI.h" #include "../../MiscHelpers/Common/TreeItemModel.h" @@ -36,10 +36,11 @@ protected: struct SSandBoxNode: STreeNode { - SSandBoxNode(const QVariant& Id) : STreeNode(Id) { inUse = -1; } + SSandBoxNode(const QVariant& Id) : STreeNode(Id) { inUse = -1; boxType = -1; } CSandBoxPtr pBox; int inUse; + int boxType; CBoxedProcessPtr pProcess; }; @@ -53,7 +54,29 @@ protected: //virtual QVariant GetDefaultIcon() const; private: - QIcon m_BoxEmpty; - QIcon m_BoxInUse; + enum EBoxColors + { + eYelow = 0, + eRed, + eGreen, + eBlue, + eCyan, + eMagenta, + eOrang, + eMaxColor, + + eNormal = eYelow, + eLogApi = eRed, + eOpenLogApi = eCyan, + eOpenBox = eGreen, + // = eMagenta, + // = eOrang, + eAnonBox = eBlue + }; + + QMap > m_BoxIcons; + + //QIcon m_BoxEmpty; + //QIcon m_BoxInUse; QIcon m_ExeIcon; }; \ No newline at end of file diff --git a/SandboxiePlus/SandMan/Resources/Boxes/sandbox-b-empty.png b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-b-empty.png new file mode 100644 index 00000000..5a0d03af Binary files /dev/null and b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-b-empty.png differ diff --git a/SandboxiePlus/SandMan/Resources/Boxes/sandbox-b-full.png b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-b-full.png new file mode 100644 index 00000000..e3a27335 Binary files /dev/null and b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-b-full.png differ diff --git a/SandboxiePlus/SandMan/Resources/Boxes/sandbox-c-empty.png b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-c-empty.png new file mode 100644 index 00000000..d23c6b75 Binary files /dev/null and b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-c-empty.png differ diff --git a/SandboxiePlus/SandMan/Resources/Boxes/sandbox-c-full.png b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-c-full.png new file mode 100644 index 00000000..2a60113a Binary files /dev/null and b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-c-full.png differ diff --git a/SandboxiePlus/SandMan/Resources/Boxes/sandbox-g-empty.png b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-g-empty.png new file mode 100644 index 00000000..c38c22ae Binary files /dev/null and b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-g-empty.png differ diff --git a/SandboxiePlus/SandMan/Resources/Boxes/sandbox-g-full.png b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-g-full.png new file mode 100644 index 00000000..aea1a974 Binary files /dev/null and b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-g-full.png differ diff --git a/SandboxiePlus/SandMan/Resources/Boxes/sandbox-m-empty.png b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-m-empty.png new file mode 100644 index 00000000..d7069d20 Binary files /dev/null and b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-m-empty.png differ diff --git a/SandboxiePlus/SandMan/Resources/Boxes/sandbox-m-full.png b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-m-full.png new file mode 100644 index 00000000..d132924b Binary files /dev/null and b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-m-full.png differ diff --git a/SandboxiePlus/SandMan/Resources/Boxes/sandbox-o-empty.png b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-o-empty.png new file mode 100644 index 00000000..127c3bb8 Binary files /dev/null and b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-o-empty.png differ diff --git a/SandboxiePlus/SandMan/Resources/Boxes/sandbox-o-full.png b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-o-full.png new file mode 100644 index 00000000..472626d6 Binary files /dev/null and b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-o-full.png differ diff --git a/SandboxiePlus/SandMan/Resources/Boxes/sandbox-r-empty.png b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-r-empty.png new file mode 100644 index 00000000..9b229cdf Binary files /dev/null and b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-r-empty.png differ diff --git a/SandboxiePlus/SandMan/Resources/Boxes/sandbox-r-full.png b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-r-full.png new file mode 100644 index 00000000..f5321110 Binary files /dev/null and b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-r-full.png differ diff --git a/SandboxiePlus/SandMan/Resources/Boxes/sandbox-y-empty.png b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-y-empty.png new file mode 100644 index 00000000..79301033 Binary files /dev/null and b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-y-empty.png differ diff --git a/SandboxiePlus/SandMan/Resources/Boxes/sandbox-y-full.png b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-y-full.png new file mode 100644 index 00000000..884d6a54 Binary files /dev/null and b/SandboxiePlus/SandMan/Resources/Boxes/sandbox-y-full.png differ diff --git a/SandboxiePlus/SandMan/Resources/SandMan.qrc b/SandboxiePlus/SandMan/Resources/SandMan.qrc index b52c2747..f56f6ff7 100644 --- a/SandboxiePlus/SandMan/Resources/SandMan.qrc +++ b/SandboxiePlus/SandMan/Resources/SandMan.qrc @@ -26,4 +26,20 @@ Actions/Advanced.png Actions/Service.png + + Boxes/sandbox-b-empty.png + Boxes/sandbox-b-full.png + Boxes/sandbox-c-empty.png + Boxes/sandbox-c-full.png + Boxes/sandbox-g-empty.png + Boxes/sandbox-g-full.png + Boxes/sandbox-m-empty.png + Boxes/sandbox-m-full.png + Boxes/sandbox-r-empty.png + Boxes/sandbox-r-full.png + Boxes/sandbox-y-empty.png + Boxes/sandbox-y-full.png + Boxes/sandbox-o-empty.png + Boxes/sandbox-o-full.png + diff --git a/SandboxiePlus/SandMan/SandMan.cpp b/SandboxiePlus/SandMan/SandMan.cpp index 3fe6ec6c..85f41cbc 100644 --- a/SandboxiePlus/SandMan/SandMan.cpp +++ b/SandboxiePlus/SandMan/SandMan.cpp @@ -10,7 +10,7 @@ #include "./Dialogs/MultiErrorDialog.h" #include "../QSbieAPI/SbieUtils.h" -CSbieAPI* theAPI = NULL; +CSbiePlusAPI* theAPI = NULL; #if defined(Q_OS_WIN) #include @@ -67,6 +67,8 @@ public: HWND MainWndHandle = NULL; #endif +CSandMan* theGUI = NULL; + CSandMan::CSandMan(QWidget *parent) : QMainWindow(parent) { @@ -76,9 +78,11 @@ CSandMan::CSandMan(QWidget *parent) QApplication::instance()->installNativeEventFilter(new CNativeEventFilter); #endif + theGUI = this; + m_bExit = false; - theAPI = new CSbieAPI(this); + theAPI = new CSbiePlusAPI(this); connect(theAPI, SIGNAL(StatusChanged()), this, SLOT(OnStatusChanged())); 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_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(); m_pResourceLog->setEnabled(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&))); if (CSbieUtils::IsRunning(CSbieUtils::eAll) || theConf->GetBool("Options/StartIfStopped", true)) ConnectSbie(); - if (theConf->GetBool("Options/WatchIni", true)) - theAPI->WatchIni(); - - m_uTimerID = startTimer(250); } @@ -366,6 +372,8 @@ CSandMan::~CSandMan() theConf->SetValue("GUI/LogTab", m_pLogTabs->currentIndex()); theAPI = NULL; + + theGUI = NULL; } void CSandMan::OnExit() @@ -457,6 +465,7 @@ void CSandMan::OnMessage(const QString& Message) if (m_bConnectPending) theAPI->Connect(true); } + m_pProgressDialog->hide(); m_bConnectPending = false; m_bStopPending = false; } @@ -536,10 +545,15 @@ void CSandMan::OnStatusChanged() OnLogMessage(tr("Sbie Directory: %1").arg(theAPI->GetSbiePath())); OnLogMessage(tr("Loaded Config: %1").arg(theAPI->GetIniPath())); + + if (theConf->GetBool("Options/WatchIni", true)) + theAPI->WatchIni(true); } else { appTitle.append(tr(" - Driver NOT connected").arg(theAPI->GetVersion())); + + theAPI->WatchIni(false); } this->setWindowTitle(appTitle); } @@ -716,6 +730,7 @@ void CSandMan::OnMaintenance() if (Status.GetStatus() == OP_ASYNC) { statusBar()->showMessage(tr("Executing maintenance operation, please wait...")); + m_pProgressDialog->show(); return; } @@ -739,7 +754,7 @@ void CSandMan::OnCleanUp() void CSandMan::OnSetKeep() { - theConf->SetValue("Options/pKeepTerminated", m_pKeepTerminated->isChecked()); + theConf->SetValue("Options/KeepTerminated", m_pKeepTerminated->isChecked()); } void CSandMan::OnEditIni() diff --git a/SandboxiePlus/SandMan/SandMan.h b/SandboxiePlus/SandMan/SandMan.h index dff98bfa..06fb9f66 100644 --- a/SandboxiePlus/SandMan/SandMan.h +++ b/SandboxiePlus/SandMan/SandMan.h @@ -5,15 +5,17 @@ #include "../MiscHelpers/Common/Settings.h" #include "../MiscHelpers/Common/TreeViewEx.h" #include "../MiscHelpers/Common/PanelView.h" +#include "../MiscHelpers/Common/ProgressDialog.h" #include "Models/ResMonModel.h" #define VERSION_MJR 0 #define VERSION_MIN 2 -#define VERSION_REV 0 +#define VERSION_REV 1 #define VERSION_UPD 0 -#include "../QSbieAPI/SbieAPI.h" +//#include "../QSbieAPI/SbieAPI.h" +#include "SbiePlusAPI.h" class CSbieView; class CApiLog; @@ -26,6 +28,8 @@ public: CSandMan(QWidget *parent = Q_NULLPTR); virtual ~CSandMan(); + CProgressDialog* GetProgressDialog() { return m_pProgressDialog; } + static QString GetVersion(); static void CheckResults(QList Results); @@ -145,4 +149,8 @@ private: bool m_bIconEmpty; bool m_bExit; + + CProgressDialog* m_pProgressDialog; }; + +extern CSandMan* theGUI; \ No newline at end of file diff --git a/SandboxiePlus/SandMan/SandMan.vcxproj b/SandboxiePlus/SandMan/SandMan.vcxproj index f081bead..232e5294 100644 --- a/SandboxiePlus/SandMan/SandMan.vcxproj +++ b/SandboxiePlus/SandMan/SandMan.vcxproj @@ -197,6 +197,7 @@ + Create Create @@ -213,6 +214,7 @@ + diff --git a/SandboxiePlus/SandMan/SandMan.vcxproj.filters b/SandboxiePlus/SandMan/SandMan.vcxproj.filters index 5ad8c298..a237d557 100644 --- a/SandboxiePlus/SandMan/SandMan.vcxproj.filters +++ b/SandboxiePlus/SandMan/SandMan.vcxproj.filters @@ -61,6 +61,9 @@ Dialogs + + SandMan + @@ -89,6 +92,9 @@ Dialogs + + SandMan + diff --git a/SandboxiePlus/SandMan/SbiePlusAPI.cpp b/SandboxiePlus/SandMan/SbiePlusAPI.cpp new file mode 100644 index 00000000..c9ad6893 --- /dev/null +++ b/SandboxiePlus/SandMan/SbiePlusAPI.cpp @@ -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(); +} \ No newline at end of file diff --git a/SandboxiePlus/SandMan/SbiePlusAPI.h b/SandboxiePlus/SandMan/SbiePlusAPI.h new file mode 100644 index 00000000..23a72bdf --- /dev/null +++ b/SandboxiePlus/SandMan/SbiePlusAPI.h @@ -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; + +}; \ No newline at end of file diff --git a/SandboxiePlus/SandMan/Views/SbieView.cpp b/SandboxiePlus/SandMan/Views/SbieView.cpp index 59e27176..44e45886 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.cpp +++ b/SandboxiePlus/SandMan/Views/SbieView.cpp @@ -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) return; + theGUI->GetProgressDialog()->show(); + + m_BoxesToClean = 0; foreach(const CSandBoxPtr& pBox, SandBoxes) + { + m_BoxesToClean++; Results.append(pBox->CleanBox()); + connect(pBox.data(), SIGNAL(BoxCleaned()), this, SLOT(OnBoxCleaned())); + } } else if (Action == m_pMenuEmptyBox) { @@ -180,6 +187,14 @@ void CSbieView::OnSandBoxAction() CSandMan::CheckResults(Results); } +void CSbieView::OnBoxCleaned() +{ + disconnect(sender(), SIGNAL(BoxCleaned()), this, SLOT(OnBoxCleaned())); + + if(--m_BoxesToClean <= 0) + theGUI->GetProgressDialog()->hide(); +} + void CSbieView::OnProcessAction() { QList Results; diff --git a/SandboxiePlus/SandMan/Views/SbieView.h b/SandboxiePlus/SandMan/Views/SbieView.h index bcb1b625..574fcbb1 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.h +++ b/SandboxiePlus/SandMan/Views/SbieView.h @@ -24,6 +24,8 @@ private slots: void OnSandBoxAction(); void OnProcessAction(); + void OnBoxCleaned(); + protected: virtual void OnMenu(const QPoint& Point); virtual QTreeView* GetView() { return m_pSbieTree; } @@ -52,4 +54,6 @@ private: QAction* m_pMenuSuspend; QAction* m_pMenuResume; int m_iMenuProc; + + int m_BoxesToClean; }; \ No newline at end of file diff --git a/SandboxiePlus/SandMan/main.cpp b/SandboxiePlus/SandMan/main.cpp index 388eb1c4..825baf67 100644 --- a/SandboxiePlus/SandMan/main.cpp +++ b/SandboxiePlus/SandMan/main.cpp @@ -4,13 +4,33 @@ #include "../QSbieAPI/SbieAPI.h" #include "../QtSingleApp/src/qtsingleapplication.h" #include "../QSbieAPI/SbieUtils.h" +#include "../MiscHelpers/Common/qRC4.h" +#include "../MiscHelpers/Common/Common.h" +#include CSettings* theConf = NULL; +void PackDriver(); +void UnPackDrivers(); + 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); + //InitConsole(false); + if (app.arguments().contains("-rc4")) + { + PackDriver(); + return 0; + } + SB_STATUS Status = CSbieUtils::DoAssist(); if (Status.GetStatus()) { app.sendMessage("Status:" + Status.GetText()); @@ -22,6 +42,8 @@ int main(int argc, char *argv[]) theConf = new CSettings("Sandboxie-Plus"); + UnPackDrivers(); + //QThreadPool::globalInstance()->setMaxThreadCount(theConf->GetInt("Options/MaxThreadPool", 10)); CSandMan* pWnd = new CSandMan(); @@ -38,3 +60,118 @@ int main(int argc, char *argv[]) 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( + "

Important Notie

" + ); + QString Text = QObject::tr( + "

Sandboxie requires a driver to operate (SbieDrv.sys), Windows however denies loading a driver file that has not been digitally signed using an expensive EV-Code Signing Certificate. " + "Such certificates cost upwards of 1000$ per year!

" + "

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.

" + "

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 Windows Kernel \"Tax\".

" + "

Therefore, the required driver is provided in an obfuscated form and before use must be unpacked. " + "When doing so said said Anti Virus Ass's will complain and attempt to destroy the freshly created file. " + "Please be aware that this is a false positive 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 configure an aproproate exemption.

" + + "

" + "

If you want the project to obtain a genuine EV-Code Signing Certificate please visit the Homepage and please donate.

" + "

" + + "

If you want to proceed with the unpacking of the driver pres YES.

" + ); + 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.")); +} \ No newline at end of file diff --git a/SandboxiePlus/SandMan/stdafx.h b/SandboxiePlus/SandMan/stdafx.h index 99e826a6..9a4bac2c 100644 --- a/SandboxiePlus/SandMan/stdafx.h +++ b/SandboxiePlus/SandMan/stdafx.h @@ -133,4 +133,4 @@ using namespace std; #define USE_QEXTWIDGETS extern class CSettings* theConf; -extern class CSbieAPI* theAPI; \ No newline at end of file +extern class CSbiePlusAPI* theAPI; \ No newline at end of file