Watch interesting system objects

This commit is contained in:
momo5502
2024-12-23 11:15:53 +01:00
parent 86c7886b62
commit 56af439dcd
3 changed files with 48 additions and 6 deletions

View File

@@ -97,7 +97,7 @@ namespace
windows_emulator win_emu{settings};
(void)&watch_system_objects;
//watch_system_objects(win_emu);
watch_system_objects(win_emu);
win_emu.buffer_stdout = true;
//win_emu.verbose_calls = true;

View File

@@ -8,14 +8,24 @@ emulator_hook* watch_object(windows_emulator& emu, emulator_object<T> object)
const reflect_type_info<T> info{};
return emu.emu().hook_memory_read(object.value(), object.size(),
[i = std::move(info), object, &emu](const uint64_t address, size_t, uint64_t)
[i = std::move(info), object, &emu](
const uint64_t address, size_t, uint64_t)
{
const auto rip = emu.emu().read_instruction_pointer();
const auto* mod = emu.process().module_manager.find_by_address(rip);
const auto is_main_access = mod == emu.process().executable;
if (!emu.verbose_calls && !is_main_access)
{
return;
}
const auto offset = address - object.value();
emu.logger.log("Object access: %s - 0x%llX (%s) at 0x%llX (%s)\n", i.get_type_name().c_str(),
offset,
i.get_member_name(offset).c_str(), rip,
emu.process().module_manager.find_name(rip));
emu.logger.print(is_main_access ? color::green : color::dark_gray,
"Object access: %s - 0x%llX (%s) at 0x%llX (%s)\n",
i.get_type_name().c_str(),
offset,
i.get_member_name(offset).c_str(), rip,
mod ? mod->name.c_str() : "<N/A>");
});
}