diff options
| author | Peter LaFosse <peter@vector35.com> | 2019-04-05 21:55:47 -0400 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2019-04-07 18:19:49 -0400 |
| commit | e34e52c2f797c9b97b592abb311e3a5bc2194b4a (patch) | |
| tree | 713307be0740705debbd5a3ca62abc6234b510d8 | |
| parent | 5de327770ec8c3f1aca9c774d850442edb9a3610 (diff) | |
Add API for geting a list of type names without the associated objects
| -rw-r--r-- | binaryninjaapi.h | 1 | ||||
| -rw-r--r-- | binaryninjacore.h | 2 | ||||
| -rw-r--r-- | binaryview.cpp | 17 | ||||
| -rw-r--r-- | python/binaryview.py | 11 |
4 files changed, 31 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 65cba272..9fe63e43 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1432,6 +1432,7 @@ namespace BinaryNinja bool ParseTypeString(const std::string& text, std::map<QualifiedName, Ref<Type>>& result, std::string& errors); std::map<QualifiedName, Ref<Type>> GetTypes(); + std::vector<QualifiedName> GetTypeNames(const std::string& matching=""); Ref<Type> GetTypeByName(const QualifiedName& name); Ref<Type> GetTypeById(const std::string& id); std::string GetTypeId(const QualifiedName& name); diff --git a/binaryninjacore.h b/binaryninjacore.h index eadc4b2e..8422cdfc 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -2815,6 +2815,8 @@ extern "C" BINARYNINJACOREAPI BNQualifiedNameAndType* BNGetAnalysisTypeList(BNBinaryView* view, size_t* count); BINARYNINJACOREAPI void BNFreeTypeList(BNQualifiedNameAndType* types, size_t count); + 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* BNGetAnalysisTypeById(BNBinaryView* view, const char* id); BINARYNINJACOREAPI char* BNGetAnalysisTypeId(BNBinaryView* view, BNQualifiedName* name); diff --git a/binaryview.cpp b/binaryview.cpp index 3bf61f34..1c345dfb 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -1928,6 +1928,23 @@ map<QualifiedName, Ref<Type>> BinaryView::GetTypes() } +vector<QualifiedName> BinaryView::GetTypeNames(const string& matching) +{ + size_t count; + BNQualifiedName* names = BNGetAnalysisTypeNames(m_object, &count, matching.c_str()); + + vector<QualifiedName> result; + result.reserve(count); + for (size_t i = 0; i < count; i++) + { + result.push_back(QualifiedName::FromAPIObject(&names[i])); + } + + BNFreeTypeNameList(names, count); + return result; +} + + Ref<Type> BinaryView::GetTypeByName(const QualifiedName& name) { BNQualifiedName nameObj = name.GetAPIObject(); diff --git a/python/binaryview.py b/python/binaryview.py index 373823c8..c92a9120 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -1197,6 +1197,17 @@ class BinaryView(object): return result @property + def type_names(self): + """List of defined type names (read-only)""" + count = ctypes.c_ulonglong(0) + name_list = core.BNGetAnalysisTypeNames(self.handle, count, "") + result = [] + for i in range(0, count.value): + result.append(types.QualifiedName._from_core_struct(name_list[i])) + core.BNFreeTypeNameList(name_list, count.value) + return result + + @property def segments(self): """List of segments (read-only)""" count = ctypes.c_ulonglong(0) |
