diff --git a/src/common/platform/file_management.hpp b/src/common/platform/file_management.hpp index 0aa70ccf..d0a98586 100644 --- a/src/common/platform/file_management.hpp +++ b/src/common/platform/file_management.hpp @@ -396,6 +396,14 @@ typedef struct _FILE_BOTH_DIR_INFORMATION char16_t FileName[1]; } FILE_BOTH_DIR_INFORMATION, *PFILE_BOTH_DIR_INFORMATION; +typedef struct _FILE_RENAME_INFORMATION +{ + BOOLEAN ReplaceIfExists; + EMULATOR_CAST(uint64_t, HANDLE) RootDirectory; + ULONG FileNameLength; + char16_t FileName[1]; +} FILE_RENAME_INFORMATION, *PFILE_RENAME_INFORMATION; + #ifndef OS_WINDOWS typedef struct _FILE_ID_128 { diff --git a/src/tools/create-root.bat b/src/tools/create-root.bat index c05c2808..53570fd3 100644 --- a/src/tools/create-root.bat +++ b/src/tools/create-root.bat @@ -129,6 +129,10 @@ CALL :collect cabinet.dll CALL :collect msacm32.dll CALL :collect coloradapterclient.dll CALL :collect netmsg.dll +CALL :collect rstrtmgr.dll +CALL :collect ncrypt.dll +CALL :collect ntasn1.dll +CALL :collect srvcli.dll CALL :collect locale.nls CALL :collect c_1252.nls diff --git a/src/windows-emulator/syscalls.cpp b/src/windows-emulator/syscalls.cpp index e30004d4..c4d52edb 100644 --- a/src/windows-emulator/syscalls.cpp +++ b/src/windows-emulator/syscalls.cpp @@ -165,6 +165,9 @@ namespace syscalls // syscalls/mutant.cpp: NTSTATUS handle_NtReleaseMutant(const syscall_context& c, handle mutant_handle, emulator_object previous_count); + NTSTATUS handle_NtOpenMutant(const syscall_context& c, const emulator_object mutant_handle, + const ACCESS_MASK /*desired_access*/, + const emulator_object>> object_attributes); NTSTATUS handle_NtCreateMutant(const syscall_context& c, emulator_object mutant_handle, ACCESS_MASK /*desired_access*/, emulator_object>> object_attributes, @@ -678,6 +681,11 @@ namespace syscalls return STATUS_NOT_SUPPORTED; } + NTSTATUS handle_NtUserSetCursor() + { + return STATUS_NOT_SUPPORTED; + } + NTSTATUS handle_NtUserFindExistingCursorIcon() { return STATUS_NOT_SUPPORTED; @@ -1096,6 +1104,8 @@ void syscall_dispatcher::add_handlers(std::map& ha add_handler(NtUserChangeWindowMessageFilterEx); add_handler(NtUserDestroyWindow); add_handler(NtQueryInformationByName); + add_handler(NtUserSetCursor); + add_handler(NtOpenMutant); #undef add_handler } diff --git a/src/windows-emulator/syscalls/file.cpp b/src/windows-emulator/syscalls/file.cpp index fdeb61ee..1aa0257f 100644 --- a/src/windows-emulator/syscalls/file.cpp +++ b/src/windows-emulator/syscalls/file.cpp @@ -63,6 +63,35 @@ namespace syscalls return STATUS_INVALID_HANDLE; } + if (info_class == FileRenameInformation) + { + if (length < sizeof(FILE_RENAME_INFORMATION)) + { + return STATUS_BUFFER_OVERFLOW; + } + + const auto info = c.emu.read_memory(file_information); + auto new_name = read_string(c.emu, file_information + offsetof(FILE_RENAME_INFORMATION, FileName), + info.FileNameLength / 2); + + if (info.RootDirectory) + { + const auto* root = c.proc.files.get(info.RootDirectory); + if (!root) + { + return STATUS_INVALID_HANDLE; + } + + const auto has_separator = root->name.ends_with(u"\\") || root->name.ends_with(u"/"); + new_name = root->name + (has_separator ? u"" : u"\\") + new_name; + } + + c.win_emu.log.warn("--> File rename requested: %s --> %s\n", u16_to_u8(f->name).c_str(), + u16_to_u8(new_name).c_str()); + + return STATUS_ACCESS_DENIED; + } + if (info_class == FileBasicInformation) { return STATUS_NOT_SUPPORTED; diff --git a/src/windows-emulator/syscalls/mutant.cpp b/src/windows-emulator/syscalls/mutant.cpp index b3bba6ca..5a86cfbe 100644 --- a/src/windows-emulator/syscalls/mutant.cpp +++ b/src/windows-emulator/syscalls/mutant.cpp @@ -32,6 +32,40 @@ namespace syscalls return succeeded ? STATUS_SUCCESS : STATUS_MUTANT_NOT_OWNED; } + NTSTATUS handle_NtOpenMutant(const syscall_context& c, const emulator_object mutant_handle, + const ACCESS_MASK /*desired_access*/, + const emulator_object>> object_attributes) + { + std::u16string name{}; + if (object_attributes) + { + const auto attributes = object_attributes.read(); + if (attributes.ObjectName) + { + name = read_unicode_string( + c.emu, emulator_object>>{c.emu, attributes.ObjectName}); + c.win_emu.log.print(color::dark_gray, "--> Mutant name: %s\n", u16_to_u8(name).c_str()); + } + } + + if (name.empty()) + { + return STATUS_OBJECT_NAME_NOT_FOUND; + } + + for (auto& entry : c.proc.mutants) + { + if (entry.second.name == name) + { + ++entry.second.ref_count; + mutant_handle.write(c.proc.mutants.make_handle(entry.first)); + return STATUS_SUCCESS; + } + } + + return STATUS_OBJECT_NAME_NOT_FOUND; + } + NTSTATUS handle_NtCreateMutant(const syscall_context& c, const emulator_object mutant_handle, const ACCESS_MASK /*desired_access*/, const emulator_object>> object_attributes, @@ -75,4 +109,4 @@ namespace syscalls return STATUS_SUCCESS; } -} \ No newline at end of file +} diff --git a/src/windows-emulator/syscalls/port.cpp b/src/windows-emulator/syscalls/port.cpp index 32b5c0e0..50072d50 100644 --- a/src/windows-emulator/syscalls/port.cpp +++ b/src/windows-emulator/syscalls/port.cpp @@ -77,12 +77,19 @@ namespace syscalls // TODO: Fix this. This is broken and wrong. - const emulator_object>> data{c.emu, receive_message.value() + 0x48}; - const auto dest = data.read(); - const auto base = dest.Base; + try + { + const emulator_object>> data{c.emu, receive_message.value() + 0x48}; + const auto dest = data.read(); + const auto base = dest.Base; - const auto value = base + 0x10; - c.emu.write_memory(base + 8, &value, sizeof(value)); + const auto value = base + 0x10; + c.emu.write_memory(base + 8, &value, sizeof(value)); + } + catch (...) + { + return STATUS_NOT_SUPPORTED; + } return STATUS_SUCCESS; }