From afd917ff5167116cc2342ab1f40c25bdeb448aa6 Mon Sep 17 00:00:00 2001 From: Soufiane Fariss Date: Fri, 12 Apr 2024 03:43:41 +0200 Subject: [PATCH 1/5] print environment details upon stack trace --- data/python/jepeval.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/data/python/jepeval.py b/data/python/jepeval.py index c40f323..3f510f2 100644 --- a/data/python/jepeval.py +++ b/data/python/jepeval.py @@ -81,4 +81,23 @@ def _jepeval(line): traceback.print_exc() + def log_env_details(): + import platform + + import jep + from java.lang import System + + print( + "Python={python_version}, Arch={arch}, OS={os}, Ghidra={ghidra_version}, Java={java_version}, Ghidrathon=4.0.0, Jep={jep_version}".format( + python_version=platform.python_version(), + arch=System.getProperty("os.arch"), + os=System.getProperty("os.name"), + ghidra_version=getGhidraVersion(), + java_version=System.getProperty("java.version"), + jep_version=jep.__version__, + ) + ) + + log_env_details() + return more_input_needed From 99b25b8f9d56a5b836ad58533f97235c09bc516d Mon Sep 17 00:00:00 2001 From: Soufiane Fariss Date: Wed, 17 Apr 2024 21:05:11 +0200 Subject: [PATCH 2/5] Add Ghidrathon plugin version number --- src/main/java/ghidrathon/GhidrathonPlugin.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/ghidrathon/GhidrathonPlugin.java b/src/main/java/ghidrathon/GhidrathonPlugin.java index df2a45d..267fb7f 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 String getVersion() { + return VERSION; + } + @Override protected void init() { From c1a84003b1d3b69a6d45ff8c91c442df7dd5128d Mon Sep 17 00:00:00 2001 From: Soufiane Fariss Date: Thu, 18 Apr 2024 21:53:13 +0200 Subject: [PATCH 3/5] Move exception handling and whitelisting to utils.py --- data/python/jepeval.py | 22 +++------------------- data/python/jeprunscript.py | 3 +++ data/python/utils.py | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 19 deletions(-) create mode 100644 data/python/utils.py diff --git a/data/python/jepeval.py b/data/python/jepeval.py index 3f510f2..2ad7431 100644 --- a/data/python/jepeval.py +++ b/data/python/jepeval.py @@ -79,25 +79,9 @@ def _jepeval(line): # in the Ghidra console window import traceback - traceback.print_exc() - - def log_env_details(): - import platform - - import jep - from java.lang import System + import utils - print( - "Python={python_version}, Arch={arch}, OS={os}, Ghidra={ghidra_version}, Java={java_version}, Ghidrathon=4.0.0, Jep={jep_version}".format( - python_version=platform.python_version(), - arch=System.getProperty("os.arch"), - os=System.getProperty("os.name"), - ghidra_version=getGhidraVersion(), - java_version=System.getProperty("java.version"), - jep_version=jep.__version__, - ) - ) - - log_env_details() + traceback.print_exc() + utils.log_env_details(type(err)) return more_input_needed diff --git a/data/python/jeprunscript.py b/data/python/jeprunscript.py index f36558a..6035e73 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 utils + traceback.print_exc() + utils.log_env_details(type(err)) diff --git a/data/python/utils.py b/data/python/utils.py new file mode 100644 index 0000000..abee90e --- /dev/null +++ b/data/python/utils.py @@ -0,0 +1,24 @@ +import sys +import platform + +import jep +import ghidrathon +from java.lang import System + +ALLOWED_EXCEPTIONS = [RuntimeError, OSError] + + +def log_env_details(exc_type): + if any(issubclass(exc_type, exc_class) for exc_class in ALLOWED_EXCEPTIONS): + print( + "Python={python_version}, Arch={arch}, OS={os}, Ghidra={ghidra_version}, Java={java_version}, Ghidrathon={ghidrathon_version}, Jep={jep_version}".format( + python_version=platform.python_version(), + arch=System.getProperty("os.arch"), + os=System.getProperty("os.name"), + ghidra_version=getGhidraVersion(), + java_version=System.getProperty("java.version"), + ghidrathon_version="4.0.0", + jep_version=jep.__version__, + ), + file=sys.stderr, + ) From 46f45fdffff6c8df64e5d9f87f41d0c1a91ef523 Mon Sep 17 00:00:00 2001 From: Soufiane Fariss Date: Sun, 28 Apr 2024 16:50:19 +0200 Subject: [PATCH 4/5] 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 --- data/python/jepeval.py | 4 ++-- data/python/jeprunscript.py | 4 ++-- data/python/jeputils.py | 22 +++++++++++++++++ data/python/utils.py | 24 ------------------- .../java/ghidrathon/GhidrathonPlugin.java | 2 +- 5 files changed, 27 insertions(+), 29 deletions(-) create mode 100644 data/python/jeputils.py delete mode 100644 data/python/utils.py diff --git a/data/python/jepeval.py b/data/python/jepeval.py index 2ad7431..f6edf17 100644 --- a/data/python/jepeval.py +++ b/data/python/jepeval.py @@ -79,9 +79,9 @@ def _jepeval(line): # in the Ghidra console window import traceback - import utils + import jeputils traceback.print_exc() - utils.log_env_details(type(err)) + jeputils.log_env_details(type(err)) return more_input_needed diff --git a/data/python/jeprunscript.py b/data/python/jeprunscript.py index 6035e73..6e8e254 100644 --- a/data/python/jeprunscript.py +++ b/data/python/jeprunscript.py @@ -36,7 +36,7 @@ def jep_runscript(path): # messages in the Ghidra console window import traceback - import utils + import jeputils traceback.print_exc() - utils.log_env_details(type(err)) + jeputils.log_env_details(type(err)) diff --git a/data/python/jeputils.py b/data/python/jeputils.py new file mode 100644 index 0000000..389fe6b --- /dev/null +++ b/data/python/jeputils.py @@ -0,0 +1,22 @@ +import sys +import platform + +import jep +import ghidrathon +from java.lang import System + +ALLOWED_EXCEPTIONS = [RuntimeError, OSError] + + +def log_env_details(exc_type): + if any(issubclass(exc_type, exc_class) for exc_class in 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/data/python/utils.py b/data/python/utils.py deleted file mode 100644 index abee90e..0000000 --- a/data/python/utils.py +++ /dev/null @@ -1,24 +0,0 @@ -import sys -import platform - -import jep -import ghidrathon -from java.lang import System - -ALLOWED_EXCEPTIONS = [RuntimeError, OSError] - - -def log_env_details(exc_type): - if any(issubclass(exc_type, exc_class) for exc_class in ALLOWED_EXCEPTIONS): - print( - "Python={python_version}, Arch={arch}, OS={os}, Ghidra={ghidra_version}, Java={java_version}, Ghidrathon={ghidrathon_version}, Jep={jep_version}".format( - python_version=platform.python_version(), - arch=System.getProperty("os.arch"), - os=System.getProperty("os.name"), - ghidra_version=getGhidraVersion(), - java_version=System.getProperty("java.version"), - ghidrathon_version="4.0.0", - jep_version=jep.__version__, - ), - file=sys.stderr, - ) diff --git a/src/main/java/ghidrathon/GhidrathonPlugin.java b/src/main/java/ghidrathon/GhidrathonPlugin.java index 267fb7f..85e3a8d 100644 --- a/src/main/java/ghidrathon/GhidrathonPlugin.java +++ b/src/main/java/ghidrathon/GhidrathonPlugin.java @@ -73,7 +73,7 @@ GhidrathonScript getInteractiveScript() { return interactiveScript; } - public String getVersion() { + public static String getVersion() { return VERSION; } From b2a99ccaddb83ae143e4ae5cbc02ea238e8a057d Mon Sep 17 00:00:00 2001 From: Soufiane Fariss Date: Mon, 29 Apr 2024 19:16:08 +0200 Subject: [PATCH 5/5] refactor: pass exception object to log_env_details --- data/python/jepeval.py | 2 +- data/python/jeprunscript.py | 2 +- data/python/jeputils.py | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/data/python/jepeval.py b/data/python/jepeval.py index f6edf17..a60bcbf 100644 --- a/data/python/jepeval.py +++ b/data/python/jepeval.py @@ -82,6 +82,6 @@ def _jepeval(line): import jeputils traceback.print_exc() - jeputils.log_env_details(type(err)) + jeputils.log_env_details(err) return more_input_needed diff --git a/data/python/jeprunscript.py b/data/python/jeprunscript.py index 6e8e254..49937dc 100644 --- a/data/python/jeprunscript.py +++ b/data/python/jeprunscript.py @@ -39,4 +39,4 @@ def jep_runscript(path): import jeputils traceback.print_exc() - jeputils.log_env_details(type(err)) + jeputils.log_env_details(err) diff --git a/data/python/jeputils.py b/data/python/jeputils.py index 389fe6b..aa0823e 100644 --- a/data/python/jeputils.py +++ b/data/python/jeputils.py @@ -5,11 +5,12 @@ import ghidrathon from java.lang import System -ALLOWED_EXCEPTIONS = [RuntimeError, OSError] +ALLOWED_EXCEPTIONS = (RuntimeError, OSError) -def log_env_details(exc_type): - if any(issubclass(exc_type, exc_class) for exc_class in ALLOWED_EXCEPTIONS): +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')}, "