| 1070 | return python_bin |
| 1071 | |
| 1072 | def _load_module(self, ctx, _repo_path: bytes, _module: bytes, force: bool): |
| 1073 | repo_path = _repo_path.decode("utf-8") |
| 1074 | module = _module.decode("utf-8") |
| 1075 | try: |
| 1076 | repo = RepositoryManager()[repo_path] |
| 1077 | plugin = repo[module] |
| 1078 | |
| 1079 | if not force and self.apiName not in plugin.api: |
| 1080 | raise ValueError(f"Plugin API name is not {self.name}") |
| 1081 | |
| 1082 | if not force and core.core_platform not in plugin.install_platforms: |
| 1083 | raise ValueError( |
| 1084 | f"Current platform {core.core_platform} isn't in list of valid platforms for this plugin {plugin.install_platforms}" |
| 1085 | ) |
| 1086 | if not plugin.installed: |
| 1087 | plugin.installed = True |
| 1088 | |
| 1089 | plugin_full_path = str(Path(repo.full_path) / plugin.path) |
| 1090 | if repo.full_path not in sys.path: |
| 1091 | sys.path.append(repo.full_path) |
| 1092 | if plugin_full_path not in sys.path: |
| 1093 | sys.path.append(plugin_full_path) |
| 1094 | |
| 1095 | if plugin.subdir: |
| 1096 | __import__(module + "." + plugin.subdir.replace("/", ".")) |
| 1097 | else: |
| 1098 | __import__(module) |
| 1099 | return True |
| 1100 | except KeyError: |
| 1101 | logger.log_error(f"Failed to find python plugin: {repo_path}/{module}") |
| 1102 | except ImportError as ie: |
| 1103 | logger.log_error(f"Failed to import python plugin: {repo_path}/{module}: {ie}") |
| 1104 | except binaryninja.UIPluginInHeadlessError: |
| 1105 | logger.log_info(f"Ignored python UI plugin: {repo_path}/{module}") |
| 1106 | return False |
| 1107 | |
| 1108 | # This function can only be used to execute commands that return ASCII-only output, otherwise the decoding will fail |
| 1109 | def _run_args(self, args, env: Optional[Dict]=None): |