Skip to content

Commit

Permalink
1.13.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidXanatos committed Feb 20, 2024
1 parent d4bf085 commit 010d878
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- added missing checkbox for API tracing
- fixed incompatibility with Windows ARM64 Insider build 26052 and later
- fixed [1.12.6] Symlink and open path issue [#3537](https://github.com/sandboxie-plus/Sandboxie/issues/3537)

### Changed
- changed DynData format to add flags
Expand Down
74 changes: 62 additions & 12 deletions Sandboxie/core/dll/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -2692,6 +2692,12 @@ _FX NTSTATUS File_NtCreateFileImpl(
}
}

if (Dll_ApiTrace) {
WCHAR trace_str[2048];
ULONG len = Sbie_snwprintf(trace_str, 2048, L"File_NtCreateFileImpl %s DesiredAccess=0x%08X CreateDisposition=0x%08X CreateOptions=0x%08X", TruePath, DesiredAccess, CreateDisposition, CreateOptions);
SbieApi_MonitorPut2Ex(MONITOR_APICALL | MONITOR_TRACE, len, trace_str, FALSE, FALSE);
}

SkipOriginalTry = (status == STATUS_BAD_INITIAL_PC);

//if ( (wcsstr(TruePath, L"Harddisk0\\DR0") != 0) || wcsstr(TruePath, L"HarddiskVolume3") != 0) {
Expand Down Expand Up @@ -3833,6 +3839,12 @@ _FX NTSTATUS File_NtCreateFileImpl(
status = GetExceptionCode();
}

if (Dll_ApiTrace) {
WCHAR trace_str[2048];
ULONG len = Sbie_snwprintf(trace_str, 2048, L"File_NtCreateFileImpl status = 0x%08X", status);
SbieApi_MonitorPut2Ex(MONITOR_APICALL | MONITOR_TRACE, len, trace_str, FALSE, FALSE);
}

SetLastError(LastError);
return status;
}
Expand Down Expand Up @@ -5047,6 +5059,12 @@ _FX NTSTATUS File_NtQueryFullAttributesFileImpl(
ObjectAttributes->RootDirectory, ObjectAttributes->ObjectName,
&TruePath, &CopyPath, &FileFlags);

if (Dll_ApiTrace) {
WCHAR trace_str[2048];
ULONG len = Sbie_snwprintf(trace_str, 2048, L"File_NtQueryFullAttributesFileImpl %s", TruePath);
SbieApi_MonitorPut2Ex(MONITOR_APICALL | MONITOR_TRACE, len, trace_str, FALSE, FALSE);
}

if (! NT_SUCCESS(status)) {

if (status == STATUS_BAD_INITIAL_PC) {
Expand Down Expand Up @@ -5243,6 +5261,12 @@ _FX NTSTATUS File_NtQueryFullAttributesFileImpl(
status = STATUS_OBJECT_NAME_INVALID;
}

if (Dll_ApiTrace) {
WCHAR trace_str[2048];
ULONG len = Sbie_snwprintf(trace_str, 2048, L"File_NtQueryFullAttributesFileImpl status = 0x%08X", status);
SbieApi_MonitorPut2Ex(MONITOR_APICALL | MONITOR_TRACE, len, trace_str, FALSE, FALSE);
}

Dll_PopTlsNameBuffer(TlsData);
SetLastError(LastError);
return status;
Expand Down Expand Up @@ -5563,6 +5587,12 @@ _FX ULONG File_GetFinalPathNameByHandleW(
err = GetLastError();
}

if (Dll_ApiTrace) {
WCHAR trace_str[2048];
ULONG len = Sbie_snwprintf(trace_str, 2048, L"File_GetFinalPathNameByHandleW %s", lpszFilePath);
SbieApi_MonitorPut2Ex(MONITOR_APICALL | MONITOR_TRACE, len, trace_str, FALSE, FALSE);
}

SetLastError(err);
return rc;
}
Expand All @@ -5578,11 +5608,11 @@ _FX WCHAR *File_GetFinalPathNameByHandleW_2(WCHAR *TruePath, ULONG dwFlags)
static const WCHAR *_DosPrefix = L"\\\\?\\UNC\\";
const FILE_DRIVE *file_drive;
const FILE_LINK *file_link;
const WCHAR *suffix;
const WCHAR *suffix, *suffix2;
WCHAR *path;
WCHAR *ReparsedPath;
ULONG TruePath_len;
ULONG suffix_len;
ULONG suffix_len, suffix2_len;
WCHAR drive_letter;
BOOLEAN AddBackslash;

Expand Down Expand Up @@ -5679,6 +5709,7 @@ _FX WCHAR *File_GetFinalPathNameByHandleW_2(WCHAR *TruePath, ULONG dwFlags)
ReparsedPath = NULL;
AddBackslash = FALSE;
drive_letter = 0;
suffix2 = NULL;

file_link = File_FindPermLinksForMatchPath(TruePath, TruePath_len);
if (file_link) {
Expand Down Expand Up @@ -5728,18 +5759,33 @@ _FX WCHAR *File_GetFinalPathNameByHandleW_2(WCHAR *TruePath, ULONG dwFlags)

file_drive = File_GetDriveForPath(TruePath, TruePath_len);
if (! file_drive) {
// release lock by File_FindPermLinksForMatchPath
LeaveCriticalSection(File_DrivesAndLinks_CritSec);
SetLastError(ERROR_PATH_NOT_FOUND);
return NULL;
}

drive_letter = file_drive->letter;
suffix = TruePath + file_drive->len;
file_drive = File_GetDriveForPath(file_link->src, file_link->src_len);
if (!file_drive) {

// release lock by File_GetDriveForPath
LeaveCriticalSection(File_DrivesAndLinks_CritSec);
// release lock by File_FindPermLinksForMatchPath
LeaveCriticalSection(File_DrivesAndLinks_CritSec);
SetLastError(ERROR_PATH_NOT_FOUND);
return NULL;
}
else
{
drive_letter = file_drive->letter;
suffix = file_link->src + file_drive->len;
suffix2 = TruePath + file_link->dst_len;

// release lock by File_GetDriveForPath
LeaveCriticalSection(File_DrivesAndLinks_CritSec);
}
}
else
{
drive_letter = file_drive->letter;
suffix = TruePath + file_drive->len;

// release lock by File_GetDriveForPath
LeaveCriticalSection(File_DrivesAndLinks_CritSec);
}
}

// release lock by File_FindPermLinksForMatchPath
Expand Down Expand Up @@ -5785,11 +5831,15 @@ _FX WCHAR *File_GetFinalPathNameByHandleW_2(WCHAR *TruePath, ULONG dwFlags)
} else { // VOLUME_NAME_DOS

suffix_len = wcslen(suffix);
path = Dll_AllocTemp((suffix_len + 16) * sizeof(WCHAR));
suffix2_len = suffix2 ? wcslen(suffix2) : 0;
path = Dll_AllocTemp((suffix_len + suffix2_len + 16) * sizeof(WCHAR));
wmemcpy(path, _DosPrefix, 4);
path[4] = drive_letter;
path[5] = L':';
wmemcpy(path + 6, suffix, suffix_len + 1);
if (suffix2)
wcscat(path, suffix2);

}

if (AddBackslash)
Expand Down
15 changes: 14 additions & 1 deletion Sandboxie/core/dll/file_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ _FX FILE_LINK *File_FindPermLinksForMatchPath(
link = List_Head(File_PermLinks);
while (link) {

const ULONG src_len = link->src_len;
/*const ULONG src_len = link->src_len;
if (
#ifdef WOW64_FS_REDIR
Expand All @@ -1338,6 +1338,19 @@ _FX FILE_LINK *File_FindPermLinksForMatchPath(
(name[src_len] == L'\\' || name[src_len] == L'\0') &&
_wcsnicmp(name, link->src, src_len) == 0) {
return link;
}*/

const ULONG dst_len = link->dst_len;

if (
#ifdef WOW64_FS_REDIR
link != File_Wow64FileLink &&
#endif WOW64_FS_REDIR
name_len >= dst_len &&
(name[dst_len] == L'\\' || name[dst_len] == L'\0') &&
_wcsnicmp(name, link->dst, dst_len) == 0) {

return link;
}

Expand Down

0 comments on commit 010d878

Please sign in to comment.