diff --git a/src/emulator/serialization.hpp b/src/emulator/serialization.hpp index 342735aa..0b6f916d 100644 --- a/src/emulator/serialization.hpp +++ b/src/emulator/serialization.hpp @@ -39,7 +39,8 @@ namespace utils template struct has_serialize_function(), - std::declval&>()))>> + std::declval&>()) + )>> : std::true_type { }; @@ -51,7 +52,8 @@ namespace utils template struct has_deserialize_function(), std::declval&>()))>> + std::declval(), + std::declval&>()))>> : std::true_type { }; diff --git a/src/windows-emulator/registry_manager.cpp b/src/windows-emulator/registry_manager.cpp index c73f5f94..be8bd01e 100644 --- a/src/windows-emulator/registry_manager.cpp +++ b/src/windows-emulator/registry_manager.cpp @@ -1,5 +1,7 @@ #include "registry_manager.hpp" + #include +#include namespace { @@ -39,31 +41,41 @@ namespace registry_manager::~registry_manager() = default; -registry_manager::registry_manager(const std::filesystem::path& hive_path) +registry_manager::registry_manager(std::filesystem::path hive_path) + : hive_path_(std::move(hive_path)) { + this->setup(); +} + +void registry_manager::setup() +{ + this->path_mapping_.clear(); + this->hives_.clear(); + const std::filesystem::path root = R"(\registry)"; const std::filesystem::path machine = root / "machine"; - register_hive(this->hives_, machine / "system", hive_path / "SYSTEM"); - register_hive(this->hives_, machine / "security", hive_path / "SECURITY"); - register_hive(this->hives_, machine / "sam", hive_path / "SAM"); - register_hive(this->hives_, machine / "software", hive_path / "SOFTWARE"); - register_hive(this->hives_, machine / "system", hive_path / "SYSTEM"); - register_hive(this->hives_, machine / "hardware", hive_path / "HARDWARE"); + register_hive(this->hives_, machine / "system", this->hive_path_ / "SYSTEM"); + register_hive(this->hives_, machine / "security", this->hive_path_ / "SECURITY"); + register_hive(this->hives_, machine / "sam", this->hive_path_ / "SAM"); + register_hive(this->hives_, machine / "software", this->hive_path_ / "SOFTWARE"); + register_hive(this->hives_, machine / "system", this->hive_path_ / "SYSTEM"); + register_hive(this->hives_, machine / "hardware", this->hive_path_ / "HARDWARE"); - register_hive(this->hives_, root / "user", hive_path / "NTUSER.dat"); + register_hive(this->hives_, root / "user", this->hive_path_ / "NTUSER.dat"); this->add_path_mapping(machine / "system" / "CurrentControlSet", machine / "system" / "ControlSet001"); } void registry_manager::serialize(utils::buffer_serializer& buffer) const { - (void)buffer; + buffer.write(this->hive_path_); } void registry_manager::deserialize(utils::buffer_deserializer& buffer) { - (void)buffer; + buffer.read(this->hive_path_); + this->setup(); } std::filesystem::path registry_manager::normalize_path(const std::filesystem::path& path) const diff --git a/src/windows-emulator/registry_manager.hpp b/src/windows-emulator/registry_manager.hpp index bbdeabd8..43a544f5 100644 --- a/src/windows-emulator/registry_manager.hpp +++ b/src/windows-emulator/registry_manager.hpp @@ -35,7 +35,8 @@ public: using hive_ptr = std::unique_ptr; using hive_map = std::unordered_map; - registry_manager(const std::filesystem::path& hive_path); + registry_manager() = default; + registry_manager(std::filesystem::path hive_path); ~registry_manager(); void serialize(utils::buffer_serializer& buffer) const; @@ -45,6 +46,7 @@ public: std::optional get_value(const registry_key& key, const std::string_view name); private: + std::filesystem::path hive_path_{}; hive_map hives_{}; std::unordered_map path_mapping_{}; @@ -52,4 +54,6 @@ private: void add_path_mapping(const std::filesystem::path& key, const std::filesystem::path& value); hive_map::iterator find_hive(const std::filesystem::path& key); + + void setup(); };