From 74ec07c642d60393956a9aff2bee969db26f8704 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Tue, 5 Nov 2024 19:36:18 +0100 Subject: [PATCH] Some I/O fixes --- src/windows-emulator/handles.hpp | 1 + src/windows-emulator/syscalls.cpp | 39 +++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/windows-emulator/handles.hpp b/src/windows-emulator/handles.hpp index 977ea26c..2daefbbb 100644 --- a/src/windows-emulator/handles.hpp +++ b/src/windows-emulator/handles.hpp @@ -315,6 +315,7 @@ constexpr auto CONSOLE_SERVER = make_pseudo_handle(0x1338, handle_types::section constexpr auto CM_API = make_pseudo_handle(0x1338, handle_types::file); constexpr auto KSEC_DD = make_pseudo_handle(0x1339, handle_types::file); constexpr auto AFD_ENDPOINT = make_pseudo_handle(0x133A, handle_types::file); +constexpr auto CNG = make_pseudo_handle(0x133B, handle_types::file); constexpr auto CONSOLE_HANDLE = make_pseudo_handle(0x1, handle_types::file); constexpr auto STDOUT_HANDLE = make_pseudo_handle(0x2, handle_types::file); diff --git a/src/windows-emulator/syscalls.cpp b/src/windows-emulator/syscalls.cpp index 35c71a61..8b4997c0 100644 --- a/src/windows-emulator/syscalls.cpp +++ b/src/windows-emulator/syscalls.cpp @@ -2028,7 +2028,7 @@ namespace const emulator_object object_attributes, const emulator_object /*io_status_block*/, const emulator_object /*allocation_size*/, ULONG /*file_attributes*/, - ULONG /*share_access*/, ULONG create_disposition, ULONG /*create_options*/, + ULONG /*share_access*/, ULONG create_disposition, ULONG create_options, uint64_t /*ea_buffer*/, ULONG /*ea_length*/) { @@ -2058,6 +2058,12 @@ namespace return STATUS_SUCCESS; } + if (filename == L"\\Device\\CNG") + { + file_handle.write(CNG.bits); + return STATUS_SUCCESS; + } + if (filename.starts_with(L"\\Device\\Afd\\Endpoint")) { file_handle.write(AFD_ENDPOINT.bits); @@ -2093,10 +2099,25 @@ namespace printer.cancel(); - if (f.name.ends_with(L"\\")) + if (f.name.ends_with(L"\\") || create_options & FILE_DIRECTORY_FILE) { c.win_emu.logger.print(color::dark_gray, "--> Opening folder: %S\n", f.name.c_str()); + if (create_disposition & FILE_CREATE) + { + std::error_code ec{}; + std::filesystem::create_directory(f.name, ec); + + if (ec) + { + return STATUS_ACCESS_DENIED; + } + } + else if (!std::filesystem::is_directory(f.name)) + { + return STATUS_OBJECT_NAME_NOT_FOUND; + } + const auto handle = c.proc.files.store(std::move(f)); file_handle.write(handle.bits); @@ -2107,6 +2128,11 @@ namespace const auto* mode = map_mode(desired_access, create_disposition); + if (!mode || wcslen(mode) == 0) + { + return STATUS_NOT_SUPPORTED; + } + FILE* file{}; const auto error = _wfopen_s(&file, f.name.c_str(), mode); @@ -2476,6 +2502,14 @@ namespace return STATUS_SUCCESS; } + + NTSTATUS handle_NtGetCurrentProcessorNumberEx(const syscall_context& c, + const emulator_object processor_number) + { + constexpr PROCESSOR_NUMBER number{}; + processor_number.write(number); + return STATUS_SUCCESS; + } } void syscall_dispatcher::add_handlers(std::map& handler_mapping) @@ -2569,6 +2603,7 @@ void syscall_dispatcher::add_handlers(std::map& ha add_handler(NtAccessCheck); add_handler(NtCreateKey); add_handler(NtNotifyChangeKey); + add_handler(NtGetCurrentProcessorNumberEx); #undef add_handler }