void *handle = dlopen("/data/local/tmp/libnative-lib.so", RTLD_LAZY);

if (!handle) {
    printf("\nFailed to load library\n");

void *offset = dlsym(handle, "Java_com_example_test_MainActivity_testFunc");

I'm using the above code to call a function inside an android native library (.so) from an executable c program which runs on android devices and compiled using Android NDK.
The input arguments of the function is something like this:

typedef jstring (*target_func)(JNIEnv* env, jobject oj, jstring path);

I have simulated the JNIEnv using some tricks and i have the first parameter.
The second parameter i will pass NULL (because i checked the parameters in IDA Pro and i know the target function won't use the second argument) and the third parameter doesn't matter for us (it is ok).

When i call this function my program crashed because the target function uses env->FindClass to find some java classes but my env (that i have simulated) doesn't contain that java class.
How can i inject (or another trick) to add that java class into my env ?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.