Browse Source

Migrate from detours to mhook-2.3

Alex Marsev 5 years ago
parent
commit
db9f9e31b8

+ 5
- 5
Readme.md View File

@@ -78,11 +78,6 @@ MPC-HC makes use of the following third-party code:
78 78
         <td>GPLv2</td>
79 79
         <td>http://www.datamekanix.com/sizecbar/</td>
80 80
     </tr>
81
-    <tr>
82
-        <td>Detours</td>
83
-        <td>MSR-SSLA</td>
84
-        <td>http://research.microsoft.com/en-us/projects/detours/</td>
85
-    </tr>
86 81
     <tr>
87 82
         <td>LAV Filters</td>
88 83
         <td>GPLv2</td>
@@ -103,6 +98,11 @@ MPC-HC makes use of the following third-party code:
103 98
         <td>Simplified BSD License</td>
104 99
         <td>http://mediaarea.net/MediaInfo</td>
105 100
     </tr>
101
+    <tr>
102
+        <td>Mhook</td>
103
+        <td>MIT License</td>
104
+        <td>http://codefromthe70s.org/mhook23.aspx</td>
105
+    </tr>
106 106
     <tr>
107 107
         <td>MultiMon</td>
108 108
         <td>CPOL</td>

+ 1
- 1
docs/Readme.txt View File

@@ -53,11 +53,11 @@ Project             License                     Website
53 53
 ATL Server          Ms-LPL                      http://atlserver.codeplex.com/
54 54
 CLineNumberEdit     -                           http://www.codeproject.com/Articles/6385/Controls-in-controls-A-line-numbering-edit-box
55 55
 CSizingControlBar   GPLv2                       http://www.datamekanix.com/sizecbar/
56
-Detours             MSR-SSLA                    http://research.microsoft.com/en-us/projects/detours/
57 56
 LAV Filters         GPLv2                       http://code.google.com/p/lavfilters/
58 57
 Little CMS          MIT License                 http://www.littlecms.com/
59 58
 Logitech SDK        -                           -
60 59
 MediaInfoLib        Simplified BSD License      http://mediaarea.net/MediaInfo
60
+Mhook               MIT License                 http://codefromthe70s.org/mhook23.aspx
61 61
 MultiMon            CPOL                        http://www.codeproject.com/KB/GDI/multimon.aspx
62 62
 QuickTime SDK       -                           http://developer.apple.com/quicktime/
63 63
 RARFileSource       GPLv2+                      http://www.v12pwr.com/RARFileSource/

+ 0
- 536
include/detours/detours.h View File

@@ -1,536 +0,0 @@
1
-//////////////////////////////////////////////////////////////////////////////
2
-//
3
-//  Core Detours Functionality (detours.h of detours.lib)
4
-//
5
-//  Microsoft Research Detours Package, Version 3.0 Build_316.
6
-//
7
-//  Copyright (c) Microsoft Corporation.  All rights reserved.
8
-//
9
-
10
-#pragma once
11
-#ifndef _DETOURS_H_
12
-#define _DETOURS_H_
13
-
14
-#define DETOURS_VERSION     30000   // 3.00.00
15
-
16
-//////////////////////////////////////////////////////////////////////////////
17
-//
18
-
19
-#if (_MSC_VER < 1299)
20
-typedef LONG LONG_PTR;
21
-typedef ULONG ULONG_PTR;
22
-#endif
23
-
24
-#ifndef __in_z
25
-#define __in_z
26
-#endif
27
-
28
-//////////////////////////////////////////////////////////////////////////////
29
-//
30
-#ifndef GUID_DEFINED
31
-#define GUID_DEFINED
32
-typedef struct  _GUID
33
-{
34
-    DWORD Data1;
35
-    WORD Data2;
36
-    WORD Data3;
37
-    BYTE Data4[ 8 ];
38
-} GUID;
39
-
40
-#ifdef INITGUID
41
-#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
42
-        const GUID name \
43
-                = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }
44
-#else
45
-#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
46
-    const GUID name
47
-#endif // INITGUID
48
-#endif // !GUID_DEFINED
49
-
50
-#if defined(__cplusplus)
51
-#ifndef _REFGUID_DEFINED
52
-#define _REFGUID_DEFINED
53
-#define REFGUID             const GUID &
54
-#endif // !_REFGUID_DEFINED
55
-#else // !__cplusplus
56
-#ifndef _REFGUID_DEFINED
57
-#define _REFGUID_DEFINED
58
-#define REFGUID             const GUID * const
59
-#endif // !_REFGUID_DEFINED
60
-#endif // !__cplusplus
61
-
62
-//
63
-//////////////////////////////////////////////////////////////////////////////
64
-
65
-#ifdef __cplusplus
66
-extern "C" {
67
-#endif // __cplusplus
68
-
69
-/////////////////////////////////////////////////// Instruction Target Macros.
70
-//
71
-#define DETOUR_INSTRUCTION_TARGET_NONE          ((PVOID)0)
72
-#define DETOUR_INSTRUCTION_TARGET_DYNAMIC       ((PVOID)(LONG_PTR)-1)
73
-#define DETOUR_SECTION_HEADER_SIGNATURE         0x00727444   // "Dtr\0"
74
-
75
-extern const GUID DETOUR_EXE_RESTORE_GUID;
76
-extern const GUID DETOUR_EXE_HELPER_GUID;
77
-
78
-#define DETOUR_TRAMPOLINE_SIGNATURE             0x21727444  // Dtr!
79
-typedef struct _DETOUR_TRAMPOLINE DETOUR_TRAMPOLINE, *PDETOUR_TRAMPOLINE;
80
-
81
-/////////////////////////////////////////////////////////// Binary Structures.
82
-//
83
-#pragma pack(push, 8)
84
-typedef struct _DETOUR_SECTION_HEADER
85
-{
86
-    DWORD       cbHeaderSize;
87
-    DWORD       nSignature;
88
-    DWORD       nDataOffset;
89
-    DWORD       cbDataSize;
90
-
91
-    DWORD       nOriginalImportVirtualAddress;
92
-    DWORD       nOriginalImportSize;
93
-    DWORD       nOriginalBoundImportVirtualAddress;
94
-    DWORD       nOriginalBoundImportSize;
95
-
96
-    DWORD       nOriginalIatVirtualAddress;
97
-    DWORD       nOriginalIatSize;
98
-    DWORD       nOriginalSizeOfImage;
99
-    DWORD       cbPrePE;
100
-
101
-    DWORD       nOriginalClrFlags;
102
-    DWORD       reserved1;
103
-    DWORD       reserved2;
104
-    DWORD       reserved3;
105
-
106
-    // Followed by cbPrePE bytes of data.
107
-} DETOUR_SECTION_HEADER, *PDETOUR_SECTION_HEADER;
108
-
109
-typedef struct _DETOUR_SECTION_RECORD
110
-{
111
-    DWORD       cbBytes;
112
-    DWORD       nReserved;
113
-    GUID        guid;
114
-} DETOUR_SECTION_RECORD, *PDETOUR_SECTION_RECORD;
115
-
116
-typedef struct _DETOUR_CLR_HEADER
117
-{
118
-    // Header versioning
119
-    ULONG                   cb;
120
-    USHORT                  MajorRuntimeVersion;
121
-    USHORT                  MinorRuntimeVersion;
122
-
123
-    // Symbol table and startup information
124
-    IMAGE_DATA_DIRECTORY    MetaData;
125
-    ULONG                   Flags;
126
-
127
-    // Followed by the rest of the IMAGE_COR20_HEADER
128
-} DETOUR_CLR_HEADER, *PDETOUR_CLR_HEADER;
129
-
130
-typedef struct _DETOUR_EXE_RESTORE
131
-{
132
-    DWORD               cb;
133
-    DWORD               cbidh;
134
-    DWORD               cbinh;
135
-    DWORD               cbclr;
136
-
137
-    PBYTE               pidh;
138
-    PBYTE               pinh;
139
-    PBYTE               pclr;
140
-
141
-    IMAGE_DOS_HEADER    idh;
142
-    union {
143
-        IMAGE_NT_HEADERS    inh;
144
-        IMAGE_NT_HEADERS32  inh32;
145
-        IMAGE_NT_HEADERS64  inh64;
146
-        BYTE                raw[sizeof(IMAGE_NT_HEADERS64) +
147
-                                sizeof(IMAGE_SECTION_HEADER) * 32];
148
-    };
149
-    DETOUR_CLR_HEADER   clr;
150
-
151
-} DETOUR_EXE_RESTORE, *PDETOUR_EXE_RESTORE;
152
-
153
-typedef struct _DETOUR_EXE_HELPER
154
-{
155
-    DWORD               cb;
156
-    DWORD               pid;
157
-    CHAR                DllName[MAX_PATH];
158
-
159
-} DETOUR_EXE_HELPER, *PDETOUR_EXE_HELPER;
160
-
161
-#pragma pack(pop)
162
-
163
-#define DETOUR_SECTION_HEADER_DECLARE(cbSectionSize) \
164
-{ \
165
-      sizeof(DETOUR_SECTION_HEADER),\
166
-      DETOUR_SECTION_HEADER_SIGNATURE,\
167
-      sizeof(DETOUR_SECTION_HEADER),\
168
-      (cbSectionSize),\
169
-      \
170
-      0,\
171
-      0,\
172
-      0,\
173
-      0,\
174
-      \
175
-      0,\
176
-      0,\
177
-      0,\
178
-      0,\
179
-}
180
-
181
-/////////////////////////////////////////////////////////////// Helper Macros.
182
-//
183
-#define DETOURS_STRINGIFY(x)    DETOURS_STRINGIFY_(x)
184
-#define DETOURS_STRINGIFY_(x)    #x
185
-
186
-///////////////////////////////////////////////////////////// Binary Typedefs.
187
-//
188
-typedef BOOL (CALLBACK *PF_DETOUR_BINARY_BYWAY_CALLBACK)(PVOID pContext,
189
-                                                         PCHAR pszFile,
190
-                                                         PCHAR *ppszOutFile);
191
-
192
-typedef BOOL (CALLBACK *PF_DETOUR_BINARY_FILE_CALLBACK)(PVOID pContext,
193
-                                                        PCHAR pszOrigFile,
194
-                                                        PCHAR pszFile,
195
-                                                        PCHAR *ppszOutFile);
196
-
197
-typedef BOOL (CALLBACK *PF_DETOUR_BINARY_SYMBOL_CALLBACK)(PVOID pContext,
198
-                                                          ULONG nOrigOrdinal,
199
-                                                          ULONG nOrdinal,
200
-                                                          ULONG *pnOutOrdinal,
201
-                                                          PCHAR pszOrigSymbol,
202
-                                                          PCHAR pszSymbol,
203
-                                                          PCHAR *ppszOutSymbol);
204
-
205
-typedef BOOL (CALLBACK *PF_DETOUR_BINARY_COMMIT_CALLBACK)(PVOID pContext);
206
-
207
-typedef BOOL (CALLBACK *PF_DETOUR_ENUMERATE_EXPORT_CALLBACK)(PVOID pContext,
208
-                                                             ULONG nOrdinal,
209
-                                                             PCHAR pszName,
210
-                                                             PVOID pCode);
211
-
212
-typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FILE_CALLBACK)(PVOID pContext,
213
-                                                        HMODULE hModule,
214
-                                                        PCSTR pszFile);
215
-
216
-typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FUNC_CALLBACK)(PVOID pContext,
217
-                                                        DWORD nOrdinal,
218
-                                                        PCSTR pszFunc,
219
-                                                        PVOID pvFunc);
220
-
221
-typedef VOID * PDETOUR_BINARY;
222
-typedef VOID * PDETOUR_LOADED_BINARY;
223
-
224
-//////////////////////////////////////////////////////////// Transaction APIs.
225
-//
226
-LONG WINAPI DetourTransactionBegin(VOID);
227
-LONG WINAPI DetourTransactionAbort(VOID);
228
-LONG WINAPI DetourTransactionCommit(VOID);
229
-LONG WINAPI DetourTransactionCommitEx(PVOID **pppFailedPointer);
230
-
231
-LONG WINAPI DetourUpdateThread(HANDLE hThread);
232
-
233
-LONG WINAPI DetourAttach(PVOID *ppPointer,
234
-                         PVOID pDetour);
235
-
236
-LONG WINAPI DetourAttachEx(PVOID *ppPointer,
237
-                           PVOID pDetour,
238
-                           PDETOUR_TRAMPOLINE *ppRealTrampoline,
239
-                           PVOID *ppRealTarget,
240
-                           PVOID *ppRealDetour);
241
-
242
-LONG WINAPI DetourDetach(PVOID *ppPointer,
243
-                         PVOID pDetour);
244
-
245
-BOOL WINAPI DetourSetIgnoreTooSmall(BOOL fIgnore);
246
-BOOL WINAPI DetourSetRetainRegions(BOOL fRetain);
247
-
248
-////////////////////////////////////////////////////////////// Code Functions.
249
-//
250
-PVOID WINAPI DetourFindFunction(PCSTR pszModule, PCSTR pszFunction);
251
-PVOID WINAPI DetourCodeFromPointer(PVOID pPointer, PVOID *ppGlobals);
252
-PVOID WINAPI DetourCopyInstruction(PVOID pDst,
253
-                                   PVOID *pDstPool,
254
-                                   PVOID pSrc,
255
-                                   PVOID *ppTarget,
256
-                                   LONG *plExtra);
257
-
258
-///////////////////////////////////////////////////// Loaded Binary Functions.
259
-//
260
-HMODULE WINAPI DetourGetContainingModule(PVOID pvAddr);
261
-HMODULE WINAPI DetourEnumerateModules(HMODULE hModuleLast);
262
-PVOID WINAPI DetourGetEntryPoint(HMODULE hModule);
263
-ULONG WINAPI DetourGetModuleSize(HMODULE hModule);
264
-BOOL WINAPI DetourEnumerateExports(HMODULE hModule,
265
-                                   PVOID pContext,
266
-                                   PF_DETOUR_ENUMERATE_EXPORT_CALLBACK pfExport);
267
-BOOL WINAPI DetourEnumerateImports(HMODULE hModule,
268
-                                   PVOID pContext,
269
-                                   PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile,
270
-                                   PF_DETOUR_IMPORT_FUNC_CALLBACK pfImportFunc);
271
-
272
-PVOID WINAPI DetourFindPayload(HMODULE hModule, REFGUID rguid, DWORD *pcbData);
273
-PVOID WINAPI DetourFindPayloadEx(REFGUID rguid, DWORD * pcbData);
274
-DWORD WINAPI DetourGetSizeOfPayloads(HMODULE hModule);
275
-
276
-///////////////////////////////////////////////// Persistent Binary Functions.
277
-//
278
-
279
-PDETOUR_BINARY WINAPI DetourBinaryOpen(HANDLE hFile);
280
-PVOID WINAPI DetourBinaryEnumeratePayloads(PDETOUR_BINARY pBinary,
281
-                                           GUID *pGuid,
282
-                                           DWORD *pcbData,
283
-                                           DWORD *pnIterator);
284
-PVOID WINAPI DetourBinaryFindPayload(PDETOUR_BINARY pBinary,
285
-                                     REFGUID rguid,
286
-                                     DWORD *pcbData);
287
-PVOID WINAPI DetourBinarySetPayload(PDETOUR_BINARY pBinary,
288
-                                    REFGUID rguid,
289
-                                    PVOID pData,
290
-                                    DWORD cbData);
291
-BOOL WINAPI DetourBinaryDeletePayload(PDETOUR_BINARY pBinary, REFGUID rguid);
292
-BOOL WINAPI DetourBinaryPurgePayloads(PDETOUR_BINARY pBinary);
293
-BOOL WINAPI DetourBinaryResetImports(PDETOUR_BINARY pBinary);
294
-BOOL WINAPI DetourBinaryEditImports(PDETOUR_BINARY pBinary,
295
-                                    PVOID pContext,
296
-                                    PF_DETOUR_BINARY_BYWAY_CALLBACK pfByway,
297
-                                    PF_DETOUR_BINARY_FILE_CALLBACK pfFile,
298
-                                    PF_DETOUR_BINARY_SYMBOL_CALLBACK pfSymbol,
299
-                                    PF_DETOUR_BINARY_COMMIT_CALLBACK pfCommit);
300
-BOOL WINAPI DetourBinaryWrite(PDETOUR_BINARY pBinary, HANDLE hFile);
301
-BOOL WINAPI DetourBinaryClose(PDETOUR_BINARY pBinary);
302
-
303
-/////////////////////////////////////////////////// Create Process & Load Dll.
304
-//
305
-typedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEA)
306
-    (LPCSTR lpApplicationName,
307
-     LPSTR lpCommandLine,
308
-     LPSECURITY_ATTRIBUTES lpProcessAttributes,
309
-     LPSECURITY_ATTRIBUTES lpThreadAttributes,
310
-     BOOL bInheritHandles,
311
-     DWORD dwCreationFlags,
312
-     LPVOID lpEnvironment,
313
-     LPCSTR lpCurrentDirectory,
314
-     LPSTARTUPINFOA lpStartupInfo,
315
-     LPPROCESS_INFORMATION lpProcessInformation);
316
-
317
-typedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEW)
318
-    (LPCWSTR lpApplicationName,
319
-     LPWSTR lpCommandLine,
320
-     LPSECURITY_ATTRIBUTES lpProcessAttributes,
321
-     LPSECURITY_ATTRIBUTES lpThreadAttributes,
322
-     BOOL bInheritHandles,
323
-     DWORD dwCreationFlags,
324
-     LPVOID lpEnvironment,
325
-     LPCWSTR lpCurrentDirectory,
326
-     LPSTARTUPINFOW lpStartupInfo,
327
-     LPPROCESS_INFORMATION lpProcessInformation);
328
-
329
-BOOL WINAPI DetourCreateProcessWithDllA(LPCSTR lpApplicationName,
330
-                                        __in_z LPSTR lpCommandLine,
331
-                                        LPSECURITY_ATTRIBUTES lpProcessAttributes,
332
-                                        LPSECURITY_ATTRIBUTES lpThreadAttributes,
333
-                                        BOOL bInheritHandles,
334
-                                        DWORD dwCreationFlags,
335
-                                        LPVOID lpEnvironment,
336
-                                        LPCSTR lpCurrentDirectory,
337
-                                        LPSTARTUPINFOA lpStartupInfo,
338
-                                        LPPROCESS_INFORMATION lpProcessInformation,
339
-                                        LPCSTR lpDllName,
340
-                                        PDETOUR_CREATE_PROCESS_ROUTINEA
341
-                                        pfCreateProcessA);
342
-
343
-BOOL WINAPI DetourCreateProcessWithDllW(LPCWSTR lpApplicationName,
344
-                                        __in_z LPWSTR lpCommandLine,
345
-                                        LPSECURITY_ATTRIBUTES lpProcessAttributes,
346
-                                        LPSECURITY_ATTRIBUTES lpThreadAttributes,
347
-                                        BOOL bInheritHandles,
348
-                                        DWORD dwCreationFlags,
349
-                                        LPVOID lpEnvironment,
350
-                                        LPCWSTR lpCurrentDirectory,
351
-                                        LPSTARTUPINFOW lpStartupInfo,
352
-                                        LPPROCESS_INFORMATION lpProcessInformation,
353
-                                        LPCSTR lpDllName,
354
-                                        PDETOUR_CREATE_PROCESS_ROUTINEW
355
-                                        pfCreateProcessW);
356
-
357
-#ifdef UNICODE
358
-#define DetourCreateProcessWithDll      DetourCreateProcessWithDllW
359
-#define PDETOUR_CREATE_PROCESS_ROUTINE  PDETOUR_CREATE_PROCESS_ROUTINEW
360
-#else
361
-#define DetourCreateProcessWithDll      DetourCreateProcessWithDllA
362
-#define PDETOUR_CREATE_PROCESS_ROUTINE  PDETOUR_CREATE_PROCESS_ROUTINEA
363
-#endif // !UNICODE
364
-
365
-BOOL WINAPI DetourCreateProcessWithDllExA(LPCSTR lpApplicationName,
366
-                                          __in_z LPSTR lpCommandLine,
367
-                                          LPSECURITY_ATTRIBUTES lpProcessAttributes,
368
-                                          LPSECURITY_ATTRIBUTES lpThreadAttributes,
369
-                                          BOOL bInheritHandles,
370
-                                          DWORD dwCreationFlags,
371
-                                          LPVOID lpEnvironment,
372
-                                          LPCSTR lpCurrentDirectory,
373
-                                          LPSTARTUPINFOA lpStartupInfo,
374
-                                          LPPROCESS_INFORMATION lpProcessInformation,
375
-                                          LPCSTR lpDllName,
376
-                                          PDETOUR_CREATE_PROCESS_ROUTINEA
377
-                                          pfCreateProcessA);
378
-
379
-BOOL WINAPI DetourCreateProcessWithDllExW(LPCWSTR lpApplicationName,
380
-                                          __in_z LPWSTR lpCommandLine,
381
-                                          LPSECURITY_ATTRIBUTES lpProcessAttributes,
382
-                                          LPSECURITY_ATTRIBUTES lpThreadAttributes,
383
-                                          BOOL bInheritHandles,
384
-                                          DWORD dwCreationFlags,
385
-                                          LPVOID lpEnvironment,
386
-                                          LPCWSTR lpCurrentDirectory,
387
-                                          LPSTARTUPINFOW lpStartupInfo,
388
-                                          LPPROCESS_INFORMATION lpProcessInformation,
389
-                                          LPCSTR lpDllName,
390
-                                          PDETOUR_CREATE_PROCESS_ROUTINEW
391
-                                          pfCreateProcessW);
392
-
393
-#ifdef UNICODE
394
-#define DetourCreateProcessWithDllEx    DetourCreateProcessWithDllExW
395
-#define PDETOUR_CREATE_PROCESS_ROUTINE  PDETOUR_CREATE_PROCESS_ROUTINEW
396
-#else
397
-#define DetourCreateProcessWithDllEx    DetourCreateProcessWithDllExA
398
-#define PDETOUR_CREATE_PROCESS_ROUTINE  PDETOUR_CREATE_PROCESS_ROUTINEA
399
-#endif // !UNICODE
400
-
401
-BOOL WINAPI DetourProcessViaHelperA(DWORD dwTargetPid,
402
-                                    LPCSTR lpDllName,
403
-                                    PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA);
404
-
405
-BOOL WINAPI DetourProcessViaHelperW(DWORD dwTargetPid,
406
-                                    LPCSTR lpDllName,
407
-                                    PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW);
408
-
409
-#ifdef UNICODE
410
-#define DetourProcessViaHelper          DetourProcessViaHelperW
411
-#else
412
-#define DetourProcessViaHelper          DetourProcessViaHelperA
413
-#endif // !UNICODE
414
-
415
-BOOL WINAPI DetourUpdateProcessWithDll(HANDLE hProcess,
416
-                                       LPCSTR *plpDlls,
417
-                                       DWORD nDlls);
418
-
419
-BOOL WINAPI DetourCopyPayloadToProcess(HANDLE hProcess,
420
-                                       REFGUID rguid,
421
-                                       PVOID pvData,
422
-                                       DWORD cbData);
423
-BOOL WINAPI DetourRestoreAfterWith(VOID);
424
-BOOL WINAPI DetourRestoreAfterWithEx(PVOID pvData, DWORD cbData);
425
-BOOL WINAPI DetourIsHelperProcess(VOID);
426
-VOID CALLBACK DetourFinishHelperProcess(HWND, HINSTANCE, LPSTR, INT);
427
-
428
-//
429
-//////////////////////////////////////////////////////////////////////////////
430
-#ifdef __cplusplus
431
-}
432
-#endif // __cplusplus
433
-
434
-//////////////////////////////////////////////// Detours Internal Definitions.
435
-//
436
-#ifdef __cplusplus
437
-#ifdef DETOURS_INTERNAL
438
-
439
-#ifndef __deref_out
440
-#define __deref_out
441
-#endif
442
-
443
-#ifndef __deref
444
-#define __deref
445
-#endif
446
-
447
-//////////////////////////////////////////////////////////////////////////////
448
-//
449
-#if (_MSC_VER < 1299)
450
-#include <imagehlp.h>
451
-typedef IMAGEHLP_MODULE IMAGEHLP_MODULE64;
452
-typedef PIMAGEHLP_MODULE PIMAGEHLP_MODULE64;
453
-typedef IMAGEHLP_SYMBOL SYMBOL_INFO;
454
-typedef PIMAGEHLP_SYMBOL PSYMBOL_INFO;
455
-
456
-static inline
457
-LONG InterlockedCompareExchange(LONG *ptr, LONG nval, LONG oval)
458
-{
459
-    return (LONG)::InterlockedCompareExchange((PVOID*)ptr, (PVOID)nval, (PVOID)oval);
460
-}
461
-#else
462
-#include <dbghelp.h>
463
-#endif
464
-
465
-#ifdef IMAGEAPI // defined by DBGHELP.H
466
-typedef LPAPI_VERSION (NTAPI *PF_ImagehlpApiVersionEx)(LPAPI_VERSION AppVersion);
467
-
468
-typedef BOOL (NTAPI *PF_SymInitialize)(IN HANDLE hProcess,
469
-                                       IN LPCSTR UserSearchPath,
470
-                                       IN BOOL fInvadeProcess);
471
-typedef DWORD (NTAPI *PF_SymSetOptions)(IN DWORD SymOptions);
472
-typedef DWORD (NTAPI *PF_SymGetOptions)(VOID);
473
-typedef DWORD64 (NTAPI *PF_SymLoadModule64)(IN HANDLE hProcess,
474
-                                            IN HANDLE hFile,
475
-                                            IN PSTR ImageName,
476
-                                            IN PSTR ModuleName,
477
-                                            IN DWORD64 BaseOfDll,
478
-                                            IN DWORD SizeOfDll);
479
-typedef BOOL (NTAPI *PF_SymGetModuleInfo64)(IN HANDLE hProcess,
480
-                                            IN DWORD64 qwAddr,
481
-                                            OUT PIMAGEHLP_MODULE64 ModuleInfo);
482
-typedef BOOL (NTAPI *PF_SymFromName)(IN HANDLE hProcess,
483
-                                     IN LPSTR Name,
484
-                                     OUT PSYMBOL_INFO Symbol);
485
-
486
-typedef struct _DETOUR_SYM_INFO
487
-{
488
-    HANDLE                  hProcess;
489
-    HMODULE                 hDbgHelp;
490
-    PF_ImagehlpApiVersionEx pfImagehlpApiVersionEx;
491
-    PF_SymInitialize        pfSymInitialize;
492
-    PF_SymSetOptions        pfSymSetOptions;
493
-    PF_SymGetOptions        pfSymGetOptions;
494
-    PF_SymLoadModule64      pfSymLoadModule64;
495
-    PF_SymGetModuleInfo64   pfSymGetModuleInfo64;
496
-    PF_SymFromName          pfSymFromName;
497
-} DETOUR_SYM_INFO, *PDETOUR_SYM_INFO;
498
-
499
-PDETOUR_SYM_INFO DetourLoadDbgHelp(VOID);
500
-
501
-#endif // IMAGEAPI
502
-
503
-#ifndef DETOUR_TRACE
504
-#if DETOUR_DEBUG
505
-#define DETOUR_TRACE(x) printf x
506
-#define DETOUR_BREAK()  __debugbreak()
507
-#include <stdio.h>
508
-#include <limits.h>
509
-#else
510
-#define DETOUR_TRACE(x)
511
-#define DETOUR_BREAK()
512
-#endif
513
-#endif
514
-
515
-#ifdef DETOURS_IA64
516
-#error Feature not supported in this release.
517
-
518
-
519
-
520
-#endif // DETOURS_IA64
521
-
522
-#ifdef DETOURS_ARM
523
-#error Feature not supported in this release.
524
-
525
-
526
-
527
-#endif // DETOURS_ARM
528
-
529
-//////////////////////////////////////////////////////////////////////////////
530
-
531
-#endif // DETOURS_INTERNAL
532
-#endif // __cplusplus
533
-
534
-#endif // _DETOURS_H_
535
-//
536
-////////////////////////////////////////////////////////////////  End of File.

BIN
lib/detours.lib View File


BIN
lib64/detours.lib View File


+ 27
- 0
mpc-hc.sln View File

@@ -111,6 +111,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RARFileSource", "src\thirdp
111 111
 EndProject
112 112
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LAVFilters", "src\thirdparty\LAVFilters\LAVFilters.vcxproj", "{ED257874-E12E-4143-AF0A-0676DA3BB18C}"
113 113
 EndProject
114
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mhook", "src\thirdparty\mhook\mhook.vcxproj", "{F841363C-A630-4716-8941-CDDC1F32CFC3}"
115
+EndProject
114 116
 Global
115 117
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
116 118
 		Debug Filter|Win32 = Debug Filter|Win32
@@ -1065,6 +1067,30 @@ Global
1065 1067
 		{ED257874-E12E-4143-AF0A-0676DA3BB18C}.Release|Win32.Build.0 = Release|Win32
1066 1068
 		{ED257874-E12E-4143-AF0A-0676DA3BB18C}.Release|x64.ActiveCfg = Release|x64
1067 1069
 		{ED257874-E12E-4143-AF0A-0676DA3BB18C}.Release|x64.Build.0 = Release|x64
1070
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Filter|Win32.ActiveCfg = Debug|Win32
1071
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Filter|Win32.Build.0 = Debug|Win32
1072
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Filter|x64.ActiveCfg = Debug|x64
1073
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Filter|x64.Build.0 = Debug|x64
1074
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Lite|Win32.ActiveCfg = Debug|Win32
1075
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Lite|Win32.Build.0 = Debug|Win32
1076
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Lite|x64.ActiveCfg = Debug|x64
1077
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Lite|x64.Build.0 = Debug|x64
1078
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug|Win32.ActiveCfg = Debug|Win32
1079
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug|Win32.Build.0 = Debug|Win32
1080
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug|x64.ActiveCfg = Debug|x64
1081
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug|x64.Build.0 = Debug|x64
1082
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Filter|Win32.ActiveCfg = Release|Win32
1083
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Filter|Win32.Build.0 = Release|Win32
1084
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Filter|x64.ActiveCfg = Release|x64
1085
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Filter|x64.Build.0 = Release|x64
1086
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Lite|Win32.ActiveCfg = Release|Win32
1087
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Lite|Win32.Build.0 = Release|Win32
1088
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Lite|x64.ActiveCfg = Release|x64
1089
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Lite|x64.Build.0 = Release|x64
1090
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release|Win32.ActiveCfg = Release|Win32
1091
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release|Win32.Build.0 = Release|Win32
1092
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release|x64.ActiveCfg = Release|x64
1093
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release|x64.Build.0 = Release|x64
1068 1094
 	EndGlobalSection
1069 1095
 	GlobalSection(SolutionProperties) = preSolution
1070 1096
 		HideSolutionNode = FALSE
@@ -1089,6 +1115,7 @@ Global
1089 1115
 		{DA8461C4-7683-4360-9372-2A9E0F1795C2} = {D9A0529B-9EC4-4D30-9E05-A5D533739D95}
1090 1116
 		{2B7F22D7-1750-47C5-8709-1A3688B62499} = {D9A0529B-9EC4-4D30-9E05-A5D533739D95}
1091 1117
 		{ED257874-E12E-4143-AF0A-0676DA3BB18C} = {D9A0529B-9EC4-4D30-9E05-A5D533739D95}
1118
+		{F841363C-A630-4716-8941-CDDC1F32CFC3} = {D9A0529B-9EC4-4D30-9E05-A5D533739D95}
1092 1119
 		{03208025-D5C2-426A-B0FA-251D4338F30C} = {2913B7E4-7A8B-43D5-A60B-345A0782816A}
1093 1120
 		{476B97B4-F079-4A44-AF89-52CA30C35E28} = {2913B7E4-7A8B-43D5-A60B-345A0782816A}
1094 1121
 		{4CC7AE86-3E0A-430A-BFF4-BF00204CAFB0} = {2913B7E4-7A8B-43D5-A60B-345A0782816A}

+ 27
- 0
mpc-hc_vs2012.sln View File

@@ -110,6 +110,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RARFileSource", "src\thirdp
110 110
 EndProject
111 111
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LAVFilters", "src\thirdparty\LAVFilters\LAVFilters.vcxproj", "{ED257874-E12E-4143-AF0A-0676DA3BB18C}"
112 112
 EndProject
113
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mhook", "src\thirdparty\mhook\mhook.vcxproj", "{F841363C-A630-4716-8941-CDDC1F32CFC3}"
114
+EndProject
113 115
 Global
114 116
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
115 117
 		Debug Filter|Win32 = Debug Filter|Win32
@@ -1064,6 +1066,30 @@ Global
1064 1066
 		{ED257874-E12E-4143-AF0A-0676DA3BB18C}.Release|Win32.Build.0 = Release|Win32
1065 1067
 		{ED257874-E12E-4143-AF0A-0676DA3BB18C}.Release|x64.ActiveCfg = Release|x64
1066 1068
 		{ED257874-E12E-4143-AF0A-0676DA3BB18C}.Release|x64.Build.0 = Release|x64
1069
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Filter|Win32.ActiveCfg = Debug|Win32
1070
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Filter|Win32.Build.0 = Debug|Win32
1071
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Filter|x64.ActiveCfg = Debug|x64
1072
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Filter|x64.Build.0 = Debug|x64
1073
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Lite|Win32.ActiveCfg = Debug|Win32
1074
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Lite|Win32.Build.0 = Debug|Win32
1075
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Lite|x64.ActiveCfg = Debug|x64
1076
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Lite|x64.Build.0 = Debug|x64
1077
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug|Win32.ActiveCfg = Debug|Win32
1078
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug|Win32.Build.0 = Debug|Win32
1079
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug|x64.ActiveCfg = Debug|x64
1080
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug|x64.Build.0 = Debug|x64
1081
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Filter|Win32.ActiveCfg = Release|Win32
1082
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Filter|Win32.Build.0 = Release|Win32
1083
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Filter|x64.ActiveCfg = Release|x64
1084
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Filter|x64.Build.0 = Release|x64
1085
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Lite|Win32.ActiveCfg = Release|Win32
1086
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Lite|Win32.Build.0 = Release|Win32
1087
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Lite|x64.ActiveCfg = Release|x64
1088
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Lite|x64.Build.0 = Release|x64
1089
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release|Win32.ActiveCfg = Release|Win32
1090
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release|Win32.Build.0 = Release|Win32
1091
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release|x64.ActiveCfg = Release|x64
1092
+		{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release|x64.Build.0 = Release|x64
1067 1093
 	EndGlobalSection
1068 1094
 	GlobalSection(SolutionProperties) = preSolution
1069 1095
 		HideSolutionNode = FALSE
@@ -1088,6 +1114,7 @@ Global
1088 1114
 		{DA8461C4-7683-4360-9372-2A9E0F1795C2} = {D9A0529B-9EC4-4D30-9E05-A5D533739D95}
1089 1115
 		{2B7F22D7-1750-47C5-8709-1A3688B62499} = {D9A0529B-9EC4-4D30-9E05-A5D533739D95}
1090 1116
 		{ED257874-E12E-4143-AF0A-0676DA3BB18C} = {D9A0529B-9EC4-4D30-9E05-A5D533739D95}
1117
+		{F841363C-A630-4716-8941-CDDC1F32CFC3} = {D9A0529B-9EC4-4D30-9E05-A5D533739D95}
1091 1118
 		{03208025-D5C2-426A-B0FA-251D4338F30C} = {2913B7E4-7A8B-43D5-A60B-345A0782816A}
1092 1119
 		{476B97B4-F079-4A44-AF89-52CA30C35E28} = {2913B7E4-7A8B-43D5-A60B-345A0782816A}
1093 1120
 		{4CC7AE86-3E0A-430A-BFF4-BF00204CAFB0} = {2913B7E4-7A8B-43D5-A60B-345A0782816A}

+ 30
- 30
src/mpc-hc/FakeFilterMapper2.cpp View File

@@ -25,7 +25,7 @@
25 25
 #include "DSUtil.h"
26 26
 
27 27
 #include <InitGuid.h>
28
-#include "detours/detours.h"
28
+#include "mhook/mhook-lib/mhook.h"
29 29
 
30 30
 
31 31
 HRESULT(__stdcall* Real_CoCreateInstance)(CONST IID& a0,
@@ -526,35 +526,35 @@ bool CFilterMapper2::fInitialized = false;
526 526
 void CFilterMapper2::Init()
527 527
 {
528 528
     if (!fInitialized) {
529
-        DetourAttach(&(PVOID&)Real_CoCreateInstance, (PVOID)Mine_CoCreateInstance);
530
-        DetourAttach(&(PVOID&)Real_RegCloseKey, (PVOID)Mine_RegCloseKey);
531
-        DetourAttach(&(PVOID&)Real_RegFlushKey, (PVOID)Mine_RegFlushKey);
532
-        DetourAttach(&(PVOID&)Real_RegCreateKeyA, (PVOID)Mine_RegCreateKeyA);
533
-        DetourAttach(&(PVOID&)Real_RegCreateKeyW, (PVOID)Mine_RegCreateKeyW);
534
-        DetourAttach(&(PVOID&)Real_RegCreateKeyExA, (PVOID)Mine_RegCreateKeyExA);
535
-        DetourAttach(&(PVOID&)Real_RegCreateKeyExW, (PVOID)Mine_RegCreateKeyExW);
536
-        DetourAttach(&(PVOID&)Real_RegDeleteKeyA, (PVOID)Mine_RegDeleteKeyA);
537
-        DetourAttach(&(PVOID&)Real_RegDeleteKeyW, (PVOID)Mine_RegDeleteKeyW);
538
-        DetourAttach(&(PVOID&)Real_RegDeleteValueA, (PVOID)Mine_RegDeleteValueA);
539
-        DetourAttach(&(PVOID&)Real_RegDeleteValueW, (PVOID)Mine_RegDeleteValueW);
540
-        DetourAttach(&(PVOID&)Real_RegEnumKeyExA, (PVOID)Mine_RegEnumKeyExA);
541
-        DetourAttach(&(PVOID&)Real_RegEnumKeyExW, (PVOID)Mine_RegEnumKeyExW);
542
-        DetourAttach(&(PVOID&)Real_RegEnumValueA, (PVOID)Mine_RegEnumValueA);
543
-        DetourAttach(&(PVOID&)Real_RegEnumValueW, (PVOID)Mine_RegEnumValueW);
544
-        DetourAttach(&(PVOID&)Real_RegOpenKeyA, (PVOID)Mine_RegOpenKeyA);
545
-        DetourAttach(&(PVOID&)Real_RegOpenKeyW, (PVOID)Mine_RegOpenKeyW);
546
-        DetourAttach(&(PVOID&)Real_RegOpenKeyExA, (PVOID)Mine_RegOpenKeyExA);
547
-        DetourAttach(&(PVOID&)Real_RegOpenKeyExW, (PVOID)Mine_RegOpenKeyExW);
548
-        DetourAttach(&(PVOID&)Real_RegQueryInfoKeyA, (PVOID)Mine_RegQueryInfoKeyA);
549
-        DetourAttach(&(PVOID&)Real_RegQueryInfoKeyW, (PVOID)Mine_RegQueryInfoKeyW);
550
-        DetourAttach(&(PVOID&)Real_RegQueryValueA, (PVOID)Mine_RegQueryValueA);
551
-        DetourAttach(&(PVOID&)Real_RegQueryValueW, (PVOID)Mine_RegQueryValueW);
552
-        DetourAttach(&(PVOID&)Real_RegQueryValueExA, (PVOID)Mine_RegQueryValueExA);
553
-        DetourAttach(&(PVOID&)Real_RegQueryValueExW, (PVOID)Mine_RegQueryValueExW);
554
-        DetourAttach(&(PVOID&)Real_RegSetValueA, (PVOID)Mine_RegSetValueA);
555
-        DetourAttach(&(PVOID&)Real_RegSetValueW, (PVOID)Mine_RegSetValueW);
556
-        DetourAttach(&(PVOID&)Real_RegSetValueExA, (PVOID)Mine_RegSetValueExA);
557
-        DetourAttach(&(PVOID&)Real_RegSetValueExW, (PVOID)Mine_RegSetValueExW);
529
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_CoCreateInstance, (PVOID)Mine_CoCreateInstance));
530
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegCloseKey, (PVOID)Mine_RegCloseKey));
531
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegFlushKey, (PVOID)Mine_RegFlushKey));
532
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegCreateKeyA, (PVOID)Mine_RegCreateKeyA));
533
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegCreateKeyW, (PVOID)Mine_RegCreateKeyW));
534
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegCreateKeyExA, (PVOID)Mine_RegCreateKeyExA));
535
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegCreateKeyExW, (PVOID)Mine_RegCreateKeyExW));
536
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegDeleteKeyA, (PVOID)Mine_RegDeleteKeyA));
537
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegDeleteKeyW, (PVOID)Mine_RegDeleteKeyW));
538
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegDeleteValueA, (PVOID)Mine_RegDeleteValueA));
539
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegDeleteValueW, (PVOID)Mine_RegDeleteValueW));
540
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegEnumKeyExA, (PVOID)Mine_RegEnumKeyExA));
541
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegEnumKeyExW, (PVOID)Mine_RegEnumKeyExW));
542
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegEnumValueA, (PVOID)Mine_RegEnumValueA));
543
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegEnumValueW, (PVOID)Mine_RegEnumValueW));
544
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegOpenKeyA, (PVOID)Mine_RegOpenKeyA));
545
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegOpenKeyW, (PVOID)Mine_RegOpenKeyW));
546
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegOpenKeyExA, (PVOID)Mine_RegOpenKeyExA));
547
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegOpenKeyExW, (PVOID)Mine_RegOpenKeyExW));
548
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegQueryInfoKeyA, (PVOID)Mine_RegQueryInfoKeyA));
549
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegQueryInfoKeyW, (PVOID)Mine_RegQueryInfoKeyW));
550
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegQueryValueA, (PVOID)Mine_RegQueryValueA));
551
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegQueryValueW, (PVOID)Mine_RegQueryValueW));
552
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegQueryValueExA, (PVOID)Mine_RegQueryValueExA));
553
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegQueryValueExW, (PVOID)Mine_RegQueryValueExW));
554
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegSetValueA, (PVOID)Mine_RegSetValueA));
555
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegSetValueW, (PVOID)Mine_RegSetValueW));
556
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegSetValueExA, (PVOID)Mine_RegSetValueExA));
557
+        ENSURE(Mhook_SetHook(&(PVOID&)Real_RegSetValueExW, (PVOID)Mine_RegSetValueExW));
558 558
 
559 559
         fInitialized = true;
560 560
     }

+ 11
- 8
src/mpc-hc/mpc-hc.vcxproj View File

@@ -160,7 +160,7 @@
160 160
       <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
161 161
     </ResourceCompile>
162 162
     <Link>
163
-      <AdditionalDependencies>RARFileSource.res;delayimp.lib;detours.lib;dsound.lib;dxguid.lib;GdiPlus.lib;Psapi.lib;QTMLClient.lib;SetupAPI.lib;UxTheme.lib;Vfw32.lib;Winmm.lib;d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
163
+      <AdditionalDependencies>RARFileSource.res;delayimp.lib;dsound.lib;dxguid.lib;GdiPlus.lib;Psapi.lib;QTMLClient.lib;SetupAPI.lib;UxTheme.lib;Vfw32.lib;Winmm.lib;d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
164 164
       <AdditionalLibraryDirectories>$(SolutionDir)bin\lib\$(Configuration)_$(Platform);$(SolutionDir)lib;$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
165 165
       <AdditionalLibraryDirectories Condition="'$(PlatformToolsetVersion)'=='110'">$(SolutionDir)bin12\lib\$(Configuration)_$(Platform);$(SolutionDir)lib;$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
166 166
       <IgnoreSpecificDefaultLibraries>LIBCMT.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
@@ -181,7 +181,7 @@
181 181
       <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
182 182
     </ResourceCompile>
183 183
     <Link>
184
-      <AdditionalDependencies>AudioSwitcher.lib;BaseClasses.lib;BaseMuxer.lib;BufferFilter.lib;CmdUI.lib;DeCSS.lib;DSMMuxer.lib;DSUtil.lib;Filters.lib;kasumi.lib;LCDUI.lib;lcms2.lib;MatroskaMuxer.lib;MpcAudioRenderer.lib;ResizableLib.lib;sizecbar.lib;SoundTouch.lib;StreamDriveThru.lib;SubPic.lib;Subtitles.lib;SubtitleSource.lib;SyncClock.lib;system.lib;TreePropSheet.lib;unrar.lib;VideoRenderers.lib;WavDest.lib;zlib.lib;UxTheme.lib;delayimp.lib;detours.lib;dsound.lib;dxguid.lib;GdiPlus.lib;Psapi.lib;QTMLClient.lib;SetupAPI.lib;Vfw32.lib;Winmm.lib;d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
184
+      <AdditionalDependencies>AudioSwitcher.lib;BaseClasses.lib;BaseMuxer.lib;BufferFilter.lib;CmdUI.lib;DeCSS.lib;DSMMuxer.lib;DSUtil.lib;Filters.lib;kasumi.lib;LCDUI.lib;lcms2.lib;MatroskaMuxer.lib;MpcAudioRenderer.lib;ResizableLib.lib;sizecbar.lib;SoundTouch.lib;StreamDriveThru.lib;SubPic.lib;Subtitles.lib;SubtitleSource.lib;SyncClock.lib;system.lib;TreePropSheet.lib;unrar.lib;VideoRenderers.lib;WavDest.lib;zlib.lib;UxTheme.lib;delayimp.lib;dsound.lib;dxguid.lib;GdiPlus.lib;Psapi.lib;QTMLClient.lib;SetupAPI.lib;Vfw32.lib;Winmm.lib;d3d9.lib;mhook.lib;%(AdditionalDependencies)</AdditionalDependencies>
185 185
       <AdditionalLibraryDirectories>$(SolutionDir)bin\lib\Debug_$(Platform);$(SolutionDir)lib;$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
186 186
       <AdditionalLibraryDirectories Condition="'$(PlatformToolsetVersion)'=='110'">$(SolutionDir)bin12\lib\Debug_$(Platform);$(SolutionDir)lib;$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
187 187
       <DelayLoadDLLs>d3d9.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
@@ -203,7 +203,7 @@
203 203
       <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
204 204
     </ResourceCompile>
205 205
     <Link>
206
-      <AdditionalDependencies>RARFileSource.res;delayimp.lib;detours.lib;dsound.lib;dxguid.lib;GdiPlus.lib;Psapi.lib;SetupAPI.lib;strmiids.lib;UxTheme.lib;Uuid.Lib;Vfw32.lib;Version.lib;Winmm.lib;d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
206
+      <AdditionalDependencies>RARFileSource.res;delayimp.lib;dsound.lib;dxguid.lib;GdiPlus.lib;Psapi.lib;SetupAPI.lib;strmiids.lib;UxTheme.lib;Uuid.Lib;Vfw32.lib;Version.lib;Winmm.lib;d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
207 207
       <AdditionalLibraryDirectories>$(SolutionDir)bin\lib\$(Configuration)_$(Platform);$(SolutionDir)lib64;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
208 208
       <AdditionalLibraryDirectories Condition="'$(PlatformToolsetVersion)'=='110'">$(SolutionDir)bin12\lib\$(Configuration)_$(Platform);$(SolutionDir)lib64;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
209 209
       <IgnoreSpecificDefaultLibraries>LIBCMT.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
@@ -224,7 +224,7 @@
224 224
       <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
225 225
     </ResourceCompile>
226 226
     <Link>
227
-      <AdditionalDependencies>AudioSwitcher.lib;BaseClasses.lib;BaseMuxer.lib;BufferFilter.lib;CmdUI.lib;DeCSS.lib;DSMMuxer.lib;DSUtil.lib;Filters.lib;kasumi.lib;LCDUI.lib;lcms2.lib;MatroskaMuxer.lib;MpcAudioRenderer.lib;ResizableLib.lib;sizecbar.lib;SoundTouch.lib;StreamDriveThru.lib;SubPic.lib;Subtitles.lib;SubtitleSource.lib;SyncClock.lib;system.lib;TreePropSheet.lib;unrar.lib;VideoRenderers.lib;WavDest.lib;zlib.lib;UxTheme.lib;delayimp.lib;detours.lib;dsound.lib;dxguid.lib;GdiPlus.lib;Psapi.lib;SetupAPI.lib;strmiids.lib;Uuid.Lib;Version.lib;Vfw32.lib;Winmm.lib;d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
227
+      <AdditionalDependencies>AudioSwitcher.lib;BaseClasses.lib;BaseMuxer.lib;BufferFilter.lib;CmdUI.lib;DeCSS.lib;DSMMuxer.lib;DSUtil.lib;Filters.lib;kasumi.lib;LCDUI.lib;lcms2.lib;MatroskaMuxer.lib;MpcAudioRenderer.lib;ResizableLib.lib;sizecbar.lib;SoundTouch.lib;StreamDriveThru.lib;SubPic.lib;Subtitles.lib;SubtitleSource.lib;SyncClock.lib;system.lib;TreePropSheet.lib;unrar.lib;VideoRenderers.lib;WavDest.lib;zlib.lib;UxTheme.lib;delayimp.lib;dsound.lib;dxguid.lib;GdiPlus.lib;Psapi.lib;SetupAPI.lib;strmiids.lib;Uuid.Lib;Version.lib;Vfw32.lib;Winmm.lib;d3d9.lib;mhook.lib;%(AdditionalDependencies)</AdditionalDependencies>
228 228
       <AdditionalLibraryDirectories>$(SolutionDir)bin\lib\Debug_$(Platform);$(SolutionDir)lib64;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
229 229
       <AdditionalLibraryDirectories Condition="'$(PlatformToolsetVersion)'=='110'">$(SolutionDir)bin12\lib\Debug_$(Platform);$(SolutionDir)lib64;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
230 230
       <DelayLoadDLLs>d3d9.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
@@ -246,7 +246,7 @@
246 246
       <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
247 247
     </ResourceCompile>
248 248
     <Link>
249
-      <AdditionalDependencies>RARFileSource.res;delayimp.lib;detours.lib;dsound.lib;dxguid.lib;GdiPlus.lib;Psapi.lib;QTMLClient.lib;SetupAPI.lib;UxTheme.lib;Vfw32.lib;Winmm.lib;d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
249
+      <AdditionalDependencies>RARFileSource.res;delayimp.lib;dsound.lib;dxguid.lib;GdiPlus.lib;Psapi.lib;QTMLClient.lib;SetupAPI.lib;UxTheme.lib;Vfw32.lib;Winmm.lib;d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
250 250
       <AdditionalLibraryDirectories>$(SolutionDir)bin\lib\$(Configuration)_$(Platform);$(SolutionDir)lib;$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
251 251
       <AdditionalLibraryDirectories Condition="'$(PlatformToolsetVersion)'=='110'">$(SolutionDir)bin12\lib\$(Configuration)_$(Platform);$(SolutionDir)lib;$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
252 252
       <DelayLoadDLLs>d3d9.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
@@ -266,7 +266,7 @@
266 266
       <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
267 267
     </ResourceCompile>
268 268
     <Link>
269
-      <AdditionalDependencies>AudioSwitcher.lib;BaseClasses.lib;BaseMuxer.lib;BufferFilter.lib;CmdUI.lib;DeCSS.lib;DSMMuxer.lib;DSUtil.lib;Filters.lib;kasumi.lib;LCDUI.lib;lcms2.lib;MatroskaMuxer.lib;MpcAudioRenderer.lib;ResizableLib.lib;sizecbar.lib;SoundTouch.lib;StreamDriveThru.lib;SubPic.lib;Subtitles.lib;SubtitleSource.lib;SyncClock.lib;system.lib;TreePropSheet.lib;unrar.lib;VideoRenderers.lib;WavDest.lib;zlib.lib;UxTheme.lib;delayimp.lib;detours.lib;dsound.lib;dxguid.lib;GdiPlus.lib;Psapi.lib;QTMLClient.lib;SetupAPI.lib;Vfw32.lib;Winmm.lib;d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
269
+      <AdditionalDependencies>AudioSwitcher.lib;BaseClasses.lib;BaseMuxer.lib;BufferFilter.lib;CmdUI.lib;DeCSS.lib;DSMMuxer.lib;DSUtil.lib;Filters.lib;kasumi.lib;LCDUI.lib;lcms2.lib;MatroskaMuxer.lib;MpcAudioRenderer.lib;ResizableLib.lib;sizecbar.lib;SoundTouch.lib;StreamDriveThru.lib;SubPic.lib;Subtitles.lib;SubtitleSource.lib;SyncClock.lib;system.lib;TreePropSheet.lib;unrar.lib;VideoRenderers.lib;WavDest.lib;zlib.lib;UxTheme.lib;delayimp.lib;dsound.lib;dxguid.lib;GdiPlus.lib;Psapi.lib;QTMLClient.lib;SetupAPI.lib;Vfw32.lib;Winmm.lib;d3d9.lib;mhook.lib;%(AdditionalDependencies)</AdditionalDependencies>
270 270
       <AdditionalLibraryDirectories>$(SolutionDir)bin\lib\Release_$(Platform);$(SolutionDir)lib;$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
271 271
       <AdditionalLibraryDirectories Condition="'$(PlatformToolsetVersion)'=='110'">$(SolutionDir)bin12\lib\Release_$(Platform);$(SolutionDir)lib;$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
272 272
       <DelayLoadDLLs>d3d9.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
@@ -287,7 +287,7 @@
287 287
       <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
288 288
     </ResourceCompile>
289 289
     <Link>
290
-      <AdditionalDependencies>RARFileSource.res;delayimp.lib;detours.lib;dsound.lib;dxguid.lib;GdiPlus.lib;Psapi.lib;SetupAPI.lib;strmiids.lib;UxTheme.lib;Uuid.Lib;Vfw32.lib;Version.lib;Winmm.lib;d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
290
+      <AdditionalDependencies>RARFileSource.res;delayimp.lib;dsound.lib;dxguid.lib;GdiPlus.lib;Psapi.lib;SetupAPI.lib;strmiids.lib;UxTheme.lib;Uuid.Lib;Vfw32.lib;Version.lib;Winmm.lib;d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
291 291
       <AdditionalLibraryDirectories>$(SolutionDir)bin\lib\$(Configuration)_$(Platform);$(SolutionDir)lib64;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
292 292
       <AdditionalLibraryDirectories Condition="'$(PlatformToolsetVersion)'=='110'">$(SolutionDir)bin12\lib\$(Configuration)_$(Platform);$(SolutionDir)lib64;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
293 293
       <DelayLoadDLLs>d3d9.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
@@ -307,7 +307,7 @@
307 307
       <AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
308 308
     </ResourceCompile>
309 309
     <Link>
310
-      <AdditionalDependencies>AudioSwitcher.lib;BaseClasses.lib;BaseMuxer.lib;BufferFilter.lib;CmdUI.lib;DeCSS.lib;DSMMuxer.lib;DSUtil.lib;Filters.lib;kasumi.lib;LCDUI.lib;lcms2.lib;MatroskaMuxer.lib;MpcAudioRenderer.lib;ResizableLib.lib;sizecbar.lib;SoundTouch.lib;StreamDriveThru.lib;SubPic.lib;Subtitles.lib;SubtitleSource.lib;SyncClock.lib;system.lib;TreePropSheet.lib;unrar.lib;VideoRenderers.lib;WavDest.lib;zlib.lib;UxTheme.lib;delayimp.lib;detours.lib;dsound.lib;dxguid.lib;GdiPlus.lib;Psapi.lib;SetupAPI.lib;strmiids.lib;Uuid.Lib;Version.lib;Vfw32.lib;Winmm.lib;d3d9.lib;%(AdditionalDependencies)</AdditionalDependencies>
310
+      <AdditionalDependencies>AudioSwitcher.lib;BaseClasses.lib;BaseMuxer.lib;BufferFilter.lib;CmdUI.lib;DeCSS.lib;DSMMuxer.lib;DSUtil.lib;Filters.lib;kasumi.lib;LCDUI.lib;lcms2.lib;MatroskaMuxer.lib;MpcAudioRenderer.lib;ResizableLib.lib;sizecbar.lib;SoundTouch.lib;StreamDriveThru.lib;SubPic.lib;Subtitles.lib;SubtitleSource.lib;SyncClock.lib;system.lib;TreePropSheet.lib;unrar.lib;VideoRenderers.lib;WavDest.lib;zlib.lib;UxTheme.lib;delayimp.lib;dsound.lib;dxguid.lib;GdiPlus.lib;Psapi.lib;SetupAPI.lib;strmiids.lib;Uuid.Lib;Version.lib;Vfw32.lib;Winmm.lib;d3d9.lib;mhook.lib;%(AdditionalDependencies)</AdditionalDependencies>
311 311
       <AdditionalLibraryDirectories>$(SolutionDir)bin\lib\Release_$(Platform);$(SolutionDir)lib64;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
312 312
       <AdditionalLibraryDirectories>$(SolutionDir)bin12\lib\Release_$(Platform);$(SolutionDir)lib64;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
313 313
       <DelayLoadDLLs>d3d9.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
@@ -792,6 +792,9 @@
792 792
     <ProjectReference Include="..\thirdparty\MediaInfo\MediaInfoLib.vcxproj">
793 793
       <Project>{20e0f8d6-213c-460b-b361-9c725cb375c7}</Project>
794 794
     </ProjectReference>
795
+    <ProjectReference Include="..\thirdparty\mhook\mhook.vcxproj">
796
+      <Project>{f841363c-a630-4716-8941-cddc1f32cfc3}</Project>
797
+    </ProjectReference>
795 798
     <ProjectReference Include="..\thirdparty\RARFileSource\RARFileSource.vcxproj">
796 799
       <Project>{2b7f22d7-1750-47c5-8709-1a3688b62499}</Project>
797 800
     </ProjectReference>

+ 10
- 19
src/mpc-hc/mplayerc.cpp View File

@@ -36,7 +36,7 @@
36 36
 #include "FileAssoc.h"
37 37
 #include "UpdateChecker.h"
38 38
 #include "winddk/ntddcdvd.h"
39
-#include "detours/detours.h"
39
+#include "mhook/mhook-lib/mhook.h"
40 40
 #include <afxsock.h>
41 41
 #include <atlsync.h>
42 42
 #include <atlutil.h>
@@ -1127,8 +1127,6 @@ BOOL CMPlayerCApp::InitInstance()
1127 1127
     // Remove the working directory from the search path to work around the DLL preloading vulnerability
1128 1128
     SetDllDirectory(_T(""));
1129 1129
 
1130
-    long lError;
1131
-
1132 1130
     if (SetHeapOptions()) {
1133 1131
         TRACE(_T("Terminate on corruption enabled\n"));
1134 1132
     } else {
@@ -1137,19 +1135,15 @@ BOOL CMPlayerCApp::InitInstance()
1137 1135
         TRACE(heap_err);
1138 1136
     }
1139 1137
 
1140
-    DetourRestoreAfterWith();
1141
-    DetourTransactionBegin();
1142
-    DetourUpdateThread(GetCurrentThread());
1143
-
1144
-    DetourAttach(&(PVOID&)Real_IsDebuggerPresent, (PVOID)Mine_IsDebuggerPresent);
1145
-    DetourAttach(&(PVOID&)Real_ChangeDisplaySettingsExA, (PVOID)Mine_ChangeDisplaySettingsExA);
1146
-    DetourAttach(&(PVOID&)Real_ChangeDisplaySettingsExW, (PVOID)Mine_ChangeDisplaySettingsExW);
1147
-    DetourAttach(&(PVOID&)Real_CreateFileA, (PVOID)Mine_CreateFileA);
1148
-    DetourAttach(&(PVOID&)Real_CreateFileW, (PVOID)Mine_CreateFileW);
1149
-    DetourAttach(&(PVOID&)Real_mixerSetControlDetails, (PVOID)Mine_mixerSetControlDetails);
1150
-    DetourAttach(&(PVOID&)Real_DeviceIoControl, (PVOID)Mine_DeviceIoControl);
1138
+    ENSURE(Mhook_SetHook(&(PVOID&)Real_IsDebuggerPresent, (PVOID)Mine_IsDebuggerPresent));
1139
+    ENSURE(Mhook_SetHook(&(PVOID&)Real_ChangeDisplaySettingsExA, (PVOID)Mine_ChangeDisplaySettingsExA));
1140
+    ENSURE(Mhook_SetHook(&(PVOID&)Real_ChangeDisplaySettingsExW, (PVOID)Mine_ChangeDisplaySettingsExW));
1141
+    ENSURE(Mhook_SetHook(&(PVOID&)Real_CreateFileA, (PVOID)Mine_CreateFileA));
1142
+    ENSURE(Mhook_SetHook(&(PVOID&)Real_CreateFileW, (PVOID)Mine_CreateFileW));
1143
+    ENSURE(Mhook_SetHook(&(PVOID&)Real_mixerSetControlDetails, (PVOID)Mine_mixerSetControlDetails));
1144
+    ENSURE(Mhook_SetHook(&(PVOID&)Real_DeviceIoControl, (PVOID)Mine_DeviceIoControl));
1151 1145
 
1152
-    DetourAttach(&(PVOID&)Real_LockWindowUpdate, (PVOID)Mine_LockWindowUpdate);
1146
+    ENSURE(Mhook_SetHook(&(PVOID&)Real_LockWindowUpdate, (PVOID)Mine_LockWindowUpdate));
1153 1147
 
1154 1148
     m_hNTDLL = LoadLibrary(_T("ntdll.dll"));
1155 1149
 #ifndef _DEBUG  // Disable NtQueryInformationProcess in debug (prevent VS debugger to stop on crash address)
@@ -1157,16 +1151,13 @@ BOOL CMPlayerCApp::InitInstance()
1157 1151
         Real_NtQueryInformationProcess = (FUNC_NTQUERYINFORMATIONPROCESS)GetProcAddress(m_hNTDLL, "NtQueryInformationProcess");
1158 1152
 
1159 1153
         if (Real_NtQueryInformationProcess) {
1160
-            DetourAttach(&(PVOID&)Real_NtQueryInformationProcess, (PVOID)Mine_NtQueryInformationProcess);
1154
+            ENSURE(Mhook_SetHook(&(PVOID&)Real_NtQueryInformationProcess, (PVOID)Mine_NtQueryInformationProcess));
1161 1155
         }
1162 1156
     }
1163 1157
 #endif
1164 1158
 
1165 1159
     CFilterMapper2::Init();
1166 1160
 
1167
-    lError = DetourTransactionCommit();
1168
-    ASSERT(lError == NOERROR);
1169
-
1170 1161
     if (FAILED(OleInitialize(0))) {
1171 1162
         AfxMessageBox(_T("OleInitialize failed!"));
1172 1163
         return FALSE;

+ 93
- 0
src/thirdparty/mhook/disasm-lib/cpu.c View File

@@ -0,0 +1,93 @@
1
+// Copyright (C) 2003, Matt Conover (mconover@gmail.com)
2
+#include "cpu.h"
3
+#include <assert.h>
4
+
5
+// NOTE: this assumes default scenarios (i.e., we assume CS/DS/ES/SS and flat
6
+// and all have a base of 0 and limit of 0xffffffff, we don't try to verify
7
+// that in the GDT)
8
+//
9
+// TODO: use inline assembly to get selector for segment
10
+// Segment = x86 segment register (SEG_ES = 0, SEG_CS = 1, ...)
11
+BYTE *GetAbsoluteAddressFromSegment(BYTE Segment, DWORD Offset)
12
+{
13
+	switch (Segment)
14
+	{
15
+		// Windows uses a flat address space (except FS for x86 and GS for x64)
16
+		case 0: // SEG_ES
17
+		case 1: // SEG_CS
18
+		case 2: // SEG_SS
19
+		case 3: // SEG_DS
20
+			return (BYTE *)(DWORD_PTR)Offset;
21
+		case 4: // SEG_FS
22
+		case 5: // SEG_GS
23
+			return (BYTE *)(DWORD_PTR)Offset;
24
+			// Note: we're really supposed to do this, but get_teb is not implemented
25
+			// in this bastardized version of the disassembler.
26
+			// return (BYTE *)get_teb() + Offset;
27
+		default:
28
+			assert(0);
29
+			return (BYTE *)(DWORD_PTR)Offset;
30
+	}
31
+}
32
+
33
+// This is an GDT/LDT selector (pGDT+Selector)
34
+BYTE *GetAbsoluteAddressFromSelector(WORD Selector, DWORD Offset)
35
+{
36
+	DESCRIPTOR_ENTRY Entry;
37
+	GATE_ENTRY *Gate;
38
+	ULONG_PTR Base;
39
+	
40
+	assert(Selector < 0x10000);
41
+	if (!GetThreadSelectorEntry(GetCurrentThread(), Selector, (LDT_ENTRY *)&Entry)) return NULL;
42
+	if (!Entry.Present) return NULL;
43
+	if (Entry.System)
44
+	{
45
+		Base = 0;
46
+#ifdef _WIN64
47
+		Base |= (ULONG_PTR)Entry.HighOffset64 << 32;
48
+#endif
49
+		Base |= Entry.BaseHi << 24;
50
+		Base |= Entry.BaseMid << 16;
51
+		Base |= Entry.BaseLow;
52
+	}
53
+	else
54
+	{
55
+		switch (Entry.Type)
56
+		{
57
+			case 1: // 16-bit TSS (available)
58
+			case 2: // LDT
59
+			case 3: // 16-bit TSS (busy)
60
+			case 9: // 32-bit TSS (available)
61
+			case 11: // 32-bit TSS (busy)
62
+				Base = 0;
63
+#ifdef _WIN64
64
+				Base |= (ULONG_PTR)Entry.HighOffset64 << 32;
65
+#endif
66
+				Base |= Entry.BaseHi << 24;
67
+				Base |= Entry.BaseMid << 16;
68
+				Base |= Entry.BaseLow;
69
+				break;
70
+
71
+			case 4: // 16-bit call gate
72
+			case 5: // task gate
73
+			case 6: // 16-bit interrupt gate
74
+			case 7: // 16-bit task gate
75
+			case 12: // 32-bit call gate
76
+			case 14: // 32-bit interrupt gate
77
+			case 15: // 32-bit trap gate
78
+				Gate = (GATE_ENTRY *)&Entry;
79
+#ifdef _WIN64
80
+				Base = ((ULONG_PTR)Gate->HighOffset64 << 32) | (Gate->HighOffset << 16) | Gate->LowOffset;
81
+#else
82
+				Base = (Gate->HighOffset << 16) | Gate->LowOffset;
83
+#endif
84
+				assert(!Offset); Offset = 0;
85
+				break;
86
+			default:
87
+				assert(0);
88
+				return NULL;
89
+		}
90
+	}
91
+	return (BYTE *)Base + Offset;
92
+}
93
+

+ 277
- 0
src/thirdparty/mhook/disasm-lib/cpu.h View File

@@ -0,0 +1,277 @@
1
+// Copyright (C) 2003, Matt Conover (mconover@gmail.com)
2
+#ifndef CPU_H
3
+#define CPU_H
4
+#ifdef __cplusplus
5
+extern "C" {
6
+#endif
7
+#pragma pack(push,1)
8
+
9
+#include <windows.h>
10
+#include "misc.h"
11
+
12
+////////////////////////////////////////////////////////
13
+// System descriptors
14
+////////////////////////////////////////////////////////
15
+
16
+#define GDT_NULL 0
17
+#define GDT_R0_CODE 0x08
18
+#define GDT_R0_DATA 0x10
19
+#define GDT_R3_CODE 0x18
20
+#define GDT_R3_DATA 0x20
21
+#define GDT_TSS 0x28
22
+#define GDT_PCR 0x30
23
+#define GDT_R3_TEB 0x38
24
+#define GDT_VDM 0x40
25
+#define GDT_LDT 0x48
26
+#define GDT_DOUBLEFAULT_TSS 0x50
27
+#define GDT_NMI_TSS 0x58
28
+
29
+// 16-bit GDT entries:
30
+// TODO: #define GDT_ABIOS_UNKNOWN   0x60  (22F30-32F2F)
31
+#define GDT_ABIOS_VIDEO 0x68
32
+#define GDT_ABIOS_GDT   0x70 // descriptor describing ABIOS GDT itself
33
+#define GDT_ABIOS_NTOS  0x78 // first 64K of NTOSKRNL
34
+#define GDT_ABIOS_CDA   0xE8 // common data area
35
+#define GDT_ABIOS_CODE  0xF0 // KiI386AbiosCall
36
+#define GDT_ABIOS_STACK 0xF8
37
+
38
+#define SELECTOR_RPL_MASK 0x03 // bits 0-1
39
+#define SELECTOR_LDT      0x04 // bit 2
40
+
41
+// for data selectors
42
+#define DATA_ACCESS_MASK       (1<<0)
43
+#define DATA_WRITE_ENABLE_MASK (1<<1)
44
+#define DATA_EXPAND_DOWN_MASK  (1<<2)
45
+
46
+// for code selectors
47
+#define CODE_ACCESS_MASK       (1<<0)
48
+#define CODE_READ_MASK         (1<<1)
49
+#define CODE_CONFORMING_MASK   (1<<2)
50
+#define CODE_FLAG              (1<<3)
51
+
52
+#define TASK_GATE      5
53
+#define INTERRUPT_GATE 6
54
+#define TRAP_GATE      7
55
+
56
+typedef struct _IDT_ENTRY
57
+{
58
+   USHORT LowOffset;
59
+   USHORT Selector;
60
+   UCHAR Ignored : 5;
61
+   UCHAR Zero : 3;
62
+   UCHAR Type : 3;
63
+   UCHAR Is32Bit : 1;
64
+   UCHAR Ignored2 : 1;
65
+   UCHAR DPL : 2;
66
+   UCHAR Present : 1;
67
+   USHORT HighOffset;
68
+#ifdef _WIN64
69
+   ULONG HighOffset64;
70
+   ULONG Reserved;
71
+#endif
72
+} IDT_ENTRY, TRAP_GATE_ENTRY;
73
+
74
+typedef struct _CALL_GATE_ENTRY
75
+{
76
+   USHORT LowOffset;
77
+   USHORT Selector;
78
+   UCHAR ParameterCount: 4;
79
+   UCHAR Ignored : 3;
80
+   UCHAR Type : 5;
81
+   UCHAR DPL : 2;
82
+   UCHAR Present : 1;
83
+   USHORT HighOffset;
84
+#ifdef _WIN64
85
+   ULONG HighOffset64;
86
+   ULONG Reserved;
87
+#endif
88
+} CALL_GATE_ENTRY;
89
+
90
+typedef struct _TASK_GATE_ENTRY
91
+{
92
+   USHORT Ignored;
93
+   USHORT Selector;
94
+   UCHAR Ignored2 : 5;
95
+   UCHAR Zero : 3;
96
+   UCHAR Type : 5;
97
+   UCHAR DPL : 2;
98
+   UCHAR Present : 1;
99
+   USHORT Ignored3;
100
+} TASK_GATE_ENTRY;
101
+
102
+typedef struct _DESCRIPTOR_ENTRY
103
+{
104
+    USHORT  LimitLow;
105
+    USHORT  BaseLow;
106
+    UCHAR   BaseMid;
107
+    UCHAR   Type : 4;        // 10EWA (code), E=ExpandDown, W=Writable, A=Accessed
108
+                             // 11CRA (data), C=Conforming, R=Readable, A=Accessed
109
+    UCHAR   System : 1;      // if 1 then it is a gate or LDT
110
+    UCHAR   DPL : 2;         // descriptor privilege level; 
111
+                             // for data selectors, MAX(CPL, RPL) must be <= DPL to access (or else GP# fault)
112
+                             // for non-conforming code selectors (without callgate), MAX(CPL, RPL) must be <= DPL to access (or else GP# fault)
113
+                             // for conforming code selectors, MAX(CPL, RPL) must be >= DPL (i.e., CPL 0-2 cannot access if DPL is 3)
114
+                             // for non-conforming code selectors (with call gate), DPL indicates lowest privilege allowed to access gate
115
+    UCHAR   Present : 1;
116
+    UCHAR   LimitHigh : 4;
117
+    UCHAR   Available: 1;    // aka AVL
118
+    UCHAR   Reserved : 1;
119
+    UCHAR   Is32Bit : 1;     // aka B flag
120
+    UCHAR   Granularity : 1; // aka G flag
121
+    UCHAR   BaseHi : 8;
122
+#ifdef _WIN64
123
+   ULONG HighOffset64;
124
+   ULONG Reserved2;
125
+#endif
126
+} DESCRIPTOR_ENTRY;
127
+
128
+typedef struct _GATE_ENTRY
129
+{
130
+   USHORT LowOffset;
131
+   UCHAR Skip;
132
+   UCHAR Type : 5;
133
+   UCHAR DPL : 2;
134
+   UCHAR Present : 1;
135
+   USHORT HighOffset;
136
+#ifdef _WIN64
137
+   ULONG HighOffset64;
138
+   ULONG Reserved;
139
+#endif
140
+} GATE_ENTRY;
141
+
142
+// TODO: update for X64
143
+typedef struct _PTE_ENTRY
144
+{
145
+    ULONG Present : 1;
146
+    ULONG Write : 1;
147
+    ULONG Owner : 1; // E.g., user mode or supervisor mode
148
+    ULONG WriteThrough : 1;
149
+    ULONG CacheDisable : 1;
150
+    ULONG Accessed : 1;
151
+    ULONG Dirty : 1;
152
+    ULONG PAT : 1;
153
+    ULONG Global : 1;
154
+    ULONG CopyOnWrite : 1;
155
+    ULONG Prototype : 1;
156
+    ULONG Transition : 1;
157
+    ULONG Address : 20;
158
+} PTE_ENTRY;
159
+
160
+// TODO: update for X64
161
+typedef struct _PDE_ENTRY
162
+{
163
+	ULONG Present : 1;
164
+	ULONG Write : 1;
165
+	ULONG Owner : 1;
166
+	ULONG WriteThrough : 1;
167
+	ULONG CacheDisable : 1;
168
+	ULONG Accessed : 1;
169
+	ULONG Reserved1 : 1;
170
+	ULONG PageSize : 1;
171
+	ULONG Global : 1;
172
+	ULONG Reserved : 3;
173
+	ULONG Address : 20;
174
+} PDE_ENTRY;
175
+
176
+// TODO: update for X64
177
+typedef struct _IO_ACCESS_MAP
178
+{
179
+    UCHAR DirectionMap[32];
180
+    UCHAR IoMap[8196];
181
+} IO_ACCESS_MAP;
182
+
183
+#define MIN_TSS_SIZE FIELD_OFFSET(TSS_ENTRY, IoMaps)
184
+// TODO: update for X64
185
+typedef struct _TSS_ENTRY
186
+{
187
+    USHORT  Backlink;
188
+    USHORT  Reserved0;
189
+    ULONG   Esp0;
190
+    USHORT  Ss0;
191
+    USHORT  Reserved1;
192
+    ULONG   NotUsed1[4];
193
+    ULONG   CR3;
194
+    ULONG   Eip;
195
+    ULONG   NotUsed2[9];
196
+    USHORT  Es;
197
+    USHORT  Reserved2;
198
+    USHORT  Cs;
199
+    USHORT  Reserved3;
200
+    USHORT  Ss;
201
+    USHORT  Reserved4;
202
+    USHORT  Ds;
203
+    USHORT  Reserved5;
204
+    USHORT  Fs;
205
+    USHORT  Reserved6;
206
+    USHORT  Gs;
207
+    USHORT  Reserved7;
208
+    USHORT  LDT;
209
+    USHORT  Reserved8;
210
+    USHORT  Flags;
211
+    USHORT  IoMapBase;
212
+    IO_ACCESS_MAP IoMaps[1];
213
+    UCHAR IntDirectionMap[32];
214
+} TSS_ENTRY;
215
+
216
+// TODO: update for X64
217
+typedef struct _TSS16_ENTRY
218
+{
219
+    USHORT  Backlink;
220
+    USHORT  Sp0;
221
+    USHORT  Ss0;
222
+    USHORT  Sp1;
223
+    USHORT  Ss1;
224
+    USHORT  Sp2;
225
+    USHORT  Ss3;
226
+    USHORT  Ip;
227
+    USHORT  Flags;
228
+    USHORT  Ax;
229
+    USHORT  Cx;
230
+    USHORT  Dx;
231
+    USHORT  Bx;
232
+    USHORT  Sp;
233
+    USHORT  Bp;
234
+    USHORT  Si;
235
+    USHORT  Di;
236
+    USHORT  Es;
237
+    USHORT  Cs;
238
+    USHORT  Ss;
239
+    USHORT  Ds;
240
+    USHORT  LDT;
241
+} TSS16_ENTRY;
242
+
243
+// TODO: update for X64
244
+typedef struct _GDT_ENTRY
245
+{
246
+    USHORT  LimitLow;
247
+    USHORT  BaseLow;
248
+    union {
249
+        struct {
250
+            UCHAR   BaseMid;
251
+            UCHAR   Flags1;
252
+            UCHAR   Flags2;
253
+            UCHAR   BaseHi;
254
+        } Bytes;
255
+        struct {
256
+            ULONG   BaseMid : 8;
257
+            ULONG   Type : 5;
258
+            ULONG   Dpl : 2;
259
+            ULONG   Pres : 1;
260
+            ULONG   LimitHi : 4;
261
+            ULONG   Sys : 1;
262
+            ULONG   Reserved_0 : 1;
263
+            ULONG   Default_Big : 1;
264
+            ULONG   Granularity : 1;
265
+            ULONG   BaseHi : 8;
266
+        } Bits;
267
+    } HighWord;
268
+} GDT_ENTRY;
269
+
270
+BYTE *GetAbsoluteAddressFromSegment(BYTE Segment, DWORD Offset);
271
+BYTE *GetAbsoluteAddressFromSelector(WORD Selector, DWORD Offset);
272
+
273
+#pragma pack(pop)
274
+#ifdef __cplusplus
275
+}
276
+#endif
277
+#endif // CPU_H

+ 122
- 0
src/thirdparty/mhook/disasm-lib/disasm.c View File

@@ -0,0 +1,122 @@
1
+// Copyright (C) 2004, Matt Conover (mconover@gmail.com)
2
+#undef NDEBUG
3
+#include <assert.h>
4
+#include <windows.h>
5
+#include "disasm.h"
6
+
7
+#ifdef NO_SANITY_CHECKS
8
+#define NDEBUG
9
+#undef assert
10
+#define assert(x)
11
+#endif
12
+
13
+//////////////////////////////////////////////////////////////////////
14
+// Global variables
15
+//////////////////////////////////////////////////////////////////////
16
+
17
+ARCHITECTURE_FORMAT SupportedArchitectures[] =
18
+{
19
+	{ ARCH_X86,	&X86 },
20
+	{ ARCH_X86_16, &X86 },
21
+	{ ARCH_X64,	&X86 },
22
+	{ ARCH_UNKNOWN, NULL }
23
+};
24
+
25
+typedef struct _DISASM_ARG_INFO
26
+{
27
+	INSTRUCTION *MatchedInstruction;
28
+	BOOL MatchPrefix;
29
+	U8 *Opcode;
30
+	U32 OpcodeLength;
31
+	INSTRUCTION_TYPE InstructionType;
32
+	U32 Count;
33
+} DISASM_ARG_INFO;
34
+
35
+//////////////////////////////////////////////////////////////////////
36
+// Function prototypes
37
+//////////////////////////////////////////////////////////////////////
38
+
39
+BOOL InitInstruction(INSTRUCTION *Instruction, DISASSEMBLER *Disassembler);
40
+struct _ARCHITECTURE_FORMAT *GetArchitectureFormat(ARCHITECTURE_TYPE Type);
41
+
42
+//////////////////////////////////////////////////////////////////////
43
+// Disassembler setup
44
+//////////////////////////////////////////////////////////////////////
45
+
46
+BOOL InitDisassembler(DISASSEMBLER *Disassembler, ARCHITECTURE_TYPE Architecture)
47
+{
48
+	ARCHITECTURE_FORMAT *ArchFormat;
49
+
50
+	memset(Disassembler, 0, sizeof(DISASSEMBLER));
51
+	Disassembler->Initialized = DISASSEMBLER_INITIALIZED;
52
+	
53
+	ArchFormat = GetArchitectureFormat(Architecture);
54
+	if (!ArchFormat) { assert(0); return FALSE; }
55
+	Disassembler->ArchType = ArchFormat->Type;
56
+	Disassembler->Functions = ArchFormat->Functions;
57
+	return TRUE;
58
+}
59
+
60
+void CloseDisassembler(DISASSEMBLER *Disassembler)
61
+{
62
+	memset(Disassembler, 0, sizeof(DISASSEMBLER));
63
+}
64
+
65
+//////////////////////////////////////////////////////////////////////
66
+// Instruction setup
67
+//////////////////////////////////////////////////////////////////////
68
+
69
+BOOL InitInstruction(INSTRUCTION *Instruction, DISASSEMBLER *Disassembler)
70
+{
71
+	memset(Instruction, 0, sizeof(INSTRUCTION));
72
+	Instruction->Initialized = INSTRUCTION_INITIALIZED;
73
+	Instruction->Disassembler = Disassembler;
74
+	memset(Instruction->String, ' ', MAX_OPCODE_DESCRIPTION-1);
75
+	Instruction->String[MAX_OPCODE_DESCRIPTION-1] = '\0';
76
+	return TRUE;
77
+}
78
+
79
+// If Decode = FALSE, only the following fields are valid:
80
+// Instruction->Length, Instruction->Address, Instruction->Prefixes, Instruction->PrefixCount,
81
+// Instruction->OpcodeBytes, Instruction->Instruction->OpcodeLength, Instruction->Groups,
82
+// Instruction->Type, Instruction->OperandCount
83
+//
84
+// If Disassemble = TRUE, then Instruction->String is valid (also requires Decode = TRUE)
85
+//
86
+// WARNING: This will overwrite the previously obtained instruction
87
+INSTRUCTION *GetInstruction(DISASSEMBLER *Disassembler, U64 VirtualAddress, U8 *Address, U32 Flags)
88
+{
89
+	if (Disassembler->Initialized != DISASSEMBLER_INITIALIZED) { assert(0); return NULL; }
90
+	assert(Address);
91
+	InitInstruction(&Disassembler->Instruction, Disassembler);
92
+	Disassembler->Instruction.Address = Address;	
93
+	Disassembler->Instruction.VirtualAddressDelta = VirtualAddress - (U64)Address;
94
+	if (!Disassembler->Functions->GetInstruction(&Disassembler->Instruction, Address, Flags))
95
+	{
96
+		assert(Disassembler->Instruction.Address == Address);
97
+		assert(Disassembler->Instruction.Length < MAX_INSTRUCTION_LENGTH);
98
+
99
+		// Save the address that failed, in case the lower-level disassembler didn't
100
+		Disassembler->Instruction.Address = Address;
101
+		Disassembler->Instruction.ErrorOccurred = TRUE;
102
+		return NULL;
103
+	}
104
+	return &Disassembler->Instruction;
105
+}
106
+
107
+///////////////////////////////////////////////////////////////////////////
108
+// Miscellaneous
109
+///////////////////////////////////////////////////////////////////////////
110
+
111
+static ARCHITECTURE_FORMAT *GetArchitectureFormat(ARCHITECTURE_TYPE Type)
112
+{
113
+	ARCHITECTURE_FORMAT *Format;
114
+	for (Format = SupportedArchitectures; Format->Type != ARCH_UNKNOWN; Format++)
115
+	{
116
+		if (Format->Type == Type) return Format;
117
+	}
118
+
119
+	assert(0);
120
+	return NULL;
121
+}
122
+

+ 578
- 0
src/thirdparty/mhook/disasm-lib/disasm.h View File

@@ -0,0 +1,578 @@
1
+// Copyright (C) 2004, Matt Conover (mconover@gmail.com)
2
+//
3
+// WARNING:
4
+// I wouldn't recommend changing any flags like OP_*, ITYPE_*, or *_MASK
5
+// aside from those marked as UNUSED. This is because the flags parts of
6
+// the flags are architecture independent and other are left to specific
7
+// architectures to define, so unless you understand the relationships
8
+// between them, I would leave them as is.
9
+
10
+#ifndef DISASM_H
11
+#define DISASM_H
12
+#ifdef __cplusplus
13
+extern "C" {
14
+#endif
15
+#include <windows.h>
16
+#include <stdio.h>
17
+#include "misc.h"
18
+
19
+typedef signed char S8;
20
+typedef unsigned char U8;
21
+typedef signed short S16;
22
+typedef unsigned short U16;
23
+typedef signed long S32;
24
+typedef unsigned long U32;
25
+typedef LONG64 S64;
26
+typedef ULONG64 U64;
27
+
28
+#ifdef SPEEDY
29
+// On Visual Studio 6, making the internal functions inline makes compiling take forever
30
+#define INTERNAL static _inline 
31
+#define INLINE _inline
32
+#else
33
+#define INTERNAL static
34
+#define INLINE
35
+#endif
36
+
37
+#define VALID_INSTRUCTION(i) ((i) && !((i)->ErrorOccurred))
38
+#define NEXT_INSTRUCTION(i) ((i)->Address + (i)->Length)
39
+#define DISASM_ARCH_TYPE(dis) ((dis)->ArchType)
40
+#define INS_ARCH_TYPE(ins) DISASM_ARCH_TYPE((ins)->Disassembler)
41
+
42
+// NOTE: these should be as big set to the maximum of the supported architectures
43
+#define MAX_PREFIX_LENGTH 15
44
+#define MAX_OPERAND_COUNT 3
45
+#define MAX_INSTRUCTION_LENGTH 25
46
+#define MAX_OPCODE_LENGTH 3
47
+#define MAX_OPCODE_DESCRIPTION 256
48
+
49
+/////////////////////////////////////////////////////////////////////
50
+// Code branch
51
+/////////////////////////////////////////////////////////////////////
52
+
53
+#define MAX_CODE_REFERENCE_COUNT 3
54
+
55
+typedef struct _CODE_BRANCH
56
+{
57
+	U64 Addresses[MAX_CODE_REFERENCE_COUNT]; // NULL if multiple to addresses
58
+	U32 Count;
59
+	U8 IsLoop : 1;
60
+	U8 IsCall : 1; // branch if false
61
+	U8 IsIndirect : 1; // call/jmp [Address]
62
+	U8 AddressOffset: 5;
63
+	struct _INSTRUCTION_OPERAND *Operand; // the operand containg the address
64
+} CODE_BRANCH;
65
+
66
+/////////////////////////////////////////////////////////////////////
67
+// Data references
68
+/////////////////////////////////////////////////////////////////////
69
+
70
+#define MAX_DATA_REFERENCE_COUNT 3
71
+
72
+typedef struct _DATA_REFERENCE
73
+{
74
+	U64 Addresses[MAX_DATA_REFERENCE_COUNT]; // NULL if multiple to addresses
75
+	U32 Count;
76
+	ULONG_PTR DataSize;
77
+	struct _INSTRUCTION_OPERAND *Operand; // the operand containg the address
78
+} DATA_REFERENCE;
79
+
80
+////////////////////////////////////////////////////////////////////
81
+// Instruction
82
+/////////////////////////////////////////////////////////////////////
83
+
84
+//
85
+// Instruction types (bits 0-7)
86
+// Instruction groups (bits 8-26)
87
+//
88
+#define ITYPE_EXEC_OFFSET     (1<<8)
89
+#define ITYPE_ARITH_OFFSET    (1<<9)
90
+#define ITYPE_LOGIC_OFFSET    (1<<10)
91
+#define ITYPE_STACK_OFFSET    (1<<11)
92
+#define ITYPE_TESTCOND_OFFSET (1<<12)
93
+#define ITYPE_LOAD_OFFSET     (1<<13)
94
+#define ITYPE_ARRAY_OFFSET    (1<<14)
95
+#define ITYPE_BIT_OFFSET      (1<<15)
96
+#define ITYPE_FLAG_OFFSET     (1<<16)
97
+#define ITYPE_FPU_OFFSET      (1<<17)
98
+#define ITYPE_TRAPS_OFFSET    (1<<18)
99
+#define ITYPE_SYSTEM_OFFSET   (1<<19)
100
+#define ITYPE_OTHER_OFFSET    (1<<20)
101
+#define ITYPE_UNUSED1_OFFSET  (1<<21)
102
+#define ITYPE_UNUSED2_OFFSET  (1<<22)
103
+#define ITYPE_UNUSED3_OFFSET  (1<<23)
104
+#define ITYPE_UNUSED4_OFFSET  (1<<24)
105
+#define ITYPE_UNUSED5_OFFSET  (1<<25)
106
+#define ITYPE_UNUSED6_OFFSET  (1<<26)
107
+#define ITYPE_EXT_UNUSED1     (1<<27)
108
+#define ITYPE_EXT_UNUSED2     (1<<28)
109
+#define ITYPE_EXT_UNUSED3     (1<<29)
110
+#define ITYPE_EXT_UNUSED4     (1<<30)
111
+#define ITYPE_EXT_UNUSED5     (1<<31)
112
+
113
+//
114
+// X86-specific flags (bits 27-31)
115
+//
116
+
117
+#define ITYPE_EXT_64     ITYPE_EXT_UNUSED1 // Use index 1 if in 64-bit mode and 0 otherwise
118
+#define ITYPE_EXT_MODRM  ITYPE_EXT_UNUSED2 // ModRM byte may extend the opcode
119
+#define ITYPE_EXT_SUFFIX ITYPE_EXT_UNUSED3 // byte after ModRM/SIB/displacement is the third opcode
120
+#define ITYPE_EXT_PREFIX ITYPE_EXT_UNUSED4 // prefix
121
+#define ITYPE_EXT_FPU    ITYPE_EXT_UNUSED5 // FPU instructions require special handling
122
+
123
+#define ITYPE_3DNOW_OFFSET ITYPE_UNUSED1_OFFSET
124
+#define ITYPE_MMX_OFFSET   ITYPE_UNUSED2_OFFSET
125
+#define ITYPE_SSE_OFFSET   ITYPE_UNUSED3_OFFSET
126
+#define ITYPE_SSE2_OFFSET  ITYPE_UNUSED4_OFFSET
127
+#define ITYPE_SSE3_OFFSET  ITYPE_UNUSED5_OFFSET
128
+
129
+//
130
+// Instruction types
131
+//
132
+
133
+#define ITYPE_TYPE_MASK  0x7FFFFFFF
134
+#define ITYPE_GROUP_MASK 0x7FFFFF00
135
+
136
+typedef enum _INSTRUCTION_TYPE
137
+{
138
+	// ITYPE_EXEC group
139
+	ITYPE_EXEC = ITYPE_EXEC_OFFSET,
140
+	ITYPE_BRANCH,
141
+	ITYPE_BRANCHCC, // conditional (not necessarily just flags)
142
+	ITYPE_CALL,
143
+	ITYPE_CALLCC, // conditional (not necessarily just flags)
144
+	ITYPE_RET,
145
+	ITYPE_LOOPCC,
146
+
147
+	// ITYPE_ARITH group
148
+	ITYPE_ARITH = ITYPE_ARITH_OFFSET,
149
+	ITYPE_XCHGADD,
150
+	ITYPE_ADD,
151
+	ITYPE_SUB,
152
+	ITYPE_MUL,
153
+	ITYPE_DIV,
154
+	ITYPE_INC,
155
+	ITYPE_DEC,
156
+	ITYPE_SHL,
157
+	ITYPE_SHR,
158
+	ITYPE_ROL,
159
+	ITYPE_ROR,
160
+
161
+	// ITYPE_LOGIC group
162
+	ITYPE_LOGIC=ITYPE_LOGIC_OFFSET,
163
+	ITYPE_AND,
164
+	ITYPE_OR,
165
+	ITYPE_XOR,
166
+	ITYPE_NOT,
167
+	ITYPE_NEG,
168
+
169
+	// ITYPE_STACK group
170
+	ITYPE_STACK=ITYPE_STACK_OFFSET,
171
+	ITYPE_PUSH,
172
+	ITYPE_POP,
173
+	ITYPE_PUSHA,
174
+	ITYPE_POPA,
175
+	ITYPE_PUSHF,
176
+	ITYPE_POPF,
177
+	ITYPE_ENTER,
178
+	ITYPE_LEAVE,
179
+
180
+	// ITYPE_TESTCOND group
181
+	ITYPE_TESTCOND=ITYPE_TESTCOND_OFFSET,
182
+		ITYPE_TEST,
183
+		ITYPE_CMP,
184
+
185
+	// ITYPE_LOAD group
186
+	ITYPE_LOAD=ITYPE_LOAD_OFFSET,
187
+		ITYPE_MOV,
188
+		ITYPE_MOVCC, // conditional
189
+		ITYPE_LEA,
190
+		ITYPE_XCHG,
191
+		ITYPE_XCHGCC, // conditional
192
+
193
+	// ITYPE_ARRAY group
194
+	ITYPE_ARRAY=ITYPE_ARRAY_OFFSET,
195
+		ITYPE_STRCMP,
196
+		ITYPE_STRLOAD,
197
+		ITYPE_STRMOV,
198
+		ITYPE_STRSTOR,
199
+		ITYPE_XLAT,
200
+
201
+	// ITYPE_BIT group
202
+	ITYPE_BIT=ITYPE_BIT_OFFSET,
203
+		ITYPE_BITTEST,
204
+		ITYPE_BITSET,
205
+		ITYPE_BITCLR,
206
+
207
+	// ITYPE_FLAG group
208
+	// PF = parify flag
209
+	// ZF = zero flag
210
+	// OF = overflow flag
211
+	// DF = direction flag
212
+	// SF = sign flag
213
+	ITYPE_FLAG=ITYPE_FLAG_OFFSET,
214
+		// clear
215
+		ITYPE_CLEARCF, 
216
+		ITYPE_CLEARZF,
217
+		ITYPE_CLEAROF,
218
+		ITYPE_CLEARDF,
219
+		ITYPE_CLEARSF,
220
+		ITYPE_CLEARPF,
221
+		// set
222
+		ITYPE_SETCF, 
223
+		ITYPE_SETZF,
224
+		ITYPE_SETOF,
225
+		ITYPE_SETDF,
226
+		ITYPE_SETSF,
227
+		ITYPE_SETPF,
228
+		// toggle
229
+		ITYPE_TOGCF, 
230
+		ITYPE_TOGZF,
231
+		ITYPE_TOGOF,
232
+		ITYPE_TOGDF,
233
+		ITYPE_TOGSF,
234
+		ITYPE_TOGPF,
235
+
236
+	// ITYPE_FPU group
237
+	ITYPE_FPU=ITYPE_FPU_OFFSET,
238
+		ITYPE_FADD,
239
+		ITYPE_FSUB,
240
+		ITYPE_FMUL,
241
+		ITYPE_FDIV,
242
+		ITYPE_FCOMP,
243
+		ITYPE_FEXCH,
244
+		ITYPE_FLOAD,
245
+		ITYPE_FLOADENV,
246
+		ITYPE_FSTORE,
247
+		ITYPE_FSTOREENV,
248
+		ITYPE_FSAVE,
249
+		ITYPE_FRESTORE,
250
+		ITYPE_FMOVCC,
251
+
252
+	ITYPE_UNUSED1=ITYPE_UNUSED1_OFFSET,
253
+	ITYPE_UNUSED2=ITYPE_UNUSED2_OFFSET,
254
+	ITYPE_UNUSED3=ITYPE_UNUSED3_OFFSET,
255
+
256
+	// ITYPE_MMX group
257
+	ITYPE_MMX=ITYPE_MMX_OFFSET,
258
+		ITYPE_MMX_MOV,
259
+		ITYPE_MMX_ADD,
260
+		ITYPE_MMX_SUB,
261
+		ITYPE_MMX_MUL,
262
+		ITYPE_MMX_DIV,
263
+		ITYPE_MMX_AND,
264
+		ITYPE_MMX_OR,
265
+		ITYPE_MMX_XOR,
266
+		ITYPE_MMX_CMP,
267
+
268
+	// ITYPE_SSE group
269
+	ITYPE_SSE=ITYPE_SSE_OFFSET,
270
+		ITYPE_SSE_MOV,
271
+		ITYPE_SSE_ADD,
272
+		ITYPE_SSE_SUB,
273
+		ITYPE_SSE_MUL,
274
+		ITYPE_SSE_DIV,
275
+		ITYPE_SSE_AND,
276
+		ITYPE_SSE_OR,
277
+		ITYPE_SSE_XOR,
278
+		ITYPE_SSE_CMP,
279
+		
280
+		// ITYPE_SSE2 group
281
+	ITYPE_SSE2=ITYPE_SSE2_OFFSET,
282
+		ITYPE_SSE2_MOV,
283
+		ITYPE_SSE2_ADD,
284
+		ITYPE_SSE2_SUB,
285
+		ITYPE_SSE2_MUL,
286
+		ITYPE_SSE2_DIV,
287
+		ITYPE_SSE2_AND,
288
+		ITYPE_SSE2_OR,
289
+		ITYPE_SSE2_XOR,
290
+		ITYPE_SSE2_CMP,
291
+
292
+	// ITYPE_SSE3 group
293
+	ITYPE_SSE3=ITYPE_SSE3_OFFSET,
294
+		ITYPE_SSE3_MOV,
295
+		ITYPE_SSE3_ADD,
296
+		ITYPE_SSE3_SUB,
297
+		ITYPE_SSE3_MUL,
298
+		ITYPE_SSE3_DIV,
299
+		ITYPE_SSE3_AND,
300
+		ITYPE_SSE3_OR,
301
+		ITYPE_SSE3_XOR,
302
+		ITYPE_SSE3_CMP,
303
+
304
+	// ITYPE_3DNOW group
305
+	ITYPE_3DNOW=ITYPE_3DNOW_OFFSET,
306
+		ITYPE_3DNOW_ADD,
307
+		ITYPE_3DNOW_SUB,
308
+		ITYPE_3DNOW_MUL,
309
+		ITYPE_3DNOW_DIV,
310
+		ITYPE_3DNOW_CMP,
311
+		ITYPE_3DNOW_XCHG,
312
+
313
+	// ITYPE_TRAP
314
+	ITYPE_TRAPS=ITYPE_TRAPS_OFFSET, 
315
+		ITYPE_TRAP, // generate trap
316
+		ITYPE_TRAPCC,  // conditional trap gen
317
+		ITYPE_TRAPRET,    // return from trap
318
+		ITYPE_BOUNDS,  // gen bounds trap
319
+		ITYPE_DEBUG,   // gen breakpoint trap
320
+		ITYPE_TRACE,   // gen single step trap
321
+		ITYPE_INVALID, // gen invalid instruction
322
+		ITYPE_OFLOW,   // gen overflow trap
323
+
324
+	// ITYPE_SYSTEM group
325
+	ITYPE_SYSTEM=ITYPE_SYSTEM_OFFSET,
326
+		ITYPE_HALT,    // halt machine
327
+		ITYPE_IN,      // input form port
328
+		ITYPE_OUT,     // output to port
329
+		ITYPE_CPUID,   // identify cpu
330
+		ITYPE_SETIF,   // allow interrupts
331
+		ITYPE_CLEARIF, // block interrupts
332
+		ITYPE_SYSCALL,
333
+		ITYPE_SYSCALLRET,
334
+
335
+	// ITYPE_OTHER group
336
+	ITYPE_OTHER = ITYPE_OTHER_OFFSET,
337
+		ITYPE_NOP,
338
+		ITYPE_BCDCONV, // convert to/from BCD
339
+		ITYPE_SZCONV   // convert size of operand
340
+} INSTRUCTION_TYPE;
341
+
342
+//
343
+// Operand flags
344
+//
345
+
346
+// Type = bits 0-6 (these are mutually exclusive -- bits 0-6 will always be a power of 2))
347
+#define OPTYPE_NONE    0x00
348
+#define OPTYPE_IMM    0x01 // immediate value
349
+#define OPTYPE_OFFSET 0x02 // relative offset
350
+#define OPTYPE_FLOAT  0x03 // floating point
351
+#define OPTYPE_BCD    0x04
352
+#define OPTYPE_STRING 0x05
353
+#define OPTYPE_SPECIAL 0x06
354
+#define OPTYPE_MASK   0x7F
355
+
356
+// Flags = bits 7-23 (these can be combinations)
357
+// These are used in the X86 opcode table
358
+#define OP_REG      (1<<7) // 0x80
359
+#define OP_SIGNED   (1<<8)
360
+#define OP_SYS      (1<<9) // parameter is an index into some system structure
361
+#define OP_CONDR    (1<<10)
362
+#define OP_CONDW    (1<<11)
363
+#define OP_UNUSED   (1<<12)
364
+#define OP_SRC      (1<<13) // operand is source operand
365
+#define OP_DST      (1<<14) // operand is destination operand
366
+#define OP_EXEC     (1<<15) // operand is executed
367
+
368
+#define OP_CONDE     OP_CONDR
369
+#define OP_COND_EXEC (OP_CONDE|OP_EXEC) // executed only if the pre-conditions are met
370
+#define OP_COND_SRC  (OP_CONDR|OP_SRC) // set only if pre-conditions are met
371
+#define OP_COND_DST  (OP_CONDW|OP_DST) // set only if pre-conditions are met
372
+#define OP_COND      (OP_CONDR|OP_CONDW)
373
+
374
+// Bits 16-31 are available for use outside of the opcode table, but they can only
375
+// be used in INSTRUCTION_OPERAND.Flags, they may conflit with the architecture specific
376
+// operands. For example, bits 16-31 are used in X86 for AMODE_* and OPTYPE_*
377
+#define OP_ADDRESS    (1<<16)
378
+#define OP_LOCAL      (1<<17)
379
+#define OP_PARAM      (1<<18)
380
+#define OP_GLOBAL     (1<<19)
381
+#define OP_FAR        (1<<20)
382
+#define OP_IPREL      (1<<21)
383
+
384
+//
385
+// X86-specific flags (bits 27-31)
386
+//
387
+#define OP_MSR      (OP_SYS|OP_UNUSED)
388
+
389
+//
390
+// Other architecture flags
391
+//
392
+#define OP_DELAY  OP_UNUSED // delayed instruction (e.g., delayed branch that executes after the next instruction)
393
+
394
+/////////////////////////////////////////////////////////////////////
395
+// Architectures
396
+/////////////////////////////////////////////////////////////////////
397
+
398
+typedef enum _ARCHITECTURE_TYPE
399
+{
400
+	ARCH_UNKNOWN=0,
401
+	
402
+	// x86-based
403
+	ARCH_X86,    // 32-bit x86
404
+	ARCH_X86_16, // 16-bit x86
405
+	ARCH_X64,    // AMD64 and Intel EMD64
406
+	
407
+	// everything else
408
+	ARCH_ALPHA,
409
+	ARCH_ARM,
410
+	ARCH_DOTNET,
411
+	ARCH_EFI,
412
+	ARCH_IA64,
413
+	ARCH_M68K,
414
+	ARCH_MIPS,
415
+	ARCH_PPC,
416
+	ARCH_SH3,
417
+	ARCH_SH4,
418
+	ARCH_SPARC,
419
+	ARCH_THUMB
420
+
421
+} ARCHITECTURE_TYPE;
422
+
423
+typedef BOOL (*INIT_INSTRUCTION)(struct _INSTRUCTION *Instruction);
424
+typedef void (*DUMP_INSTRUCTION)(struct _INSTRUCTION *Instruction, BOOL ShowBytes, BOOL Verbose);
425
+typedef BOOL (*GET_INSTRUCTION)(struct _INSTRUCTION *Instruction, U8 *Address, U32 Flags);
426
+typedef U8 *(*FIND_FUNCTION_BY_PROLOGUE)(struct _INSTRUCTION *Instruction, U8 *StartAddress, U8 *EndAddress, U32 Flags);
427
+
428
+typedef struct _ARCHITECTURE_FORMAT_FUNCTIONS
429
+{
430
+	INIT_INSTRUCTION InitInstruction;
431
+	DUMP_INSTRUCTION DumpInstruction;
432
+	GET_INSTRUCTION GetInstruction;
433
+	FIND_FUNCTION_BY_PROLOGUE FindFunctionByPrologue;
434
+} ARCHITECTURE_FORMAT_FUNCTIONS;
435
+
436
+typedef struct _ARCHITECTURE_FORMAT
437
+{
438
+	ARCHITECTURE_TYPE Type;
439
+	ARCHITECTURE_FORMAT_FUNCTIONS *Functions;
440
+} ARCHITECTURE_FORMAT;
441
+
442
+#define DISASSEMBLER_INITIALIZED 0x1234566F
443
+#define INSTRUCTION_INITIALIZED 0x1234567F
444
+
445
+#include "disasm_x86.h"
446
+
447
+typedef struct DECLSPEC_ALIGN(16) _S128
448
+{
449
+    U64 Low;
450
+    S64 High;
451
+} S128;
452
+typedef struct DECLSPEC_ALIGN(16) _U128
453
+{
454
+    U64 Low;
455
+    U64 High;
456
+} U128;
457
+
458
+typedef struct _INSTRUCTION_OPERAND
459
+{
460
+	U32 Flags;
461
+	U8 Type : 6;
462
+	U8 Unused : 2;
463
+	U16 Length;
464
+	
465
+
466
+	// If non-NULL, this indicates the target address of the instruction (e.g., a branch or
467
+	// a displacement with no base register). However, this address is only reliable if the
468
+	// image is mapped correctly (e.g., the executable is mapped as an image and fixups have
469
+	// been applied if it is not at its preferred image base).
470
+	//
471
+	// If disassembling a 16-bit DOS application, TargetAddress is in the context of 
472
+	// X86Instruction->Segment. For example, if TargetAddress is the address of a code branch, 
473
+	// it is in the CS segment (unless X86Instruction->HasSegmentOverridePrefix is set). If 
474
+	// TargetAddress is a data pointer, it is in the DS segment (unless 
475
+	// X86Instruction->HasSegmentOverridePrefix is set)
476
+	U64 TargetAddress;
477
+	U32 Register;
478
+
479
+	union
480
+	{
481
+		// All 8/16/32-bit operands are extended to 64-bits automatically
482
+		// If you want to downcast, check whether Flags & OP_SIGNED is set
483
+		// Like this:
484
+		// U32 GetOperand32(OPERAND *Operand)
485
+		// {
486
+		//	if (Operand->Flags & OP_SIGNED) return (S32)Operand->Value_S64;
487
+		//	else return (U32)Operand->Value_U64;
488
+		//}
489
+		U64 Value_U64;
490
+		S64 Value_S64;
491
+		U128 Value_U128;
492
+		U128 Float128;
493
+		U8 Float80[80];
494
+		U8 BCD[10];
495
+	};
496
+} INSTRUCTION_OPERAND;
497
+
498
+typedef struct _INSTRUCTION
499
+{
500
+	U32 Initialized;
501
+	struct _DISASSEMBLER *Disassembler;
502
+
503
+	char String[MAX_OPCODE_DESCRIPTION];
504
+	U8 StringIndex;
505
+	U64 VirtualAddressDelta;
506
+
507
+	U32 Groups; // ITYPE_EXEC, ITYPE_ARITH, etc. -- NOTE groups can be OR'd together
508
+	INSTRUCTION_TYPE Type; // ITYPE_ADD, ITYPE_RET, etc. -- NOTE there is only one possible type
509
+
510
+	U8 *Address;
511
+	U8 *OpcodeAddress;
512
+	U32 Length;
513
+
514
+	U8 Prefixes[MAX_PREFIX_LENGTH];
515
+	U32 PrefixCount;
516
+
517
+	U8 LastOpcode; // last byte of opcode
518
+	U8 OpcodeBytes[MAX_OPCODE_LENGTH];
519
+	U32 OpcodeLength; // excludes any operands and prefixes
520
+
521
+	INSTRUCTION_OPERAND Operands[MAX_OPERAND_COUNT];
522
+	U32 OperandCount;
523
+
524
+	X86_INSTRUCTION X86;
525
+
526
+	DATA_REFERENCE DataSrc;
527
+	DATA_REFERENCE DataDst;
528
+	CODE_BRANCH CodeBranch;
529
+
530
+	// Direction depends on which direction the stack grows
531
+	// For example, on x86 a push results in StackChange < 0 since the stack grows down
532
+	// This is only relevant if (Group & ITYPE_STACK) is true
533
+	//
534
+	// If Groups & ITYPE_STACK is set but StackChange = 0, it means that the change
535
+	// couldn't be determined (non-constant)
536
+	LONG StackChange;
537
+
538
+	// Used to assist in debugging
539
+	// If set, the current instruction is doing something that requires special handling
540
+	// For example, popf can cause tracing to be disabled
541
+
542
+	U8 StringAligned : 1; // internal only
543
+	U8 NeedsEmulation : 1; // instruction does something that re
544
+	U8 Repeat : 1; // instruction repeats until some condition is met (e.g., REP prefix on X86)
545
+	U8 ErrorOccurred : 1; // set if instruction is invalid
546
+	U8 AnomalyOccurred : 1; // set if instruction is anomalous
547
+	U8 LastInstruction : 1; // tells the iterator callback it is the last instruction
548
+	U8 CodeBlockFirst: 1;
549
+	U8 CodeBlockLast : 1;
550
+} INSTRUCTION;
551
+
552
+typedef struct _DISASSEMBLER
553
+{
554
+	U32 Initialized;
555
+	ARCHITECTURE_TYPE ArchType;
556
+	ARCHITECTURE_FORMAT_FUNCTIONS *Functions;
557
+	INSTRUCTION Instruction;
558
+	U32 Stage1Count; // GetInstruction called
559
+	U32 Stage2Count; // Opcode fully decoded
560
+	U32 Stage3CountNoDecode;   // made it through all checks when DISASM_DECODE is not set
561
+	U32 Stage3CountWithDecode; // made it through all checks when DISASM_DECODE is set
562
+} DISASSEMBLER;
563
+
564
+#define DISASM_DISASSEMBLE         (1<<1)
565
+#define DISASM_DECODE              (1<<2)
566
+#define DISASM_SUPPRESSERRORS      (1<<3)
567
+#define DISASM_SHOWFLAGS           (1<<4)
568
+#define DISASM_ALIGNOUTPUT         (1<<5)
569
+#define DISASM_DISASSEMBLE_MASK (DISASM_ALIGNOUTPUT|DISASM_SHOWBYTES|DISASM_DISASSEMBLE)
570
+
571
+BOOL InitDisassembler(DISASSEMBLER *Disassembler, ARCHITECTURE_TYPE Architecture);
572
+void CloseDisassembler(DISASSEMBLER *Disassembler);
573
+INSTRUCTION *GetInstruction(DISASSEMBLER *Disassembler, U64 VirtualAddress, U8 *Address, U32 Flags);
574
+
575
+#ifdef __cplusplus
576
+}
577
+#endif
578
+#endif // DISASM_H

+ 4662
- 0
src/thirdparty/mhook/disasm-lib/disasm_x86.c
File diff suppressed because it is too large
View File


+ 837
- 0
src/thirdparty/mhook/disasm-lib/disasm_x86.h View File

@@ -0,0 +1,837 @@
1
+// Copyright (C) 2004, Matt Conover (mconover@gmail.com)
2
+#ifndef X86_DISASM_H
3
+#define X86_DISASM_H
4
+#ifdef __cplusplus
5
+extern "C" {
6
+#endif
7
+
8
+// NOTE: the processor may actually accept less than this amount (officially 15)
9
+// #define AMD64_MAX_INSTRUCTION_LEN 15 // theoretical max 25=5+2+1+1+8+8
10
+#define AMD64_MAX_PREFIX_LENGTH 5 // 4 legacy + 1 rex
11
+#define AMD64_MAX_ADDRESS_LENGTH 18 // modrm + sib + 8 byte displacement + 8 byte immediate value
12
+
13
+// NOTE: the processor may actually accept less than this amount (officially 15)
14
+#define X86_MAX_INSTRUCTION_LEN 15 // theoretical 16=4+2+1+1+4+4
15
+#define X86_MAX_PREFIX_LENGTH 4
16
+#define X86_MAX_OPCODE_LENGTH 3 // third byte is either a suffix or prefix
17
+#define X86_MAX_ADDRESS_LENGTH 10 // modrm + sib + 4 byte displacement + 4 byte immediate value
18
+#define X86_MAX_OPERANDS 3
19
+
20
+#define X86_PREFIX(a) ((a)->MnemonicFlags == ITYPE_EXT_PREFIX)
21
+#define X86_SPECIAL_EXTENSION(a) ((a)->MnemonicFlags & (ITYPE_EXT_MODRM|ITYPE_EXT_FPU|ITYPE_EXT_SUFFIX|ITYPE_EXT_64))
22
+#define X86_EXTENDED_OPCODE(a) ((a)->Table)
23
+#define X86_INVALID(a) (!(a)->MnemonicFlags && !(a)->Table)
24
+#define X86_OPERAND_COUNT(a) ((a)->OperandFlags[0] ? ((a)->OperandFlags[1] ? ((a)->OperandFlags[2] ? 3 : 2) : 1) : 0)
25
+#define X86_GET_CATEGORY(p) ((p)->MnemonicFlags & ITYPE_GROUP_MASK)
26
+#define X86_GET_TYPE(p) ((p)->MnemonicFlags & ITYPE_TYPE_MASK)
27
+
28
+// Various instructions being specially decoded
29
+#define X86_TWO_BYTE_OPCODE 0x0f
30
+#define PREFIX_SEGMENT_OVERRIDE_ES 0x26
31
+#define PREFIX_SEGMENT_OVERRIDE_CS 0x2e
32
+#define PREFIX_BRANCH_NOT_TAKEN 0x2e // used only with conditional jumps
33
+#define PREFIX_SEGMENT_OVERRIDE_SS 0x36
34
+#define PREFIX_SEGMENT_OVERRIDE_DS 0x3e
35
+#define PREFIX_BRANCH_TAKEN 0x3e // used only with conditional jumps
36
+#define PREFIX_SEGMENT_OVERRIDE_FS 0x64
37
+#define PREFIX_SEGMENT_OVERRIDE_GS 0x65
38
+#define PREFIX_OPERAND_SIZE 0x66
39
+#define PREFIX_ADDRESS_SIZE 0x67
40
+#define PREFIX_LOCK 0xf0
41
+#define PREFIX_REPNE 0xf2
42
+#define PREFIX_REP 0xf3
43
+
44
+//////////////////////////////////////////////////////////////////
45
+// Implicit operand handling
46
+//////////////////////////////////////////////////////////////////
47
+
48
+#define X86_AMODE_MASK   0x00FF0000 // bits 16-23 (AMODE_*)
49
+#define X86_OPFLAGS_MASK 0x0000FF80 // bits 7-15 (OPTYPE_*)
50
+#define X86_OPTYPE_MASK  0xFF0000FF // bits 0-7 (OPTYPE_* below + OP_REG) and 24-31 (OPTYPE_* above)
51
+
52
+#define OPTYPE_0   0x01
53
+#define OPTYPE_1   0x02
54
+#define OPTYPE_FF  0x03
55
+//...
56
+#define OPTYPE_CS  0x10
57
+#define OPTYPE_DS  0x11
58
+#define OPTYPE_ES  0x12
59
+#define OPTYPE_FS  0x13
60
+#define OPTYPE_GS  0x14
61
+#define OPTYPE_SS  0x15
62
+#define OPTYPE_CR0 0x16
63
+#define OPTYPE_TSC 0x17 // time stamp counter
64
+//...
65
+#define OPTYPE_FLAGS  0x20
66
+#define OPTYPE_xFLAGS 0x21 // RFLAGS/EFLAGS (depending on operand size)
67
+#define OPTYPE_xCX_HI_xBX_LO 0x22 // represented by 2 registers CX:BX or ECX:EBX (depending on operand size)
68
+#define OPTYPE_xDX_HI_xAX_LO 0x23 // DX:AX or EDX:EAX (depending on operand size)
69
+#define OPTYPE_EDX_HI_EAX_LO 0x24 // DX:AX or EDX:EAX (depending on operand size)
70
+#define OPTYPE_EDX_ECX_EBX_EAX 0x25 // all registers are set
71
+//...
72
+#define OPTYPE_STx 0x30
73
+#define OPTYPE_ST0 0x31
74
+#define OPTYPE_ST1 0x32
75
+#define OPTYPE_FPU_STATUS  0x33
76
+#define OPTYPE_FPU_CONTROL 0x34
77
+#define OPTYPE_FPU_TAG 0x35
78
+#define OPTYPE_FLDZ   0x36 // 0
79
+#define OPTYPE_FLD1   0x37 // 1
80
+#define OPTYPE_FLDPI  0x38 // pi
81
+#define OPTYPE_FLDL2T 0x39 // lg 10
82
+#define OPTYPE_FLDL2E 0x3A // lg e
83
+#define OPTYPE_FLDLG2 0x3B // log_10 2
84
+#define OPTYPE_FLDLN2 0x3C // log_e 2
85
+//...
86
+#define OPTYPE_CS_MSR 0x40
87
+#define OPTYPE_EIP_MSR 0x41
88
+#define OPTYPE_ESP_MSR 0x42
89
+#define OPTYPE_KERNELBASE_MSR 0x43
90
+#define OPTYPE_FMASK_MSR 0x44
91
+#define OPTYPE_STAR_MSR 0x45
92
+#define OPTYPE_CSTAR_MSR 0x46 // 32-bit mode
93
+#define OPTYPE_LSTAR_MSR 0x47 // 64-bit mode
94
+
95
+
96
+// NOTE: OPTYPES >= 0x80 reserved for registers (OP_REG+XX)
97
+#define OPTYPE_REG_AL OP_REG+0x01
98
+#define OPTYPE_REG_CL OP_REG+0x02
99
+#define OPTYPE_REG_AH OP_REG+0x03
100
+#define OPTYPE_REG_AX OP_REG+0x04
101
+#define OPTYPE_REG_DX OP_REG+0x05
102
+#define OPTYPE_REG_ECX OP_REG+0x06
103
+#define OPTYPE_REG8 OP_REG+0x07
104
+
105
+// If address size is 2, use BP
106
+// If address size is 4, use EBP
107
+// If address size is 8, use RBP
108
+#define OPTYPE_REG_xBP OP_REG+0x08
109
+
110
+// If address size is 2, use BP
111
+// If address size is 4, use EBP
112
+// If address size is 8, use RBP
113
+#define OPTYPE_REG_xSP OP_REG+0x09
114
+
115
+// If operand size is 2, take 8-bit register
116
+// If operand size is 4, take 16-bit register
117
+// If operand size is 8, take 32-bit register
118
+#define OPTYPE_REG_xAX_SMALL OP_REG+0x0a
119
+
120
+// If operand size is 2, take 16-bit register
121
+// If operand size is 4, take 32-bit register
122
+// If operand size is 8, take 64-bit register
123
+#define OPTYPE_REG_xAX_BIG OP_REG+0x0b
124
+
125
+typedef enum _CPU_TYPE
126
+{
127
+	CPU_UNKNOWN=0,
128
+
129
+	///////////////////////////////////////
130
+	// 1st generation
131
+	///////////////////////////////////////
132
+	// 1978
133
+	//CPU_8086 = 1MB address limit, 16-bit registers
134
+	// 1982
135
+	//CPU_i186
136
+
137
+	///////////////////////////////////////
138
+	// 2nd generation
139
+	///////////////////////////////////////
140
+	// 1982
141
+	//CPU_I286 // 16MB limit, 16-bit registers, added protected mode
142
+	CPU_I287, // CPU_I286 + math coprocessor
143
+
144
+	///////////////////////////////////////
145
+	// 3rd generation
146
+	///////////////////////////////////////
147
+	// 1985
148
+	CPU_I386, // 32-bit registers, 4GB memory limit
149
+	// 1988
150
+	CPU_I387, // CPU_I386 + math coprocessor
151
+
152
+	///////////////////////////////////////
153
+	// 4th generation (1989)
154
+	///////////////////////////////////////
155
+	CPU_I486,
156
+
157
+	///////////////////////////////////////
158
+	// 5th generation
159
+	///////////////////////////////////////
160
+	// 1993
161
+	CPU_PENTIUM, // superscalar architecture
162
+	// 1997
163
+	//CPU_PENTIUM_MMX
164
+	
165
+	///////////////////////////////////////
166
+	// 6th generation (1995)
167
+	///////////////////////////////////////
168
+	CPU_PENTIUM_PRO, // P6 architecture, no MMX, out-of-order execution, speculative execution
169
+	//CPU_CYRIX_6X86,
170
+	//CPU_AMD_K5 // RISC processor
171
+	// 1997
172
+	CPU_PENTIUM2, // Pentium Pro architecture + MMX
173
+	//CPU_AMD_K6,
174
+	//CPU_CYRIX_6X86MX, // Cyrix 6x86 + MMX
175
+	// 1998
176
+	CPU_AMD_K6_2, // added 3DNow! (MMX)
177
+	// 1999
178
+	// CPU_AMD_K6_3 // added SSE
179
+
180
+	///////////////////////////////////////
181
+	// 7th generation
182
+	///////////////////////////////////////
183
+	// 1999
184
+	CPU_PENTIUM3, // introduced SSE
185
+	// CPU_AMD_K7 // aka Athlon
186
+	// 2000
187
+	CPU_PENTIUM4, // introduced SSE2 and hyperthreading
188
+
189
+	// 2004? 2005?
190
+	CPU_PRESCOTT, // introduced SSE3
191
+
192
+	///////////////////////////////////////
193
+	// 8th generation (X86-64)
194
+	// IA32 instruction set with 64-bit extensions, >4GB RAM
195
+	///////////////////////////////////////
196
+
197
+	// 2003
198
+	CPU_AMD64, // includes Athlon 64 and Opteron aka X86-64
199
+
200
+	// 2004?
201
+	//CPU_EMD64 // Intel's version of AMD64
202
+	CPU_IA64 // aka Itanium: new instruction set -- adds JMPE to IA32 mode to return to IA64 native code
203
+
204
+} CPU_TYPE;
205
+
206
+//////////////////////////////////////////////////////////////////
207
+// Conditions (these can be OR'd)
208
+//////////////////////////////////////////////////////////////////
209
+
210
+// Used for Flags.Preconditions
211
+#define COND_O   (1<<0)  // overflow (signed)
212
+#define COND_C   (1<<1)  // below (unsigned)
213
+#define COND_Z   (1<<2)  // equal (unsigned)
214
+#define COND_S   (1<<3)  // sign set (signed)
215
+#define COND_P   (1<<4)  // parity even
216
+#define COND_BE  (1<<5)  // CF or ZF is set (unsigned)
217
+#define COND_L   (1<<6)  // (SF && !OF) || (OF && !SF)
218
+#define COND_LE  (1<<7)  // ZF || (SF && !OF) || (OF && !SF) (signed)
219
+#define COND_NO  (1<<8)  // !O
220
+#define COND_NC  (1<<9)  // !C (not below, above or equal to)
221
+#define COND_NZ  (1<<10) // !Z (not equal)
222
+#define COND_NS  (1<<11) // !S
223
+#define COND_NP  (1<<12) // !P (parity odd)
224
+#define COND_NL  (1<<13) // (!SF && !OF) || (SF && OF)
225
+#define COND_G   (1<<14) // !ZF && ((!SF && !OF) || (SF && OF))
226
+#define COND_D   (1<<15) // DF
227
+#define COND_REG_xCX_BIG_Z  (1<<16) // CX/ECX/RCX (depending on address size) == 0
228
+#define COND_REG_xCX_BIG_NZ (1<<17) // CX/ECX/RCX (depending on address size) != 0
229
+#define COND_OP1_EQ_OP2 (1<<18)
230
+#define COND_OP1_EQ_OP3 (1<<19)
231
+#define COND_B   COND_C
232
+#define COND_NAE COND_C
233
+#define COND_E   COND_Z
234
+#define COND_NA  COND_BE
235
+#define COND_PE  COND_P
236
+#define COND_U   COND_P
237
+#define COND_NGE COND_L
238
+#define COND_NG  COND_LE
239
+#define COND_PO  COND_NP
240
+#define COND_NU  COND_NP
241
+#define COND_NE  COND_NZ
242
+#define COND_NB  COND_NC
243
+#define COND_AE  COND_NC
244
+#define COND_NE  COND_NZ
245
+#define COND_A   (COND_NC|COND_NZ)
246
+#define COND_NBE COND_A
247
+#define COND_GE COND_NL
248
+#define COND_NLE COND_G
249
+
250
+// Used for Opcode.FlagsChanged
251
+#define FLAG_CF_SET (1<<0)
252
+#define FLAG_DF_SET (1<<1)
253
+#define FLAG_IF_SET (1<<2)
254
+#define FLAG_SET_MASK (FLAG_CF_SET|FLAG_DF_SET|FLAG_IF_SET)
255
+
256
+#define FLAG_SF_CLR (1<<3)
257
+#define FLAG_ZF_CLR (1<<4)
258
+#define FLAG_AF_CLR (1<<5)
259
+#define FLAG_CF_CLR (1<<6)
260
+#define FLAG_DF_CLR (1<<7)
261
+#define FLAG_IF_CLR (1<<8)
262
+#define FLAG_OF_CLR (1<<9)
263
+#define FPU_C0_CLR (1<<19)
264
+#define FPU_C1_CLR (1<<20)
265
+#define FPU_C2_CLR (1<<21)
266
+#define FPU_C3_CLR (1<<22)
267
+#define FPU_ALL_CLR (FPU_C0_CLR|FPU_C1_CLR|FPU_C2_CLR|FPU_C3_CLR)
268
+#define FLAG_CLR_MASK (FLAG_SF_CLR|FLAG_ZF_CLR|FLAG_AF_CLR|FLAG_CF_CLR|FLAG_DF_CLR|FLAG_IF_CLR|FLAG_OF_CLR|FPU_ALL_CLR)
269
+
270
+#define FLAG_OF_MOD (1<<10)
271
+#define FLAG_SF_MOD (1<<11)
272
+#define FLAG_ZF_MOD (1<<12)
273
+#define FLAG_AF_MOD (1<<13)
274
+#define FLAG_PF_MOD (1<<14)
275
+#define FLAG_CF_MOD (1<<15)
276
+#define FLAG_DF_MOD (1<<16)
277
+#define FLAG_IF_MOD (1<<17)
278
+#define FLAG_ALL_MOD (FLAG_OF_MOD|FLAG_SF_MOD|FLAG_ZF_MOD|FLAG_AF_MOD|FLAG_PF_MOD|FLAG_CF_MOD|FLAG_DF_MOD|FLAG_IF_MOD)
279
+#define FLAG_COMMON_MOD (FLAG_OF_MOD|FLAG_SF_MOD|FLAG_ZF_MOD|FLAG_AF_MOD|FLAG_PF_MOD|FLAG_CF_MOD)
280
+#define FPU_C0_MOD (1<<23)
281
+#define FPU_C1_MOD (1<<24)
282
+#define FPU_C2_MOD (1<<25)
283
+#define FPU_C3_MOD (1<<26)
284
+#define FPU_ALL_MOD (FPU_C0_MOD|FPU_C1_MOD|FPU_C2_MOD|FPU_C3_MOD)
285
+#define FLAG_MOD_MASK (FLAG_ALL_MOD|FPU_ALL_MOD)
286
+
287
+#define FLAG_CF_TOG (1<<18)
288
+#define FLAG_TOG_MASK FLAG_CF_TOG
289
+
290
+// Used for Opcode.ResultsIfTrue and Opcode.ResultsIfFalse
291
+#define OP1_DST         (1<<0)
292
+#define OP2_DST         (1<<1)
293
+#define OP3_DST         (1<<2)
294
+#define OP1_SRC         (1<<3)
295
+#define OP2_SRC         (1<<4)
296
+#define OP3_SRC         (1<<5)
297
+#define FPU_STACK_INC   (1<<6)
298
+#define FPU_STACK_INC2  (1<<7)
299
+#define FPU_STACK_DEC   (1<<8)
300
+#define SERIALIZE_WRITE (1<<9)
301
+#define SERIALIZE_READ  (1<<10)
302
+#define xCX_DEC         (1<<11)
303
+#define xCX_REP_DEC     (1<<12)
304
+#define xDI_DEC         (1<<13)
305
+#define xDI_INC         (1<<14)
306
+#define xSI_DEC         (1<<15)
307
+#define xSI_INC         (1<<16)
308
+#define xDI_DECx        (1<<17)
309
+#define xDI_INCx        (1<<18)
310
+#define xSI_DECx        (1<<19)
311
+#define xSI_INCx        (1<<20)
312
+#define FPU_STACK_PUSH FPU_STACK_DEC
313
+#define FPU_STACK_POP  FPU_STACK_INC
314
+#define FPU_STACK_POP2 FPU_STACK_INC2
315
+#define SERIALIZE_ALL (SERIALIZE_WRITE|SERIALIZE_READ)
316
+
317
+#define X86_SEGMENT_OFFSET 0x00
318
+#define X86_TEST_OFFSET    0x10
319
+#define X86_CONTROL_OFFSET 0x20
320
+#define X86_DEBUG_OFFSET   0x30
321
+#define X86_FPU_OFFSET     0x40
322
+#define X86_MMX_OFFSET     0x50
323
+#define X86_XMM_OFFSET     0x60
324
+#define X86_8BIT_OFFSET    0x70
325
+#define X86_16BIT_OFFSET   0x80
326
+#define X86_32BIT_OFFSET   0x90
327
+#define AMD64_8BIT_OFFSET  0xA0
328
+#define AMD64_16BIT_OFFSET 0xB0
329
+#define AMD64_32BIT_OFFSET 0xC0
330
+#define AMD64_64BIT_OFFSET 0xD0
331
+
332
+typedef enum _X86_REGISTER
333
+{
334
+	// Segments
335
+	X86_SEG_ES = X86_SEGMENT_OFFSET,
336
+	X86_SEG_CS,
337
+	X86_SEG_SS,
338
+	X86_SEG_DS,
339
+	X86_SEG_FS,
340
+	X86_SEG_GS,
341
+
342
+	// Miscellaneous
343
+	X86_REG_FLAGS,
344
+	X86_REG_EFLAGS,
345
+	AMD64_REG_RFLAGS,
346
+	X86_REG_IP,
347
+	X86_REG_EIP,
348
+	AMD64_REG_RIP,
349
+
350
+	// Test registers
351
+	X86_REG_TR0 = X86_TEST_OFFSET,
352
+	X86_REG_TR1,
353
+	X86_REG_TR2,
354
+	X86_REG_TR3,
355
+	X86_REG_TR4,
356
+	X86_REG_TR5,
357
+	X86_REG_TR6,
358
+	X86_REG_TR7,
359
+	X86_REG_TR8,
360
+	X86_REG_TR9,
361
+	X86_REG_TR10,
362
+	X86_REG_TR11,
363
+	X86_REG_TR12,
364
+	X86_REG_TR13,
365
+	X86_REG_TR14,
366
+	X86_REG_TR15,
367
+
368
+	// Control registers
369
+	X86_REG_CR0=X86_CONTROL_OFFSET,
370
+	X86_REG_CR1,
371
+	X86_REG_CR2,
372
+	X86_REG_CR3,
373
+	X86_REG_CR4,
374
+	X86_REG_CR5,
375
+	X86_REG_CR6,
376
+	X86_REG_CR7,
377
+	X86_REG_CR8,
378
+	X86_REG_CR9,
379
+	X86_REG_CR10,
380
+	X86_REG_CR11,
381
+	X86_REG_CR12,
382
+	X86_REG_CR13,
383
+	X86_REG_CR14,
384
+	X86_REG_CR15,
385
+
386
+	// Debug registers
387
+	X86_REG_DR0=X86_DEBUG_OFFSET,
388
+	X86_REG_DR1,
389
+	X86_REG_DR2,
390
+	X86_REG_DR3,
391
+	X86_REG_DR4,
392
+	X86_REG_DR5,
393
+	X86_REG_DR6,
394
+	X86_REG_DR7,
395
+	X86_REG_DR8,
396
+	X86_REG_DR9,
397
+	X86_REG_DR10,
398
+	X86_REG_DR11,
399
+	X86_REG_DR12,
400
+	X86_REG_DR13,
401
+	X86_REG_DR14,
402
+	X86_REG_DR15,
403
+
404
+	// FPU registers
405
+	X86_REG_ST0=X86_FPU_OFFSET,
406
+	X86_REG_ST1,
407
+	X86_REG_ST2,
408
+	X86_REG_ST3,
409
+	X86_REG_ST4,
410
+	X86_REG_ST5,
411
+	X86_REG_ST6,
412
+	X86_REG_ST7,
413
+
414
+	// MMX registers
415
+	X86_REG_MM0=X86_MMX_OFFSET,
416
+	X86_REG_MM1,
417
+	X86_REG_MM2,
418
+	X86_REG_MM3,
419
+	X86_REG_MM4,
420
+	X86_REG_MM5,
421
+	X86_REG_MM6,
422
+	X86_REG_MM7,
423
+
424
+	// XMM registers
425
+	X86_REG_XMM0=X86_XMM_OFFSET,
426
+	X86_REG_XMM1,
427
+	X86_REG_XMM2,
428
+	X86_REG_XMM3,
429
+	X86_REG_XMM4,
430
+	X86_REG_XMM5,
431
+	X86_REG_XMM6,
432
+	X86_REG_XMM7,
433
+
434
+	// 8-bit registers
435
+	X86_REG_AL=X86_8BIT_OFFSET,
436
+	X86_REG_CL,
437
+	X86_REG_DL,
438
+	X86_REG_BL,
439
+	X86_REG_AH,
440
+	X86_REG_CH,
441
+	X86_REG_DH,
442
+	X86_REG_BH,
443
+
444
+	// 16-bit registers
445
+	X86_REG_AX=X86_16BIT_OFFSET,
446
+	X86_REG_CX,
447
+	X86_REG_DX,
448
+	X86_REG_BX,
449
+	X86_REG_SP,
450
+	X86_REG_BP,
451
+	X86_REG_SI,
452
+	X86_REG_DI,
453
+
454
+	// 32-bit registers
455
+	X86_REG_EAX=X86_32BIT_OFFSET,
456
+	X86_REG_ECX,
457
+	X86_REG_EDX,
458
+	X86_REG_EBX,
459
+	X86_REG_ESP,
460
+	X86_REG_EBP,
461
+	X86_REG_ESI,
462
+	X86_REG_EDI,
463
+
464
+	// AMD64 8-bit registers
465
+	AMD64_REG_AL=AMD64_8BIT_OFFSET,
466
+	AMD64_REG_CL,
467
+	AMD64_REG_DL,
468
+	AMD64_REG_BL,
469
+	AMD64_REG_SPL,
470
+	AMD64_REG_BPL,
471
+	AMD64_REG_SIL,
472
+	AMD64_REG_DIL,
473
+	AMD64_REG_R8B,
474
+	AMD64_REG_R9B,
475
+	AMD64_REG_R10B,
476
+	AMD64_REG_R11B,
477
+	AMD64_REG_R12B,
478
+	AMD64_REG_R13B,
479
+	AMD64_REG_R14B,
480
+	AMD64_REG_R15B,
481
+
482
+	// AMD64 16-bit registers
483
+	AMD64_REG_AX=AMD64_16BIT_OFFSET,
484
+	AMD64_REG_CX,
485
+	AMD64_REG_DX,
486
+	AMD64_REG_BX,
487
+	AMD64_REG_SP,
488
+	AMD64_REG_BP,
489
+	AMD64_REG_SI,
490
+	AMD64_REG_DI,
491
+	AMD64_REG_R8W,
492
+	AMD64_REG_R9W,
493
+	AMD64_REG_R10W,
494
+	AMD64_REG_R11W,
495
+	AMD64_REG_R12W,
496
+	AMD64_REG_R13W,
497
+	AMD64_REG_R14W,
498
+	AMD64_REG_R15W,
499
+
500
+	// AMD64 32-bit registers
501
+	AMD64_REG_EAX=AMD64_32BIT_OFFSET,
502
+	AMD64_REG_ECX,
503
+	AMD64_REG_EDX,
504
+	AMD64_REG_EBX,
505
+	AMD64_REG_ESP,
506
+	AMD64_REG_EBP,
507
+	AMD64_REG_ESI,
508
+	AMD64_REG_EDI,
509
+	AMD64_REG_R8D,
510
+	AMD64_REG_R9D,
511
+	AMD64_REG_R10D,
512
+	AMD64_REG_R11D,
513
+	AMD64_REG_R12D,
514
+	AMD64_REG_R13D,
515
+	AMD64_REG_R14D,
516
+	AMD64_REG_R15D,
517
+
518
+	// AMD64 64-bit registers
519
+	AMD64_REG_RAX=AMD64_64BIT_OFFSET,
520
+	AMD64_REG_RCX,
521
+	AMD64_REG_RDX,
522
+	AMD64_REG_RBX,
523
+	AMD64_REG_RSP,
524
+	AMD64_REG_RBP,
525
+	AMD64_REG_RSI,
526
+	AMD64_REG_RDI,
527
+	AMD64_REG_R8,
528
+	AMD64_REG_R9,
529
+	AMD64_REG_R10,
530
+	AMD64_REG_R11,
531
+	AMD64_REG_R12,
532
+	AMD64_REG_R13,
533
+	AMD64_REG_R14,
534
+	AMD64_REG_R15
535
+} X86_REGISTER;
536
+
537
+typedef enum _X86_TEST_REGISTER
538
+{
539
+	REG_TR0=0,
540
+	REG_TR1,
541
+	REG_TR2,
542
+	REG_TR3,
543
+	REG_TR4,
544
+	REG_TR5,
545
+	REG_TR6,
546
+	REG_TR7,
547
+	REG_TR8,
548
+	REG_TR9,
549
+	REG_TR10,
550
+	REG_TR11,
551
+	REG_TR12,
552
+	REG_TR13,
553
+	REG_TR14,
554
+	REG_TR15
555
+} X86_TEST_REGISTER;
556
+
557
+typedef enum _X86_CONTROL_REGISTER
558
+{
559
+	REG_CR0,
560
+	REG_CR1,
561
+	REG_CR2,
562
+	REG_CR3,
563
+	REG_CR4,
564
+	REG_CR5,
565
+	REG_CR6,
566
+	REG_CR7,
567
+	REG_CR8,
568
+	REG_CR9,
569
+	REG_CR10,
570
+	REG_CR11,
571
+	REG_CR12,
572
+	REG_CR13,
573
+	REG_CR14,
574
+	REG_CR15
575