diff options
author | Tsuda Kageyu <tsuda.kageyu@gmail.com> | 2016-12-31 15:48:20 +0300 |
---|---|---|
committer | Tsuda Kageyu <tsuda.kageyu@gmail.com> | 2016-12-31 15:48:20 +0300 |
commit | bbadef6c0b1759315b96aab065d5d99375168802 (patch) | |
tree | 632903e5e7296fd548230e8a67ae19433af400ca | |
parent | cc019757aa6848c59aa58685191b6118f647ecfd (diff) | |
parent | fea705c5e545c1ddd1c791d28c19db82121b9ec9 (diff) |
Merge branch 'master' of https://github.com/TsudaKageyu/minhook
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | build/VC15/MinHook.vcxproj | 10 | ||||
-rw-r--r-- | build/VC15/libMinHook.vcxproj | 10 | ||||
-rw-r--r-- | include/MinHook.h | 2 | ||||
-rw-r--r-- | src/buffer.c | 10 | ||||
-rw-r--r-- | src/buffer.h | 2 | ||||
-rw-r--r-- | src/hde/hde32.c | 4 | ||||
-rw-r--r-- | src/hde/hde64.c | 4 | ||||
-rw-r--r-- | src/hook.c | 8 | ||||
-rw-r--r-- | src/trampoline.c | 20 | ||||
-rw-r--r-- | src/trampoline.h | 2 |
11 files changed, 43 insertions, 32 deletions
@@ -1,5 +1,7 @@ # MinHook +[![License](https://img.shields.io/badge/License-BSD%202--Clause-orange.svg)](https://opensource.org/licenses/BSD-2-Clause) + The Minimalistic x86/x64 API Hooking Library for Windows http://www.codeproject.com/KB/winsdk/LibMinHook.aspx @@ -14,6 +16,7 @@ I need some funds to continue developing this library. All contributions gratefu - ####v1.3.3 - ?? Jan 2017 (Probably 7 or 8) * Added a helper function ```MH_CreateHookApiEx```. (Thanks to asm256) + * Support Visual Studio 2017 RC. - ####v1.3.2.1 - 9 Nov 2015 (Nuget package only) * Fixed an insufficient support for Visual Studio 2015. diff --git a/build/VC15/MinHook.vcxproj b/build/VC15/MinHook.vcxproj index d5ecda2..1d51833 100644 --- a/build/VC15/MinHook.vcxproj +++ b/build/VC15/MinHook.vcxproj @@ -28,23 +28,23 @@ <ConfigurationType>DynamicLibrary</ConfigurationType> <CharacterSet>Unicode</CharacterSet> <WholeProgramOptimization>true</WholeProgramOptimization> - <PlatformToolset>v140_xp</PlatformToolset> + <PlatformToolset>v141_xp</PlatformToolset> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <ConfigurationType>DynamicLibrary</ConfigurationType> <CharacterSet>Unicode</CharacterSet> - <PlatformToolset>v140_xp</PlatformToolset> + <PlatformToolset>v141_xp</PlatformToolset> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <ConfigurationType>DynamicLibrary</ConfigurationType> <CharacterSet>Unicode</CharacterSet> <WholeProgramOptimization>true</WholeProgramOptimization> - <PlatformToolset>v140_xp</PlatformToolset> + <PlatformToolset>v141_xp</PlatformToolset> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <ConfigurationType>DynamicLibrary</ConfigurationType> <CharacterSet>Unicode</CharacterSet> - <PlatformToolset>v140_xp</PlatformToolset> + <PlatformToolset>v141_xp</PlatformToolset> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <ImportGroup Label="ExtensionSettings"> @@ -186,4 +186,4 @@ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> -</Project>
\ No newline at end of file +</Project> diff --git a/build/VC15/libMinHook.vcxproj b/build/VC15/libMinHook.vcxproj index 263b811..0d4352e 100644 --- a/build/VC15/libMinHook.vcxproj +++ b/build/VC15/libMinHook.vcxproj @@ -28,23 +28,23 @@ <ConfigurationType>StaticLibrary</ConfigurationType> <CharacterSet>Unicode</CharacterSet> <WholeProgramOptimization>true</WholeProgramOptimization> - <PlatformToolset>v140_xp</PlatformToolset> + <PlatformToolset>v141_xp</PlatformToolset> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <ConfigurationType>StaticLibrary</ConfigurationType> <CharacterSet>Unicode</CharacterSet> - <PlatformToolset>v140_xp</PlatformToolset> + <PlatformToolset>v141_xp</PlatformToolset> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <ConfigurationType>StaticLibrary</ConfigurationType> <CharacterSet>Unicode</CharacterSet> <WholeProgramOptimization>true</WholeProgramOptimization> - <PlatformToolset>v140_xp</PlatformToolset> + <PlatformToolset>v141_xp</PlatformToolset> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> <ConfigurationType>StaticLibrary</ConfigurationType> <CharacterSet>Unicode</CharacterSet> - <PlatformToolset>v140_xp</PlatformToolset> + <PlatformToolset>v141_xp</PlatformToolset> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <ImportGroup Label="ExtensionSettings"> @@ -171,4 +171,4 @@ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> -</Project>
\ No newline at end of file +</Project> diff --git a/include/MinHook.h b/include/MinHook.h index 6ab9e45..6b410f3 100644 --- a/include/MinHook.h +++ b/include/MinHook.h @@ -28,7 +28,7 @@ #pragma once -#if !(defined _M_IX86) && !(defined _M_X64) +#if !(defined _M_IX86) && !(defined _M_X64) && !(defined __i386__) && !(defined __x86_64__) #error MinHook supports only x86 and x64 systems. #endif diff --git a/src/buffer.c b/src/buffer.c index 45b63aa..db3f92a 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -85,7 +85,7 @@ VOID UninitializeBuffer(VOID) } //------------------------------------------------------------------------- -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) static LPVOID FindPrevFreeRegion(LPVOID pAddress, LPVOID pMinAddr, DWORD dwAllocationGranularity) { ULONG_PTR tryAddr = (ULONG_PTR)pAddress; @@ -116,7 +116,7 @@ static LPVOID FindPrevFreeRegion(LPVOID pAddress, LPVOID pMinAddr, DWORD dwAlloc #endif //------------------------------------------------------------------------- -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) static LPVOID FindNextFreeRegion(LPVOID pAddress, LPVOID pMaxAddr, DWORD dwAllocationGranularity) { ULONG_PTR tryAddr = (ULONG_PTR)pAddress; @@ -151,7 +151,7 @@ static LPVOID FindNextFreeRegion(LPVOID pAddress, LPVOID pMaxAddr, DWORD dwAlloc static PMEMORY_BLOCK GetMemoryBlock(LPVOID pOrigin) { PMEMORY_BLOCK pBlock; -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) ULONG_PTR minAddr; ULONG_PTR maxAddr; @@ -174,7 +174,7 @@ static PMEMORY_BLOCK GetMemoryBlock(LPVOID pOrigin) // Look the registered blocks for a reachable one. for (pBlock = g_pMemoryBlocks; pBlock != NULL; pBlock = pBlock->pNext) { -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) // Ignore the blocks too far. if ((ULONG_PTR)pBlock < minAddr || (ULONG_PTR)pBlock >= maxAddr) continue; @@ -184,7 +184,7 @@ static PMEMORY_BLOCK GetMemoryBlock(LPVOID pOrigin) return pBlock; } -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) // Alloc a new block above if not found. { LPVOID pAlloc = pOrigin; diff --git a/src/buffer.h b/src/buffer.h index f3e9acc..8961b74 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -29,7 +29,7 @@ #pragma once // Size of each memory slot. -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) #define MEMORY_SLOT_SIZE 64 #else #define MEMORY_SLOT_SIZE 32 diff --git a/src/hde/hde32.c b/src/hde/hde32.c index c3c62e8..08fa25b 100644 --- a/src/hde/hde32.c +++ b/src/hde/hde32.c @@ -5,6 +5,8 @@ * */ +#if defined(_M_IX86) || defined(__i386__) + #include "hde32.h" #include "table32.h" @@ -320,3 +322,5 @@ unsigned int hde32_disasm(const void *code, hde32s *hs) return (unsigned int)hs->len; } + +#endif // defined(_M_IX86) || defined(__i386__) diff --git a/src/hde/hde64.c b/src/hde/hde64.c index 72f9517..c23e2fc 100644 --- a/src/hde/hde64.c +++ b/src/hde/hde64.c @@ -5,6 +5,8 @@ * */ +#if defined(_M_X64) || defined(__x86_64__) + #include "hde64.h" #include "table64.h" @@ -331,3 +333,5 @@ unsigned int hde64_disasm(const void *code, hde64s *hs) return (unsigned int)hs->len; } + +#endif // defined(_M_X64) || defined(__x86_64__) @@ -173,7 +173,7 @@ static DWORD_PTR FindOldIP(PHOOK_ENTRY pHook, DWORD_PTR ip) return (DWORD_PTR)pHook->pTarget + pHook->oldIPs[i]; } -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) // Check relay function. if (ip == (DWORD_PTR)pHook->pDetour) return (DWORD_PTR)pHook->pTarget; @@ -202,7 +202,7 @@ static void ProcessThreadIPs(HANDLE hThread, UINT pos, UINT action) // move IP to the proper address. CONTEXT c; -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) DWORD64 *pIP = &c.Rip; #else DWORD *pIP = &c.Eip; @@ -239,7 +239,7 @@ static void ProcessThreadIPs(HANDLE hThread, UINT pos, UINT action) enable = TRUE; break; - case ACTION_APPLY_QUEUED: + default: // ACTION_APPLY_QUEUED enable = pHook->queueEnable; break; } @@ -559,7 +559,7 @@ MH_STATUS WINAPI MH_CreateHook(LPVOID pTarget, LPVOID pDetour, LPVOID *ppOrigina if (pHook != NULL) { pHook->pTarget = ct.pTarget; -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) pHook->pDetour = ct.pRelay; #else pHook->pDetour = ct.pDetour; diff --git a/src/trampoline.c b/src/trampoline.c index 2e264c1..807b9c9 100644 --- a/src/trampoline.c +++ b/src/trampoline.c @@ -32,7 +32,7 @@ #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0])) #endif -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) #include "./hde/hde64.h" typedef hde64s HDE; #define HDE_DISASM(code, hs) hde64_disasm(code, hs) @@ -46,7 +46,7 @@ #include "buffer.h" // Maximum size of a trampoline function. -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) #define TRAMPOLINE_MAX_SIZE (MEMORY_SLOT_SIZE - sizeof(JMP_ABS)) #else #define TRAMPOLINE_MAX_SIZE MEMORY_SLOT_SIZE @@ -71,7 +71,7 @@ static BOOL IsCodePadding(LPBYTE pInst, UINT size) //------------------------------------------------------------------------- BOOL CreateTrampolineFunction(PTRAMPOLINE ct) { -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) CALL_ABS call = { 0xFF, 0x15, 0x00000002, // FF15 00000002: CALL [RIP+8] 0xEB, 0x08, // EB 08: JMP +10 @@ -105,7 +105,7 @@ BOOL CreateTrampolineFunction(PTRAMPOLINE ct) UINT8 newPos = 0; ULONG_PTR jmpDest = 0; // Destination address of an internal jump. BOOL finished = FALSE; // Is the function completed? -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) UINT8 instBuf[16]; #endif @@ -129,7 +129,7 @@ BOOL CreateTrampolineFunction(PTRAMPOLINE ct) { // The trampoline function is long enough. // Complete the function with the jump to the target function. -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) jmp.address = pOldInst; #else jmp.operand = (UINT32)(pOldInst - (pNewInst + sizeof(jmp))); @@ -139,7 +139,7 @@ BOOL CreateTrampolineFunction(PTRAMPOLINE ct) finished = TRUE; } -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) else if ((hs.modrm & 0xC7) == 0x05) { // Instructions using RIP relative addressing. (ModR/M = 00???101B) @@ -169,7 +169,7 @@ BOOL CreateTrampolineFunction(PTRAMPOLINE ct) { // Direct relative CALL ULONG_PTR dest = pOldInst + hs.len + (INT32)hs.imm.imm32; -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) call.address = dest; #else call.operand = (UINT32)(dest - (pNewInst + sizeof(call))); @@ -196,7 +196,7 @@ BOOL CreateTrampolineFunction(PTRAMPOLINE ct) } else { -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) jmp.address = dest; #else jmp.operand = (UINT32)(dest - (pNewInst + sizeof(jmp))); @@ -236,7 +236,7 @@ BOOL CreateTrampolineFunction(PTRAMPOLINE ct) else { UINT8 cond = ((hs.opcode != 0x0F ? hs.opcode : hs.opcode2) & 0x0F); -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) // Invert the condition in x64 mode to simplify the conditional jump logic. jcc.opcode = 0x71 ^ cond; jcc.address = dest; @@ -304,7 +304,7 @@ BOOL CreateTrampolineFunction(PTRAMPOLINE ct) ct->patchAbove = TRUE; } -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) // Create a relay function. jmp.address = (ULONG_PTR)ct->pDetour; diff --git a/src/trampoline.h b/src/trampoline.h index 0b16d6c..e0038da 100644 --- a/src/trampoline.h +++ b/src/trampoline.h @@ -93,7 +93,7 @@ typedef struct _TRAMPOLINE LPVOID pDetour; // [In] Address of the detour function. LPVOID pTrampoline; // [In] Buffer address for the trampoline and relay function. -#ifdef _M_X64 +#if defined(_M_X64) || defined(__x86_64__) LPVOID pRelay; // [Out] Address of the relay function. #endif BOOL patchAbove; // [Out] Should use the hot patch area? |