From 9bd5c380e5e0490b68ce899d2fca190d9a63ceba Mon Sep 17 00:00:00 2001 From: gmh5225 <2315157@qq.com> Date: Sun, 3 Jul 2022 21:53:09 +0800 Subject: [PATCH] Solving "What happens if you hit a breakpoint before a system breakpoint" --- GleeBug/Debugger.Loop.Exception.cpp | 22 ---------------------- GleeBug/Debugger.Loop.Process.cpp | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/GleeBug/Debugger.Loop.Exception.cpp b/GleeBug/Debugger.Loop.Exception.cpp index f104b75..c4c515b 100644 --- a/GleeBug/Debugger.Loop.Exception.cpp +++ b/GleeBug/Debugger.Loop.Exception.cpp @@ -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(); } diff --git a/GleeBug/Debugger.Loop.Process.cpp b/GleeBug/Debugger.Loop.Process.cpp index 5819983..a652091 100644 --- a/GleeBug/Debugger.Loop.Process.cpp +++ b/GleeBug/Debugger.Loop.Process.cpp @@ -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);