diff --git a/src/dbg/breakpoint.cpp b/src/dbg/breakpoint.cpp index 31c3ef46..93ad4f19 100644 --- a/src/dbg/breakpoint.cpp +++ b/src/dbg/breakpoint.cpp @@ -152,6 +152,13 @@ bool BpEnable(duint Address, BP_TYPE Type, bool Enable) return false; bpInfo->enabled = Enable; + + //Re-read oldbytes + if (Enable && Type == BPNORMAL) + { + if (!MemRead(Address, &bpInfo->oldbytes, sizeof(bpInfo->oldbytes))) + return false; + } return true; } diff --git a/src/dbg/debugger.cpp b/src/dbg/debugger.cpp index 6d8d268b..3c05b6ca 100644 --- a/src/dbg/debugger.cpp +++ b/src/dbg/debugger.cpp @@ -522,8 +522,22 @@ bool cbSetModuleBreakpoints(const BREAKPOINT* bp) { case BPNORMAL: { - if(!SetBPX(bp->addr, bp->titantype, (void*)cbUserBreakpoint)) - dprintf("Could not set breakpoint " fhex "! (SetBPX)\n", bp->addr); + unsigned short oldbytes; + if (MemRead(bp->addr, &oldbytes, sizeof(oldbytes))) + { + if (oldbytes != bp->oldbytes) + { + dprintf("Breakpoint " fhex " has been disabled because the bytes don't match! Expected: %02X %02X, Found: %02X %02X\n", + bp->addr, + ((unsigned char*)&bp->oldbytes)[0], ((unsigned char*)&bp->oldbytes)[1], + ((unsigned char*)&oldbytes)[0], ((unsigned char*)&oldbytes)[1]); + BpEnable(bp->addr, BPNORMAL, false); + } + else if (!SetBPX(bp->addr, bp->titantype, (void*)cbUserBreakpoint)) + dprintf("Could not set breakpoint " fhex "! (SetBPX)\n", bp->addr); + } + else + dprintf("MemRead failed on breakpoint address" fhex "!\n", bp->addr); } break;