diff --git a/src/windows-emulator/handles.hpp b/src/windows-emulator/handles.hpp index 2daefbbb..c88f5cc3 100644 --- a/src/windows-emulator/handles.hpp +++ b/src/windows-emulator/handles.hpp @@ -6,6 +6,7 @@ struct handle_types { invalid = 0, file, + device, event, section, symlink, diff --git a/src/windows-emulator/io_device.hpp b/src/windows-emulator/io_device.hpp new file mode 100644 index 00000000..11c79d15 --- /dev/null +++ b/src/windows-emulator/io_device.hpp @@ -0,0 +1,80 @@ +#pragma once + +#include +#include + +struct io_device +{ + io_device() = default; + virtual ~io_device() = default; + + // TODO + virtual void read() = 0; + virtual void write() = 0; + + virtual void serialize(utils::buffer_serializer& buffer) const = 0; + virtual void deserialize(utils::buffer_deserializer& buffer) = 0; +}; + +// TODO +inline std::unique_ptr create_device(const std::wstring_view device) +{ + (void)device; + return {}; +} + +class io_device_container : public io_device +{ +public: + io_device_container() = default; + + io_device_container(std::wstring device) + : device_name_(std::move(device)) + { + this->setup(); + } + + void read() override + { + this->assert_validity(); + this->device_->read(); + } + + void write() override + { + this->assert_validity(); + this->device_->write(); + } + + void serialize(utils::buffer_serializer& buffer) const override + { + this->assert_validity(); + + buffer.write_string(this->device_name_); + this->device_->serialize(buffer); + } + + void deserialize(utils::buffer_deserializer& buffer) override + { + buffer.read_string(this->device_name_); + this->setup(); + this->device_->deserialize(buffer); + } + +private: + std::wstring device_name_{}; + std::unique_ptr device_{}; + + void setup() + { + this->device_ = create_device(this->device_name_); + } + + void assert_validity() const + { + if (!this->device_) + { + throw std::runtime_error("Device not created!"); + } + } +}; diff --git a/src/windows-emulator/process_context.hpp b/src/windows-emulator/process_context.hpp index 919f69c8..4bb6a234 100644 --- a/src/windows-emulator/process_context.hpp +++ b/src/windows-emulator/process_context.hpp @@ -11,6 +11,7 @@ #include #include +#include "io_device.hpp" #define PEB_SEGMENT_SIZE (20 << 20) // 20 MB #define GS_SEGMENT_SIZE (1 << 20) // 1 MB @@ -392,6 +393,7 @@ struct process_context handle_store events{}; handle_store files{}; + handle_store devices{}; handle_store semaphores{}; handle_store ports{}; handle_store registry_keys{}; @@ -428,6 +430,7 @@ struct process_context buffer.write(this->shared_section_size); buffer.write(this->events); buffer.write(this->files); + buffer.write(this->devices); buffer.write(this->semaphores); buffer.write(this->ports); buffer.write(this->registry_keys); @@ -469,6 +472,7 @@ struct process_context buffer.read(this->shared_section_size); buffer.read(this->events); buffer.read(this->files); + buffer.read(this->devices); buffer.read(this->semaphores); buffer.read(this->ports); buffer.read(this->registry_keys);