From 5646f03f9a61feb24584a8a5da94027783b16e5a Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Fri, 18 Mar 2022 12:35:46 -0400 Subject: Fix a bunch of reference miscounts in the C++ and python apis --- binaryview.cpp | 10 +++++----- demangle.cpp | 4 ++-- function.cpp | 6 +++--- highlevelil.cpp | 2 +- mediumlevelil.cpp | 2 +- platform.cpp | 8 ++++---- python/binaryview.py | 8 ++++---- python/typelibrary.py | 4 ++-- python/types.py | 8 ++++++-- type.cpp | 14 +++++++------- 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>(new Type(result.type), result.typeConfidence); + var.type = Confidence>(new Type(BNNewTypeReference(result.type)), result.typeConfidence); var.autoDiscovered = result.autoDiscovered; return true; } @@ -2167,7 +2167,7 @@ std::map>>> BinaryView::GetAllTypesRe for (size_t j = 0; j < fields[i].count; j++) { BNTypeWithConfidence tc = fields[i].types[j]; - Ref type = tc.type ? new Type(tc.type) : nullptr; + Ref type = tc.type ? new Type(BNNewTypeReference(tc.type)) : nullptr; types.push_back(Confidence>(type, tc.confidence)); } } @@ -2204,7 +2204,7 @@ std::vector>> BinaryView::GetTypesReferenced(const Qualifie for (size_t i = 0; i < count; i++) { BNTypeWithConfidence tc = types[i]; - Ref type = tc.type ? new Type(tc.type) : nullptr; + Ref type = tc.type ? new Type(BNNewTypeReference(tc.type)) : nullptr; result.push_back(Confidence>(type, tc.confidence)); } @@ -3119,7 +3119,7 @@ Ref 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> BinaryView::CreateStructureMemberFromAccess(const Qualifie BNTypeWithConfidence type = BNCreateStructureMemberFromAccess(m_object, &typeObj, offset); if (type.type) - return Confidence>(new Type(type.type), type.confidence); + return Confidence>(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 Function::GetType() const Confidence> Function::GetReturnType() const { BNTypeWithConfidence tc = BNGetFunctionReturnType(m_object); - Ref type = tc.type ? new Type(tc.type) : nullptr; + Ref type = tc.type ? new Type(BNNewTypeReference(tc.type)) : nullptr; return Confidence>(type, tc.confidence); } @@ -1456,7 +1456,7 @@ Confidence> Function::GetVariableType(const Variable& var) BNTypeWithConfidence type = BNGetVariableType(m_object, &var); if (!type.type) return nullptr; - return Confidence>(new Type(type.type), type.confidence); + return Confidence>(new Type(BNNewTypeReference(type.type)), type.confidence); } @@ -1643,7 +1643,7 @@ void Function::SetUserCallRegisterStackAdjustment( Confidence> Function::GetCallTypeAdjustment(Architecture* arch, uint64_t addr) { BNTypeWithConfidence result = BNGetCallTypeAdjustment(m_object, arch->GetObject(), addr); - return Confidence>(result.type ? new Type(result.type) : nullptr, result.confidence); + return Confidence>(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> HighLevelILFunction::GetExprType(size_t expr) BNTypeWithConfidence result = BNGetHighLevelILExprType(m_object, expr); if (!result.type) return nullptr; - return Confidence>(new Type(result.type), result.confidence); + return Confidence>(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> MediumLevelILFunction::GetExprType(size_t expr) BNTypeWithConfidence result = BNGetMediumLevelILExprType(m_object, expr); if (!result.type) return nullptr; - return Confidence>(new Type(result.type), result.confidence); + return Confidence>(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 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 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 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 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> Type::GetChildType() const { BNTypeWithConfidence type = BNGetChildType(m_object); if (type.type) - return Confidence>(new Type(type.type), type.confidence); + return Confidence>(new Type(BNNewTypeReference(type.type)), type.confidence); return nullptr; } @@ -737,7 +737,7 @@ Ref 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::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::WithReplacedStructure(Structure* from, Structure* to) BNFreeType(result); return this; } - return new Type(result); + return new Type(BNNewTypeReference(result)); } @@ -977,7 +977,7 @@ Ref 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::WithReplacedNamedTypeReference(NamedTypeReference* from, NamedTy BNFreeType(result); return this; } - return new Type(result); + return new Type(BNNewTypeReference(result)); } @@ -1208,7 +1208,7 @@ Confidence> TypeBuilder::GetChildType() const { BNTypeWithConfidence type = BNGetTypeBuilderChildType(m_object); if (type.type) - return Confidence>(new Type(type.type), type.confidence); + return Confidence>(new Type(BNNewTypeReference(type.type)), type.confidence); return nullptr; } -- cgit v1.3.1