From 3d403cfae9d5a366f112c8a5936a371a01cfd230 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Mon, 10 Jul 2017 21:40:51 -0400 Subject: Add confidence levels to type objects --- type.cpp | 175 +++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 127 insertions(+), 48 deletions(-) (limited to 'type.cpp') diff --git a/type.cpp b/type.cpp index 6e55bb69..837b212d 100644 --- a/type.cpp +++ b/type.cpp @@ -261,15 +261,17 @@ size_t Type::GetAlignment() const } -bool Type::IsSigned() const +Confidence Type::IsSigned() const { - return BNIsTypeSigned(m_object); + BNBoolWithConfidence result = BNIsTypeSigned(m_object); + return Confidence(result.value, result.confidence); } -bool Type::IsConst() const +Confidence Type::IsConst() const { - return BNIsTypeConst(m_object); + BNBoolWithConfidence result = BNIsTypeConst(m_object); + return Confidence(result.value, result.confidence); } @@ -279,56 +281,70 @@ bool Type::IsFloat() const } -BNMemberScope Type::GetScope() const +Confidence Type::GetScope() const { - return BNTypeGetMemberScope(m_object); + BNMemberScopeWithConfidence result = BNTypeGetMemberScope(m_object); + return Confidence(result.value, result.confidence); } -void Type::SetScope(BNMemberScope scope) +void Type::SetScope(const Confidence& scope) { - return BNTypeSetMemberScope(m_object, scope); + BNMemberScopeWithConfidence mc; + mc.value = scope.GetValue(); + mc.confidence = scope.GetConfidence(); + return BNTypeSetMemberScope(m_object, &mc); } -BNMemberAccess Type::GetAccess() const +Confidence Type::GetAccess() const { - return BNTypeGetMemberAccess(m_object); + BNMemberAccessWithConfidence result = BNTypeGetMemberAccess(m_object); + return Confidence(result.value, result.confidence); } -void Type::SetAccess(BNMemberAccess access) +void Type::SetAccess(const Confidence& access) { - return BNTypeSetMemberAccess(m_object, access); + BNMemberAccessWithConfidence mc; + mc.value = access.GetValue(); + mc.confidence = access.GetConfidence(); + return BNTypeSetMemberAccess(m_object, &mc); } -void Type::SetConst(bool cnst) +void Type::SetConst(const Confidence& cnst) { - BNTypeSetConst(m_object, cnst); + BNBoolWithConfidence bc; + bc.value = cnst.GetValue(); + bc.confidence = cnst.GetConfidence(); + BNTypeSetConst(m_object, &bc); } -void Type::SetVolatile(bool vltl) +void Type::SetVolatile(const Confidence& vltl) { - BNTypeSetVolatile(m_object, vltl); + BNBoolWithConfidence bc; + bc.value = vltl.GetValue(); + bc.confidence = vltl.GetConfidence(); + BNTypeSetVolatile(m_object, &bc); } -Ref Type::GetChildType() const +Confidence> Type::GetChildType() const { - BNType* type = BNGetChildType(m_object); - if (type) - return new Type(type); + BNTypeWithConfidence type = BNGetChildType(m_object); + if (type.type) + return Confidence>(new Type(type.type), type.confidence); return nullptr; } -Ref Type::GetCallingConvention() const +Confidence> Type::GetCallingConvention() const { - BNCallingConvention* cc = BNGetTypeCallingConvention(m_object); - if (cc) - return new CoreCallingConvention(cc); + BNCallingConventionWithConfidence cc = BNGetTypeCallingConvention(m_object); + if (cc.convention) + return Confidence>(new CoreCallingConvention(cc.convention), cc.confidence); return nullptr; } @@ -343,7 +359,7 @@ vector Type::GetParameters() const { NameAndType param; param.name = types[i].name; - param.type = new Type(BNNewTypeReference(types[i].type)); + param.type = Confidence>(new Type(BNNewTypeReference(types[i].type)), types[i].typeConfidence); result.push_back(param); } @@ -358,9 +374,10 @@ bool Type::HasVariableArguments() const } -bool Type::CanReturn() const +Confidence Type::CanReturn() const { - return BNFunctionTypeCanReturn(m_object); + BNBoolWithConfidence result = BNFunctionTypeCanReturn(m_object); + return Confidence(result.value, result.confidence); } @@ -447,6 +464,7 @@ vector Type::GetTokens() const token.size = tokens[i].size; token.operand = tokens[i].operand; token.context = tokens[i].context; + token.confidence = tokens[i].confidence; token.address = tokens[i].address; result.push_back(token); } @@ -471,6 +489,7 @@ vector Type::GetTokensBeforeName() const token.size = tokens[i].size; token.operand = tokens[i].operand; token.context = tokens[i].context; + token.confidence = tokens[i].confidence; token.address = tokens[i].address; result.push_back(token); } @@ -495,6 +514,7 @@ vector Type::GetTokensAfterName() const token.size = tokens[i].size; token.operand = tokens[i].operand; token.context = tokens[i].context; + token.confidence = tokens[i].confidence; token.address = tokens[i].address; result.push_back(token); } @@ -522,9 +542,12 @@ Ref Type::BoolType() } -Ref Type::IntegerType(size_t width, bool sign, const string& altName) +Ref Type::IntegerType(size_t width, const Confidence& sign, const string& altName) { - return new Type(BNCreateIntegerType(width, sign, altName.c_str())); + BNBoolWithConfidence bc; + bc.value = sign.GetValue(); + bc.confidence = sign.GetConfidence(); + return new Type(BNCreateIntegerType(width, &bc, altName.c_str())); } @@ -577,45 +600,86 @@ Ref Type::EnumerationType(Architecture* arch, Enumeration* enm, size_t wid } -Ref Type::PointerType(Architecture* arch, Type* type, bool cnst, bool vltl, BNReferenceType refType) +Ref Type::PointerType(Architecture* arch, const Confidence>& type, + const Confidence& cnst, const Confidence& vltl, BNReferenceType refType) { - return new Type(BNCreatePointerType(arch->GetObject(), type->GetObject(), cnst, vltl, refType)); + BNTypeWithConfidence typeConf; + typeConf.type = type->GetObject(); + typeConf.confidence = type.GetConfidence(); + + BNBoolWithConfidence cnstConf; + cnstConf.value = cnst.GetValue(); + cnstConf.confidence = cnst.GetConfidence(); + + BNBoolWithConfidence vltlConf; + vltlConf.value = vltl.GetValue(); + vltlConf.confidence = vltl.GetConfidence(); + + return new Type(BNCreatePointerType(arch->GetObject(), &typeConf, &cnstConf, &vltlConf, refType)); } -Ref Type::PointerType(size_t width, Type* type, bool cnst, bool vltl, BNReferenceType refType) +Ref Type::PointerType(size_t width, const Confidence>& type, + const Confidence& cnst, const Confidence& vltl, BNReferenceType refType) { - return new Type(BNCreatePointerTypeOfWidth(width, type->GetObject(), cnst, vltl, refType)); + BNTypeWithConfidence typeConf; + typeConf.type = type->GetObject(); + typeConf.confidence = type.GetConfidence(); + + BNBoolWithConfidence cnstConf; + cnstConf.value = cnst.GetValue(); + cnstConf.confidence = cnst.GetConfidence(); + + BNBoolWithConfidence vltlConf; + vltlConf.value = vltl.GetValue(); + vltlConf.confidence = vltl.GetConfidence(); + + return new Type(BNCreatePointerTypeOfWidth(width, &typeConf, &cnstConf, &vltlConf, refType)); } -Ref Type::ArrayType(Type* type, uint64_t elem) +Ref Type::ArrayType(const Confidence>& type, uint64_t elem) { - return new Type(BNCreateArrayType(type->GetObject(), elem)); + BNTypeWithConfidence typeConf; + typeConf.type = type->GetObject(); + typeConf.confidence = type.GetConfidence(); + return new Type(BNCreateArrayType(&typeConf, elem)); } -Ref Type::FunctionType(Type* returnValue, CallingConvention* callingConvention, - const std::vector& params, bool varArg) +Ref Type::FunctionType(const Confidence>& returnValue, + const Confidence>& callingConvention, + const std::vector& params, bool varArg) { + BNTypeWithConfidence returnValueConf; + returnValueConf.type = returnValue->GetObject(); + returnValueConf.confidence = returnValue.GetConfidence(); + + BNCallingConventionWithConfidence callingConventionConf; + callingConventionConf.convention = callingConvention ? callingConvention->GetObject() : nullptr; + callingConventionConf.confidence = callingConvention.GetConfidence(); + BNNameAndType* paramArray = new BNNameAndType[params.size()]; for (size_t i = 0; i < params.size(); i++) { paramArray[i].name = (char*)params[i].name.c_str(); paramArray[i].type = params[i].type->GetObject(); + paramArray[i].typeConfidence = params[i].type.GetConfidence(); } - Type* type = new Type(BNCreateFunctionType(returnValue->GetObject(), - callingConvention ? callingConvention->GetObject() : nullptr, - paramArray, params.size(), varArg)); + Type* type = new Type(BNCreateFunctionType(&returnValueConf, &callingConventionConf, + paramArray, params.size(), varArg)); delete[] paramArray; return type; } -void Type::SetFunctionCanReturn(bool canReturn) +void Type::SetFunctionCanReturn(const Confidence& canReturn) { - BNSetFunctionCanReturn(m_object, canReturn); + BNBoolWithConfidence bc; + bc.value = canReturn.GetValue(); + bc.confidence = canReturn.GetConfidence(); + BNSetFunctionCanReturn(m_object, &bc); } @@ -687,6 +751,12 @@ void Type::SetTypeName(const QualifiedName& names) } +Confidence> Type::WithConfidence(uint8_t conf) +{ + return Confidence>(this, conf); +} + + NamedTypeReference::NamedTypeReference(BNNamedTypeReference* nt) { m_object = nt; @@ -870,15 +940,21 @@ BNStructureType Structure::GetStructureType() const } -void Structure::AddMember(Type* type, const string& name) +void Structure::AddMember(const Confidence>& type, const string& name) { - BNAddStructureMember(m_object, type->GetObject(), name.c_str()); + BNTypeWithConfidence tc; + tc.type = type->GetObject(); + tc.confidence = type.GetConfidence(); + BNAddStructureMember(m_object, &tc, name.c_str()); } -void Structure::AddMemberAtOffset(Type* type, const string& name, uint64_t offset) +void Structure::AddMemberAtOffset(const Confidence>& type, const string& name, uint64_t offset) { - BNAddStructureMemberAtOffset(m_object, type->GetObject(), name.c_str(), offset); + BNTypeWithConfidence tc; + tc.type = type->GetObject(); + tc.confidence = type.GetConfidence(); + BNAddStructureMemberAtOffset(m_object, &tc, name.c_str(), offset); } @@ -888,9 +964,12 @@ void Structure::RemoveMember(size_t idx) } -void Structure::ReplaceMember(size_t idx, Type* type, const std::string& name) +void Structure::ReplaceMember(size_t idx, const Confidence>& type, const std::string& name) { - BNReplaceStructureMember(m_object, idx, type->GetObject(), name.c_str()); + BNTypeWithConfidence tc; + tc.type = type->GetObject(); + tc.confidence = type.GetConfidence(); + BNReplaceStructureMember(m_object, idx, &tc, name.c_str()); } -- cgit v1.3.1