From 56866ad97ab7cc207ce85542c5ec20e01a10352d Mon Sep 17 00:00:00 2001 From: Fariss Date: Wed, 8 May 2024 21:29:24 +0200 Subject: [PATCH] print environment details upon stack trace (#101) * print environment details upon stack trace * Add Ghidrathon plugin version number * Move exception handling and whitelisting to utils.py * Renamed jeputils & reformatted env details string This commit: - renames utils.py to jeputils.py avoid confusion. - reformats environment details string as a format string - enables getVersion method to be called statically * refactor: pass exception object to log_env_details --------- Co-authored-by: Soufiane Fariss --- data/python/jepeval.py | 3 +++ data/python/jeprunscript.py | 3 +++ data/python/jeputils.py | 23 +++++++++++++++++++ .../java/ghidrathon/GhidrathonPlugin.java | 6 +++++ 4 files changed, 35 insertions(+) create mode 100644 data/python/jeputils.py diff --git a/data/python/jepeval.py b/data/python/jepeval.py index c40f323..a60bcbf 100644 --- a/data/python/jepeval.py +++ b/data/python/jepeval.py @@ -79,6 +79,9 @@ def _jepeval(line): # in the Ghidra console window import traceback + import jeputils + traceback.print_exc() + jeputils.log_env_details(err) return more_input_needed diff --git a/data/python/jeprunscript.py b/data/python/jeprunscript.py index f36558a..49937dc 100644 --- a/data/python/jeprunscript.py +++ b/data/python/jeprunscript.py @@ -36,4 +36,7 @@ def jep_runscript(path): # messages in the Ghidra console window import traceback + import jeputils + traceback.print_exc() + jeputils.log_env_details(err) diff --git a/data/python/jeputils.py b/data/python/jeputils.py new file mode 100644 index 0000000..aa0823e --- /dev/null +++ b/data/python/jeputils.py @@ -0,0 +1,23 @@ +import sys +import platform + +import jep +import ghidrathon +from java.lang import System + +ALLOWED_EXCEPTIONS = (RuntimeError, OSError) + + +def log_env_details(exc): + exc_type = type(exc) + if issubclass(exc_type, ALLOWED_EXCEPTIONS): + print( + f"Python={platform.python_version()}, " + f"Arch={System.getProperty('os.arch')}, " + f"OS={System.getProperty('os.name')}, " + f"Ghidra={getGhidraVersion()}, " + f"Java={System.getProperty('java.version')}, " + f"Ghidrathon={ghidrathon.GhidrathonPlugin.getVersion()}, " + f"Jep={jep.__version__}", + file=sys.stderr, + ) diff --git a/src/main/java/ghidrathon/GhidrathonPlugin.java b/src/main/java/ghidrathon/GhidrathonPlugin.java index df2a45d..85e3a8d 100644 --- a/src/main/java/ghidrathon/GhidrathonPlugin.java +++ b/src/main/java/ghidrathon/GhidrathonPlugin.java @@ -46,6 +46,8 @@ public class GhidrathonPlugin extends ProgramPlugin implements InterpreterConnection, OptionsChangeListener { + private static final String VERSION = "4.0.0"; + private InterpreterConsole console; private GhidrathonConsoleInputThread inputThread; private TaskMonitor interactiveTaskMonitor; @@ -71,6 +73,10 @@ GhidrathonScript getInteractiveScript() { return interactiveScript; } + public static String getVersion() { + return VERSION; + } + @Override protected void init() {