-
Notifications
You must be signed in to change notification settings - Fork 0
/
Offset.cpp
55 lines (47 loc) · 1.25 KB
/
Offset.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <ntddk.h>
#include "Offset.h"
// ntoskrnl.exe는 윈도우 버전과 관계없이 현재까지는 항상 다음과 같은 정보를 가졌음.
// ImageName : System
// PID : 4
// PLIST_ENTRY = PID + sizeof(PID)
extern "C"
ULONG CalcPIDOffset()
{
PEPROCESS peprocess = IoGetCurrentProcess();
HANDLE pid = PsGetCurrentProcessId();
PLIST_ENTRY list = NULL;
int i;
for (i = 0; i < PAGE_SIZE; i += 4)
{
if (*(PHANDLE)((PCHAR)peprocess + i) == pid)
{
// PLIST_ENTRY는 PID 다음에 위치해있음.
list = (PLIST_ENTRY)((unsigned char*)peprocess + i + sizeof(HANDLE));
// 유효한 주소인지 확인한다.
if (MmIsAddressValid(list))
{
// 정상적으로 연결된 리스트인지 확인 후 PID 주소를 반환한다.
if (list == list->Flink->Blink)
{
return i;
}
}
}
}
return 0;
}
extern "C"
ULONG CalcProcessNameOffset()
{
// ntoskrn.exe 의 EPROCESS 구조체 획득
PEPROCESS ntosKrnl = PsInitialSystemProcess;
int i = 0;
for (i = 0; i < PAGE_SIZE; i++)
{
if (RtlCompareMemory((PCHAR)ntosKrnl + i, "System", 6) == 6)
{
return i;
}
}
return 0;
}