(self, arch: Optional['architecture.Architecture'] = None, handle=None)
| 99 | _registered_platforms = [] |
| 100 | |
| 101 | def __init__(self, arch: Optional['architecture.Architecture'] = None, handle=None): |
| 102 | if handle is None: |
| 103 | if arch is None: |
| 104 | raise ValueError("platform must have an associated architecture") |
| 105 | assert self.__class__.name is not None, "Can not instantiate Platform directly, you probably want arch.standalone_platform" |
| 106 | _arch = arch |
| 107 | if len(self.global_regs) == 0: |
| 108 | self.__dict__["global_regs"] = arch.global_regs |
| 109 | self._cb = core.BNCustomPlatform() |
| 110 | self._cb.context = 0 |
| 111 | self._cb.init = self._cb.init.__class__(self._init) |
| 112 | self._cb.viewInit = self._cb.viewInit.__class__(self._view_init) |
| 113 | self._cb.getGlobalRegisters = self._cb.getGlobalRegisters.__class__(self._get_global_regs) |
| 114 | self._cb.freeRegisterList = self._cb.freeRegisterList.__class__(self._free_register_list) |
| 115 | self._cb.getGlobalRegisterType = self._cb.getGlobalRegisterType.__class__(self._get_global_reg_type) |
| 116 | self._cb.adjustTypeParserInput = self._cb.adjustTypeParserInput.__class__(self._adjust_type_parser_input) |
| 117 | self._cb.freeTypeParserInput = self._cb.freeTypeParserInput.__class__(self._free_type_parser_input) |
| 118 | self._pending_reg_lists = {} |
| 119 | self._pending_parser_input_lists = {} |
| 120 | if self.__class__.type_file_path is None: |
| 121 | _handle = core.BNCreateCustomPlatform(arch.handle, self.__class__.name, self._cb) |
| 122 | assert _handle is not None |
| 123 | else: |
| 124 | dir_buf = (ctypes.c_char_p * len(self.__class__.type_include_dirs))() |
| 125 | for (i, dir) in enumerate(self.__class__.type_include_dirs): |
| 126 | dir_buf[i] = dir.encode('charmap') |
| 127 | _handle = core.BNCreateCustomPlatformWithTypes( |
| 128 | arch.handle, self.__class__.name, self._cb, self.__class__.type_file_path, dir_buf, |
| 129 | len(self.__class__.type_include_dirs) |
| 130 | ) |
| 131 | assert _handle is not None |
| 132 | self.__class__._registered_platforms.append(self) |
| 133 | else: |
| 134 | if type(self) is Platform: |
| 135 | binaryninja.log_warn( |
| 136 | ":py:func:`Platform(handle=...)` is deprecated, use :py:func:`CorePlatform._from_cache(handle=...)`" |
| 137 | ) |
| 138 | _handle = handle |
| 139 | _arch = architecture.CoreArchitecture._from_cache(core.BNGetPlatformArchitecture(_handle)) |
| 140 | count = ctypes.c_ulonglong() |
| 141 | regs = core.BNGetPlatformGlobalRegisters(handle, count) |
| 142 | result = [] |
| 143 | for i in range(0, count.value): |
| 144 | result.append(_arch.get_reg_name(regs[i])) |
| 145 | core.BNFreeRegisterList(regs) |
| 146 | self.__dict__["global_regs"] = result |
| 147 | assert _handle is not None |
| 148 | assert _arch is not None |
| 149 | self.handle: ctypes.POINTER(core.BNPlatform) = _handle |
| 150 | self._arch = _arch |
| 151 | self._name = None |
| 152 | |
| 153 | def _init(self, ctxt): |
| 154 | pass |
no test coverage detected