Skip to content

Commit

Permalink
print environment details upon stack trace (#101)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
fariss and fariss authored May 8, 2024
1 parent a3deefd commit 56866ad
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions data/python/jepeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions data/python/jeprunscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
23 changes: 23 additions & 0 deletions data/python/jeputils.py
Original file line number Diff line number Diff line change
@@ -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,
)
6 changes: 6 additions & 0 deletions src/main/java/ghidrathon/GhidrathonPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -71,6 +73,10 @@ GhidrathonScript getInteractiveScript() {
return interactiveScript;
}

public static String getVersion() {
return VERSION;
}

@Override
protected void init() {

Expand Down

0 comments on commit 56866ad

Please sign in to comment.