Browse Source

Migrate from detours to mhook-2.3

tags/1.7.0
Alex Marsev 6 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:
<td>GPLv2</td>
<td>http://www.datamekanix.com/sizecbar/</td>
</tr>
<tr>
<td>Detours</td>
<td>MSR-SSLA</td>
<td>http://research.microsoft.com/en-us/projects/detours/</td>
</tr>
<tr>
<td>LAV Filters</td>
<td>GPLv2</td>
@@ -103,6 +98,11 @@ MPC-HC makes use of the following third-party code:
<td>Simplified BSD License</td>
<td>http://mediaarea.net/MediaInfo</td>
</tr>
<tr>
<td>Mhook</td>
<td>MIT License</td>
<td>http://codefromthe70s.org/mhook23.aspx</td>
</tr>
<tr>
<td>MultiMon</td>
<td>CPOL</td>

+ 1
- 1
docs/Readme.txt View File

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

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

@@ -1,536 +0,0 @@
//////////////////////////////////////////////////////////////////////////////
//
// Core Detours Functionality (detours.h of detours.lib)
//
// Microsoft Research Detours Package, Version 3.0 Build_316.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
#pragma once
#ifndef _DETOURS_H_
#define _DETOURS_H_
#define DETOURS_VERSION 30000 // 3.00.00
//////////////////////////////////////////////////////////////////////////////
//
#if (_MSC_VER < 1299)
typedef LONG LONG_PTR;
typedef ULONG ULONG_PTR;
#endif
#ifndef __in_z
#define __in_z
#endif
//////////////////////////////////////////////////////////////////////////////
//
#ifndef GUID_DEFINED
#define GUID_DEFINED
typedef struct _GUID
{
DWORD Data1;
WORD Data2;
WORD Data3;
BYTE Data4[ 8 ];
} GUID;
#ifdef INITGUID
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
const GUID name \
= { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
#else
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
const GUID name
#endif // INITGUID
#endif // !GUID_DEFINED
#if defined(__cplusplus)
#ifndef _REFGUID_DEFINED
#define _REFGUID_DEFINED
#define REFGUID const GUID &
#endif // !_REFGUID_DEFINED
#else // !__cplusplus
#ifndef _REFGUID_DEFINED
#define _REFGUID_DEFINED
#define REFGUID const GUID * const
#endif // !_REFGUID_DEFINED
#endif // !__cplusplus
//
//////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/////////////////////////////////////////////////// Instruction Target Macros.
//
#define DETOUR_INSTRUCTION_TARGET_NONE ((PVOID)0)
#define DETOUR_INSTRUCTION_TARGET_DYNAMIC ((PVOID)(LONG_PTR)-1)
#define DETOUR_SECTION_HEADER_SIGNATURE 0x00727444 // "Dtr\0"
extern const GUID DETOUR_EXE_RESTORE_GUID;
extern const GUID DETOUR_EXE_HELPER_GUID;
#define DETOUR_TRAMPOLINE_SIGNATURE 0x21727444 // Dtr!
typedef struct _DETOUR_TRAMPOLINE DETOUR_TRAMPOLINE, *PDETOUR_TRAMPOLINE;
/////////////////////////////////////////////////////////// Binary Structures.
//
#pragma pack(push, 8)
typedef struct _DETOUR_SECTION_HEADER
{
DWORD cbHeaderSize;
DWORD nSignature;
DWORD nDataOffset;
DWORD cbDataSize;
DWORD nOriginalImportVirtualAddress;
DWORD nOriginalImportSize;
DWORD nOriginalBoundImportVirtualAddress;
DWORD nOriginalBoundImportSize;
DWORD nOriginalIatVirtualAddress;
DWORD nOriginalIatSize;
DWORD nOriginalSizeOfImage;
DWORD cbPrePE;
DWORD nOriginalClrFlags;
DWORD reserved1;
DWORD reserved2;
DWORD reserved3;
// Followed by cbPrePE bytes of data.
} DETOUR_SECTION_HEADER, *PDETOUR_SECTION_HEADER;
typedef struct _DETOUR_SECTION_RECORD
{
DWORD cbBytes;
DWORD nReserved;
GUID guid;
} DETOUR_SECTION_RECORD, *PDETOUR_SECTION_RECORD;
typedef struct _DETOUR_CLR_HEADER
{
// Header versioning
ULONG cb;
USHORT MajorRuntimeVersion;
USHORT MinorRuntimeVersion;
// Symbol table and startup information
IMAGE_DATA_DIRECTORY MetaData;
ULONG Flags;
// Followed by the rest of the IMAGE_COR20_HEADER
} DETOUR_CLR_HEADER, *PDETOUR_CLR_HEADER;
typedef struct _DETOUR_EXE_RESTORE
{
DWORD cb;
DWORD cbidh;
DWORD cbinh;
DWORD cbclr;
PBYTE pidh;
PBYTE pinh;
PBYTE pclr;
IMAGE_DOS_HEADER idh;
union {
IMAGE_NT_HEADERS inh;
IMAGE_NT_HEADERS32 inh32;
IMAGE_NT_HEADERS64 inh64;
BYTE raw[sizeof(IMAGE_NT_HEADERS64) +
sizeof(IMAGE_SECTION_HEADER) * 32];
};
DETOUR_CLR_HEADER clr;
} DETOUR_EXE_RESTORE, *PDETOUR_EXE_RESTORE;
typedef struct _DETOUR_EXE_HELPER
{
DWORD cb;
DWORD pid;
CHAR DllName[MAX_PATH];
} DETOUR_EXE_HELPER, *PDETOUR_EXE_HELPER;
#pragma pack(pop)
#define DETOUR_SECTION_HEADER_DECLARE(cbSectionSize) \
{ \
sizeof(DETOUR_SECTION_HEADER),\
DETOUR_SECTION_HEADER_SIGNATURE,\
sizeof(DETOUR_SECTION_HEADER),\
(cbSectionSize),\
\
0,\
0,\
0,\
0,\
\
0,\
0,\
0,\
0,\
}
/////////////////////////////////////////////////////////////// Helper Macros.
//
#define DETOURS_STRINGIFY(x) DETOURS_STRINGIFY_(x)
#define DETOURS_STRINGIFY_(x) #x
///////////////////////////////////////////////////////////// Binary Typedefs.
//
typedef BOOL (CALLBACK *PF_DETOUR_BINARY_BYWAY_CALLBACK)(PVOID pContext,
PCHAR pszFile,
PCHAR *ppszOutFile);
typedef BOOL (CALLBACK *PF_DETOUR_BINARY_FILE_CALLBACK)(PVOID pContext,
PCHAR pszOrigFile,
PCHAR pszFile,
PCHAR *ppszOutFile);
typedef BOOL (CALLBACK *PF_DETOUR_BINARY_SYMBOL_CALLBACK)(PVOID pContext,
ULONG nOrigOrdinal,
ULONG nOrdinal,
ULONG *pnOutOrdinal,
PCHAR pszOrigSymbol,
PCHAR pszSymbol,
PCHAR *ppszOutSymbol);
typedef BOOL (CALLBACK *PF_DETOUR_BINARY_COMMIT_CALLBACK)(PVOID pContext);
typedef BOOL (CALLBACK *PF_DETOUR_ENUMERATE_EXPORT_CALLBACK)(PVOID pContext,
ULONG nOrdinal,
PCHAR pszName,
PVOID pCode);
typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FILE_CALLBACK)(PVOID pContext,
HMODULE hModule,
PCSTR pszFile);
typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FUNC_CALLBACK)(PVOID pContext,
DWORD nOrdinal,
PCSTR pszFunc,
PVOID pvFunc);
typedef VOID * PDETOUR_BINARY;
typedef VOID * PDETOUR_LOADED_BINARY;
//////////////////////////////////////////////////////////// Transaction APIs.
//
LONG WINAPI DetourTransactionBegin(VOID);
LONG WINAPI DetourTransactionAbort(VOID);
LONG WINAPI DetourTransactionCommit(VOID);
LONG WINAPI DetourTransactionCommitEx(PVOID **pppFailedPointer);
LONG WINAPI DetourUpdateThread(HANDLE hThread);
LONG WINAPI DetourAttach(PVOID *ppPointer,
PVOID pDetour);
LONG WINAPI DetourAttachEx(PVOID *ppPointer,
PVOID pDetour,
PDETOUR_TRAMPOLINE *ppRealTrampoline,
PVOID *ppRealTarget,
PVOID *ppRealDetour);
LONG WINAPI DetourDetach(PVOID *ppPointer,
PVOID pDetour);
BOOL WINAPI DetourSetIgnoreTooSmall(BOOL fIgnore);
BOOL WINAPI DetourSetRetainRegions(BOOL fRetain);
////////////////////////////////////////////////////////////// Code Functions.
//
PVOID WINAPI DetourFindFunction(PCSTR pszModule, PCSTR pszFunction);
PVOID WINAPI DetourCodeFromPointer(PVOID pPointer, PVOID *ppGlobals);
PVOID WINAPI DetourCopyInstruction(PVOID pDst,
PVOID *pDstPool,
PVOID pSrc,
PVOID *ppTarget,
LONG *plExtra);
///////////////////////////////////////////////////// Loaded Binary Functions.
//
HMODULE WINAPI DetourGetContainingModule(PVOID pvAddr);
HMODULE WINAPI DetourEnumerateModules(HMODULE hModuleLast);
PVOID WINAPI DetourGetEntryPoint(HMODULE hModule);
ULONG WINAPI DetourGetModuleSize(HMODULE hModule);
BOOL WINAPI DetourEnumerateExports(HMODULE hModule,
PVOID pContext,
PF_DETOUR_ENUMERATE_EXPORT_CALLBACK pfExport);
BOOL WINAPI DetourEnumerateImports(HMODULE hModule,
PVOID pContext,
PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile,
PF_DETOUR_IMPORT_FUNC_CALLBACK pfImportFunc);
PVOID WINAPI DetourFindPayload(HMODULE hModule, REFGUID rguid, DWORD *pcbData);
PVOID WINAPI DetourFindPayloadEx(REFGUID rguid, DWORD * pcbData);
DWORD WINAPI DetourGetSizeOfPayloads(HMODULE hModule);
///////////////////////////////////////////////// Persistent Binary Functions.
//
PDETOUR_BINARY WINAPI DetourBinaryOpen(HANDLE hFile);
PVOID WINAPI DetourBinaryEnumeratePayloads(PDETOUR_BINARY pBinary,
GUID *pGuid,
DWORD *pcbData,
DWORD *pnIterator);
PVOID WINAPI DetourBinaryFindPayload(PDETOUR_BINARY pBinary,
REFGUID rguid,
DWORD *pcbData);
PVOID WINAPI DetourBinarySetPayload(PDETOUR_BINARY pBinary,
REFGUID rguid,
PVOID pData,
DWORD cbData);
BOOL WINAPI DetourBinaryDeletePayload(PDETOUR_BINARY pBinary, REFGUID rguid);
BOOL WINAPI DetourBinaryPurgePayloads(PDETOUR_BINARY pBinary);
BOOL WINAPI DetourBinaryResetImports(PDETOUR_BINARY pBinary);
BOOL WINAPI DetourBinaryEditImports(PDETOUR_BINARY pBinary,
PVOID pContext,
PF_DETOUR_BINARY_BYWAY_CALLBACK pfByway,
PF_DETOUR_BINARY_FILE_CALLBACK pfFile,
PF_DETOUR_BINARY_SYMBOL_CALLBACK pfSymbol,
PF_DETOUR_BINARY_COMMIT_CALLBACK pfCommit);
BOOL WINAPI DetourBinaryWrite(PDETOUR_BINARY pBinary, HANDLE hFile);
BOOL WINAPI DetourBinaryClose(PDETOUR_BINARY pBinary);
/////////////////////////////////////////////////// Create Process & Load Dll.
//
typedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEA)
(LPCSTR lpApplicationName,
LPSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCSTR lpCurrentDirectory,
LPSTARTUPINFOA lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation);
typedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEW)
(LPCWSTR lpApplicationName,
LPWSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCWSTR lpCurrentDirectory,
LPSTARTUPINFOW lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation);
BOOL WINAPI DetourCreateProcessWithDllA(LPCSTR lpApplicationName,
__in_z LPSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCSTR lpCurrentDirectory,
LPSTARTUPINFOA lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation,
LPCSTR lpDllName,
PDETOUR_CREATE_PROCESS_ROUTINEA
pfCreateProcessA);
BOOL WINAPI DetourCreateProcessWithDllW(LPCWSTR lpApplicationName,
__in_z LPWSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCWSTR lpCurrentDirectory,
LPSTARTUPINFOW lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation,
LPCSTR lpDllName,
PDETOUR_CREATE_PROCESS_ROUTINEW
pfCreateProcessW);
#ifdef UNICODE
#define DetourCreateProcessWithDll DetourCreateProcessWithDllW
#define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEW
#else
#define DetourCreateProcessWithDll DetourCreateProcessWithDllA
#define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEA
#endif // !UNICODE
BOOL WINAPI DetourCreateProcessWithDllExA(LPCSTR lpApplicationName,
__in_z LPSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCSTR lpCurrentDirectory,
LPSTARTUPINFOA lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation,
LPCSTR lpDllName,
PDETOUR_CREATE_PROCESS_ROUTINEA
pfCreateProcessA);
BOOL WINAPI DetourCreateProcessWithDllExW(LPCWSTR lpApplicationName,
__in_z LPWSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCWSTR lpCurrentDirectory,
LPSTARTUPINFOW lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation,
LPCSTR lpDllName,
PDETOUR_CREATE_PROCESS_ROUTINEW
pfCreateProcessW);
#ifdef UNICODE
#define DetourCreateProcessWithDllEx DetourCreateProcessWithDllExW
#define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEW
#else
#define DetourCreateProcessWithDllEx DetourCreateProcessWithDllExA
#define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEA
#endif // !UNICODE
BOOL WINAPI DetourProcessViaHelperA(DWORD dwTargetPid,
LPCSTR lpDllName,
PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA);
BOOL WINAPI DetourProcessViaHelperW(DWORD dwTargetPid,
LPCSTR lpDllName,
PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW);
#ifdef UNICODE
#define DetourProcessViaHelper DetourProcessViaHelperW
#else
#define DetourProcessViaHelper DetourProcessViaHelperA
#endif // !UNICODE
BOOL WINAPI DetourUpdateProcessWithDll(HANDLE hProcess,
LPCSTR *plpDlls,
DWORD nDlls);
BOOL WINAPI DetourCopyPayloadToProcess(HANDLE hProcess,
REFGUID rguid,
PVOID pvData,
DWORD cbData);
BOOL WINAPI DetourRestoreAfterWith(VOID);
BOOL WINAPI DetourRestoreAfterWithEx(PVOID pvData, DWORD cbData);
BOOL WINAPI DetourIsHelperProcess(VOID);
VOID CALLBACK DetourFinishHelperProcess(HWND, HINSTANCE, LPSTR, INT);
//
//////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif // __cplusplus
//////////////////////////////////////////////// Detours Internal Definitions.
//
#ifdef __cplusplus
#ifdef DETOURS_INTERNAL
#ifndef __deref_out
#define __deref_out
#endif
#ifndef __deref
#define __deref
#endif
//////////////////////////////////////////////////////////////////////////////
//
#if (_MSC_VER < 1299)
#include <imagehlp.h>
typedef IMAGEHLP_MODULE IMAGEHLP_MODULE64;
typedef PIMAGEHLP_MODULE PIMAGEHLP_MODULE64;
typedef IMAGEHLP_SYMBOL SYMBOL_INFO;
typedef PIMAGEHLP_SYMBOL PSYMBOL_INFO;
static inline
LONG InterlockedCompareExchange(LONG *ptr, LONG nval, LONG oval)
{
return (LONG)::InterlockedCompareExchange((PVOID*)ptr, (PVOID)nval, (PVOID)oval);
}
#else
#include <dbghelp.h>
#endif
#ifdef IMAGEAPI // defined by DBGHELP.H
typedef LPAPI_VERSION (NTAPI *PF_ImagehlpApiVersionEx)(LPAPI_VERSION AppVersion);
typedef BOOL (NTAPI *PF_SymInitialize)(IN HANDLE hProcess,
IN LPCSTR UserSearchPath,
IN BOOL fInvadeProcess);
typedef DWORD (NTAPI *PF_SymSetOptions)(IN DWORD SymOptions);
typedef DWORD (NTAPI *PF_SymGetOptions)(VOID);
typedef DWORD64 (NTAPI *PF_SymLoadModule64)(IN HANDLE hProcess,
IN HANDLE hFile,
IN PSTR ImageName,
IN PSTR ModuleName,
IN DWORD64 BaseOfDll,
IN DWORD SizeOfDll);
typedef BOOL (NTAPI *PF_SymGetModuleInfo64)(IN HANDLE hProcess,
IN DWORD64 qwAddr,
OUT PIMAGEHLP_MODULE64 ModuleInfo);
typedef BOOL (NTAPI *PF_SymFromName)(IN HANDLE hProcess,
IN LPSTR Name,
OUT PSYMBOL_INFO Symbol);
typedef struct _DETOUR_SYM_INFO
{
HANDLE hProcess;
HMODULE hDbgHelp;
PF_ImagehlpApiVersionEx pfImagehlpApiVersionEx;
PF_SymInitialize pfSymInitialize;
PF_SymSetOptions pfSymSetOptions;
PF_SymGetOptions pfSymGetOptions;
PF_SymLoadModule64 pfSymLoadModule64;
PF_SymGetModuleInfo64 pfSymGetModuleInfo64;
PF_SymFromName pfSymFromName;
} DETOUR_SYM_INFO, *PDETOUR_SYM_INFO;
PDETOUR_SYM_INFO DetourLoadDbgHelp(VOID);
#endif // IMAGEAPI
#ifndef DETOUR_TRACE
#if DETOUR_DEBUG
#define DETOUR_TRACE(x) printf x
#define DETOUR_BREAK() __debugbreak()
#include <stdio.h>
#include <limits.h>
#else
#define DETOUR_TRACE(x)
#define DETOUR_BREAK()
#endif
#endif
#ifdef DETOURS_IA64
#error Feature not supported in this release.
#endif // DETOURS_IA64
#ifdef DETOURS_ARM
#error Feature not supported in this release.
#endif // DETOURS_ARM
//////////////////////////////////////////////////////////////////////////////
#endif // DETOURS_INTERNAL
#endif // __cplusplus
#endif // _DETOURS_H_
//
//////////////////////////////////////////////////////////////// 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
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LAVFilters", "src\thirdparty\LAVFilters\LAVFilters.vcxproj", "{ED257874-E12E-4143-AF0A-0676DA3BB18C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mhook", "src\thirdparty\mhook\mhook.vcxproj", "{F841363C-A630-4716-8941-CDDC1F32CFC3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug Filter|Win32 = Debug Filter|Win32
@@ -1065,6 +1067,30 @@ Global
{ED257874-E12E-4143-AF0A-0676DA3BB18C}.Release|Win32.Build.0 = Release|Win32
{ED257874-E12E-4143-AF0A-0676DA3BB18C}.Release|x64.ActiveCfg = Release|x64
{ED257874-E12E-4143-AF0A-0676DA3BB18C}.Release|x64.Build.0 = Release|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Filter|Win32.ActiveCfg = Debug|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Filter|Win32.Build.0 = Debug|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Filter|x64.ActiveCfg = Debug|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Filter|x64.Build.0 = Debug|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Lite|Win32.ActiveCfg = Debug|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Lite|Win32.Build.0 = Debug|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Lite|x64.ActiveCfg = Debug|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Lite|x64.Build.0 = Debug|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug|Win32.ActiveCfg = Debug|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug|Win32.Build.0 = Debug|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug|x64.ActiveCfg = Debug|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug|x64.Build.0 = Debug|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Filter|Win32.ActiveCfg = Release|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Filter|Win32.Build.0 = Release|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Filter|x64.ActiveCfg = Release|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Filter|x64.Build.0 = Release|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Lite|Win32.ActiveCfg = Release|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Lite|Win32.Build.0 = Release|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Lite|x64.ActiveCfg = Release|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Lite|x64.Build.0 = Release|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release|Win32.ActiveCfg = Release|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release|Win32.Build.0 = Release|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release|x64.ActiveCfg = Release|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -1089,6 +1115,7 @@ Global
{DA8461C4-7683-4360-9372-2A9E0F1795C2} = {D9A0529B-9EC4-4D30-9E05-A5D533739D95}
{2B7F22D7-1750-47C5-8709-1A3688B62499} = {D9A0529B-9EC4-4D30-9E05-A5D533739D95}
{ED257874-E12E-4143-AF0A-0676DA3BB18C} = {D9A0529B-9EC4-4D30-9E05-A5D533739D95}
{F841363C-A630-4716-8941-CDDC1F32CFC3} = {D9A0529B-9EC4-4D30-9E05-A5D533739D95}
{03208025-D5C2-426A-B0FA-251D4338F30C} = {2913B7E4-7A8B-43D5-A60B-345A0782816A}
{476B97B4-F079-4A44-AF89-52CA30C35E28} = {2913B7E4-7A8B-43D5-A60B-345A0782816A}
{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
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LAVFilters", "src\thirdparty\LAVFilters\LAVFilters.vcxproj", "{ED257874-E12E-4143-AF0A-0676DA3BB18C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mhook", "src\thirdparty\mhook\mhook.vcxproj", "{F841363C-A630-4716-8941-CDDC1F32CFC3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug Filter|Win32 = Debug Filter|Win32
@@ -1064,6 +1066,30 @@ Global
{ED257874-E12E-4143-AF0A-0676DA3BB18C}.Release|Win32.Build.0 = Release|Win32
{ED257874-E12E-4143-AF0A-0676DA3BB18C}.Release|x64.ActiveCfg = Release|x64
{ED257874-E12E-4143-AF0A-0676DA3BB18C}.Release|x64.Build.0 = Release|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Filter|Win32.ActiveCfg = Debug|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Filter|Win32.Build.0 = Debug|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Filter|x64.ActiveCfg = Debug|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Filter|x64.Build.0 = Debug|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Lite|Win32.ActiveCfg = Debug|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Lite|Win32.Build.0 = Debug|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Lite|x64.ActiveCfg = Debug|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug Lite|x64.Build.0 = Debug|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug|Win32.ActiveCfg = Debug|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug|Win32.Build.0 = Debug|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug|x64.ActiveCfg = Debug|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Debug|x64.Build.0 = Debug|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Filter|Win32.ActiveCfg = Release|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Filter|Win32.Build.0 = Release|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Filter|x64.ActiveCfg = Release|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Filter|x64.Build.0 = Release|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Lite|Win32.ActiveCfg = Release|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Lite|Win32.Build.0 = Release|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Lite|x64.ActiveCfg = Release|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release Lite|x64.Build.0 = Release|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release|Win32.ActiveCfg = Release|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release|Win32.Build.0 = Release|Win32
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release|x64.ActiveCfg = Release|x64
{F841363C-A630-4716-8941-CDDC1F32CFC3}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -1088,6 +1114,7 @@ Global
{DA8461C4-7683-4360-9372-2A9E0F1795C2} = {D9A0529B-9EC4-4D30-9E05-A5D533739D95}
{2B7F22D7-1750-47C5-8709-1A3688B62499} = {D9A0529B-9EC4-4D30-9E05-A5D533739D95}
{ED257874-E12E-4143-AF0A-0676DA3BB18C} = {D9A0529B-9EC4-4D30-9E05-A5D533739D95}
{F841363C-A630-4716-8941-CDDC1F32CFC3} = {D9A0529B-9EC4-4D30-9E05-A5D533739D95}
{03208025-D5C2-426A-B0FA-251D4338F30C} = {2913B7E4-7A8B-43D5-A60B-345A0782816A}
{476B97B4-F079-4A44-AF89-52CA30C35E28} = {2913B7E4-7A8B-43D5-A60B-345A0782816A}
{4CC7AE86-3E0A-430A-BFF4-BF00204CAFB0} = {2913B7E4-7A8B-43D5-A60B-345A0782816A}

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

@@ -25,7 +25,7 @@
#include "DSUtil.h"
#include <InitGuid.h>
#include "detours/detours.h"
#include "mhook/mhook-lib/mhook.h"
HRESULT(__stdcall* Real_CoCreateInstance)(CONST IID& a0,
@@ -526,35 +526,35 @@ bool CFilterMapper2::fInitialized = false;
void CFilterMapper2::Init()
{
if (!fInitialized) {
DetourAttach(&(PVOID&)Real_CoCreateInstance, (PVOID)Mine_CoCreateInstance);
DetourAttach(&(PVOID&)Real_RegCloseKey, (PVOID)Mine_RegCloseKey);
DetourAttach(&(PVOID&)Real_RegFlushKey, (PVOID)Mine_RegFlushKey);
DetourAttach(&(PVOID&)Real_RegCreateKeyA, (PVOID)Mine_RegCreateKeyA);
DetourAttach(&(PVOID&)Real_RegCreateKeyW, (PVOID)Mine_RegCreateKeyW);
DetourAttach(&(PVOID&)Real_RegCreateKeyExA, (PVOID)Mine_RegCreateKeyExA);
DetourAttach(&(PVOID&)Real_RegCreateKeyExW, (PVOID)Mine_RegCreateKeyExW);
DetourAttach(&(PVOID&)Real_RegDeleteKeyA, (PVOID)Mine_RegDeleteKeyA);
DetourAttach(&(PVOID&)Real_RegDeleteKeyW, (PVOID)Mine_RegDeleteKeyW);
DetourAttach(&(PVOID&)Real_RegDeleteValueA, (PVOID)Mine_RegDeleteValueA);
DetourAttach(&(PVOID&)Real_RegDeleteValueW, (PVOID)Mine_RegDeleteValueW);
DetourAttach(&(PVOID&)Real_RegEnumKeyExA, (PVOID)Mine_RegEnumKeyExA);
DetourAttach(&(PVOID&)Real_RegEnumKeyExW, (PVOID)Mine_RegEnumKeyExW);
DetourAttach(&(PVOID&)Real_RegEnumValueA, (PVOID)Mine_RegEnumValueA);
DetourAttach(&(PVOID&)Real_RegEnumValueW, (PVOID)Mine_RegEnumValueW);
DetourAttach(&(PVOID&)Real_RegOpenKeyA, (PVOID)Mine_RegOpenKeyA);
DetourAttach(&(PVOID&)Real_RegOpenKeyW, (PVOID)Mine_RegOpenKeyW);
DetourAttach(&(PVOID&)Real_RegOpenKeyExA, (PVOID)Mine_RegOpenKeyExA);
DetourAttach(&(PVOID&)Real_RegOpenKeyExW, (PVOID)Mine_RegOpenKeyExW);
DetourAttach(&(PVOID&)Real_RegQueryInfoKeyA, (PVOID)Mine_RegQueryInfoKeyA);
DetourAttach(&(PVOID&)Real_RegQueryInfoKeyW, (PVOID)Mine_RegQueryInfoKeyW);
DetourAttach(&(PVOID&)Real_RegQueryValueA, (PVOID)Mine_RegQueryValueA);
DetourAttach(&(PVOID&)Real_RegQueryValueW, (PVOID)Mine_RegQueryValueW);
DetourAttach(&(PVOID&)Real_RegQueryValueExA, (PVOID)Mine_RegQueryValueExA);
DetourAttach(&(PVOID&)Real_RegQueryValueExW, (PVOID)Mine_RegQueryValueExW);
DetourAttach(&(PVOID&)Real_RegSetValueA, (PVOID)Mine_RegSetValueA);
DetourAttach(&(PVOID&)Real_RegSetValueW, (PVOID)Mine_RegSetValueW);
DetourAttach(&(PVOID&)Real_RegSetValueExA, (PVOID)Mine_RegSetValueExA);
DetourAttach(&(PVOID&)Real_RegSetValueExW, (PVOID)Mine_RegSetValueExW);
ENSURE(Mhook_SetHook(&(PVOID&)Real_CoCreateInstance, (PVOID)Mine_CoCreateInstance));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegCloseKey, (PVOID)Mine_RegCloseKey));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegFlushKey, (PVOID)Mine_RegFlushKey));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegCreateKeyA, (PVOID)Mine_RegCreateKeyA));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegCreateKeyW, (PVOID)Mine_RegCreateKeyW));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegCreateKeyExA, (PVOID)Mine_RegCreateKeyExA));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegCreateKeyExW, (PVOID)Mine_RegCreateKeyExW));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegDeleteKeyA, (PVOID)Mine_RegDeleteKeyA));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegDeleteKeyW, (PVOID)Mine_RegDeleteKeyW));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegDeleteValueA, (PVOID)Mine_RegDeleteValueA));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegDeleteValueW, (PVOID)Mine_RegDeleteValueW));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegEnumKeyExA, (PVOID)Mine_RegEnumKeyExA));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegEnumKeyExW, (PVOID)Mine_RegEnumKeyExW));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegEnumValueA, (PVOID)Mine_RegEnumValueA));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegEnumValueW, (PVOID)Mine_RegEnumValueW));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegOpenKeyA, (PVOID)Mine_RegOpenKeyA));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegOpenKeyW, (PVOID)Mine_RegOpenKeyW));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegOpenKeyExA, (PVOID)Mine_RegOpenKeyExA));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegOpenKeyExW, (PVOID)Mine_RegOpenKeyExW));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegQueryInfoKeyA, (PVOID)Mine_RegQueryInfoKeyA));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegQueryInfoKeyW, (PVOID)Mine_RegQueryInfoKeyW));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegQueryValueA, (PVOID)Mine_RegQueryValueA));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegQueryValueW, (PVOID)Mine_RegQueryValueW));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegQueryValueExA, (PVOID)Mine_RegQueryValueExA));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegQueryValueExW, (PVOID)Mine_RegQueryValueExW));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegSetValueA, (PVOID)Mine_RegSetValueA));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegSetValueW, (PVOID)Mine_RegSetValueW));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegSetValueExA, (PVOID)Mine_RegSetValueExA));
ENSURE(Mhook_SetHook(&(PVOID&)Real_RegSetValueExW, (PVOID)Mine_RegSetValueExW));
fInitialized = true;
}

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

@@ -160,7 +160,7 @@
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
<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>
<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>
<AdditionalLibraryDirectories>$(SolutionDir)bin\lib\$(Configuration)_$(Platform);$(SolutionDir)lib;$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories Condition="'$(PlatformToolsetVersion)'=='110'">$(SolutionDir)bin12\lib\$(Configuration)_$(Platform);$(SolutionDir)lib;$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<IgnoreSpecificDefaultLibraries>LIBCMT.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
@@ -181,7 +181,7 @@
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
<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>
<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>
<AdditionalLibraryDirectories>$(SolutionDir)bin\lib\Debug_$(Platform);$(SolutionDir)lib;$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories Condition="'$(PlatformToolsetVersion)'=='110'">$(SolutionDir)bin12\lib\Debug_$(Platform);$(SolutionDir)lib;$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<DelayLoadDLLs>d3d9.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
@@ -203,7 +203,7 @@
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
<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>
<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>
<AdditionalLibraryDirectories>$(SolutionDir)bin\lib\$(Configuration)_$(Platform);$(SolutionDir)lib64;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories Condition="'$(PlatformToolsetVersion)'=='110'">$(SolutionDir)bin12\lib\$(Configuration)_$(Platform);$(SolutionDir)lib64;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<IgnoreSpecificDefaultLibraries>LIBCMT.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
@@ -224,7 +224,7 @@
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
<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>
<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>
<AdditionalLibraryDirectories>$(SolutionDir)bin\lib\Debug_$(Platform);$(SolutionDir)lib64;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories Condition="'$(PlatformToolsetVersion)'=='110'">$(SolutionDir)bin12\lib\Debug_$(Platform);$(SolutionDir)lib64;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<DelayLoadDLLs>d3d9.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
@@ -246,7 +246,7 @@
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
<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>
<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>
<AdditionalLibraryDirectories>$(SolutionDir)bin\lib\$(Configuration)_$(Platform);$(SolutionDir)lib;$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories Condition="'$(PlatformToolsetVersion)'=='110'">$(SolutionDir)bin12\lib\$(Configuration)_$(Platform);$(SolutionDir)lib;$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<DelayLoadDLLs>d3d9.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
@@ -266,7 +266,7 @@
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
<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>
<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>
<AdditionalLibraryDirectories>$(SolutionDir)bin\lib\Release_$(Platform);$(SolutionDir)lib;$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories Condition="'$(PlatformToolsetVersion)'=='110'">$(SolutionDir)bin12\lib\Release_$(Platform);$(SolutionDir)lib;$(DXSDK_DIR)Lib\x86;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<DelayLoadDLLs>d3d9.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
@@ -287,7 +287,7 @@
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
<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>
<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>
<AdditionalLibraryDirectories>$(SolutionDir)bin\lib\$(Configuration)_$(Platform);$(SolutionDir)lib64;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories Condition="'$(PlatformToolsetVersion)'=='110'">$(SolutionDir)bin12\lib\$(Configuration)_$(Platform);$(SolutionDir)lib64;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<DelayLoadDLLs>d3d9.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
@@ -307,7 +307,7 @@
<AdditionalIncludeDirectories>..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ResourceCompile>
<Link>
<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>
<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>
<AdditionalLibraryDirectories>$(SolutionDir)bin\lib\Release_$(Platform);$(SolutionDir)lib64;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalLibraryDirectories>$(SolutionDir)bin12\lib\Release_$(Platform);$(SolutionDir)lib64;$(DXSDK_DIR)Lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<DelayLoadDLLs>d3d9.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
@@ -792,6 +792,9 @@
<ProjectReference Include="..\thirdparty\MediaInfo\MediaInfoLib.vcxproj">
<Project>{20e0f8d6-213c-460b-b361-9c725cb375c7}</Project>
</ProjectReference>
<ProjectReference Include="..\thirdparty\mhook\mhook.vcxproj">
<Project>{f841363c-a630-4716-8941-cddc1f32cfc3}</Project>
</ProjectReference>
<ProjectReference Include="..\thirdparty\RARFileSource\RARFileSource.vcxproj">
<Project>{2b7f22d7-1750-47c5-8709-1a3688b62499}</Project>
</ProjectReference>

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

@@ -36,7 +36,7 @@
#include "FileAssoc.h"
#include "UpdateChecker.h"
#include "winddk/ntddcdvd.h"
#include "detours/detours.h"
#include "mhook/mhook-lib/mhook.h"
#include <afxsock.h>
#include <atlsync.h>
#include <atlutil.h>
@@ -1127,8 +1127,6 @@ BOOL CMPlayerCApp::InitInstance()
// Remove the working directory from the search path to work around the DLL preloading vulnerability
SetDllDirectory(_T(""));
long lError;
if (SetHeapOptions()) {
TRACE(_T("Terminate on corruption enabled\n"));
} else {
@@ -1137,19 +1135,15 @@ BOOL CMPlayerCApp::InitInstance()
TRACE(heap_err);
}
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)Real_IsDebuggerPresent, (PVOID)Mine_IsDebuggerPresent);
DetourAttach(&(PVOID&)Real_ChangeDisplaySettingsExA, (PVOID)Mine_ChangeDisplaySettingsExA);
DetourAttach(&(PVOID&)Real_ChangeDisplaySettingsExW, (PVOID)Mine_ChangeDisplaySettingsExW);
DetourAttach(&(PVOID&)Real_CreateFileA, (PVOID)Mine_CreateFileA);
DetourAttach(&(PVOID&)Real_CreateFileW, (PVOID)Mine_CreateFileW);
DetourAttach(&(PVOID&)Real_mixerSetControlDetails, (PVOID)Mine_mixerSetControlDetails);
DetourAttach(&(PVOID&)Real_DeviceIoControl, (PVOID)Mine_DeviceIoControl);
ENSURE(Mhook_SetHook(&(PVOID&)Real_IsDebuggerPresent, (PVOID)Mine_IsDebuggerPresent));
ENSURE(Mhook_SetHook(&(PVOID&)Real_ChangeDisplaySettingsExA, (PVOID)Mine_ChangeDisplaySettingsExA));
ENSURE(Mhook_SetHook(&(PVOID&)Real_ChangeDisplaySettingsExW, (PVOID)Mine_ChangeDisplaySettingsExW));
ENSURE(Mhook_SetHook(&(PVOID&)Real_CreateFileA, (PVOID)Mine_CreateFileA));
ENSURE(Mhook_SetHook(&(PVOID&)Real_CreateFileW, (PVOID)Mine_CreateFileW));
ENSURE(Mhook_SetHook(&(PVOID&)Real_mixerSetControlDetails, (PVOID)Mine_mixerSetControlDetails));
ENSURE(Mhook_SetHook(&(PVOID&)Real_DeviceIoControl, (PVOID)Mine_DeviceIoControl));
DetourAttach(&(PVOID&)Real_LockWindowUpdate, (PVOID)Mine_LockWindowUpdate);
ENSURE(Mhook_SetHook(&(PVOID&)Real_LockWindowUpdate, (PVOID)Mine_LockWindowUpdate));
m_hNTDLL = LoadLibrary(_T("ntdll.dll"));
#ifndef _DEBUG // Disable NtQueryInformationProcess in debug (prevent VS debugger to stop on crash address)
@@ -1157,16 +1151,13 @@ BOOL CMPlayerCApp::InitInstance()
Real_NtQueryInformationProcess = (FUNC_NTQUERYINFORMATIONPROCESS)GetProcAddress(m_hNTDLL, "NtQueryInformationProcess");
if (Real_NtQueryInformationProcess) {
DetourAttach(&(PVOID&)Real_NtQueryInformationProcess, (PVOID)Mine_NtQueryInformationProcess);
ENSURE(Mhook_SetHook(&(PVOID&)Real_NtQueryInformationProcess, (PVOID)Mine_NtQueryInformationProcess));
}
}
#endif
CFilterMapper2::Init();
lError = DetourTransactionCommit();
ASSERT(lError == NOERROR);
if (FAILED(OleInitialize(0))) {
AfxMessageBox(_T("OleInitialize failed!"));
return FALSE;

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

@@ -0,0 +1,93 @@
// Copyright (C) 2003, Matt Conover (mconover@gmail.com)
#include "cpu.h"
#include <assert.h>

// NOTE: this assumes default scenarios (i.e., we assume CS/DS/ES/SS and flat
// and all have a base of 0 and limit of 0xffffffff, we don't try to verify
// that in the GDT)
//
// TODO: use inline assembly to get selector for segment
// Segment = x86 segment register (SEG_ES = 0, SEG_CS = 1, ...)
BYTE *GetAbsoluteAddressFromSegment(BYTE Segment, DWORD Offset)
{
switch (Segment)
{
// Windows uses a flat address space (except FS for x86 and GS for x64)
case 0: // SEG_ES
case 1: // SEG_CS
case 2: // SEG_SS
case 3: // SEG_DS
return (BYTE *)(DWORD_PTR)Offset;
case 4: // SEG_FS
case 5: // SEG_GS
return (BYTE *)(DWORD_PTR)Offset;
// Note: we're really supposed to do this, but get_teb is not implemented
// in this bastardized version of the disassembler.
// return (BYTE *)get_teb() + Offset;
default:
assert(0);
return (BYTE *)(DWORD_PTR)Offset;
}
}

// This is an GDT/LDT selector (pGDT+Selector)
BYTE *GetAbsoluteAddressFromSelector(WORD Selector, DWORD Offset)
{
DESCRIPTOR_ENTRY Entry;
GATE_ENTRY *Gate;
ULONG_PTR Base;
assert(Selector < 0x10000);
if (!GetThreadSelectorEntry(GetCurrentThread(), Selector, (LDT_ENTRY *)&Entry)) return NULL;
if (!Entry.Present) return NULL;
if (Entry.System)
{
Base = 0;
#ifdef _WIN64
Base |= (ULONG_PTR)Entry.HighOffset64 << 32;
#endif
Base |= Entry.BaseHi << 24;
Base |= Entry.BaseMid << 16;
Base |= Entry.BaseLow;
}
else
{
switch (Entry.Type)
{
case 1: // 16-bit TSS (available)
case 2: // LDT
case 3: // 16-bit TSS (busy)
case 9: // 32-bit TSS (available)
case 11: // 32-bit TSS (busy)
Base = 0;
#ifdef _WIN64
Base |= (ULONG_PTR)Entry.HighOffset64 << 32;
#endif
Base |= Entry.BaseHi << 24;
Base |= Entry.BaseMid << 16;
Base |= Entry.BaseLow;
break;

case 4: // 16-bit call gate
case 5: // task gate
case 6: // 16-bit interrupt gate
case 7: // 16-bit task gate
case 12: // 32-bit call gate
case 14: // 32-bit interrupt gate
case 15: // 32-bit trap gate
Gate = (GATE_ENTRY *)&Entry;
#ifdef _WIN64
Base = ((ULONG_PTR)Gate->HighOffset64 << 32) | (Gate->HighOffset << 16) | Gate->LowOffset;
#else
Base = (Gate->HighOffset << 16) | Gate->LowOffset;
#endif
assert(!Offset); Offset = 0;
break;
default:
assert(0);
return NULL;
}
}
return (BYTE *)Base + Offset;
}


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

@@ -0,0 +1,277 @@
// Copyright (C) 2003, Matt Conover (mconover@gmail.com)
#ifndef CPU_H
#define CPU_H
#ifdef __cplusplus
extern "C" {
#endif
#pragma pack(push,1)

#include <windows.h>
#include "misc.h"

////////////////////////////////////////////////////////
// System descriptors
////////////////////////////////////////////////////////

#define GDT_NULL 0
#define GDT_R0_CODE 0x08
#define GDT_R0_DATA 0x10
#define GDT_R3_CODE 0x18
#define GDT_R3_DATA 0x20
#define GDT_TSS 0x28
#define GDT_PCR 0x30
#define GDT_R3_TEB 0x38
#define GDT_VDM 0x40
#define GDT_LDT 0x48
#define GDT_DOUBLEFAULT_TSS 0x50
#define GDT_NMI_TSS 0x58

// 16-bit GDT entries:
// TODO: #define GDT_ABIOS_UNKNOWN 0x60 (22F30-32F2F)
#define GDT_ABIOS_VIDEO 0x68
#define GDT_ABIOS_GDT 0x70 // descriptor describing ABIOS GDT itself
#define GDT_ABIOS_NTOS 0x78 // first 64K of NTOSKRNL
#define GDT_ABIOS_CDA 0xE8 // common data area
#define GDT_ABIOS_CODE 0xF0 // KiI386AbiosCall
#define GDT_ABIOS_STACK 0xF8

#define SELECTOR_RPL_MASK 0x03 // bits 0-1
#define SELECTOR_LDT 0x04 // bit 2

// for data selectors
#define DATA_ACCESS_MASK (1<<0)
#define DATA_WRITE_ENABLE_MASK (1<<1)
#define DATA_EXPAND_DOWN_MASK (1<<2)

// for code selectors
#define CODE_ACCESS_MASK (1<<0)
#define CODE_READ_MASK (1<<1)
#define CODE_CONFORMING_MASK (1<<2)
#define CODE_FLAG (1<<3)

#define TASK_GATE 5
#define INTERRUPT_GATE 6
#define TRAP_GATE 7

typedef struct _IDT_ENTRY
{
USHORT LowOffset;
USHORT Selector;
UCHAR Ignored : 5;
UCHAR Zero : 3;
UCHAR Type : 3;
UCHAR Is32Bit : 1;
UCHAR Ignored2 : 1;
UCHAR DPL : 2;
UCHAR Present : 1;
USHORT HighOffset;
#ifdef _WIN64
ULONG HighOffset64;
ULONG Reserved;
#endif
} IDT_ENTRY, TRAP_GATE_ENTRY;

typedef struct _CALL_GATE_ENTRY
{
USHORT LowOffset;
USHORT Selector;
UCHAR ParameterCount: 4;
UCHAR Ignored : 3;
UCHAR Type : 5;
UCHAR DPL : 2;
UCHAR Present : 1;
USHORT HighOffset;
#ifdef _WIN64
ULONG HighOffset64;
ULONG Reserved;
#endif
} CALL_GATE_ENTRY;

typedef struct _TASK_GATE_ENTRY
{
USHORT Ignored;
USHORT Selector;
UCHAR Ignored2 : 5;
UCHAR Zero : 3;
UCHAR Type : 5;
UCHAR DPL : 2;
UCHAR Present : 1;
USHORT Ignored3;
} TASK_GATE_ENTRY;

typedef struct _DESCRIPTOR_ENTRY
{
USHORT LimitLow;
USHORT BaseLow;
UCHAR BaseMid;
UCHAR Type : 4; // 10EWA (code), E=ExpandDown, W=Writable, A=Accessed
// 11CRA (data), C=Conforming, R=Readable, A=Accessed
UCHAR System : 1; // if 1 then it is a gate or LDT
UCHAR DPL : 2; // descriptor privilege level;
// for data selectors, MAX(CPL, RPL) must be <= DPL to access (or else GP# fault)
// for non-conforming code selectors (without callgate), MAX(CPL, RPL) must be <= DPL to access (or else GP# fault)
// for conforming code selectors, MAX(CPL, RPL) must be >= DPL (i.e., CPL 0-2 cannot access if DPL is 3)
// for non-conforming code selectors (with call gate), DPL indicates lowest privilege allowed to access gate
UCHAR Present : 1;
UCHAR LimitHigh : 4;
UCHAR Available: 1; // aka AVL
UCHAR Reserved : 1;
UCHAR Is32Bit : 1; // aka B flag
UCHAR Granularity : 1; // aka G flag
UCHAR BaseHi : 8;
#ifdef _WIN64
ULONG HighOffset64;
ULONG Reserved2;
#endif
} DESCRIPTOR_ENTRY;

typedef struct _GATE_ENTRY
{
USHORT LowOffset;
UCHAR Skip;
UCHAR Type : 5;
UCHAR DPL : 2;
UCHAR Present : 1;
USHORT HighOffset;
#ifdef _WIN64
ULONG HighOffset64;
ULONG Reserved;
#endif
} GATE_ENTRY;

// TODO: update for X64
typedef struct _PTE_ENTRY
{
ULONG Present : 1;
ULONG Write : 1;
ULONG Owner : 1; // E.g., user mode or supervisor mode
ULONG WriteThrough : 1;
ULONG CacheDisable : 1;
ULONG Accessed : 1;
ULONG Dirty : 1;
ULONG PAT : 1;
ULONG Global : 1;
ULONG CopyOnWrite : 1;
ULONG Prototype : 1;
ULONG Transition : 1;
ULONG Address : 20;
} PTE_ENTRY;

// TODO: update for X64
typedef struct _PDE_ENTRY
{
ULONG Present : 1;
ULONG Write : 1;
ULONG Owner : 1;
ULONG WriteThrough : 1;
ULONG CacheDisable : 1;
ULONG Accessed : 1;
ULONG Reserved1 : 1;
ULONG PageSize : 1;
ULONG Global : 1;
ULONG Reserved : 3;
ULONG Address : 20;
} PDE_ENTRY;

// TODO: update for X64
typedef struct _IO_ACCESS_MAP
{
UCHAR DirectionMap[32];
UCHAR IoMap[8196];
} IO_ACCESS_MAP;

#define MIN_TSS_SIZE FIELD_OFFSET(TSS_ENTRY, IoMaps)
// TODO: update for X64
typedef struct _TSS_ENTRY
{
USHORT Backlink;
USHORT Reserved0;
ULONG Esp0;
USHORT Ss0;
USHORT Reserved1;
ULONG NotUsed1[4];
ULONG CR3;
ULONG Eip;
ULONG NotUsed2[9];
USHORT Es;
USHORT Reserved2;
USHORT Cs;
USHORT Reserved3;
USHORT Ss;
USHORT Reserved4;
USHORT Ds;
USHORT Reserved5;
USHORT Fs;
USHORT Reserved6;
USHORT Gs;
USHORT Reserved7;
USHORT LDT;
USHORT Reserved8;
USHORT Flags;
USHORT IoMapBase;
IO_ACCESS_MAP IoMaps[1];
UCHAR IntDirectionMap[32];
} TSS_ENTRY;

// TODO: update for X64
typedef struct _TSS16_ENTRY
{
USHORT Backlink;
USHORT Sp0;
USHORT Ss0;
USHORT Sp1;
USHORT Ss1;
USHORT Sp2;
USHORT Ss3;
USHORT Ip;
USHORT Flags;
USHORT Ax;
USHORT Cx;
USHORT Dx;
USHORT Bx;
USHORT Sp;
USHORT Bp;
USHORT Si;
USHORT Di;
USHORT Es;
USHORT Cs;
USHORT Ss;
USHORT Ds;
USHORT LDT;
} TSS16_ENTRY;

// TODO: update for X64
typedef struct _GDT_ENTRY
{
USHORT LimitLow;
USHORT BaseLow;
union {
struct {
UCHAR BaseMid;
UCHAR Flags1;
UCHAR Flags2;
UCHAR BaseHi;
} Bytes;
struct {
ULONG BaseMid : 8;
ULONG Type : 5;
ULONG Dpl : 2;
ULONG Pres : 1;
ULONG LimitHi : 4;
ULONG Sys : 1;
ULONG Reserved_0 : 1;
ULONG Default_Big : 1;
ULONG Granularity : 1;
ULONG BaseHi : 8;
} Bits;
} HighWord;
} GDT_ENTRY;

BYTE *GetAbsoluteAddressFromSegment(BYTE Segment, DWORD Offset);
BYTE *GetAbsoluteAddressFromSelector(WORD Selector, DWORD Offset);

#pragma pack(pop)
#ifdef __cplusplus
}
#endif
#endif // CPU_H

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

@@ -0,0 +1,122 @@
// Copyright (C) 2004, Matt Conover (mconover@gmail.com)
#undef NDEBUG
#include <assert.h>
#include <windows.h>
#include "disasm.h"

#ifdef NO_SANITY_CHECKS
#define NDEBUG
#undef assert
#define assert(x)
#endif

//////////////////////////////////////////////////////////////////////
// Global variables
//////////////////////////////////////////////////////////////////////

ARCHITECTURE_FORMAT SupportedArchitectures[] =
{
{ ARCH_X86, &X86 },
{ ARCH_X86_16, &X86 },
{ ARCH_X64, &X86 },
{ ARCH_UNKNOWN, NULL }
};

typedef struct _DISASM_ARG_INFO
{
INSTRUCTION *MatchedInstruction;
BOOL MatchPrefix;
U8 *Opcode;
U32 OpcodeLength;
INSTRUCTION_TYPE InstructionType;
U32 Count;
} DISASM_ARG_INFO;

//////////////////////////////////////////////////////////////////////
// Function prototypes
//////////////////////////////////////////////////////////////////////

BOOL InitInstruction(INSTRUCTION *Instruction, DISASSEMBLER *Disassembler);
struct _ARCHITECTURE_FORMAT *GetArchitectureFormat(ARCHITECTURE_TYPE Type);

//////////////////////////////////////////////////////////////////////
// Disassembler setup
//////////////////////////////////////////////////////////////////////

BOOL InitDisassembler(DISASSEMBLER *Disassembler, ARCHITECTURE_TYPE Architecture)
{
ARCHITECTURE_FORMAT *ArchFormat;

memset(Disassembler, 0, sizeof(DISASSEMBLER));
Disassembler->Initialized = DISASSEMBLER_INITIALIZED;
ArchFormat = GetArchitectureFormat(Architecture);
if (!ArchFormat) { assert(0); return FALSE; }
Disassembler->ArchType = ArchFormat->Type;
Disassembler->Functions = ArchFormat->Functions;
return TRUE;
}

void CloseDisassembler(DISASSEMBLER *Disassembler)
{
memset(Disassembler, 0, sizeof(DISASSEMBLER));
}

//////////////////////////////////////////////////////////////////////
// Instruction setup
//////////////////////////////////////////////////////////////////////

BOOL InitInstruction(INSTRUCTION *Instruction, DISASSEMBLER *Disassembler)
{
memset(Instruction, 0, sizeof(INSTRUCTION));
Instruction->Initialized = INSTRUCTION_INITIALIZED;
Instruction->Disassembler = Disassembler;
memset(Instruction->String, ' ', MAX_OPCODE_DESCRIPTION-1);
Instruction->String[MAX_OPCODE_DESCRIPTION-1] = '\0';
return TRUE;
}

// If Decode = FALSE, only the following fields are valid:
// Instruction->Length, Instruction->Address, Instruction->Prefixes, Instruction->PrefixCount,
// Instruction->OpcodeBytes, Instruction->Instruction->OpcodeLength, Instruction->Groups,
// Instruction->Type, Instruction->OperandCount
//
// If Disassemble = TRUE, then Instruction->String is valid (also requires Decode = TRUE)
//
// WARNING: This will overwrite the previously obtained instruction
INSTRUCTION *GetInstruction(DISASSEMBLER *Disassembler, U64 VirtualAddress, U8 *Address, U32 Flags)
{
if (Disassembler->Initialized != DISASSEMBLER_INITIALIZED) { assert(0); return NULL; }
assert(Address);
InitInstruction(&Disassembler->Instruction, Disassembler);
Disassembler->Instruction.Address = Address;
Disassembler->Instruction.VirtualAddressDelta = VirtualAddress - (U64)Address;
if (!Disassembler->Functions->GetInstruction(&Disassembler->Instruction, Address, Flags))
{
assert(Disassembler->Instruction.Address == Address);
assert(Disassembler->Instruction.Length < MAX_INSTRUCTION_LENGTH);

// Save the address that failed, in case the lower-level disassembler didn't
Disassembler->Instruction.Address = Address;
Disassembler->Instruction.ErrorOccurred = TRUE;
return NULL;
}
return &Disassembler->Instruction;
}

///////////////////////////////////////////////////////////////////////////
// Miscellaneous
///////////////////////////////////////////////////////////////////////////

static ARCHITECTURE_FORMAT *GetArchitectureFormat(ARCHITECTURE_TYPE Type)
{
ARCHITECTURE_FORMAT *Format;
for (Format = SupportedArchitectures; Format->Type != ARCH_UNKNOWN; Format++)
{
if (Format->Type == Type) return Format;
}

assert(0);
return NULL;
}


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

@@ -0,0 +1,578 @@
// Copyright (C) 2004, Matt Conover (mconover@gmail.com)
//
// WARNING:
// I wouldn't recommend changing any flags like OP_*, ITYPE_*, or *_MASK
// aside from those marked as UNUSED. This is because the flags parts of
// the flags are architecture independent and other are left to specific
// architectures to define, so unless you understand the relationships
// between them, I would leave them as is.

#ifndef DISASM_H
#define DISASM_H
#ifdef __cplusplus
extern "C" {
#endif
#include <windows.h>
#include <stdio.h>
#include "misc.h"

typedef signed char S8;
typedef unsigned char U8;
typedef signed short S16;
typedef unsigned short U16;
typedef signed long S32;
typedef unsigned long U32;
typedef LONG64 S64;
typedef ULONG64 U64;

#ifdef SPEEDY
// On Visual Studio 6, making the internal functions inline makes compiling take forever
#define INTERNAL static _inline
#define INLINE _inline
#else
#define INTERNAL static
#define INLINE
#endif

#define VALID_INSTRUCTION(i) ((i) && !((i)->ErrorOccurred))
#define NEXT_INSTRUCTION(i) ((i)->Address + (i)->Length)
#define DISASM_ARCH_TYPE(dis) ((dis)->ArchType)
#define INS_ARCH_TYPE(ins) DISASM_ARCH_TYPE((ins)->Disassembler)

// NOTE: these should be as big set to the maximum of the supported architectures
#define MAX_PREFIX_LENGTH 15
#define MAX_OPERAND_COUNT 3
#define MAX_INSTRUCTION_LENGTH 25
#define MAX_OPCODE_LENGTH 3
#define MAX_OPCODE_DESCRIPTION 256

/////////////////////////////////////////////////////////////////////
// Code branch
/////////////////////////////////////////////////////////////////////

#define MAX_CODE_REFERENCE_COUNT 3

typedef struct _CODE_BRANCH
{
U64 Addresses[MAX_CODE_REFERENCE_COUNT]; // NULL if multiple to addresses
U32 Count;
U8 IsLoop : 1;
U8 IsCall : 1; // branch if false
U8 IsIndirect : 1; // call/jmp [Address]
U8 AddressOffset: 5;
struct _INSTRUCTION_OPERAND *Operand; // the operand containg the address
} CODE_BRANCH;

/////////////////////////////////////////////////////////////////////
// Data references
/////////////////////////////////////////////////////////////////////

#define MAX_DATA_REFERENCE_COUNT 3

typedef struct _DATA_REFERENCE
{
U64 Addresses[MAX_DATA_REFERENCE_COUNT]; // NULL if multiple to addresses
U32 Count;
ULONG_PTR DataSize;
struct _INSTRUCTION_OPERAND *Operand; // the operand containg the address
} DATA_REFERENCE;

////////////////////////////////////////////////////////////////////
// Instruction
/////////////////////////////////////////////////////////////////////

//
// Instruction types (bits 0-7)
// Instruction groups (bits 8-26)
//
#define ITYPE_EXEC_OFFSET (1<<8)
#define ITYPE_ARITH_OFFSET (1<<9)
#define ITYPE_LOGIC_OFFSET (1<<10)
#define ITYPE_STACK_OFFSET (1<<11)
#define ITYPE_TESTCOND_OFFSET (1<<12)
#define ITYPE_LOAD_OFFSET (1<<13)
#define ITYPE_ARRAY_OFFSET (1<<14)
#define ITYPE_BIT_OFFSET (1<<15)
#define ITYPE_FLAG_OFFSET (1<<16)
#define ITYPE_FPU_OFFSET (1<<17)
#define ITYPE_TRAPS_OFFSET (1<<18)
#define ITYPE_SYSTEM_OFFSET (1<<19)
#define ITYPE_OTHER_OFFSET (1<<20)
#define ITYPE_UNUSED1_OFFSET (1<<21)
#define ITYPE_UNUSED2_OFFSET (1<<22)
#define ITYPE_UNUSED3_OFFSET (1<<23)
#define ITYPE_UNUSED4_OFFSET (1<<24)
#define ITYPE_UNUSED5_OFFSET (1<<25)
#define ITYPE_UNUSED6_OFFSET (1<<26)
#define ITYPE_EXT_UNUSED1 (1<<27)
#define ITYPE_EXT_UNUSED2 (1<<28)
#define ITYPE_EXT_UNUSED3 (1<<29)
#define ITYPE_EXT_UNUSED4 (1<<30)
#define ITYPE_EXT_UNUSED5 (1<<31)

//
// X86-specific flags (bits 27-31)
//

#define ITYPE_EXT_64 ITYPE_EXT_UNUSED1 // Use index 1 if in 64-bit mode and 0 otherwise
#define ITYPE_EXT_MODRM ITYPE_EXT_UNUSED2 // ModRM byte may extend the opcode
#define ITYPE_EXT_SUFFIX ITYPE_EXT_UNUSED3 // byte after ModRM/SIB/displacement is the third opcode
#define ITYPE_EXT_PREFIX ITYPE_EXT_UNUSED4 // prefix
#define ITYPE_EXT_FPU ITYPE_EXT_UNUSED5 // FPU instructions require special handling

#define ITYPE_3DNOW_OFFSET ITYPE_UNUSED1_OFFSET
#define ITYPE_MMX_OFFSET ITYPE_UNUSED2_OFFSET
#define ITYPE_SSE_OFFSET ITYPE_UNUSED3_OFFSET
#define ITYPE_SSE2_OFFSET ITYPE_UNUSED4_OFFSET
#define ITYPE_SSE3_OFFSET ITYPE_UNUSED5_OFFSET

//
// Instruction types
//

#define ITYPE_TYPE_MASK 0x7FFFFFFF
#define ITYPE_GROUP_MASK 0x7FFFFF00

typedef enum _INSTRUCTION_TYPE
{
// ITYPE_EXEC group
ITYPE_EXEC = ITYPE_EXEC_OFFSET,
ITYPE_BRANCH,
ITYPE_BRANCHCC, // conditional (not necessarily just flags)
ITYPE_CALL,
ITYPE_CALLCC, // conditional (not necessarily just flags)
ITYPE_RET,
ITYPE_LOOPCC,

// ITYPE_ARITH group
ITYPE_ARITH = ITYPE_ARITH_OFFSET,
ITYPE_XCHGADD,
ITYPE_ADD,
ITYPE_SUB,
ITYPE_MUL,
ITYPE_DIV,
ITYPE_INC,
ITYPE_DEC,
ITYPE_SHL,
ITYPE_SHR,
ITYPE_ROL,
ITYPE_ROR,

// ITYPE_LOGIC group
ITYPE_LOGIC=ITYPE_LOGIC_OFFSET,
ITYPE_AND,
ITYPE_OR,
ITYPE_XOR,
ITYPE_NOT,
ITYPE_NEG,

// ITYPE_STACK group
ITYPE_STACK=ITYPE_STACK_OFFSET,
ITYPE_PUSH,
ITYPE_POP,
ITYPE_PUSHA,
ITYPE_POPA,
ITYPE_PUSHF,
ITYPE_POPF,
ITYPE_ENTER,
ITYPE_LEAVE,

// ITYPE_TESTCOND group
ITYPE_TESTCOND=ITYPE_TESTCOND_OFFSET,
ITYPE_TEST,
ITYPE_CMP,

// ITYPE_LOAD group
ITYPE_LOAD=ITYPE_LOAD_OFFSET,
ITYPE_MOV,
ITYPE_MOVCC, // conditional
ITYPE_LEA,
ITYPE_XCHG,
ITYPE_XCHGCC, // conditional

// ITYPE_ARRAY group
ITYPE_ARRAY=ITYPE_ARRAY_OFFSET,
ITYPE_STRCMP,
ITYPE_STRLOAD,
ITYPE_STRMOV,
ITYPE_STRSTOR,
ITYPE_XLAT,

// ITYPE_BIT group
ITYPE_BIT=ITYPE_BIT_OFFSET,
ITYPE_BITTEST,
ITYPE_BITSET,
ITYPE_BITCLR,

// ITYPE_FLAG group
// PF = parify flag
// ZF = zero flag
// OF = overflow flag
// DF = direction flag
// SF = sign flag
ITYPE_FLAG=ITYPE_FLAG_OFFSET,
// clear
ITYPE_CLEARCF,
ITYPE_CLEARZF,
ITYPE_CLEAROF,
ITYPE_CLEARDF,
ITYPE_CLEARSF,
ITYPE_CLEARPF,
// set
ITYPE_SETCF,
ITYPE_SETZF,
ITYPE_SETOF,
ITYPE_SETDF,
ITYPE_SETSF,
ITYPE_SETPF,
// toggle
ITYPE_TOGCF,
ITYPE_TOGZF,
ITYPE_TOGOF,
ITYPE_TOGDF,
ITYPE_TOGSF,
ITYPE_TOGPF,

// ITYPE_FPU group
ITYPE_FPU=ITYPE_FPU_OFFSET,
ITYPE_FADD,
ITYPE_FSUB,
ITYPE_FMUL,
ITYPE_FDIV,
ITYPE_FCOMP,
ITYPE_FEXCH,
ITYPE_FLOAD,
ITYPE_FLOADENV,
ITYPE_FSTORE,
ITYPE_FSTOREENV,
ITYPE_FSAVE,
ITYPE_FRESTORE,
ITYPE_FMOVCC,

ITYPE_UNUSED1=ITYPE_UNUSED1_OFFSET,
ITYPE_UNUSED2=ITYPE_UNUSED2_OFFSET,
ITYPE_UNUSED3=ITYPE_UNUSED3_OFFSET,

// ITYPE_MMX group
ITYPE_MMX=ITYPE_MMX_OFFSET,
ITYPE_MMX_MOV,
ITYPE_MMX_ADD,
ITYPE_MMX_SUB,
ITYPE_MMX_MUL,
ITYPE_MMX_DIV,
ITYPE_MMX_AND,
ITYPE_MMX_OR,
ITYPE_MMX_XOR,
ITYPE_MMX_CMP,

// ITYPE_SSE group
ITYPE_SSE=ITYPE_SSE_OFFSET,
ITYPE_SSE_MOV,
ITYPE_SSE_ADD,
ITYPE_SSE_SUB,
ITYPE_SSE_MUL,
ITYPE_SSE_DIV,
ITYPE_SSE_AND,
ITYPE_SSE_OR,
ITYPE_SSE_XOR,
ITYPE_SSE_CMP,
// ITYPE_SSE2 group
ITYPE_SSE2=ITYPE_SSE2_OFFSET,
ITYPE_SSE2_MOV,
ITYPE_SSE2_ADD,
ITYPE_SSE2_SUB,
ITYPE_SSE2_MUL,
ITYPE_SSE2_DIV,
ITYPE_SSE2_AND,
ITYPE_SSE2_OR,
ITYPE_SSE2_XOR,
ITYPE_SSE2_CMP,

// ITYPE_SSE3 group
ITYPE_SSE3=ITYPE_SSE3_OFFSET,
ITYPE_SSE3_MOV,
ITYPE_SSE3_ADD,
ITYPE_SSE3_SUB,
ITYPE_SSE3_MUL,
ITYPE_SSE3_DIV,
ITYPE_SSE3_AND,
ITYPE_SSE3_OR,
ITYPE_SSE3_XOR,
ITYPE_SSE3_CMP,

// ITYPE_3DNOW group
ITYPE_3DNOW=ITYPE_3DNOW_OFFSET,
ITYPE_3DNOW_ADD,
ITYPE_3DNOW_SUB,
ITYPE_3DNOW_MUL,
ITYPE_3DNOW_DIV,
ITYPE_3DNOW_CMP,
ITYPE_3DNOW_XCHG,

// ITYPE_TRAP
ITYPE_TRAPS=ITYPE_TRAPS_OFFSET,
ITYPE_TRAP, // generate trap
ITYPE_TRAPCC, // conditional trap gen
ITYPE_TRAPRET, // return from trap
ITYPE_BOUNDS, // gen bounds trap
ITYPE_DEBUG, // gen breakpoint trap
ITYPE_TRACE, // gen single step trap
ITYPE_INVALID, // gen invalid instruction
ITYPE_OFLOW, // gen overflow trap

// ITYPE_SYSTEM group
ITYPE_SYSTEM=ITYPE_SYSTEM_OFFSET,
ITYPE_HALT, // halt machine
ITYPE_IN, // input form port
ITYPE_OUT, // output to port
ITYPE_CPUID, // identify cpu
ITYPE_SETIF, // allow interrupts
ITYPE_CLEARIF, // block interrupts
ITYPE_SYSCALL,
ITYPE_SYSCALLRET,

// ITYPE_OTHER group
ITYPE_OTHER = ITYPE_OTHER_OFFSET,
ITYPE_NOP,
ITYPE_BCDCONV, // convert to/from BCD
ITYPE_SZCONV // convert size of operand
} INSTRUCTION_TYPE;

//
// Operand flags
//

// Type = bits 0-6 (these are mutually exclusive -- bits 0-6 will always be a power of 2))
#define OPTYPE_NONE 0x00
#define OPTYPE_IMM 0x01 // immediate value
#define OPTYPE_OFFSET 0x02 // relative offset
#define OPTYPE_FLOAT 0x03 // floating point
#define OPTYPE_BCD 0x04
#define OPTYPE_STRING 0x05
#define OPTYPE_SPECIAL 0x06
#define OPTYPE_MASK 0x7F

// Flags = bits 7-23 (these can be combinations)
// These are used in the X86 opcode table
#define OP_REG (1<<7) // 0x80
#define OP_SIGNED (1<<8)
#define OP_SYS (1<<9) // parameter is an index into some system structure
#define OP_CONDR (1<<10)
#define OP_CONDW (1<<11)
#define OP_UNUSED (1<<12)
#define OP_SRC (1<<13) // operand is source operand
#define OP_DST (1<<14) // operand is destination operand
#define OP_EXEC (1<<15) // operand is executed

#define OP_CONDE OP_CONDR
#define OP_COND_EXEC (OP_CONDE|OP_EXEC) // executed only if the pre-conditions are met
#define OP_COND_SRC (OP_CONDR|OP_SRC) // set only if pre-conditions are met
#define OP_COND_DST (OP_CONDW|OP_DST) // set only if pre-conditions are met
#define OP_COND (OP_CONDR|OP_CONDW)

// Bits 16-31 are available for use outside of the opcode table, but they can only
// be used in INSTRUCTION_OPERAND.Flags, they may conflit with the architecture specific
// operands. For example, bits 16-31 are used in X86 for AMODE_* and OPTYPE_*
#define OP_ADDRESS (1<<16)
#define OP_LOCAL (1<<17)
#define OP_PARAM (1<<18)
#define OP_GLOBAL (1<<19)
#define OP_FAR (1<<20)
#define OP_IPREL (1<<21)

//
// X86-specific flags (bits 27-31)
//
#define OP_MSR (OP_SYS|OP_UNUSED)

//
// Other architecture flags
//
#define OP_DELAY OP_UNUSED // delayed instruction (e.g., delayed branch that executes after the next instruction)

/////////////////////////////////////////////////////////////////////
// Architectures
/////////////////////////////////////////////////////////////////////

typedef enum _ARCHITECTURE_TYPE
{
ARCH_UNKNOWN=0,
// x86-based
ARCH_X86, // 32-bit x86
ARCH_X86_16, // 16-bit x86
ARCH_X64, // AMD64 and Intel EMD64
// everything else
ARCH_ALPHA,
ARCH_ARM,
ARCH_DOTNET,
ARCH_EFI,
ARCH_IA64,
ARCH_M68K,
ARCH_MIPS,
ARCH_PPC,
ARCH_SH3,
ARCH_SH4,
ARCH_SPARC,
ARCH_THUMB

} ARCHITECTURE_TYPE;

typedef BOOL (*INIT_INSTRUCTION)(struct _INSTRUCTION *Instruction);
typedef void (*DUMP_INSTRUCTION)(struct _INSTRUCTION *Instruction, BOOL ShowBytes, BOOL Verbose);
typedef BOOL (*GET_INSTRUCTION)(struct _INSTRUCTION *Instruction, U8 *Address, U32 Flags);
typedef U8 *(*FIND_FUNCTION_BY_PROLOGUE)(struct _INSTRUCTION *Instruction, U8 *StartAddress, U8 *EndAddress, U32 Flags);

typedef struct _ARCHITECTURE_FORMAT_FUNCTIONS
{
INIT_INSTRUCTION InitInstruction;
DUMP_INSTRUCTION DumpInstruction;
GET_INSTRUCTION GetInstruction;
FIND_FUNCTION_BY_PROLOGUE FindFunctionByPrologue;
} ARCHITECTURE_FORMAT_FUNCTIONS;

typedef struct _ARCHITECTURE_FORMAT
{
ARCHITECTURE_TYPE Type;
ARCHITECTURE_FORMAT_FUNCTIONS *Functions;
} ARCHITECTURE_FORMAT;

#define DISASSEMBLER_INITIALIZED 0x1234566F
#define INSTRUCTION_INITIALIZED 0x1234567F

#include "disasm_x86.h"

typedef struct DECLSPEC_ALIGN(16) _S128
{
U64 Low;
S64 High;
} S128;
typedef struct DECLSPEC_ALIGN(16) _U128
{
U64 Low;
U64 High;
} U128;

typedef struct _INSTRUCTION_OPERAND
{
U32 Flags;
U8 Type : 6;
U8 Unused : 2;
U16 Length;

// If non-NULL, this indicates the target address of the instruction (e.g., a branch or
// a displacement with no base register). However, this address is only reliable if the
// image is mapped correctly (e.g., the executable is mapped as an image and fixups have
// been applied if it is not at its preferred image base).
//
// If disassembling a 16-bit DOS application, TargetAddress is in the context of
// X86Instruction->Segment. For example, if TargetAddress is the address of a code branch,
// it is in the CS segment (unless X86Instruction->HasSegmentOverridePrefix is set). If
// TargetAddress is a data pointer, it is in the DS segment (unless
// X86Instruction->HasSegmentOverridePrefix is set)
U64 TargetAddress;
U32 Register;

union
{
// All 8/16/32-bit operands are extended to 64-bits automatically
// If you want to downcast, check whether Flags & OP_SIGNED is set
// Like this:
// U32 GetOperand32(OPERAND *Operand)
// {
// if (Operand->Flags & OP_SIGNED) return (S32)Operand->Value_S64;
// else return (U32)Operand->Value_U64;
//}
U64 Value_U64;
S64 Value_S64;
U128 Value_U128;
U128 Float128;
U8 Float80[80];
U8 BCD[10];
};
} INSTRUCTION_OPERAND;

typedef struct _INSTRUCTION
{
U32 Initialized;
struct _DISASSEMBLER *Disassembler;

char String[MAX_OPCODE_DESCRIPTION];
U8 StringIndex;
U64 VirtualAddressDelta;

U32 Groups; // ITYPE_EXEC, ITYPE_ARITH, etc. -- NOTE groups can be OR'd together
INSTRUCTION_TYPE Type; // ITYPE_ADD, ITYPE_RET, etc. -- NOTE there is only one possible type

U8 *Address;
U8 *OpcodeAddress;
U32 Length;

U8 Prefixes[MAX_PREFIX_LENGTH];
U32 PrefixCount;

U8 LastOpcode; // last byte of opcode
U8 OpcodeBytes[MAX_OPCODE_LENGTH];
U32 OpcodeLength; // excludes any operands and prefixes

INSTRUCTION_OPERAND Operands[MAX_OPERAND_COUNT];
U32 OperandCount;

X86_INSTRUCTION X86;

DATA_REFERENCE DataSrc;
DATA_REFERENCE DataDst;
CODE_BRANCH CodeBranch;

// Direction depends on which direction the stack grows
// For example, on x86 a push results in StackChange < 0 since the stack grows down
// This is only relevant if (Group & ITYPE_STACK) is true
//
// If Groups & ITYPE_STACK is set but StackChange = 0, it means that the change
// couldn't be determined (non-constant)
LONG StackChange;

// Used to assist in debugging
// If set, the current instruction is doing something that requires special handling
// For example, popf can cause tracing to be disabled

U8 StringAligned : 1; // internal only
U8 NeedsEmulation : 1; // instruction does something that re
U8 Repeat : 1; // instruction repeats until some condition is met (e.g., REP prefix on X86)
U8 ErrorOccurred : 1; // set if instruction is invalid
U8 AnomalyOccurred : 1; // set if instruction is anomalous
U8 LastInstruction : 1; // tells the iterator callback it is the last instruction
U8 CodeBlockFirst: 1;
U8 CodeBlockLast : 1;
} INSTRUCTION;

typedef struct _DISASSEMBLER
{
U32 Initialized;
ARCHITECTURE_TYPE ArchType;
ARCHITECTURE_FORMAT_FUNCTIONS *Functions;
INSTRUCTION Instruction;
U32 Stage1Count; // GetInstruction called
U32 Stage2Count; // Opcode fully decoded
U32 Stage3CountNoDecode; // made it through all checks when DISASM_DECODE is not set
U32 Stage3CountWithDecode; // made it through all checks when DISASM_DECODE is set
} DISASSEMBLER;

#define DISASM_DISASSEMBLE (1<<1)
#define DISASM_DECODE (1<<2)
#define DISASM_SUPPRESSERRORS (1<<3)
#define DISASM_SHOWFLAGS (1<<4)
#define DISASM_ALIGNOUTPUT (1<<5)
#define DISASM_DISASSEMBLE_MASK (DISASM_ALIGNOUTPUT|DISASM_SHOWBYTES|DISASM_DISASSEMBLE)

BOOL InitDisassembler(DISASSEMBLER *Disassembler, ARCHITECTURE_TYPE Architecture);
void CloseDisassembler(DISASSEMBLER *Disassembler);
INSTRUCTION *GetInstruction(DISASSEMBLER *Disassembler, U64 VirtualAddress, U8 *Address, U32 Flags);

#ifdef __cplusplus
}
#endif
#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 @@
// Copyright (C) 2004, Matt Conover (mconover@gmail.com)
#ifndef X86_DISASM_H
#define X86_DISASM_H
#ifdef __cplusplus
extern "C" {
#endif

// NOTE: the processor may actually accept less than this amount (officially 15)
// #define AMD64_MAX_INSTRUCTION_LEN 15 // theoretical max 25=5+2+1+1+8+8
#define AMD64_MAX_PREFIX_LENGTH 5 // 4 legacy + 1 rex
#define AMD64_MAX_ADDRESS_LENGTH 18 // modrm + sib + 8 byte displacement + 8 byte immediate value

// NOTE: the processor may actually accept less than this amount (officially 15)
#define X86_MAX_INSTRUCTION_LEN 15 // theoretical 16=4+2+1+1+4+4
#define X86_MAX_PREFIX_LENGTH 4
#define X86_MAX_OPCODE_LENGTH 3 // third byte is either a suffix or prefix
#define X86_MAX_ADDRESS_LENGTH 10 // modrm + sib + 4 byte displacement + 4 byte immediate value
#define X86_MAX_OPERANDS 3

#define X86_PREFIX(a) ((a)->MnemonicFlags == ITYPE_EXT_PREFIX)
#define X86_SPECIAL_EXTENSION(a) ((a)->MnemonicFlags & (ITYPE_EXT_MODRM|ITYPE_EXT_FPU|ITYPE_EXT_SUFFIX|ITYPE_EXT_64))
#define X86_EXTENDED_OPCODE(a) ((a)->Table)
#define X86_INVALID(a) (!(a)->MnemonicFlags && !(a)->Table)
#define X86_OPERAND_COUNT(a) ((a)->OperandFlags[0] ? ((a)->OperandFlags[1] ? ((a)->OperandFlags[2] ? 3 : 2) : 1) : 0)
#define X86_GET_CATEGORY(p) ((p)->MnemonicFlags & ITYPE_GROUP_MASK)
#define X86_GET_TYPE(p) ((p)->MnemonicFlags & ITYPE_TYPE_MASK)

// Various instructions being specially decoded
#define X86_TWO_BYTE_OPCODE 0x0f
#define PREFIX_SEGMENT_OVERRIDE_ES 0x26
#define PREFIX_SEGMENT_OVERRIDE_CS 0x2e
#define PREFIX_BRANCH_NOT_TAKEN 0x2e // used only with conditional jumps
#define PREFIX_SEGMENT_OVERRIDE_SS 0x36
#define PREFIX_SEGMENT_OVERRIDE_DS 0x3e
#define PREFIX_BRANCH_TAKEN 0x3e // used only with conditional jumps
#define PREFIX_SEGMENT_OVERRIDE_FS 0x64
#define PREFIX_SEGMENT_OVERRIDE_GS 0x65
#define PREFIX_OPERAND_SIZE 0x66
#define PREFIX_ADDRESS_SIZE 0x67
#define PREFIX_LOCK 0xf0
#define PREFIX_REPNE 0xf2
#define PREFIX_REP 0xf3

//////////////////////////////////////////////////////////////////
// Implicit operand handling
//////////////////////////////////////////////////////////////////

#define X86_AMODE_MASK 0x00FF0000 // bits 16-23 (AMODE_*)
#define X86_OPFLAGS_MASK 0x0000FF80 // bits 7-15 (OPTYPE_*)
#define X86_OPTYPE_MASK 0xFF0000FF // bits 0-7 (OPTYPE_* below + OP_REG) and 24-31 (OPTYPE_* above)

#define OPTYPE_0 0x01
#define OPTYPE_1 0x02
#define OPTYPE_FF 0x03
//...
#define OPTYPE_CS 0x10
#define OPTYPE_DS 0x11
#define OPTYPE_ES 0x12
#define OPTYPE_FS 0x13
#define OPTYPE_GS 0x14
#define OPTYPE_SS 0x15
#define OPTYPE_CR0 0x16
#define OPTYPE_TSC 0x17 // time stamp counter
//...
#define OPTYPE_FLAGS 0x20
#define OPTYPE_xFLAGS 0x21 // RFLAGS/EFLAGS (depending on operand size)
#define OPTYPE_xCX_HI_xBX_LO 0x22 // represented by 2 registers CX:BX or ECX:EBX (depending on operand size)
#define OPTYPE_xDX_HI_xAX_LO 0x23 // DX:AX or EDX:EAX (depending on operand size)
#define OPTYPE_EDX_HI_EAX_LO 0x24 // DX:AX or EDX:EAX (depending on operand size)
#define OPTYPE_EDX_ECX_EBX_EAX 0x25 // all registers are set
//...
#define OPTYPE_STx 0x30
#define OPTYPE_ST0 0x31
#define OPTYPE_ST1 0x32
#define OPTYPE_FPU_STATUS 0x33
#define OPTYPE_FPU_CONTROL 0x34
#define OPTYPE_FPU_TAG 0x35
#define OPTYPE_FLDZ 0x36 // 0
#define OPTYPE_FLD1 0x37 // 1
#define OPTYPE_FLDPI 0x38 // pi
#define OPTYPE_FLDL2T 0x39 // lg 10
#define OPTYPE_FLDL2E 0x3A // lg e
#define OPTYPE_FLDLG2 0x3B // log_10 2
#define OPTYPE_FLDLN2 0x3C // log_e 2
//...
#define OPTYPE_CS_MSR 0x40
#define OPTYPE_EIP_MSR 0x41
#define OPTYPE_ESP_MSR 0x42
#define OPTYPE_KERNELBASE_MSR 0x43
#define OPTYPE_FMASK_MSR 0x44
#define OPTYPE_STAR_MSR 0x45
#define OPTYPE_CSTAR_MSR 0x46 // 32-bit mode
#define OPTYPE_LSTAR_MSR 0x47 // 64-bit mode


// NOTE: OPTYPES >= 0x80 reserved for registers (OP_REG+XX)
#define OPTYPE_REG_AL OP_REG+0x01
#define OPTYPE_REG_CL OP_REG+0x02
#define OPTYPE_REG_AH OP_REG+0x03
#define OPTYPE_REG_AX OP_REG+0x04
#define OPTYPE_REG_DX OP_REG+0x05
#define OPTYPE_REG_ECX OP_REG+0x06
#define OPTYPE_REG8 OP_REG+0x07

// If address size is 2, use BP
// If address size is 4, use EBP
// If address size is 8, use RBP
#define OPTYPE_REG_xBP OP_REG+0x08

// If address size is 2, use BP
// If address size is 4, use EBP
// If address size is 8, use RBP
#define OPTYPE_REG_xSP OP_REG+0x09

// If operand size is 2, take 8-bit register
// If operand size is 4, take 16-bit register
// If operand size is 8, take 32-bit register
#define OPTYPE_REG_xAX_SMALL OP_REG+0x0a