-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathWoW64Utils.c
More file actions
287 lines (273 loc) · 8.09 KB
/
WoW64Utils.c
File metadata and controls
287 lines (273 loc) · 8.09 KB
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
/*
* Copyright (c) 2016 Wolk-1024 <wolk1024@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "WoW64Utils.h"
/*
@28
*/
NTSTATUS
NTAPI
NtWow64ReadVirtualMemory64(
_In_ HANDLE ProcessHandle,
_In_ DWORD64 BaseAddress,
_Out_ PVOID Buffer,
_In_ DWORD64 NumberOfBytesToRead,
_Out_opt_ DWORD64 *NumberOfBytesRead OPTIONAL
)
{
DWORD64 Proc64 = IsWoW64() ? GetProcAddress64(GetNtdll64(), "NtReadVirtualMemory") : 0;
if (Proc64)
return (NTSTATUS)x64Call(Proc64, 5, (DWORD64)ProcessHandle, (DWORD64)BaseAddress, (DWORD64)Buffer, (DWORD64)NumberOfBytesToRead, (DWORD64)NumberOfBytesRead);
else
return STATUS_NOT_IMPLEMENTED;
}
/*
@28
*/
NTSTATUS
NTAPI
NtWow64WriteVirtualMemory64(
_In_ HANDLE ProcessHandle,
_In_ DWORD64 BaseAddress,
_In_ PVOID Buffer,
_In_ DWORD64 NumberOfBytesToWrite,
_Out_opt_ DWORD64 *NumberOfBytesWritten OPTIONAL
)
{
DWORD64 Proc64 = IsWoW64() ? GetProcAddress64(GetNtdll64(), "NtWriteVirtualMemory") : 0;
if (Proc64)
return (NTSTATUS)x64Call(Proc64, 5, (DWORD64)ProcessHandle, (DWORD64)BaseAddress, (DWORD64)Buffer, (DWORD64)NumberOfBytesToWrite, (DWORD64)NumberOfBytesWritten);
else
return STATUS_NOT_IMPLEMENTED;
}
/*
@24
*/
NTSTATUS
NTAPI
NtWow64AllocateVirtualMemory64(
_In_ HANDLE ProcessHandle,
_Inout_ DWORD64 *BaseAddress,
_In_ DWORD ZeroBits,
_Inout_ DWORD64 *RegionSize,
_In_ DWORD AllocationType,
_In_ DWORD Protect
)
{
DWORD64 Proc64 = IsWoW64() ? GetProcAddress64(GetNtdll64(), "NtAllocateVirtualMemory") : 0;
if (Proc64)
return (NTSTATUS)x64Call(Proc64, 6, (DWORD64)ProcessHandle, (DWORD64)BaseAddress, (DWORD64)ZeroBits, (DWORD64)RegionSize, (DWORD64)AllocationType, (DWORD64)Protect);
else
return STATUS_NOT_IMPLEMENTED;
}
/*
@16
*/
NTSTATUS
NTAPI
NtWow64FreeVirtualMemory64(
_In_ HANDLE ProcessHandle,
_Inout_ DWORD64 *BaseAddress,
_Inout_ DWORD64 *RegionSize,
_In_ DWORD FreeType
)
{
DWORD64 Proc64 = IsWoW64() ? GetProcAddress64(GetNtdll64(), "NtFreeVirtualMemory") : 0;
if (Proc64)
return (NTSTATUS)x64Call(Proc64, 4, (DWORD64)ProcessHandle, (DWORD64)BaseAddress, (DWORD64)RegionSize, (DWORD64)FreeType);
else
return STATUS_NOT_IMPLEMENTED;
}
/*
@20
*/
NTSTATUS
NTAPI
NtWow64ProtectVirtualMemory64(
_In_ HANDLE ProcessHandle,
_Inout_ DWORD64 *BaseAddress,
_Inout_ DWORD64 *NumberOfBytesToProtect,
_In_ DWORD NewAccessProtection,
_Out_ PDWORD OldAccessProtection
)
{
DWORD64 Proc64 = IsWoW64() ? GetProcAddress64(GetNtdll64(), "NtProtectVirtualMemory") : 0;
if (Proc64)
return (NTSTATUS)x64Call(Proc64, 5, (DWORD64)ProcessHandle, (DWORD64)BaseAddress, (DWORD64)NumberOfBytesToProtect, (DWORD64)NewAccessProtection, (DWORD64)OldAccessProtection);
else
return STATUS_NOT_IMPLEMENTED;
}
/*
@32
*/
NTSTATUS
NTAPI
NtWow64QueryVirtualMemory64(
_In_ HANDLE ProcessHandle,
_In_ DWORD64 BaseAddress,
_In_ MEMORY_INFORMATION_CLASS64 MemoryInformationClass,
_Out_ PVOID Buffer,
_In_ DWORD64 Length,
_Out_opt_ PDWORD64 ReturnLength OPTIONAL
)
{
DWORD64 Proc64 = IsWoW64() ? GetProcAddress64(GetNtdll64(), "NtQueryVirtualMemory") : 0;
if (Proc64)
return (NTSTATUS)x64Call(Proc64, 6, (DWORD64)ProcessHandle, (DWORD64)BaseAddress, (DWORD64)MemoryInformationClass, (DWORD64)Buffer, (DWORD64)Length, (DWORD64)ReturnLength);
else
return STATUS_NOT_IMPLEMENTED;
}
/*
@20
*/
NTSTATUS
NTAPI
NtWow64QueryInformationThread64(
_In_ HANDLE ThreadHandle,
_In_ THREAD_INFORMATION_CLASS64 ThreadInformationClass,
_Out_ PVOID ThreadInformation,
_In_ DWORD ThreadInformationLength,
_Out_opt_ PDWORD ReturnLength OPTIONAL
)
{
DWORD64 Proc64 = IsWoW64() ? GetProcAddress64(GetNtdll64(), "NtQueryInformationThread") : 0;
if (Proc64)
return (NTSTATUS)x64Call(Proc64, 5, (DWORD64)ThreadHandle, (DWORD64)ThreadInformationClass, (DWORD64)ThreadInformation, (DWORD64)ThreadInformationLength, (DWORD64)ReturnLength);
else
return STATUS_NOT_IMPLEMENTED;
}
/*
@20
*/
NTSTATUS
NTAPI
NtWow64QueryInformationProcess64(
_In_ HANDLE ProcessHandle,
_In_ PROCESS_INFORMATION_CLASS64 ProcessInformationClass,
_Out_ PVOID ProcessInformation,
_In_ DWORD ProcessInformationLength,
_Out_opt_ PDWORD ReturnLength OPTIONAL
)
{
DWORD64 Proc64 = IsWoW64() ? GetProcAddress64(GetNtdll64(), "NtQueryInformationProcess") : 0;
if (Proc64)
return (NTSTATUS)x64Call(Proc64, 5, (DWORD64)ProcessHandle, (DWORD64)ProcessInformationClass, (DWORD64)ProcessInformation, (DWORD64)ProcessInformationLength, (DWORD64)ReturnLength);
else
return STATUS_NOT_IMPLEMENTED;
}
/*
@16
*/
NTSTATUS
NTAPI
NtWow64SetInformationProcess64(
_In_ HANDLE ProcessHandle,
_In_ PROCESS_INFORMATION_CLASS64 ProcessInformationClass,
_In_ PVOID ProcessInformation,
_In_ DWORD ProcessInformationLength
)
{
DWORD64 Proc64 = IsWoW64() ? GetProcAddress64(GetNtdll64(), "NtSetInformationProcess") : 0;
if (Proc64)
return (NTSTATUS)x64Call(Proc64, 4, (DWORD64)ProcessHandle, (DWORD64)ProcessInformationClass, (DWORD64)ProcessInformation, (DWORD64)ProcessInformationLength);
else
return STATUS_NOT_IMPLEMENTED;
}
/*
@16
*/
NTSTATUS
NTAPI
NtWow64GetNativeSystemInformation(
_In_ SYSTEM_INFORMATION_CLASS64 SystemInformationClass,
_Out_ PVOID SystemInformation,
_In_ DWORD SystemInformationLength,
_Out_opt_ PDWORD ReturnLength OPTIONAL
)
{
DWORD64 Proc64 = IsWoW64() ? GetProcAddress64(GetNtdll64(), "NtQuerySystemInformation") : 0;
if (Proc64)
return (NTSTATUS)x64Call(Proc64, 4, (DWORD64)SystemInformationClass, (DWORD64)SystemInformation, (DWORD64)SystemInformationLength, (DWORD64)ReturnLength);
else
return STATUS_NOT_IMPLEMENTED;
}
/*
@8
*/
NTSTATUS
NTAPI
NtWow64GetContextThread64(
_In_ HANDLE ThreadHandle,
_Out_ PCONTEXT64 Context
)
{
DWORD64 Proc64 = IsWoW64() ? GetProcAddress64(GetNtdll64(), "NtGetContextThread") : 0;
if (Proc64)
return (NTSTATUS)x64Call(Proc64, 2, (DWORD64)ThreadHandle, (DWORD64)Context);
else
return STATUS_NOT_IMPLEMENTED;
}
/*
@8
*/
NTSTATUS
NTAPI
NtWow64SetContextThread64(
_In_ HANDLE ThreadHandle,
_In_ PCONTEXT64 Context
)
{
DWORD64 Proc64 = IsWoW64() ? GetProcAddress64(GetNtdll64(), "NtSetContextThread") : 0;
if (Proc64)
return (NTSTATUS)x64Call(Proc64, 2, (DWORD64)ThreadHandle, (DWORD64)Context);
else
return STATUS_NOT_IMPLEMENTED;
}
/*
@48
*/
NTSTATUS
NTAPI
RtlWow64CreateUserThread64(
_In_ HANDLE ProcessHandle,
_In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor OPTIONAL,
_In_ BOOLEAN CreateSuspended,
_In_ DWORD StackZeroBits,
_Inout_ PDWORD StackReserved,
_Inout_ PDWORD StackCommit,
_In_ DWORD64 StartAddress,
_In_opt_ DWORD64 StartParameter OPTIONAL,
_Out_ PHANDLE64 ThreadHandle,
_Out_ PCLIENT_ID64 ClientID
)
{
DWORD64 Proc64 = IsWoW64() ? GetProcAddress64(GetNtdll64(), "RtlCreateUserThread") : 0;
if (Proc64)
{
return (NTSTATUS)x64Call(Proc64, 10,
(DWORD64)ProcessHandle, //
(DWORD64)SecurityDescriptor, //
(DWORD64)CreateSuspended, //
(DWORD64)StackZeroBits, //
(DWORD64)StackReserved, //
(DWORD64)StackCommit, //
(DWORD64)StartAddress, //
(DWORD64)StartParameter, //
(DWORD64)ThreadHandle, //
(DWORD64)ClientID); //
}
return STATUS_NOT_IMPLEMENTED;
}