diff options
-rw-r--r-- | subhook.c | 2 | ||||
-rw-r--r-- | subhook.h | 16 | ||||
-rw-r--r-- | subhook_x86.c | 19 |
3 files changed, 26 insertions, 11 deletions
@@ -77,6 +77,6 @@ SUBHOOK_EXPORT void SUBHOOK_API subhook_set_flags(struct subhook *hook, int flag #include "subhook_linux.c" #endif -#if defined SUBHOOK_X86 +#if defined SUBHOOK_X86 || defined SUBHOOK_X86_64 #include "subhook_x86.c" #endif @@ -30,6 +30,8 @@ #if defined _M_IX86 || defined __i386__ #define SUBHOOK_X86 +#elif defined _M_AMD64 || __amd64__ + #define SUBHOOK_X86_64 #else #error Unsupported architecture #endif @@ -56,10 +58,14 @@ #endif #if !defined SUBHOOK_API - #if defined SUBHOOK_WINDOWS - #define SUBHOOK_API __cdecl - #elif defined SUBHOOK_LINUX - #define SUBHOOK_API __attribute__((cdecl)) + #if defined SUBHOOK_X86 + #if defined SUBHOOK_WINDOWS + #define SUBHOOK_API __cdecl + #elif defined SUBHOOK_LINUX + #define SUBHOOK_API __attribute__((cdecl)) + #endif + #else + #define SUBHOOK_API #endif #endif @@ -236,6 +242,6 @@ private: bool installed_; }; -#endif +#endif /* __cplusplus */ #endif /* SUBHOOK_H */ diff --git a/subhook_x86.c b/subhook_x86.c index 428e958..1257bd8 100644 --- a/subhook_x86.c +++ b/subhook_x86.c @@ -28,10 +28,19 @@ #include <stdlib.h> #include <string.h> +#ifdef _WIN32 + #if defined SUBHOOK_X86 + typedef __int32 intptr_t; + #elif defined SUBHOOK_X86_64 + typedef __int64 intptr_t; + #endif +#else + #include <stdint.h> +#endif + #include "subhook.h" #include "subhook_private.h" -/* 1 byte for opcode + 4 for address */ #define SUBHOOK_JUMP_SIZE 5 struct subhook_x86 { @@ -52,7 +61,7 @@ void subhook_arch_free(struct subhook *hook) { SUBHOOK_EXPORT int SUBHOOK_API subhook_install(struct subhook *hook) { static const unsigned char jmp = 0xE9; void *src, *dst; - int offset; + intptr_t offset; if (subhook_is_installed(hook)) return -EINVAL; @@ -67,8 +76,8 @@ SUBHOOK_EXPORT int SUBHOOK_API subhook_install(struct subhook *hook) { memcpy(src, &jmp, sizeof(jmp)); /* jump address is relative to next instruction */ - offset = (int)dst - ((int)src + SUBHOOK_JUMP_SIZE); - memcpy((void*)((int)src + 1), &offset, SUBHOOK_JUMP_SIZE - sizeof(jmp)); + offset = (intptr_t)dst - ((intptr_t)src + SUBHOOK_JUMP_SIZE); + memcpy((void*)((intptr_t)src + 1), &offset, SUBHOOK_JUMP_SIZE - sizeof(jmp)); subhook_set_flags(hook, subhook_get_flags(hook) | SUBHOOK_FLAG_INSTALLED); @@ -87,7 +96,7 @@ SUBHOOK_EXPORT int SUBHOOK_API subhook_remove(struct subhook *hook) { SUBHOOK_EXPORT void *SUBHOOK_API subhook_read_dst(void *src) { if (*(unsigned char*)src == 0xE9) - return (void *)(*(int *)((int)src + 1) + (int)src + SUBHOOK_JUMP_SIZE); + return (void *)(*(intptr_t *)((intptr_t)src + 1) + (intptr_t)src + SUBHOOK_JUMP_SIZE); return NULL; } |