Clear software breakpoint records after memory is unmapped

DLL unload events arrive after the image memory is gone. If restoring the original byte fails, allow deletion when VirtualQueryEx confirms the address is free or reserved, so stale breakpoint and callback records cannot block installation after reload.

Keep restoration failures in committed memory and failed memory queries as errors, preserving the breakpoint state for a retry.
This commit is contained in:
Duncan Ogilvie 2026-10-17 21:40:38 +02:00
parent 0ee4126a92
commit b2b68b8a78
1 changed files with 11 additions and 3 deletions

View File

@ -69,9 +69,17 @@ namespace GleeBug
return false; return false;
const auto & info = found->second; const auto & info = found->second;
//restore the breakpoint bytes // Restore the breakpoint bytes if the memory still exists. DLL unload
// events arrive after the image has been unmapped, so there is nothing
// to restore in that case, but the breakpoint records must be removed.
if(!MemWriteUnsafe(address, info.internal.software.oldbytes, info.internal.software.size)) if(!MemWriteUnsafe(address, info.internal.software.oldbytes, info.internal.software.size))
{
MEMORY_BASIC_INFORMATION mbi = {};
if(!VirtualQueryEx(hProcess, LPCVOID(address), &mbi, sizeof(mbi)) ||
(mbi.State != MEM_FREE && mbi.State != MEM_RESERVE))
return false; return false;
}
else
FlushInstructionCache(hProcess, nullptr, 0); FlushInstructionCache(hProcess, nullptr, 0);
recentlyDeletedSwbp.insert(address); recentlyDeletedSwbp.insert(address);