能力值:
( LV2,RANK:10 )
|
-
-
2 楼
要根据进程PID获取进程的PEB,可以使用Windows API中的NtQueryInformationProcess函数。 以下是使用C代码的示例: #include <windows.h>
#include <stdio.h>
typedef NTSTATUS(WINAPI* PNT_QUERY_INFORMATION_PROCESS)(
HANDLE ProcessHandle,
PROCESSINFOCLASS ProcessInformationClass,
PVOID ProcessInformation,
ULONG ProcessInformationLength,
PULONG ReturnLength
);
void PrintLastError(DWORD error) {
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)& lpMsgBuf, 0, NULL);
printf("Error: %s", (LPCTSTR)lpMsgBuf);
LocalFree(lpMsgBuf);
}
DWORD_PTR GetPebAddress(DWORD PID) {
DWORD_PTR pebAddress = 0;
HMODULE ntdll = LoadLibraryA("ntdll.dll");
PNT_QUERY_INFORMATION_PROCESS NtQueryInformationProcess =
(PNT_QUERY_INFORMATION_PROCESS)GetProcAddress(ntdll, "NtQueryInformationProcess");
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, PID);
if (hProcess != NULL) {
PROCESS_BASIC_INFORMATION pbi;
ULONG returnLength;
NTSTATUS status = NtQueryInformationProcess(hProcess, ProcessBasicInformation, (PVOID)& pbi, sizeof(PROCESS_BASIC_INFORMATION), & returnLength);
if (status == STATUS_SUCCESS) {
pebAddress = (DWORD_PTR)pbi.PebBaseAddress;
}
else {
PrintLastError(status);
}
CloseHandle(hProcess);
}
FreeLibrary(ntdll);
return pebAddress;
}
int main() {
DWORD PID = 1234; // Replace with the PID of the process you want to query
DWORD_PTR pebAddress = GetPebAddress(PID);
if (pebAddress == 0) {
printf("Failed to get PEB address for process %ld", PID);
}
else {
printf("PEB address for process %ld: 0x%p", PID, (LPVOID)pebAddress);
}
return 0;
}
在此示例中,GetPebAddress函数接受进程的PID,使用NtQueryInformationProcess函数获取进程基本信息,然后返回PEB的地址。注意确保已将Windows.h和stdio.h包含在代码中,并将PID替换为要查询的进程PID。
|
能力值:
( LV6,RANK:90 )
|
-
-
3 楼
PsLookupProcessByProcessId PsGetProcessPeb/PsGetProcessWow64Process
|
能力值:
( LV13,RANK:385 )
|
-
-
4 楼
分RING3还是RING0. RING3: NtQueryInformationProcess 使用功能号 ProcessBasicInformation (1楼AI回答还是准确的) RING0: PsGetProcessPeb(驱动如果是32位,那么获取的PEB就是32位的,驱动如果是64位,那么获取的PEB就是64位的) 如何在64位驱动下获取32位进程PEB. 需要使用API PsGetProcessWow64Process
最后于 2023-4-19 17:00
被TkBinary编辑
,原因:
|
能力值:
( LV5,RANK:68 )
|
-
-
5 楼
经典AI答题
|
|
|