Solving "What happens if you hit a breakpoint before a system breakpoint"

This commit is contained in:
gmh5225 2022-07-03 21:53:09 +08:00
parent 69be313fac
commit 9bd5c380e5
No known key found for this signature in database
GPG Key ID: 3BBC731F40B2CEC1
2 changed files with 22 additions and 22 deletions

View File

@ -15,28 +15,6 @@ namespace GleeBug
mProcess->systemBreakpoint = true;
mContinueStatus = DBG_CONTINUE;
//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*/,
_Out_ LPDWORD /*lpFlags*/,
_Out_ PBOOL /*lpPermanent*/
);
static auto GPDP = GETPROCESSDEPPOLICY(GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "GetProcessDEPPolicy"));
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))
mProcess->permanentDep = lpFlags != 0 && bPermanent;
CloseHandle(hProcess);
}
#else
mProcess->permanentDep = true;
#endif //_WIN64
//call the callback
cbSystemBreakpoint();
}

View File

@ -33,6 +33,28 @@ namespace GleeBug
});
mThread = mProcess->thread = mProcess->threads.find(mDebugEvent.dwThreadId)->second.get();
//get process DEP policy
#ifndef _WIN64
typedef BOOL(WINAPI * GETPROCESSDEPPOLICY)(
_In_ HANDLE /*hProcess*/,
_Out_ LPDWORD /*lpFlags*/,
_Out_ PBOOL /*lpPermanent*/
);
static auto GPDP = GETPROCESSDEPPOLICY(GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "GetProcessDEPPolicy"));
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))
mProcess->permanentDep = lpFlags != 0 && bPermanent;
CloseHandle(hProcess);
}
#else
mProcess->permanentDep = true;
#endif //_WIN64
//call the debug event callback
cbCreateProcessEvent(createProcess, *mProcess);