Merge pull request #69 from gmh5225/Branch_fix_dep

Solving DEP problem when attaching process
This commit is contained in:
Duncan Ogilvie 2022-07-20 12:21:16 +02:00 committed by GitHub
commit f6896bc22e
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 22 deletions

View File

@ -15,28 +15,6 @@ namespace GleeBug
mProcess->systemBreakpoint = true; mProcess->systemBreakpoint = true;
mContinueStatus = DBG_CONTINUE; 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 //call the callback
cbSystemBreakpoint(); cbSystemBreakpoint();
} }

View File

@ -33,6 +33,28 @@ namespace GleeBug
}); });
mThread = mProcess->thread = mProcess->threads.find(mDebugEvent.dwThreadId)->second.get(); 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 //call the debug event callback
cbCreateProcessEvent(createProcess, *mProcess); cbCreateProcessEvent(createProcess, *mProcess);