Skip to content

Commit

Permalink
Fix registry value queries
Browse files Browse the repository at this point in the history
  • Loading branch information
momo5502 committed Nov 4, 2024
1 parent 808dca6 commit 713a6d1
Showing 1 changed file with 43 additions and 32 deletions.
75 changes: 43 additions & 32 deletions src/windows-emulator/syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,80 +183,85 @@ namespace

if (key_value_information_class == KeyValueBasicInformation)
{
const auto required_size = offsetof(KEY_VALUE_BASIC_INFORMATION, Name) + (original_name.size() * 2) - 1;
constexpr auto base_size = offsetof(KEY_VALUE_BASIC_INFORMATION, Name);
const auto required_size = base_size + (original_name.size() * 2) - 1;
result_length.write(static_cast<ULONG>(required_size));

if (required_size > length)
{
return STATUS_BUFFER_TOO_SMALL;
}

KEY_VALUE_BASIC_INFORMATION info{};
info.TitleIndex = 0;
info.Type = value->type;
info.NameLength = static_cast<ULONG>(original_name.size() * 2);

const emulator_object<KEY_VALUE_BASIC_INFORMATION> info_obj{c.emu, key_value_information};
info_obj.write(info);
if (base_size <= length)
{
c.emu.write_memory(key_value_information, &info, base_size);
}

c.emu.write_memory(key_value_information + offsetof(KEY_VALUE_BASIC_INFORMATION, Name),
original_name.data(),
info.NameLength);
if (required_size > length)
{
return STATUS_BUFFER_OVERFLOW;
}

c.emu.write_memory(key_value_information + base_size, original_name.data(), info.NameLength);

return STATUS_SUCCESS;
}

if (key_value_information_class == KeyValuePartialInformation)
{
const auto required_size = offsetof(KEY_VALUE_PARTIAL_INFORMATION, Data) + value->data.size();
constexpr auto base_size = offsetof(KEY_VALUE_PARTIAL_INFORMATION, Data);
const auto required_size = base_size + value->data.size();
result_length.write(static_cast<ULONG>(required_size));

if (required_size > length)
{
return STATUS_BUFFER_TOO_SMALL;
}

KEY_VALUE_PARTIAL_INFORMATION info{};
info.TitleIndex = 0;
info.Type = value->type;
info.DataLength = static_cast<ULONG>(value->data.size());

const emulator_object<KEY_VALUE_PARTIAL_INFORMATION> info_obj{c.emu, key_value_information};
info_obj.write(info);
if (base_size <= length)
{
c.emu.write_memory(key_value_information, &info, base_size);
}

c.emu.write_memory(key_value_information + offsetof(KEY_VALUE_PARTIAL_INFORMATION, Data),
value->data.data(),
value->data.size());
if (required_size > length)
{
return STATUS_BUFFER_OVERFLOW;
}

c.emu.write_memory(key_value_information + base_size, value->data.data(), value->data.size());

return STATUS_SUCCESS;
}

if (key_value_information_class == KeyValueFullInformation)
{
constexpr auto base_size = offsetof(KEY_VALUE_FULL_INFORMATION, Name);
const auto name_size = original_name.size() * 2;
const auto value_size = value->data.size();
const auto required_size = offsetof(KEY_VALUE_FULL_INFORMATION, Name) + name_size + value_size + -1;
const auto required_size = base_size + name_size + value_size + -1;
result_length.write(static_cast<ULONG>(required_size));

if (required_size > length)
{
return STATUS_BUFFER_TOO_SMALL;
}

KEY_VALUE_FULL_INFORMATION info{};
info.TitleIndex = 0;
info.Type = value->type;
info.DataLength = static_cast<ULONG>(value->data.size());
info.NameLength = static_cast<ULONG>(original_name.size() * 2);

const emulator_object<KEY_VALUE_FULL_INFORMATION> info_obj{c.emu, key_value_information};
info_obj.write(info);
if (base_size <= length)
{
c.emu.write_memory(key_value_information, &info, base_size);
}

c.emu.write_memory(key_value_information + offsetof(KEY_VALUE_BASIC_INFORMATION, Name),
if (required_size > length)
{
return STATUS_BUFFER_OVERFLOW;
}

c.emu.write_memory(key_value_information + base_size,
original_name.data(),
info.NameLength);

c.emu.write_memory(key_value_information + offsetof(KEY_VALUE_FULL_INFORMATION, Name) + info.NameLength,
c.emu.write_memory(key_value_information + base_size + info.NameLength,
value->data.data(),
value->data.size());

Expand All @@ -273,6 +278,11 @@ namespace
return STATUS_NOT_SUPPORTED;
}

NTSTATUS handle_NtNotifyChangeKey()
{
return STATUS_NOT_SUPPORTED;
}

NTSTATUS handle_NtSetInformationThread(const syscall_context& c, const uint64_t thread_handle,
const THREADINFOCLASS info_class,
const uint64_t thread_information,
Expand Down Expand Up @@ -2543,6 +2553,7 @@ void syscall_dispatcher::add_handlers(std::map<std::string, syscall_handler>& ha
add_handler(NtGetNlsSectionPtr);
add_handler(NtAccessCheck);
add_handler(NtCreateKey);
add_handler(NtNotifyChangeKey);

#undef add_handler
}

0 comments on commit 713a6d1

Please sign in to comment.