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
153 stars 14 forks source link

askChoices error python3.11 #27

Closed moval0x1 closed 1 year ago

moval0x1 commented 1 year ago

Hi, I'm trying to use askChoices with Pyhidra (python 3.11), but I always receive an error:

Tests.py> Running...
Tests.py> Traceback (most recent call last):
  File "/home/remnux/ghidra_scripts/Tests.py", line 51, in <module>
    choices = askChoices("Options", "Select your option",
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: No matching overloads found for ghidra.app.script.GhidraScript.askChoices(str,str,list,list), options are:
    public java.util.List ghidra.app.script.GhidraScript.askChoices(java.lang.String,java.lang.String,java.util.List) throws ghidra.util.exception.CancelledException
    public java.util.List ghidra.app.script.GhidraScript.askChoices(java.lang.String,java.lang.String,java.util.List,java.util.List) throws ghidra.util.exception.CancelledException

Tests.py> Finished!

Code:

choices = askChoices("Options", "Select your option",
                     [0, 1, 2],
                     ["Option 1", "Option 2", "Option 3"])

The same code without Pyhidra (with python 2.7) runs correctly. image

Just askChoice(s) has this problem, askInt, askString, askDouble all these work well. Can someone please help me with this issue? image

dc3-tsd commented 1 year ago

For lists being passed into Java functions, you'll need to first convert the list from Python to Java using something like java.util.ArrayList​ so Java can figure out the correct overloaded method to call. We are looking into improving this so that lists will automatically convert in the background when possible.


choices = askChoices(
    "Options", "Select your option",
    java.util.ArrayList([0, 1, 2]),
    java.util.ArrayList(["Option 1", "Option 2", "Option 3"]),
)
moval0x1 commented 1 year ago

Thank you, @dc3-tsd! It worked perfectly!