Skip to content

Commit 37941e4

Browse files
committed
Refactor MSVC demangler parse and finalize flow
Split MSVC symbol parsing from finalization by carrying the parsed qualified name in DemangleContext instead of using mutable demangler-wide name state. Function parsing now returns a DemangledFunction with the parsed DemangledTypeNode plus optional decoded thunk adjustor metadata, and the symbol-context callers finalize name-dependent work such as thunk suffixes and implicit this parameter synthesis. Expand DemangledTypeNode into the shared representation used by the MSVC path for delayed type construction, platform-aware widths, calling convention resolution, member pointers, postfix forms, and explicit implicit-this parameters. This lets MSVC parsing produce structured type/name data first and defer Binary Ninja Type construction until finalization has the platform and view context. Also route MSVC string literals, raw type-info names, vtables, RTTI, dynamic init/fini stubs, local guards, and referenced-symbol template values through explicit DemangledTypeNode/name flow. Extensively tested with the MSVC demangler unit suite and a 199,500-symbol regression corpus with zero output changes or failures.
1 parent 6a1de81 commit 37941e4

11 files changed

Lines changed: 3567 additions & 1401 deletions

File tree

demangle.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,19 @@ namespace BinaryNinja {
4747
bool DemangleMS(Architecture* arch, const std::string& mangledName, Ref<Type>& outType, QualifiedName& outVarName,
4848
BinaryView* view)
4949
{
50-
const bool simplify = Settings::Instance()->Get<bool>("analysis.types.templateSimplifier", view);
51-
return DemangleMS(arch, mangledName, outType, outVarName, simplify);
50+
BNType* localType = nullptr;
51+
char** localVarName = nullptr;
52+
size_t localSize = 0;
53+
if (!BNDemangleMSWithOptions(arch->GetObject(), mangledName.c_str(), &localType, &localVarName, &localSize,
54+
view ? view->GetObject() : nullptr))
55+
return false;
56+
outType = localType ? new Type(localType) : nullptr;
57+
for (size_t i = 0; i < localSize; i++)
58+
{
59+
outVarName.push_back(localVarName[i]);
60+
}
61+
BNFreeDemangledName(&localVarName, localSize);
62+
return true;
5263
}
5364

5465
bool DemangleMS(Architecture* arch, const std::string& mangledName, Ref<Type>& outType, QualifiedName& outVarName,

0 commit comments

Comments
 (0)