From cd9eea2fdbd51c25a9f17435c561b6fe9377960f Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Wed, 15 Oct 2025 13:07:19 -0400 Subject: Add GetTypeCount API Add note about type_names not being sorted anymore --- binaryninjaapi.h | 8 +++++++- binaryninjacore.h | 1 + python/binaryview.py | 5 ++++- python/typecontainer.py | 8 ++++++++ typecontainer.cpp | 6 ++++++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index a243f974..fd1363b2 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -20115,7 +20115,7 @@ namespace BinaryNinja { */ std::optional> GetTypeIds() const; - /*! Get all type names in a Type Container. + /*! Get all type names in a Type Container. Sort order is not guaranteed in 5.2 and later. \return List of all type names */ @@ -20127,6 +20127,12 @@ namespace BinaryNinja { */ std::optional> GetTypeNamesAndIds() const; + /*! Get the number of types in a Type Container. + + \return Number of types in the container + */ + size_t GetTypeCount() const; + /*! Parse a single type and name from a string containing their definition, with knowledge of the types in the Type Container. diff --git a/binaryninjacore.h b/binaryninjacore.h index c6fa691d..60850f38 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -5642,6 +5642,7 @@ extern "C" BINARYNINJACOREAPI bool BNTypeContainerGetTypeIds(BNTypeContainer* container, char*** typeIds, size_t* count); BINARYNINJACOREAPI bool BNTypeContainerGetTypeNames(BNTypeContainer* container, BNQualifiedName** typeNames, size_t* count); BINARYNINJACOREAPI bool BNTypeContainerGetTypeNamesAndIds(BNTypeContainer* container, char*** typeIds, BNQualifiedName** typeNames, size_t* count); + BINARYNINJACOREAPI size_t BNTypeContainerGetTypeCount(BNTypeContainer* container); BINARYNINJACOREAPI bool BNTypeContainerParseTypeString(BNTypeContainer* container, const char* source, bool importDepencencies, BNQualifiedNameAndType* result, BNTypeParserError** errors, size_t* errorCount diff --git a/python/binaryview.py b/python/binaryview.py index 26d20edd..4a8526e3 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -3471,7 +3471,10 @@ class BinaryView: @property def type_names(self) -> List['_types.QualifiedName']: - """List of defined type names (read-only)""" + """List of defined type names (read-only) + + .. note:: Sort order is not guaranteed in 5.2 and later. + """ count = ctypes.c_ulonglong(0) name_list = core.BNGetAnalysisTypeNames(self.handle, count, "") assert name_list is not None, "core.BNGetAnalysisTypeNames returned None" diff --git a/python/typecontainer.py b/python/typecontainer.py index b4a9e794..aafa9117 100644 --- a/python/typecontainer.py +++ b/python/typecontainer.py @@ -329,6 +329,14 @@ class TypeContainer: core.BNFreeStringList(result_ids, result_count.value) return result + @property + def type_count(self) -> int: + """ + Get the number of types in a Type Container. + :return: Number of types in the container + """ + return core.BNTypeContainerGetTypeCount(self.handle) + def parse_type_string( self, source: str, import_dependencies: bool = True ) -> Tuple[Optional[Tuple['_types.QualifiedNameType', '_types.Type']], List['typeparser.TypeParserError']]: diff --git a/typecontainer.cpp b/typecontainer.cpp index 244c7a27..d6283cf0 100644 --- a/typecontainer.cpp +++ b/typecontainer.cpp @@ -336,6 +336,12 @@ std::optional> TypeContainer::Get } +size_t TypeContainer::GetTypeCount() const +{ + return BNTypeContainerGetTypeCount(m_object); +} + + bool TypeContainer::ParseTypeString( const std::string& source, bool importDependencies, -- cgit v1.3.1