Skip to content

Commit b0965fa

Browse files
bdashemesare
authored andcommitted
[SharedCache] Add activities to core.function.metaAnalysis rather than a new named workflow
Activities are registered with a `viewType` predicate to ensure they only run in shared cache views. Adding activities to `core.function.metaAnalysis` lets activities registered by plug-ins run in the shared cache without the plug-ins having to be aware of the shared cache. Work towards #6779.
1 parent 17ac386 commit b0965fa

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

view/sharedcache/core/SharedCacheView.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,11 @@ bool SharedCacheView::Init()
241241
Ref<Settings> programSettings = Settings::Instance();
242242
auto previousWorkflow = programSettings->Get<std::string>("analysis.workflows.functionWorkflow", this);
243243

244-
// If we are a new file (not a database) lets go ahead and set the function workflow.
245-
// We do not set the workflow on database as the user might have changed it in load options prior.
246-
// We also need to update usages of `core.function.dsc` to `core.function.sharedCache`
247-
if (!GetFile()->IsBackedByDatabase() || previousWorkflow == "core.function.dsc")
248-
programSettings->Set("analysis.workflows.functionWorkflow", "core.function.sharedCache", this);
244+
// Earlier versions of the shared cache plug-in used a named workflow rather than
245+
// modifying `core.function.metaAnalysis`. Update reference to those older workflow
246+
// names to `core.function.metaAnalysis`.
247+
if (previousWorkflow == "core.function.dsc" || previousWorkflow == "core.function.sharedCache")
248+
programSettings->Set("analysis.workflows.functionWorkflow", "core.function.metaAnalysis", this);
249249
}
250250

251251
if (m_parseOnly)

view/sharedcache/workflow/ObjCActivity.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,21 @@ using namespace BinaryNinja;
77

88
void ObjCActivity::Register(Workflow &workflow)
99
{
10-
workflow.RegisterActivity(new Activity("core.analysis.objc.adjustCallType", &AdjustCallType));
11-
workflow.Insert("core.function.analyzeTailCalls", "core.analysis.objc.adjustCallType");
10+
workflow.RegisterActivity(new Activity(R"({
11+
"name": "core.analysis.sharedCache.objc.adjustCallType",
12+
"eligibility": {
13+
"predicates": [
14+
{
15+
"type": "viewType",
16+
"operator": "in",
17+
"value": [
18+
"DSCView"
19+
]
20+
}
21+
]
22+
}
23+
})", &AdjustCallType));
24+
workflow.Insert("core.function.analyzeTailCalls", "core.analysis.sharedCache.objc.adjustCallType");
1225
}
1326

1427
std::vector<std::string> splitSelector(const std::string& selector) {

view/sharedcache/workflow/SharedCacheWorkflow.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,21 +365,28 @@ void AnalyzeFunction(Ref<AnalysisContext> ctx)
365365

366366
void SharedCacheWorkflow::Register()
367367
{
368-
Ref<Workflow> workflow = Workflow::Instance("core.function.baseAnalysis")->Clone("core.function.sharedCache");
368+
Ref<Workflow> workflow = Workflow::Instance("core.function.metaAnalysis")->Clone("core.function.metaAnalysis");
369369

370370
// Register and insert activities here.
371371
ObjCActivity::Register(*workflow);
372-
workflow->RegisterActivity(new Activity("core.analysis.sharedCache.analysis", &AnalyzeFunction));
372+
workflow->RegisterActivity(new Activity(R"({
373+
"name": "core.analysis.sharedCache.analysis",
374+
"eligibility": {
375+
"predicates": [
376+
{
377+
"type": "viewType",
378+
"operator": "in",
379+
"value": [
380+
"DSCView"
381+
]
382+
}
383+
]
384+
}
385+
})", &AnalyzeFunction));
373386
std::vector<std::string> inserted = { "core.analysis.sharedCache.analysis" };
374387
workflow->Insert("core.function.analyzeTailCalls", inserted);
375388

376-
static constexpr auto WORKFLOW_DESCRIPTION = R"({
377-
"title": "Shared Cache Workflow",
378-
"description": "Shared Cache Workflow",
379-
"capabilities": []
380-
})";
381-
382-
Workflow::RegisterWorkflow(workflow, WORKFLOW_DESCRIPTION);
389+
Workflow::RegisterWorkflow(workflow);
383390
}
384391

385392
extern "C"

0 commit comments

Comments
 (0)