Skip to content

Commit cd9eea2

Browse files
committed
Add GetTypeCount API
Add note about type_names not being sorted anymore
1 parent 4780a84 commit cd9eea2

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

binaryninjaapi.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20115,7 +20115,7 @@ namespace BinaryNinja {
2011520115
*/
2011620116
std::optional<std::unordered_set<std::string>> GetTypeIds() const;
2011720117

20118-
/*! Get all type names in a Type Container.
20118+
/*! Get all type names in a Type Container. Sort order is not guaranteed in 5.2 and later.
2011920119

2012020120
\return List of all type names
2012120121
*/
@@ -20127,6 +20127,12 @@ namespace BinaryNinja {
2012720127
*/
2012820128
std::optional<std::unordered_map<std::string, QualifiedName>> GetTypeNamesAndIds() const;
2012920129

20130+
/*! Get the number of types in a Type Container.
20131+
20132+
\return Number of types in the container
20133+
*/
20134+
size_t GetTypeCount() const;
20135+
2013020136
/*! Parse a single type and name from a string containing their definition,
2013120137
with knowledge of the types in the Type Container.
2013220138

binaryninjacore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5642,6 +5642,7 @@ extern "C"
56425642
BINARYNINJACOREAPI bool BNTypeContainerGetTypeIds(BNTypeContainer* container, char*** typeIds, size_t* count);
56435643
BINARYNINJACOREAPI bool BNTypeContainerGetTypeNames(BNTypeContainer* container, BNQualifiedName** typeNames, size_t* count);
56445644
BINARYNINJACOREAPI bool BNTypeContainerGetTypeNamesAndIds(BNTypeContainer* container, char*** typeIds, BNQualifiedName** typeNames, size_t* count);
5645+
BINARYNINJACOREAPI size_t BNTypeContainerGetTypeCount(BNTypeContainer* container);
56455646
BINARYNINJACOREAPI bool BNTypeContainerParseTypeString(BNTypeContainer* container,
56465647
const char* source, bool importDepencencies, BNQualifiedNameAndType* result,
56475648
BNTypeParserError** errors, size_t* errorCount

python/binaryview.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3471,7 +3471,10 @@ def dependency_sorted_types(self) -> TypeMapping:
34713471

34723472
@property
34733473
def type_names(self) -> List['_types.QualifiedName']:
3474-
"""List of defined type names (read-only)"""
3474+
"""List of defined type names (read-only)
3475+
3476+
.. note:: Sort order is not guaranteed in 5.2 and later.
3477+
"""
34753478
count = ctypes.c_ulonglong(0)
34763479
name_list = core.BNGetAnalysisTypeNames(self.handle, count, "")
34773480
assert name_list is not None, "core.BNGetAnalysisTypeNames returned None"

python/typecontainer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,14 @@ def type_names_and_ids(self) -> Optional[Mapping[str, '_types.QualifiedName']]:
329329
core.BNFreeStringList(result_ids, result_count.value)
330330
return result
331331

332+
@property
333+
def type_count(self) -> int:
334+
"""
335+
Get the number of types in a Type Container.
336+
:return: Number of types in the container
337+
"""
338+
return core.BNTypeContainerGetTypeCount(self.handle)
339+
332340
def parse_type_string(
333341
self, source: str, import_dependencies: bool = True
334342
) -> Tuple[Optional[Tuple['_types.QualifiedNameType', '_types.Type']], List['typeparser.TypeParserError']]:

typecontainer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,12 @@ std::optional<std::unordered_map<std::string, QualifiedName>> TypeContainer::Get
336336
}
337337

338338

339+
size_t TypeContainer::GetTypeCount() const
340+
{
341+
return BNTypeContainerGetTypeCount(m_object);
342+
}
343+
344+
339345
bool TypeContainer::ParseTypeString(
340346
const std::string& source,
341347
bool importDependencies,

0 commit comments

Comments
 (0)