Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/TsudaKageyu/minhook.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZLOFENIX <admin@zlofenix.org>2015-05-19 13:46:32 +0300
committerZLOFENIX <admin@zlofenix.org>2015-05-19 13:46:32 +0300
commit58e62a90eaa4d5c6af16774cc9db7e334e647d51 (patch)
treed625ebf05282ce9a276ebab9796ee35de7204fac
parentfb327694ee4f0d325c068a8efaffd852a0598f33 (diff)
Support for MinGW, small fixes.
-rw-r--r--build/MinGW/make.bat1
-rw-r--r--dll_resources/MinHook_utf8.rc32
-rw-r--r--src/HDE/hde32.c5
-rw-r--r--src/HDE/hde64.c5
-rw-r--r--src/buffer.c5
-rw-r--r--src/hook.c34
-rw-r--r--src/trampoline.c14
7 files changed, 91 insertions, 5 deletions
diff --git a/build/MinGW/make.bat b/build/MinGW/make.bat
new file mode 100644
index 0000000..21d49f6
--- /dev/null
+++ b/build/MinGW/make.bat
@@ -0,0 +1 @@
+windres -i ../../dll_resources/MinHook_utf8.rc -o MinHook_rc.o && dllwrap --driver-name g++ -o MinHook.dll -masm=intel --def ../../dll_resources/MinHook.def -Wl,-enable-stdcall-fixup -Wall -DMINGW 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/dll_resources/MinHook_utf8.rc b/dll_resources/MinHook_utf8.rc
new file mode 100644
index 0000000..2c27a9f
--- /dev/null
+++ b/dll_resources/MinHook_utf8.rc
@@ -0,0 +1,32 @@
+1 VERSIONINFO
+ FILEVERSION 1,3,2,0
+ PRODUCTVERSION 1,3,2,0
+ FILEFLAGSMASK 0x17L
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "CompanyName", "Tsuda Kageyu"
+ VALUE "FileDescription", "MinHook - The Minimalistic API Hook Library for x64/x86"
+ VALUE "FileVersion", "1.3.2.0"
+ VALUE "InternalName", "MinHookD"
+ VALUE "LegalCopyright", "Copyright (C) 2009-2015 Tsuda Kageyu. All rights reserved."
+ VALUE "LegalTrademarks", "Tsuda Kageyu"
+ VALUE "ProductName", "MinHook DLL"
+ VALUE "ProductVersion", "1.3.2.0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
diff --git a/src/HDE/hde32.c b/src/HDE/hde32.c
index 391bd79..1a50e5e 100644
--- a/src/HDE/hde32.c
+++ b/src/HDE/hde32.c
@@ -5,7 +5,6 @@
*
*/
-#include <intrin.h>
#include "hde32.h"
#include "table32.h"
@@ -15,7 +14,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.
+#ifdef MINGW
+ memset((LPBYTE)hs, 0, sizeof(hde32s));
+#else
__stosb((LPBYTE)hs, 0, sizeof(hde32s));
+#endif
for (x = 16; x; x--)
switch (c = *p++) {
diff --git a/src/HDE/hde64.c b/src/HDE/hde64.c
index 68a5611..0312146 100644
--- a/src/HDE/hde64.c
+++ b/src/HDE/hde64.c
@@ -5,7 +5,6 @@
*
*/
-#include <intrin.h>
#include "hde64.h"
#include "table64.h"
@@ -16,7 +15,11 @@ unsigned int hde64_disasm(const void *code, hde64s *hs)
uint8_t op64 = 0;
// Avoid using memset to reduce the footprint.
+#ifdef MINGW
+ memset((LPBYTE)hs, 0, sizeof(hde64s));
+#else
__stosb((LPBYTE)hs, 0, sizeof(hde64s));
+#endif
for (x = 16; x; x--)
switch (c = *p++) {
diff --git a/src/buffer.c b/src/buffer.c
index b3d9306..68d2b30 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -29,6 +29,11 @@
#include <Windows.h>
#include "buffer.h"
+#ifndef max
+#define max(a,b) (((a) > (b)) ? (a) : (b))
+#define min(a,b) (((a) < (b)) ? (a) : (b))
+#endif
+
// Size of each memory block. (= page size of VirtualAlloc)
#define MEMORY_BLOCK_SIZE 0x1000
diff --git a/src/hook.c b/src/hook.c
index f6478a9..6470c3b 100644
--- a/src/hook.c
+++ b/src/hook.c
@@ -26,10 +26,23 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifdef MINGW
+#define _WIN32_WINNT 0x0501
+#define WIN32_LEAN_AND_MEAN
+#endif
#include <Windows.h>
#include <TlHelp32.h>
+#ifdef MINGW
+#include <x86intrin.h>
+#include <limits.h>
+#ifndef ARRAYSIZE
+ #define ARRAYSIZE sizeof
+#endif
+#include <unistd.h>
+#else
#include <intrin.h>
#include <xmmintrin.h>
+#endif
#include "../include/MinHook.h"
#include "buffer.h"
@@ -435,15 +448,26 @@ static VOID EnterSpinLock(VOID)
SIZE_T spinCount = 0;
// Wait until the flag is FALSE.
+#ifdef MINGW
+ while (InterlockedCompareExchange(&g_isLocked, TRUE, FALSE) != FALSE)
+ {
+#else
while (_InterlockedCompareExchange(&g_isLocked, TRUE, FALSE) != FALSE)
{
_ReadWriteBarrier();
-
+#endif
// Prevent the loop from being too busy.
+#ifdef MINGW
+ if (spinCount < 16)
+ usleep(250);
+ else if (spinCount < 32)
+ usleep(500);
+#else
if (spinCount < 16)
_mm_pause();
else if (spinCount < 32)
Sleep(0);
+#endif
else
Sleep(1);
@@ -454,8 +478,12 @@ static VOID EnterSpinLock(VOID)
//-------------------------------------------------------------------------
static VOID LeaveSpinLock(VOID)
{
+#ifdef MINGW
+ InterlockedExchange(&g_isLocked, FALSE);
+#else
_ReadWriteBarrier();
_InterlockedExchange(&g_isLocked, FALSE);
+#endif
}
//-------------------------------------------------------------------------
@@ -837,7 +865,7 @@ 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;
@@ -864,6 +892,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/src/trampoline.c b/src/trampoline.c
index 8e59c3f..bad6cf1 100644
--- a/src/trampoline.c
+++ b/src/trampoline.c
@@ -27,7 +27,11 @@
*/
#include <Windows.h>
-#include <intrin.h>
+#ifdef MINGW
+#ifndef ARRAYSIZE
+ #define ARRAYSIZE sizeof
+#endif
+#endif
#ifdef _M_X64
#include "./hde/hde64.h"
@@ -145,7 +149,11 @@ BOOL CreateTrampolineFunction(PTRAMPOLINE ct)
PUINT32 pRelAddr;
// Avoid using memcpy to reduce the footprint.
+#ifdef MINGW
+ 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).
@@ -266,7 +274,11 @@ BOOL CreateTrampolineFunction(PTRAMPOLINE ct)
ct->nIP++;
// Avoid using memcpy to reduce the footprint.
+#ifdef MINGW
+ memcpy((LPBYTE)ct->pTrampoline + newPos, pCopySrc, copySize);
+#else
__movsb((LPBYTE)ct->pTrampoline + newPos, pCopySrc, copySize);
+#endif
newPos += copySize;
oldPos += hs.len;
}