2

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.

twid
  • 6,368
  • 4
  • 32
  • 50

2 Answers2

2

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

Mohsin
  • 852
  • 8
  • 28
  • that's promising... Now need to get structure for other OS'' as java has to be platform independent – twid Sep 21 '12 at 10:38
0

You can use the system property

System.getProperty("java.version");

to get the Java version.

You can use the internal system property

System.getProperty("sun.arch.data.model")

to get the data model. The response will be "32" for a 32 bit library "64" for a 64 bit library, and "unknown" for an unknown data model.

This internal system property only returns a value for an Oracle JVM.

Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111
  • this is not what i am looking for...to be precise i need is get this from library itself... – twid Sep 21 '12 at 08:01