Finding exposed methods in native libraries to access over JNA / JNI?

老子叫甜甜 提交于 2019-12-08 05:52:20

问题


Hi : I wanted to use JNA to access some functions in a native library.

1) How can i introspect the native library files (.so files, for example) to see what methods are available ?

2) Is there a one-one mapping between the methods accessible in .so files and the C code built to compile those files?

3) Is JNA gauranteed to work in all cases where the only java/native interop involves calling native libraries from Java (I assume this is the classic use case for JNA) -- or is JNI sometimes required instead?


回答1:


1) depends.exe on windows, objdump, nm, et al. on *nix variants.

2) Most shared libraries are designed for C-style linkage. This generally means that you can look up addresses corresponding to symbols in the library, but the type (variable, constant, or function) and signature information (for functions) is not usually embedded in the library.

3) JNA uses a very few generalized JNI operations to perform all its magic: open shared libraries, look up symbols, read/write memory, call functions. There are very few situations where you would have to use JNI over JNA, at least when dealing with libraries with C linkage.



来源:https://stackoverflow.com/questions/14161355/finding-exposed-methods-in-native-libraries-to-access-over-jna-jni

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!