From 817766af27129d6e88aa4d895ce55c9f1526faec Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Fri, 24 Jul 2026 12:28:49 -0400 Subject: [PATCH] GP-0: Fixing PyGhidra application name on Linux, and a couple of other PyGhidra tweaks (Closes #8362) --- Ghidra/Features/PyGhidra/src/main/py/README.md | 1 + Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/gui.py | 8 ++------ .../PyGhidra/src/main/py/src/pyghidra/launcher.py | 4 ++++ .../Features/PyGhidra/src/main/py/src/pyghidra/script.py | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Ghidra/Features/PyGhidra/src/main/py/README.md b/Ghidra/Features/PyGhidra/src/main/py/README.md index 4c6f173e53..d292da545a 100644 --- a/Ghidra/Features/PyGhidra/src/main/py/README.md +++ b/Ghidra/Features/PyGhidra/src/main/py/README.md @@ -575,6 +575,7 @@ __3.2.0__ * PyGhidra now depends on `JPype >=1.5.2, != 1.6.0, != 1.7.0`. * Using `typing_extensions` to properly deprecate [`pyghidra.open_program()`](#pyghidraopen_program) and [`pyghidra.run_script()`](#pyghidrarun_script). +* Fixed the PyGhidra WM_CLASS/application name on Linux (requires Ghidra 12.2 or later). __3.1.0__ * PyGhidra will now, by default, restore `sys.modules` to its prior state after a PyGhidra script is diff --git a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/gui.py b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/gui.py index 517c1d46bf..4bcb9ce645 100644 --- a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/gui.py +++ b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/gui.py @@ -21,7 +21,7 @@ import platform import sys import traceback from typing import List, NoReturn -import warnings +from typing_extensions import deprecated import pyghidra @@ -153,11 +153,7 @@ def gui(install_dir: Path = None, vm_args: List[str] = None): launcher.vm_args += vm_args launcher.start() - +@deprecated("get_current_interpreter has been moved. Please use pyghidra.get_current_interpreter.") def get_current_interpreter(): - warnings.warn( - "get_current_interpreter has been moved. Please use pyghidra.get_current_interpreter", - DeprecationWarning - ) return pyghidra.get_current_interpreter() diff --git a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/launcher.py b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/launcher.py index c920a355b0..79032156f2 100644 --- a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/launcher.py +++ b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/launcher.py @@ -746,6 +746,10 @@ class GuiPyGhidraLauncher(PyGhidraLauncher): stdout = _PyGhidraStdOut(sys.stdout) stderr = _PyGhidraStdOut(sys.stderr) with contextlib.redirect_stdout(stdout), contextlib.redirect_stderr(stderr): + try: + Ghidra.setLinuxApplicationName() + except AttributeError: + pass # Ghidra 12.2 and later Thread(lambda: Ghidra.main(["ghidra.GhidraRun", *self.args])).start() is_exiting = threading.Event() Runtime.getRuntime().addShutdownHook(Thread(is_exiting.set)) diff --git a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/script.py b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/script.py index 559d9e09bf..0f17bafef5 100644 --- a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/script.py +++ b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/script.py @@ -280,14 +280,14 @@ def get_current_interpreter(): try: from ghidra.util import SystemUtilities from ghidra.framework.main import AppInfo + from ghidra.pyghidra import PyGhidraScriptProvider global _headless_interpreter if SystemUtilities.isInHeadlessMode(): if _headless_interpreter is None: # one hasn't been created yet so make one now - PyGhidraScriptProvider = JClass("ghidra.pyghidra.PyGhidraScriptProvider") - _headless_interpreter = PyGhidraScriptProvider.PyGhidraHeadlessScript() + _headless_interpreter = PyGhidraScriptProvider().getScriptInstance(None, None) # type: ignore return _headless_interpreter project = AppInfo.getActiveProject()