Prepare filesystem support

This commit is contained in:
momo5502
2025-01-21 18:00:11 +01:00
parent 739cbbf549
commit 24bebc4ee2
11 changed files with 145 additions and 53 deletions

View File

@@ -5,18 +5,7 @@
namespace
{
std::filesystem::path canonicalize_module_path(const std::filesystem::path& file)
{
constexpr std::u16string_view nt_prefix = u"\\??\\";
const auto wide_file = file.u16string();
if (!wide_file.starts_with(nt_prefix))
{
return canonical(absolute(file));
}
return canonicalize_module_path(wide_file.substr(nt_prefix.size()));
}
}
namespace utils
@@ -64,26 +53,32 @@ namespace utils
}
}
module_manager::module_manager(emulator& emu)
: emu_(&emu)
module_manager::module_manager(emulator& emu, file_system& file_sys)
: emu_(&emu),
file_sys_(&file_sys)
{
}
mapped_module* module_manager::map_module(const std::filesystem::path& file, logger& logger)
mapped_module* module_manager::map_module(const std::filesystem::path& file, const logger& logger)
{
auto canonical_file = canonicalize_module_path(file);
return this->map_local_module(this->file_sys_->translate(file), logger);
}
for (auto& mod : this->modules_)
mapped_module* module_manager::map_local_module(const std::filesystem::path& file, const logger& logger)
{
auto local_file = canonical(absolute(file));
for (auto& mod : this->modules_ | std::views::values)
{
if (mod.second.path == canonical_file)
if (mod.path == file)
{
return &mod.second;
return &mod;
}
}
try
{
auto mod = map_module_from_file(*this->emu_, std::move(canonical_file));
auto mod = map_module_from_file(*this->emu_, std::move(local_file));
logger.log("Mapped %s at 0x%" PRIx64 "\n", mod.path.generic_string().c_str(), mod.image_base);

View File

@@ -1,16 +1,19 @@
#pragma once
#include "mapped_module.hpp"
#include <emulator.hpp>
#include "mapped_module.hpp"
#include "../file_system.hpp"
class logger;
class module_manager
{
public:
using module_map = std::map<uint64_t, mapped_module>;
module_manager(emulator& emu);
module_manager(emulator& emu, file_system& file_sys);
mapped_module* map_module(const std::filesystem::path& file, logger& logger);
mapped_module* map_module(const std::filesystem::path& file, const logger& logger);
mapped_module* map_local_module(const std::filesystem::path& file, const logger& logger);
mapped_module* find_by_address(const uint64_t address)
{
@@ -45,6 +48,7 @@ class module_manager
private:
emulator* emu_{};
file_system* file_sys_{};
module_map modules_{};