summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2022-03-18 12:35:46 -0400
committerPeter LaFosse <peter@vector35.com>2022-03-23 14:52:09 -0400
commit5646f03f9a61feb24584a8a5da94027783b16e5a (patch)
tree662104a1ddcc47cfd9c6717e90a5f56c137a1f2e
parent33bddd0c8ad5c45a07c56caa964dd42631cd169c (diff)
Fix a bunch of reference miscounts in the C++ and python apis
-rw-r--r--binaryview.cpp10
-rw-r--r--demangle.cpp4
-rw-r--r--function.cpp6
-rw-r--r--highlevelil.cpp2
-rw-r--r--mediumlevelil.cpp2
-rw-r--r--platform.cpp8
-rw-r--r--python/binaryview.py8
-rw-r--r--python/typelibrary.py4
-rw-r--r--python/types.py8
-rw-r--r--type.cpp14
10 files changed, 35 insertions, 31 deletions
diff --git a/binaryview.cpp b/binaryview.cpp
index 541c6ca9..13e9f439 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -1641,7 +1641,7 @@ bool BinaryView::GetDataVariableAtAddress(uint64_t addr, DataVariable& var)
return false;
var.address = result.address;
- var.type = Confidence<Ref<Type>>(new Type(result.type), result.typeConfidence);
+ var.type = Confidence<Ref<Type>>(new Type(BNNewTypeReference(result.type)), result.typeConfidence);
var.autoDiscovered = result.autoDiscovered;
return true;
}
@@ -2167,7 +2167,7 @@ std::map<uint64_t, std::vector<Confidence<Ref<Type>>>> BinaryView::GetAllTypesRe
for (size_t j = 0; j < fields[i].count; j++)
{
BNTypeWithConfidence tc = fields[i].types[j];
- Ref<Type> type = tc.type ? new Type(tc.type) : nullptr;
+ Ref<Type> type = tc.type ? new Type(BNNewTypeReference(tc.type)) : nullptr;
types.push_back(Confidence<Ref<Type>>(type, tc.confidence));
}
}
@@ -2204,7 +2204,7 @@ std::vector<Confidence<Ref<Type>>> BinaryView::GetTypesReferenced(const Qualifie
for (size_t i = 0; i < count; i++)
{
BNTypeWithConfidence tc = types[i];
- Ref<Type> type = tc.type ? new Type(tc.type) : nullptr;
+ Ref<Type> type = tc.type ? new Type(BNNewTypeReference(tc.type)) : nullptr;
result.push_back(Confidence<Ref<Type>>(type, tc.confidence));
}
@@ -3119,7 +3119,7 @@ Ref<Type> BinaryView::GetTypeById(const string& id)
BNType* type = BNGetAnalysisTypeById(m_object, id.c_str());
if (!type)
return nullptr;
- return new Type(type);
+ return new Type(BNNewTypeReference(type));
}
@@ -3764,7 +3764,7 @@ Confidence<Ref<Type>> BinaryView::CreateStructureMemberFromAccess(const Qualifie
BNTypeWithConfidence type = BNCreateStructureMemberFromAccess(m_object, &typeObj, offset);
if (type.type)
- return Confidence<Ref<Type>>(new Type(type.type), type.confidence);
+ return Confidence<Ref<Type>>(new Type(BNNewTypeReference(type.type)), type.confidence);
return nullptr;
}
diff --git a/demangle.cpp b/demangle.cpp
index f79b2a7b..66395fc1 100644
--- a/demangle.cpp
+++ b/demangle.cpp
@@ -20,7 +20,7 @@ namespace BinaryNinja {
return false;
if (!localType)
return false;
- *outType = new Type(localType);
+ *outType = new Type(BNNewTypeReference(localType));
for (size_t i = 0; i < localSize; i++)
{
outVarName.push_back(localVarName[i]);
@@ -47,7 +47,7 @@ namespace BinaryNinja {
return false;
if (!localType)
return false;
- *outType = new Type(localType);
+ *outType = new Type(BNNewTypeReference(localType));
for (size_t i = 0; i < localSize; i++)
{
outVarName.push_back(localVarName[i]);
diff --git a/function.cpp b/function.cpp
index 712c8155..eb9907af 100644
--- a/function.cpp
+++ b/function.cpp
@@ -767,7 +767,7 @@ Ref<Type> Function::GetType() const
Confidence<Ref<Type>> Function::GetReturnType() const
{
BNTypeWithConfidence tc = BNGetFunctionReturnType(m_object);
- Ref<Type> type = tc.type ? new Type(tc.type) : nullptr;
+ Ref<Type> type = tc.type ? new Type(BNNewTypeReference(tc.type)) : nullptr;
return Confidence<Ref<Type>>(type, tc.confidence);
}
@@ -1456,7 +1456,7 @@ Confidence<Ref<Type>> Function::GetVariableType(const Variable& var)
BNTypeWithConfidence type = BNGetVariableType(m_object, &var);
if (!type.type)
return nullptr;
- return Confidence<Ref<Type>>(new Type(type.type), type.confidence);
+ return Confidence<Ref<Type>>(new Type(BNNewTypeReference(type.type)), type.confidence);
}
@@ -1643,7 +1643,7 @@ void Function::SetUserCallRegisterStackAdjustment(
Confidence<Ref<Type>> Function::GetCallTypeAdjustment(Architecture* arch, uint64_t addr)
{
BNTypeWithConfidence result = BNGetCallTypeAdjustment(m_object, arch->GetObject(), addr);
- return Confidence<Ref<Type>>(result.type ? new Type(result.type) : nullptr, result.confidence);
+ return Confidence<Ref<Type>>(result.type ? new Type(BNNewTypeReference(result.type)) : nullptr, result.confidence);
}
diff --git a/highlevelil.cpp b/highlevelil.cpp
index aab49ea0..d0b3b4e2 100644
--- a/highlevelil.cpp
+++ b/highlevelil.cpp
@@ -491,7 +491,7 @@ Confidence<Ref<Type>> HighLevelILFunction::GetExprType(size_t expr)
BNTypeWithConfidence result = BNGetHighLevelILExprType(m_object, expr);
if (!result.type)
return nullptr;
- return Confidence<Ref<Type>>(new Type(result.type), result.confidence);
+ return Confidence<Ref<Type>>(new Type(BNNewTypeReference(result.type)), result.confidence);
}
diff --git a/mediumlevelil.cpp b/mediumlevelil.cpp
index f2eb5fa9..71604caf 100644
--- a/mediumlevelil.cpp
+++ b/mediumlevelil.cpp
@@ -832,7 +832,7 @@ Confidence<Ref<Type>> MediumLevelILFunction::GetExprType(size_t expr)
BNTypeWithConfidence result = BNGetMediumLevelILExprType(m_object, expr);
if (!result.type)
return nullptr;
- return Confidence<Ref<Type>>(new Type(result.type), result.confidence);
+ return Confidence<Ref<Type>>(new Type(BNNewTypeReference(result.type)), result.confidence);
}
diff --git a/platform.cpp b/platform.cpp
index 68e812dc..b3ec68e8 100644
--- a/platform.cpp
+++ b/platform.cpp
@@ -349,7 +349,7 @@ Ref<Type> Platform::GetTypeByName(const QualifiedName& name)
QualifiedName::FreeAPIObject(&nameObj);
if (!type)
return nullptr;
- return new Type(type);
+ return new Type(BNNewTypeReference(type));
}
@@ -360,7 +360,7 @@ Ref<Type> Platform::GetVariableByName(const QualifiedName& name)
QualifiedName::FreeAPIObject(&nameObj);
if (!type)
return nullptr;
- return new Type(type);
+ return new Type(BNNewTypeReference(type));
}
@@ -371,7 +371,7 @@ Ref<Type> Platform::GetFunctionByName(const QualifiedName& name, bool exactMatch
QualifiedName::FreeAPIObject(&nameObj);
if (!type)
return nullptr;
- return new Type(type);
+ return new Type(BNNewTypeReference(type));
}
@@ -389,7 +389,7 @@ Ref<Type> Platform::GetSystemCallType(uint32_t n)
BNType* type = BNGetPlatformSystemCallType(m_object, n);
if (!type)
return nullptr;
- return new Type(type);
+ return new Type(BNNewTypeReference(type));
}
diff --git a/python/binaryview.py b/python/binaryview.py
index 3ebe79af..84a415e2 100644
--- a/python/binaryview.py
+++ b/python/binaryview.py
@@ -6293,7 +6293,7 @@ class BinaryView:
obj = core.BNGetAnalysisTypeByName(self.handle, _name)
if not obj:
return None
- return _types.Type.create(obj, platform=self.platform)
+ return _types.Type.create(core.BNNewTypeReference(obj), platform=self.platform)
def get_type_by_id(self, id: str) -> Optional['_types.Type']:
"""
@@ -6314,7 +6314,7 @@ class BinaryView:
obj = core.BNGetAnalysisTypeById(self.handle, id)
if not obj:
return None
- return _types.Type.create(obj, platform=self.platform)
+ return _types.Type.create(core.BNNewTypeReference(obj), platform=self.platform)
def get_type_name_by_id(self, id: str) -> Optional['_types.QualifiedName']:
"""
@@ -6550,7 +6550,7 @@ class BinaryView:
)
if handle is None:
return None
- return _types.Type.create(handle, platform=self.platform)
+ return _types.Type.create(core.BNNewTypeReference(handle), platform=self.platform)
def import_library_object(self, name: str, lib: typelibrary.TypeLibrary = None) -> Optional['_types.Type']:
"""
@@ -6572,7 +6572,7 @@ class BinaryView:
)
if handle is None:
return None
- return _types.Type.create(handle, platform=self.platform)
+ return _types.Type.create(core.BNNewTypeReference(handle), platform=self.platform)
def export_type_to_library(self, lib: typelibrary.TypeLibrary, name: Optional[str], type_obj: StringOrType) -> None:
"""
diff --git a/python/typelibrary.py b/python/typelibrary.py
index 8a56e978..2d2c8fb1 100644
--- a/python/typelibrary.py
+++ b/python/typelibrary.py
@@ -321,7 +321,7 @@ class TypeLibrary:
t = core.BNGetTypeLibraryNamedObject(self.handle, name._to_core_struct())
if t is None:
return None
- return types.Type.create(t)
+ return types.Type.create(core.BNNewTypeReference(t))
def get_named_type(self, name: str) -> Optional[types.Type]:
"""
@@ -337,7 +337,7 @@ class TypeLibrary:
t = core.BNGetTypeLibraryNamedType(self.handle, name._to_core_struct())
if t is None:
return None
- return types.Type.create(t)
+ return types.Type.create(core.BNNewTypeReference(t))
@property
def named_objects(self) -> Dict[str, types.Type]:
diff --git a/python/types.py b/python/types.py
index 2201e6a6..69ab0a8d 100644
--- a/python/types.py
+++ b/python/types.py
@@ -1799,10 +1799,14 @@ class Type:
return MutableTypeBuilder(type.mutable_copy(), bv, name, platform, confidence)
def with_replaced_structure(self, from_struct, to_struct):
- return Type.create(handle=core.BNTypeWithReplacedStructure(self._handle, from_struct.handle, to_struct.handle))
+ handle = core.BNTypeWithReplacedStructure(self._handle, from_struct.handle, to_struct.handle)
+ ref_handle = core.BNNewTypeReference(handle)
+ return Type.create(handle=ref_handle)
def with_replaced_enumeration(self, from_enum, to_enum):
- return Type.create(handle=core.BNTypeWithReplacedEnumeration(self._handle, from_enum.handle, to_enum.handle))
+ handle = core.BNTypeWithReplacedEnumeration(self._handle, from_enum.handle, to_enum.handle)
+ ref_handle = core.BNNewTypeReference(handle)
+ return Type.create(handle=ref_handle)
def with_replaced_named_type_reference(self, from_ref, to_ref):
return Type.create(
diff --git a/type.cpp b/type.cpp
index d46a9d32..56526611 100644
--- a/type.cpp
+++ b/type.cpp
@@ -504,7 +504,7 @@ Confidence<Ref<Type>> Type::GetChildType() const
{
BNTypeWithConfidence type = BNGetChildType(m_object);
if (type.type)
- return Confidence<Ref<Type>>(new Type(type.type), type.confidence);
+ return Confidence<Ref<Type>>(new Type(BNNewTypeReference(type.type)), type.confidence);
return nullptr;
}
@@ -737,7 +737,7 @@ Ref<Type> Type::NamedType(const string& id, const QualifiedName& name, Type* typ
BNQualifiedName nameObj = name.GetAPIObject();
BNType* coreObj = BNCreateNamedTypeReferenceFromTypeAndId(id.c_str(), &nameObj, type ? type->GetObject() : nullptr);
QualifiedName::FreeAPIObject(&nameObj);
- return coreObj ? new Type(coreObj) : nullptr;
+ return coreObj ? new Type(BNNewTypeReference(coreObj)) : nullptr;
}
@@ -746,7 +746,7 @@ Ref<Type> Type::NamedType(BinaryView* view, const QualifiedName& name)
BNQualifiedName nameObj = name.GetAPIObject();
BNType* coreObj = BNCreateNamedTypeReferenceFromType(view->GetObject(), &nameObj);
QualifiedName::FreeAPIObject(&nameObj);
- return coreObj ? new Type(coreObj) : nullptr;
+ return coreObj ? new Type(BNNewTypeReference(coreObj)) : nullptr;
}
@@ -965,7 +965,7 @@ Ref<Type> Type::WithReplacedStructure(Structure* from, Structure* to)
BNFreeType(result);
return this;
}
- return new Type(result);
+ return new Type(BNNewTypeReference(result));
}
@@ -977,7 +977,7 @@ Ref<Type> Type::WithReplacedEnumeration(Enumeration* from, Enumeration* to)
BNFreeType(result);
return this;
}
- return new Type(result);
+ return new Type(BNNewTypeReference(result));
}
@@ -989,7 +989,7 @@ Ref<Type> Type::WithReplacedNamedTypeReference(NamedTypeReference* from, NamedTy
BNFreeType(result);
return this;
}
- return new Type(result);
+ return new Type(BNNewTypeReference(result));
}
@@ -1208,7 +1208,7 @@ Confidence<Ref<Type>> TypeBuilder::GetChildType() const
{
BNTypeWithConfidence type = BNGetTypeBuilderChildType(m_object);
if (type.type)
- return Confidence<Ref<Type>>(new Type(type.type), type.confidence);
+ return Confidence<Ref<Type>>(new Type(BNNewTypeReference(type.type)), type.confidence);
return nullptr;
}