-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRpcCoreManager.c
303 lines (267 loc) · 10.8 KB
/
RpcCoreManager.c
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#include "RpcCommon\RpcCommon.h"
#include "RpcCore/RpcCore.h"
#include "RpcCommon\Misc.h"
#include <conio.h>
typedef struct _RpcCoreManager_T{
void* pNativeCoreCtxt;
RpcCore_T* pNativeCore;
#ifdef _WIN64
void* pWow64CoreCtxt;
RpcCore_T* pWow64Core;
#endif
}RpcCoreManager_T;
#if 0
// RpcCore
VOID* __fastcall RpcCoreInit(BOOL bForce); //returns a private context for the RpcCoreEngine
VOID __fastcall RpcCoreUninit(VOID* pRpcCoreCtxt);
RpcProcessInfo_T* __fastcall RpcCoreGetProcessInfo(void* pRpcCoreCtxt, DWORD Pid, DWORD Ppid, ULONG ProcessInfoMask);
VOID __fastcall RpcCoreFreeProcessInfo(void* pRpcCoreCtxt, RpcProcessInfo_T* pRpcProcessInfo);
RpcInterfaceInfo_T* __fastcall RpcCoreGetInterfaceInfo(void* pRpcCoreCtxt, DWORD Pid, RPC_IF_ID* pIf, ULONG InterfaceInfoMask);
VOID __fastcall RpcCoreFreeInterfaceInfo(void* pRpcCoreCtxt, RpcInterfaceInfo_T* pRpcInterfaceInfo);
BOOL __fastcall RpcCoreEnumProcessInterfaces(void* pRpcCoreCtxt, DWORD Pid, RpcCoreEnumProcessInterfacesCallbackFn_T RpcCoreEnumProcessInterfacesCallbackFn, void* pCallbackCtxt, ULONG InterfaceInfoMask);
BOOL __fastcall RpcCoreEnumProcessEndpoints(void* pRpcCoreCtxt, DWORD Pid, RpcCoreEnumProcessEndpointsCallbackFn_T RpcCoreEnumProcessEndpointsCallbackFn, void* pCallbackCtxt);
BOOL __fastcall RpcCoreEnumProcessAuthInfo(void* pRpcCoreCtxt, DWORD Pid, RpcCoreEnumProcessAuthInfoCallbackFn_T RpcCoreEnumProcessAuthInfoCallbackFn, void* pCallbackCtxt);
RpcCore_T gRpcCoreManager =
{
0,
//"Generic RpcCore Manager",
FALSE,
FALSE,
&RpcCoreInit,
&RpcCoreUninit,
&RpcCoreGetProcessInfo,
&RpcCoreFreeProcessInfo,
&RpcCoreGetInterfaceInfo,
&RpcCoreFreeInterfaceInfo,
&RpcCoreEnumProcessInterfaces,
&RpcCoreEnumProcessEndpoints,
&RpcCoreEnumProcessAuthInfo,
};
#endif // 0
//------------------------------------------------------------------------------
BOOL NTAPI LoadCoreEngine(RpcCore_T** ppRpcCoreHelper, void** ppRpcCoreCtxt, BOOL bWow64Helper, BOOL bForce)
{
WIN32_FIND_DATAA Win32FindData;
HMODULE hLib;
// Version_T Version;
HANDLE hFindFile = INVALID_HANDLE_VALUE;
RpcCore_T* pRpcCoreHelper = NULL;
BOOL bResult = FALSE;
hFindFile = FindFirstFileA("*.dll", &Win32FindData);
if (hFindFile == INVALID_HANDLE_VALUE) goto End;
do
{
hLib = LoadLibraryA(Win32FindData.cFileName);
if (hLib != NULL)
{
pRpcCoreHelper = (RpcCore_T*)(ULONG_PTR)GetProcAddress(hLib, RPC_CORE_EXPORT_SYMBOL);
if (pRpcCoreHelper != NULL)
{
*ppRpcCoreCtxt = pRpcCoreHelper->RpcCoreInitFn(bForce);
if (*ppRpcCoreCtxt != NULL)
{
pRpcCoreHelper->RpcCoreUninitFn(*ppRpcCoreCtxt);
if (bWow64Helper == pRpcCoreHelper->bWow64Helper)
{
_cprintf("RpcCore : %s\n", Win32FindData.cFileName);
_cprintf("Helper : 0x%p\n", pRpcCoreHelper);
_cprintf("Wow64 : ");
if (pRpcCoreHelper->bWow64Helper) _cprintf("TRUE\n"); else _cprintf("FALSE\n");
*ppRpcCoreHelper = pRpcCoreHelper;
bResult = TRUE;
goto End;
}
}
}
FreeLibrary(hLib);
}
} while (FindNextFileA(hFindFile, &Win32FindData));
End:
if (hFindFile != INVALID_HANDLE_VALUE) FindClose(hFindFile);
return (bResult);
}
//-----------------------------------------------------------------------------
VOID* __fastcall RpcCoreInit(BOOL bForce)
{
RpcCoreManager_T* pRpcCoreManager;
pRpcCoreManager = (RpcCoreManager_T*)OS_ALLOC(sizeof(RpcCoreManager_T));
if (pRpcCoreManager == NULL) return NULL;
if (!LoadCoreEngine(&pRpcCoreManager->pNativeCore, &pRpcCoreManager->pNativeCoreCtxt, FALSE, bForce))
{
const char Caption[] = "Unsupported runtime version";
#ifdef _WIN64
const char Msg[] = "Please send us a mail to [email protected] with your rpcrt4.dll files (in System32 and SysWOW64 directories)";
#else
const char Msg[] = "Please send us a mail to [email protected] with your rpcrt4.dll file (in System32 directory)";
#endif
#ifdef _DEBUG
_cprintf("** %s **\n%s\n",Caption,Msg);
#else
MessageBoxA(NULL, Msg, Caption, MB_OK);
#endif
ExitProcess(0);
}
pRpcCoreManager->pNativeCoreCtxt = pRpcCoreManager->pNativeCore->RpcCoreInitFn(bForce);
#ifdef _WIN64
if (!LoadCoreEngine(&pRpcCoreManager->pWow64Core, &pRpcCoreManager->pWow64CoreCtxt, TRUE,bForce))
{
OS_FREE(pRpcCoreManager);
return NULL;
}
pRpcCoreManager->pWow64CoreCtxt = pRpcCoreManager->pWow64Core->RpcCoreInitFn(bForce);
#endif
return (pRpcCoreManager);
}
//-----------------------------------------------------------------------------
VOID __fastcall RpcCoreUninit(VOID* pRpcCoreCtxt)
{
RpcCoreManager_T* pRpcCoreManager;
pRpcCoreManager = (RpcCoreManager_T*)pRpcCoreCtxt;
if (pRpcCoreManager == NULL) goto End;
pRpcCoreManager->pNativeCore->RpcCoreUninitFn(pRpcCoreManager->pNativeCoreCtxt);
#ifdef _WIN64
pRpcCoreManager->pWow64Core->RpcCoreUninitFn(pRpcCoreManager->pWow64CoreCtxt);
#endif
OS_FREE(pRpcCoreManager);
End:
return;
}
//-----------------------------------------------------------------------------
RpcProcessInfo_T* __fastcall RpcCoreGetProcessInfo(void* pRpcCoreCtxt, DWORD Pid, DWORD Ppid, ULONG ProcessInfoMask)
{
RpcCoreManager_T* pRpcCoreManager = NULL;
RpcProcessInfo_T* pRpcProcessInfo = NULL;
pRpcCoreManager = (RpcCoreManager_T*)pRpcCoreCtxt;
if (pRpcCoreManager == NULL) goto End;
#ifdef _WIN64
if (IsProcessWow64(Pid))
{
pRpcProcessInfo = pRpcCoreManager->pWow64Core->RpcCoreGetProcessInfoFn(pRpcCoreManager->pWow64CoreCtxt, Pid, Ppid, ProcessInfoMask);
}
else
#endif
{
pRpcProcessInfo = pRpcCoreManager->pNativeCore->RpcCoreGetProcessInfoFn(pRpcCoreManager->pNativeCoreCtxt, Pid, Ppid, ProcessInfoMask);
}
End:
return (pRpcProcessInfo);
}
//-----------------------------------------------------------------------------
VOID __fastcall RpcCoreFreeProcessInfo(void* pRpcCoreCtxt, RpcProcessInfo_T* pRpcProcessInfo)
{
RpcCoreManager_T* pRpcCoreManager = NULL;
pRpcCoreManager = (RpcCoreManager_T*)pRpcCoreCtxt;
if (pRpcCoreManager != NULL)
{
#ifdef _WIN64
if (IsProcessWow64(pRpcProcessInfo->Pid))
{
pRpcCoreManager->pWow64Core->RpcCoreFreeProcessInfoFn(pRpcCoreManager->pWow64CoreCtxt, pRpcProcessInfo);
}
else
#endif
{
pRpcCoreManager->pNativeCore->RpcCoreFreeProcessInfoFn(pRpcCoreManager->pNativeCoreCtxt, pRpcProcessInfo);
}
}
}
//-----------------------------------------------------------------------------
RpcInterfaceInfo_T* __fastcall RpcCoreGetInterfaceInfo(void* pRpcCoreCtxt, DWORD Pid, RPC_IF_ID* pIf, ULONG InterfaceInfoMask)
{
RpcCoreManager_T* pRpcCoreManager = NULL;
RpcInterfaceInfo_T* pRpcInterfaceInfo = NULL;
pRpcCoreManager = (RpcCoreManager_T*)pRpcCoreCtxt;
if (pRpcCoreManager == NULL) goto End;
#ifdef _WIN64
if (IsProcessWow64(Pid))
{
pRpcInterfaceInfo = pRpcCoreManager->pWow64Core->RpcCoreGetInterfaceInfoFn(pRpcCoreManager->pWow64CoreCtxt, Pid, pIf, InterfaceInfoMask);
}
else
#endif
{
pRpcInterfaceInfo = pRpcCoreManager->pNativeCore->RpcCoreGetInterfaceInfoFn(pRpcCoreManager->pNativeCoreCtxt, Pid, pIf, InterfaceInfoMask);
}
End:
return (pRpcInterfaceInfo);
}
//-----------------------------------------------------------------------------
VOID __fastcall RpcCoreFreeInterfaceInfo(void* pRpcCoreCtxt, RpcInterfaceInfo_T* pRpcInterfaceInfo)
{
RpcCoreManager_T* pRpcCoreManager = NULL;
if (pRpcInterfaceInfo == NULL) return;
pRpcCoreManager = (RpcCoreManager_T*)pRpcCoreCtxt;
if (pRpcCoreManager != NULL)
{
#ifdef _WIN64
if (IsProcessWow64(pRpcInterfaceInfo->Pid))
{
pRpcCoreManager->pWow64Core->RpcCoreFreeInterfaceInfoFn(pRpcCoreManager->pWow64CoreCtxt, pRpcInterfaceInfo);
}
else
#endif
{
pRpcCoreManager->pNativeCore->RpcCoreFreeInterfaceInfoFn(pRpcCoreManager->pNativeCoreCtxt, pRpcInterfaceInfo);
}
}
}
//-----------------------------------------------------------------------------
BOOL __fastcall RpcCoreEnumProcessInterfaces(void* pRpcCoreCtxt, DWORD Pid, RpcCoreEnumProcessInterfacesCallbackFn_T RpcCoreEnumProcessInterfacesCallbackFn, void* pCallbackCtxt, ULONG InterfaceInfoMask)
{
RpcCoreManager_T* pRpcCoreManager = NULL;
BOOL bResult = FALSE;
pRpcCoreManager = (RpcCoreManager_T*)pRpcCoreCtxt;
if (pRpcCoreManager == NULL) goto End;
#ifdef _WIN64
if (IsProcessWow64(Pid))
{
bResult = pRpcCoreManager->pWow64Core->RpcCoreEnumProcessInterfacesFn(pRpcCoreManager->pWow64CoreCtxt, Pid, RpcCoreEnumProcessInterfacesCallbackFn, pCallbackCtxt, InterfaceInfoMask);
}
else
#endif
{
bResult = pRpcCoreManager->pNativeCore->RpcCoreEnumProcessInterfacesFn(pRpcCoreManager->pNativeCoreCtxt, Pid, RpcCoreEnumProcessInterfacesCallbackFn, pCallbackCtxt, InterfaceInfoMask);
}
End:
return (bResult);
}
//-----------------------------------------------------------------------------
BOOL __fastcall RpcCoreEnumProcessEndpoints(void* pRpcCoreCtxt, DWORD Pid, RpcCoreEnumProcessEndpointsCallbackFn_T RpcCoreEnumProcessEndpointsCallbackFn, void* pCallbackCtxt)
{
RpcCoreManager_T* pRpcCoreManager = NULL;
BOOL bResult = FALSE;
pRpcCoreManager = (RpcCoreManager_T*)pRpcCoreCtxt;
if (pRpcCoreManager == NULL) goto End;
#ifdef _WIN64
if (IsProcessWow64(Pid))
{
bResult = pRpcCoreManager->pWow64Core->RpcCoreEnumProcessEndpointsFn(pRpcCoreManager->pWow64CoreCtxt, Pid, RpcCoreEnumProcessEndpointsCallbackFn, pCallbackCtxt);
}
else
#endif
{
bResult = pRpcCoreManager->pNativeCore->RpcCoreEnumProcessEndpointsFn(pRpcCoreManager->pNativeCoreCtxt, Pid, RpcCoreEnumProcessEndpointsCallbackFn, pCallbackCtxt);
}
End:
return (bResult);
}
//-----------------------------------------------------------------------------
BOOL __fastcall RpcCoreEnumProcessAuthInfo(void* pRpcCoreCtxt, DWORD Pid, RpcCoreEnumProcessAuthInfoCallbackFn_T RpcCoreEnumProcessAuthInfoCallbackFn, void* pCallbackCtxt)
{
RpcCoreManager_T* pRpcCoreManager = NULL;
BOOL bResult = FALSE;
pRpcCoreManager = (RpcCoreManager_T*)pRpcCoreCtxt;
if (pRpcCoreManager == NULL) goto End;
#ifdef _WIN64
if (IsProcessWow64(Pid))
{
bResult = pRpcCoreManager->pWow64Core->RpcCoreEnumProcessAuthInfoFn(pRpcCoreManager->pWow64CoreCtxt, Pid, RpcCoreEnumProcessAuthInfoCallbackFn, pCallbackCtxt);
}
else
#endif
{
bResult = pRpcCoreManager->pNativeCore->RpcCoreEnumProcessAuthInfoFn(pRpcCoreManager->pNativeCoreCtxt, Pid, RpcCoreEnumProcessAuthInfoCallbackFn, pCallbackCtxt);
}
End:
return (bResult);
}