()
| 46 | } |
| 47 | |
| 48 | pub fn main() { |
| 49 | println!("Starting session..."); |
| 50 | // This loads all the core architecture, platform, etc plugins |
| 51 | let headless_session = |
| 52 | binaryninja::headless::Session::new().expect("Failed to initialize session"); |
| 53 | |
| 54 | println!("Registering workflow..."); |
| 55 | let old_meta_workflow = Workflow::instance("core.function.metaAnalysis"); |
| 56 | let meta_workflow = old_meta_workflow.clone_to("core.function.metaAnalysis"); |
| 57 | let activity = Activity::new_with_action(RUST_ACTIVITY_CONFIG, example_activity); |
| 58 | meta_workflow.register_activity(&activity).unwrap(); |
| 59 | meta_workflow.insert("core.function.runFunctionRecognizers", [RUST_ACTIVITY_NAME]); |
| 60 | // Re-register the meta workflow with our changes. |
| 61 | meta_workflow.register().unwrap(); |
| 62 | |
| 63 | println!("Loading binary..."); |
| 64 | let bv = headless_session |
| 65 | .load("/bin/cat") |
| 66 | .expect("Couldn't open `/bin/cat`"); |
| 67 | |
| 68 | // traverse all llil expressions and look for the constant 0x1337 |
| 69 | for func in &bv.functions() { |
| 70 | if let Ok(llil) = func.low_level_il() { |
| 71 | for block in &llil.basic_blocks() { |
| 72 | for instr in block.iter() { |
| 73 | instr.visit_tree(&mut |expr| { |
| 74 | if let LowLevelILExpressionKind::Const(value) = expr.kind() { |
| 75 | if value.value() == 0x1337 { |
| 76 | println!( |
| 77 | "Found constant 0x1337 at instruction 0x{:x} in function {}", |
| 78 | instr.address(), |
| 79 | func.start() |
| 80 | ); |
| 81 | } |
| 82 | } |
| 83 | VisitorAction::Descend |
| 84 | }); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |
nothing calls this directly
no test coverage detected