我试图通过一个进程的模块枚举它来获取它运行的内存地址范围。这个函数可以很好地处理其他进程。但是,在我打算分析的特定进程中,我得到错误代码5,ERROR_ACCESS_DENIED。请注意,在位置1,我得到错误代码0,在位置2,我得到错误代码5.我知道可以保护一些内核对象,这可以解释这个错误代码。这是什么原因?如果是这样,是否可以解决这个问题?
int PrintModules(DWORD processID)
{
HMODULE hMods[1024];
HANDLE hProcess;
DWORD cbNeeded;
unsigned int i;
// Print the process identifier.
printf("\nProcess ID: %u\n", processID);
// Get a handle to the process.
hProcess = OpenProcess(PROCESS_ALL_ACCESS,
FALSE, processID);
std::cout << "POSITION 1 : " << GetLastError() << std::endl;
if (NULL == hProcess)
{
return 1;
}
// Get a list of all the modules in this process.
if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
{
for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++)
{
TCHAR szModName[MAX_PATH];
// Get the full path to the module's file.
if (GetModuleFileNameEx(hProcess, hMods[i], szModName,
sizeof(szModName) / sizeof(TCHAR)))
{
// Print the module name and handle value.
_tprintf(TEXT("\t%s (0x%08X)\n"), szModName, hMods[i]);
}
}
}
else {
std::cout << "POSITION 2 : " <<GetLastError() << std::endl;
}
// Release the handle to the process.
CloseHandle(hProcess);
return 0;
}
答案 0 :(得分:0)
ERROR_ACCESS_DENIED表示您的句柄无效。出于两个原因之一,您在调用OpenProcess时会得到无效的句柄。
您的进程ID错误或您没有以管理员身份运行。您需要以管理员身份运行才能获得PROCESS_ALL_ACCESS权限。