From 4cd098626e76c433a2d772d20ab158f108e78b74 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 25 Jan 2025 08:09:00 +0100 Subject: [PATCH] Support host/default apiset loc and empty emulation root --- src/windows-emulator/file_system.hpp | 18 +++++++++++++----- src/windows-emulator/windows_emulator.cpp | 16 ++++++++++++---- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/windows-emulator/file_system.hpp b/src/windows-emulator/file_system.hpp index a9a1e237..8f8e46b0 100644 --- a/src/windows-emulator/file_system.hpp +++ b/src/windows-emulator/file_system.hpp @@ -2,6 +2,8 @@ #include "std_include.hpp" #include "windows_path.hpp" +#include + class file_system { public: @@ -13,12 +15,18 @@ class file_system std::filesystem::path translate(const windows_path& win_path) const { - if (win_path.is_absolute()) - { - return this->root_ / win_path.to_portable_path(); - } + const auto& full_path = win_path.is_absolute() // + ? win_path + : (this->working_dir_ / win_path); - return this->root_ / (this->working_dir_ / win_path).to_portable_path(); +#ifdef OS_WINDOWS + if (this->root_.empty()) + { + return full_path.u16string(); + } +#endif + + return this->root_ / full_path.to_portable_path(); } void set_working_directory(windows_path working_dir) diff --git a/src/windows-emulator/windows_emulator.cpp b/src/windows-emulator/windows_emulator.cpp index f944849e..168f17a4 100644 --- a/src/windows-emulator/windows_emulator.cpp +++ b/src/windows-emulator/windows_emulator.cpp @@ -151,7 +151,7 @@ namespace { #ifdef OS_WINDOWS case apiset_location::host: { - auto apiSetMap = + const auto apiSetMap = reinterpret_cast(NtCurrentTeb64()->ProcessEnvironmentBlock->ApiSetMap); const auto* dataPtr = reinterpret_cast(apiSetMap); std::vector buffer(dataPtr, dataPtr + apiSetMap->Size); @@ -162,7 +162,7 @@ namespace throw std::runtime_error("The APISET host location is not supported on this platform"); #endif case apiset_location::file: { - auto apiset = utils::io::read_file(root / "api-set.bin"); + const auto apiset = utils::io::read_file(root / "api-set.bin"); if (apiset.empty()) throw std::runtime_error("Failed to read file api-set.bin"); return decompress_apiset(apiset); @@ -278,8 +278,16 @@ namespace proc_params.MaximumLength = proc_params.Length; }); - // TODO: make this configurable - const apiset_location apiset_loc = apiset_location::file; + apiset_location apiset_loc = apiset_location::file; + + if (win_emu.root_directory.empty()) + { +#ifdef OS_WINDOWS + apiset_loc = apiset_location::host; +#else + apiset_loc = apiset_location::default_windows_11; +#endif + } context.peb.access([&](PEB64& peb) { peb.ImageBaseAddress = nullptr;