c++ - 32位进程在Windows10 x64系统上获取另一个32位进程的PEB失败
问题描述
代码:
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };
WCHAR lpCmdline[] = L"ad.exe";
if (!CreateProcess(
NULL,
lpCmdline,
NULL, NULL, TRUE,
CREATE_SUSPENDED, NULL, NULL, &si, &pi)) {
wprintf(L"Create process fail: %d\n", GetLastError());
return -1;
}
PROCESS_BASIC_INFORMATION pbi = { 0 };
NtQueryInformationProcessFn pNtQueryInformationProcess = (NtQueryInformationProcessFn) \
GetProcAddress(LoadLibrary(L"ntdll"), "NtQueryInformationProcess");
ULONG dwRead;
if (NT_ERROR(pNtQueryInformationProcess(
pi.hProcess, ProcessBasicInformation,
&pbi, sizeof pbi, &dwRead))) {
wprintf(L"Call NtQueryInformationProcess error: %d\n", GetLastError());
return -1;
}
PEB peb = { 0 };
SIZE_T stRead;
if (!ReadProcessMemory(pi.hProcess, pbi.PebBaseAddress, &peb, sizeof PEB, NULL)) {
wprintf(L"Call ReadProcessMemory fail: %d\n", GetLastError());
return -1;
}
return 0;
编译为 x86 二进制文件,ad.exe
也是 x86 二进制文件。系统是Windows10 64位
PS C:\> .\t.exe
Call ReadProcessMemory fail: 6
PS C:\> file .\t.exe
.\t.exe: PE32 executable (console) Intel 80386, for MS Windows
PS C:\> file .\ad.exe
.\ad.exe: PE32 executable (console) Intel 80386, for MS Windows
解决方案
推荐阅读
- python - 使用 conda 时直接链接到 requirements.txt 中的 github
- flutter - Flutter 应用程序错误 - RenderBox 未布置:RenderFlex#0bf43 relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
- python - 在终端上突出显示文件名
- python - 如何更改 ASCII 文件的单元大小、xllcorner 和 yllcorner?
- java - 从类路径中获取所有类,这些类通过 X 的超类继承类 X
- javascript - 为什么使用 requestAnimationFrame 时图像会消失?
- html - 有带角材料的三态切换滑块吗?
- python-attrs - 大致比较用`attrs`定义的类的十进制属性
- html-email - 可以在 MJML 中加入伪元素吗?
- java - Spring Boot @RestController,在反序列化 @RequestBody 中的集合时可以容忍 MismatchedInputException