mirror of
https://github.com/momo5502/emulator.git
synced 2026-01-18 19:23:56 +00:00
Fix serialization
This commit is contained in:
@@ -38,8 +38,8 @@ namespace utils
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct has_serialize_function<T, std::void_t<decltype(serialize(std::declval<buffer_serializer&>(),
|
||||
std::declval<const T&>()))>>
|
||||
struct has_serialize_function<T, std::void_t<decltype(::serialize(std::declval<buffer_serializer&>(),
|
||||
std::declval<const std::remove_cvref_t<T>&>()))>>
|
||||
: std::true_type
|
||||
{
|
||||
};
|
||||
@@ -50,8 +50,8 @@ namespace utils
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct has_deserialize_function<T, std::void_t<decltype(deserialize(
|
||||
std::declval<buffer_deserializer&>(), std::declval<T&>()))>>
|
||||
struct has_deserialize_function<T, std::void_t<decltype(::deserialize(
|
||||
std::declval<buffer_deserializer&>(), std::declval<std::remove_cvref_t<T>&>()))>>
|
||||
: std::true_type
|
||||
{
|
||||
};
|
||||
@@ -122,7 +122,7 @@ namespace utils
|
||||
}
|
||||
else if constexpr (detail::has_deserialize_function<T>::value)
|
||||
{
|
||||
deserialize(*this, object);
|
||||
::deserialize(*this, object);
|
||||
}
|
||||
else if constexpr (std::is_trivially_copyable_v<T>)
|
||||
{
|
||||
@@ -338,7 +338,7 @@ namespace utils
|
||||
}
|
||||
else if constexpr (detail::has_serialize_function<T>::value)
|
||||
{
|
||||
serialize(*this, object);
|
||||
::serialize(*this, object);
|
||||
}
|
||||
else if constexpr (std::is_trivially_copyable_v<T>)
|
||||
{
|
||||
|
||||
30
src/emulator/serialization_helper.hpp
Normal file
30
src/emulator/serialization_helper.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "serialization.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
|
||||
inline void serialize(utils::buffer_serializer& buffer, const std::chrono::steady_clock::time_point& tp)
|
||||
{
|
||||
buffer.write(tp.time_since_epoch().count());
|
||||
}
|
||||
|
||||
inline void deserialize(utils::buffer_deserializer& buffer, std::chrono::steady_clock::time_point& tp)
|
||||
{
|
||||
using time_point = std::chrono::steady_clock::time_point;
|
||||
using duration = time_point::duration;
|
||||
|
||||
const auto count = buffer.read<duration::rep>();
|
||||
tp = time_point{duration{count}};
|
||||
}
|
||||
|
||||
inline void serialize(utils::buffer_serializer& buffer, const std::filesystem::path& path)
|
||||
{
|
||||
buffer.write_string<wchar_t>(path.wstring());
|
||||
}
|
||||
|
||||
inline void deserialize(utils::buffer_deserializer& buffer, std::filesystem::path& path)
|
||||
{
|
||||
path = buffer.read_string<wchar_t>();
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <utils/file_handle.hpp>
|
||||
|
||||
#include <x64_emulator.hpp>
|
||||
#include <serialization_helper.hpp>
|
||||
|
||||
|
||||
#define PEB_SEGMENT_SIZE (20 << 20) // 20 MB
|
||||
@@ -24,20 +25,6 @@
|
||||
#define GDT_LIMIT 0x1000
|
||||
#define GDT_ENTRY_SIZE 0x8
|
||||
|
||||
inline void serialize(utils::buffer_serializer& buffer, const std::chrono::steady_clock::time_point& tp)
|
||||
{
|
||||
buffer.write(tp.time_since_epoch().count());
|
||||
}
|
||||
|
||||
inline void deserialize(utils::buffer_deserializer& buffer, std::chrono::steady_clock::time_point& tp)
|
||||
{
|
||||
using time_point = std::chrono::steady_clock::time_point;
|
||||
using duration = time_point::duration;
|
||||
|
||||
const auto count = buffer.read<duration::rep>();
|
||||
tp = time_point{duration{count}};
|
||||
}
|
||||
|
||||
struct ref_counted_object
|
||||
{
|
||||
uint32_t ref_count{1};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "std_include.hpp"
|
||||
#include <serialization.hpp>
|
||||
#include <serialization_helper.hpp>
|
||||
|
||||
class hive_parser;
|
||||
|
||||
@@ -12,14 +12,14 @@ struct registry_key
|
||||
|
||||
void serialize(utils::buffer_serializer& buffer) const
|
||||
{
|
||||
buffer.write_string<wchar_t>(this->hive.wstring());
|
||||
buffer.write_string<wchar_t>(this->path.wstring());
|
||||
buffer.write(this->hive);
|
||||
buffer.write(this->path);
|
||||
}
|
||||
|
||||
void deserialize(utils::buffer_deserializer& buffer)
|
||||
{
|
||||
this->hive = buffer.read_string<wchar_t>();
|
||||
this->path = buffer.read_string<wchar_t>();
|
||||
buffer.read(this->hive);
|
||||
buffer.read(this->path);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user