0
votes

I am attempting to get the Version info for a .exe using the Version.dll and JNA.

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
import com.sun.jna.win32.W32APIOptions;

/**
 *
 * @author geverding
 */
public interface Version extends Library {

Version INSTANCE = (Version) Native.loadLibrary("Version", Version.class, W32APIOptions.UNICODE_OPTIONS);

public int GetFileVersionInfoSizeW(String lptstrFilename);

public int GetFileVersionInfo(String lptstrFilename, int dwHandle, int dwLen, PointerByReference lpData);

public int VerQueryValue(PointerByReference pBlock, String lpSubBlock, PointerByReference lplpBuffer, IntByReference puLen);

}

...in the Main method

int dwlen = Version.INSTANCE.GetFileVersionInfoSizeW("C:\\Test\\VNCSetup.EXE");

At this point the JRE throws a exception

#

A fatal error has been detected by the Java Runtime Environment:

#

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000007fefc6e14ff,

pid=3884, tid=2248 #

JRE version: 6.0_26-b03

Java VM: Java HotSpot(TM) 64-Bit Server VM (20.1-b02 mixed mode

windows-amd64 compressed oops)

Problematic frame:

C [Version.dll+0x14ff]

#

If you would like to submit a bug report, please visit:

http://java.sun.com/webapps/bugreport/crash.jsp

The crash happened outside the Java Virtual Machine in native code.

See problematic frame for where to report the bug.

#

--------------- T H R E A D ---------------

Current thread (0x000000000054c000): JavaThread "main" [_thread_in_native, id=2248, stack(0x00000000024e0000,0x00000000025e0000)]

siginfo: ExceptionCode=0xc0000005, writing address 0x00000001800161ca

Registers: RAX=0x00000000025df4d8, RBX=0x000000009c2e9678, RCX=0x0000000000000001, RDX=0x000000000774fda0 RSP=0x00000000025df330, RBP=0x00000000025df3b0, RSI=0x000000009c0a4258, RDI=0x0000000000000001 R8 =0x00000001800161ca, R9 =0x000000006da78189, R10=0x00000000025f79b2, R11=0x00000000025df380 R12=0x000000000774fda0, R13=0x000000009c2e9678, R14=0x00000000025df758, R15=0x000000000054c000 RIP=0x000007fefc6e14ff, EFLAGS=0x0000000000010206

Top of Stack: (sp=0x00000000025df330) 0x00000000025df330:
00000000025df388 00000000025df4d8 0x00000000025df340:
0000000000000008 cccccccccccccccc 0x00000000025df350:
00000000025df478 00000001800161e1 0x00000000025df360:
0000000000000000 00000000025df478 0x00000000025df370:
000000009c0a4258 0000000180016213 0x00000000025df380:
000000009c2e9678 00000001800161ca 0x00000000025df390:
0000000000540000 000000006da78189 0x00000000025df3a0:
00000000025f2cd6 000000000000000a 0x00000000025df3b0:
00000000025df380 000000006da7c399 0x00000000025df3c0:
00000000025df400 000000018000ec6a 0x00000000025df3d0:
000000018000e580 00000000025df408 0x00000000025df3e0:
0000000000000028 000000000000000a 0x00000000025df3f0:
00000000025df680 000007fefc6e15fc 0x00000000025df400:
cccccccccccccccc 00000000025df510 0x00000000025df410:
00000000025df680 00000000025df4c0 0x00000000025df420:
cccccccccccccccc cccccccccccccccc

Instructions: (pc=0x000007fefc6e14ff) 0x000007fefc6e14df: c3 90 90 90 90 90 90 90 90 48 89 5c 24 08 56 57 0x000007fefc6e14ef: 41 54 48 83 ec 30 4c 8b e2 8b f9 4d 85 c0 74 04 0x000007fefc6e14ff: 41 83 20 00 b9 01 00 00 00 ff 15 c2 4b 00 00 8b 0x000007fefc6e150f: d8 89 44 24 60 33 d2 44 8d 42 22 49 8b cc ff 15

Register to memory mapping:

RAX=0x00000000025df4d8 is pointing into the stack for thread: 0x000000000054c000 RBX=0x000000009c2e9678 is an oop {method} - klass: {other class} RCX=0x0000000000000001 is an unknown value RDX=0x000000000774fda0 is an unknown value RSP=0x00000000025df330 is pointing into the stack for thread: 0x000000000054c000 RBP=0x00000000025df3b0 is pointing into the stack for thread: 0x000000000054c000 RSI=0x000000009c0a4258 is an oop {instance class} - klass: {other class} RDI=0x0000000000000001 is an unknown value R8 =0x00000001800161ca is an unknown value R9 =0x000000006da78189 is an unknown value R10=0x00000000025f79b2 is an Interpreter codelet method entry point (kind = native) [0x00000000025f74c0, 0x00000000025f8380] 3776 bytes R11=0x00000000025df380 is pointing into the stack for thread: 0x000000000054c000 R12=0x000000000774fda0 is an unknown value R13=0x000000009c2e9678 is an oop {method} - klass: {other class} R14=0x00000000025df758 is pointing into the stack for thread: 0x000000000054c000 R15=0x000000000054c000 is a thread

Stack: [0x00000000024e0000,0x00000000025e0000], sp=0x00000000025df330, free space=1020k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) C [Version.dll+0x14ff] GetFileVersionInfoSizeExW+0x17

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code) j com.sun.jna.Native.invokeInt(JI[Ljava/lang/Object;)I+0 j com.sun.jna.Function.invoke([Ljava/lang/Object;Ljava/lang/Class;Z)Ljava/lang/Object;+333 j com.sun.jna.Function.invoke(Ljava/lang/Class;[Ljava/lang/Object;Ljava/util/Map;)Ljava/lang/Object;+214 j com.sun.jna.Library$Handler.invoke(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;+341 j $Proxy0.GetFileVersionInfoSize(Ljava/lang/String;)I+16 j windowsversion.WindowsVersion.main([Ljava/lang/String;)V+26 v ~StubRoutines::call_stub

--------------- P R O C E S S ---------------

Java Threads: ( => current thread ) 0x0000000006463800 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=2284, stack(0x0000000006d00000,0x0000000006e00000)] 0x000000000645f800 JavaThread "C2 CompilerThread1" daemon [_thread_blocked, id=3808, stack(0x0000000006c00000,0x0000000006d00000)] 0x000000000645e000 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=3780, stack(0x0000000006b00000,0x0000000006c00000)] 0x000000000644d000 JavaThread "JDWP Command Reader" daemon [_thread_in_native, id=2944, stack(0x0000000006a00000,0x0000000006b00000)] 0x0000000006449800 JavaThread "JDWP Event Helper Thread" daemon [_thread_blocked, id=744, stack(0x0000000006900000,0x0000000006a00000)] 0x0000000006443800 JavaThread "JDWP Transport Listener: dt_shmem" daemon [_thread_blocked, id=3336, stack(0x0000000006800000,0x0000000006900000)] 0x0000000000525000 JavaThread "Attach Listener" daemon [_thread_blocked, id=3244, stack(0x0000000006700000,0x0000000006800000)] 0x0000000000524800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=1784, stack(0x0000000006600000,0x0000000006700000)] 0x000000000050c000 JavaThread "Finalizer" daemon [_thread_blocked, id=3652, stack(0x0000000006300000,0x0000000006400000)] 0x0000000000508800 JavaThread "Reference Handler" daemon [_thread_blocked, id=2216, stack(0x0000000006200000,0x0000000006300000)] =>0x000000000054c000 JavaThread "main" [_thread_in_native, id=2248, stack(0x00000000024e0000,0x00000000025e0000)]

Other Threads: 0x0000000000502000 VMThread [stack: 0x0000000006100000,0x0000000006200000] [id=3596] 0x0000000006480000 WatcherThread [stack: 0x0000000006e00000,0x0000000006f00000] [id=3156]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap PSYoungGen total 28352K, used 2499K [0x00000000e0600000, 0x00000000e25a0000, 0x0000000100000000) eden space 24320K, 10% used [0x00000000e0600000,0x00000000e0870f18,0x00000000e1dc0000) from space 4032K, 0% used [0x00000000e21b0000,0x00000000e21b0000,0x00000000e25a0000) to
space 4032K, 0% used [0x00000000e1dc0000,0x00000000e1dc0000,0x00000000e21b0000) PSOldGen
total 64768K, used 0K [0x00000000a1200000, 0x00000000a5140000, 0x00000000e0600000) object space 64768K, 0% used [0x00000000a1200000,0x00000000a1200000,0x00000000a5140000) PSPermGen total 21248K, used 4506K [0x000000009c000000, 0x000000009d4c0000, 0x00000000a1200000) object space 21248K, 21% used [0x000000009c000000,0x000000009c466a90,0x000000009d4c0000)

Code Cache [0x00000000025e0000, 0x0000000002850000, 0x00000000055e0000) total_blobs=191 nmethods=7 adapters=146 free_code_cache=49918592 largest_free_block=8704

Dynamic libraries: 0x0000000000400000 - 0x000000000042e000 C:\Program Files\Java\jdk1.6.0_26\bin\java.exe 0x0000000077620000 - 0x00000000777cc000 C:\Windows\SYSTEM32\ntdll.dll 0x0000000077500000 - 0x000000007761f000 C:\Windows\system32\kernel32.dll 0x000007fefd840000 - 0x000007fefd8ab000 C:\Windows\system32\KERNELBASE.dll 0x000007fefdb70000 - 0x000007fefdc4b000 C:\Windows\system32\ADVAPI32.dll 0x000007feff5c0000 - 0x000007feff65f000 C:\Windows\system32\msvcrt.dll 0x000007feff5a0000 - 0x000007feff5bf000 C:\Windows\SYSTEM32\sechost.dll 0x000007fefda40000 - 0x000007fefdb6e000 C:\Windows\system32\RPCRT4.dll 0x000000006d890000 - 0x000000006e048000 C:\Program Files\Java\jdk1.6.0_26\jre\bin\server\jvm.dll 0x0000000077400000 - 0x00000000774fa000 C:\Windows\system32\USER32.dll 0x000007feff8c0000 - 0x000007feff927000 C:\Windows\system32\GDI32.dll 0x000007feff3b0000 - 0x000007feff3be000 C:\Windows\system32\LPK.dll 0x000007fefd970000 - 0x000007fefda3a000 C:\Windows\system32\USP10.dll 0x000007fefb090000 - 0x000007fefb0cb000 C:\Windows\system32\WINMM.dll 0x000007feff7e0000 - 0x000007feff80e000 C:\Windows\system32\IMM32.DLL 0x000007feff2a0000 - 0x000007feff3a9000 C:\Windows\system32\MSCTF.dll 0x000000006d800000 - 0x000000006d80e000 C:\Program Files\Java\jdk1.6.0_26\jre\bin\verify.dll 0x000000006d450000 - 0x000000006d477000 C:\Program Files\Java\jdk1.6.0_26\jre\bin\java.dll 0x00000000777f0000 - 0x00000000777f7000 C:\Windows\system32\PSAPI.DLL 0x000000006d4c0000 - 0x000000006d4f4000 C:\Program Files\Java\jdk1.6.0_26\jre\bin\jdwp.dll 0x000000006d6d0000 - 0x000000006d6d8000 C:\Program Files\Java\jdk1.6.0_26\jre\bin\npt.dll 0x000000006d850000 - 0x000000006d862000 C:\Program Files\Java\jdk1.6.0_26\jre\bin\zip.dll 0x000000006d300000 - 0x000000006d30a000 C:\Program Files\Java\jdk1.6.0_26\jre\bin\dt_shmem.dll 0x000007fefce50000 - 0x000007fefce67000 C:\Windows\system32\CRYPTSP.dll 0x000007fefcb50000 - 0x000007fefcb97000 C:\Windows\system32\rsaenh.dll 0x000007fefc8b0000 - 0x000007fefc8ce000 C:\Windows\system32\USERENV.dll 0x000007fefd580000 - 0x000007fefd58f000 C:\Windows\system32\profapi.dll 0x000007fefd4b0000 - 0x000007fefd4bf000 C:\Windows\system32\CRYPTBASE.dll 0x000000006d6a0000 - 0x000000006d6b7000 C:\Program Files\Java\jdk1.6.0_26\jre\bin\net.dll 0x000007fefec90000 - 0x000007fefecdd000 C:\Windows\system32\WS2_32.dll 0x000007feff810000 - 0x000007feff818000 C:\Windows\system32\NSI.dll 0x000007fefcdf0000 - 0x000007fefce44000 C:\Windows\system32\mswsock.dll 0x000007fefcde0000 - 0x000007fefcde7000 C:\Windows\System32\wship6.dll 0x000007fefae10000 - 0x000007fefae25000 C:\Windows\system32\NLAapi.dll 0x000007fefcc70000 - 0x000007fefcccb000 C:\Windows\system32\DNSAPI.dll 0x000007fef4a70000 - 0x000007fef4a7b000 C:\Windows\System32\winrnr.dll 0x000007fef4a50000 - 0x000007fef4a65000 C:\Windows\system32\napinsp.dll 0x000007fef4a30000 - 0x000007fef4a49000 C:\Windows\system32\pnrpnsp.dll 0x000007fefc7b0000 - 0x000007fefc7b7000 C:\Windows\System32\wshtcpip.dll 0x000007fefb470000 - 0x000007fefb497000 C:\Windows\system32\IPHLPAPI.DLL 0x000007fefb450000 - 0x000007fefb45b000 C:\Windows\system32\WINNSI.DLL 0x000007fef4b50000 - 0x000007fef4b58000 C:\Windows\system32\rasadhlp.dll 0x000007fefb2e0000 - 0x000007fefb333000 C:\Windows\System32\fwpuclnt.dll 0x0000000180000000 - 0x0000000180037000 C:\Users\geverding\AppData\Local\Temp\jna7891581094505694184.dll 0x000007fefc6e0000 - 0x000007fefc6ec000 C:\Windows\system32\Version.dll

VM Arguments: jvm_args: -Xdebug -Xrunjdwp:transport=dt_shmem,address=javadebug -Dfile.encoding=UTF-8 java_command: windowsversion.WindowsVersion Launcher Type: SUN_STANDARD

Environment Variables: PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files (x86)\WinMerge;C:\Program Files\SlikSvn\bin\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files (x86)\WinMerge;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;c:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files (x86)\WinMerge;C:\Program Files (x86)\CVSNT;C:\Program Files\WinRar;C:\Program Files\WinRar;C:\ProgramFiles\SlikSvn\bin USERNAME=geverding OS=Windows_NT PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 15 Stepping 6, GenuineIntel

--------------- S Y S T E M ---------------

OS: Windows 7 Build 7600

CPU:total 2 (2 cores per cpu, 1 threads per core) family 6 model 15 stepping 6, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3

Memory: 4k page, physical 6216888k(3835956k free), swap 12431876k(9888884k free)

vm_info: Java HotSpot(TM) 64-Bit Server VM (20.1-b02) for windows-amd64 JRE (1.6.0_26-b03), built on May 4 2011 07:15:24 by "java_re" with MS VC++ 8.0 (VS2005)

time: Wed Aug 03 11:33:47 2011 elapsed time: 8 seconds

Anybody have any ideas why this is happening?

1
Can you separate the call out that crashes the VM into two lines, the first getting the instance, the second making the method call, and see what one terminates the VM? This sort of hard crash is commonplace when you get something wrong executing native code outside the VM.Michael Berry
@berry120, I found my error after messing around with it. MSDN says that a parameter in this method call is optional MSDN. Apparently It needs to be there because after I added the second parameter that part of the code worked. Do you have any experience with JNA/getting file version info?GEverding
Afraid not - I've never really needed to and I probably wouldn't approach it in this way anyway since it ties you down to platform specific APIs. I'd probably go along the route of using a checksum instead personally.Michael Berry
i'm relatively new to programming so this might be wrong. Im attempting to get version info for a local file to determine if i need to download/install a file stored on a server. A checksum will only tell me if the file is corrupted or not, That's the way I understand it. Pls correct me if I'm wrong.GEverding
A checksum is (pretty much) unique to a file - changing just one byte in the file gives a completely different checksum. So if you know the checksum of the latest file on the server, and the current local file has a different checksum, it must be an older version.Michael Berry

1 Answers

0
votes

If this is a MS library, you need to derive from StdCallLibrary, or add an OPTION_CALLING_CONVENTION=>STDCALL_CONVENTION to the options passed to your library load.

If you call with the wrong calling convention, you will likely crash the VM.