I want to get the PEB from the "notepad.exe" process. Does someone know how to do it?
I tried the GetModuleHandle
API, but it doesn't return a valid pointer (it return zero every time) because I have to be the caller process of that module.
For that reason, I want to know how to get it to work with EnumProcessModules
or CreateToolhelp32Snapshot
.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With