通過PsGetCurrentProcess函數來獲取當前調用驅動的進程的EPROCESS結構的地址.EPROCESS結構的0x174偏移處存放着進程名.
思路如下:
驅動程序的加載函數DriverEntry是運行在System進程中的.
(1) 通過PsGetCurrentProcess可以獲取System進程的內核EPROCESS結構的地址,
(2) 從該地址開始尋找"System"字符串.
(3) 找到了便是EPROCESS的進程名存放的偏移處,得到進程名在EPROCESS結構的偏移后,
(4) 進程調用驅動的時候,就可以直接在該偏移處獲取當前進程名.
代碼如下:
DWORD GetProcessNameOffset()
{
PEPROCESS curproc;
DWORD procNameOffset;
//獲取EPROCESS結構的地址
curproc = PsGetCurrentProcess();
for(int i=0; i< 4096; i++)
{
if( !strncmp( "System", (PCHAR) curproc + i, strlen("System") ))
{
procNameOffset = i;
return procNameOffset;
}
}
return 0;
}