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

Question: NameError: Name 'monitor' is not defined #17

Closed dreyes15 closed 1 year ago

dreyes15 commented 1 year ago

So I am trying to write a script to calculate the Cyclomatic complexity of each function, and keep running into the error that monitor is not defined. So far I haven't been able to find a good solution on how to get around this. ` import pyhidra with pyhidra.open_program("test") as flat_api: from ghidra.program.model.listing import Function, FunctionIterator from ghidra.program.util import CyclomaticComplexity

program  = flat_api.getCurrentProgram()

functions = currentProgram.getFunctionManager().getFunctions(
    True
) 
func_to_complexity = list()
cc = CyclomaticComplexity()
for function in functions:  # type: Function
    complexity = cc.calculateCyclomaticComplexity(function, monitor)
    func_to_complexity.append(
        {
            "function": str(function),
            "address": function.getEntryPoint(),
            "complexity": complexity,
        }
    )`

Can anyone help in identifying where monitor comes from? Or how to pass the monitor object to the Cyclomatic Complexity function.

dreyes15 commented 1 year ago

Figured out that you can get around this by using From ghidra.util.task import TaskMonitor and replacing monitor with TaskMonitor.DUMMY