Fix running relative applications

This commit is contained in:
momo5502
2025-02-08 17:52:11 +01:00
parent 7efe75ba97
commit 9f4a80b42e
2 changed files with 10 additions and 5 deletions

View File

@@ -209,7 +209,7 @@ namespace
emu.reg<uint16_t>(x64_register::ss, 0x2B);
}
void setup_context(windows_emulator& win_emu, const emulator_settings& settings,
void setup_context(windows_emulator& win_emu, const emulator_settings& settings, const windows_path& application,
const windows_path& working_directory)
{
auto& emu = win_emu.emu();
@@ -259,7 +259,7 @@ namespace
allocator.copy_string(u"SystemRoot=C:\\WINDOWS");
allocator.copy_string(u"");
const auto application_str = settings.application.u16string();
const auto application_str = application.u16string();
std::u16string command_line = u"\"" + application_str + u"\"";
@@ -889,9 +889,13 @@ void windows_emulator::setup_process(const emulator_settings& settings, const wi
auto& context = this->process();
context.mod_manager = module_manager(emu, this->file_sys()); // TODO: Cleanup module manager
setup_context(*this, settings, working_directory);
const auto application = settings.application.is_absolute() //
? settings.application
: (working_directory / settings.application);
context.executable = context.mod_manager.map_module(settings.application, this->log, true);
setup_context(*this, settings, application, working_directory);
context.executable = context.mod_manager.map_module(application, this->log, true);
context.peb.access([&](PEB64& peb) {
peb.ImageBaseAddress = reinterpret_cast<std::uint64_t*>(context.executable->image_base); //

View File

@@ -74,7 +74,8 @@ class windows_path
}
template <typename T>
requires(!std::is_same_v<T, windows_path> && !std::is_same_v<T, std::filesystem::path>)
requires(!std::is_same_v<std::remove_cvref_t<T>, windows_path> &&
!std::is_same_v<std::remove_cvref_t<T>, std::filesystem::path>)
windows_path(T&& path_like)
: windows_path(std::filesystem::path(std::forward<T>(path_like)))
{