At 11.08 13/06/2002, you wrote:
I’m writing a device driver at kernel mode and I need to know some
informations’ processes like the Image Path Name (in the PEB that is in
the process address space at 0x7FFDF000) but not only that the current
process but also of the other processes which I’ve the handle.
How can I read PEB structure of the other processes?
First of all: you need to use undocumented calls and procedures. Do it at
your own risk. Possibly re-evaluate the problem, ask yourself if there
aren’t better ways to achieve what you need. Don’t do it in a commercial
product, because it will very likely break in future versions of Windows,
or not work at all even in some present and past versions
NtReadVirtualMemory. Since ntoskrnl.exe doesn’t export it, you have to roll
your own. ReactOS (http:</http:>) ntoskrnl’s version reads like
this, it should work, or at least give you enough hints:
NTSTATUS STDCALL
NtReadVirtualMemory(IN HANDLE ProcessHandle,
IN PVOID BaseAddress,
OUT PVOID Buffer,
IN ULONG NumberOfBytesToRead,
OUT PULONG NumberOfBytesRead)
{
NTSTATUS Status;
PMDL Mdl;
PVOID SystemAddress;
PEPROCESS Process;
Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_VM_WRITE,
NULL,
UserMode,
(PVOID*)(&Process),
NULL);
if (Status != STATUS_SUCCESS)
{
return(Status);
}
Mdl = MmCreateMdl(NULL,
Buffer,
NumberOfBytesToRead);
MmProbeAndLockPages(Mdl,
UserMode,
IoWriteAccess);
KeAttachProcess(Process);
SystemAddress = MmGetSystemAddressForMdl(Mdl);
memcpy(SystemAddress, BaseAddress, NumberOfBytesToRead);
KeDetachProcess();
if (Mdl->MappedSystemVa != NULL)
{
MmUnmapLockedPages(Mdl->MappedSystemVa, Mdl);
}
MmUnlockPages(Mdl);
ExFreePool(Mdl);
ObDereferenceObject(Process);
*NumberOfBytesRead = NumberOfBytesToRead;
return(STATUS_SUCCESS);
}
PS: if you also need a definition of all the fields in the PEB, have a look
at ReactOS’s napi/teb.h header:
http://mok.lvcm.com/cgi-bin/reactos/ros-cvs/~checkout~/reactos/include/napi/
teb.h