Ghidra is a software reverse engineering (SRE) framework
GP-0: Fixing PyGhidra application name on Linux, and a couple of other PyGhidra tweaks (Closes #8362)
Ryan Kurtz817766af2712
diff --git a/Ghidra/Features/PyGhidra/src/main/py/README.md b/Ghidra/Features/PyGhidra/src/main/py/README.mdindex 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 isdiff --git a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/gui.py b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/gui.pyindex 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 platformimport sysimport tracebackfrom typing import List, NoReturn-import warnings+from typing_extensions import deprecatedimport pyghidra@@ -153,11 +153,7 @@ def gui(install_dir: Path = None, vm_args: List[str] = None):launcher.vm_args += vm_argslauncher.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.pyindex 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 laterThread(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.pyindex 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 SystemUtilitiesfrom ghidra.framework.main import AppInfo+ from ghidra.pyghidra import PyGhidraScriptProviderglobal _headless_interpreterif 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: ignorereturn _headless_interpreterproject = AppInfo.getActiveProject()