I'm gonna write a c program that loads a native android library (.so) this is my code:
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
typedef void (*target_func)(JNIEnv* env, jobject obj, int x);
int main(int argc, char ** argv) {
char *lib = "/path/to/lib.so"
void *handle = dlopen(lib, RTLD_LAZY);
if (NULL == handle) {
printf("load library error\n");
return 1;
}
void *offset_func = dlsym(handle, "Java_com_example_test_MainActivity_myFunc");
if (NULL == offset_func) {
printf("getprocaddress error\n");
return 1;
}
target_func target = (target_func)((unsigned char *)offset_func);
target(nullptr, nullptr, 10); // Here i need to pass JNIEnv pointer
return 0;
}
The only thing that i need is to pass the JNIEnv (the first parameter), Is there any way ??
My program runs on android emulator and because of that i tried to resolve JNIEnv from libart.so but i wasn't success to disassemble libart.so in IDA Pro.
I know when we launch an apk in our device, the ART (or Dalvik) creates JNIEnv for the app but i don't know how can i emulate and create JNIEnv similar to ART.