From 0f26e9236d52e5e2f0a8e64114d954a516cbeb95 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Tue, 8 Apr 2025 14:16:05 -0400 Subject: [SharedCache] Apply demangled names and types more broadly Fixes the case of stub functions being applied with mangled names. --- view/sharedcache/workflow/SharedCacheWorkflow.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'view/sharedcache/workflow/SharedCacheWorkflow.cpp') diff --git a/view/sharedcache/workflow/SharedCacheWorkflow.cpp b/view/sharedcache/workflow/SharedCacheWorkflow.cpp index 5980d141..c0c90f87 100644 --- a/view/sharedcache/workflow/SharedCacheWorkflow.cpp +++ b/view/sharedcache/workflow/SharedCacheWorkflow.cpp @@ -87,22 +87,28 @@ void IdentifyStub(BinaryView& view, const SharedCacheController& controller, uin if (!symbol.has_value()) return; + // Demangle if possible, the type pulled will be used, however type library will take precedence. + auto [demangledName, demangledType] = symbol->DemangledName(view); + auto rawName = STUB_PREFIX + symbol->name; + auto shortName = STUB_PREFIX + demangledName; + // Try and retrieve a type for the stub function using type libraries. if (const auto targetFunc = view.GetAnalysisFunction(view.GetDefaultPlatform(), stubFuncAddr)) { // NOTE: The type library name is expected to be the image name currently. // Try and pull the type from the associated type library (if there is one) - Ref type = nullptr; + Ref selectedType = demangledType; if (const auto image = controller.GetImageContaining(symbolAddr)) if (auto typeLib = TypeLibraryFromName(view, image->name)) - type = view.ImportTypeLibraryObject(typeLib, {symbol->name}); + selectedType = view.ImportTypeLibraryObject(typeLib, {symbol->name}); - if (type) - targetFunc->SetAutoType(type); + if (selectedType) + targetFunc->SetAutoType(selectedType); } // Define the new symbol! - view.DefineAutoSymbol(new Symbol(symbol->type, STUB_PREFIX + symbol->name, stubFuncAddr)); + auto bnSymbol = new Symbol(symbol->type, shortName, shortName, rawName, stubFuncAddr, nullptr); + view.DefineAutoSymbol(bnSymbol); } void AnalyzeStubFunction(Ref func, Ref mlil, SharedCacheController& controller, bool loadImage) -- cgit v1.3.1