From ca2d870a3aac0b2154b06f3ab075ca22bd0a0596 Mon Sep 17 00:00:00 2001 From: Ryan Snyder Date: Fri, 13 Sep 2019 21:08:25 -0400 Subject: typelibrary: more consistent naming, type exports --- python/architecture.py | 3 +-- python/binaryview.py | 28 +++++++++++++++++++++++----- python/platform.py | 2 +- 3 files changed, 25 insertions(+), 8 deletions(-) (limited to 'python') diff --git a/python/architecture.py b/python/architecture.py index 296bdab9..8498951d 100644 --- a/python/architecture.py +++ b/python/architecture.py @@ -31,7 +31,6 @@ import binaryninja from binaryninja import log from binaryninja import lowlevelil from binaryninja import types -from binaryninja import typelibrary from binaryninja import databuffer from binaryninja import platform from binaryninja import callingconvention @@ -438,7 +437,7 @@ class Architecture(with_metaclass(_ArchitectureMetaClass, object)): result = [] handles = core.BNGetArchitectureTypeLibraries(self.handle, count) for i in range(0, count.value): - result.append(typelibrary.TypeLibrary(core.BNNewTypeLibraryReference(handles[i]))) + result.append(binaryninja.typelibrary.TypeLibrary(core.BNNewTypeLibraryReference(handles[i]))) core.BNFreeTypeLibraryList(handles, count.value) return result diff --git a/python/binaryview.py b/python/binaryview.py index fe3d7dbe..251e96dd 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -1621,7 +1621,7 @@ class BinaryView(object): def type_libraries(self): """List of imported type libraries (read-only)""" count = ctypes.c_ulonglong(0) - libraries = core.BNBinaryViewGetTypeLibraries(self.handle, count) + libraries = core.BNGetBinaryViewTypeLibraries(self.handle, count) result = [] for i in range(0, count.value): result.append(typelibrary.TypeLibrary(core.BNNewTypeLibraryReference(libraries[i]))) @@ -4500,7 +4500,7 @@ class BinaryView(object): """ if not isinstance(lib, typelibrary.TypeLibrary): raise ValueError("must pass in a TypeLibrary object") - core.BNBinaryViewAddTypeLibrary(self.handle, lib.handle) + core.BNAddBinaryViewTypeLibrary(self.handle, lib.handle) def get_type_library(self, name): """ @@ -4512,7 +4512,7 @@ class BinaryView(object): :Example: """ - handle = core.BNBinaryViewGetTypeLibrary(self.handle, name) + handle = core.BNGetBinaryViewTypeLibrary(self.handle, name) if handle is None: return None return typelibrary.TypeLibrary(handle) @@ -4640,7 +4640,7 @@ class BinaryView(object): def import_library_type(self, name, lib = None): if not isinstance(name, types.QualifiedName): name = types.QualifiedName(name) - handle = core.BNBinaryViewImportLibraryType(self.handle, None if lib is None else lib.handle, name._get_core_struct()) + handle = core.BNBinaryViewImportTypeLibraryType(self.handle, None if lib is None else lib.handle, name._get_core_struct()) if handle is None: return None return types.Type(handle, platform = self.platform) @@ -4648,11 +4648,29 @@ class BinaryView(object): def import_library_object(self, name, lib = None): if not isinstance(name, types.QualifiedName): name = types.QualifiedName(name) - handle = core.BNBinaryViewImportLibraryObject(self.handle, None if lib is None else lib.handle, name._get_core_struct()) + handle = core.BNBinaryViewImportTypeLibraryObject(self.handle, None if lib is None else lib.handle, name._get_core_struct()) if handle is None: return None return types.Type(handle, platform = self.platform) + def export_type_to_library(self, lib, name, type_obj): + if not isinstance(name, types.QualifiedName): + name = types.QualifiedName(name) + if not isinstance(lib, typelibrary.TypeLibrary): + raise ValueError("lib must be a TypeLibrary object") + if not isinstance(type_obj, types.Type): + raise ValueError("type_obj must be a Type object") + core.BNBinaryViewExportTypeToTypeLibrary(self.handle, lib.handle, name._get_core_struct(), type_obj.handle) + + def export_object_to_library(self, lib, name, type_obj): + if not isinstance(name, types.QualifiedName): + name = types.QualifiedName(name) + if not isinstance(lib, typelibrary.TypeLibrary): + raise ValueError("lib must be a TypeLibrary object") + if not isinstance(type_obj, types.Type): + raise ValueError("type_obj must be a Type object") + core.BNBinaryViewExportObjectToTypeLibrary(self.handle, lib.handle, name._get_core_struct(), type_obj.handle) + def register_platform_types(self, platform): """ ``register_platform_types`` ensures that the platform-specific types for a :py:Class:`Platform` are available diff --git a/python/platform.py b/python/platform.py index 2d061172..2091e1d1 100644 --- a/python/platform.py +++ b/python/platform.py @@ -296,7 +296,7 @@ class Platform(with_metaclass(_PlatformMetaClass, object)): core.BNFreeTypeLibraryList(libs, count.value) return result - def type_libraries_by_name(self, name): + def get_type_libraries_by_name(self, name): count = ctypes.c_ulonglong(0) libs = core.BNGetPlatformTypeLibrariesByName(self.handle, name, count) result = [] -- cgit v1.3.1