From 748983133e5290f8fed74977ad69422926d78a1f Mon Sep 17 00:00:00 2001 From: Mike Hunhoff Date: Wed, 6 Sep 2023 07:12:45 -0600 Subject: [PATCH] add state function to Python builtins that exposes GhidraState object (#75) --- data/python/jepwrappers.py | 5 +++++ data/python/tests/test_jepbridge.py | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/data/python/jepwrappers.py b/data/python/jepwrappers.py index ec50ed5..1d12a44 100644 --- a/data/python/jepwrappers.py +++ b/data/python/jepwrappers.py @@ -307,6 +307,10 @@ def wrapped_monitor(): return get_script().getMonitor() +def wrapped_state(): + return get_script_state() + + def wrapped_currentProgram(): return get_script_state().getCurrentProgram() @@ -328,6 +332,7 @@ def wrapped_currentHighlight(): __builtins__["monitor"] = wrapped_monitor +__builtins__["state"] = wrapped_state __builtins__["currentProgram"] = wrapped_currentProgram __builtins__["currentAddress"] = wrapped_currentAddress __builtins__["currentLocation"] = wrapped_currentLocation diff --git a/data/python/tests/test_jepbridge.py b/data/python/tests/test_jepbridge.py index 501533b..89fd9a9 100644 --- a/data/python/tests/test_jepbridge.py +++ b/data/python/tests/test_jepbridge.py @@ -46,6 +46,7 @@ def test_type_instance(self): def test_ghidra_script_variables(self): self.assertIsJavaObject(monitor()) + self.assertIsJavaObject(state()) self.assertIsJavaObject(currentAddress()) self.assertIsJavaObject(currentProgram()) self.assertIsJavaObject(currentLocation()) @@ -53,6 +54,7 @@ def test_ghidra_script_variables(self): self.assertIsJavaObject(currentSelection()) self.assertIsNotJavaObject(monitor) + self.assertIsNotJavaObject(state) self.assertIsNotJavaObject(currentAddress) self.assertIsNotJavaObject(currentProgram) self.assertIsNotJavaObject(currentLocation) @@ -61,8 +63,12 @@ def test_ghidra_script_variables(self): def test_ghidra_script_methods(self): self.assertIsInstance(getGhidraVersion(), str) + self.assertIsJavaObject(getState()) def test_java_excluded_packages(self): import pdb self.assertIsNotJavaObject(pdb) + + def test_ghidra_script_state(self): + self.assertTrue(state() == getState())