Fix GetComputerName (#313)

This commit is contained in:
Maurice Heumann
2025-05-24 11:30:48 +02:00
committed by GitHub
6 changed files with 46 additions and 5 deletions

View File

@@ -678,6 +678,13 @@ namespace
printf("Time: %lld\n", std::chrono::duration_cast<std::chrono::nanoseconds>(epoch_time).count());
}
bool test_apis()
{
wchar_t buffer[0x100];
DWORD size = sizeof(buffer) / 2;
return GetComputerNameExW(ComputerNameNetBIOS, buffer, &size);
}
bool test_apc()
{
int executions = 0;
@@ -721,6 +728,7 @@ int main(const int argc, const char* argv[])
RUN_TEST(test_io, "I/O")
RUN_TEST(test_dir_io, "Dir I/O")
RUN_TEST(test_apis, "APIs")
RUN_TEST(test_working_directory, "Working Directory")
RUN_TEST(test_registry, "Registry")
RUN_TEST(test_system_info, "System Info")

View File

@@ -410,6 +410,7 @@ constexpr auto DBWIN_BUFFER = make_pseudo_handle(0x2, handle_types::section);
constexpr auto WER_PORT_READY = make_pseudo_handle(0x1, handle_types::event);
constexpr auto DBWIN_DATA_READY = make_pseudo_handle(0x2, handle_types::event);
constexpr auto DBWIN_BUFFER_READY = make_pseudo_handle(0x3, handle_types::event);
constexpr auto SVCCTRL_START_EVENT = make_pseudo_handle(0x4, handle_types::event);
constexpr auto CONSOLE_HANDLE = make_pseudo_handle(0x1, handle_types::file);
constexpr auto STDOUT_HANDLE = make_pseudo_handle(0x2, handle_types::file);

View File

@@ -28,6 +28,25 @@ namespace
{
hives[key] = std::make_unique<hive_parser>(file);
}
std::pair<utils::path_key, bool> perform_path_substitution(
const std::unordered_map<utils::path_key, utils::path_key>& path_mapping, utils::path_key path)
{
for (const auto& mapping : path_mapping)
{
if (path == mapping.first)
{
return {mapping.second, true};
}
if (is_subpath(mapping.first.get(), path.get()))
{
return {mapping.second.get() / path.get().lexically_relative(mapping.first.get()), true};
}
}
return {std::move(path), false};
}
}
registry_manager::registry_manager() = default;
@@ -59,15 +78,20 @@ void registry_manager::setup()
register_hive(this->hives_, root / "user", this->hive_path_ / "NTUSER.DAT");
this->add_path_mapping(machine / "system" / "CurrentControlSet", machine / "system" / "ControlSet001");
this->add_path_mapping(machine / "system" / "ControlSet001" / "Control" / "ComputerName" / "ActiveComputerName",
machine / "system" / "ControlSet001" / "Control" / "ComputerName" / "ComputerName");
}
utils::path_key registry_manager::normalize_path(const utils::path_key& path) const
utils::path_key registry_manager::normalize_path(utils::path_key path) const
{
for (const auto& mapping : this->path_mapping_)
for (size_t i = 0; i < 10; ++i)
{
if (is_subpath(mapping.first.get(), path.get()))
auto [new_path, changed] = perform_path_substitution(this->path_mapping_, std::move(path));
path = std::move(new_path);
if (!changed)
{
return mapping.second.get() / path.get().lexically_relative(mapping.first.get());
break;
}
}

View File

@@ -76,7 +76,7 @@ class registry_manager
hive_map hives_{};
std::unordered_map<utils::path_key, utils::path_key> path_mapping_{};
utils::path_key normalize_path(const utils::path_key& path) const;
utils::path_key normalize_path(utils::path_key path) const;
void add_path_mapping(const utils::path_key& key, const utils::path_key& value);
hive_map::iterator find_hive(const utils::path_key& key);

View File

@@ -107,6 +107,12 @@ namespace syscalls
return STATUS_SUCCESS;
}
if (name == u"Global\\SvcctrlStartEvent_A3752DX")
{
event_handle.write(SVCCTRL_START_EVENT.bits);
return STATUS_SUCCESS;
}
if (name == u"DBWIN_DATA_READY")
{
event_handle.write(DBWIN_DATA_READY.bits);

View File

@@ -129,6 +129,8 @@ namespace syscalls
}
const auto query_name = read_unicode_string(c.emu, value_name);
c.win_emu.log.print(color::dark_gray, "--> Query value key: %s (%s\\%s)\n", u16_to_u8(query_name).c_str(),
key->hive.get().string().c_str(), key->path.get().string().c_str());
const auto value = c.win_emu.registry.get_value(*key, u16_to_u8(query_name));
if (!value)