From 44d8b535bd12b81110d3a0826b895bd0d5657f2b Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Sun, 11 Feb 2024 11:30:41 -0500 Subject: Add BinaryView::GetTypeNameByGuid API --- binaryninjaapi.h | 8 ++++++++ binaryninjacore.h | 2 ++ binaryview.cpp | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 39a0be59..d412464d 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -5943,6 +5943,14 @@ namespace BinaryNinja { */ Ref ImportTypeLibraryTypeByGuid(const std::string& guid); + + /* Looks up the name of a type by its guid in the current BinaryView's set of type libraries + + \param guid + \return The QualifedName of the type or std::nullopt if it was not found + */ + std::optional GetTypeNameByGuid(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 9472339e..e7c895de 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -5594,6 +5594,8 @@ extern "C" BNBinaryView* view, BNTypeLibrary** lib, BNQualifiedName* name); BINARYNINJACOREAPI BNType* BNBinaryViewImportTypeLibraryTypeByGuid( BNBinaryView* view, const char* guid); + BINARYNINJACOREAPI BNQualifiedName BNBinaryViewGetTypeNameByGuid( + 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 4a6adb92..057c0954 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -4212,6 +4212,18 @@ Ref BinaryView::ImportTypeLibraryTypeByGuid(const string& guid) } +std::optional BinaryView::GetTypeNameByGuid(const std::string& guid) +{ + auto result = BNBinaryViewGetTypeNameByGuid(m_object, guid.c_str()); + if (result.nameCount == 0) + return std::nullopt; + + auto name = QualifiedName::FromAPIObject(&result); + BNFreeQualifiedName(&result); + return name; +} + + void BinaryView::ExportTypeToTypeLibrary(TypeLibrary* lib, const QualifiedName& name, Type* type) { BNQualifiedName apiName = name.GetAPIObject(); -- cgit v1.3.1