summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Wagner <rusty.wagner@gmail.com>2025-07-11 17:55:04 -0400
committerRusty Wagner <rusty.wagner@gmail.com>2025-07-15 13:55:33 -0400
commit6894a946b1fa5ad24e64d24bb7f606bae14c300a (patch)
tree1caa51b5e5ddab129462dc245c70377aedd800ae
parente83374c78ccb8f7351fa3fdbaa0cbb099281898d (diff)
Add API to get all type references at the same time to avoid duplicating work
-rw-r--r--binaryninjaapi.h14
-rw-r--r--binaryninjacore.h12
-rw-r--r--binaryview.cpp35
3 files changed, 61 insertions, 0 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 85dedca7..8d3fed9c 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -4554,6 +4554,13 @@ namespace BinaryNinja {
BNRegisterValue ToAPIObject();
};
+ struct AllTypeReferences
+ {
+ std::vector<ReferenceSource> codeRefs;
+ std::vector<uint64_t> dataRefs;
+ std::vector<TypeReferenceSource> typeRefs;
+ };
+
struct AllTypeFieldReferences
{
std::vector<TypeFieldReference> codeRefs;
@@ -5654,6 +5661,13 @@ namespace BinaryNinja {
*/
std::vector<TypeReferenceSource> GetTypeReferencesForTypeField(const QualifiedName& type, uint64_t offset);
+ /*! Returns a all references to a specific type. This includes code, data, and type references.
+
+ \param type QualifiedName of the type
+ \return AllTypeReferences structure with all references
+ */
+ AllTypeReferences GetAllReferencesForType(const QualifiedName& type);
+
/*! Returns a all references to a specific type field. This includes code, data, and type references.
\param type QualifiedName of the type
diff --git a/binaryninjacore.h b/binaryninjacore.h
index b4c29816..fbdcf4f5 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -3732,6 +3732,16 @@ extern "C"
bool higherToLowerDirect;
} BNExprMapInfo;
+ typedef struct BNAllTypeReferences
+ {
+ BNReferenceSource* codeRefs;
+ size_t codeRefCount;
+ uint64_t* dataRefs;
+ size_t dataRefCount;
+ BNTypeReferenceSource* typeRefs;
+ size_t typeRefCount;
+ } BNAllTypeReferences;
+
typedef struct BNAllTypeFieldReferences
{
BNTypeFieldReference* codeRefs;
@@ -5055,6 +5065,8 @@ extern "C"
BINARYNINJACOREAPI BNTypeReferenceSource* BNGetTypeReferencesForTypeField(
BNBinaryView* view, BNQualifiedName* type, uint64_t offset, size_t* count);
+ BINARYNINJACOREAPI BNAllTypeReferences BNGetAllReferencesForType(BNBinaryView* view, BNQualifiedName* type);
+ BINARYNINJACOREAPI void BNFreeAllTypeReferences(BNAllTypeReferences* refs);
BINARYNINJACOREAPI BNAllTypeFieldReferences BNGetAllReferencesForTypeField(
BNBinaryView* view, BNQualifiedName* type, uint64_t offset);
BINARYNINJACOREAPI void BNFreeAllTypeFieldReferences(BNAllTypeFieldReferences* refs);
diff --git a/binaryview.cpp b/binaryview.cpp
index f2e72930..665228c1 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -2685,6 +2685,41 @@ vector<TypeReferenceSource> 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<uint64_t>(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();