From bff2775e7a778ce95d746f8317586c4317ea217a Mon Sep 17 00:00:00 2001 From: mrexodia Date: Fri, 19 Aug 2016 16:02:06 +0200 Subject: [PATCH] fixed DEP policy query (documentation of GetProcessDEPPolicy is total bullshit for x64) --- GleeBug/Debugger.Loop.Exception.cpp | 21 ++++++++++++++++++++- GleeBug/Debugger.Process.cpp | 19 ------------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/GleeBug/Debugger.Loop.Exception.cpp b/GleeBug/Debugger.Loop.Exception.cpp index 4c5a0bd..b9db2ed 100644 --- a/GleeBug/Debugger.Loop.Exception.cpp +++ b/GleeBug/Debugger.Loop.Exception.cpp @@ -10,6 +10,25 @@ namespace GleeBug mProcess->systemBreakpoint = true; mContinueStatus = DBG_CONTINUE; + //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) + { + DWORD lpFlags; + BOOL bPermanent; + if (GPDP(mProcess->hProcess, &lpFlags, &bPermanent)) + mProcess->permanentDep = lpFlags && bPermanent; + } +#else + mProcess->permanentDep = true; +#endif //_WIN64 + //call the callback cbSystemBreakpoint(); } @@ -155,7 +174,7 @@ namespace GleeBug //call the debug event callback cbExceptionEvent(exceptionInfo); - //dispatch the exception + //dispatch the exception (https://msdn.microsoft.com/en-us/library/windows/desktop/aa363082(v=vs.85).aspx) switch (exceptionInfo.ExceptionRecord.ExceptionCode) { case STATUS_BREAKPOINT: diff --git a/GleeBug/Debugger.Process.cpp b/GleeBug/Debugger.Process.cpp index 0a51fd9..1b0ba6d 100644 --- a/GleeBug/Debugger.Process.cpp +++ b/GleeBug/Debugger.Process.cpp @@ -13,25 +13,6 @@ namespace GleeBug { for (int i = 0; i < HWBP_COUNT; i++) hardwareBreakpoints[i].enabled = false; - - // DEP is disabled if lpFlagsDep == 0 - 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) - { - DWORD lpFlags; - BOOL bPermanent; - if (GPDP(hProcess, &lpFlags, &bPermanent)) - permanentDep = lpFlags && bPermanent; -#ifdef _WIN64 - else if (GetLastError() == ERROR_NOT_SUPPORTED) - permanentDep = true; -#endif - } } void Process::StepOver(const StepCallback & cbStep)