Support host/default apiset loc and empty emulation root

This commit is contained in:
momo5502
2025-01-25 08:09:00 +01:00
parent 0454120f45
commit 4cd098626e
2 changed files with 25 additions and 9 deletions

View File

@@ -2,6 +2,8 @@
#include "std_include.hpp"
#include "windows_path.hpp"
#include <platform/compiler.hpp>
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)

View File

@@ -151,7 +151,7 @@ namespace
{
#ifdef OS_WINDOWS
case apiset_location::host: {
auto apiSetMap =
const auto apiSetMap =
reinterpret_cast<const API_SET_NAMESPACE*>(NtCurrentTeb64()->ProcessEnvironmentBlock->ApiSetMap);
const auto* dataPtr = reinterpret_cast<const uint8_t*>(apiSetMap);
std::vector<uint8_t> 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;