Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooking /system/bin/linker #43

Closed
jacobvhall opened this issue May 13, 2019 · 1 comment
Closed

Hooking /system/bin/linker #43

jacobvhall opened this issue May 13, 2019 · 1 comment

Comments

@jacobvhall
Copy link

Hello, I want to hook usages of open in linker, but it is not working. I can hook open in other libs, like libart but not in the linker. Is this not possible with xHook?

I want to hook this open specifically http://androidxref.com/5.0.0_r2/xref/bionic/linker/linker.cpp#723

Thank you for your wonderful tool.

int (*old_open)(const char *pathname, int flags, mode_t mode);
int my_open(const char *pathname, int flags, mode_t mode) {

    int result = old_open(pathname, flags, mode);
    __android_log_print(ANDROID_LOG_DEBUG, "xHook", "open - %s, %d, result %d", pathname, flags, result);
    return result;
}

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
    JNIEnv* env;
    if (vm->GetEnv((void**)&env, JNI_VERSION_1_6) != JNI_OK) {
        return JNI_ERR; // JNI version not supported.
    }
    __android_log_print(ANDROID_LOG_DEBUG, "Culet", " JNI_OnLoad");
    xhook_enable_debug(1);
    xhook_enable_sigsegv_protection(0);
    xhook_register(".*\\linker$", "open", (void *)my_open, (void**)&old_open);
    xhook_refresh(0);
    return  JNI_VERSION_1_6;
}

@caikelun
Copy link
Collaborator

No. xHook (or any other PLT hook tools) does not apply to linker.

Linker does not dependent on any dynamic libraries in runtime ...

arm-linux-androideabi-readelf -d ./linker | grep NEEDED

... even libc.so.
http://androidxref.com/5.0.0_r2/xref/bionic/linker/Android.mk#49

LOCAL_STATIC_LIBRARIES := libc_nomalloc

Because there is no other dynamic linker that can help the /system/bin/linker load these libraries.

There is almost no relocation info in linker ...

arm-linux-androideabi-readelf -r ./linker

... and this knocked down PLT hook approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants