mirror of https://github.com/x64dbg/GleeBug
correctly handle breakpoints happening before the system breakpoint
This commit is contained in:
parent
2dd2cb1e3d
commit
7dc011516d
|
|
@ -4,13 +4,17 @@ namespace GleeBug
|
|||
{
|
||||
void Debugger::exceptionBreakpoint(const EXCEPTION_RECORD & exceptionRecord, const bool firstChance)
|
||||
{
|
||||
if (!mProcess->systemBreakpoint) //handle system breakpoint
|
||||
//check if the breakpoint exists
|
||||
auto foundInfo = mProcess->breakpoints.find({ BreakpointType::Software, ptr(exceptionRecord.ExceptionAddress) });
|
||||
if(foundInfo == mProcess->breakpoints.end())
|
||||
{
|
||||
if(!mProcess->systemBreakpoint) //handle system breakpoint
|
||||
{
|
||||
//set internal state
|
||||
mProcess->systemBreakpoint = true;
|
||||
mContinueStatus = DBG_CONTINUE;
|
||||
|
||||
//get process DEP policy
|
||||
//get process DEP policy (TODO: what happens if a breakpoint is hit before the system breakpoint?)
|
||||
#ifndef _WIN64
|
||||
typedef BOOL(WINAPI * GETPROCESSDEPPOLICY)(
|
||||
_In_ HANDLE /*hProcess*/,
|
||||
|
|
@ -18,13 +22,13 @@ namespace GleeBug
|
|||
_Out_ PBOOL /*lpPermanent*/
|
||||
);
|
||||
static auto GPDP = GETPROCESSDEPPOLICY(GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "GetProcessDEPPolicy"));
|
||||
if (GPDP)
|
||||
if(GPDP)
|
||||
{
|
||||
//If you use mProcess->hProcess GetProcessDEPPolicy will put garbage in bPermanent.
|
||||
auto hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, mProcess->dwProcessId);
|
||||
DWORD lpFlags;
|
||||
BOOL bPermanent;
|
||||
if (GPDP(hProcess, &lpFlags, &bPermanent))
|
||||
if(GPDP(hProcess, &lpFlags, &bPermanent))
|
||||
mProcess->permanentDep = lpFlags != 0 && bPermanent;
|
||||
CloseHandle(hProcess);
|
||||
}
|
||||
|
|
@ -35,12 +39,9 @@ namespace GleeBug
|
|||
//call the callback
|
||||
cbSystemBreakpoint();
|
||||
}
|
||||
else
|
||||
{
|
||||
//check if the breakpoint exists
|
||||
auto foundInfo = mProcess->breakpoints.find({ BreakpointType::Software, ptr(exceptionRecord.ExceptionAddress) });
|
||||
if (foundInfo == mProcess->breakpoints.end())
|
||||
return;
|
||||
}
|
||||
|
||||
const auto info = foundInfo->second;
|
||||
|
||||
//set continue status
|
||||
|
|
@ -54,7 +55,7 @@ namespace GleeBug
|
|||
mThread->StepInternal(std::bind([this, info]()
|
||||
{
|
||||
//only restore the bytes if the breakpoint still exists
|
||||
if (mProcess->breakpoints.find({ BreakpointType::Software, info.address }) != mProcess->breakpoints.end())
|
||||
if(mProcess->breakpoints.find({ BreakpointType::Software, info.address }) != mProcess->breakpoints.end())
|
||||
mProcess->MemWriteUnsafe(info.address, info.internal.software.newbytes, info.internal.software.size);
|
||||
}));
|
||||
|
||||
|
|
@ -63,14 +64,13 @@ namespace GleeBug
|
|||
|
||||
//call the user callback
|
||||
auto foundCallback = mProcess->breakpointCallbacks.find({ BreakpointType::Software, info.address });
|
||||
if (foundCallback != mProcess->breakpointCallbacks.end())
|
||||
if(foundCallback != mProcess->breakpointCallbacks.end())
|
||||
foundCallback->second(info);
|
||||
|
||||
//delete the breakpoint if it is singleshoot
|
||||
if (info.singleshoot)
|
||||
if(info.singleshoot)
|
||||
mProcess->DeleteGenericBreakpoint(info);
|
||||
}
|
||||
}
|
||||
|
||||
void Debugger::exceptionSingleStep(const EXCEPTION_RECORD & exceptionRecord, const bool firstChance)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue