mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-19 11:43:56 +00:00
Fix path key
This commit is contained in:
@@ -7,14 +7,14 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
bool is_subpath(const std::filesystem::path& root, const std::filesystem::path& p)
|
||||
bool is_subpath(const utils::path_key& root, const utils::path_key& p)
|
||||
{
|
||||
auto root_it = root.begin();
|
||||
auto p_it = p.begin();
|
||||
auto root_it = root.get().begin();
|
||||
auto p_it = p.get().begin();
|
||||
|
||||
for (; root_it != root.end(); ++root_it, ++p_it)
|
||||
for (; root_it != root.get().end(); ++root_it, ++p_it)
|
||||
{
|
||||
if (p_it == p.end() || *root_it != *p_it)
|
||||
if (p_it == p.get().end() || *root_it != *p_it)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -23,8 +23,7 @@ namespace
|
||||
return true;
|
||||
}
|
||||
|
||||
void register_hive(registry_manager::hive_map& hives, const std::filesystem::path& key,
|
||||
const std::filesystem::path& file)
|
||||
void register_hive(registry_manager::hive_map& hives, const utils::path_key& key, const std::filesystem::path& file)
|
||||
{
|
||||
hives[key] = std::make_unique<hive_parser>(file);
|
||||
}
|
||||
@@ -72,7 +71,7 @@ void registry_manager::deserialize(utils::buffer_deserializer& buffer)
|
||||
this->setup();
|
||||
}
|
||||
|
||||
std::filesystem::path registry_manager::normalize_path(const std::filesystem::path& path) const
|
||||
utils::path_key registry_manager::normalize_path(const utils::path_key& path) const
|
||||
{
|
||||
const utils::path_key canonical_path = path;
|
||||
|
||||
@@ -87,16 +86,16 @@ std::filesystem::path registry_manager::normalize_path(const std::filesystem::pa
|
||||
return canonical_path.get();
|
||||
}
|
||||
|
||||
void registry_manager::add_path_mapping(const std::filesystem::path& key, const std::filesystem::path& value)
|
||||
void registry_manager::add_path_mapping(const utils::path_key& key, const utils::path_key& value)
|
||||
{
|
||||
this->path_mapping_[key] = value;
|
||||
}
|
||||
|
||||
std::optional<registry_key> registry_manager::get_key(const std::filesystem::path& key)
|
||||
std::optional<registry_key> registry_manager::get_key(const utils::path_key& key)
|
||||
{
|
||||
const auto normal_key = this->normalize_path(key);
|
||||
|
||||
if (is_subpath(normal_key, "\\registry\\machine"))
|
||||
if (is_subpath(normal_key, utils::path_key{"\\registry\\machine"}))
|
||||
{
|
||||
registry_key reg_key{};
|
||||
reg_key.hive = normal_key;
|
||||
@@ -111,14 +110,14 @@ std::optional<registry_key> registry_manager::get_key(const std::filesystem::pat
|
||||
|
||||
registry_key reg_key{};
|
||||
reg_key.hive = iterator->first.get();
|
||||
reg_key.path = normal_key.lexically_relative(reg_key.hive);
|
||||
reg_key.path = normal_key.get().lexically_relative(reg_key.hive.get());
|
||||
|
||||
if (reg_key.path.empty())
|
||||
if (reg_key.path.get().empty())
|
||||
{
|
||||
return {std::move(reg_key)};
|
||||
}
|
||||
|
||||
const auto entry = iterator->second->get_sub_key(reg_key.path);
|
||||
const auto entry = iterator->second->get_sub_key(reg_key.path.get());
|
||||
if (!entry)
|
||||
{
|
||||
return std::nullopt;
|
||||
@@ -137,7 +136,7 @@ std::optional<registry_value> registry_manager::get_value(const registry_key& ke
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto* entry = iterator->second->get_value(key.path, name);
|
||||
auto* entry = iterator->second->get_value(key.path.get(), name);
|
||||
if (!entry)
|
||||
{
|
||||
return std::nullopt;
|
||||
@@ -151,11 +150,11 @@ std::optional<registry_value> registry_manager::get_value(const registry_key& ke
|
||||
return v;
|
||||
}
|
||||
|
||||
registry_manager::hive_map::iterator registry_manager::find_hive(const std::filesystem::path& key)
|
||||
registry_manager::hive_map::iterator registry_manager::find_hive(const utils::path_key& key)
|
||||
{
|
||||
for (auto i = this->hives_.begin(); i != this->hives_.end(); ++i)
|
||||
{
|
||||
if (is_subpath(i->first.get(), key))
|
||||
if (is_subpath(i->first, key))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
struct registry_key
|
||||
{
|
||||
std::filesystem::path hive{};
|
||||
std::filesystem::path path{};
|
||||
utils::path_key hive{};
|
||||
utils::path_key path{};
|
||||
|
||||
void serialize(utils::buffer_serializer& buffer) const
|
||||
{
|
||||
@@ -48,7 +48,7 @@ class registry_manager
|
||||
void serialize(utils::buffer_serializer& buffer) const;
|
||||
void deserialize(utils::buffer_deserializer& buffer);
|
||||
|
||||
std::optional<registry_key> get_key(const std::filesystem::path& key);
|
||||
std::optional<registry_key> get_key(const utils::path_key& key);
|
||||
std::optional<registry_value> get_value(const registry_key& key, std::string name);
|
||||
|
||||
private:
|
||||
@@ -56,10 +56,10 @@ class registry_manager
|
||||
hive_map hives_{};
|
||||
std::unordered_map<utils::path_key, utils::path_key> path_mapping_{};
|
||||
|
||||
std::filesystem::path normalize_path(const std::filesystem::path& path) const;
|
||||
void add_path_mapping(const std::filesystem::path& key, const std::filesystem::path& value);
|
||||
utils::path_key normalize_path(const 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 std::filesystem::path& key);
|
||||
hive_map::iterator find_hive(const utils::path_key& key);
|
||||
|
||||
void setup();
|
||||
};
|
||||
|
||||
@@ -77,13 +77,13 @@ namespace
|
||||
return STATUS_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
const std::filesystem::path full_path = parent_handle->hive / parent_handle->path / key;
|
||||
const std::filesystem::path full_path = parent_handle->hive.get() / parent_handle->path.get() / key;
|
||||
key = full_path.u16string();
|
||||
}
|
||||
|
||||
c.win_emu.log.print(color::dark_gray, "--> Registry key: %s\n", u16_to_u8(key).c_str());
|
||||
|
||||
auto entry = c.proc.registry.get_key(key);
|
||||
auto entry = c.proc.registry.get_key({key});
|
||||
if (!entry.has_value())
|
||||
{
|
||||
return STATUS_OBJECT_NAME_NOT_FOUND;
|
||||
@@ -115,8 +115,8 @@ namespace
|
||||
|
||||
if (key_information_class == KeyNameInformation)
|
||||
{
|
||||
auto key_name = (key->hive / key->path).wstring();
|
||||
while (key_name.ends_with('/') || key_name.ends_with('\\'))
|
||||
auto key_name = (key->hive.get() / key->path.get()).u16string();
|
||||
while (key_name.ends_with(u'/') || key_name.ends_with(u'\\'))
|
||||
{
|
||||
key_name.pop_back();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user