Skip to content

Commit

Permalink
FIX: Invalid len calculation of mprotect call.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Obser committed Mar 19, 2015
1 parent d018132 commit 78e11f5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/src/main/jni/hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@

JNIEXPORT void JNICALL Java_de_larma_arthook_Native_munprotect(JNIEnv *env, jclass _cls, jlong addr, jlong len) {
int pagesize = sysconf(_SC_PAGESIZE);

int i = mprotect((void *)(addr-(addr%pagesize)), (size_t)len, PROT_READ | PROT_WRITE | PROT_EXEC);
int alignment = (addr%pagesize);

int i = mprotect((void *)(addr-alignment), (size_t)(len+alignment), PROT_READ | PROT_WRITE | PROT_EXEC);
if (i == -1) {
LOGV("mprotect failed: %d", errno);
}
Expand Down

0 comments on commit 78e11f5

Please sign in to comment.