From 8399c6ad652faa1f374d5ed677d7819f1edb0562 Mon Sep 17 00:00:00 2001 From: DavidXanatos <3890945+DavidXanatos@users.noreply.github.com> Date: Mon, 8 May 2023 09:39:27 +0200 Subject: [PATCH] 1.9.3 --- CHANGELOG.md | 7 ++ Sandboxie/core/drv/conf.c | 101 +++++++++++++++++---------- Sandboxie/core/svc/sbieiniserver.cpp | 9 ++- 3 files changed, 80 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e4f19c4..bdc8655d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added - added setting to disable overlay icons +- added ability to specify sandboxie.ini location in registry + - open "HKLM\SYSTEM\CurrentControlSet\Services\SbieDrv" and set "IniPath" + - use a for the path like "\??\C:\my_path\my_sandboxie.ini" + +### Changed +- improved hadling of dll injection failure ### Fixed - fixed issue with command lines [#2858](https://github.com/sandboxie-plus/Sandboxie/issues/2858) @@ -16,6 +22,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). + ## [1.9.2 / 5.64.2] - 2023-04-24 ### Added diff --git a/Sandboxie/core/drv/conf.c b/Sandboxie/core/drv/conf.c index 722ca538..89e81820 100644 --- a/Sandboxie/core/drv/conf.c +++ b/Sandboxie/core/drv/conf.c @@ -1,6 +1,6 @@ /* * Copyright 2004-2020 Sandboxie Holdings, LLC - * Copyright 2020-2021 David Xanatos, xanasoft.com + * Copyright 2020-2023 David Xanatos, xanasoft.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -64,7 +64,8 @@ typedef struct _CONF_DATA { #ifdef USE_CONF_MAP HASH_MAP sections_map; #endif - BOOLEAN home; // TRUE if configuration read from Driver_Home_Path + ULONG home; // 1 if configuration read from Driver_Home_Path + WCHAR* path; ULONG encoding; // 0 - unicode, 1 - utf8, 2 - unicode (byte swapped) volatile ULONG use_count; @@ -203,7 +204,7 @@ _FX NTSTATUS Conf_Read(ULONG session_id) WCHAR linenum_str[32]; ULONG path_len; WCHAR *path = NULL; - BOOLEAN path_home; + ULONG path_home; STREAM *stream = NULL; POOL *pool; @@ -212,29 +213,59 @@ _FX NTSTATUS Conf_Read(ULONG session_id) // or (Home Path)\Sandboxie.ini // - path_len = 32; // room for \SystemRoot - if (path_len < wcslen(Driver_HomePathDos) * sizeof(WCHAR)) - path_len = wcslen(Driver_HomePathDos) * sizeof(WCHAR); - path_len += 64; // room for \Sandboxie.ini + path_len = 260 * sizeof(WCHAR); + //path_len = 32; // room for \SystemRoot + if (path_len < wcslen(Driver_HomePathDos) * sizeof(WCHAR) + 64) + path_len = wcslen(Driver_HomePathDos) * sizeof(WCHAR) + 64; + //path_len += 64; // room for \Sandboxie.ini + - path = ExAllocatePoolWithTag(PagedPool, path_len, tzuk); - if (! path) + pool = Pool_Create(); + if (! pool) return STATUS_INSUFFICIENT_RESOURCES; + path = Mem_Alloc(pool, path_len); + if (! path) { + Pool_Delete(pool); + return STATUS_INSUFFICIENT_RESOURCES; + } + + // + // try open a custom configuration file, if set + // + + UNICODE_STRING IniPath = { 0, (USHORT)path_len - (4 * sizeof(WCHAR)), path }; + status = GetRegString(RTL_REGISTRY_ABSOLUTE, Driver_RegistryPath, L"IniPath", &IniPath); + if (NT_SUCCESS(status)) { + + if (path[0] != L'\\') { + wmemmove(path + 4, path, (IniPath.Length / sizeof(WCHAR)) + 1); + wmemcpy(path, L"\\??\\", 4); + } + + path_home = 2; + status = Stream_Open( + &stream, path, + FILE_GENERIC_READ, 0, FILE_SHARE_READ, FILE_OPEN, 0); + } + // // open the configuration file, try both places, home first // - path_home = TRUE; // = FALSE; - RtlStringCbPrintfW(path, path_len, path_sandboxie, Driver_HomePathDos); // , SystemRoot); + if (!NT_SUCCESS(status)) { - status = Stream_Open( - &stream, path, FILE_GENERIC_READ, 0, FILE_SHARE_READ, FILE_OPEN, 0); + path_home = 1; + RtlStringCbPrintfW(path, path_len, path_sandboxie, Driver_HomePathDos); + + status = Stream_Open( + &stream, path, FILE_GENERIC_READ, 0, FILE_SHARE_READ, FILE_OPEN, 0); + } if (status == STATUS_OBJECT_NAME_NOT_FOUND) { - path_home = FALSE; // = TRUE; - RtlStringCbPrintfW(path, path_len, path_sandboxie, SystemRoot); // , Driver_HomePathDos); + path_home = 0; + RtlStringCbPrintfW(path, path_len, path_sandboxie, SystemRoot); status = Stream_Open( &stream, path, @@ -256,7 +287,7 @@ _FX NTSTATUS Conf_Read(ULONG session_id) } if (! NT_SUCCESS(status)) { - ExFreePoolWithTag(path, tzuk); + Pool_Delete(pool); return status; } @@ -264,25 +295,23 @@ _FX NTSTATUS Conf_Read(ULONG session_id) // read data from the file // - pool = Pool_Create(); - if (! pool) - status = STATUS_INSUFFICIENT_RESOURCES; - - else { - - data.pool = pool; - List_Init(&data.sections); + data.pool = pool; + List_Init(&data.sections); #ifdef USE_CONF_MAP - map_init(&data.sections_map, data.pool); - data.sections_map.func_key_size = NULL; - data.sections_map.func_match_key = &str_map_match; - data.sections_map.func_hash_key = &str_map_hash; - map_resize(&data.sections_map, 16); // prepare some buckets for better performance + map_init(&data.sections_map, data.pool); + data.sections_map.func_key_size = NULL; + data.sections_map.func_match_key = &str_map_match; + data.sections_map.func_hash_key = &str_map_hash; + map_resize(&data.sections_map, 16); // prepare some buckets for better performance #endif - data.home = path_home; - data.use_count = 0; + data.home = path_home; + if (path_home == 2) + data.path = Mem_AllocStringEx(data.pool, path, TRUE); + else + data.path = NULL; + data.use_count = 0; - if (stream) { + if (stream) { status = Stream_Read_BOM(stream, &data.encoding); @@ -291,7 +320,6 @@ _FX NTSTATUS Conf_Read(ULONG session_id) status = Conf_Read_Sections(stream, &data, &linenum); if (status == STATUS_END_OF_FILE) status = STATUS_SUCCESS; - } } if (stream) Stream_Close(stream); @@ -370,6 +398,7 @@ _FX NTSTATUS Conf_Read(ULONG session_id) } } + Mem_Free(path, path_len); if (pool) Pool_Delete(pool); // may be either data.pool or old Conf_Data.pool @@ -399,7 +428,6 @@ _FX NTSTATUS Conf_Read(ULONG session_id) } } - ExFreePoolWithTag(path, tzuk); return status; } @@ -1225,7 +1253,8 @@ _FX const WCHAR *Conf_Get( // return "H" if configuration file was found in the Sandboxie // home directory, or "W" if it was found in Windows directory - value = (Conf_Data.home) ? Conf_H : Conf_W; + if (Conf_Data.path) value = Conf_Data.path; + else value = (Conf_Data.home) ? Conf_H : Conf_W; } else if ((!have_section) && have_setting && _wcsicmp(setting, L"IniEncoding") == 0) { @@ -1426,6 +1455,7 @@ _FX NTSTATUS Conf_Api_Reload(PROCESS *proc, ULONG64 *parms) #endif Conf_Data.home = FALSE; + Conf_Data.path = NULL; Conf_Data.encoding = 0; ExReleaseResourceLite(Conf_Lock); @@ -1664,6 +1694,7 @@ _FX BOOLEAN Conf_Init(void) #endif Conf_Data.home = FALSE; + Conf_Data.path = NULL; Conf_Data.encoding = 0; if (! Mem_GetLockResource(&Conf_Lock, TRUE)) diff --git a/Sandboxie/core/svc/sbieiniserver.cpp b/Sandboxie/core/svc/sbieiniserver.cpp index 6dbc9c88..ea9b1e13 100644 --- a/Sandboxie/core/svc/sbieiniserver.cpp +++ b/Sandboxie/core/svc/sbieiniserver.cpp @@ -2135,8 +2135,13 @@ bool SbieIniServer::GetIniPath(WCHAR **IniPath, *IsUTF8 = TRUE; } - LONG rc = SbieApi_QueryConfAsIs(NULL, L"IniLocation", 0, path, 8); - if (rc == 0 && *path == L'H') { + LONG rc = SbieApi_QueryConfAsIs(NULL, L"IniLocation", 0, path, 260 * sizeof(WCHAR)); + if (rc == 0 && *path == L'\\') { + + if (wcsnicmp(path, L"\\??\\", 4) == 0) + wmemmove(path, path + 4, wcslen(path)+1 - 4); + } + else if (rc == 0 && *path == L'H') { // // Sandboxie.ini was last read from Sandboxie home directory