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)
analyzeHeadless
do you provide?