Fix computername

This commit is contained in:
momo5502
2025-05-24 11:06:09 +02:00
parent 0f33c7ea13
commit 92bdf26669
4 changed files with 39 additions and 5 deletions

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

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