Injecting class into the JNIEnv in android jni

  android, apktool, c++, java

C++ code:

extern "C" JNIEXPORT void JNICALL
Java_com_example_afl_MainActivity_stringFromJNI(
        JNIEnv* env,
        jobject /* this */) {
    
    // env->DefineClass(...)
}

I’m calling the above function from Java side code:

public class MainActivity extends AppCompatActivity {

    static {
        System.loadLibrary("native-lib");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        stringFromJNI();  // call cpp function


    }

    public native String stringFromJNI();
}

My question is about the env->DefineClass(...) in cpp code.
As you see the android VM passes JNIEnv *env to my native function, so by using env pointer i have access to all of my java classes and i can use them (i have access to all of my java side classes and i can create instance object and do everything).
But how can access to a class which is in another apk and it is in another package name ?
I wanna decompile the target apk and copy that class and inject that class to my env using the env->DefineClass function but i don’t know how can i complete this task.
Thanks for any reply 🙂

Source: Windows Questions C++

LEAVE A COMMENT