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
182 stars 16 forks source link

Ghidra 10.3 API GhidraProgramUtilities change breaks _analyze_program #28

Closed clearbluejar closed 1 year ago

clearbluejar commented 1 year ago

There has been a change to GhidraProgramUtilities. setAnalyzedFlag has been replaced with markProgramAnalyzed

Sample program:

import pyhidra

with pyhidra.open_program("/bin/ls", analyze=True, project_location='/tmp') as flat_api:
    from ghidra.program.util import GhidraProgramUtilities

    program = flat_api.getCurrentProgram()

Output:

Traceback (most recent call last):
  File "/tmp/issue.py", line 3, in <module>
    with pyhidra.open_program("/bin/ls", analyze=True, project_location='/tmp') as flat_api:
  File "/usr/local/lib/python3.11/contextlib.py", line 137, in __enter__
    return next(self.gen)
           ^^^^^^^^^^^^^^
  File "/workspaces/ghidrecomp/.env/lib/python3.11/site-packages/pyhidra/core.py", line 179, in open_program
    _analyze_program(flat_api, program)
  File "/workspaces/ghidrecomp/.env/lib/python3.11/site-packages/pyhidra/core.py", line 127, in _analyze_program
    GhidraProgramUtilities.setAnalyzedFlag(program, True)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'ghidra.program.util.GhidraProgramUtilities' has no attribute 'setAnalyzedFlag'. Did you mean: 'resetAnalysisFlags'?

I am having the same issue https://github.com/clearbluejar/ghidrecomp/issues/7. Thinking of adding a helper function that selects the correct API based on Ghidra version. Won't be as clean. Are there other places pyhidra is handling API changes?

clearbluejar commented 1 year ago

This is my simple helper function for ghidrecomp. https://github.com/clearbluejar/ghidrecomp/commit/a233ccdfaeb94dea9bf4e3577e7c8230aa84de9d#diff-d8c1ac77e5ef29de3416dbfa86c1959a84b869c376b8f422ad1b83feb643e3c4R46

clearbluejar commented 1 year ago

looks to be fixed in https://github.com/dod-cyber-crime-center/pyhidra/commit/58e97b016bc81dd59d3817a81542dd8782d01353

perfect