Skip to content

Commit

Permalink
Serialize registry manager
Browse files Browse the repository at this point in the history
  • Loading branch information
momo5502 committed Nov 3, 2024
1 parent 898299d commit c96aaaa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/emulator/serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ namespace utils

template <typename T>
struct has_serialize_function<T, std::void_t<decltype(::serialize(std::declval<buffer_serializer&>(),
std::declval<const std::remove_cvref_t<T>&>()))>>
std::declval<const std::remove_cvref_t<T>&>())
)>>
: std::true_type
{
};
Expand All @@ -51,7 +52,8 @@ namespace utils

template <typename T>
struct has_deserialize_function<T, std::void_t<decltype(::deserialize(
std::declval<buffer_deserializer&>(), std::declval<std::remove_cvref_t<T>&>()))>>
std::declval<buffer_deserializer&>(),
std::declval<std::remove_cvref_t<T>&>()))>>
: std::true_type
{
};
Expand Down
32 changes: 22 additions & 10 deletions src/windows-emulator/registry_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "registry_manager.hpp"

#include <hive_parser.hh>
#include <serialization_helper.hpp>

namespace
{
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/windows-emulator/registry_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class registry_manager
using hive_ptr = std::unique_ptr<hive_parser>;
using hive_map = std::unordered_map<std::filesystem::path, hive_ptr>;

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;
Expand All @@ -45,11 +46,14 @@ class registry_manager
std::optional<registry_value> get_value(const registry_key& key, const std::string_view name);

private:
std::filesystem::path hive_path_{};
hive_map hives_{};
std::unordered_map<std::filesystem::path, std::filesystem::path> 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);

hive_map::iterator find_hive(const std::filesystem::path& key);

void setup();
};

0 comments on commit c96aaaa

Please sign in to comment.