Merge remote-tracking branch 'origin/patch'

This commit is contained in:
Ryan Kurtz 2025-02-07 09:56:36 -05:00
commit 684ed5ec6c
2 changed files with 19 additions and 2 deletions

View file

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
## ##
__version__ = "2.0.0" __version__ = "2.0.1"
# stub for documentation and typing # stub for documentation and typing
# this is mostly to hide the function parameter # this is mostly to hide the function parameter

View file

@ -109,6 +109,22 @@ class _PyGhidraImportLoader:
def exec_module(self, fullname): def exec_module(self, fullname):
pass 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.contextmanager @contextlib.contextmanager
def _plugin_lock(): def _plugin_lock():
@ -390,8 +406,9 @@ class PyGhidraLauncher:
**jpype_kwargs **jpype_kwargs
) )
# Install hook into python importlib # Install hooks into python importlib
sys.meta_path.append(_PyGhidraImportLoader()) sys.meta_path.append(_PyGhidraImportLoader())
sys.meta_path.append(_GhidraBundleFinder())
imports.registerDomain("ghidra") imports.registerDomain("ghidra")