-
Notifications
You must be signed in to change notification settings - Fork 5
/
el_win_structs.cpp
164 lines (115 loc) · 3.75 KB
/
el_win_structs.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
// el_win_structs.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "./el_win_structs.h"
typedef LONG (WINAPI *NTQIP)(HANDLE, ELPROCESS_INFORMATION_CLASS, PVOID, ULONG, PULONG);
PELPEB EL_GetPeb()
{
ELPEB *peb = (ELPEB *) 0x7ffdf000;
ELPROCESS_BASIC_INFORMATION tPbi;
NTQIP NtQueryInfoProcess = NULL;
DWORD tSize;
HMODULE tNtDll = LoadLibrary( "ntdll.dll" );
if( tNtDll == NULL )
return NULL;
NtQueryInfoProcess = (NTQIP) GetProcAddress( tNtDll, "NtQueryInformationProcess" );
if( NtQueryInfoProcess == NULL )
return NULL;
HANDLE tProc = GetCurrentProcess();
NtQueryInfoProcess( tProc, ProcessBasicInformation, &tPbi, sizeof( tPbi ), &tSize );
peb = (ELPEB *) tPbi.PebBaseAddress;
return peb;
}
DWORD EL_PrintModules( PELPEB peb )
{
if( peb == NULL )
{
return 0;
}
//printf( "Image Base: 0x%x\n", peb->ImageBaseAddress );
//printf( "Current Dir: %s\n", peb->ProcessParameters->CurrentDirectoryPath.Buffer );
//walk module list
//load order
//printf( "Load Order\n" );
PELLIST_ENTRY tLinkEntry = (PELLIST_ENTRY)&peb->LoaderData->InLoadOrderModuleList;
PELLIST_ENTRY tHead = tLinkEntry;
do
{
tLinkEntry = tLinkEntry->Flink;
ELLDR_MODULE *tTmp = (ELLDR_MODULE *)tLinkEntry;
//wprintf( L"\tMODULE: %s\n", tTmp->BaseDllName.Buffer );
}while( tLinkEntry->Flink != tHead );
//printf( "Init Order\n" );
tLinkEntry = (PELLIST_ENTRY)&peb->LoaderData->InInitializationOrderModuleList;
tHead = tLinkEntry;
do
{
tLinkEntry = tLinkEntry->Flink;
ELLDR_MODULE *tTmp = (ELLDR_MODULE *)( (DWORD)tLinkEntry - sizeof( ELLIST_ENTRY ) * 2 );
//wprintf( L"\tMODULE: %s\n", tTmp->BaseDllName.Buffer );
}while( tLinkEntry->Flink != tHead );
//printf( "Memory Order\n" );
tLinkEntry = (PELLIST_ENTRY)&peb->LoaderData->InMemoryOrderModuleList;
tHead = tLinkEntry;
do
{
tLinkEntry = tLinkEntry->Flink;
ELLDR_MODULE *tTmp = (ELLDR_MODULE *)( (DWORD)tLinkEntry - sizeof( ELLIST_ENTRY ) );
//wprintf( L"\tMODULE: %s\n", tTmp->BaseDllName.Buffer );
}while( tLinkEntry->Flink != tHead );
return 1;
}
DWORD EL_HideModule( PELPEB peb, const wchar_t *dll )
{
if( peb == NULL || dll == NULL )
{
return 0;
}
//walk module list
//load order
DWORD tOffSet = 0x00;
PELLIST_ENTRY tLinkEntry = (PELLIST_ENTRY)&peb->LoaderData->InLoadOrderModuleList;
PELLIST_ENTRY tHead = tLinkEntry;
do
{
tLinkEntry = tLinkEntry->Flink;
ELLDR_MODULE *tTmp = (ELLDR_MODULE *)tLinkEntry;
if( wcsstr( tTmp->BaseDllName.Buffer, dll ) != 0 )
{
tLinkEntry->Blink->Flink = tLinkEntry->Flink;
tLinkEntry->Flink->Blink = tLinkEntry->Blink;
tTmp->HashTableEntry.Blink->Flink = tTmp->HashTableEntry.Flink;
tTmp->HashTableEntry.Flink->Blink = tTmp->HashTableEntry.Blink;
break;
}
}while( tLinkEntry->Flink != tHead );
tLinkEntry = (PELLIST_ENTRY)&peb->LoaderData->InInitializationOrderModuleList;
tHead = tLinkEntry;
do
{
tLinkEntry = tLinkEntry->Flink;
ELLDR_MODULE *tTmp = (ELLDR_MODULE *)( (DWORD)tLinkEntry - sizeof( ELLIST_ENTRY ) * 2 );
if( wcsstr( tTmp->BaseDllName.Buffer, dll ) != 0 )
{
tLinkEntry->Blink->Flink = tLinkEntry->Flink;
tLinkEntry->Flink->Blink = tLinkEntry->Blink;
break;
}
}while( tLinkEntry->Flink != tHead );
tLinkEntry = (PELLIST_ENTRY)&peb->LoaderData->InMemoryOrderModuleList;
tHead = tLinkEntry;
do
{
tLinkEntry = tLinkEntry->Flink;
ELLDR_MODULE *tTmp = (ELLDR_MODULE *)( (DWORD)tLinkEntry - sizeof( ELLIST_ENTRY ) );
if( wcsstr( tTmp->BaseDllName.Buffer, dll ) != 0 )
{
tLinkEntry->Blink->Flink = tLinkEntry->Flink;
tLinkEntry->Flink->Blink = tLinkEntry->Blink;
memset( tTmp->FullDllName.Buffer, 0, tTmp->FullDllName.Length );
memset( tTmp, 0, sizeof( ELLDR_MODULE ) );
break;
}
}while( tLinkEntry->Flink != tHead );
return 1;
}