A forum for reverse engineering, OS internals and malware analysis 

Forum for discussion about kernel-mode development.
 #19325  by Stylo
 Sun May 19, 2013 6:52 pm
Well.. i've tried to access the eprocess on my windows 7 x64 machine and when i tried to print the process id i got bsod.
that's the code sample from the driver
Code: Select all
EPROCESS eProcess;
INT iProcess;

eProcess = PsGetCurrentProcess();
iProcess = (INT)eProcess; // that's how i access to eprocess (works on win xp)
DbgPrint("Process Id: %d\r\n", *(INT*)(iProcess + 0x188)); // 0x188 = process id offset on eprocess structure for windows 7 x64
In which method are you using to access the EPROCESS?
 #19329  by r2nwcnydc
 Sun May 19, 2013 10:19 pm
You are casting the pointer to an INT then using the value as a pointer again. On 32 bit this fine, because the pointer is 32 bits long (same as an INT), but on 64 bit it is not. You lose the upper 32 bits of the pointer, and you may even convert the upper 32 bits to 0xffffffff when you convert back to a 64-bit pointer. The below code should work (I have NOT tested it, though).
Code: Select all
PEPROCESS eProcess;
INT* iProcess;

eProcess = PsGetCurrentProcess();
iProcess = (INT*)eProcess; // that's how i access to eprocess (works on win xp)
DbgPrint("Process Id: %d\r\n", *(iProcess + 0x62)); // 0x62 = (0x188/sizeof(INT)) = process id offset on eprocess structure for windows 7 x64
 #19339  by EP_X0FF
 Mon May 20, 2013 9:15 am
@Stylo

1. IDK why from all methods available you decided to use most hardcore, bugged and not portable.
Just a coupe of methods:
a) PsGetProcessId (already mentioned). Even no need type casts.
b) ObReferenceObjectByPointer, ZwQueryInformationProcess (double overhead as you want _current_ process id).
c) Your hardcore method

2. Your offset is incorrect. For all Windows 7 x64 it is:
Code: Select all
+0x180 UniqueProcessId  : Ptr64 
 #19343  by EP_X0FF
 Mon May 20, 2013 2:47 pm
Stylo wrote:Yeah but what if i want to access other fields than process id (like ActiveProcessLinks or token)?
And why do you need this?
 #19345  by EP_X0FF
 Mon May 20, 2013 2:56 pm
Hiding process will lead to delayed BSOD on x64. Overall: if the field cannot be accessed anyhow through kernel mode API, only the way to read/change it - offsets.
 #19352  by Stylo
 Mon May 20, 2013 7:33 pm
EP_X0FF wrote:Hiding process will lead to delayed BSOD on x64.
Really?? How come?!
what will happen if i redirect the Flink / Blink fields at ActiveProcessLinks that should cause BSOD?
EP_X0FF wrote:Overall: if the field cannot be accessed anyhow through kernel mode API, only the way to read/change it - offsets.
I'm trying to access it through it's offset but getting BSOD..
 #19353  by Vrtule
 Mon May 20, 2013 7:49 pm
Really?? How come?!
what will happen if i redirect the Flink / Blink fields at ActiveProcessLinks that should cause BSOD?
I think this list of EPROCESS structures is guarded by Kernel Patch Protection (Patchguard).

Of course, you can read/write some EPROCESS members directly AFAIK. But keep in mind that offsets of the fields can change with new version of Windows or with a new Service Pack. This applies to other kernel data structures as well. For example, there was a quite major change in Object Type structures between Vista and Vista SP1 because of introduction of OB Filtering Model.

And do not cast pointers to ints, use (U)LONG_PTR if you need to treat them as unmbers.