aboutsummaryrefslogtreecommitdiff
path: root/subhook_x86.c
diff options
context:
space:
mode:
authorZeex <zeex@rocketmail.com>2018-09-06 23:17:54 +0600
committerZeex <zeex@rocketmail.com>2018-09-06 23:18:07 +0600
commitb6226952edf11318b7bb8c0e6d7994ddce8e7ca2 (patch)
treed8e5d1c5379bdb222f72ed9230088be7ec812906 /subhook_x86.c
parent753673f7f71ccd285d90d725996e0e4dea3c51ce (diff)
downloadsubhook-b6226952edf11318b7bb8c0e6d7994ddce8e7ca2.zip
subhook-b6226952edf11318b7bb8c0e6d7994ddce8e7ca2.tar.gz
subhook-b6226952edf11318b7bb8c0e6d7994ddce8e7ca2.tar.bz2
Don't check for jmp offset overflow in 32-bit build (#33)
Diffstat (limited to 'subhook_x86.c')
-rw-r--r--subhook_x86.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/subhook_x86.c b/subhook_x86.c
index 909e900..549225c 100644
--- a/subhook_x86.c
+++ b/subhook_x86.c
@@ -50,6 +50,7 @@
#include <stdint.h>
#endif
+#define ABS(x) ((x) > 0 ? (x) : (-(x)))
#define MAX_INSN_LEN 15 /* maximum length of x86 instruction */
#define JMP_OPCODE 0xE9
@@ -280,16 +281,15 @@ static int subhook_make_jmp32(void *src, void *dst) {
struct subhook_jmp32 *jmp = (struct subhook_jmp32 *)src;
intptr_t src_addr = (intptr_t)src;
intptr_t dst_addr = (intptr_t)dst;
- int64_t distance;
+#ifdef SUBHOOK_X86_64
+ int64_t distance = ABS(src_addr - dst_addr);
+#endif
- if (src_addr > dst_addr) {
- distance = src_addr - dst_addr;
- } else {
- distance = dst_addr - src_addr;
- }
+#ifdef SUBHOOK_X86_64
if (distance < INT32_MIN || distance > INT32_MAX) {
return -EOVERFLOW;
}
+#endif
jmp->opcode = JMP_OPCODE;
jmp->offset = (int32_t)(dst_addr - (src_addr + sizeof(*jmp)));