From 4228550369203586221653870001917263661713 Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Mon, 7 Apr 2025 17:28:47 -0400 Subject: [SharedCache] Support loading from user plugins directory too Check for the core plugin setting and, if it's disabled, look in the user directory --- .../api/python/_sharedcachecore_template.py | 45 ++++++++++++++-------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'view/sharedcache/api/python') diff --git a/view/sharedcache/api/python/_sharedcachecore_template.py b/view/sharedcache/api/python/_sharedcachecore_template.py index 6b5b174f..01cf4b02 100644 --- a/view/sharedcache/api/python/_sharedcachecore_template.py +++ b/view/sharedcache/api/python/_sharedcachecore_template.py @@ -8,22 +8,37 @@ import platform core = None core_platform = platform.system() -# By the time the debugger is loaded, binaryninja has not fully initialized. -# So we cannot call binaryninja.bundled_plugin_path() -from binaryninja._binaryninjacore import BNGetBundledPluginDirectory, BNFreeString -if core_platform == "Darwin": - _base_path = BNGetBundledPluginDirectory() - core = ctypes.CDLL(os.path.join(_base_path, "libsharedcache.dylib")) - -elif core_platform == "Linux": - _base_path = BNGetBundledPluginDirectory() - core = ctypes.CDLL(os.path.join(_base_path, "libsharedcache.so")) - -elif (core_platform == "Windows") or (core_platform.find("CYGWIN_NT") == 0): - _base_path = BNGetBundledPluginDirectory() - core = ctypes.CDLL(os.path.join(_base_path, "sharedcache.dll")) +from binaryninja import Settings +if Settings().get_bool("corePlugins.view.sharedCache"): + from binaryninja._binaryninjacore import BNGetBundledPluginDirectory + if core_platform == "Darwin": + _base_path = BNGetBundledPluginDirectory() + core = ctypes.CDLL(os.path.join(_base_path, "libsharedcache.dylib")) + + elif core_platform == "Linux": + _base_path = BNGetBundledPluginDirectory() + core = ctypes.CDLL(os.path.join(_base_path, "libsharedcache.so")) + + elif (core_platform == "Windows") or (core_platform.find("CYGWIN_NT") == 0): + _base_path = BNGetBundledPluginDirectory() + core = ctypes.CDLL(os.path.join(_base_path, "sharedcache.dll")) + else: + raise Exception("OS not supported") else: - raise Exception("OS not supported") + from binaryninja._binaryninjacore import BNGetUserPluginDirectory + if core_platform == "Darwin": + _base_path = BNGetUserPluginDirectory() + core = ctypes.CDLL(os.path.join(_base_path, "libsharedcache.dylib")) + + elif core_platform == "Linux": + _base_path = BNGetUserPluginDirectory() + core = ctypes.CDLL(os.path.join(_base_path, "libsharedcache.so")) + + elif (core_platform == "Windows") or (core_platform.find("CYGWIN_NT") == 0): + _base_path = BNGetUserPluginDirectory() + core = ctypes.CDLL(os.path.join(_base_path, "sharedcache.dll")) + else: + raise Exception("OS not supported") def cstr(var) -> Optional[ctypes.c_char_p]: if var is None: -- cgit v1.3.1