From 7efe75ba97205042bf011b202fea192036efed97 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 8 Feb 2025 17:31:53 +0100 Subject: [PATCH] Remove working directory translations --- src/windows-emulator/file_system.hpp | 30 +++++++---------------- src/windows-emulator/windows_emulator.cpp | 21 +--------------- src/windows-emulator/windows_emulator.hpp | 4 +-- 3 files changed, 11 insertions(+), 44 deletions(-) diff --git a/src/windows-emulator/file_system.hpp b/src/windows-emulator/file_system.hpp index 159cf311..f0ffa98d 100644 --- a/src/windows-emulator/file_system.hpp +++ b/src/windows-emulator/file_system.hpp @@ -4,28 +4,22 @@ #include -struct working_directory_provider -{ - virtual windows_path get_working_directory() = 0; -}; - class file_system { public: - file_system(std::filesystem::path root, working_directory_provider& working_dir_provider) - : root_(std::move(root)), - working_dir_provider_(&working_dir_provider) + file_system(std::filesystem::path root) + : root_(std::move(root)) { } std::filesystem::path translate(const windows_path& win_path) const { - assert(win_path.is_absolute() && "Path should always be absolute"); - const auto& full_path = win_path.is_absolute() // - ? win_path - : (this->working_dir_provider_->get_working_directory() / win_path); + if (!win_path.is_absolute()) + { + throw std::runtime_error("Only absolute paths can be translated!"); + } - const auto mapping = this->mappings_.find(full_path); + const auto mapping = this->mappings_.find(win_path); if (mapping != this->mappings_.end()) { return mapping->second; @@ -34,19 +28,14 @@ class file_system #ifdef OS_WINDOWS if (this->root_.empty()) { - return full_path.u16string(); + return win_path.u16string(); } #endif // TODO: Sanitize path to prevent traversal! - return this->root_ / full_path.to_portable_path(); + return this->root_ / win_path.to_portable_path(); } - /*const windows_path& get_working_directory() const - { - return this->working_dir_; - }*/ - windows_path local_to_windows_path(const std::filesystem::path& local_path) const { const auto absolute_local_path = absolute(local_path); @@ -84,6 +73,5 @@ class file_system private: std::filesystem::path root_{}; - working_directory_provider* working_dir_provider_{}; std::unordered_map mappings_{}; }; diff --git a/src/windows-emulator/windows_emulator.cpp b/src/windows-emulator/windows_emulator.cpp index b41e0cf6..f5c70926 100644 --- a/src/windows-emulator/windows_emulator.cpp +++ b/src/windows-emulator/windows_emulator.cpp @@ -866,7 +866,7 @@ windows_emulator::windows_emulator(const emulator_settings& settings, emulator_c windows_emulator::windows_emulator(const std::filesystem::path& emulation_root, std::unique_ptr emu) : emulation_root_{emulation_root.empty() ? emulation_root : absolute(emulation_root)}, - file_sys_(emulation_root_.empty() ? emulation_root_ : emulation_root_ / "filesys", *this), + file_sys_(emulation_root_.empty() ? emulation_root_ : emulation_root_ / "filesys"), emu_(std::move(emu)), process_(*emu_, file_sys_) { @@ -942,25 +942,6 @@ bool windows_emulator::activate_thread(const uint32_t id) return switch_to_thread(*this, *thread, true); } -windows_path windows_emulator::get_working_directory() -{ - if (!this->process_.peb) - { - return {}; - } - - const auto peb = this->process_.peb.read(); - if (!peb.ProcessParameters) - { - return {}; - } - - const auto& emu = this->emu(); - - const auto process_params = emu.read_memory(peb.ProcessParameters); - return read_unicode_string(emu, process_params.CurrentDirectory.DosPath); -} - void windows_emulator::on_instruction_execution(const uint64_t address) { auto& process = this->process(); diff --git a/src/windows-emulator/windows_emulator.hpp b/src/windows-emulator/windows_emulator.hpp index fe95dc71..69a17497 100644 --- a/src/windows-emulator/windows_emulator.hpp +++ b/src/windows-emulator/windows_emulator.hpp @@ -48,7 +48,7 @@ enum class apiset_location : uint8_t default_windows_11 }; -class windows_emulator : working_directory_provider +class windows_emulator { public: windows_emulator(const std::filesystem::path& emulation_root, @@ -190,8 +190,6 @@ class windows_emulator : working_directory_provider return this->emulation_root_; } - windows_path get_working_directory() override; - private: std::filesystem::path emulation_root_{}; file_system file_sys_;