()
| 18 | |
| 19 | #[test] |
| 20 | fn test_render_layer_linear_view() { |
| 21 | let _session = Session::new().expect("Failed to initialize session"); |
| 22 | let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap(); |
| 23 | let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view"); |
| 24 | |
| 25 | struct NopRenderLayer; |
| 26 | impl RenderLayer for NopRenderLayer { |
| 27 | fn apply_to_disassembly_block( |
| 28 | &self, |
| 29 | _block: &BasicBlock<NativeBlock>, |
| 30 | lines: Vec<DisassemblyTextLine>, |
| 31 | ) -> Vec<DisassemblyTextLine> { |
| 32 | println!("Nothing added to disassembly block"); |
| 33 | lines |
| 34 | } |
| 35 | } |
| 36 | let (_, nop_render_layer) = |
| 37 | register_render_layer("Nop Render Layer", NopRenderLayer, Default::default()); |
| 38 | |
| 39 | // Create linear view object stuff |
| 40 | let settings = DisassemblySettings::new(); |
| 41 | settings.set_option(DisassemblyOption::ShowAddress, false); |
| 42 | settings.set_option(DisassemblyOption::WaitForIL, true); |
| 43 | settings.set_option(DisassemblyOption::IndentHLILBody, false); |
| 44 | settings.set_option(DisassemblyOption::ShowCollapseIndicators, false); |
| 45 | settings.set_option(DisassemblyOption::ShowFunctionHeader, false); |
| 46 | |
| 47 | let linear_view = LinearViewObject::disassembly(&view, &settings); |
| 48 | let mut cursor = linear_view.create_cursor(); |
| 49 | // Seek to the start of the function `__crt_strtox::is_overflow_condition<uint64_t>` |
| 50 | cursor.seek_to_address(view.original_image_base() + 0x26240); |
| 51 | let current_object = cursor.current_object(); |
| 52 | let current_lines = cursor.lines().to_vec(); |
| 53 | |
| 54 | let new_lines = nop_render_layer.apply_to_linear_view_object( |
| 55 | ¤t_object, |
| 56 | None, |
| 57 | None, |
| 58 | current_lines.clone(), |
| 59 | ); |
| 60 | |
| 61 | // These should 100% be in the same order. If not that is a bug. |
| 62 | |
| 63 | for (i, (current_line, new_line)) in current_lines.iter().zip(new_lines.iter()).enumerate() { |
| 64 | if current_line != new_line { |
| 65 | assert_eq!(current_line, new_line, "Line mismatch at index {}", i); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | struct AddRenderLayer; |
| 70 | impl RenderLayer for AddRenderLayer { |
| 71 | fn apply_to_disassembly_block( |
| 72 | &self, |
| 73 | _block: &BasicBlock<NativeBlock>, |
| 74 | mut lines: Vec<DisassemblyTextLine>, |
| 75 | ) -> Vec<DisassemblyTextLine> { |
| 76 | println!("Adding to disassembly block"); |
| 77 | lines.push(DisassemblyTextLine::from("heyyyyy")); |
nothing calls this directly
no test coverage detected