Skip to content

Commit 3279636

Browse files
committed
Migrate remaining demangler consumers
Update the remaining C++ views, cache workflows, RTTI users, UI declarations, and plugin build wiring to the config-based demangler APIs. Remove duplicated cache-symbol helpers made obsolete by the unified result path.
1 parent 3632dca commit 3279636

30 files changed

Lines changed: 129 additions & 158 deletions

plugins/idb_import/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ file(GLOB API_SOURCES CONFIGURE_DEPENDS
1212
${PROJECT_SOURCE_DIR}/../../rust/binaryninjacore-sys/Cargo.toml
1313
${PROJECT_SOURCE_DIR}/../../rust/binaryninjacore-sys/src/*
1414
${PROJECT_SOURCE_DIR}/../../rust/Cargo.toml
15+
${PROJECT_SOURCE_DIR}/../../rust/src/*.rs
1516
${PROJECT_SOURCE_DIR}/../../rust/src/*/*.rs)
1617

1718
if(CMAKE_BUILD_TYPE MATCHES Debug)

plugins/pdb-ng/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ file(GLOB API_SOURCES CONFIGURE_DEPENDS
6060
${BN_API_SOURCE_DIR}/rust/binaryninjacore-sys/Cargo.toml
6161
${BN_API_SOURCE_DIR}/rust/binaryninjacore-sys/src/*
6262
${BN_API_SOURCE_DIR}/rust/Cargo.toml
63+
${BN_API_SOURCE_DIR}/rust/src/*.rs
6364
${BN_API_SOURCE_DIR}/rust/src/*/*.rs)
6465

6566
set_property(TARGET ${PROJECT_NAME} PROPERTY OUTPUT_FILE_PATH ${OUTPUT_FILE_PATH})

plugins/rtti/itanium.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ ItaniumRTTIProcessor::ItaniumRTTIProcessor(const Ref<BinaryView> &view, bool use
672672
{
673673
m_view = view;
674674
m_logger = view->CreateLogger("Itanium RTTI");
675+
m_simplifyTemplates = Settings::Instance()->Get<bool>("analysis.types.templateSimplifier", view);
675676
allowMangledClassNames = useMangled;
676677
checkWritableRData = checkRData;
677678
m_classInfo = {};

plugins/rtti/microsoft.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ std::vector<BaseClassInfo> MicrosoftRTTIProcessor::ProcessClassHierarchyDescript
368368
continue;
369369
}
370370
auto baseClassTypeDesc = TypeDescriptor(m_view, baseClassTypeDescAddr);
371-
auto baseClassName = DemangleNameMS(m_view, allowMangledClassNames, baseClassTypeDesc.name);
371+
auto baseClassName = DemangleNameMS(
372+
m_view, allowMangledClassNames, baseClassTypeDesc.name, m_simplifyTemplates);
372373
if (!baseClassName.has_value())
373374
{
374375
m_logger->LogWarnF("Skipping BaseClassDescriptor with mangled name {:#x}", baseClassTypeDescAddr);
@@ -415,7 +416,7 @@ std::optional<ClassInfo> MicrosoftRTTIProcessor::ProcessRTTI(uint64_t coLocatorA
415416
// Get type descriptor then check to see if the class name was demangled.
416417
auto typeDescAddr = resolveAddr(coLocator->pTypeDescriptor);
417418
auto typeDesc = TypeDescriptor(m_view, typeDescAddr);
418-
auto className = DemangleNameMS(m_view, allowMangledClassNames, typeDesc.name);
419+
auto className = DemangleNameMS(m_view, allowMangledClassNames, typeDesc.name, m_simplifyTemplates);
419420
if (!className.has_value())
420421
return std::nullopt;
421422

@@ -607,6 +608,7 @@ MicrosoftRTTIProcessor::MicrosoftRTTIProcessor(const Ref<BinaryView> &view, bool
607608
{
608609
m_view = view;
609610
m_logger = view->CreateLogger("Microsoft RTTI");
611+
m_simplifyTemplates = Settings::Instance()->Get<bool>("analysis.types.templateSimplifier", view);
610612
allowMangledClassNames = useMangled;
611613
allowAnonymousClassNames = allowAnonymous;
612614
checkWritableRData = checkRData;

plugins/rtti/rtti.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,18 @@ Ref<Symbol> RTTI::GetRealSymbol(BinaryView *view, uint64_t relocAddr, uint64_t s
3434
}
3535

3636

37-
std::optional<std::string> RTTI::DemangleNameMS(BinaryView* view, bool allowMangled, const std::string &mangledName)
37+
std::optional<std::string> RTTI::DemangleNameMS(
38+
BinaryView* view, bool allowMangled, const std::string &mangledName, bool simplifyTemplates)
3839
{
39-
QualifiedName demangledName = {};
40-
Ref<Type> outType = {};
41-
if (!DemangleMS(view->GetDefaultArchitecture(), mangledName, outType, demangledName, view))
40+
auto result = DemangleMS(view->GetDefaultPlatform(), mangledName, simplifyTemplates);
41+
if (!result)
4242
return DemangleNameLLVM(allowMangled, mangledName);
43-
return NormalizeRTTIClassName(demangledName.GetString());
43+
return NormalizeRTTIClassName(result->name.GetString());
4444
}
4545

4646

4747
std::optional<std::string> RTTI::DemangleNameGNU3(BinaryView* view, bool allowMangled, const std::string &mangledName)
4848
{
49-
QualifiedName demangledName = {};
50-
Ref<Type> outType = {};
51-
5249
std::string adjustedMangledName = mangledName;
5350
// For some reason some of the names that start with ZN are not prefixed by `_`.
5451
if (adjustedMangledName.rfind("ZN", 0) == 0)
@@ -62,7 +59,8 @@ std::optional<std::string> RTTI::DemangleNameGNU3(BinaryView* view, bool allowMa
6259
if (adjustedMangledName.rfind("_Z", 0) != 0)
6360
adjustedMangledName = "_Z" + adjustedMangledName;
6461

65-
if (!DemangleGNU3(view->GetDefaultArchitecture(), adjustedMangledName, outType, demangledName, true))
62+
auto result = DemangleGNU3(view->GetDefaultPlatform(), adjustedMangledName, true);
63+
if (!result)
6664
return allowMangled ? std::optional(mangledName) : std::nullopt;
6765

6866
// Because we might have a generic name such as "PackageListGui::PackageListGui" returned, we must attempt to
@@ -71,10 +69,10 @@ std::optional<std::string> RTTI::DemangleNameGNU3(BinaryView* view, bool allowMa
7169
// MANGLED: ZN14PackageListGuiC1EON10Filesystem4PathENS_14UnderSubheaderEbE3$_1
7270
// GENERIC DEMANGLED: PackageListGui::PackageListGui
7371
// UPDATED DEMANGLED: PackageListGui::PackageListGui(Filesystem::Path&&, PackageListGui::UnderSubheader, bool)
74-
if (outType && outType->IsFunction())
75-
demangledName.push_back(outType->GetStringAfterName(view->GetDefaultPlatform()));
72+
if (result->type && result->type->IsFunction())
73+
result->name.push_back(result->type->GetStringAfterName(view->GetDefaultPlatform()));
7674

77-
return demangledName.GetString();
75+
return result->name.GetString();
7876
}
7977

8078

@@ -100,11 +98,10 @@ std::optional<std::string> RTTI::DemangleNameItanium(BinaryView* view, bool allo
10098

10199
std::optional<std::string> RTTI::DemangleNameLLVM(bool allowMangled, const std::string &mangledName)
102100
{
103-
QualifiedName demangledName = {};
104-
Ref<Type> outType = {};
105-
if (!DemangleLLVM(mangledName, demangledName, true))
101+
auto result = DemangleLLVM(mangledName, true);
102+
if (!result)
106103
return allowMangled ? std::optional(mangledName) : std::nullopt;
107-
return NormalizeRTTIClassName(demangledName.GetString());
104+
return NormalizeRTTIClassName(result->name.GetString());
108105
}
109106

110107

plugins/rtti/rtti.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ constexpr int RTTI_CONFIDENCE = 100;
88
namespace BinaryNinja::RTTI {
99
Ref<Symbol> GetRealSymbol(BinaryView *view, uint64_t relocAddr, uint64_t symAddr);
1010

11-
std::optional<std::string> DemangleNameMS(BinaryView* view, bool allowMangled, const std::string &mangledName);
11+
std::optional<std::string> DemangleNameMS(
12+
BinaryView* view, bool allowMangled, const std::string &mangledName, bool simplifyTemplates);
1213

1314
std::optional<std::string> DemangleNameGNU3(BinaryView* view, bool allowMangled, const std::string &mangledName);
1415

@@ -81,6 +82,7 @@ namespace BinaryNinja::RTTI {
8182

8283
Ref<BinaryView> m_view;
8384
Ref<Logger> m_logger;
85+
bool m_simplifyTemplates = false;
8486

8587
std::map<uint64_t, ClassInfo> m_classInfo;
8688
std::map<uint64_t, ClassInfo> m_unhandledClassInfo;

plugins/workflow_objc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ file(GLOB_RECURSE API_SOURCES CONFIGURE_DEPENDS
8181
${PROJECT_SOURCE_DIR}/../../rust/binaryninjacore-sys/Cargo.toml
8282
${PROJECT_SOURCE_DIR}/../../rust/binaryninjacore-sys/src/*.rs
8383
${PROJECT_SOURCE_DIR}/../../rust/Cargo.toml
84+
${PROJECT_SOURCE_DIR}/../../rust/src/*.rs
8485
${PROJECT_SOURCE_DIR}/../../rust/src/*/*.rs)
8586

8687
find_program(RUSTUP_PATH rustup REQUIRED HINTS ~/.cargo/bin)

plugins/workflow_swift/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ file(GLOB_RECURSE API_SOURCES CONFIGURE_DEPENDS
8181
${PROJECT_SOURCE_DIR}/../../rust/binaryninjacore-sys/Cargo.toml
8282
${PROJECT_SOURCE_DIR}/../../rust/binaryninjacore-sys/src/*.rs
8383
${PROJECT_SOURCE_DIR}/../../rust/Cargo.toml
84+
${PROJECT_SOURCE_DIR}/../../rust/src/*.rs
8485
${PROJECT_SOURCE_DIR}/../../rust/src/*/*.rs)
8586

8687
find_program(RUSTUP_PATH rustup REQUIRED HINTS ~/.cargo/bin)

ui/linearview.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ class BINARYNINJAUIAPI LinearView : public QAbstractScrollArea, public View, pub
233233
BinaryNinja::FunctionViewType m_ilViewType, m_prevILViewType = InvalidILViewType;
234234
HexEditorHighlightState m_highlightState;
235235
bool m_singleFunctionView = false;
236+
bool m_simplifyTemplates = false;
236237

237238
InstructionEdit* m_instrEdit = nullptr;
238239

@@ -311,7 +312,7 @@ class BINARYNINJAUIAPI LinearView : public QAbstractScrollArea, public View, pub
311312
StructureRef defineInnerName(TypeRef type, uint64_t offset, uint64_t size, std::set<TypeRef>& seen);
312313
StructureRef defineInnerIntegerSize(TypeRef type, uint64_t offset, uint64_t size, std::set<TypeRef>& seen);
313314
StructureRef defineInnerSign(TypeRef type, uint64_t offset, uint64_t size, std::set<TypeRef>& seen);
314-
TypeRef getPointerTypeAndName(ArchitectureRef arch, uint64_t addr, std::string& name);
315+
TypeRef getPointerTypeAndName(uint64_t addr, std::string& name);
315316
std::string getVariableName(uint64_t addr);
316317

317318
BinaryNinja::Ref<BinaryNinja::LinearViewObject> createLinearViewObject();

view/elf/elfview.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,6 @@ bool ElfView::Init()
497497
uint64_t preferredImageBase = initialImageBase;
498498
Ref<Settings> viewSettings = Settings::Instance();
499499
m_extractMangledTypes = viewSettings->Get<bool>("analysis.extractTypesFromMangledNames", this);
500-
m_simplifyTemplates = viewSettings->Get<bool>("analysis.types.templateSimplifier", this);
501500

502501
bool platformSetByUser = false;
503502
Ref<Settings> settings = GetLoadSettings(GetTypeName());
@@ -808,8 +807,10 @@ bool ElfView::Init()
808807
if (!platform)
809808
platform = entryPointArch->GetStandalonePlatform();
810809

810+
m_plat = platform;
811811
SetDefaultPlatform(platform);
812812
GetParentView()->SetDefaultPlatform(platform);
813+
m_demanglerConfig = DemanglerConfig::ForBinaryView(this);
813814

814815
// Finished for parse only mode
815816
if (m_parseOnly)
@@ -2617,19 +2618,16 @@ void ElfView::DefineElfSymbol(BNSymbolType type, const string& incomingName, uin
26172618
string shortName = rawName;
26182619
string fullName = rawName;
26192620
Confidence<Ref<Type>> typeRef = symbolTypeRef;
2620-
if (m_arch)
2621+
2622+
if (auto result = Demangler::DemangleAny(rawName, m_demanglerConfig))
26212623
{
2622-
QualifiedName demangledName;
2623-
Ref<Type> demangledType;
2624-
if (DemangleGeneric(m_arch, rawName, demangledType, demangledName, this, m_simplifyTemplates))
2625-
{
2626-
shortName = demangledName.GetString();
2627-
fullName = shortName;
2628-
if (demangledType)
2629-
fullName += demangledType->GetStringAfterName();
2630-
if (!typeRef && m_extractMangledTypes && !GetDefaultPlatform()->GetFunctionByName(rawName))
2631-
typeRef = demangledType;
2632-
}
2624+
auto demangledType = result->type;
2625+
shortName = result->name.GetString();
2626+
fullName = shortName;
2627+
if (demangledType)
2628+
fullName += demangledType->GetStringAfterName();
2629+
if (!typeRef && m_extractMangledTypes && !m_plat->GetFunctionByName(rawName))
2630+
typeRef = demangledType;
26332631
}
26342632

26352633
if (!typeRef && m_arch && (m_arch->GetName() == "hexagon" || m_arch->GetName() == "tms320c6x"))

0 commit comments

Comments
 (0)