Fix module logging

This commit is contained in:
momo5502
2025-06-07 07:11:27 +02:00
parent bc77faec3d
commit 9372e27453
4 changed files with 16 additions and 7 deletions

View File

@@ -63,6 +63,17 @@ namespace
debugger::handle_events(ec);
#endif
}
void handle_module_load(const analysis_context& c, const mapped_module& mod)
{
c.win_emu->log.log("Mapped %s at 0x%" PRIx64 "\n", mod.path.generic_string().c_str(), mod.image_base);
}
void handle_module_unload(const analysis_context& c, const mapped_module& mod)
{
c.win_emu->log.log("Unmapping %s (0x%" PRIx64 ")\n", mod.path.generic_string().c_str(), mod.image_base);
}
void handle_instruction(analysis_context& c, const uint64_t address)
{
auto& win_emu = *c.win_emu;
@@ -200,6 +211,8 @@ void register_analysis_callbacks(analysis_context& c)
cb.on_stdout = make_callback(c, handle_stdout);
cb.on_syscall = make_callback(c, handle_syscall);
cb.on_ioctrl = make_callback(c, handle_ioctrl);
cb.on_module_load = make_callback(c, handle_module_load);
cb.on_module_unload = make_callback(c, handle_module_unload);
cb.on_instruction = make_callback(c, handle_instruction);
cb.on_thread_switch = make_callback(c, handle_thread_switch);
cb.on_generic_access = make_callback(c, handle_generic_access);

View File

@@ -122,8 +122,6 @@ mapped_module* module_manager::map_local_module(const std::filesystem::path& fil
auto mod = map_module_from_file(*this->memory_, std::move(local_file));
mod.is_static = is_static;
logger.log("Mapped %s at 0x%" PRIx64 "\n", mod.path.generic_string().c_str(), mod.image_base);
const auto image_base = mod.image_base;
const auto entry = this->modules_.try_emplace(image_base, std::move(mod));
this->callbacks_->on_module_load(entry.first->second);
@@ -163,7 +161,7 @@ void module_manager::deserialize(utils::buffer_deserializer& buffer)
this->win32u = win32u_base ? this->find_by_address(win32u_base) : nullptr;
}
bool module_manager::unmap(const uint64_t address, const logger& logger)
bool module_manager::unmap(const uint64_t address)
{
const auto mod = this->modules_.find(address);
if (mod == this->modules_.end())
@@ -176,8 +174,6 @@ bool module_manager::unmap(const uint64_t address, const logger& logger)
return true;
}
logger.log("Unmapping %s (0x%" PRIx64 ")\n", mod->second.path.generic_string().c_str(), mod->second.image_base);
this->callbacks_->on_module_unload(mod->second);
unmap_module(*this->memory_, mod->second);
this->modules_.erase(mod);

View File

@@ -51,7 +51,7 @@ class module_manager
void serialize(utils::buffer_serializer& buffer) const;
void deserialize(utils::buffer_deserializer& buffer);
bool unmap(uint64_t address, const logger& logger);
bool unmap(uint64_t address);
const module_map& modules() const
{
return modules_;

View File

@@ -287,7 +287,7 @@ namespace syscalls
const auto* mod = c.win_emu.mod_manager.find_by_address(base_address);
if (mod != nullptr)
{
if (c.win_emu.mod_manager.unmap(base_address, c.win_emu.log))
if (c.win_emu.mod_manager.unmap(base_address))
{
return STATUS_SUCCESS;
}