0

I'm pretty new to Ghidra, and looking to use it's API (headless analyzer) and get the assembled file through command line using python.

Here is my code, which is likely far from the correct code. It gives error, and I am stuck. Would you please help?

The command I am using to run the script is:

analyzeHeadless ~/Desktop/ghidra_9.1-BETA_DEV   DNETSamples.gpr -scriptPath ~/Desktop/ghidra_9.1-BETA_DEV  -postScript disassemble.py    -process -recursive

And this is disassemble.py:

#!/usr/bin/python
# -*- coding: utf-8 -*-


from ghidra.util.task import ConsoleTaskMonitor
from ghidra.app.cmd.disassemble import DisassembleCommand
from ghidra.app.script import GhidraScript
from  ghidra.program.model.address import AddressSet



addset = AddressSet()
addset.add(currentAddress)
cmd = DisassembleCommand(addset, None, True)
cmd.doDisassembly​(ConsoleTaskMonitor(), currentProgram, 0)

The error is java.lang.IllegalArgumentException: Cannot create PyString with non-byte value:

INFO  SCRIPT: ghidra_9.1-BETA_DEV/ghidra_decomp.py (HeadlessAnalyzer)
Exception in thread "Python script execution thread" java.lang.IllegalArgumentException: Cannot create PyString with non-byte value
    at org.python.core.PyString.<init>(PyString.java:57)
    at org.python.core.PyString.<init>(PyString.java:70)
    at org.python.core.PyString.<init>(PyString.java:74)
    at org.python.core.PySyntaxError.<init>(PySyntaxError.java:31)
    at org.python.core.ParserFacade.fixParseError(ParserFacade.java:95)
    at org.python.core.ParserFacade.parse(ParserFacade.java:190)
    at org.python.core.Py.compile_flags(Py.java:2185)
    at org.python.core.\__builtin__.execfile_flags(\__builtin__.java:527)
    at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:286)
    at ghidra.python.GhidraPythonInterpreter.execFile(GhidraPythonInterpreter.java:232)
    at ghidra.python.PythonScriptExecutionThread.run(PythonScriptExecutionThread.java:51)
  • What error? We can’t see your screen. – Igor Skochinsky Oct 23 at 21:41
  • 1
    updated my post to include the error. – Memphis4Ever Oct 23 at 21:47
  • 1
    @Memphis4Ever maybe include how you run the this script. What parameters to analyzeHeadless do you provide? – Paweł Łukasik Oct 24 at 19:15
  • 1
    I've run your command with updated paths (and under windows) and it run successfully. But I would look into this 'non-byte value' info that Ghidra reports. Try checking your script in hex-editor. Maybe there's some non-ASCII character in your script? – Paweł Łukasik Oct 27 at 6:26
0

The solution is to delete your project (or use new) and add -deleteproject next time when you run your analyzeHeadless script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.