Ghidra is a software reverse engineering (SRE) framework
GP-5298: PyGhidra can now find modules that live in directories specified by the Bundle Manager
Ryan Kurtzd71dc292ca2e
diff --git a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/__init__.py b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/__init__.pyindex 58b01b5552..79dd7071a4 100644--- a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/__init__.py+++ b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/__init__.py@@ -13,7 +13,7 @@# See the License for the specific language governing permissions and# limitations under the License.##-__version__ = "2.0.0"+__version__ = "2.0.1"# stub for documentation and typing# this is mostly to hide the function parameterdiff --git a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/launcher.py b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/launcher.pyindex e16c5ca4a7..03365ed161 100644--- a/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/launcher.py+++ b/Ghidra/Features/PyGhidra/src/main/py/src/pyghidra/launcher.py@@ -109,6 +109,22 @@ class _PyGhidraImportLoader:def exec_module(self, fullname):pass+class _GhidraBundleFinder(importlib.machinery.PathFinder):+ """ (internal) Used to find modules in Ghidra bundle locations """++ def find_spec(self, fullname, path=None, target=None):+ from ghidra.framework import Application+ from ghidra.app.script import GhidraScriptUtil+ if Application.isInitialized():+ GhidraScriptUtil.acquireBundleHostReference()+ try:+ for directory in GhidraScriptUtil.getEnabledScriptSourceDirectories():+ spec = super().find_spec(fullname, [directory.absolutePath], target)+ if spec is not None:+ return spec+ finally:+ GhidraScriptUtil.releaseBundleHostReference()+ return None@contextlib.contextmanagerdef _plugin_lock():@@ -390,8 +406,9 @@ class PyGhidraLauncher:**jpype_kwargs)- # Install hook into python importlib+ # Install hooks into python importlibsys.meta_path.append(_PyGhidraImportLoader())+ sys.meta_path.append(_GhidraBundleFinder())imports.registerDomain("ghidra")