1616#ifdef BINARYNINJACORE_LIBRARY
1717#include " binaryview.h"
1818#endif
19+ #include < algorithm>
1920#include < cinttypes>
2021
2122#ifdef BINARYNINJACORE_LIBRARY
@@ -957,6 +958,26 @@ string DemangledTypeNode::GetTypeAndName(const StringList& name) const
957958}
958959
959960
961+ bool DemangledTypeNode::HasUndeterminedTopLevelSize () const
962+ {
963+ switch (m_typeClass)
964+ {
965+ case NamedTypeReferenceClass:
966+ return m_widthKind == FixedWidth && m_width == 0 ;
967+ case ArrayTypeClass:
968+ return m_childType && m_childType->HasUndeterminedTopLevelSize ();
969+ default :
970+ return false ;
971+ }
972+ }
973+
974+
975+ uint8_t DemangledTypeNode::GetValueConfidence () const
976+ {
977+ return HasUndeterminedTopLevelSize () ? BN_DEFAULT_CONFIDENCE : BN_FULL_CONFIDENCE ;
978+ }
979+
980+
960981Ref<Type> DemangledTypeNode::Finalize (Architecture* arch, Platform* platform) const
961982{
962983 switch (m_typeClass)
@@ -1043,14 +1064,22 @@ Ref<Type> DemangledTypeNode::Finalize(Architecture* arch, Platform* platform) co
10431064 case FunctionTypeClass:
10441065 {
10451066 Ref<Type> retType = m_childType ? m_childType->Finalize (arch, platform) : Ref<Type>(Type::VoidType ());
1067+ uint8_t retTypeConfidence = m_childType ? m_childType->GetValueConfidence () : BN_FULL_CONFIDENCE ;
1068+ retTypeConfidence = std::min (retTypeConfidence, m_returnTypeConfidence);
1069+
10461070 vector<FunctionParameter> finalParams;
10471071 finalParams.reserve (m_params.size () + (m_implicitThisParameterType ? 1 : 0 ));
10481072 if (m_implicitThisParameterType)
1049- finalParams.push_back ({" this" , m_implicitThisParameterType->Finalize (arch, platform), true , Variable ()});
1073+ {
1074+ Ref<Type> thisType = m_implicitThisParameterType->Finalize (arch, platform);
1075+ finalParams.push_back ({" this" , thisType->WithConfidence (m_implicitThisParameterType->GetValueConfidence ()),
1076+ true , Variable ()});
1077+ }
10501078 for (auto & p : m_params)
10511079 {
10521080 Ref<Type> pType = p.type ? p.type ->Finalize (arch, platform) : Ref<Type>(Type::VoidType ());
1053- finalParams.push_back ({p.name , pType, true , Variable ()});
1081+ uint8_t pTypeConfidence = p.type ? p.type ->GetValueConfidence () : BN_FULL_CONFIDENCE ;
1082+ finalParams.push_back ({p.name , pType->WithConfidence (pTypeConfidence), true , Variable ()});
10541083 }
10551084 Confidence<Ref<CallingConvention>> callingConvention;
10561085 if (m_callingConvention)
@@ -1061,7 +1090,7 @@ Ref<Type> DemangledTypeNode::Finalize(Architecture* arch, Platform* platform) co
10611090 callingConvention = Confidence<Ref<CallingConvention>>(resolvedCallingConvention, BN_FULL_CONFIDENCE );
10621091 }
10631092 TypeBuilder tb = TypeBuilder::FunctionType (
1064- retType->WithConfidence (static_cast < uint8_t >(m_returnTypeConfidence) ), callingConvention, finalParams,
1093+ retType->WithConfidence (retTypeConfidence ), callingConvention, finalParams,
10651094 Confidence<bool >(m_hasVariableArgs, m_hasVariableArgs ? BN_DEFAULT_CONFIDENCE : 0 ));
10661095 tb.SetConst (m_const);
10671096 tb.SetVolatile (m_volatile);
0 commit comments