diff options
| author | Peter LaFosse <peter@vector35.com> | 2024-02-07 17:19:24 -0500 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2024-02-07 17:19:34 -0500 |
| commit | e1542ed05f3f8c273206bb9ead8d39fea87430bb (patch) | |
| tree | c7927fe2b3a4cd0122ee8f95727d75fcefb0017a | |
| parent | f5ceadd9baddaa55111d6112e487428363fe981f (diff) | |
Add ImportTypeLibraryTypeByGuid API and dialog
| -rw-r--r-- | binaryninjaapi.h | 14 | ||||
| -rw-r--r-- | binaryninjacore.h | 2 | ||||
| -rw-r--r-- | binaryview.cpp | 9 | ||||
| -rw-r--r-- | python/binaryview.py | 22 | ||||
| -rw-r--r-- | ui/typebrowser.h | 1 |
5 files changed, 35 insertions, 13 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index e3a5ec4d..66bf0c21 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -5892,6 +5892,20 @@ namespace BinaryNinja { */ Ref<Type> ImportTypeLibraryObject(Ref<TypeLibrary>& lib, const QualifiedName& name); + + /*! Recursively imports a type by guid from the current BinaryView's set of type libraries + + This API is dependent on the set of TypeLibraries for the current BinaryView's Platform, + having appropriate metadata to resolve the type by guid. The key "type_guids" must contain + a map(string(guid), string(type_name)) or + map(string(guid), tuple(sting(type_name), string(library_name))). + + \param guid + \return The type, or nullptr if it was not found + + */ + Ref<Type> ImportTypeLibraryTypeByGuid(const std::string& guid); + /*! Recursively exports ``type`` into ``lib`` as a type with name ``name`` As other referenced types are encountered, they are either copied into the destination type library or diff --git a/binaryninjacore.h b/binaryninjacore.h index 085c52fb..90eaaf00 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -5562,6 +5562,8 @@ extern "C" BNBinaryView* view, BNTypeLibrary** lib, BNQualifiedName* name); BINARYNINJACOREAPI BNType* BNBinaryViewImportTypeLibraryObject( BNBinaryView* view, BNTypeLibrary** lib, BNQualifiedName* name); + BINARYNINJACOREAPI BNType* BNBinaryViewImportTypeLibraryTypeByGuid( + BNBinaryView* view, const char* guid); BINARYNINJACOREAPI void BNBinaryViewExportTypeToTypeLibrary( BNBinaryView* view, BNTypeLibrary* lib, BNQualifiedName* name, BNType* type); diff --git a/binaryview.cpp b/binaryview.cpp index 600b46ac..aa275d4a 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -4161,6 +4161,15 @@ Ref<Type> BinaryView::ImportTypeLibraryObject(Ref<TypeLibrary>& lib, const Quali } +Ref<Type> BinaryView::ImportTypeLibraryTypeByGuid(const string& guid) +{ + BNType* result = BNBinaryViewImportTypeLibraryTypeByGuid(m_object, guid.c_str()); + if (!result) + return nullptr; + return new Type(result); +} + + void BinaryView::ExportTypeToTypeLibrary(TypeLibrary* lib, const QualifiedName& name, Type* type) { BNQualifiedName apiName = name.GetAPIObject(); diff --git a/python/binaryview.py b/python/binaryview.py index cb671d58..96c93876 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -7490,11 +7490,14 @@ class BinaryView: return None return _types.Type.create(handle, platform=self.platform) - def import_com_type_for_guid(self, guid: Union[str, uuid.UUID]) -> Optional['_types.Type']: + def import_type_by_guid(self, guid: Union[str, uuid.UUID]) -> Optional['_types.Type']: """ - ``import_com_type_for_guid`` recursively imports a com interface given its GUID. + ``import_type_by_guid`` recursively imports a type interface given its GUID. - .. note:: This method is only available on Windows. + .. note:: To support this type of lookup a type library must have + contain a metadata key called "type_guids" which is a map + Dict[string_guid, string_type_name] or + Dict[string_guid, Tuple[string_type_name, type_library_name]] :param str guid: GUID of the COM interface to import :return: the object type, with any interior `NamedTypeReferences` renamed as necessary to be appropriate for the current view @@ -7506,17 +7509,10 @@ class BinaryView: if self.arch is None: return None - tl_name = "winX64common" if self.arch.name == "x86_64" else "win32common" - tl = self.get_type_library(tl_name) - if tl is None: - return None + if type_handle := core.BNBinaryViewImportTypeLibraryTypeByGuid(self.handle, guid): + return _types.Type.create(type_handle, platform=self.platform) - type_name = tl.metadata.get("com_interface_guids", {}) - assert isinstance(type_name, dict) - type_name = type_name.get(guid, None) - if type_name is None: - return None - return self.import_library_type(type_name, tl) + return None def import_library_object(self, name: str, lib: Optional[typelibrary.TypeLibrary] = None) -> Optional[Tuple['typelibrary.TypeLibrary', '_types.Type']]: """ diff --git a/ui/typebrowser.h b/ui/typebrowser.h index b17a73ad..006568fa 100644 --- a/ui/typebrowser.h +++ b/ui/typebrowser.h @@ -430,6 +430,7 @@ public: void importType(); bool canAddTypeLibrary(); void addTypeLibrary(); + void importTypeByGUID(); bool canExpandAll(); void expandAll(); bool canCollapseAll(); |
