def list(self): binaryninja._init_plugins() count = ctypes.c_ulonglong() platforms = core.BNGetPlatformList(count) result = [] for i in range(0, count.value): result.append( Platform(handle=core.BNNewPlatformReference(platforms[i]))) core.BNFreePlatformList(platforms, count.value) return result
def _parse_types_from_source(self, ctxt, source, fileName, platform_, existingTypes, existingTypeCount, options, optionCount, includeDirs, includeDirCount, autoTypeSource, result, errors, errorCount) -> bool: try: source_py = core.pyNativeStr(source) file_name_py = core.pyNativeStr(fileName) platform_py = platform.Platform( handle=core.BNNewPlatformReference(platform_)) existing_types_py = [] for i in range(existingTypeCount): existing_types_py.append( QualifiedNameTypeAndId._from_core_struct(existingTypes[i])) options_py = [] for i in range(optionCount): options_py.append(core.pyNativeStr(options[i])) include_dirs_py = [] for i in range(includeDirCount): include_dirs_py.append(core.pyNativeStr(includeDirs[i])) auto_type_source = core.pyNativeStr(autoTypeSource) (result_py, errors_py) = self.parse_types_from_source( source_py, file_name_py, platform_py, existing_types_py, options_py, include_dirs_py, auto_type_source) if result_py is not None and result is not None: result_struct = result_py._to_core_struct() TypeParser._cached_result = result_struct result[0] = result_struct if errorCount is not None: errorCount[0] = len(errors_py) if errors is not None: errors_out = (core.BNTypeParserError * len(errors_py))() for i in range(len(errors_py)): errors_out[i] = errors_py[i]._to_core_struct() TypeParser._cached_error = errors_out errors[0] = errors_out return result_py is not None except: result[0].typeCount = 0 result[0].variableCount = 0 result[0].functionCount = 0 errorCount[0] = 0 log_error(traceback.format_exc()) return False
def get_list(cls, os = None, arch = None): binaryninja._init_plugins() count = ctypes.c_ulonglong() if os is None: platforms = core.BNGetPlatformList(count) elif arch is None: platforms = core.BNGetPlatformListByOS(os) else: platforms = core.BNGetPlatformListByArchitecture(os, arch.handle) result = [] for i in range(0, count.value): result.append(Platform(handle = core.BNNewPlatformReference(platforms[i]))) core.BNFreePlatformList(platforms, count.value) return result
def _get_type_string(self, ctxt, type, platform, name, escaping, result): try: platform_py = None if platform: platform_py = _platform.Platform( handle=core.BNNewPlatformReference(platform)) result_py = self.get_type_string( types.Type(handle=core.BNNewTypeReference(type)), platform_py, types.QualifiedName._from_core_struct(name.contents), escaping) TypePrinter._cached_string = core.cstr(result_py) result[0] = TypePrinter._cached_string return True except: log_error(traceback.format_exc()) return False
def _preprocess_source(self, ctxt, source, fileName, platform_, existingTypes, existingTypeCount, options, optionCount, includeDirs, includeDirCount, output, errors, errorCount) -> bool: try: source_py = core.pyNativeStr(source) file_name_py = core.pyNativeStr(fileName) platform_py = platform.Platform( handle=core.BNNewPlatformReference(platform_)) existing_types_py = [] for i in range(existingTypeCount): existing_types_py.append( QualifiedNameTypeAndId._from_core_struct(existingTypes[i])) options_py = [] for i in range(optionCount): options_py.append(core.pyNativeStr(options[i])) include_dirs_py = [] for i in range(includeDirCount): include_dirs_py.append(core.pyNativeStr(includeDirs[i])) (output_py, errors_py) = self.preprocess_source( source_py, file_name_py, platform_py, existing_types_py, options_py, include_dirs_py) if output_py is not None and output is not None: TypeParser._cached_string = core.cstr(output_py) output[0] = TypeParser._cached_string if errorCount is not None: errorCount[0] = len(errors_py) if errors is not None: errors_out = (core.BNTypeParserError * len(errors_py))() for i in range(len(errors_py)): errors_out[i] = errors_py[i]._to_core_struct() TypeParser._cached_error = errors_out errors[0] = errors_out return output_py is not None except: errorCount[0] = 0 log_error(traceback.format_exc()) return False
def _get_type_tokens(self, ctxt, type, platform, name, base_confidence, escaping, result, result_count): try: platform_py = None if platform: platform_py = _platform.Platform( handle=core.BNNewPlatformReference(platform)) result_py = self.get_type_tokens( types.Type(handle=core.BNNewTypeReference(type)), platform_py, types.QualifiedName._from_core_struct(name.contents), base_confidence, escaping) TypePrinter._cached_tokens = _function.InstructionTextToken._get_core_struct( result_py) result[0] = TypePrinter._cached_tokens result_count[0] = len(result_py) return True except: log_error(traceback.format_exc()) return False
def _parse_type_string(self, ctxt, source, platform_, existingTypes, existingTypeCount, result, errors, errorCount) -> bool: try: source_py = core.pyNativeStr(source) platform_py = platform.Platform( handle=core.BNNewPlatformReference(platform_)) existing_types_py = [] for i in range(existingTypeCount): existing_types_py.append( QualifiedNameTypeAndId._from_core_struct(existingTypes[i])) (result_py, errors_py) = self.parse_type_string(source_py, platform_py, existing_types_py) if result_py is not None and result is not None: result[0].name = types.QualifiedName( result_py[0])._to_core_struct() result[0].type = core.BNNewTypeReference(result_py[1].handle) if errorCount is not None: errorCount[0] = len(errors_py) if errors is not None: errors_out = (core.BNTypeParserError * len(errors_py))() for i in range(len(errors_py)): errors_out[i] = errors_py[i]._to_core_struct() TypeParser._cached_error = errors_out errors[0] = errors_out return result_py is not None except: errorCount[0] = 0 log_error(traceback.format_exc()) return False