|
2X 계열에서만 유효하며, GetProcessNameOffset 함수를 DriverEntry에서 실행하여(DriverEntry 는 시스템, "System" 프로세스가 호출함)
PEPROCESS 에서 프로세스 명이 위치한 Offset 을 얻어와야 함.
이후 원하는 곳에서 GetProcessName 함수를 사용하여 프로세스 이름을 얻어오면 됨
#define PROCNAMELEN 32
#define NT_PROCNAMELEN 16
ULONG GetProcessNameOffset()
{
PEPROCESS Curprocess;
int i;
//현재 프로세스를 얻어옴
Curprocess = PsGetCurrentProcess();
// Scan for 12KB, hoping the KPEB never grows that big!
//PAGE_SIZE : 4KB
//총 12KB(KPEB 가 12KB 이상에 있을 수 없음)를 스캔하면서 "System" 프로세스 이름이 있는 위치를 찾아냄
for(i = 0; i < 3*PAGE_SIZE; i++)
{
if(!strncmp("System", (PCHAR)Curprocess + i, strlen("System")))
{
return i;
}
}
return 0;
}
PCHARGetProcessName(PCHAR ProcessName)
{
PEPROCESS Curprocess;
char *NamePointer;
ULONG i;
if(gProcessNameOffset != 0)
{
Curprocess = PsGetCurrentProcess();
//현재 얻어진 프로세스에서 ProcessNameOffset 크기 이후에 프로세스 이름이 있음
NamePointer = (PCHAR)Curprocess + gProcessNameOffset;
strncpy(ProcessName, NamePointer, NT_PROCNAMELEN-1 );
ProcessName[NT_PROCNAMELEN-1] = 0;
}
else
{
strcpy(ProcessName, "???");
} return ProcessName;
}
|