From d7cb0b3acc0621aa69061d0d1199ac33c664e58f Mon Sep 17 00:00:00 2001 From: Peter LaFosse Date: Thu, 25 May 2017 19:51:45 -0400 Subject: Modify how structures are created in the type system, expose additional structure APIs --- binaryninjaapi.h | 6 +++--- binaryninjacore.h | 5 +++-- python/types.py | 12 ++++++++---- type.cpp | 14 ++++++++++---- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/binaryninjaapi.h b/binaryninjaapi.h index d27ab5fa..5ea6d909 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -1723,7 +1723,7 @@ namespace BinaryNinja public: Structure(); Structure(BNStructure* s); - Structure(BNStructureType type, bool isUnion = false, bool packed = false); + Structure(BNStructureType type, bool packed = false); std::vector GetMembers() const; uint64_t GetWidth() const; @@ -1733,8 +1733,8 @@ namespace BinaryNinja bool IsPacked() const; void SetPacked(bool packed); bool IsUnion() const; - void SetUnion(bool u); - + void SetStructureType(BNStructureType type); + BNStructureType GetStructureType() const; void AddMember(Type* type, const std::string& name); void AddMemberAtOffset(Type* type, const std::string& name, uint64_t offset); void RemoveMember(size_t idx); diff --git a/binaryninjacore.h b/binaryninjacore.h index 23014782..8880747c 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -2496,7 +2496,7 @@ extern "C" BINARYNINJACOREAPI BNNamedTypeReference* BNNewNamedTypeReference(BNNamedTypeReference* nt); BINARYNINJACOREAPI BNStructure* BNCreateStructure(void); - BINARYNINJACOREAPI BNStructure* BNCreateStructureWithOptions(BNStructureType type, bool isUnion, bool packed); + BINARYNINJACOREAPI BNStructure* BNCreateStructureWithOptions(BNStructureType type, bool packed); BINARYNINJACOREAPI BNStructure* BNNewStructureReference(BNStructure* s); BINARYNINJACOREAPI void BNFreeStructure(BNStructure* s); @@ -2509,7 +2509,8 @@ extern "C" BINARYNINJACOREAPI bool BNIsStructurePacked(BNStructure* s); BINARYNINJACOREAPI void BNSetStructurePacked(BNStructure* s, bool packed); BINARYNINJACOREAPI bool BNIsStructureUnion(BNStructure* s); - BINARYNINJACOREAPI void BNSetStructureUnion(BNStructure* s, bool u); + BINARYNINJACOREAPI void BNSetStructureType(BNStructure* s, BNStructureType type); + BINARYNINJACOREAPI BNStructureType BNGetStructureType(BNStructure* s); BINARYNINJACOREAPI void BNAddStructureMember(BNStructure* s, BNType* type, const char* name); BINARYNINJACOREAPI void BNAddStructureMemberAtOffset(BNStructure* s, BNType* type, const char* name, uint64_t offset); diff --git a/python/types.py b/python/types.py index 1e566f68..f8e416f4 100644 --- a/python/types.py +++ b/python/types.py @@ -22,7 +22,7 @@ import ctypes # Binary Ninja components import _binaryninjacore as core -from enums import SymbolType, TypeClass, NamedTypeReferenceClass, InstructionTextTokenType +from enums import SymbolType, TypeClass, NamedTypeReferenceClass, InstructionTextTokenType, StructureType import callingconvention import function @@ -646,9 +646,13 @@ class Structure(object): def union(self): return core.BNIsStructureUnion(self.handle) - @union.setter - def union(self, value): - core.BNSetStructureUnion(self.handle, value) + @property + def type(self): + return StructureType(core.BNGetStructureType(self.handle)) + + @type.setter + def type(self, value): + core.BNSetStructureType(self.handle, value) def __setattr__(self, name, value): try: diff --git a/type.cpp b/type.cpp index 5dd00cbd..6e55bb69 100644 --- a/type.cpp +++ b/type.cpp @@ -784,9 +784,9 @@ Structure::Structure() } -Structure::Structure(BNStructureType type, bool isUnion, bool packed) +Structure::Structure(BNStructureType type, bool packed) { - m_object = BNCreateStructureWithOptions(type, isUnion, packed); + m_object = BNCreateStructureWithOptions(type, packed); } @@ -858,9 +858,15 @@ bool Structure::IsUnion() const } -void Structure::SetUnion(bool u) +void Structure::SetStructureType(BNStructureType t) { - BNSetStructureUnion(m_object, u); + BNSetStructureType(m_object, t); +} + + +BNStructureType Structure::GetStructureType() const +{ + return BNGetStructureType(m_object); } -- cgit v1.3.1