diff options
Diffstat (limited to 'rust/examples/workflow')
| -rw-r--r-- | rust/examples/workflow/Cargo.toml | 11 | ||||
| -rw-r--r-- | rust/examples/workflow/build.rs | 68 | ||||
| -rw-r--r-- | rust/examples/workflow/src/lib.rs | 70 |
3 files changed, 0 insertions, 149 deletions
diff --git a/rust/examples/workflow/Cargo.toml b/rust/examples/workflow/Cargo.toml deleted file mode 100644 index 4c2309ca..00000000 --- a/rust/examples/workflow/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "workflow" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -binaryninja = { path="../../" } -log = "0.4"
\ No newline at end of file diff --git a/rust/examples/workflow/build.rs b/rust/examples/workflow/build.rs deleted file mode 100644 index 5ba9bcde..00000000 --- a/rust/examples/workflow/build.rs +++ /dev/null @@ -1,68 +0,0 @@ -use std::env; -use std::fs::File; -use std::io::BufReader; -use std::path::PathBuf; - -#[cfg(target_os = "macos")] -static LASTRUN_PATH: (&str, &str) = ("HOME", "Library/Application Support/Binary Ninja/lastrun"); - -#[cfg(target_os = "linux")] -static LASTRUN_PATH: (&str, &str) = ("HOME", ".binaryninja/lastrun"); - -#[cfg(windows)] -static LASTRUN_PATH: (&str, &str) = ("APPDATA", "Binary Ninja\\lastrun"); - -// Check last run location for path to BinaryNinja; Otherwise check the default install locations -fn link_path() -> PathBuf { - use std::io::prelude::*; - - let home = PathBuf::from(env::var(LASTRUN_PATH.0).unwrap()); - let lastrun = PathBuf::from(&home).join(LASTRUN_PATH.1); - - File::open(lastrun) - .and_then(|f| { - let mut binja_path = String::new(); - let mut reader = BufReader::new(f); - - reader.read_line(&mut binja_path)?; - Ok(PathBuf::from(binja_path.trim())) - }) - .unwrap_or_else(|_| { - #[cfg(target_os = "macos")] - return PathBuf::from("/Applications/Binary Ninja.app/Contents/MacOS"); - - #[cfg(target_os = "linux")] - return home.join("binaryninja"); - - #[cfg(windows)] - return PathBuf::from(env::var("PROGRAMFILES").unwrap()) - .join("Vector35\\BinaryNinja\\"); - }) -} - -fn main() { - // Use BINARYNINJADIR first for custom BN builds/configurations (BN devs/build server), fallback on defaults - let install_path = env::var("BINARYNINJADIR") - .map(PathBuf::from) - .unwrap_or_else(|_| link_path()); - - #[cfg(target_os = "linux")] - println!( - "cargo:rustc-link-arg=-Wl,-rpath,{},-L{},-l:libbinaryninjacore.so.1", - install_path.to_str().unwrap(), - install_path.to_str().unwrap(), - ); - - #[cfg(target_os = "macos")] - println!( - "cargo:rustc-link-arg=-Wl,-rpath,{},-L{},-lbinaryninjacore", - install_path.to_str().unwrap(), - install_path.to_str().unwrap(), - ); - - #[cfg(target_os = "windows")] - { - println!("cargo:rustc-link-lib=binaryninjacore"); - println!("cargo:rustc-link-search={}", install_path.to_str().unwrap()); - } -} diff --git a/rust/examples/workflow/src/lib.rs b/rust/examples/workflow/src/lib.rs deleted file mode 100644 index 6f415941..00000000 --- a/rust/examples/workflow/src/lib.rs +++ /dev/null @@ -1,70 +0,0 @@ -use binaryninja::llil::{ - ExprInfo, LiftedNonSSA, NonSSA, VisitorAction, -}; -use binaryninja::workflow::{Activity, AnalysisContext, Workflow}; -use log::LevelFilter; -use binaryninja::logger::Logger; - -const RUST_ACTIVITY_NAME: &'static str = "analysis.plugins.rustexample"; -const RUST_ACTIVITY_CONFIG: &'static str = r#"{ - "name": "analysis.plugins.rustexample", - "title" : "Rust Example", - "description": "This analysis step logs out some information about the function...", - "eligibility": { - "auto": { "default": true }, - "runOnce": false - } -}"#; - -fn example_activity(analysis_context: &AnalysisContext) { - let func = analysis_context.function(); - log::info!( - "Activity `{}` called in function {} with workflow {:?}!", - RUST_ACTIVITY_NAME, - func.start(), - func.workflow().map(|wf| wf.name()) - ); - // If we have llil available, replace that as well. - if let Some(llil) = unsafe { analysis_context.llil_function::<NonSSA<LiftedNonSSA>>() } { - for basic_block in &func.basic_blocks() { - for instr in basic_block.iter() { - if let Some(llil_instr) = llil.instruction_at(instr) { - llil_instr.visit_tree(&mut |expr, info| { - match info { - ExprInfo::Const(_op) => { - // Replace all consts with 0x1337. - log::info!( - "Replacing llil expression @ 0x{:x} : {}", - instr, - expr.index() - ); - unsafe { - llil.replace_expression(expr.index(), llil.const_int(4, 0x1337)) - }; - } - _ => {} - } - VisitorAction::Descend - }); - } - } - } - analysis_context.set_lifted_il_function(&llil); - } -} - -#[no_mangle] -#[allow(non_snake_case)] -pub extern "C" fn CorePluginInit() -> bool { - Logger::new("Workflow Example").with_level(LevelFilter::Info).init(); - - log::info!("Initialized the plugin"); - - let meta_workflow = Workflow::new_from_copy("core.function.metaAnalysis"); - let activity = Activity::new_with_action(RUST_ACTIVITY_CONFIG, example_activity); - meta_workflow.register_activity(&activity).unwrap(); - meta_workflow.insert("core.function.runFunctionRecognizers", [RUST_ACTIVITY_NAME]); - // Re-register the meta workflow with our changes. - meta_workflow.register().unwrap(); - true -} |
