diff options
author | Tsuda Kageyu <tsuda.kageyu@gmail.com> | 2016-12-05 08:47:55 +0300 |
---|---|---|
committer | Tsuda Kageyu <tsuda.kageyu@gmail.com> | 2016-12-05 08:47:55 +0300 |
commit | a184d61b356ff39758ab7b9f0a3de38ea9e17c17 (patch) | |
tree | 1d900b12af5ddba69b61fcda01343b46fb188116 | |
parent | 8c8a31f4badbcf0a49b34f6d45b8236eda9d2cbc (diff) |
Support GCC predefined macros to detect x64 mode.
-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/hook.c | 6 | ||||
-rw-r--r-- | src/trampoline.c | 20 | ||||
-rw-r--r-- | src/trampoline.h | 2 |
6 files changed, 21 insertions, 21 deletions
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 @@ -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; @@ -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? |