From 395a6dc683bcb687ad5fd1c5b1b63205ffd1af79 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Thu, 7 Aug 2025 22:53:00 -0700 Subject: [Rust] Add builder API for creating workflows `Workflow::new` is replaced by `Workflow::build` that returns a `Builder` type that supports the operations that mutate a workflow, such as registering activities. `Workflow::instance` is replaced by `Workflow::get` to make clear that it is intended to look up an existing workflow. `Workflow::cloned` is introduced to wrap the common pattern of retrieving an existing workflow and cloning it with the same name in order to modify it. `Builder::activity_before` / `Builder::activity_after` are introduced to wrap the common pattern of registering an activity then inserting it before or after a given activity. --- plugins/svd/src/lib.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'plugins/svd/src') diff --git a/plugins/svd/src/lib.rs b/plugins/svd/src/lib.rs index b02b1ec2..3a40d2c0 100644 --- a/plugins/svd/src/lib.rs +++ b/plugins/svd/src/lib.rs @@ -9,7 +9,6 @@ use binaryninja::logger::Logger; use binaryninja::workflow::{Activity, AnalysisContext, Workflow}; use log::LevelFilter; -pub const LOADER_ACTIVITY_NAME: &str = "analysis.svd.loader"; const LOADER_ACTIVITY_CONFIG: &str = r#"{ "name": "analysis.svd.loader", "title" : "SVD Loader", @@ -62,7 +61,10 @@ impl Command for LoadSVDFile { #[allow(non_snake_case)] #[cfg(not(feature = "demo"))] pub extern "C" fn CorePluginInit() -> bool { - plugin_init(); + if plugin_init().is_err() { + log::error!("Failed to initialize SVD plug-in"); + return false; + } true } @@ -70,11 +72,14 @@ pub extern "C" fn CorePluginInit() -> bool { #[allow(non_snake_case)] #[cfg(feature = "demo")] pub extern "C" fn SVDPluginInit() -> bool { - plugin_init(); + if plugin_init().is_err() { + log::error!("Failed to initialize SVD plug-in"); + return false; + } true } -fn plugin_init() { +fn plugin_init() -> Result<(), ()> { Logger::new("SVD").with_level(LevelFilter::Debug).init(); binaryninja::command::register_command( @@ -113,12 +118,10 @@ fn plugin_init() { }; // Register new workflow activity to load svd information. - let old_module_meta_workflow = Workflow::instance("core.module.metaAnalysis"); - let module_meta_workflow = old_module_meta_workflow.clone_to("core.module.metaAnalysis"); let loader_activity = Activity::new_with_action(LOADER_ACTIVITY_CONFIG, loader_activity); - module_meta_workflow - .register_activity(&loader_activity) - .unwrap(); - module_meta_workflow.insert("core.module.loadDebugInfo", [LOADER_ACTIVITY_NAME]); - module_meta_workflow.register().unwrap(); + Workflow::cloned("core.module.metaAnalysis") + .ok_or(())? + .activity_before(&loader_activity, "core.module.loadDebugInfo")? + .register()?; + Ok(()) } -- cgit v1.3.1