How to get the Process Environment Block (PEB) from extern process?

后端 未结 1 1446
感动是毒
感动是毒 2020-12-11 06:37

So... I need get the peb from the \"notepad.exe\" process, someone knows how to make it?

I was trying with the \"GetModuleHandle\" API, but... doesn\'t returns me th

相关标签:
1条回答
  • 2020-12-11 07:01

    Matt Pietrek described how to do that in a 1994 Under the Hood column. It was about how to get the environment variables of another process, where the first step is to get a pointer to the PEB. To do that, he says, call NtQueryInformationProcess. The PROCESS_BASIC_INFORMATION structure it fills contains the base address of the PEB structure. (You'll need to use ReadProcessMemory to read it since the address will be in the context of the external process's address space, not yours.)

    To call NtQueryInformationProcess, you'll need a handle to the process. If you started the process yourself (by calling CreateProcess), then you already have a handle. Otherwise, you'll need to find the process ID and then call OpenProcess. To get the process ID, search for the process you want with EnumProcesses or Process32First/Process32Next. (I prefer the latter because it provides more information with less work.)

    0 讨论(0)
提交回复
热议问题