diff options
-rw-r--r-- | subhook_linux.c | 2 | ||||
-rw-r--r-- | subhook_private.h | 2 | ||||
-rw-r--r-- | subhook_windows.c | 2 | ||||
-rw-r--r-- | subhook_x86.c | 24 |
4 files changed, 19 insertions, 11 deletions
diff --git a/subhook_linux.c b/subhook_linux.c index 3202cf6..75fb03c 100644 --- a/subhook_linux.c +++ b/subhook_linux.c @@ -29,7 +29,7 @@ #include <unistd.h> #include <sys/mman.h> -void *subhook_unprotect(void *address, size_t size) { +void *subhook_unlock(void *address, size_t size) { intptr_t pagesize; pagesize = sysconf(_SC_PAGESIZE); diff --git a/subhook_private.h b/subhook_private.h index 3c6c461..ee6727d 100644 --- a/subhook_private.h +++ b/subhook_private.h @@ -33,6 +33,6 @@ struct subhook { void *dst; }; -void *subhook_unprotect(void *address, size_t size); +void *subhook_unlock(void *address, size_t size); #endif /* SUBHOOK_PRIVATE_H */ diff --git a/subhook_windows.c b/subhook_windows.c index 2968188..fc8a133 100644 --- a/subhook_windows.c +++ b/subhook_windows.c @@ -26,7 +26,7 @@ #include <stddef.h> #include <windows.h> -void *subhook_unprotect(void *address, size_t size) { +void *subhook_unlock(void *address, size_t size) { DWORD old; if (VirtualProtect(address, size, PAGE_EXECUTE_READWRITE, &old) == 0) diff --git a/subhook_x86.c b/subhook_x86.c index 18ba6c5..a8d9a43 100644 --- a/subhook_x86.c +++ b/subhook_x86.c @@ -72,15 +72,21 @@ SUBHOOK_EXPORT int SUBHOOK_API subhook_install(subhook_t hook) { return -EINVAL; if (!hook->unlocked) { - subhook_unprotect(hook->src, sizeof(jmp_instr)); - hook->unlocked = 1; + subhook_unlock(hook->src, sizeof(jmp_instr)); + hook->unlocked = 1; } - memcpy(((struct subhook_x86 *)hook)->code, hook->src, sizeof(jmp_instr)); - memcpy(hook->src, &jmp_instr, sizeof(jmp_instr)); + memcpy(((struct subhook_x86 *)hook)->code, + hook->src, + sizeof(jmp_instr)); + memcpy(hook->src, + &jmp_instr, + sizeof(jmp_instr)); - offset = (intptr_t)hook->dst - ((intptr_t)hook->src + sizeof(jmp_instr)); - memcpy((void *)((intptr_t)hook->src + sizeof(jmp_opcode)), &offset, + offset = (intptr_t)hook->dst - ( + (intptr_t)hook->src + sizeof(jmp_instr)); + memcpy((void *)((intptr_t)hook->src + sizeof(jmp_opcode)), + &offset, sizeof(jmp_instr) - sizeof(jmp_opcode)); hook->installed = 1; @@ -91,7 +97,8 @@ SUBHOOK_EXPORT int SUBHOOK_API subhook_remove(subhook_t hook) { if (!hook->installed) return -EINVAL; - memcpy(hook->src, ((struct subhook_x86 *)hook)->code, + memcpy(hook->src, + ((struct subhook_x86 *)hook)->code, sizeof(jmp_instr)); hook->installed = 0; @@ -106,7 +113,8 @@ SUBHOOK_EXPORT void *SUBHOOK_API subhook_read_dst(void *src) { if (opcode != jmp_opcode) return NULL; - memcpy(&offset, (void *)((intptr_t)src + sizeof(jmp_opcode)), + memcpy(&offset, + (void *)((intptr_t)src + sizeof(jmp_opcode)), sizeof(offset)); return (void *)(offset + (intptr_t)src + sizeof(jmp_instr)); } |