diff --git a/README.md b/README.md index e635e65..43366af 100644 --- a/README.md +++ b/README.md @@ -42,21 +42,9 @@ Android NDK = build the hijack tool = ``` cd hijack -cd jni ndk-build -cd .. -adb push libs/armeabi/hijack -cd .. -``` - -= build the instrumentation base code = - -``` -cd instruments -cd base -cd jni -ndk-build -cd .. +adb push libs/armeabi/hijack /data/local/tmp/ +adb shell chmod 755 /data/local/tmp/hijack cd .. ``` @@ -64,10 +52,9 @@ cd .. ``` cd example -cd jni ndk-build -cd .. adb push libs/armeabi/libexample.so /data/local/tmp/ +adb shell chmod 755 /data/local/tmp/libexample.so ``` === How to Run === @@ -78,7 +65,8 @@ su cd /data/local/tmp # GET PID from com.android.phone ./hijack -d -p PID -l /data/local/tmp/libexample.so -cat adbi_example.log +exit +adb logcat (see log entries hook-epoll) ``` output should look similar to: diff --git a/instruments/base/hook.c b/instruments/base/hook.c index 1c13fd3..a718ead 100644 --- a/instruments/base/hook.c +++ b/instruments/base/hook.c @@ -48,11 +48,11 @@ int hook_direct(struct hook_t *h, unsigned int addr, void *hookf) { int i; - log("addr = %x\n", addr) - log("hookf = %x\n", hookf) + log("addr = %x\n", (unsigned int)addr) + log("hookf = %x\n", (unsigned int)hookf) if ((addr % 4 == 0 && (unsigned int)hookf % 4 != 0) || (addr % 4 != 0 && (unsigned int)hookf % 4 == 0)) - log("addr 0x%x and hook 0x%x\n don't match!\n", addr, hookf) + log("addr 0x%x and hook 0x%x\n don't match!\n", (unsigned int)addr, (unsigned int)hookf) //log("ARM\n") h->thumb = 0; @@ -81,11 +81,11 @@ int hook(struct hook_t *h, int pid, char *libname, char *funcname, void *hook_ar return 0; } - log("hooking: %s = 0x%x ", funcname, addr) + log("hooking: %s = 0x%x ", funcname, (unsigned int)addr) strncpy(h->name, funcname, sizeof(h->name)-1); if (addr % 4 == 0) { - log("ARM using 0x%x\n", hook_arm) + log("ARM using 0x%x\n", (unsigned int)hook_arm) h->thumb = 0; h->patch = (unsigned int)hook_arm; h->orig = addr; @@ -99,9 +99,9 @@ int hook(struct hook_t *h, int pid, char *libname, char *funcname, void *hook_ar } else { if ((unsigned long int)hook_thumb % 4 == 0) - log("warning hook is not thumb 0x%x\n", hook_thumb) + log("warning hook is not thumb 0x%x\n", (unsigned int)hook_thumb) h->thumb = 1; - log("THUMB using 0x%x\n", hook_thumb) + log("THUMB using 0x%x\n", (unsigned int)hook_thumb) h->patch = (unsigned int)hook_thumb; h->orig = addr; h->jumpt[1] = 0xb4; diff --git a/instruments/example/epoll.c b/instruments/example/epoll.c index e77961e..8e1ce30 100644 --- a/instruments/example/epoll.c +++ b/instruments/example/epoll.c @@ -8,6 +8,7 @@ * License: LGPL v2.1 * */ +// Modified by B.Kerler to support Android Logcat + NDK9 #define _GNU_SOURCE #include @@ -30,7 +31,10 @@ #include "../base/base.h" #undef log +#include +#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "hook-epoll", __VA_ARGS__)) +#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "hook-epoll", __VA_ARGS__)) #define log(...) \ {FILE *fp = fopen("/data/local/tmp/adbi_example.log", "a+");\ fprintf(fp, __VA_ARGS__);\ @@ -56,7 +60,7 @@ extern int my_epoll_wait_arm(int epfd, struct epoll_event *events, int maxevents */ static void my_log(char *msg) { - log(msg) + LOGI("%s",msg); } int my_epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout) @@ -68,10 +72,10 @@ int my_epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeo int res = orig_epoll_wait(epfd, events, maxevents, timeout); if (counter) { hook_postcall(&eph); - log("epoll_wait() called\n"); + LOGI("epoll_wait() called\n"); counter--; if (!counter) - log("removing hook for epoll_wait()\n"); + LOGI("removing hook for epoll_wait()\n"); } return res; @@ -81,7 +85,7 @@ void my_init(void) { counter = 3; - log("%s started\n", __FILE__) + LOGI("%s started\n", __FILE__); set_logfunction(my_log); diff --git a/instruments/example/epoll_arm.c b/instruments/example/epoll_arm.c index bf916a8..118f191 100644 --- a/instruments/example/epoll_arm.c +++ b/instruments/example/epoll_arm.c @@ -11,6 +11,7 @@ #include #include +#include extern int my_epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout); diff --git a/instruments/example/jni/Android.mk b/instruments/example/jni/Android.mk index 73b392f..bd5754f 100644 --- a/instruments/example/jni/Android.mk +++ b/instruments/example/jni/Android.mk @@ -17,9 +17,8 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := libexample -LOCAL_SRC_FILES := ../epoll.c ../epoll_arm.c.arm -LOCAL_LDLIBS := -L./libs -ldl -ldvm -lbase -LOCAL_LDLIBS := -Wl,--start-group ../../base/obj/local/armeabi/libbase.a -Wl,--end-group +LOCAL_SRC_FILES := ../epoll.c ../epoll_arm.c.arm ../../base/util.c ../../base/hook.c ../../base/base.c +LOCAL_LDLIBS := -L./libs -ldl -llog LOCAL_CFLAGS := -g include $(BUILD_SHARED_LIBRARY)