diff options
author | Zeex <zeex@rocketmail.com> | 2016-08-27 04:55:56 +0600 |
---|---|---|
committer | Zeex <zeex@rocketmail.com> | 2016-08-27 04:56:09 +0600 |
commit | cdb4c0e8a89a7d0f56523ce748d3dd30e1e7cffb (patch) | |
tree | 194035a0eecd1d07082fc1ad7604f12affc7756d /subhook_x86.c | |
parent | 93d167a7359a9c76ed9379b9022db0aa5cd91407 (diff) | |
download | subhook-cdb4c0e8a89a7d0f56523ce748d3dd30e1e7cffb.zip subhook-cdb4c0e8a89a7d0f56523ce748d3dd30e1e7cffb.tar.gz subhook-cdb4c0e8a89a7d0f56523ce748d3dd30e1e7cffb.tar.bz2 |
Make sure offset fits in 32 bits
Diffstat (limited to 'subhook_x86.c')
-rw-r--r-- | subhook_x86.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/subhook_x86.c b/subhook_x86.c index e00d9a5..46645cc 100644 --- a/subhook_x86.c +++ b/subhook_x86.c @@ -33,9 +33,12 @@ #include "subhook_private.h" #ifdef SUBHOOK_WINDOWS + #define INT32_MAX 0x7fffffff + #define INT32_MIN (-INT32_MAX - 1) typedef unsigned __int8 uint8_t; typedef __int32 int32_t; typedef unsigned __int32 uint32_t; + typedef __int64 int64_t; #if SUBHOOK_BITS == 32 typedef __int32 intptr_t; typedef unsigned __int32 uintptr_t; @@ -247,9 +250,13 @@ static size_t subhook_get_jmp_size(subhook_options_t options) { static void subhook_make_jmp32(void *src, void *dst) { struct subhook_jmp32 *jmp = (struct subhook_jmp32 *)src; + int64_t offset; + + offset = ((intptr_t)dst - ((intptr_t)src + sizeof(*jmp))); + assert(offset > INT32_MIN && offset < INT32_MAX); jmp->opcode = JMP_OPCODE; - jmp->offset = (int32_t)((intptr_t)dst - ((intptr_t)src + sizeof(*jmp))); + jmp->offset = (int32_t)offset; } #if SUBHOOK_BITS == 64 |