Search code examples
javanativenative-code

is it possible to get native library information once get loaded


Is it possible to get information about Native library, Once got loaded for example architecture of library(32-bit or 64-bit) from java.

Purpose: to display library version and architecture of library to user at runtime.


Solution

  • All native libraries (Windows EXE, DLL, OCX, SYS etc.) are in PE format. Significance of PE files is, the data structures on disk are the same data structures used in memory.

    Loading an executable into memory (for example, by calling LoadLibrary) is primarily a matter of mapping certain ranges of a PE file into the address space.

    The central location where the PE format (as well as COFF files) is described is WINNT.H. Within this header file, you'll find nearly every structure definition, enumeration, and #define needed to work with PE files or the equivalent structures in memory.

    There's a PE field called CHARACTERESTICS at offset 0x0FE, there are numerous characterestics like IMAGE_FILE_32BIT_MACHINE , IMAGE_FILE_EXECUTABLE_IMAGE. IMAGE_FILE_32BIT_MACHINE (0x100) is for 32 bit DLL/EXE.

    You can use Java's Reflection API to figure it out. Example can help you -

    http://www.devdaily.com/java/jwarehouse/scala/src/msil/ch/epfl/lamp/compiler/msil/PEType.java.shtml