Skip to content

Commit edf6223

Browse files
committed
[WARP] Generate function guids for mach-o objective-c binaries
Previously we only added the warp function activities to the meta workflow, however objective-c plugin currently registers its own workflow that we must add the activities to as well. Fixes #7172
1 parent d5d4fd7 commit edf6223

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

plugins/warp/src/plugin.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use binaryninja::background_task::BackgroundTask;
1212
use binaryninja::command::{
1313
register_command, register_command_for_function, register_command_for_project,
1414
};
15-
use binaryninja::is_ui_enabled;
1615
use binaryninja::logger::Logger;
1716
use binaryninja::settings::Settings;
17+
use binaryninja::{add_optional_plugin_dependency, is_ui_enabled};
1818
use log::LevelFilter;
1919
use reqwest::StatusCode;
2020

@@ -197,3 +197,9 @@ pub extern "C" fn CorePluginInit() -> bool {
197197

198198
true
199199
}
200+
201+
#[unsafe(no_mangle)]
202+
pub extern "C" fn CorePluginDependencies() {
203+
// TODO: Remove this once the objectivec workflow is registered on the meta workflow.
204+
add_optional_plugin_dependency("workflow_objc");
205+
}

plugins/warp/src/plugin/workflow.rs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,21 @@ pub fn run_matcher(view: &BinaryView) {
108108
if functions_by_target_and_guid.is_empty() && !view.functions().is_empty() {
109109
// The user is likely trying to run the matcher on a database before guids were automatically
110110
// generated, we should alert them and ask if they would like to reanalyze.
111-
// TODO: Call reanalyze for them?
112-
log::error!("Trying to match with an older database, please reanalyze the database.");
111+
// NOTE: We only alert if we actually have the GUID activity enabled.
112+
if let Some(sample_function) = view.functions().iter().next() {
113+
let function_workflow = sample_function
114+
.workflow()
115+
.expect("Function has no workflow");
116+
if function_workflow.contains(GUID_ACTIVITY_NAME) {
117+
log::error!("No function guids in database, please reanalyze the database.");
118+
} else {
119+
log::error!(
120+
"Activity '{}' is not in workflow '{}', create function guids manually to run matcher...",
121+
GUID_ACTIVITY_NAME,
122+
function_workflow.name()
123+
)
124+
}
125+
}
113126
background_task.finish();
114127
return;
115128
}
@@ -245,22 +258,21 @@ pub fn insert_workflow() {
245258
}
246259
};
247260

248-
let old_function_meta_workflow = Workflow::instance("core.function.metaAnalysis");
249-
let function_meta_workflow = old_function_meta_workflow.clone_to("core.function.metaAnalysis");
250261
let guid_activity = Activity::new_with_action(GUID_ACTIVITY_CONFIG, guid_activity);
251262
let apply_activity = Activity::new_with_action(APPLY_ACTIVITY_CONFIG, apply_activity);
252-
function_meta_workflow
253-
.register_activity(&guid_activity)
254-
.unwrap();
255-
// Because we are going to impact analysis with application we must make sure the function update is triggered to continue to update analysis.
256-
function_meta_workflow
257-
.register_activity(&apply_activity)
258-
.unwrap();
259-
function_meta_workflow
260-
.insert_after("core.function.runFunctionRecognizers", [GUID_ACTIVITY_NAME]);
261-
function_meta_workflow
262-
.insert_after("core.function.generateMediumLevelIL", [APPLY_ACTIVITY_NAME]);
263-
function_meta_workflow.register().unwrap();
263+
264+
let add_function_activities = |workflow: &Workflow| {
265+
let new_workflow = workflow.clone_to(&workflow.name());
266+
new_workflow.register_activity(&guid_activity).unwrap();
267+
new_workflow.register_activity(&apply_activity).unwrap();
268+
new_workflow.insert_after("core.function.runFunctionRecognizers", [GUID_ACTIVITY_NAME]);
269+
new_workflow.insert_after("core.function.generateMediumLevelIL", [APPLY_ACTIVITY_NAME]);
270+
new_workflow.register().unwrap();
271+
};
272+
273+
add_function_activities(&Workflow::instance("core.function.metaAnalysis"));
274+
// TODO: Remove this once the objectivec workflow is registered on the meta workflow.
275+
add_function_activities(&Workflow::instance("core.function.objectiveC"));
264276

265277
let old_module_meta_workflow = Workflow::instance("core.module.metaAnalysis");
266278
let module_meta_workflow = old_module_meta_workflow.clone_to("core.module.metaAnalysis");

0 commit comments

Comments
 (0)