Android - NDK Shared libraries extracting relevant

2020-03-30 16:36发布

问题:

I'm trying to extract the relevant symbols from a shared library that contains JNI glue code, but nm doesn't seem to help enough. The method signatures aren't there so I don't know which arguments to pass.

Any ideas?

bash-3.2# ./arm-linux-androideabi-nm -D ~/Desktop/backup/whiteBox/libamplayerjni.so | grep Java
00030d6c T Java_com_farcore_playerservice_AmPlayer_GL2XScale
00030da8 T Java_com_farcore_playerservice_AmPlayer_close
00030d74 T Java_com_farcore_playerservice_AmPlayer_disable2X2XYScale
...

obdump isnt of much help either

bash-3.2# ./arm-linux-androideabi-objdump -TC ~/Desktop/backup/whiteBox/libamplayerjni.so | grep Java
00030c00 g    DF .text  00000008 Java_com_farcore_playerservice_AmPlayer_getDivxInfo
00030c08 g    DF .text  00000008 Java_com_farcore_playerservice_AmPlayer_setIVolume
00030c10 g    DF .text  00000008 Java_com_farcore_playerservice_AmPlayer_mute
00030c18 g    DF .text  00000008 Java_com_farcore_playerservice_AmPlayer_unmute
00030c20 g    DF .text  00000008 Java_com_farcore_playerservice_AmPlayer_setVideoBlackOut

回答1:

As JNI use C calling convention (cdecl), there are no arguments information in the function signature. You need to analysis the corresponding java(dalvik) code to find out the arguments type.

Here is my jni library:

00001408 g    DF .text  0000000a Java_info_kghost_android_openvpn_FileDescriptorHolder_close
00001a14 g    DF .text  00000198 Java_info_kghost_android_openvpn_ManagementSocket_read__ILjava_nio_ByteBuffer_2II
00001414 g    DF .text  0000000c Java_info_kghost_android_openvpn_ManagementSocket_shutdown
000017c4 g    DF .text  00000250 Java_info_kghost_android_openvpn_ManagementSocket_read__ILjava_nio_ByteBuffer_2IILinfo_kghost_android_openvpn_FileDescriptorHolder_2
0000142c g    DF .text  00000200 Java_info_kghost_android_openvpn_ManagementSocket_write__ILjava_nio_ByteBuffer_2IILinfo_kghost_android_openvpn_FileDescriptorHolder_2
00001420 g    DF .text  0000000a Java_info_kghost_android_openvpn_ManagementSocket_close
0000162c g    DF .text  00000198 Java_info_kghost_android_openvpn_ManagementSocket_write__ILjava_nio_ByteBuffer_2II
00001bd4 g    DF .text  000000d4 Java_info_kghost_android_openvpn_ManagementSocket_open

if there is no overload method, the signature won't contain arguments information; if the method is overloaded, the signature will contain arguments information in function name.

And you need to load the jni library explicitly before using the native method:

System.loadLibrary("your-library-name");

Make sure your library is placed inside LD_LIBRARY_PATH, /lib directory on Android, check the mmap (/proc/pid/maps) to see if it is loaded successful.