From 92bdf26669b1ed01ce7c45ccd1dfa6d489b0496e Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 24 May 2025 11:06:09 +0200 Subject: [PATCH] Fix computername --- src/samples/test-sample/test.cpp | 8 +++++ .../registry/registry_manager.cpp | 32 ++++++++++++++++--- .../registry/registry_manager.hpp | 2 +- src/windows-emulator/syscalls/registry.cpp | 2 ++ 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/samples/test-sample/test.cpp b/src/samples/test-sample/test.cpp index 520ceab3..518409a2 100644 --- a/src/samples/test-sample/test.cpp +++ b/src/samples/test-sample/test.cpp @@ -678,6 +678,13 @@ namespace printf("Time: %lld\n", std::chrono::duration_cast(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") diff --git a/src/windows-emulator/registry/registry_manager.cpp b/src/windows-emulator/registry/registry_manager.cpp index b6d7c860..55e6aa04 100644 --- a/src/windows-emulator/registry/registry_manager.cpp +++ b/src/windows-emulator/registry/registry_manager.cpp @@ -28,6 +28,25 @@ namespace { hives[key] = std::make_unique(file); } + + std::pair perform_path_substitution( + const std::unordered_map& 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; } } diff --git a/src/windows-emulator/registry/registry_manager.hpp b/src/windows-emulator/registry/registry_manager.hpp index 4107f97a..809713aa 100644 --- a/src/windows-emulator/registry/registry_manager.hpp +++ b/src/windows-emulator/registry/registry_manager.hpp @@ -76,7 +76,7 @@ class registry_manager hive_map hives_{}; std::unordered_map 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); diff --git a/src/windows-emulator/syscalls/registry.cpp b/src/windows-emulator/syscalls/registry.cpp index 2b219311..969a0d70 100644 --- a/src/windows-emulator/syscalls/registry.cpp +++ b/src/windows-emulator/syscalls/registry.cpp @@ -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)