From 6894a946b1fa5ad24e64d24bb7f606bae14c300a Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Fri, 11 Jul 2025 17:55:04 -0400 Subject: Add API to get all type references at the same time to avoid duplicating work --- binaryview.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'binaryview.cpp') diff --git a/binaryview.cpp b/binaryview.cpp index f2e72930..665228c1 100644 --- a/binaryview.cpp +++ b/binaryview.cpp @@ -2685,6 +2685,41 @@ vector BinaryView::GetTypeReferencesForTypeField(const Qual } +AllTypeReferences BinaryView::GetAllReferencesForType(const QualifiedName& type) +{ + BNQualifiedName nameObj = type.GetAPIObject(); + BNAllTypeReferences refs = BNGetAllReferencesForType(m_object, &nameObj); + QualifiedName::FreeAPIObject(&nameObj); + + AllTypeReferences result; + + result.codeRefs.reserve(refs.codeRefCount); + for (size_t i = 0; i < refs.codeRefCount; i++) + { + ReferenceSource src; + src.func = new Function(BNNewFunctionReference(refs.codeRefs[i].func)); + src.arch = new CoreArchitecture(refs.codeRefs[i].arch); + src.addr = refs.codeRefs[i].addr; + result.codeRefs.push_back(src); + } + + result.dataRefs = vector(refs.dataRefs, &refs.dataRefs[refs.dataRefCount]); + + result.typeRefs.reserve(refs.typeRefCount); + for (size_t i = 0; i < refs.typeRefCount; i++) + { + TypeReferenceSource src; + src.name = QualifiedName::FromAPIObject(&refs.typeRefs[i].name); + src.offset = refs.typeRefs[i].offset; + src.type = refs.typeRefs[i].type; + result.typeRefs.push_back(src); + } + + BNFreeAllTypeReferences(&refs); + return result; +} + + AllTypeFieldReferences BinaryView::GetAllReferencesForTypeField(const QualifiedName& type, uint64_t offset) { BNQualifiedName nameObj = type.GetAPIObject(); -- cgit v1.3.1