Skip to content

Commit

Permalink
Fix crash when the target address space covers two memory pages. Than…
Browse files Browse the repository at this point in the history
  • Loading branch information
caikelun committed May 9, 2018
1 parent d5011c7 commit f139e19
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions libxhook/jni/xh_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
#include "xh_log.h"

#define PAGE_START(addr) ((addr) & PAGE_MASK)
#define PAGE_END(addr) (PAGE_START(addr) + PAGE_SIZE)
#define PAGE_END(addr) (PAGE_START(addr + sizeof(uintptr_t) - 1) + PAGE_SIZE)
#define PAGE_COVER(addr) (PAGE_END(addr) - PAGE_START(addr))

int xh_util_get_mem_protect(uintptr_t addr, size_t len, const char *pathname, unsigned int *prot)
{
Expand Down Expand Up @@ -108,7 +109,7 @@ int xh_util_get_addr_protect(uintptr_t addr, const char *pathname, unsigned int

int xh_util_set_addr_protect(uintptr_t addr, unsigned int prot)
{
if(0 != mprotect((void *)PAGE_START(addr), PAGE_SIZE, (int)prot))
if(0 != mprotect((void *)PAGE_START(addr), PAGE_COVER(addr), (int)prot))
return 0 == errno ? XH_ERRNO_UNKNOWN : errno;

return 0;
Expand Down
2 changes: 1 addition & 1 deletion libxhook/jni/xh_version.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#define XH_VERSION_MAJOR 1
#define XH_VERSION_MINOR 1
#define XH_VERSION_EXTRA 5
#define XH_VERSION_EXTRA 6

#define XH_VERSION ((XH_VERSION_MAJOR << 16) | (XH_VERSION_MINOR << 8) | (XH_VERSION_EXTRA))

Expand Down
2 changes: 1 addition & 1 deletion xhookwrapper/xhook/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'maven'

def version = "1.1.5"
def version = "1.1.6"

android {
compileSdkVersion 26
Expand Down

0 comments on commit f139e19

Please sign in to comment.