-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathXHideDll.cpp
167 lines (114 loc) · 3.53 KB
/
XHideDll.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//
//Author:Xjun
//
//#include "stdafx.h"
#include "XHideDll.h"
XHideDll::XHideDll()
{
}
XHideDll::~XHideDll()
{
}
PVOID XHideDll::GetProcessPEB()
{
#ifdef _WIN64
return (PVOID)__readgsqword(0x60);
#else
return (PVOID)__readfsdword(0x30);
#endif
}
BOOL XHideDll::HideInLoadOrderLinks(HMODULE dllBase)
{
BOOL r = FALSE;
PPEB peb = (PPEB)GetProcessPEB();
PLIST_ENTRY OrderModuleHead, OrderModuleTail;
PLDR_DATA_TABLE_ENTRY pLdrDataEntry = NULL;
OrderModuleHead = OrderModuleTail = peb->Ldr->InLoadOrderModuleList.Blink;
do
{
pLdrDataEntry = (PLDR_DATA_TABLE_ENTRY)CONTAINING_RECORD(OrderModuleHead, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
if (pLdrDataEntry->DllBase == NULL)
{
break;
}
// _tprintf(_T("DLLBase:%p Size:%08X ShortName:%s FullName:%s\n\n"), pLdrDataEntry->DllBase, pLdrDataEntry->SizeOfImage,
// pLdrDataEntry->BaseDllName.Buffer, pLdrDataEntry->FullDllName.Buffer);
if (pLdrDataEntry->DllBase == dllBase)
{
RemoveEntryList(OrderModuleHead);
r = TRUE;
}
OrderModuleHead = OrderModuleHead->Blink;
} while (OrderModuleHead != OrderModuleTail);
// _tprintf(_T("--------------------------------------------------------------\n"));
return r;
}
BOOL XHideDll::HideInMemoryOrderLinks(HMODULE dllBase)
{
BOOL r = FALSE;
PPEB peb = (PPEB)GetProcessPEB();
PLIST_ENTRY OrderModuleHead, OrderModuleTail;
PLDR_DATA_TABLE_ENTRY pLdrDataEntry = NULL;
OrderModuleHead = OrderModuleTail = peb->Ldr->InMemoryOrderModuleList.Blink;
do
{
pLdrDataEntry = (PLDR_DATA_TABLE_ENTRY)CONTAINING_RECORD(OrderModuleHead, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks);
if (pLdrDataEntry->DllBase == NULL)
{
break;
}
// _tprintf(_T("DLLBase:%p Size:%08X ShortName:%s FullName:%s\n\n"), pLdrDataEntry->DllBase, pLdrDataEntry->SizeOfImage,
// pLdrDataEntry->BaseDllName.Buffer, pLdrDataEntry->FullDllName.Buffer);
if (pLdrDataEntry->DllBase == dllBase)
{
RemoveEntryList(OrderModuleHead);
r = TRUE;
}
OrderModuleHead = OrderModuleHead->Blink;
} while (OrderModuleHead != OrderModuleTail);
// _tprintf(_T("--------------------------------------------------------------\n"));
return r;
}
BOOL XHideDll::HideInInitializationOrderLinks(HMODULE dllBase)
{
BOOL r = FALSE;
PPEB peb = (PPEB)GetProcessPEB();
PLIST_ENTRY OrderModuleHead, OrderModuleTail;
PLDR_DATA_TABLE_ENTRY pLdrDataEntry = NULL;
OrderModuleHead = OrderModuleTail = peb->Ldr->InInitializationOrderModuleList.Blink;
do
{
pLdrDataEntry = (PLDR_DATA_TABLE_ENTRY)CONTAINING_RECORD(OrderModuleHead, LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks);
if (pLdrDataEntry->DllBase == NULL)
{
break;
}
// _tprintf(_T("DLLBase:%p Size:%08X ShortName:%s FullName:%s\n\n"), pLdrDataEntry->DllBase, pLdrDataEntry->SizeOfImage,
// pLdrDataEntry->BaseDllName.Buffer, pLdrDataEntry->FullDllName.Buffer);
if (pLdrDataEntry->DllBase == dllBase)
{
RemoveEntryList(OrderModuleHead);
r = TRUE;
}
OrderModuleHead = OrderModuleHead->Blink;
} while (OrderModuleHead != OrderModuleTail);
//
_tprintf(_T("--------------------------------------------------------------\n"));
return r;
}
VOID XHideDll::PrintModuleList()
{
HANDLE hSnaphot;
MODULEENTRY32 md32 = { 0 };
BOOL exist;
md32.dwSize = sizeof(md32);
hSnaphot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
exist = Module32First(hSnaphot, &md32);
while (exist)
{
_tprintf(_T("%s\n"), md32.szModule);
exist = Module32Next(hSnaphot, &md32);
}
CloseHandle(hSnaphot);
_tprintf(_T("--------------------------------------------"));
}