Skip to content

Commit

Permalink
x86 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Tungstwenty committed Jun 30, 2013
1 parent 71644d4 commit 6d7b427
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ LOCAL_C_INCLUDES += dalvik \
bionic/libstdc++/include

LOCAL_MODULE_TAGS := optional
LOCAL_CFLAGS += -DWITH_JIT -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION)
ifeq ($(strip $(WITH_JIT)),true)
LOCAL_CFLAGS += -DWITH_JIT
endif
LOCAL_CFLAGS += -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION)
LOCAL_MODULE := xposed
LOCAL_MODULE_STEM := app_process_xposed_sdk$(PLATFORM_SDK_VERSION)

Expand Down
6 changes: 6 additions & 0 deletions xposed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ bool xposedOnVmCreated(JNIEnv* env, const char* className) {
startClassName = className;

// disable some access checks
#ifdef __arm__
char asmReturnTrue[] = { 0x01, 0x20, 0x70, 0x47 };
#else
char asmReturnTrue[] = { 0x31, 0xC0, 0x40, 0xC3 };
#endif
replaceAsm((void*) &dvmCheckClassAccess, asmReturnTrue, sizeof(asmReturnTrue));
replaceAsm((void*) &dvmCheckFieldAccess, asmReturnTrue, sizeof(asmReturnTrue));
replaceAsm((void*) &dvmInSamePackage, asmReturnTrue, sizeof(asmReturnTrue));
Expand Down Expand Up @@ -303,7 +307,9 @@ static jobject xposedAddLocalReference(::Thread* self, Object* obj) {
}

static void replaceAsm(void* function, char* newCode, int len) {
#ifdef __arm__
function = (void*)((int)function & ~1);
#endif
void* pageStart = (void*)((int)function & ~(PAGESIZE-1));
mprotect(pageStart, PAGESIZE, PROT_READ | PROT_WRITE | PROT_EXEC);
memcpy(function, newCode, len);
Expand Down
6 changes: 6 additions & 0 deletions xposedtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include <sys/mman.h>

static void replaceAsm(void* function, char* newCode, int len) {
#ifdef __arm__
function = (void*)((int)function & ~1);
#endif
void* pageStart = (void*)((int)function & ~(PAGESIZE-1));
mprotect(pageStart, PAGESIZE, PROT_READ | PROT_WRITE | PROT_EXEC);
memcpy(function, newCode, len);
Expand All @@ -25,7 +27,11 @@ int main(int argc, const char* const argv[]) {
return 1;
}

#ifdef __arm__
char asmReturn42[] = { 42, 0x20, 0x70, 0x47 };
#else
char asmReturn42[] = { 0xB8, 42, 0x00, 0x00, 0x00, 0xC3 };
#endif
replaceAsm((void*) asmReplaceTest, asmReturn42, sizeof(asmReturn42));

result = asmReplaceTest();
Expand Down

0 comments on commit 6d7b427

Please sign in to comment.