Ghidra is a software reverse engineering (SRE) framework
GP-0: Renaming pyghidra.monitor() to pyghidra.task_monitor() to avoid naming conflict with local monitor variables (Closes #8722)
Ryan Kurtz5e6c16073efa
diff --git a/Ghidra/Features/PyGhidra/src/main/py/README.md b/Ghidra/Features/PyGhidra/src/main/py/README.mdindex 1daf1b703d..935025c279 100644--- a/Ghidra/Features/PyGhidra/src/main/py/README.md+++ b/Ghidra/Features/PyGhidra/src/main/py/README.md@@ -220,9 +220,9 @@ def program_loader() -> "ProgramLoader.Builder":"""```-### pyghidra.monitor()+### pyghidra.task_monitor()```python-def monitor(+def task_monitor(timeout: Optional[int] = None) -> "PyGhidraTaskMonitor":"""@@ -288,22 +288,22 @@ with pyghidra.open_project(os.environ["GHIDRA_PROJECT_DIR"], "ExampleProject", cfor f in fs.files(lambda f: "os/" in f.path and f.name.startswith("decompile")):loader = loader.source(f.getFSRL()).projectFolderPath("/" + f.parentFile.name)with loader.load() as load_results:- load_results.save(pyghidra.monitor())+ load_results.save(pyghidra.task_monitor())# Analyze the windows decompiler program for a maximum of 10 secondswith pyghidra.program_context(project, "/win_x86_64/decompile.exe") as program:analysis_props = pyghidra.analysis_properties(program)with pyghidra.transaction(program):analysis_props.setBoolean("Non-Returning Functions - Discovered", False)- analysis_log = pyghidra.analyze(program, pyghidra.monitor(10))- program.save("Analyzed", pyghidra.monitor())+ analysis_log = pyghidra.analyze(program, pyghidra.task_monitor(10))+ program.save("Analyzed", pyghidra.task_monitor())# Walk the project and set a property in each decompiler programdef set_property(domain_file, program):with pyghidra.transaction(program):program_info = pyghidra.program_info(program)program_info.setString("PyGhidra Property", "Set by PyGhidra!")- program.save("Setting property", pyghidra.monitor())+ program.save("Setting property", pyghidra.task_monitor())pyghidra.walk_programs(project, set_property, program_filter=lambda f, p: p.name.startswith("decompile"))# Load some bytes as a new program@@ -312,7 +312,7 @@ with pyghidra.open_project(os.environ["GHIDRA_PROJECT_DIR"], "ExampleProject", cloader = pyghidra.program_loader().project(project).source(my_bytes).name("my_bytes")loader = loader.loaders("BinaryLoader").language("DATA:LE:64:default")with loader.load() as load_results:- load_results.save(pyghidra.monitor())+ load_results.save(pyghidra.task_monitor())# Run a GhidraScriptpyghidra.ghidra_script(f"{os.environ['GHIDRA_SCRIPTS_DIR']}/HelloWorldScript.java", project)diff --git a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/__init__.py b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/__init__.pyindex a1d38d9c59..aa02f54044 100644--- a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/__init__.py+++ b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/__init__.py@@ -58,7 +58,7 @@ from pyghidra.core import run_script, open_programfrom pyghidra.api import start, startedfrom pyghidra.api import open_project, open_filesystem, consume_program, program_context, analyzefrom pyghidra.api import ghidra_script, transaction, analysis_properties, program_info-from pyghidra.api import program_loader, monitor, walk_project, walk_programs+from pyghidra.api import program_loader, task_monitor, walk_project, walk_programsfrom pyghidra.launcher import DeferredPyGhidraLauncher, GuiPyGhidraLauncher, HeadlessPyGhidraLauncherfrom pyghidra.script import get_current_interpreterfrom pyghidra.version import ApplicationInfo, ExtensionDetails@@ -69,6 +69,6 @@ __all__ = ["DeferredPyGhidraLauncher", "ExtensionDetails", "GuiPyGhidraLauncher","HeadlessPyGhidraLauncher", "start", "started", "open_project", "open_filesystem","consume_program", "program_conext", "analyze", "ghidra_script", "transaction",- "analysis_properties", "program_info", "program_loader", "monitor", "walk_project",+ "analysis_properties", "program_info", "program_loader", "task_monitor", "walk_project","walk_programs"]diff --git a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/api.py b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/api.pyindex ecb1a87b40..b5b13d608e 100644--- a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/api.py+++ b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/api.py@@ -97,7 +97,7 @@ def open_filesystem(service = FileSystemService.getInstance()fsrl = service.getLocalFS().getLocalFSRL(File(path))- fs = service.openFileSystemContainer(fsrl, monitor())+ fs = service.openFileSystemContainer(fsrl, task_monitor())if fs is None:raise ValueError(f'"{fsrl}" is not a supported GFileSystem!')return fs@@ -131,7 +131,7 @@ def consume_program(df = project_data.getFile(path)if df is None:raise FileNotFoundError(f'"{path}" does not exist in the Project')- dobj = df.getDomainObject(consumer, True, False, monitor())+ dobj = df.getDomainObject(consumer, True, False, task_monitor())program_cls = Program.class_if not program_cls.isAssignableFrom(dobj.getClass()):dobj.release(consumer)@@ -174,7 +174,7 @@ def analyze(from ghidra.app.plugin.core.analysis import AutoAnalysisManagerif monitor is None:- monitor = monitor()+ monitor = task_monitor()with transaction(program, "Analyze"):GhidraScriptUtil.acquireBundleHostReference()@@ -236,7 +236,7 @@ def ghidra_script(controls = ScriptControls(PrintWriter(stdout_string_writer, True),PrintWriter(stderr_string_writer, True),- monitor()+ task_monitor())script.setScriptArgs(script_args)script.execute(state, controls)@@ -300,7 +300,7 @@ def program_loader() -> "ProgramLoader.Builder":from ghidra.app.util.importer import ProgramLoaderreturn ProgramLoader.builder()-def monitor(+def task_monitor(timeout: Optional[int] = None) -> "PyGhidraTaskMonitor":"""