diff options
| author | Peter LaFosse <peter@vector35.com> | 2022-01-18 09:16:25 -0500 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2022-01-19 10:52:42 -0500 |
| commit | 5d66fab3c2b36a14f9efd119a818c48c0950394a (patch) | |
| tree | 739d0b5cd2ad0f5e5c9bab02d543b48b969127c6 | |
| parent | 1e1e2c9da6d6d39c2dc41c2aa24ee35de4cd27ac (diff) | |
Make enumeration's signed property BoolWithConfidence
| -rw-r--r-- | binaryninjaapi.h | 8 | ||||
| -rw-r--r-- | binaryninjacore.h | 8 | ||||
| -rw-r--r-- | python/types.py | 4 | ||||
| -rw-r--r-- | rust/src/types.rs | 9 | ||||
| -rw-r--r-- | type.cpp | 28 |
5 files changed, 35 insertions, 22 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index e16158cc..a852290d 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -2834,8 +2834,8 @@ __attribute__ ((format (printf, 1, 2))) static Ref<Type> NamedType(const QualifiedName& name, Type* type); static Ref<Type> NamedType(const std::string& id, const QualifiedName& name, Type* type); static Ref<Type> NamedType(BinaryView* view, const QualifiedName& name); - static Ref<Type> EnumerationType(Architecture* arch, Enumeration* enm, size_t width = 0, bool isSigned = false); - static Ref<Type> EnumerationType(Enumeration* enm, size_t width, bool isSigned = false); + static Ref<Type> EnumerationType(Architecture* arch, Enumeration* enm, size_t width = 0, const Confidence<bool>& isSigned = Confidence<bool>(false, 0)); + static Ref<Type> EnumerationType(Enumeration* enm, size_t width, const Confidence<bool>& isSigned = Confidence<bool>(false, 0)); static Ref<Type> PointerType(Architecture* arch, const Confidence<Ref<Type>>& type, const Confidence<bool>& cnst = Confidence<bool>(false, 0), const Confidence<bool>& vltl = Confidence<bool>(false, 0), BNReferenceType refType = PointerReferenceType); @@ -2967,8 +2967,8 @@ __attribute__ ((format (printf, 1, 2))) static TypeBuilder NamedType(const QualifiedName& name, Type* type); static TypeBuilder NamedType(const std::string& id, const QualifiedName& name, Type* type); static TypeBuilder NamedType(BinaryView* view, const QualifiedName& name); - static TypeBuilder EnumerationType(Architecture* arch, Enumeration* enm, size_t width = 0, bool issigned = false); - static TypeBuilder EnumerationType(Architecture* arch, EnumerationBuilder* enm, size_t width = 0, bool issigned = false); + static TypeBuilder EnumerationType(Architecture* arch, Enumeration* enm, size_t width = 0, const Confidence<bool>& issigned = Confidence<bool>(false, 0)); + static TypeBuilder EnumerationType(Architecture* arch, EnumerationBuilder* enm, size_t width = 0, const Confidence<bool>& issigned = Confidence<bool>(false, 0)); static TypeBuilder PointerType(Architecture* arch, const Confidence<Ref<Type>>& type, const Confidence<bool>& cnst = Confidence<bool>(false, 0), const Confidence<bool>& vltl = Confidence<bool>(false, 0), BNReferenceType refType = PointerReferenceType); diff --git a/binaryninjacore.h b/binaryninjacore.h index f1505ad1..f1353c10 100644 --- a/binaryninjacore.h +++ b/binaryninjacore.h @@ -4757,8 +4757,8 @@ __attribute__ ((format (printf, 1, 2))) BINARYNINJACOREAPI BNType* BNCreateFloatType(size_t width, const char* altName); BINARYNINJACOREAPI BNType* BNCreateWideCharType(size_t width, const char* altName); BINARYNINJACOREAPI BNType* BNCreateStructureType(BNStructure* s); - BINARYNINJACOREAPI BNType* BNCreateEnumerationType(BNArchitecture* arch, BNEnumeration* e, size_t width, bool isSigned); - BINARYNINJACOREAPI BNType* BNCreateEnumerationTypeOfWidth(BNEnumeration* e, size_t width, bool isSigned); + BINARYNINJACOREAPI BNType* BNCreateEnumerationType(BNArchitecture* arch, BNEnumeration* e, size_t width, BNBoolWithConfidence* isSigned); + BINARYNINJACOREAPI BNType* BNCreateEnumerationTypeOfWidth(BNEnumeration* e, size_t width, BNBoolWithConfidence* isSigned); BINARYNINJACOREAPI BNType* BNCreatePointerType(BNArchitecture* arch, const BNTypeWithConfidence* const type, BNBoolWithConfidence* cnst, BNBoolWithConfidence* vltl, BNReferenceType refType); BINARYNINJACOREAPI BNType* BNCreatePointerTypeOfWidth(size_t width, const BNTypeWithConfidence* const type, @@ -4780,8 +4780,8 @@ __attribute__ ((format (printf, 1, 2))) BINARYNINJACOREAPI BNTypeBuilder* BNCreateWideCharTypeBuilder(size_t width, const char* altName); BINARYNINJACOREAPI BNTypeBuilder* BNCreateStructureTypeBuilder(BNStructure* s); BINARYNINJACOREAPI BNTypeBuilder* BNCreateStructureTypeBuilderWithBuilder(BNStructureBuilder* s); - BINARYNINJACOREAPI BNTypeBuilder* BNCreateEnumerationTypeBuilder(BNArchitecture* arch, BNEnumeration* e, size_t width, bool isSigned); - BINARYNINJACOREAPI BNTypeBuilder* BNCreateEnumerationTypeBuilderWithBuilder(BNArchitecture* arch, BNEnumerationBuilder* e, size_t width, bool isSigned); + BINARYNINJACOREAPI BNTypeBuilder* BNCreateEnumerationTypeBuilder(BNArchitecture* arch, BNEnumeration* e, size_t width, BNBoolWithConfidence* isSigned); + BINARYNINJACOREAPI BNTypeBuilder* BNCreateEnumerationTypeBuilderWithBuilder(BNArchitecture* arch, BNEnumerationBuilder* e, size_t width, BNBoolWithConfidence* isSigned); BINARYNINJACOREAPI BNTypeBuilder* BNCreatePointerTypeBuilder(BNArchitecture* arch, const BNTypeWithConfidence* const type, BNBoolWithConfidence* cnst, BNBoolWithConfidence* vltl, BNReferenceType refType); BINARYNINJACOREAPI BNTypeBuilder* BNCreatePointerTypeBuilderOfWidth(size_t width, const BNTypeWithConfidence* const type, diff --git a/python/types.py b/python/types.py index 1faec34d..8ca8e260 100644 --- a/python/types.py +++ b/python/types.py @@ -2048,7 +2048,9 @@ class EnumerationType(IntegerType): assert type_builder_handle is not None, "core.BNCreateTypeBuilderFromType returned None" enumeration_handle = core.BNGetTypeEnumeration(self._handle) assert enumeration_handle is not None, "core.BNGetTypeStructure returned None" - enumeration_builder_handle = core.BNCreateEnumerationTypeBuilder(self.platform.arch.handle, enumeration_handle, self.width, self.signed.value) + + _sign = BoolWithConfidence.get_core_struct(self.signed) + enumeration_builder_handle = core.BNCreateEnumerationTypeBuilder(self.platform.arch.handle, enumeration_handle, self.width, _sign) assert enumeration_builder_handle is not None, "core.BNCreateEnumerationTypeBuilder returned None" return EnumerationBuilder(type_builder_handle, enumeration_builder_handle, self.platform, self.confidence) diff --git a/rust/src/types.rs b/rust/src/types.rs index ec36e5d9..17721361 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -376,7 +376,7 @@ impl TypeBuilder { unsafe { Self::from_raw(BNCreateArrayTypeBuilder(&t.into().into(), count)) } } - pub fn enumeration(enumeration: &Enumeration, width: usize, is_signed: bool) -> Self { + pub fn enumeration(enumeration: &Enumeration, width: usize, is_signed: Conf<bool>) -> Self { //! The C/C++ APIs require an associated architecture, but in the core we only query the default_int_size if the given width is 0 //! For simplicity's sake, that convention isn't followed and you can query the default_int_size from an arch, if you have it, if you need to @@ -387,7 +387,7 @@ impl TypeBuilder { &mut fake_arch, enumeration.handle, width, - is_signed, + &mut is_signed.into(), )) } } @@ -727,10 +727,9 @@ impl Type { unsafe { Self::ref_from_raw(BNCreateArrayType(&t.into().into(), count)) } } - pub fn enumeration(enumeration: &Enumeration, width: usize, is_signed: bool) -> Ref<Self> { + pub fn enumeration(enumeration: &Enumeration, width: usize, is_signed: Conf<bool>) -> Ref<Self> { //! The C/C++ APIs require an associated architecture, but in the core we only query the default_int_size if the given width is 0 //! For simplicity's sake, that convention isn't followed and you can query the default_int_size from an arch, if you have it, if you need to - unsafe { // TODO : This is _extremely fragile_, we should change the internals of BNCreateEnumerationType instead of doing this let mut fake_arch: BNArchitecture = mem::zeroed(); @@ -738,7 +737,7 @@ impl Type { &mut fake_arch, enumeration.handle, width, - is_signed, + &mut is_signed.into(), )) } } @@ -746,15 +746,21 @@ Ref<Type> Type::NamedType(BinaryView* view, const QualifiedName& name) } -Ref<Type> Type::EnumerationType(Architecture* arch, Enumeration* enm, size_t width, bool isSigned) +Ref<Type> Type::EnumerationType(Architecture* arch, Enumeration* enm, size_t width, const Confidence<bool>& isSigned) { - return new Type(BNCreateEnumerationType(arch->GetObject(), enm->GetObject(), width, isSigned)); + BNBoolWithConfidence isSignedConf; + isSignedConf.value = isSigned.GetValue(); + isSignedConf.confidence = isSigned.GetConfidence(); + return new Type(BNCreateEnumerationType(arch->GetObject(), enm->GetObject(), width, &isSignedConf)); } -Ref<Type> Type::EnumerationType(Enumeration* enm, size_t width, bool isSigned) +Ref<Type> Type::EnumerationType(Enumeration* enm, size_t width, const Confidence<bool>& isSigned) { - return new Type(BNCreateEnumerationTypeOfWidth(enm->GetObject(), width, isSigned)); + BNBoolWithConfidence isSignedConf; + isSignedConf.value = isSigned.GetValue(); + isSignedConf.confidence = isSigned.GetConfidence(); + return new Type(BNCreateEnumerationTypeOfWidth(enm->GetObject(), width, &isSignedConf)); } @@ -1428,15 +1434,21 @@ TypeBuilder TypeBuilder::NamedType(BinaryView* view, const QualifiedName& name) } -TypeBuilder TypeBuilder::EnumerationType(Architecture* arch, Enumeration* enm, size_t width, bool isSigned) +TypeBuilder TypeBuilder::EnumerationType(Architecture* arch, Enumeration* enm, size_t width, const Confidence<bool>& isSigned) { - return TypeBuilder(BNCreateEnumerationTypeBuilder(arch ? arch->GetObject() : nullptr, enm->GetObject(), width, isSigned)); + BNBoolWithConfidence isSignedConf; + isSignedConf.value = isSigned.GetValue(); + isSignedConf.confidence = isSigned.GetConfidence(); + return TypeBuilder(BNCreateEnumerationTypeBuilder(arch ? arch->GetObject() : nullptr, enm->GetObject(), width, &isSignedConf)); } -TypeBuilder TypeBuilder::EnumerationType(Architecture* arch, EnumerationBuilder* enm, size_t width, bool isSigned) +TypeBuilder TypeBuilder::EnumerationType(Architecture* arch, EnumerationBuilder* enm, size_t width, const Confidence<bool>& isSigned) { - return TypeBuilder(BNCreateEnumerationTypeBuilderWithBuilder(arch->GetObject(), enm->GetObject(), width, isSigned)); + BNBoolWithConfidence isSignedConf; + isSignedConf.value = isSigned.GetValue(); + isSignedConf.confidence = isSigned.GetConfidence(); + return TypeBuilder(BNCreateEnumerationTypeBuilderWithBuilder(arch->GetObject(), enm->GetObject(), width, &isSignedConf)); } TypeBuilder TypeBuilder::PointerType(Architecture* arch, const Confidence<Ref<Type>>& type, |
