From 63e72efd13b31c1d2061b978e2a5f4688e7ba4fd Mon Sep 17 00:00:00 2001 From: Glenn Smith Date: Thu, 14 Apr 2022 17:25:29 -0400 Subject: Add Analysis::GetTypeByRef, which searches for types by id/name Due to bugs, sometimes named types will not have a correct id, leading to bugs --- binaryninjaapi.h | 2 ++ binaryninjacore.h | 1 + binaryview.cpp | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index a50fcc62..bfa94d6f 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1737,6 +1737,7 @@ namespace BinaryNinja { struct PossibleValueSet; class Metadata; class Structure; + class NamedTypeReference; struct TypeParserResult; class QueryMetadataException : public std::exception @@ -2121,6 +2122,7 @@ namespace BinaryNinja { std::map> GetTypes(); std::vector GetTypeNames(const std::string& matching = ""); Ref GetTypeByName(const QualifiedName& name); + Ref GetTypeByRef(Ref name); Ref GetTypeById(const std::string& id); std::string GetTypeId(const QualifiedName& name); QualifiedName GetTypeNameById(const std::string& id); diff --git a/binaryninjacore.h b/binaryninjacore.h index 58fb6bf2..587e5920 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -4189,6 +4189,7 @@ extern "C" BINARYNINJACOREAPI BNQualifiedName* BNGetAnalysisTypeNames(BNBinaryView* view, size_t* count, const char* matching); BINARYNINJACOREAPI void BNFreeTypeNameList(BNQualifiedName* names, size_t count); BINARYNINJACOREAPI BNType* BNGetAnalysisTypeByName(BNBinaryView* view, BNQualifiedName* name); + BINARYNINJACOREAPI BNType* BNGetAnalysisTypeByRef(BNBinaryView* view, BNNamedTypeReference* ref); BINARYNINJACOREAPI BNType* BNGetAnalysisTypeById(BNBinaryView* view, const char* id); BINARYNINJACOREAPI char* BNGetAnalysisTypeId(BNBinaryView* view, BNQualifiedName* name); BINARYNINJACOREAPI BNQualifiedName BNGetAnalysisTypeNameById(BNBinaryView* view, const char* id); diff --git a/binaryview.cpp b/binaryview.cpp index 70d866ce..24058619 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -3187,6 +3187,15 @@ Ref BinaryView::GetTypeByName(const QualifiedName& name) } +Ref BinaryView::GetTypeByRef(Ref ref) +{ + BNType* type = BNGetAnalysisTypeByRef(m_object, ref->m_object); + if (!type) + return nullptr; + return new Type(BNNewTypeReference(type)); +} + + Ref BinaryView::GetTypeById(const string& id) { BNType* type = BNGetAnalysisTypeById(m_object, id.c_str()); -- cgit v1.3.1