Skip to content

pyghidra.analyze fails to call monitor with 'NoneType' object is not callable #8722

@niooss-ledger

Description

@niooss-ledger

Describe the bug
While using PyGhidra on Ghidra's master branch, I got:

Traceback (most recent call last):
  File "ghidra_analyze_and_export_programs.py", line 105, in analyze_and_export_all_programs
    pyghidra.analyze(program)
    ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/root/.config/ghidra/ghidra_12.1_DEV/venv/lib/python3.13/site-packages/pyghidra/api.py", line 177, in analyze
    monitor = monitor()
TypeError: 'NoneType' object is not callable

To Reproduce
Steps to reproduce the behavior:

  1. On Debian 13, build and install Ghidra's current master branch (commit a0acfb8f914f77dd72a1a6661d501f758eef0a90, 12.1 DEV)
  2. Launch support/pyghidraRun
  3. In another terminal, launch a Python interactive console using PyGhidra's virtual environment with ~/.config/ghidra/ghidra_12.1_DEV/venv/bin/python3
  4. Analyze some program, like /bin/true by entering the following Python code:
import pyghidra

pyghidra.start()
project = pyghidra.open_project("/tmp", "my_project", create=True)
loaded_program = pyghidra.program_loader().project(project).source("/bin/true").load()
program = loaded_program.getPrimaryDomainObject()
pyghidra.analyze(program)
  1. Observe a Python exception
Traceback (most recent call last):
  File "<python-input-6>", line 1, in <module>
    pyghidra.analyze(program)
    ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/root/.config/ghidra/ghidra_12.1_DEV/venv/lib/python3.13/site-packages/pyghidra/api.py", line 177, in analyze
    monitor = monitor()
TypeError: 'NoneType' object is not callable

Expected behavior
No error

Screenshots
If applicable, add screenshots to help explain your problem.

Image

Environment (please complete the following information):

Additional context
Add any other context about the problem here.

This regression comes from commit c18c7a8 which modified pyghidra.api.analyze to:

def analyze(
        program: "Program", 
        monitor: Optional["TaskMonitor"] = None
    ):
    """
    Analyzes the given program.

    :param program: The Ghidra program to analyze.
    """
    from ghidra.app.script import GhidraScriptUtil

    from ghidra.program.util import GhidraProgramUtilities
    from ghidra.app.plugin.core.analysis import AutoAnalysisManager
    
    if monitor is None:
        monitor = monitor()

In the last line, monitor is a local variable which is None, so calling monitor() triggers the error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions