summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-04-03 13:00:47 -0400
committerMason Reed <mason@vector35.com>2025-04-03 13:00:47 -0400
commit578c5e77a60957a4d04eaac000679de3e5534e7b (patch)
tree8353c7e6c4be46b9b0781fd72f82d6f4cca2c634
parent254fd7b1f48c0e79889e4c786c7e507e7ac2e067 (diff)
[SharedCache] Identify unloaded symbols that are called in standard functions
Fixes https://github.com/Vector35/binaryninja-api/issues/6550
-rw-r--r--view/sharedcache/api/sharedcache.cpp10
-rw-r--r--view/sharedcache/api/sharedcacheapi.h2
-rw-r--r--view/sharedcache/workflow/SharedCacheWorkflow.cpp10
3 files changed, 22 insertions, 0 deletions
diff --git a/view/sharedcache/api/sharedcache.cpp b/view/sharedcache/api/sharedcache.cpp
index 8c9b2234..b92a0e64 100644
--- a/view/sharedcache/api/sharedcache.cpp
+++ b/view/sharedcache/api/sharedcache.cpp
@@ -125,6 +125,16 @@ std::string SharedCacheAPI::GetRegionTypeAsString(const BNSharedCacheRegionType
}
}
+Ref<Symbol> CacheSymbol::GetBNSymbol(BinaryView &view) const
+{
+ QualifiedName qname;
+ Ref<Type> outType;
+ std::string shortName = name;
+ if (DemangleGeneric(view.GetDefaultArchitecture(), name, outType, qname, &view, true))
+ shortName = qname.GetString();
+ return new Symbol(type, shortName, shortName, name, address, nullptr);
+}
+
std::string SharedCacheAPI::GetSymbolTypeAsString(const BNSymbolType &type)
{
// NOTE: We currently only use the function and data symbol for cache symbols.
diff --git a/view/sharedcache/api/sharedcacheapi.h b/view/sharedcache/api/sharedcacheapi.h
index ee49140e..db5eeefc 100644
--- a/view/sharedcache/api/sharedcacheapi.h
+++ b/view/sharedcache/api/sharedcacheapi.h
@@ -287,6 +287,8 @@ namespace SharedCacheAPI {
BNSymbolType type;
uint64_t address;
std::string name;
+
+ BinaryNinja::Ref<BinaryNinja::Symbol> GetBNSymbol(BinaryNinja::BinaryView& view) const;
};
std::string GetSymbolTypeAsString(const BNSymbolType& type);
diff --git a/view/sharedcache/workflow/SharedCacheWorkflow.cpp b/view/sharedcache/workflow/SharedCacheWorkflow.cpp
index 7dde4089..186ba85a 100644
--- a/view/sharedcache/workflow/SharedCacheWorkflow.cpp
+++ b/view/sharedcache/workflow/SharedCacheWorkflow.cpp
@@ -220,6 +220,15 @@ void AnalyzeStubFunction(Ref<Function> func, Ref<MediumLevelILFunction> mlil, Sh
void AnalyzeStandardFunction(Ref<Function> func, Ref<MediumLevelILFunction> mlil, SharedCacheController& controller)
{
auto view = func->GetView();
+ auto identifyUnmappedSymbol = [&](uint64_t symbolAddr) {
+ // Skip if already loaded.
+ if (view->IsValidOffset(symbolAddr))
+ return false;
+ const auto symbol = controller.GetSymbolAt(symbolAddr);
+ view->DefineAutoSymbol(symbol->GetBNSymbol(*view));
+ return true;
+ };
+
auto loadStubIslandRegion = [&](uint64_t regionAddr) {
// Skip if already loaded.
if (view->IsValidOffset(regionAddr))
@@ -239,6 +248,7 @@ void AnalyzeStandardFunction(Ref<Function> func, Ref<MediumLevelILFunction> mlil
{
case MLIL_CONST_PTR:
loadStubIslandRegion(expr.GetConstant<MLIL_CONST_PTR>());
+ identifyUnmappedSymbol(expr.GetConstant<MLIL_CONST_PTR>());
break;
default:
break;