Search code examples
androidjava-native-interfacereverse-engineering

Finding function pointer if the Java_... naming is not used


I'm debugging an android application and am confusing about one android shared library and here i wanna explain the problem.

There is a native function defined in java code (java side) like this:

public static native void nativeInitialize();

Package:

package com.example.ExClass;

I loaded the shared library in IDA Pro.
I thought that i can find that function in exported functions and it should be something like this Java_com_example_ExClass_nativeInitialize
But the function is not in export list and as i debugged the java side codes, i know the function is calling from java but i don't know how it is working ?!


Solution

  • If the name-mangling scheme (Java_...) is not used, then it is possible the library uses the RegisterNatives approach to associate method names with function pointers. Try searching for structs that embed the string "nativeInitialize", they should be the methods argument to RegisterNatives. Look through the JNI_OnLoad function for the call site.

    On Aarch64 assembly it should look like:

    ldr x4, [x8,#1720] # RegisterNatives is the 215th member, times 8 bytes per pointer
    bl  x4             # Could also be a br if this was the last call of the function