diff --git a/MinHook/.gitignore b/MinHook/.gitignore index bbfc50d..33a07e5 100644 --- a/MinHook/.gitignore +++ b/MinHook/.gitignore @@ -30,3 +30,14 @@ obj/ [Dd]ebug*/ [Rr]elease*/ Ankh.NoLoad +*.VC.db + +#GCC files +*.o +*.d +*.res +*.dll +*.a + +#Visual Studio Code files +.vscode/ diff --git a/MinHook/LICENSE.txt b/MinHook/LICENSE.txt index e4f9a7a..74dea27 100644 --- a/MinHook/LICENSE.txt +++ b/MinHook/LICENSE.txt @@ -1,5 +1,5 @@ MinHook - The Minimalistic API Hooking Library for x64/x86 -Copyright (C) 2009-2015 Tsuda Kageyu. +Copyright (C) 2009-2017 Tsuda Kageyu. All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/MinHook/README.md b/MinHook/README.md index f8f7b35..9b412b1 100644 --- a/MinHook/README.md +++ b/MinHook/README.md @@ -1,27 +1,50 @@ # 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 ### Donation please -Need some funds to continue developing this library. All contributions gratefully accepted. +I need some funds to continue developing this library. All contributions gratefully accepted. Click here to lend your support to: MinHook - Help me continue to develop this library and make a donation at pledgie.com ! ### Version history +- ####v1.3.3 - 8 Jan 2017 + * 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. + +- ####v1.3.2 - 1 Nov 2015 + * Support Visual Studio 2015. + * Support MinGW. + +- ####v1.3.2-beta3 - 21 Jul 2015 (Nuget package only) + * Support MinGW. (Experimental) + +- ####v1.3.2-beta2 - 18 May 2015 + * Fixed some subtle bugs. (Thanks to RaMMicHaeL) + * Added a helper function ```MH_StatusToString```. (Thanks to Jan Klass) + - ####v1.3.2-beta - 12 May 2015 * Fixed a possible thread deadlock in x64 mode. (Thanks to Aleh Kazakevich) * Reduced the footprint a little more. * Support Visual Studio 2015 RC. (Experimental) +- ####v1.3.1.1 - 7 Apr 2015 (Nuget package only) + * Support for WDK8.0 and 8.1. + - ####v1.3.1 - 19 Mar 2015 * No major changes from v1.3.1-beta. - ####v1.3.1-beta - 11 Mar 2015 - * Added the ```MH_CreateHookApi``` function. + * Added a helper function ```MH_CreateHookApi```. (Thanks to uniskz). * Fixed a false memory leak reported by some tools. * Fixed a degradated compatibility issue. diff --git a/MinHook/build/MinGW/Makefile b/MinHook/build/MinGW/Makefile new file mode 100644 index 0000000..cc16725 --- /dev/null +++ b/MinHook/build/MinGW/Makefile @@ -0,0 +1,33 @@ +WINDRES:=$(CROSS_PREFIX)windres +DLLTOOL:=$(CROSS_PREFIX)dlltool +AR:=$(CROSS_PREFIX)ar +CC:=$(CROSS_PREFIX)gcc +CCLD:=$(CC) +SRCS:=$(wildcard src/*.c src/hde/*.c) +OBJS:=$(SRCS:%.c=%.o) +DEPS:=$(SRCS:%.c=%.d) +INCS:=-Isrc -Iinclude +CFLAGS:=-masm=intel -Wall -Werror -std=c11 +LDFLAGS:=-Wl,-enable-stdcall-fixup -s -static-libgcc + +all: MinHook.dll libMinHook.dll.a libMinHook.a + +-include $(DEPS) + +libMinHook.a: $(OBJS) + $(AR) r $@ $^ +libMinHook.dll.a: MinHook.dll dll_resources/MinHook.def + $(DLLTOOL) --dllname MinHook.dll --def dll_resources/MinHook.def --output-lib $@ +MinHook.dll: $(OBJS) dll_resources/MinHook.res dll_resources/MinHook.def + $(CCLD) -o $@ -shared $(LDFLAGS) $^ + +.rc.res: + $(WINDRES) -o $@ --input-format=rc --output-format=coff $< +.c.o: + $(CC) -o $@ -c -MMD -MP $(INCS) $(CFLAGS) $< + +clean: + rm -f $(OBJS) $(DEPS) MinHook.dll libMinHook.dll.a libMinHook.a dll_resources/MinHook.res + +.PHONY: clean +.SUFFIXES: .rc .res diff --git a/MinHook/build/MinGW/make.bat b/MinHook/build/MinGW/make.bat new file mode 100644 index 0000000..7671878 --- /dev/null +++ b/MinHook/build/MinGW/make.bat @@ -0,0 +1 @@ +windres -i ../../dll_resources/MinHook.rc -o MinHook_rc.o && dllwrap --driver-name g++ -o MinHook.dll -masm=intel --def ../../dll_resources/MinHook.def -Wl,-enable-stdcall-fixup -Wall MinHook_rc.o ../../src/*.c ../../src/HDE/*.c -I../../include -I../../src -Werror -std=c++11 -s -static-libgcc -static-libstdc++|| pause \ No newline at end of file diff --git a/MinHook/build/VC10/libMinHook.vcxproj b/MinHook/build/VC10/libMinHook.vcxproj index 77673e9..589ff9a 100644 --- a/MinHook/build/VC10/libMinHook.vcxproj +++ b/MinHook/build/VC10/libMinHook.vcxproj @@ -77,7 +77,7 @@ Disabled %(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;STRICT;%(PreprocessorDefinitions) false EnableFastChecks MultiThreadedDebug @@ -95,7 +95,7 @@ Disabled %(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;STRICT;%(PreprocessorDefinitions) false EnableFastChecks MultiThreadedDebug @@ -111,7 +111,7 @@ MinSpace true %(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;STRICT;%(PreprocessorDefinitions) false MultiThreaded true @@ -131,7 +131,7 @@ MinSpace true %(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;STRICT;%(PreprocessorDefinitions) false MultiThreaded true diff --git a/MinHook/build/VC11/libMinHook.vcxproj b/MinHook/build/VC11/libMinHook.vcxproj index 73e8b2f..1a65499 100644 --- a/MinHook/build/VC11/libMinHook.vcxproj +++ b/MinHook/build/VC11/libMinHook.vcxproj @@ -81,7 +81,7 @@ Disabled %(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;STRICT;%(PreprocessorDefinitions) false EnableFastChecks MultiThreadedDebug @@ -98,7 +98,7 @@ Disabled %(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;STRICT;%(PreprocessorDefinitions) false EnableFastChecks MultiThreadedDebug @@ -112,7 +112,7 @@ MinSpace true %(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;STRICT;%(PreprocessorDefinitions) false MultiThreaded true @@ -132,7 +132,7 @@ MinSpace true %(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;STRICT;%(PreprocessorDefinitions) false MultiThreaded true diff --git a/MinHook/build/VC12/libMinHook.vcxproj b/MinHook/build/VC12/libMinHook.vcxproj index 5674663..6b2a190 100644 --- a/MinHook/build/VC12/libMinHook.vcxproj +++ b/MinHook/build/VC12/libMinHook.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -22,30 +22,29 @@ {F142A341-5EE0-442D-A15F-98AE9B48DBAE} libMinHook Win32Proj - 8.1 StaticLibrary Unicode true - v140 + v120_xp StaticLibrary Unicode - v140 + v120_xp StaticLibrary Unicode true - v140 + v120_xp StaticLibrary Unicode - v140 + v120_xp @@ -65,11 +64,13 @@ <_ProjectFileVersion>10.0.40219.1 - $(ProjectDir)lib\$(Configuration)\ + $(SolutionDir)lib\$(Configuration)\ $(Platform)\$(Configuration)\$(ProjectName)\ - $(ProjectDir)lib\$(Configuration)\ + $(SolutionDir)lib\$(Configuration)\ $(Platform)\$(Configuration)\$(ProjectName)\ - $(ProjectDir)lib\$(Configuration)\ + $(SolutionDir)lib\$(Configuration)\ + $(Platform)\$(Configuration)\$(ProjectName)\ + $(SolutionDir)lib\$(Configuration)\ $(Platform)\$(Configuration)\$(ProjectName)\ $(ProjectName).x86 $(ProjectName).x86 @@ -80,14 +81,13 @@ Disabled %(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;STRICT;%(PreprocessorDefinitions) + false EnableFastChecks - MultiThreadedDebugDLL + MultiThreadedDebug Level3 - NotSet - true - - + None + NoExtensions @@ -98,15 +98,13 @@ Disabled %(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;STRICT;%(PreprocessorDefinitions) + false EnableFastChecks - MultiThreadedDebugDLL + MultiThreadedDebug Level3 None NotSet - true - - @@ -115,16 +113,16 @@ MinSpace true %(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;STRICT;%(PreprocessorDefinitions) + false MultiThreaded true Level3 + None AnySuitable CompileAsC true - NotSet - - + NoExtensions @@ -136,15 +134,14 @@ MinSpace true %(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;STRICT;%(PreprocessorDefinitions) + false MultiThreaded true Level3 None true AnySuitable - - diff --git a/MinHook/build/VC14/libMinHook.vcxproj b/MinHook/build/VC14/libMinHook.vcxproj index 49b98a6..263b811 100644 --- a/MinHook/build/VC14/libMinHook.vcxproj +++ b/MinHook/build/VC14/libMinHook.vcxproj @@ -81,7 +81,7 @@ Disabled %(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;STRICT;%(PreprocessorDefinitions) false EnableFastChecks MultiThreadedDebug @@ -98,7 +98,7 @@ Disabled %(AdditionalIncludeDirectories) - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;STRICT;%(PreprocessorDefinitions) false EnableFastChecks MultiThreadedDebug @@ -113,7 +113,7 @@ MinSpace true %(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;STRICT;%(PreprocessorDefinitions) false MultiThreaded true @@ -134,7 +134,7 @@ MinSpace true %(AdditionalIncludeDirectories) - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;STRICT;%(PreprocessorDefinitions) false MultiThreaded true diff --git a/MinHook/build/VC15/MinHook.vcxproj b/MinHook/build/VC15/MinHook.vcxproj new file mode 100644 index 0000000..1d51833 --- /dev/null +++ b/MinHook/build/VC15/MinHook.vcxproj @@ -0,0 +1,189 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {027FAC75-3FDB-4044-8DD0-BC297BD4C461} + MinHook + Win32Proj + + + + DynamicLibrary + Unicode + true + v141_xp + + + DynamicLibrary + Unicode + v141_xp + + + DynamicLibrary + Unicode + true + v141_xp + + + DynamicLibrary + Unicode + v141_xp + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.40219.1 + $(SolutionDir)bin\$(Configuration)\ + $(Platform)\$(Configuration)\$(ProjectName)\ + true + $(SolutionDir)bin\$(Configuration)\ + $(Platform)\$(Configuration)\$(ProjectName)\ + true + $(SolutionDir)bin\$(Configuration)\ + $(Platform)\$(Configuration)\$(ProjectName)\ + false + $(SolutionDir)bin\$(Configuration)\ + $(Platform)\$(Configuration)\$(ProjectName)\ + false + $(ProjectName).x86 + $(ProjectName).x86 + $(ProjectName).x64 + $(ProjectName).x64 + + + + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;MINHOOK_EXPORTS;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebug + + + Level3 + None + + + $(SolutionDir)..\..\dll_resources\MinHook.def + false + Windows + MachineX86 + $(SolutionDir)lib\$(Configuration)\libMinHook.x86.lib;%(AdditionalDependencies) + + + + + X64 + + + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;MINHOOK_EXPORTS;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebug + + + Level3 + None + + + $(SolutionDir)..\..\dll_resources\MinHook.def + false + Windows + MachineX64 + $(SolutionDir)lib\$(Configuration)\libMinHook.x64.lib;%(AdditionalDependencies) + + + + + MinSpace + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;MINHOOK_EXPORTS;%(PreprocessorDefinitions) + MultiThreaded + true + + + Level3 + None + false + + + $(SolutionDir)..\..\dll_resources\MinHook.def + false + Windows + true + true + MachineX86 + $(SolutionDir)lib\$(Configuration)\libMinHook.x86.lib;%(AdditionalDependencies) + true + .CRT=.text + + + + + X64 + + + MinSpace + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;MINHOOK_EXPORTS;%(PreprocessorDefinitions) + MultiThreaded + true + + + Level3 + None + false + + + $(SolutionDir)..\..\dll_resources\MinHook.def + false + Windows + true + true + MachineX64 + $(SolutionDir)lib\$(Configuration)\libMinHook.x64.lib;%(AdditionalDependencies) + true + .CRT=.text + + + + + + + + + + + + diff --git a/MinHook/build/VC15/MinHookVC15.sln b/MinHook/build/VC15/MinHookVC15.sln new file mode 100644 index 0000000..946dc70 --- /dev/null +++ b/MinHook/build/VC15/MinHookVC15.sln @@ -0,0 +1,41 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.25123.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libMinHook", "libMinHook.vcxproj", "{F142A341-5EE0-442D-A15F-98AE9B48DBAE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MinHook", "MinHook.vcxproj", "{027FAC75-3FDB-4044-8DD0-BC297BD4C461}" + ProjectSection(ProjectDependencies) = postProject + {F142A341-5EE0-442D-A15F-98AE9B48DBAE} = {F142A341-5EE0-442D-A15F-98AE9B48DBAE} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Debug|Win32.ActiveCfg = Debug|Win32 + {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Debug|Win32.Build.0 = Debug|Win32 + {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Debug|x64.ActiveCfg = Debug|x64 + {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Debug|x64.Build.0 = Debug|x64 + {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Release|Win32.ActiveCfg = Release|Win32 + {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Release|Win32.Build.0 = Release|Win32 + {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Release|x64.ActiveCfg = Release|x64 + {F142A341-5EE0-442D-A15F-98AE9B48DBAE}.Release|x64.Build.0 = Release|x64 + {027FAC75-3FDB-4044-8DD0-BC297BD4C461}.Debug|Win32.ActiveCfg = Debug|Win32 + {027FAC75-3FDB-4044-8DD0-BC297BD4C461}.Debug|Win32.Build.0 = Debug|Win32 + {027FAC75-3FDB-4044-8DD0-BC297BD4C461}.Debug|x64.ActiveCfg = Debug|x64 + {027FAC75-3FDB-4044-8DD0-BC297BD4C461}.Debug|x64.Build.0 = Debug|x64 + {027FAC75-3FDB-4044-8DD0-BC297BD4C461}.Release|Win32.ActiveCfg = Release|Win32 + {027FAC75-3FDB-4044-8DD0-BC297BD4C461}.Release|Win32.Build.0 = Release|Win32 + {027FAC75-3FDB-4044-8DD0-BC297BD4C461}.Release|x64.ActiveCfg = Release|x64 + {027FAC75-3FDB-4044-8DD0-BC297BD4C461}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/MinHook/build/VC15/libMinHook.vcxproj b/MinHook/build/VC15/libMinHook.vcxproj new file mode 100644 index 0000000..064a357 --- /dev/null +++ b/MinHook/build/VC15/libMinHook.vcxproj @@ -0,0 +1,173 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {F142A341-5EE0-442D-A15F-98AE9B48DBAE} + libMinHook + Win32Proj + 10.0.16299.0 + + + + StaticLibrary + Unicode + true + v141 + + + StaticLibrary + Unicode + v141 + + + StaticLibrary + Unicode + true + v141 + + + StaticLibrary + Unicode + v141 + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.40219.1 + $(SolutionDir)lib\$(Configuration)\ + $(Platform)\$(Configuration)\$(ProjectName)\ + $(SolutionDir)lib\$(Configuration)\ + $(Platform)\$(Configuration)\$(ProjectName)\ + $(SolutionDir)lib\$(Configuration)\ + $(Platform)\$(Configuration)\$(ProjectName)\ + $(SolutionDir)lib\$(Configuration)\ + $(Platform)\$(Configuration)\$(ProjectName)\ + $(ProjectName).x86 + $(ProjectName).x86 + $(ProjectName).x64 + $(ProjectName).x64 + + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_LIB;STRICT;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebug + Level3 + None + NoExtensions + + + + + + X64 + + + Disabled + %(AdditionalIncludeDirectories) + WIN32;_DEBUG;_LIB;STRICT;%(PreprocessorDefinitions) + false + EnableFastChecks + MultiThreadedDebug + Level3 + None + NotSet + + + + + + MinSpace + true + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_LIB;STRICT;%(PreprocessorDefinitions) + false + true + Level3 + None + AnySuitable + CompileAsC + true + + + + + + X64 + + + MinSpace + true + %(AdditionalIncludeDirectories) + WIN32;NDEBUG;_LIB;STRICT;%(PreprocessorDefinitions) + false + MultiThreaded + true + Level3 + None + true + AnySuitable + + + + + + + true + true + + + true + true + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MinHook/build/VC15/libMinHook.vcxproj.filters b/MinHook/build/VC15/libMinHook.vcxproj.filters new file mode 100644 index 0000000..f2d1d97 --- /dev/null +++ b/MinHook/build/VC15/libMinHook.vcxproj.filters @@ -0,0 +1,55 @@ + + + + + Source Files + + + Source Files + + + Source Files + + + HDE + + + HDE + + + + + Header Files + + + Header Files + + + + HDE + + + HDE + + + HDE + + + HDE + + + HDE + + + + + {9d24b740-be2e-4cfd-b9a4-340a50946ee9} + + + {76381bc7-2863-4cc5-aede-926ec2c506e4} + + + {56ddb326-6179-430d-ae19-e13bfd767bfa} + + + \ No newline at end of file diff --git a/MinHook/build/VC9/libMinHook.vcproj b/MinHook/build/VC9/libMinHook.vcproj index fefb517..68b0c05 100644 --- a/MinHook/build/VC9/libMinHook.vcproj +++ b/MinHook/build/VC9/libMinHook.vcproj @@ -45,7 +45,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="" - PreprocessorDefinitions="WIN32;_DEBUG;_LIB" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;STRICT" MinimalRebuild="false" BasicRuntimeChecks="3" RuntimeLibrary="1" @@ -110,7 +110,7 @@ Optimization="0" WholeProgramOptimization="false" AdditionalIncludeDirectories="" - PreprocessorDefinitions="WIN32;_DEBUG;_LIB" + PreprocessorDefinitions="WIN32;_DEBUG;_LIB;STRICT" MinimalRebuild="false" BasicRuntimeChecks="3" RuntimeLibrary="1" @@ -177,7 +177,7 @@ EnableIntrinsicFunctions="true" WholeProgramOptimization="true" AdditionalIncludeDirectories="" - PreprocessorDefinitions="WIN32;NDEBUG;_LIB" + PreprocessorDefinitions="WIN32;NDEBUG;_LIB;STRICT" MinimalRebuild="false" RuntimeLibrary="0" EnableFunctionLevelLinking="true" @@ -246,7 +246,7 @@ EnableIntrinsicFunctions="true" WholeProgramOptimization="true" AdditionalIncludeDirectories="" - PreprocessorDefinitions="WIN32;NDEBUG;_LIB" + PreprocessorDefinitions="WIN32;NDEBUG;_LIB;STRICT" MinimalRebuild="false" RuntimeLibrary="0" EnableFunctionLevelLinking="true" diff --git a/MinHook/dll_resources/MinHook.def b/MinHook/dll_resources/MinHook.def index 66c80b3..c6af698 100644 --- a/MinHook/dll_resources/MinHook.def +++ b/MinHook/dll_resources/MinHook.def @@ -4,6 +4,7 @@ EXPORTS MH_CreateHook MH_CreateHookApi + MH_CreateHookApiEx MH_RemoveHook MH_EnableHook MH_DisableHook diff --git a/MinHook/dll_resources/MinHook.rc b/MinHook/dll_resources/MinHook.rc index a369bb5..7cbacb7 100644 Binary files a/MinHook/dll_resources/MinHook.rc and b/MinHook/dll_resources/MinHook.rc differ diff --git a/MinHook/include/MinHook.h b/MinHook/include/MinHook.h index aa6763b..15c0a87 100644 --- a/MinHook/include/MinHook.h +++ b/MinHook/include/MinHook.h @@ -1,6 +1,6 @@ /* * MinHook - The Minimalistic API Hooking Library for x64/x86 - * Copyright (C) 2009-2015 Tsuda Kageyu. + * Copyright (C) 2009-2017 Tsuda Kageyu. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,11 +28,11 @@ #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 -#include +#include // MinHook Error Codes. typedef enum MH_STATUS @@ -124,6 +124,23 @@ extern "C" { MH_STATUS WINAPI MH_CreateHookApi( LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal); + // Creates a Hook for the specified API function, in disabled state. + // Parameters: + // pszModule [in] A pointer to the loaded module name which contains the + // target function. + // pszTarget [in] A pointer to the target function name, which will be + // overridden by the detour function. + // pDetour [in] A pointer to the detour function, which will override + // the target function. + // ppOriginal [out] A pointer to the trampoline function, which will be + // used to call the original target function. + // This parameter can be NULL. + // ppTarget [out] A pointer to the target function, which will be used + // with other functions. + // This parameter can be NULL. + MH_STATUS WINAPI MH_CreateHookApiEx( + LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal, LPVOID *ppTarget); + // Removes an already created hook. // Parameters: // pTarget [in] A pointer to the target function. diff --git a/MinHook/src/HDE/hde32.c b/MinHook/src/HDE/hde32.c index 391bd79..08fa25b 100644 --- a/MinHook/src/HDE/hde32.c +++ b/MinHook/src/HDE/hde32.c @@ -5,7 +5,8 @@ * */ -#include +#if defined(_M_IX86) || defined(__i386__) + #include "hde32.h" #include "table32.h" @@ -15,7 +16,11 @@ unsigned int hde32_disasm(const void *code, hde32s *hs) uint8_t *ht = hde32_table, m_mod, m_reg, m_rm, disp_size = 0; // Avoid using memset to reduce the footprint. +#ifndef _MSC_VER + memset((LPBYTE)hs, 0, sizeof(hde32s)); +#else __stosb((LPBYTE)hs, 0, sizeof(hde32s)); +#endif for (x = 16; x; x--) switch (c = *p++) { @@ -317,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/MinHook/src/HDE/hde64.c b/MinHook/src/HDE/hde64.c index 68a5611..c23e2fc 100644 --- a/MinHook/src/HDE/hde64.c +++ b/MinHook/src/HDE/hde64.c @@ -5,7 +5,8 @@ * */ -#include +#if defined(_M_X64) || defined(__x86_64__) + #include "hde64.h" #include "table64.h" @@ -16,7 +17,11 @@ unsigned int hde64_disasm(const void *code, hde64s *hs) uint8_t op64 = 0; // Avoid using memset to reduce the footprint. +#ifndef _MSC_VER + memset((LPBYTE)hs, 0, sizeof(hde64s)); +#else __stosb((LPBYTE)hs, 0, sizeof(hde64s)); +#endif for (x = 16; x; x--) switch (c = *p++) { @@ -328,3 +333,5 @@ unsigned int hde64_disasm(const void *code, hde64s *hs) return (unsigned int)hs->len; } + +#endif // defined(_M_X64) || defined(__x86_64__) diff --git a/MinHook/src/HDE/pstdint.h b/MinHook/src/HDE/pstdint.h index 6f87bd0..84d82a0 100644 --- a/MinHook/src/HDE/pstdint.h +++ b/MinHook/src/HDE/pstdint.h @@ -1,6 +1,6 @@ /* * MinHook - The Minimalistic API Hooking Library for x64/x86 - * Copyright (C) 2009-2015 Tsuda Kageyu. All rights reserved. + * Copyright (C) 2009-2017 Tsuda Kageyu. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,7 +26,7 @@ #pragma once -#include +#include // Integer types for HDE. typedef INT8 int8_t; diff --git a/MinHook/src/buffer.c b/MinHook/src/buffer.c index b3d9306..8f9fbce 100644 --- a/MinHook/src/buffer.c +++ b/MinHook/src/buffer.c @@ -1,6 +1,6 @@ /* * MinHook - The Minimalistic API Hooking Library for x64/x86 - * Copyright (C) 2009-2015 Tsuda Kageyu. + * Copyright (C) 2009-2017 Tsuda Kageyu. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,7 +26,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include "buffer.h" // Size of each memory block. (= page size of VirtualAlloc) @@ -85,12 +85,12 @@ 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; - // Round down to the next allocation granularity. + // Round down to the allocation granularity. tryAddr -= tryAddr % dwAllocationGranularity; // Start from the previous allocation granularity multiply. @@ -99,7 +99,7 @@ static LPVOID FindPrevFreeRegion(LPVOID pAddress, LPVOID pMinAddr, DWORD dwAlloc while (tryAddr >= (ULONG_PTR)pMinAddr) { MEMORY_BASIC_INFORMATION mbi; - if (VirtualQuery((LPVOID)tryAddr, &mbi, sizeof(MEMORY_BASIC_INFORMATION)) == 0) + if (VirtualQuery((LPVOID)tryAddr, &mbi, sizeof(mbi)) == 0) break; if (mbi.State == MEM_FREE) @@ -116,12 +116,12 @@ 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; - // Round down to the next allocation granularity. + // Round down to the allocation granularity. tryAddr -= tryAddr % dwAllocationGranularity; // Start from the next allocation granularity multiply. @@ -130,7 +130,7 @@ static LPVOID FindNextFreeRegion(LPVOID pAddress, LPVOID pMaxAddr, DWORD dwAlloc while (tryAddr <= (ULONG_PTR)pMaxAddr) { MEMORY_BASIC_INFORMATION mbi; - if (VirtualQuery((LPVOID)tryAddr, &mbi, sizeof(MEMORY_BASIC_INFORMATION)) == 0) + if (VirtualQuery((LPVOID)tryAddr, &mbi, sizeof(mbi)) == 0) break; if (mbi.State == MEM_FREE) @@ -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; @@ -161,10 +161,11 @@ static PMEMORY_BLOCK GetMemoryBlock(LPVOID pOrigin) maxAddr = (ULONG_PTR)si.lpMaximumApplicationAddress; // pOrigin ± 512MB - if ((ULONG_PTR)pOrigin > MAX_MEMORY_RANGE) - minAddr = max(minAddr, (ULONG_PTR)pOrigin - MAX_MEMORY_RANGE); + if ((ULONG_PTR)pOrigin > MAX_MEMORY_RANGE && minAddr < (ULONG_PTR)pOrigin - MAX_MEMORY_RANGE) + minAddr = (ULONG_PTR)pOrigin - MAX_MEMORY_RANGE; - maxAddr = min(maxAddr, (ULONG_PTR)pOrigin + MAX_MEMORY_RANGE); + if (maxAddr > (ULONG_PTR)pOrigin + MAX_MEMORY_RANGE) + maxAddr = (ULONG_PTR)pOrigin + MAX_MEMORY_RANGE; // Make room for MEMORY_BLOCK_SIZE bytes. maxAddr -= MEMORY_BLOCK_SIZE - 1; @@ -173,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; @@ -183,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; @@ -275,7 +276,7 @@ VOID FreeBuffer(LPVOID pBuffer) PMEMORY_SLOT pSlot = (PMEMORY_SLOT)pBuffer; #ifdef _DEBUG // Clear the released slot for debugging. - memset(pSlot, 0x00, sizeof(MEMORY_SLOT)); + memset(pSlot, 0x00, sizeof(*pSlot)); #endif // Restore the released slot to the list. pSlot->pNext = pBlock->pFree; @@ -305,7 +306,7 @@ VOID FreeBuffer(LPVOID pBuffer) BOOL IsExecutableAddress(LPVOID pAddress) { MEMORY_BASIC_INFORMATION mi; - VirtualQuery(pAddress, &mi, sizeof(MEMORY_BASIC_INFORMATION)); + VirtualQuery(pAddress, &mi, sizeof(mi)); return (mi.State == MEM_COMMIT && (mi.Protect & PAGE_EXECUTE_FLAGS)); } diff --git a/MinHook/src/buffer.h b/MinHook/src/buffer.h index 99cfebd..204d551 100644 --- a/MinHook/src/buffer.h +++ b/MinHook/src/buffer.h @@ -1,6 +1,6 @@ /* * MinHook - The Minimalistic API Hooking Library for x64/x86 - * Copyright (C) 2009-2015 Tsuda Kageyu. + * Copyright (C) 2009-2017 Tsuda Kageyu. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -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/MinHook/src/hook.c b/MinHook/src/hook.c index f6478a9..ce65e57 100644 --- a/MinHook/src/hook.c +++ b/MinHook/src/hook.c @@ -1,6 +1,6 @@ /* * MinHook - The Minimalistic API Hooking Library for x64/x86 - * Copyright (C) 2009-2015 Tsuda Kageyu. + * Copyright (C) 2009-2017 Tsuda Kageyu. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,15 +26,18 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include -#include -#include +#include +#include +#include #include "../include/MinHook.h" #include "buffer.h" #include "trampoline.h" +#ifndef ARRAYSIZE + #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0])) +#endif + // Initial capacity of the HOOK_ENTRY buffer. #define INITIAL_HOOK_CAPACITY 32 @@ -62,11 +65,11 @@ typedef struct _HOOK_ENTRY LPVOID pTrampoline; // Address of the trampoline function. UINT8 backup[8]; // Original prologue of the target function. - BOOL patchAbove : 1; // Uses the hot patch area. - BOOL isEnabled : 1; // Enabled. - BOOL queueEnable : 1; // Queued for enabling/disabling when != isEnabled. + UINT8 patchAbove : 1; // Uses the hot patch area. + UINT8 isEnabled : 1; // Enabled. + UINT8 queueEnable : 1; // Queued for enabling/disabling when != isEnabled. - UINT nIP : 3; // Count of the instruction boundaries. + UINT nIP : 4; // Count of the instruction boundaries. UINT8 oldIPs[8]; // Instruction boundaries of the target function. UINT8 newIPs[8]; // Instruction boundaries of the trampoline function. } HOOK_ENTRY, *PHOOK_ENTRY; @@ -170,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; @@ -199,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; @@ -236,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; } @@ -435,14 +438,13 @@ static VOID EnterSpinLock(VOID) SIZE_T spinCount = 0; // Wait until the flag is FALSE. - while (_InterlockedCompareExchange(&g_isLocked, TRUE, FALSE) != FALSE) + while (InterlockedCompareExchange(&g_isLocked, TRUE, FALSE) != FALSE) { - _ReadWriteBarrier(); + // No need to generate a memory barrier here, since InterlockedCompareExchange() + // generates a full memory barrier itself. // Prevent the loop from being too busy. - if (spinCount < 16) - _mm_pause(); - else if (spinCount < 32) + if (spinCount < 32) Sleep(0); else Sleep(1); @@ -454,8 +456,10 @@ static VOID EnterSpinLock(VOID) //------------------------------------------------------------------------- static VOID LeaveSpinLock(VOID) { - _ReadWriteBarrier(); - _InterlockedExchange(&g_isLocked, FALSE); + // No need to generate a memory barrier here, since InterlockedExchange() + // generates a full memory barrier itself. + + InterlockedExchange(&g_isLocked, FALSE); } //------------------------------------------------------------------------- @@ -546,8 +550,8 @@ MH_STATUS WINAPI MH_CreateHook(LPVOID pTarget, LPVOID pDetour, LPVOID *ppOrigina { TRAMPOLINE ct; - ct.pTarget = pTarget; - ct.pDetour = pDetour; + ct.pTarget = pTarget; + ct.pDetour = pDetour; ct.pTrampoline = pBuffer; if (CreateTrampolineFunction(&ct)) { @@ -555,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; @@ -827,8 +831,9 @@ MH_STATUS WINAPI MH_ApplyQueued(VOID) } //------------------------------------------------------------------------- -MH_STATUS WINAPI MH_CreateHookApi( - LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal) +MH_STATUS WINAPI MH_CreateHookApiEx( + LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, + LPVOID *ppOriginal, LPVOID *ppTarget) { HMODULE hModule; LPVOID pTarget; @@ -837,13 +842,23 @@ MH_STATUS WINAPI MH_CreateHookApi( if (hModule == NULL) return MH_ERROR_MODULE_NOT_FOUND; - pTarget = GetProcAddress(hModule, pszProcName); + pTarget = (LPVOID)GetProcAddress(hModule, pszProcName); if (pTarget == NULL) return MH_ERROR_FUNCTION_NOT_FOUND; + if(ppTarget != NULL) + *ppTarget = pTarget; + return MH_CreateHook(pTarget, pDetour, ppOriginal); } +//------------------------------------------------------------------------- +MH_STATUS WINAPI MH_CreateHookApi( + LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal) +{ + return MH_CreateHookApiEx(pszModule, pszProcName, pDetour, ppOriginal, NULL); +} + //------------------------------------------------------------------------- const char * WINAPI MH_StatusToString(MH_STATUS status) { @@ -864,6 +879,8 @@ const char * WINAPI MH_StatusToString(MH_STATUS status) MH_ST2STR(MH_ERROR_UNSUPPORTED_FUNCTION) MH_ST2STR(MH_ERROR_MEMORY_ALLOC) MH_ST2STR(MH_ERROR_MEMORY_PROTECT) + MH_ST2STR(MH_ERROR_MODULE_NOT_FOUND) + MH_ST2STR(MH_ERROR_FUNCTION_NOT_FOUND) } #undef MH_ST2STR diff --git a/MinHook/src/trampoline.c b/MinHook/src/trampoline.c index 8e59c3f..ac37f0f 100644 --- a/MinHook/src/trampoline.c +++ b/MinHook/src/trampoline.c @@ -1,6 +1,6 @@ /* * MinHook - The Minimalistic API Hooking Library for x64/x86 - * Copyright (C) 2009-2015 Tsuda Kageyu. + * Copyright (C) 2009-2017 Tsuda Kageyu. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,10 +26,13 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include -#include +#include -#ifdef _M_X64 +#ifndef ARRAYSIZE + #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0])) +#endif + +#if defined(_M_X64) || defined(__x86_64__) #include "./hde/hde64.h" typedef hde64s HDE; #define HDE_DISASM(code, hs) hde64_disasm(code, hs) @@ -43,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 @@ -68,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 @@ -102,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 @@ -126,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))); @@ -136,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) @@ -145,7 +148,11 @@ BOOL CreateTrampolineFunction(PTRAMPOLINE ct) PUINT32 pRelAddr; // Avoid using memcpy to reduce the footprint. +#ifndef _MSC_VER + memcpy(instBuf, (LPBYTE)pOldInst, copySize); +#else __movsb(instBuf, (LPBYTE)pOldInst, copySize); +#endif pCopySrc = instBuf; // Relative address is stored at (instruction length - immediate value length - 4). @@ -162,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))); @@ -189,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))); @@ -229,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; @@ -266,7 +273,11 @@ BOOL CreateTrampolineFunction(PTRAMPOLINE ct) ct->nIP++; // Avoid using memcpy to reduce the footprint. +#ifndef _MSC_VER + memcpy((LPBYTE)ct->pTrampoline + newPos, pCopySrc, copySize); +#else __movsb((LPBYTE)ct->pTrampoline + newPos, pCopySrc, copySize); +#endif newPos += copySize; oldPos += hs.len; } @@ -293,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/MinHook/src/trampoline.h b/MinHook/src/trampoline.h index 885c6ed..bdffdac 100644 --- a/MinHook/src/trampoline.h +++ b/MinHook/src/trampoline.h @@ -1,6 +1,6 @@ /* * MinHook - The Minimalistic API Hooking Library for x64/x86 - * Copyright (C) 2009-2015 Tsuda Kageyu. + * Copyright (C) 2009-2017 Tsuda Kageyu. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -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? diff --git a/d3d9ex.sln b/d3d9ex.sln index 2352a0f..a61343b 100644 --- a/d3d9ex.sln +++ b/d3d9ex.sln @@ -1,12 +1,10 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.27130.2036 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OneTweakNG", "d3d9ex\d3d9ex.vcxproj", "{6C397640-B1A0-4DEF-8657-0EB21DC2FEA5}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libMinHook", "MinHook\build\VC12\libMinHook.vcxproj", "{F142A341-5EE0-442D-A15F-98AE9B48DBAE}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{5DB3A8C9-CF87-4AB6-A7C2-07B81A0DA625}" ProjectSection(SolutionItems) = preProject Common\Defines.h = Common\Defines.h @@ -20,6 +18,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{5DB3A8 Common\WinVer.h = Common\WinVer.h EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libMinHook", "MinHook\build\VC15\libMinHook.vcxproj", "{F142A341-5EE0-442D-A15F-98AE9B48DBAE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -48,6 +48,7 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CC332D21-3B2D-4534-AD8E-2525081AECA5} VisualSVNWorkingCopyRoot = . EndGlobalSection EndGlobal diff --git a/d3d9ex/AutoFix.cpp b/d3d9ex/AutoFix.cpp index 7e37c00..bb96f3c 100644 --- a/d3d9ex/AutoFix.cpp +++ b/d3d9ex/AutoFix.cpp @@ -72,7 +72,7 @@ bool MainContext::ApplyVertexBufferFix(UINT& Length, DWORD& Usage, DWORD& FVF, D // Final Fantasy XIII if (autofix == FINAL_FANTASY_XIII) { - if (Length == 358400 && FVF == 0 && Pool == D3DPOOL_MANAGED) { Usage = D3DUSAGE_DYNAMIC; Pool = D3DPOOL_DEFAULT; } + if (Length == 358400 && FVF == 0 && Pool == D3DPOOL_MANAGED) { Usage = D3DUSAGE_DYNAMIC; Pool = D3DPOOL_SYSTEMMEM; } return true; } return false; diff --git a/d3d9ex/Context.cpp b/d3d9ex/Context.cpp index ef24c8c..218bdff 100644 --- a/d3d9ex/Context.cpp +++ b/d3d9ex/Context.cpp @@ -193,6 +193,7 @@ void MainContext::ApplyBorderless(HWND hWnd) int cy = GetSystemMetrics(SM_CYSCREEN); SetWindowPos(hWnd, HWND_TOP, 0, 0, cx, cy, SWP_SHOWWINDOW | SWP_NOCOPYBITS | SWP_NOSENDCHANGING); + SetFocus(hWnd); PrintLog("HWND 0x%p: Borderless dwStyle: %lX->%lX", hWnd, dwStyle, new_dwStyle); PrintLog("HWND 0x%p: Borderless dwExStyle: %lX->%lX", hWnd, dwExStyle, new_dwExStyle); diff --git a/d3d9ex/IDirect3DDevice9.cpp b/d3d9ex/IDirect3DDevice9.cpp index d63581b..5e78c17 100644 --- a/d3d9ex/IDirect3DDevice9.cpp +++ b/d3d9ex/IDirect3DDevice9.cpp @@ -7,6 +7,8 @@ #include "IDirect3DDevice9.h" +#include + #define IDirect3DDevice9_PrintLog(...) //PrintLog(format, __VA_ARGS__); hkIDirect3DDevice9::hkIDirect3DDevice9(IDirect3DDevice9 *pIDirect3DDevice9) { diff --git a/d3d9ex/d3d9ex.vcxproj b/d3d9ex/d3d9ex.vcxproj index 9760cbd..48488e1 100644 --- a/d3d9ex/d3d9ex.vcxproj +++ b/d3d9ex/d3d9ex.vcxproj @@ -1,5 +1,5 @@  - + Debug @@ -23,19 +23,19 @@ Win32Proj d3d9ex OneTweakNG - 8.1 + 10.0.16299.0 DynamicLibrary true - v140 + v141 Unicode DynamicLibrary true - v140 + v141 Unicode @@ -44,7 +44,7 @@ true MultiByte true - v140 + v141 DynamicLibrary @@ -52,7 +52,7 @@ true MultiByte true - v140 + v141 @@ -127,8 +127,8 @@ true WIN32;NDEBUG;_WINDOWS;_USRDLL;D3D9EX_EXPORTS;%(PreprocessorDefinitions) true - MultiThreaded MaxSpeed + true Windows @@ -200,7 +200,7 @@ - + {f142a341-5ee0-442d-a15f-98ae9b48dbae}