Fix crashes due to hook deletions (#60)

This commit is contained in:
Maurice Heumann
2025-01-07 18:09:09 +01:00
committed by GitHub
2 changed files with 22 additions and 14 deletions

View File

@@ -27,7 +27,7 @@ namespace
win_emu.emu().hook_memory_write(
win_emu.process().peb.value() + offsetof(PEB64, ProcessParameters), 0x8,
[&, cache_logging](const uint64_t address, size_t, const uint64_t value) {
[&win_emu, cache_logging, params_hook](const uint64_t address, size_t, const uint64_t value) mutable {
const auto target_address = win_emu.process().peb.value() + offsetof(PEB64, ProcessParameters);
if (address == target_address)

View File

@@ -2,6 +2,7 @@
#include <x64_emulator.hpp>
#include "gdb_stub.hpp"
#include "scoped_hook.hpp"
#include <utils/concurrency.hpp>
inline std::vector gdb_registers{
x64_register::rax, x64_register::rbx, x64_register::rcx, x64_register::rdx, x64_register::rsi, x64_register::rdi,
@@ -153,12 +154,15 @@ class x64_gdb_stub_handler : public gdb_stub_handler
{
try
{
this->hooks_[{addr, size, type}] = scoped_hook(
*this->emu_, this->emu_->hook_memory_access(
addr, size, map_breakpoint_type(type),
[this](uint64_t, size_t, uint64_t, memory_operation) { this->on_interrupt(); }));
return this->hooks_.access<bool>([&](hook_map& hooks) {
hooks[{addr, size, type}] = scoped_hook(
*this->emu_, this->emu_->hook_memory_access(addr, size, map_breakpoint_type(type),
[this](uint64_t, size_t, uint64_t, memory_operation) {
this->on_interrupt(); //
}));
return true;
return true;
});
}
catch (...)
{
@@ -170,15 +174,17 @@ class x64_gdb_stub_handler : public gdb_stub_handler
{
try
{
const auto entry = this->hooks_.find({addr, size, type});
if (entry == this->hooks_.end())
{
return false;
}
return this->hooks_.access<bool>([&](hook_map& hooks) {
const auto entry = hooks.find({addr, size, type});
if (entry == hooks.end())
{
return false;
}
this->hooks_.erase(entry);
hooks.erase(entry);
return true;
return true;
});
}
catch (...)
{
@@ -193,5 +199,7 @@ class x64_gdb_stub_handler : public gdb_stub_handler
private:
x64_emulator* emu_{};
std::unordered_map<breakpoint_key, scoped_hook> hooks_{};
using hook_map = std::unordered_map<breakpoint_key, scoped_hook>;
utils::concurrency::container<hook_map> hooks_{};
};