In my project i am implementing a JNI agent which would rebind all java native methods to my customized methods in my custom ".c" file. So since JNI agent binds native methods in runtime, i will be only talking about runtime solution.
When JNI binds native methods, following function gets called:
void JNICALL NativeMethodBind(jvmtiEnv *jvmti_env,
JNIEnv* jni_env,
jthread thread,
jmethodID method,
void* address,
void** new_address_ptr)
At this point a java method gets bound to address in void* address
unless you put something into void** new_address_ptr
. Thus, in order to rebind a curtain method , i just need to overwrite the new_address_ptr
- variable.
Now, i want to rebind the functions to function-addresses in my custom .c file which contains several hundreds of different methods. And this is where i am stuck. While having the .c file and the string names of the functions, how do i get the addresses of the correspondin functions in my .c file?
I am running the project on windows64 machine with gcc 4.9.1