mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
GP-0: Renaming pyghidra.monitor() to pyghidra.task_monitor() to avoid
naming conflict with local monitor variables (Closes #8722)
This commit is contained in:
@@ -220,9 +220,9 @@ def program_loader() -> "ProgramLoader.Builder":
|
|||||||
"""
|
"""
|
||||||
```
|
```
|
||||||
|
|
||||||
### pyghidra.monitor()
|
### pyghidra.task_monitor()
|
||||||
```python
|
```python
|
||||||
def monitor(
|
def task_monitor(
|
||||||
timeout: Optional[int] = None
|
timeout: Optional[int] = None
|
||||||
) -> "PyGhidraTaskMonitor":
|
) -> "PyGhidraTaskMonitor":
|
||||||
"""
|
"""
|
||||||
@@ -288,22 +288,22 @@ with pyghidra.open_project(os.environ["GHIDRA_PROJECT_DIR"], "ExampleProject", c
|
|||||||
for f in fs.files(lambda f: "os/" in f.path and f.name.startswith("decompile")):
|
for f in fs.files(lambda f: "os/" in f.path and f.name.startswith("decompile")):
|
||||||
loader = loader.source(f.getFSRL()).projectFolderPath("/" + f.parentFile.name)
|
loader = loader.source(f.getFSRL()).projectFolderPath("/" + f.parentFile.name)
|
||||||
with loader.load() as load_results:
|
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 seconds
|
# Analyze the windows decompiler program for a maximum of 10 seconds
|
||||||
with pyghidra.program_context(project, "/win_x86_64/decompile.exe") as program:
|
with pyghidra.program_context(project, "/win_x86_64/decompile.exe") as program:
|
||||||
analysis_props = pyghidra.analysis_properties(program)
|
analysis_props = pyghidra.analysis_properties(program)
|
||||||
with pyghidra.transaction(program):
|
with pyghidra.transaction(program):
|
||||||
analysis_props.setBoolean("Non-Returning Functions - Discovered", False)
|
analysis_props.setBoolean("Non-Returning Functions - Discovered", False)
|
||||||
analysis_log = pyghidra.analyze(program, pyghidra.monitor(10))
|
analysis_log = pyghidra.analyze(program, pyghidra.task_monitor(10))
|
||||||
program.save("Analyzed", pyghidra.monitor())
|
program.save("Analyzed", pyghidra.task_monitor())
|
||||||
|
|
||||||
# Walk the project and set a property in each decompiler program
|
# Walk the project and set a property in each decompiler program
|
||||||
def set_property(domain_file, program):
|
def set_property(domain_file, program):
|
||||||
with pyghidra.transaction(program):
|
with pyghidra.transaction(program):
|
||||||
program_info = pyghidra.program_info(program)
|
program_info = pyghidra.program_info(program)
|
||||||
program_info.setString("PyGhidra Property", "Set by PyGhidra!")
|
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"))
|
pyghidra.walk_programs(project, set_property, program_filter=lambda f, p: p.name.startswith("decompile"))
|
||||||
|
|
||||||
# Load some bytes as a new program
|
# Load some bytes as a new program
|
||||||
@@ -312,7 +312,7 @@ with pyghidra.open_project(os.environ["GHIDRA_PROJECT_DIR"], "ExampleProject", c
|
|||||||
loader = pyghidra.program_loader().project(project).source(my_bytes).name("my_bytes")
|
loader = pyghidra.program_loader().project(project).source(my_bytes).name("my_bytes")
|
||||||
loader = loader.loaders("BinaryLoader").language("DATA:LE:64:default")
|
loader = loader.loaders("BinaryLoader").language("DATA:LE:64:default")
|
||||||
with loader.load() as load_results:
|
with loader.load() as load_results:
|
||||||
load_results.save(pyghidra.monitor())
|
load_results.save(pyghidra.task_monitor())
|
||||||
|
|
||||||
# Run a GhidraScript
|
# Run a GhidraScript
|
||||||
pyghidra.ghidra_script(f"{os.environ['GHIDRA_SCRIPTS_DIR']}/HelloWorldScript.java", project)
|
pyghidra.ghidra_script(f"{os.environ['GHIDRA_SCRIPTS_DIR']}/HelloWorldScript.java", project)
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ from pyghidra.core import run_script, open_program
|
|||||||
from pyghidra.api import start, started
|
from pyghidra.api import start, started
|
||||||
from pyghidra.api import open_project, open_filesystem, consume_program, program_context, analyze
|
from pyghidra.api import open_project, open_filesystem, consume_program, program_context, analyze
|
||||||
from pyghidra.api import ghidra_script, transaction, analysis_properties, program_info
|
from 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_programs
|
||||||
from pyghidra.launcher import DeferredPyGhidraLauncher, GuiPyGhidraLauncher, HeadlessPyGhidraLauncher
|
from pyghidra.launcher import DeferredPyGhidraLauncher, GuiPyGhidraLauncher, HeadlessPyGhidraLauncher
|
||||||
from pyghidra.script import get_current_interpreter
|
from pyghidra.script import get_current_interpreter
|
||||||
from pyghidra.version import ApplicationInfo, ExtensionDetails
|
from pyghidra.version import ApplicationInfo, ExtensionDetails
|
||||||
@@ -69,6 +69,6 @@ __all__ = [
|
|||||||
"DeferredPyGhidraLauncher", "ExtensionDetails", "GuiPyGhidraLauncher",
|
"DeferredPyGhidraLauncher", "ExtensionDetails", "GuiPyGhidraLauncher",
|
||||||
"HeadlessPyGhidraLauncher", "start", "started", "open_project", "open_filesystem",
|
"HeadlessPyGhidraLauncher", "start", "started", "open_project", "open_filesystem",
|
||||||
"consume_program", "program_conext", "analyze", "ghidra_script", "transaction",
|
"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"
|
"walk_programs"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ def open_filesystem(
|
|||||||
|
|
||||||
service = FileSystemService.getInstance()
|
service = FileSystemService.getInstance()
|
||||||
fsrl = service.getLocalFS().getLocalFSRL(File(path))
|
fsrl = service.getLocalFS().getLocalFSRL(File(path))
|
||||||
fs = service.openFileSystemContainer(fsrl, monitor())
|
fs = service.openFileSystemContainer(fsrl, task_monitor())
|
||||||
if fs is None:
|
if fs is None:
|
||||||
raise ValueError(f'"{fsrl}" is not a supported GFileSystem!')
|
raise ValueError(f'"{fsrl}" is not a supported GFileSystem!')
|
||||||
return fs
|
return fs
|
||||||
@@ -131,7 +131,7 @@ def consume_program(
|
|||||||
df = project_data.getFile(path)
|
df = project_data.getFile(path)
|
||||||
if df is None:
|
if df is None:
|
||||||
raise FileNotFoundError(f'"{path}" does not exist in the Project')
|
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_
|
program_cls = Program.class_
|
||||||
if not program_cls.isAssignableFrom(dobj.getClass()):
|
if not program_cls.isAssignableFrom(dobj.getClass()):
|
||||||
dobj.release(consumer)
|
dobj.release(consumer)
|
||||||
@@ -174,7 +174,7 @@ def analyze(
|
|||||||
from ghidra.app.plugin.core.analysis import AutoAnalysisManager
|
from ghidra.app.plugin.core.analysis import AutoAnalysisManager
|
||||||
|
|
||||||
if monitor is None:
|
if monitor is None:
|
||||||
monitor = monitor()
|
monitor = task_monitor()
|
||||||
|
|
||||||
with transaction(program, "Analyze"):
|
with transaction(program, "Analyze"):
|
||||||
GhidraScriptUtil.acquireBundleHostReference()
|
GhidraScriptUtil.acquireBundleHostReference()
|
||||||
@@ -236,7 +236,7 @@ def ghidra_script(
|
|||||||
controls = ScriptControls(
|
controls = ScriptControls(
|
||||||
PrintWriter(stdout_string_writer, True),
|
PrintWriter(stdout_string_writer, True),
|
||||||
PrintWriter(stderr_string_writer, True),
|
PrintWriter(stderr_string_writer, True),
|
||||||
monitor()
|
task_monitor()
|
||||||
)
|
)
|
||||||
script.setScriptArgs(script_args)
|
script.setScriptArgs(script_args)
|
||||||
script.execute(state, controls)
|
script.execute(state, controls)
|
||||||
@@ -300,7 +300,7 @@ def program_loader() -> "ProgramLoader.Builder":
|
|||||||
from ghidra.app.util.importer import ProgramLoader
|
from ghidra.app.util.importer import ProgramLoader
|
||||||
return ProgramLoader.builder()
|
return ProgramLoader.builder()
|
||||||
|
|
||||||
def monitor(
|
def task_monitor(
|
||||||
timeout: Optional[int] = None
|
timeout: Optional[int] = None
|
||||||
) -> "PyGhidraTaskMonitor":
|
) -> "PyGhidraTaskMonitor":
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user