当我尝试检查某个进程是否正在使用数据执行保护(DEP)时,我收到错误87(INVALID_PARAMETER)。我检查了我的代码,似乎没问题,但不幸的是我仍然有同样的错误。
代码:
BOOL var = true;
DWORD dwPolicy;
HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, false, 3624);
if (hProc == NULL) {
cout << "Can't open Process because of the error " << GetLastError() << endl;
}
if (GetProcessDEPPolicy(hProc, &dwPolicy, 0) != FALSE) {
if (dwPolicy == PROCESS_DEP_ENABLE) {
cout << "For try.exe process data execution prevention is enabled" << endl;
}
else if (dwPolicy == NULL) {
cout << "For try.exe process data execution prevention is disabled" << endl;
}
else {
cout << "Data is thrunked and we can't change DEP value in future" << endl;
}
}
else {
cout << "There was an error with discovering DEP in try.exe process because of "<<GetLastError() << endl;
}
编译和执行后,我得到:
There was an error with discovering DEP in try.exe process because of 87
答案 0 :(得分:3)
查看文档,定义了函数GetProcessDEPPolicy
:
BOOL WINAPI GetProcessDEPPolicy(
_In_ HANDLE hProcess,
_Out_ LPDWORD lpFlags,
_Out_ PBOOL lpPermanent
);
请注意,最后一个参数是一个out参数,它不是可选的,但你传递的是0 NULL
。电话应该是:
BOOL permanent = FALSE;
if (GetProcessDEPPolicy(hProc, &dwPolicy, &permanent) != FALSE) {