dod-cyber-crime-center / pyhidra

Pyhidra is a Python library that provides direct access to the Ghidra API within a native CPython interpreter using jpype.
Other
184 stars 16 forks source link

Error occurred during initialization of VM #47

Open clucian-mwb opened 6 days ago

clucian-mwb commented 6 days ago

I am trying to run ./pyhidraw, however it returns the following error.

Error occurred during initialization of VM
Could not find agent library instrument on the library path, with error: Can't find dependent libraries
Module java.instrument may be missing from runtime image.

Is it an issue with JDK? My java version is "21.0.5" 2024-10-15 LTS. Thx in advance

astrelsky commented 6 days ago

What JDK do you have? There is a similar issue here https://github.com/jpype-project/jpype/issues/1242

However, Ghidra already requires the full JDK so this shouldn't be an issue. I did quite a bit of testing with jpype, Ghidra + PyGhidra before jpype 1.51 went out to ensure it wouldn't break PyGhidra. I have tested up to JDK 23 without issue.

clucian-mwb commented 5 days ago

You found the problem, jpype is causing this. I was able to reproduce it exactly as mentioned in that issue

Python 3.11.9
>>> import jpype
>>> jpype.getDefaultJVMPath()
'C:\\Program Files\\Java\\jdk-21\\bin\\server\\jvm.dll'
>>> jpype.startJVM()
Error occurred during initialization of VM
Could not find agent library instrument on the library path, with error: Can't find dependent libraries
Module java.instrument may be missing from runtime image.

The dll exists at that precise path, but returns the error anyway :(

I tried both with JDK 23 and JDK 21 at the newest versions and at two older ones as well (21.0.1 and 23.0.1).

astrelsky commented 5 days ago

You found the problem, jpype is causing this. I was able to reproduce it exactly as mentioned in that issue

Python 3.11.9
>>> import jpype
>>> jpype.getDefaultJVMPath()
'C:\\Program Files\\Java\\jdk-21\\bin\\server\\jvm.dll'
>>> jpype.startJVM()
Error occurred during initialization of VM
Could not find agent library instrument on the library path, with error: Can't find dependent libraries
Module java.instrument may be missing from runtime image.

The dll exists at that precise path, but returns the error anyway :(

I tried both with JDK 23 and JDK 21 at the newest versions and at two older ones as well (21.0.1 and 23.0.1).

What JDK do you have installed? Not the version, where did you get it?

I wrote a portion of the code in jpype that handles this which is why I want to know. There is no reason for a JDK to exclude this standard module since it's for profiling and debugging.

You should have a C:\\Program Files\\Java\\jdk-21\\jmods\\java.instrument.jmod file and C:\\Program Files\\Java\\jdk-21\\lib\\modules should be around 130MB

ryanmkurtz commented 5 days ago

@clucian-mwb Can you run java -version and provide the output?

clucian-mwb commented 5 days ago

@astrelsky I tried both from here and here.

Yes I have both of those files at that paths. java.instrument.jmod is around 50MB and modules around 130MB

@ryanmkurtz This is the version I have installed right now, I tried an older one as well. Ghidra works smoothly.

java version "21.0.2" 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 21.0.2+13-LTS-58)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.2+13-LTS-58, mixed mode, sharing)