Ghidra is a software reverse engineering (SRE) framework
GP-7001: PyGhidra doesn't swallow GhidraScript exceptions anymore
Ryan Kurtzd36e9af5a1a5
diff --git a/Ghidra/Features/PyGhidra/src/main/java/ghidra/pyghidra/PyGhidraScriptProvider.java b/Ghidra/Features/PyGhidra/src/main/java/ghidra/pyghidra/PyGhidraScriptProvider.javaindex 60e0ee18c1..bd597302a9 100644--- a/Ghidra/Features/PyGhidra/src/main/java/ghidra/pyghidra/PyGhidraScriptProvider.java+++ b/Ghidra/Features/PyGhidra/src/main/java/ghidra/pyghidra/PyGhidraScriptProvider.java@@ -99,8 +99,16 @@ public final class PyGhidraScriptProvider extends AbstractPythonScriptProvider {implements PythonFieldExposer {@Override- public void run() {- scriptRunner.accept(this);+ public void run() throws Exception {+ try {+ scriptRunner.accept(this);+ }+ catch (Exception e) {+ // This is a PyExceptionProxy, which we unfortunately cannot add a custom message+ // to. We don't want to wrap it in a custom exception because then Python will lose+ // access to the original BaseException.+ throw e;+ }}/**diff --git a/Ghidra/Features/PyGhidra/src/main/py/README.md b/Ghidra/Features/PyGhidra/src/main/py/README.mdindex 20033e6778..ce3013382f 100644--- a/Ghidra/Features/PyGhidra/src/main/py/README.md+++ b/Ghidra/Features/PyGhidra/src/main/py/README.md@@ -571,6 +571,7 @@ __3.2.0__* PyGhidra's `help()` override can now show `public/private/protected` on Ghidra Java fields andmethods (available in Ghidra 12.2 and later).* When an uncaught `JException` occurs, PyGhidra will now output the full Java stack trace.+* PyGhidra no longer swallows the original exception object generated by GhidraScripts.__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/script.py b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/script.pyindex e30018b5b0..559d9e09bf 100644--- a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/script.py+++ b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/script.py@@ -256,6 +256,7 @@ class PyGhidraScript(dict):# pylint: disable=bare-exceptexcept:print_stacktrace(self._script, script_path)+ raisefinally:sys.argv = orig_argv