From 3cdc17bfaa0d1101031e30b3851ffb3cd88d3b27 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?=
<101191390+HIllya51@users.noreply.github.com>
Date: Thu, 21 Mar 2024 21:15:40 +0800
Subject: [PATCH] update minhook
1
---
libs/minhook/.editorconfig | 4 +
libs/minhook/CMakeLists.txt | 8 +-
libs/minhook/build/MinGW/Makefile | 2 +-
libs/minhook/build/VC12/libMinHook.vcxproj | 1 -
libs/minhook/build/VC14/libMinHook.vcxproj | 1 -
libs/minhook/build/VC15/libMinHook.vcxproj | 1 -
libs/minhook/build/VC16/libMinHook.vcxproj | 3 +-
libs/minhook/build/VC17/MinHook.vcxproj | 190 ++++++++++++++++++
libs/minhook/build/VC17/MinHookVC17.sln | 41 ++++
libs/minhook/build/VC17/libMinHook.vcxproj | 174 ++++++++++++++++
.../build/VC17/libMinHook.vcxproj.filters | 55 +++++
libs/minhook/src/hde/hde64.c | 4 +-
libs/minhook/src/hook.c | 121 +++++++----
libs/minhook/src/trampoline.c | 14 +-
14 files changed, 558 insertions(+), 61 deletions(-)
create mode 100644 libs/minhook/build/VC17/MinHook.vcxproj
create mode 100644 libs/minhook/build/VC17/MinHookVC17.sln
create mode 100644 libs/minhook/build/VC17/libMinHook.vcxproj
create mode 100644 libs/minhook/build/VC17/libMinHook.vcxproj.filters
diff --git a/libs/minhook/.editorconfig b/libs/minhook/.editorconfig
index 36c09e6..735e983 100644
--- a/libs/minhook/.editorconfig
+++ b/libs/minhook/.editorconfig
@@ -20,3 +20,7 @@ trim_trailing_whitespace = true
# UTF-8 with BOM
[*.{c,h,def,txt}]
charset=utf-8-bom
+
+# C/C++ code formatting
+[*.{c,h}]
+cpp_space_pointer_reference_alignment = right
diff --git a/libs/minhook/CMakeLists.txt b/libs/minhook/CMakeLists.txt
index 842b1c2..d45414e 100644
--- a/libs/minhook/CMakeLists.txt
+++ b/libs/minhook/CMakeLists.txt
@@ -24,7 +24,7 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#cmake_minimum_required(VERSION 3.0)
+cmake_minimum_required(VERSION 3.0)
project(minhook LANGUAGES C)
@@ -55,8 +55,8 @@ endif()
if(BUILD_SHARED_LIBS)
set(RESOURCES
- "dll_resources/minhook.rc"
- "dll_resources/minhook.def"
+ "dll_resources/MinHook.rc"
+ "dll_resources/MinHook.def"
)
endif()
@@ -81,7 +81,7 @@ if(WIN32)
set_target_properties(minhook PROPERTIES DEBUG_POSTFIX ".x32d")
set_target_properties(minhook PROPERTIES RELEASE_POSTFIX ".x32")
set_target_properties(minhook PROPERTIES RELWITHDEBINFO_POSTFIX ".x32")
- set_target_properties(minhook PROPERTIES MINSIZEREL_POSTFIX ".x64")
+ set_target_properties(minhook PROPERTIES MINSIZEREL_POSTFIX ".x32")
endif()
else()
set_target_properties(minhook PROPERTIES PREFIX "lib")
diff --git a/libs/minhook/build/MinGW/Makefile b/libs/minhook/build/MinGW/Makefile
index cc16725..9784745 100644
--- a/libs/minhook/build/MinGW/Makefile
+++ b/libs/minhook/build/MinGW/Makefile
@@ -17,7 +17,7 @@ all: MinHook.dll libMinHook.dll.a libMinHook.a
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 $@
+ $(DLLTOOL) --dllname MinHook.dll --input-def dll_resources/MinHook.def --output-lib $@
MinHook.dll: $(OBJS) dll_resources/MinHook.res dll_resources/MinHook.def
$(CCLD) -o $@ -shared $(LDFLAGS) $^
diff --git a/libs/minhook/build/VC12/libMinHook.vcxproj b/libs/minhook/build/VC12/libMinHook.vcxproj
index 6b2a190..7e7fe8e 100644
--- a/libs/minhook/build/VC12/libMinHook.vcxproj
+++ b/libs/minhook/build/VC12/libMinHook.vcxproj
@@ -120,7 +120,6 @@
Level3
None
AnySuitable
- CompileAsC
true
NoExtensions
diff --git a/libs/minhook/build/VC14/libMinHook.vcxproj b/libs/minhook/build/VC14/libMinHook.vcxproj
index 263b811..a429e69 100644
--- a/libs/minhook/build/VC14/libMinHook.vcxproj
+++ b/libs/minhook/build/VC14/libMinHook.vcxproj
@@ -120,7 +120,6 @@
Level3
None
AnySuitable
- CompileAsC
true
NoExtensions
diff --git a/libs/minhook/build/VC15/libMinHook.vcxproj b/libs/minhook/build/VC15/libMinHook.vcxproj
index 0d4352e..829ac34 100644
--- a/libs/minhook/build/VC15/libMinHook.vcxproj
+++ b/libs/minhook/build/VC15/libMinHook.vcxproj
@@ -120,7 +120,6 @@
Level3
None
AnySuitable
- CompileAsC
true
NoExtensions
diff --git a/libs/minhook/build/VC16/libMinHook.vcxproj b/libs/minhook/build/VC16/libMinHook.vcxproj
index 8ee4414..605871b 100644
--- a/libs/minhook/build/VC16/libMinHook.vcxproj
+++ b/libs/minhook/build/VC16/libMinHook.vcxproj
@@ -120,7 +120,6 @@
Level3
None
AnySuitable
- CompileAsC
true
NoExtensions
@@ -171,4 +170,4 @@
-
+
\ No newline at end of file
diff --git a/libs/minhook/build/VC17/MinHook.vcxproj b/libs/minhook/build/VC17/MinHook.vcxproj
new file mode 100644
index 0000000..1a7aae5
--- /dev/null
+++ b/libs/minhook/build/VC17/MinHook.vcxproj
@@ -0,0 +1,190 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ Win32
+
+
+ Release
+ x64
+
+
+
+ {027FAC75-3FDB-4044-8DD0-BC297BD4C461}
+ MinHook
+ Win32Proj
+ 10.0
+
+
+
+ DynamicLibrary
+ Unicode
+ true
+ v143
+
+
+ DynamicLibrary
+ Unicode
+ v143
+
+
+ DynamicLibrary
+ Unicode
+ true
+ v143
+
+
+ DynamicLibrary
+ Unicode
+ v143
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_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
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/libs/minhook/build/VC17/MinHookVC17.sln b/libs/minhook/build/VC17/MinHookVC17.sln
new file mode 100644
index 0000000..3c40ce3
--- /dev/null
+++ b/libs/minhook/build/VC17/MinHookVC17.sln
@@ -0,0 +1,41 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.3.32901.215
+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/libs/minhook/build/VC17/libMinHook.vcxproj b/libs/minhook/build/VC17/libMinHook.vcxproj
new file mode 100644
index 0000000..21197df
--- /dev/null
+++ b/libs/minhook/build/VC17/libMinHook.vcxproj
@@ -0,0 +1,174 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ Win32
+
+
+ Release
+ x64
+
+
+
+ {F142A341-5EE0-442D-A15F-98AE9B48DBAE}
+ libMinHook
+ Win32Proj
+ 10.0
+
+
+
+ StaticLibrary
+ Unicode
+ true
+ v143
+
+
+ StaticLibrary
+ Unicode
+ v143
+
+
+ StaticLibrary
+ Unicode
+ true
+ v143
+
+
+ StaticLibrary
+ Unicode
+ v143
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <_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
+ MultiThreaded
+ true
+ Level3
+ None
+ AnySuitable
+ true
+ NoExtensions
+
+
+
+
+
+ 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/libs/minhook/build/VC17/libMinHook.vcxproj.filters b/libs/minhook/build/VC17/libMinHook.vcxproj.filters
new file mode 100644
index 0000000..f2d1d97
--- /dev/null
+++ b/libs/minhook/build/VC17/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/libs/minhook/src/hde/hde64.c b/libs/minhook/src/hde/hde64.c
index 55a702e..ce773b1 100644
--- a/libs/minhook/src/hde/hde64.c
+++ b/libs/minhook/src/hde/hde64.c
@@ -195,7 +195,7 @@ unsigned int hde64_disasm(const void *code, hde64s *hs)
}
for (; ht != table_end; ht += 2)
if (*ht++ == opcode) {
- if (*ht++ & pref && !((*ht << m_reg) & 0x80))
+ if ((*ht++ & pref) && !((*ht << m_reg) & 0x80))
goto error_operand;
else
break;
@@ -246,6 +246,7 @@ unsigned int hde64_disasm(const void *code, hde64s *hs)
disp_size = 2;
if (!(pref & PRE_67))
disp_size <<= 1;
+ break;
}
if (m_mod != 3 && m_rm == 4) {
@@ -271,6 +272,7 @@ unsigned int hde64_disasm(const void *code, hde64s *hs)
case 4:
hs->flags |= F_DISP32;
hs->disp.disp32 = *(uint32_t *)p;
+ break;
}
p += disp_size;
} else if (pref & PRE_LOCK)
diff --git a/libs/minhook/src/hook.c b/libs/minhook/src/hook.c
index ce65e57..e387f21 100644
--- a/libs/minhook/src/hook.c
+++ b/libs/minhook/src/hook.c
@@ -140,7 +140,7 @@ static PHOOK_ENTRY AddHookEntry()
}
//-------------------------------------------------------------------------
-static void DeleteHookEntry(UINT pos)
+static VOID DeleteHookEntry(UINT pos)
{
if (pos < g_hooks.size - 1)
g_hooks.pItems[pos] = g_hooks.pItems[g_hooks.size - 1];
@@ -196,7 +196,7 @@ static DWORD_PTR FindNewIP(PHOOK_ENTRY pHook, DWORD_PTR ip)
}
//-------------------------------------------------------------------------
-static void ProcessThreadIPs(HANDLE hThread, UINT pos, UINT action)
+static VOID ProcessThreadIPs(HANDLE hThread, UINT pos, UINT action)
{
// If the thread suspended in the overwritten area,
// move IP to the proper address.
@@ -260,8 +260,11 @@ static void ProcessThreadIPs(HANDLE hThread, UINT pos, UINT action)
}
//-------------------------------------------------------------------------
-static VOID EnumerateThreads(PFROZEN_THREADS pThreads)
+static BOOL EnumerateThreads(PFROZEN_THREADS pThreads)
{
+ LPDWORD p;
+ BOOL succeeded = FALSE;
+
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
if (hSnapshot != INVALID_HANDLE_VALUE)
{
@@ -269,6 +272,7 @@ static VOID EnumerateThreads(PFROZEN_THREADS pThreads)
te.dwSize = sizeof(THREADENTRY32);
if (Thread32First(hSnapshot, &te))
{
+ succeeded = TRUE;
do
{
if (te.dwSize >= (FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID) + sizeof(DWORD))
@@ -281,16 +285,22 @@ static VOID EnumerateThreads(PFROZEN_THREADS pThreads)
pThreads->pItems
= (LPDWORD)HeapAlloc(g_hHeap, 0, pThreads->capacity * sizeof(DWORD));
if (pThreads->pItems == NULL)
+ {
+ succeeded = FALSE;
break;
+ }
}
else if (pThreads->size >= pThreads->capacity)
{
- LPDWORD p = (LPDWORD)HeapReAlloc(
- g_hHeap, 0, pThreads->pItems, (pThreads->capacity * 2) * sizeof(DWORD));
- if (p == NULL)
- break;
-
pThreads->capacity *= 2;
+ p = (LPDWORD)HeapReAlloc(
+ g_hHeap, 0, pThreads->pItems, pThreads->capacity * sizeof(DWORD));
+ if (p == NULL)
+ {
+ succeeded = FALSE;
+ break;
+ }
+
pThreads->pItems = p;
}
pThreads->pItems[pThreads->size++] = te.th32ThreadID;
@@ -298,20 +308,35 @@ static VOID EnumerateThreads(PFROZEN_THREADS pThreads)
te.dwSize = sizeof(THREADENTRY32);
} while (Thread32Next(hSnapshot, &te));
+
+ if (succeeded && GetLastError() != ERROR_NO_MORE_FILES)
+ succeeded = FALSE;
+
+ if (!succeeded && pThreads->pItems != NULL)
+ {
+ HeapFree(g_hHeap, 0, pThreads->pItems);
+ pThreads->pItems = NULL;
+ }
}
CloseHandle(hSnapshot);
}
+
+ return succeeded;
}
//-------------------------------------------------------------------------
-static VOID Freeze(PFROZEN_THREADS pThreads, UINT pos, UINT action)
+static MH_STATUS Freeze(PFROZEN_THREADS pThreads, UINT pos, UINT action)
{
+ MH_STATUS status = MH_OK;
+
pThreads->pItems = NULL;
pThreads->capacity = 0;
pThreads->size = 0;
- EnumerateThreads(pThreads);
-
- if (pThreads->pItems != NULL)
+ if (!EnumerateThreads(pThreads))
+ {
+ status = MH_ERROR_MEMORY_ALLOC;
+ }
+ else if (pThreads->pItems != NULL)
{
UINT i;
for (i = 0; i < pThreads->size; ++i)
@@ -325,6 +350,8 @@ static VOID Freeze(PFROZEN_THREADS pThreads, UINT pos, UINT action)
}
}
}
+
+ return status;
}
//-------------------------------------------------------------------------
@@ -414,19 +441,21 @@ static MH_STATUS EnableAllHooksLL(BOOL enable)
if (first != INVALID_HOOK_POS)
{
FROZEN_THREADS threads;
- Freeze(&threads, ALL_HOOKS_POS, enable ? ACTION_ENABLE : ACTION_DISABLE);
-
- for (i = first; i < g_hooks.size; ++i)
+ status = Freeze(&threads, ALL_HOOKS_POS, enable ? ACTION_ENABLE : ACTION_DISABLE);
+ if (status == MH_OK)
{
- if (g_hooks.pItems[i].isEnabled != enable)
+ for (i = first; i < g_hooks.size; ++i)
{
- status = EnableHookLL(i, enable);
- if (status != MH_OK)
- break;
+ if (g_hooks.pItems[i].isEnabled != enable)
+ {
+ status = EnableHookLL(i, enable);
+ if (status != MH_OK)
+ break;
+ }
}
- }
- Unfreeze(&threads);
+ Unfreeze(&threads);
+ }
}
return status;
@@ -644,11 +673,13 @@ MH_STATUS WINAPI MH_RemoveHook(LPVOID pTarget)
if (g_hooks.pItems[pos].isEnabled)
{
FROZEN_THREADS threads;
- Freeze(&threads, pos, ACTION_DISABLE);
+ status = Freeze(&threads, pos, ACTION_DISABLE);
+ if (status == MH_OK)
+ {
+ status = EnableHookLL(pos, FALSE);
- status = EnableHookLL(pos, FALSE);
-
- Unfreeze(&threads);
+ Unfreeze(&threads);
+ }
}
if (status == MH_OK)
@@ -687,17 +718,19 @@ static MH_STATUS EnableHook(LPVOID pTarget, BOOL enable)
}
else
{
- FROZEN_THREADS threads;
UINT pos = FindHookEntry(pTarget);
if (pos != INVALID_HOOK_POS)
{
if (g_hooks.pItems[pos].isEnabled != enable)
{
- Freeze(&threads, pos, ACTION_ENABLE);
+ FROZEN_THREADS threads;
+ status = Freeze(&threads, pos, ACTION_ENABLE);
+ if (status == MH_OK)
+ {
+ status = EnableHookLL(pos, enable);
- status = EnableHookLL(pos, enable);
-
- Unfreeze(&threads);
+ Unfreeze(&threads);
+ }
}
else
{
@@ -804,20 +837,22 @@ MH_STATUS WINAPI MH_ApplyQueued(VOID)
if (first != INVALID_HOOK_POS)
{
FROZEN_THREADS threads;
- Freeze(&threads, ALL_HOOKS_POS, ACTION_APPLY_QUEUED);
-
- for (i = first; i < g_hooks.size; ++i)
+ status = Freeze(&threads, ALL_HOOKS_POS, ACTION_APPLY_QUEUED);
+ if (status == MH_OK)
{
- PHOOK_ENTRY pHook = &g_hooks.pItems[i];
- if (pHook->isEnabled != pHook->queueEnable)
+ for (i = first; i < g_hooks.size; ++i)
{
- status = EnableHookLL(i, pHook->queueEnable);
- if (status != MH_OK)
- break;
+ PHOOK_ENTRY pHook = &g_hooks.pItems[i];
+ if (pHook->isEnabled != pHook->queueEnable)
+ {
+ status = EnableHookLL(i, pHook->queueEnable);
+ if (status != MH_OK)
+ break;
+ }
}
- }
- Unfreeze(&threads);
+ Unfreeze(&threads);
+ }
}
}
else
@@ -846,7 +881,7 @@ MH_STATUS WINAPI MH_CreateHookApiEx(
if (pTarget == NULL)
return MH_ERROR_FUNCTION_NOT_FOUND;
- if(ppTarget != NULL)
+ if (ppTarget != NULL)
*ppTarget = pTarget;
return MH_CreateHook(pTarget, pDetour, ppOriginal);
@@ -856,11 +891,11 @@ MH_STATUS WINAPI MH_CreateHookApiEx(
MH_STATUS WINAPI MH_CreateHookApi(
LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal)
{
- return MH_CreateHookApiEx(pszModule, pszProcName, pDetour, ppOriginal, NULL);
+ return MH_CreateHookApiEx(pszModule, pszProcName, pDetour, ppOriginal, NULL);
}
//-------------------------------------------------------------------------
-const char * WINAPI MH_StatusToString(MH_STATUS status)
+const char *WINAPI MH_StatusToString(MH_STATUS status)
{
#define MH_ST2STR(x) \
case x: \
diff --git a/libs/minhook/src/trampoline.c b/libs/minhook/src/trampoline.c
index c267088..d4d6f99 100644
--- a/libs/minhook/src/trampoline.c
+++ b/libs/minhook/src/trampoline.c
@@ -28,7 +28,8 @@
#include
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && !defined(MINHOOK_DISABLE_INTRINSICS)
+ #define ALLOW_INTRINSICS
#include
#endif
@@ -152,7 +153,7 @@ BOOL CreateTrampolineFunction(PTRAMPOLINE ct)
PUINT32 pRelAddr;
// Avoid using memcpy to reduce the footprint.
-#ifndef _MSC_VER
+#ifndef ALLOW_INTRINSICS
memcpy(instBuf, (LPBYTE)pOldInst, copySize);
#else
__movsb(instBuf, (LPBYTE)pOldInst, copySize);
@@ -208,7 +209,7 @@ BOOL CreateTrampolineFunction(PTRAMPOLINE ct)
pCopySrc = &jmp;
copySize = sizeof(jmp);
- // Exit the function If it is not in the branch
+ // Exit the function if it is not in the branch.
finished = (pOldInst >= jmpDest);
}
}
@@ -277,15 +278,14 @@ BOOL CreateTrampolineFunction(PTRAMPOLINE ct)
ct->nIP++;
// Avoid using memcpy to reduce the footprint.
-#ifndef _MSC_VER
+#ifndef ALLOW_INTRINSICS
memcpy((LPBYTE)ct->pTrampoline + newPos, pCopySrc, copySize);
#else
- __movsb((LPBYTE)ct->pTrampoline + newPos, pCopySrc, copySize);
+ __movsb((LPBYTE)ct->pTrampoline + newPos, (LPBYTE)pCopySrc, copySize);
#endif
newPos += copySize;
oldPos += hs.len;
- }
- while (!finished);
+ } while (!finished);
// Is there enough place for a long jump?
if (oldPos < sizeof(JMP_REL)