Skip to content

Commit

Permalink
Hopefully fixes tvfs_test for good.
Browse files Browse the repository at this point in the history
  • Loading branch information
Holt59 committed Jun 7, 2024
1 parent f05f7e5 commit 6675f68
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
26 changes: 24 additions & 2 deletions src/shared/ntdll_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,30 @@ typedef struct _FILE_BASIC_INFORMATION {
ULONG FileAttributes;
} FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;

#define FILE_DIRECTORY_FILE 0x00000001
#define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000
#define FILE_DIRECTORY_FILE 0x00000001
#define FILE_WRITE_THROUGH 0x00000002
#define FILE_SEQUENTIAL_ONLY 0x00000004
#define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008
#define FILE_SYNCHRONOUS_IO_ALERT 0x00000010
#define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020
#define FILE_NON_DIRECTORY_FILE 0x00000040
#define FILE_CREATE_TREE_CONNECTION 0x00000080
#define FILE_COMPLETE_IF_OPLOCKED 0x00000100
#define FILE_NO_EA_KNOWLEDGE 0x00000200
#define FILE_OPEN_REMOTE_INSTANCE 0x00000400
#define FILE_RANDOM_ACCESS 0x00000800
#define FILE_DELETE_ON_CLOSE 0x00001000
#define FILE_OPEN_BY_FILE_ID 0x00002000
#define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000
#define FILE_NO_COMPRESSION 0x00008000
#define FILE_OPEN_REQUIRING_OPLOCK 0x00010000
#define FILE_DISALLOW_EXCLUSIVE 0x00020000
#define FILE_SESSION_AWARE 0x00040000
#define FILE_RESERVE_OPFILTER 0x00100000
#define FILE_OPEN_REPARSE_POINT 0x00200000
#define FILE_OPEN_NO_RECALL 0x00400000
#define FILE_OPEN_FOR_FREE_SPACE_QUERY 0x00800000
#define FILE_CONTAINS_EXTENDED_CREATE_INFORMATION 0x10000000

typedef NTSTATUS(WINAPI *NtQueryDirectoryFile_type)(
HANDLE, HANDLE, PIO_APC_ROUTINE, PVOID, PIO_STATUS_BLOCK, PVOID, ULONG,
Expand Down
19 changes: 6 additions & 13 deletions test/tvfs_test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ HANDLE hooked_NtOpenFile(LPWSTR path, ACCESS_MASK accessMask, ULONG shareAccess,
attributes.ObjectName = &string;

HANDLE ret = INVALID_HANDLE_VALUE;
if (usvfs::hook_NtOpenFile(&ret, accessMask, &attributes, &statusBlock, shareAccess, openOptions) != STATUS_SUCCESS)
if (usvfs::hook_NtOpenFile(&ret, accessMask | SYNCHRONIZE,
&attributes, &statusBlock, shareAccess,
openOptions | FILE_SYNCHRONOUS_IO_NONALERT) != STATUS_SUCCESS)
{
return INVALID_HANDLE_VALUE;
}
Expand All @@ -295,11 +297,9 @@ TEST_F(USVFSTest, NtQueryDirectoryFileRegularFile)
USVFSInitParameters(&params, "usvfs_test", true, LogLevel::Debug, CrashDumpsType::None, "");
std::unique_ptr<usvfs::HookContext> ctx(CreateHookContext(params, ::GetModuleHandle(nullptr)));

TCHAR cwd[1024];
GetCurrentDirectoryW(1024, cwd);

HANDLE hdl = hooked_NtOpenFile(
cwd
L"C:\\"
, FILE_GENERIC_READ
, FILE_SHARE_READ | FILE_SHARE_WRITE
, OPEN_EXISTING);
Expand Down Expand Up @@ -330,17 +330,10 @@ TEST_F(USVFSTest, NtQueryDirectoryFileFindsVirtualFile)
std::unique_ptr<usvfs::HookContext> ctx(CreateHookContext(params, ::GetModuleHandle(nullptr)));
usvfs::RedirectionTreeContainer &tree = ctx->redirectionTable();

TCHAR cwd[1024];
GetCurrentDirectoryW(1024, cwd);

TCHAR npPath[1024];
lstrcpyW(npPath, cwd);
lstrcatW(npPath, L"\\np.exe");
tree.addFile(npPath, usvfs::RedirectionDataLocal(REAL_FILEA));

tree.addFile(L"C:\\np.exe", usvfs::RedirectionDataLocal(REAL_FILEA));

HANDLE hdl = hooked_NtOpenFile(
cwd
L"C:\\"
, FILE_GENERIC_READ
, FILE_SHARE_READ | FILE_SHARE_WRITE
, OPEN_EXISTING);
Expand Down

0 comments on commit 6675f68

Please sign in to comment.