Support more syscalls

This commit is contained in:
momo5502
2025-05-31 21:27:32 +02:00
parent 59576342d3
commit e763fdac54
6 changed files with 98 additions and 6 deletions

View File

@@ -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
{

View File

@@ -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

View File

@@ -165,6 +165,9 @@ namespace syscalls
// syscalls/mutant.cpp:
NTSTATUS handle_NtReleaseMutant(const syscall_context& c, handle mutant_handle,
emulator_object<LONG> previous_count);
NTSTATUS handle_NtOpenMutant(const syscall_context& c, const emulator_object<handle> mutant_handle,
const ACCESS_MASK /*desired_access*/,
const emulator_object<OBJECT_ATTRIBUTES<EmulatorTraits<Emu64>>> object_attributes);
NTSTATUS handle_NtCreateMutant(const syscall_context& c, emulator_object<handle> mutant_handle,
ACCESS_MASK /*desired_access*/,
emulator_object<OBJECT_ATTRIBUTES<EmulatorTraits<Emu64>>> 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<std::string, syscall_handler>& ha
add_handler(NtUserChangeWindowMessageFilterEx);
add_handler(NtUserDestroyWindow);
add_handler(NtQueryInformationByName);
add_handler(NtUserSetCursor);
add_handler(NtOpenMutant);
#undef add_handler
}

View File

@@ -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_RENAME_INFORMATION>(file_information);
auto new_name = read_string<char16_t>(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;

View File

@@ -32,6 +32,40 @@ namespace syscalls
return succeeded ? STATUS_SUCCESS : STATUS_MUTANT_NOT_OWNED;
}
NTSTATUS handle_NtOpenMutant(const syscall_context& c, const emulator_object<handle> mutant_handle,
const ACCESS_MASK /*desired_access*/,
const emulator_object<OBJECT_ATTRIBUTES<EmulatorTraits<Emu64>>> 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<UNICODE_STRING<EmulatorTraits<Emu64>>>{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<handle> mutant_handle,
const ACCESS_MASK /*desired_access*/,
const emulator_object<OBJECT_ATTRIBUTES<EmulatorTraits<Emu64>>> object_attributes,
@@ -75,4 +109,4 @@ namespace syscalls
return STATUS_SUCCESS;
}
}
}

View File

@@ -77,12 +77,19 @@ namespace syscalls
// TODO: Fix this. This is broken and wrong.
const emulator_object<PORT_DATA_ENTRY<EmulatorTraits<Emu64>>> data{c.emu, receive_message.value() + 0x48};
const auto dest = data.read();
const auto base = dest.Base;
try
{
const emulator_object<PORT_DATA_ENTRY<EmulatorTraits<Emu64>>> 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;
}