From de8b85a3f9d334c6b4e4da322422d257aed6c1f3 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 21 Dec 2024 09:55:38 +0100 Subject: [PATCH] Implement NtQueryAttributesFile syscall --- src/windows-emulator/syscall_utils.hpp | 7 +++++ src/windows-emulator/syscalls.cpp | 36 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/windows-emulator/syscall_utils.hpp b/src/windows-emulator/syscall_utils.hpp index cb053c0..3f0b565 100644 --- a/src/windows-emulator/syscall_utils.hpp +++ b/src/windows-emulator/syscall_utils.hpp @@ -243,3 +243,10 @@ inline std::chrono::system_clock::time_point convert_from_ksystem_time(const vol { return convert_from_ksystem_time(*const_cast(&time)); } + +inline LARGE_INTEGER convert_unix_to_windows_time(const __time64_t unix_time) +{ + LARGE_INTEGER windows_time{}; + windows_time.QuadPart = (unix_time + EPOCH_DIFFERENCE_1601_TO_1970_SECONDS) * HUNDRED_NANOSECONDS_IN_ONE_SECOND; + return windows_time; +} \ No newline at end of file diff --git a/src/windows-emulator/syscalls.cpp b/src/windows-emulator/syscalls.cpp index 0a8e634..63a61f0 100644 --- a/src/windows-emulator/syscalls.cpp +++ b/src/windows-emulator/syscalls.cpp @@ -2285,6 +2285,41 @@ namespace return STATUS_SUCCESS; } + NTSTATUS handle_NtQueryAttributesFile(const syscall_context& c, + const emulator_object object_attributes, + const emulator_object file_information) + { + if (!object_attributes) + { + return STATUS_INVALID_PARAMETER; + } + + const auto attributes = object_attributes.read(); + if (!attributes.ObjectName) + { + return STATUS_INVALID_PARAMETER; + } + + const auto filename = read_unicode_string(c.emu, attributes.ObjectName); + + struct _stat64 file_stat{}; + if (_wstat64(filename.c_str(), &file_stat) != 0) + { + return STATUS_OBJECT_NAME_NOT_FOUND; + } + + file_information.access([&](FILE_BASIC_INFORMATION& info) + { + info.CreationTime = convert_unix_to_windows_time(file_stat.st_atime); + info.LastAccessTime = convert_unix_to_windows_time(file_stat.st_atime); + info.LastWriteTime = convert_unix_to_windows_time(file_stat.st_mtime); + info.ChangeTime = info.LastWriteTime; + info.FileAttributes = FILE_ATTRIBUTE_NORMAL; + }); + + return STATUS_SUCCESS; + } + NTSTATUS handle_NtOpenFile(const syscall_context& c, const emulator_object file_handle, const ACCESS_MASK desired_access, @@ -2729,6 +2764,7 @@ void syscall_dispatcher::add_handlers(std::map& ha add_handler(NtNotifyChangeKey); add_handler(NtGetCurrentProcessorNumberEx); add_handler(NtQueryObject); + add_handler(NtQueryAttributesFile); #undef add_handler }