# Android Native Library - How to match java references to sub_XXX function (static way)

I'm currently learning how native functions are implemented among the ELF SO files contained inside an APK. I'm using IDA.

Native calls are always achieved in this way.

// First load the library
class myClass{
public myClass(){
super();
//then declare the methods
}
public static native int nativeMethod(byte[] arg0, boolean arg1) ;
}
void a(){
// then uses it
ret = this.nativeMethod(byte,bool) ;
}


According to my little experiences in JNI, when looking to library-native.so using a disassembler I should see something like Java_package_name_libname_class_NativeMethod among the exported function.

I cannot see any of these elements. When I'm searching the desired function (nativeMethod in the past example) inside the disassembled code, I do not find any clue.

I wonder how Dalvik process manages to call the right function when a native call is performed, and how can I find myself the source code of the desired functions ?

Thanks

nm --defined-only library-native.so
nm library-native.so : no symbols
readelf -s library-native.so | grep nativeMethod // gives no output
//The only JNI related function
nm -D --defined-only library-native.so | grep JNI

• if you run nm on the file, does it list the expected symbols? – Igor Skochinsky Apr 21 '17 at 12:49
• Hey Igor, I add the nm and readelf output. Thanks for pointing this out ! – deadeert Apr 26 '17 at 13:18

In both cases the action probably happens in the JNI_onLoad function. You will need to debug it to see what's going on.
• Thanks. Command nm -Du --defined-only native-library.so | grep -i registernative outputs nothing. Same for readelf -s native-library.so | grep -i registernative command. Are you agree with me when I conclude that option 2 you pointed is right in this case ? – deadeert Apr 26 '17 at 14:26
• RegisterNatives is a field (function pointer) in the JNIEnv structure (first argument passed to JNI_onLoad). You won't see the field names in the binary, just numerical offsets. – Igor Skochinsky Apr 26 '17 at 14:28