@@ -1914,6 +1914,38 @@ BNCallingConventionName Demangle::DemangleCallingConvention()
19141914}
19151915
19161916
1917+ Ref<CallingConvention> Demangle::ResolveCallingConvention (BNCallingConventionName cc) const
1918+ {
1919+ switch (cc)
1920+ {
1921+ case CdeclCallingConvention:
1922+ if (m_platform && m_platform->GetCdeclCallingConvention ())
1923+ return m_platform->GetCdeclCallingConvention ();
1924+ if (m_arch && m_arch->GetCdeclCallingConvention ())
1925+ return m_arch->GetCdeclCallingConvention ();
1926+ return m_arch ? m_arch->GetCallingConventionByName (" cdecl" ) : nullptr ;
1927+ case STDCallCallingConvention:
1928+ if (m_platform && m_platform->GetStdcallCallingConvention ())
1929+ return m_platform->GetStdcallCallingConvention ();
1930+ if (m_arch && m_arch->GetStdcallCallingConvention ())
1931+ return m_arch->GetStdcallCallingConvention ();
1932+ return m_arch ? m_arch->GetCallingConventionByName (" stdcall" ) : nullptr ;
1933+ case FastcallCallingConvention:
1934+ if (m_platform && m_platform->GetFastcallCallingConvention ())
1935+ return m_platform->GetFastcallCallingConvention ();
1936+ if (m_arch && m_arch->GetFastcallCallingConvention ())
1937+ return m_arch->GetFastcallCallingConvention ();
1938+ return m_arch ? m_arch->GetCallingConventionByName (" fastcall" ) : nullptr ;
1939+ case ThisCallCallingConvention:
1940+ if (m_arch)
1941+ return m_arch->GetCallingConventionByName (" thiscall" );
1942+ return nullptr ;
1943+ default :
1944+ return nullptr ;
1945+ }
1946+ }
1947+
1948+
19171949void Demangle::ConsumeExtendedModifierPrefix ()
19181950{
19191951 while (reader.PeekMatch (" $A" , 2 ))
@@ -2112,25 +2144,10 @@ DemangledTypeNode Demangle::DemangleFunction(BNNameType classFunctionType, bool
21122144
21132145 MSVC_TRACE (" \t Demangle Function Parameters %s" , reader.GetRaw ());
21142146 vector<DemangledTypeNode::Param> params;
2115- bool needsThisPtr = false ;
2116- if (includeImplicitThis && cc == ThisCallCallingConvention)
2117- {
2118- needsThisPtr = true ;
2119- }
2120- if (includeImplicitThis && funcClass != NoneFunctionClass)
2121- {
2122- if ((funcClass & VirtualFunctionClass) == VirtualFunctionClass
2123- || (funcClass & StaticThunkFunctionClass) == StaticThunkFunctionClass
2124- || (funcClass & VirtualThunkFunctionClass) == VirtualThunkFunctionClass)
2125- {
2126- needsThisPtr = true ;
2127- }
2128- else if ((funcClass & StaticFunctionClass) != StaticFunctionClass
2129- && (funcClass & GlobalFunctionClass) != GlobalFunctionClass)
2130- {
2131- needsThisPtr = true ;
2132- }
2133- }
2147+ bool needsThisPtr = includeImplicitThis
2148+ && funcClass != NoneFunctionClass
2149+ && (funcClass & StaticFunctionClass) != StaticFunctionClass
2150+ && (funcClass & GlobalFunctionClass) != GlobalFunctionClass;
21342151
21352152 DemangleVariableList (params, nameBackrefList);
21362153
@@ -2145,12 +2162,14 @@ DemangledTypeNode Demangle::DemangleFunction(BNNameType classFunctionType, bool
21452162 newType.SetPointerSuffixBits (suffix);
21462163 newType.SetNameType (classFunctionType);
21472164 newType.SetCallingConventionName (cc);
2165+ if (auto callingConvention = ResolveCallingConvention (cc))
2166+ newType.SetCallingConvention (callingConvention);
21482167 if (needsThisPtr)
21492168 {
21502169 NameList thisName = m_varName;
21512170 if (classFunctionType != OperatorReturnTypeNameType && !thisName.empty ())
21522171 thisName.pop_back ();
2153- auto thisNamedType = DemangledTypeNode::NamedType (UnknownNamedTypeClass , std::move (thisName));
2172+ auto thisNamedType = DemangledTypeNode::NamedType (TypedefNamedTypeClass , std::move (thisName));
21542173 newType.SetImplicitThisParameter (DemangledTypeNode::PointerType (
21552174 m_arch, std::move (thisNamedType), false , false , PointerReferenceType));
21562175 }
@@ -2516,6 +2535,8 @@ bool Demangle::DemangleMS(Architecture* arch, const string& mangledName, Ref<Typ
25162535 outType = nullptr ;
25172536 if (mangledName.empty () || (mangledName[0 ] != ' ?' && mangledName[0 ] != ' .' ))
25182537 return false ;
2538+ if (view)
2539+ return DemangleMS (mangledName, outType, outVarName, view);
25192540 return DemangleMS (arch, mangledName, outType, outVarName);
25202541}
25212542
@@ -2525,9 +2546,32 @@ bool Demangle::DemangleMS(Architecture* arch, const string& mangledName, Ref<Typ
25252546 outType = nullptr ;
25262547 if (mangledName.empty () || (mangledName[0 ] != ' ?' && mangledName[0 ] != ' .' ))
25272548 return false ;
2549+ if (view)
2550+ return DemangleMS (mangledName, outType, outVarName, Ref<BinaryView>(view));
25282551 return DemangleMS (arch, mangledName, outType, outVarName);
25292552}
25302553
2554+ bool Demangle::DemangleMS (Platform* platform, const string& mangledName, Ref<Type>& outType,
2555+ QualifiedName& outVarName)
2556+ {
2557+ outType = nullptr ;
2558+ if (!platform || mangledName.empty () || (mangledName[0 ] != ' ?' && mangledName[0 ] != ' .' ))
2559+ return false ;
2560+ try
2561+ {
2562+ Demangle demangle (Ref<Platform>(platform), mangledName);
2563+ auto result = demangle.Finalize ();
2564+ outType = std::move (result.first );
2565+ outVarName = std::move (result.second );
2566+ }
2567+ catch (DemangleException &e)
2568+ {
2569+ LogDebugForException (e, " Demangling Failed '%s' '%s;" , mangledName.c_str (), e.what ());
2570+ return false ;
2571+ }
2572+ return true ;
2573+ }
2574+
25312575bool Demangle::DemangleMS (Architecture* arch, const string& mangledName, Ref<Type>& outType,
25322576 QualifiedName& outVarName)
25332577{
@@ -2573,6 +2617,15 @@ bool Demangle::DemangleMS(const string& mangledName, Ref<Type>& outType,
25732617 return true ;
25742618}
25752619
2620+ bool Demangle::DemangleMS (const string& mangledName, Ref<Type>& outType,
2621+ QualifiedName& outVarName, BinaryView* view)
2622+ {
2623+ outType = nullptr ;
2624+ if (!view)
2625+ return false ;
2626+ return DemangleMS (mangledName, outType, outVarName, Ref<BinaryView>(view));
2627+ }
2628+
25762629
25772630class MSDemangler : public Demangler
25782631{
0 commit comments