summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Wagner <rusty.wagner@gmail.com>2025-10-22 20:15:04 -0400
committerRusty Wagner <rusty.wagner@gmail.com>2025-10-22 20:15:04 -0400
commit321fd674a74f84b12151987e15f835202b7ee08a (patch)
tree7662e27eab961b2a95f51e8f2be7598f944aae2f
parent186c7aafc9a275e0b5d23e176d46ece6bcfe5ec3 (diff)
Add API to dereference named type references
-rw-r--r--binaryninjaapi.h2
-rw-r--r--binaryninjacore.h3
-rw-r--r--python/types.py13
-rw-r--r--type.cpp6
4 files changed, 23 insertions, 1 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index d7958113..395ba154 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -10680,6 +10680,8 @@ namespace BinaryNinja {
int paddingCols = 64, bool collapsed = false, BNTokenEscapingType escaping = NoTokenEscapingType) const;
static std::string GetSizeSuffix(size_t size);
+
+ Ref<Type> DerefNamedTypeReference(BinaryView* view) const;
};
class EnumerationBuilder;
diff --git a/binaryninjacore.h b/binaryninjacore.h
index d5b38e11..dd03910b 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -37,7 +37,7 @@
// Current ABI version for linking to the core. This is incremented any time
// there are changes to the API that affect linking, including new functions,
// new types, or modifications to existing functions or types.
-#define BN_CURRENT_CORE_ABI_VERSION 139
+#define BN_CURRENT_CORE_ABI_VERSION 140
// Minimum ABI version that is supported for loading of plugins. Plugins that
// are linked to an ABI version less than this will not be able to load and
@@ -6870,6 +6870,7 @@ extern "C"
BINARYNINJACOREAPI BNTypeAttribute* BNGetTypeAttributes(BNType* type, size_t* count);
BINARYNINJACOREAPI char* BNGetTypeAttributeByName(BNType* type, const char* name);
BINARYNINJACOREAPI void BNFreeTypeAttributeList(BNTypeAttribute* attr, size_t count);
+ BINARYNINJACOREAPI BNType* BNDerefNamedTypeReference(BNBinaryView* view, BNType* type);
BINARYNINJACOREAPI char* BNGetTypeString(BNType* type, BNPlatform* platform, BNTokenEscapingType escaping);
BINARYNINJACOREAPI char* BNGetTypeStringBeforeName(BNType* type, BNPlatform* platform, BNTokenEscapingType escaping);
diff --git a/python/types.py b/python/types.py
index 853d0836..5ad589e0 100644
--- a/python/types.py
+++ b/python/types.py
@@ -2275,6 +2275,19 @@ class Type:
handle=core.BNTypeWithReplacedNamedTypeReference(self._handle, from_ref.ntr_handle, to_ref.ntr_handle)
return Type.create(handle)
+ def deref_named_type_reference(self, view: 'binaryview.BinaryView') -> 'Type':
+ """
+ Dereferences any named type references to find the underlying type. This may still return a
+ named type reference if there are circular references. If the type isn't a named type
+ reference, the input type is returned unchanged.
+
+ :param BinaryView view: BinaryView object owning this Type
+ :return: Type with named type references resolved
+ :rtype: :py:class:`Type`
+ """
+ handle = core.BNDerefNamedTypeReference(view.handle, self._handle)
+ return Type.create(handle)
+
@staticmethod
def void() -> 'VoidType':
return VoidType.create()
diff --git a/type.cpp b/type.cpp
index 8739055e..0625f8e0 100644
--- a/type.cpp
+++ b/type.cpp
@@ -1416,6 +1416,12 @@ string Type::GetSizeSuffix(size_t size)
}
+Ref<Type> Type::DerefNamedTypeReference(BinaryView* view) const
+{
+ return new Type(BNDerefNamedTypeReference(view->GetObject(), m_object));
+}
+
+
TypeBuilder::TypeBuilder()
{
m_object = BNCreateVoidTypeBuilder();