This commit is contained in:
DavidXanatos 2024-02-20 21:43:54 +01:00
parent d4bf08502c
commit 010d878a8e
3 changed files with 78 additions and 14 deletions

View File

@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed ### Fixed
- added missing checkbox for API tracing - added missing checkbox for API tracing
- fixed incompatibility with Windows ARM64 Insider build 26052 and later - 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
- changed DynData format to add flags - changed DynData format to add flags

View File

@ -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); SkipOriginalTry = (status == STATUS_BAD_INITIAL_PC);
//if ( (wcsstr(TruePath, L"Harddisk0\\DR0") != 0) || wcsstr(TruePath, L"HarddiskVolume3") != 0) { //if ( (wcsstr(TruePath, L"Harddisk0\\DR0") != 0) || wcsstr(TruePath, L"HarddiskVolume3") != 0) {
@ -3833,6 +3839,12 @@ ReparseLoop:
status = GetExceptionCode(); 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); SetLastError(LastError);
return status; return status;
} }
@ -5047,6 +5059,12 @@ _FX NTSTATUS File_NtQueryFullAttributesFileImpl(
ObjectAttributes->RootDirectory, ObjectAttributes->ObjectName, ObjectAttributes->RootDirectory, ObjectAttributes->ObjectName,
&TruePath, &CopyPath, &FileFlags); &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 (! NT_SUCCESS(status)) {
if (status == STATUS_BAD_INITIAL_PC) { if (status == STATUS_BAD_INITIAL_PC) {
@ -5243,6 +5261,12 @@ _FX NTSTATUS File_NtQueryFullAttributesFileImpl(
status = STATUS_OBJECT_NAME_INVALID; 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); Dll_PopTlsNameBuffer(TlsData);
SetLastError(LastError); SetLastError(LastError);
return status; return status;
@ -5563,6 +5587,12 @@ _FX ULONG File_GetFinalPathNameByHandleW(
err = GetLastError(); 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); SetLastError(err);
return rc; return rc;
} }
@ -5578,11 +5608,11 @@ _FX WCHAR *File_GetFinalPathNameByHandleW_2(WCHAR *TruePath, ULONG dwFlags)
static const WCHAR *_DosPrefix = L"\\\\?\\UNC\\"; static const WCHAR *_DosPrefix = L"\\\\?\\UNC\\";
const FILE_DRIVE *file_drive; const FILE_DRIVE *file_drive;
const FILE_LINK *file_link; const FILE_LINK *file_link;
const WCHAR *suffix; const WCHAR *suffix, *suffix2;
WCHAR *path; WCHAR *path;
WCHAR *ReparsedPath; WCHAR *ReparsedPath;
ULONG TruePath_len; ULONG TruePath_len;
ULONG suffix_len; ULONG suffix_len, suffix2_len;
WCHAR drive_letter; WCHAR drive_letter;
BOOLEAN AddBackslash; BOOLEAN AddBackslash;
@ -5679,6 +5709,7 @@ _FX WCHAR *File_GetFinalPathNameByHandleW_2(WCHAR *TruePath, ULONG dwFlags)
ReparsedPath = NULL; ReparsedPath = NULL;
AddBackslash = FALSE; AddBackslash = FALSE;
drive_letter = 0; drive_letter = 0;
suffix2 = NULL;
file_link = File_FindPermLinksForMatchPath(TruePath, TruePath_len); file_link = File_FindPermLinksForMatchPath(TruePath, TruePath_len);
if (file_link) { if (file_link) {
@ -5728,18 +5759,33 @@ _FX WCHAR *File_GetFinalPathNameByHandleW_2(WCHAR *TruePath, ULONG dwFlags)
file_drive = File_GetDriveForPath(TruePath, TruePath_len); file_drive = File_GetDriveForPath(TruePath, TruePath_len);
if (! file_drive) { if (! file_drive) {
file_drive = File_GetDriveForPath(file_link->src, file_link->src_len);
if (!file_drive) {
// release lock by File_FindPermLinksForMatchPath // release lock by File_FindPermLinksForMatchPath
LeaveCriticalSection(File_DrivesAndLinks_CritSec); LeaveCriticalSection(File_DrivesAndLinks_CritSec);
SetLastError(ERROR_PATH_NOT_FOUND); SetLastError(ERROR_PATH_NOT_FOUND);
return NULL; 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; drive_letter = file_drive->letter;
suffix = TruePath + file_drive->len; suffix = TruePath + file_drive->len;
// release lock by File_GetDriveForPath // release lock by File_GetDriveForPath
LeaveCriticalSection(File_DrivesAndLinks_CritSec); LeaveCriticalSection(File_DrivesAndLinks_CritSec);
}
} }
// release lock by File_FindPermLinksForMatchPath // release lock by File_FindPermLinksForMatchPath
@ -5785,11 +5831,15 @@ _FX WCHAR *File_GetFinalPathNameByHandleW_2(WCHAR *TruePath, ULONG dwFlags)
} else { // VOLUME_NAME_DOS } else { // VOLUME_NAME_DOS
suffix_len = wcslen(suffix); 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); wmemcpy(path, _DosPrefix, 4);
path[4] = drive_letter; path[4] = drive_letter;
path[5] = L':'; path[5] = L':';
wmemcpy(path + 6, suffix, suffix_len + 1); wmemcpy(path + 6, suffix, suffix_len + 1);
if (suffix2)
wcscat(path, suffix2);
} }
if (AddBackslash) if (AddBackslash)

View File

@ -1328,7 +1328,7 @@ _FX FILE_LINK *File_FindPermLinksForMatchPath(
link = List_Head(File_PermLinks); link = List_Head(File_PermLinks);
while (link) { while (link) {
const ULONG src_len = link->src_len; /*const ULONG src_len = link->src_len;
if ( if (
#ifdef WOW64_FS_REDIR #ifdef WOW64_FS_REDIR
@ -1338,6 +1338,19 @@ _FX FILE_LINK *File_FindPermLinksForMatchPath(
(name[src_len] == L'\\' || name[src_len] == L'\0') && (name[src_len] == L'\\' || name[src_len] == L'\0') &&
_wcsnicmp(name, link->src, src_len) == 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; return link;
} }